Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

### Changes
- [Planner] Stress tests in the `psycho` style no longer expect the app to reject strange values such as SQL-like text. Saving the value and showing it as plain text passes; a crash, an error, lost data or executed markup fails.
- [Prima] `prima browser` opens a playwright-cli session when none is open, instead of only printing the command to start one. It runs `playwright-cli open`, or `npx @playwright/cli open` when playwright-cli is not installed, at `--url` or the configured base URL. A `--pw-session` name that is not open yet is opened under that name. When several sessions are open and none is named, it still asks you to pick one.
```bash
prima browser --url https://app.example.com # browser: playwright-cli session "default" at ...
prima browser --pw-session staging # opens or reuses the "staging" session
```
## 2026-11-12

### Changes
Expand Down
2 changes: 1 addition & 1 deletion boat/prima/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export function createPrimaCommands(name = 'prima'): Command {
process.exit(0);
});

addBrowserOptions(cmd.command('browser').description('Check that a playwright-cli session is open for prima to drive')).action(async (options) => {
addBrowserOptions(cmd.command('browser').description('Open a playwright-cli session for prima to drive, or report the one already open')).action(async (options) => {
try {
console.log(await primaFor(options).browserCheck());
} catch (error) {
Expand Down
28 changes: 25 additions & 3 deletions boat/prima/src/prima.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { spawnSync } from 'node:child_process';
import { createHash } from 'node:crypto';
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
import { createRequire } from 'node:module';
Expand Down Expand Up @@ -581,7 +582,12 @@ export class Prima {

async browserCheck(): Promise<string> {
await this.loadConfig();
const { match, candidates, browser } = await this.discover();
let discovery = await this.discover();
if (!discovery.match && (this.pwSessionTitle() || !discovery.candidates.length)) {
this.openPlaywrightSession();
discovery = await this.discover();
}
const { match, candidates, browser } = discovery;
await browser?.close().catch(() => {});
if (!match) throw this.missingSessionError(candidates);
return `browser: ${this.attachmentLabel(match)} at ${match.endpoint}`;
Expand Down Expand Up @@ -722,9 +728,25 @@ export class Prima {
`);
}

private openPlaywrightSession(): void {
const args = ['open'];
const title = this.pwSessionTitle();
if (title) args.unshift(`-s=${title}`);
const url = this.options.url || this.configBaseUrl();
if (url) args.push(url);

const stdio: any = ['ignore', 'ignore', 'inherit'];
const local = spawnSync('playwright-cli', args, { stdio });
if (!local.error) return;
spawnSync('npx', ['-y', '@playwright/cli', ...args], { stdio });
}

private pwSessionTitle(): string | undefined {
return this.options.pwSession ?? process.env.PLAYWRIGHT_CLI_SESSION;
}

private async discover(descriptors = readDescriptors()): Promise<Discovery> {
const title = this.options.pwSession ?? process.env.PLAYWRIGHT_CLI_SESSION;
const opts = { title };
const opts = { title: this.pwSessionTitle() };

const alive = new Map<PwServerDescriptor, Browser>();
for (const candidate of selectDescriptor(descriptors, opts).candidates) {
Expand Down
47 changes: 46 additions & 1 deletion boat/prima/tests/prima.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1744,9 +1744,54 @@ describe('Prima browser instances', () => {
expect(await prima.browserCheck()).toBe('browser: playwright-cli session "auth" at ws://127.0.0.1:4321/auth');
});

test('browserCheck fails proposing playwright-cli open when no session is open', async () => {
test('browserCheck opens a playwright-cli session when none is open', async () => {
const { prima } = fakePrima({ url: 'https://app.example.com' });
(prima as any).loadConfig = async () => ({});
let opened = false;
(prima as any).openPlaywrightSession = () => {
opened = true;
};
(prima as any).discover = () => {
if (!opened) return { candidates: [] };
return { match: { title: 'default', endpoint: 'ws://127.0.0.1:4321/default', workspaceDir: '' }, candidates: [] };
};

expect(await prima.browserCheck()).toBe('browser: playwright-cli session "default" at ws://127.0.0.1:4321/default');
});

test('browserCheck opens a named session that is not open yet beside other sessions', async () => {
const { prima } = fakePrima({ pwSession: 'mine' });
(prima as any).loadConfig = async () => ({});
let opened = false;
(prima as any).openPlaywrightSession = () => {
opened = true;
};
(prima as any).discover = () => {
const other = { title: 'other', endpoint: 'ws://127.0.0.1:4321/other', workspaceDir: '' };
if (!opened) return { candidates: [other] };
return { match: { title: 'mine', endpoint: 'ws://127.0.0.1:4321/mine', workspaceDir: '' }, candidates: [other] };
};

expect(await prima.browserCheck()).toBe('browser: playwright-cli session "mine" at ws://127.0.0.1:4321/mine');
});

test('browserCheck asks to pick a session when several are open and none is named', async () => {
const { prima } = fakePrima();
(prima as any).loadConfig = async () => ({});
let opened = false;
(prima as any).openPlaywrightSession = () => {
opened = true;
};
(prima as any).discover = () => ({ candidates: [{ title: 'a' }, { title: 'b' }] });

await expect(prima.browserCheck()).rejects.toThrow(/--pw-session/);
expect(opened).toBe(false);
});

test('browserCheck fails proposing playwright-cli open when the launch opened nothing', async () => {
const { prima } = fakePrima({ url: 'https://app.example.com' });
(prima as any).loadConfig = async () => ({});
(prima as any).openPlaywrightSession = () => {};
(prima as any).discover = () => ({ candidates: [] });

await expect(prima.browserCheck()).rejects.toThrow(/playwright-cli open https:\/\/app.example.com/);
Expand Down
Loading