diff --git a/CHANGELOG.md b/CHANGELOG.md index 19ff7a3..fdb914a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## 0.3.0 (unreleased) + +- Add `PaseoWeb.openFiles`, `openFile`, `fileTab`, `chooseFilePanel`, `openWith`, `pinFile`, `closeFile` and `reload` for native file-panel tests. Paths identify tabs by their full workspace-relative name. Tree traversal distinguishes repeated folder names and file basenames. +- Add `ppd web --open-file PATH --with PANEL` for file-panel screenshots. +- `openFile` scrolls long Files trees to find the row. A requested panel without a picker, an unknown panel or a missing file fail with a clear message. +- Without a Paseo host and without `requirements.paseo`, `ppd check` now applies the Paseo 0.15.3 client contract instead of 0.12.0, including the 0.13.0 rules. +- Verify the daemon, compiler and web UI on Paseo 0.15.3. Add an isolated nested-file regression covering panel selection, changes, deletion, restoration, reload and reopening. +- Close the browser when initial app navigation fails. + ## 0.2.0 (2026-10-30) - Verified on Paseo 0.12.0: `ppd daemon up` and `ppd doctor` no longer print the version note on it. diff --git a/README.md b/README.md index eca9148..b4ae094 100644 --- a/README.md +++ b/README.md @@ -73,16 +73,16 @@ $ npx ppd check examples/hello-plugin PASS manifest hello-plugin, requires paseo >=0.11.2 PASS imports client, server and shared boundaries hold PASS dependencies no runtime packages -PASS paseo-compile compilePlugin of the Paseo 0.12.0 app (/Applications/Paseo.app) accepted the plugin +PASS paseo-compile compilePlugin of the Paseo 0.15.3 app (/Applications/Paseo.app) accepted the plugin PASS client-requires client requires only host modules (@getpaseo/plugin, @getpaseo/plugin/client, react, react-native, react/jsx-runtime, zod) PASS server-requires server requires only host modules and Node built-ins PASS server-eval Paseo's evaluator ran the contribution in 0 ms; RPCs: hello.greet -PASS client-eval contributions: addWorkspacePanel, addCommandCenterItem +PASS client-eval contributions: addWorkspacePanel, addCommandCenterItem (Paseo 0.15.3 rules) PASS hermes-class no class syntax in the client bundle SKIP hermes-parse hermesc not found (install react-native as a devDependency, or set HERMESC) SKIP hermes-vm Hermes VM not found (react-native ships it for macOS; or set HERMES) -PASS lucide-icons 2 icon name(s) valid against 6354 Lucide icons of the Paseo 0.12.0 app (/Applications/Paseo.app) -PASS bundle-size client 5 KiB (2 KiB gzip), budget 2.0 MiB; server 2 KiB (1 KiB gzip), eval 0 ms, budget 32.0 MiB +PASS lucide-icons 2 icon name(s) valid against 6354 Lucide icons of the Paseo 0.15.3 app (/Applications/Paseo.app) +PASS bundle-size client 3 KiB (1 KiB gzip), budget 2.0 MiB; server 2 KiB (1 KiB gzip), eval 0 ms, budget 32.0 MiB 11 passed, 0 warnings, 0 failed, 2 skipped @@ -91,7 +91,7 @@ dev daemon "default" up url: http://127.0.0.1:7800 home: $TMPDIR/ppd-default-aiOmq4 pid: 51399 - paseo: 0.12.0 + paseo: 0.15.3 workspace created for /tmp/demo-workspace $ npx ppd install examples/hello-plugin # rerun after edits, or: npx ppd dev examples/hello-plugin @@ -168,6 +168,26 @@ await assertWithinRpcBudget(() => handlers.get("doc.render")!(worstCaseInput)); `paseo-plugin-devkit/web` exports the `PaseoWeb` Playwright page object for your own browser tests. +File-panel tests can use the real Files tree and native tab menu: + +```ts +const ui = await PaseoWeb.launch({ url: daemon.url }); +try { + await ui.openWorkspace(serverId, workspaceId); + await ui.openFile("reports/live.csv", { panel: "Viewer \u2014 paseo-doc-viewer", remember: true }); + await ui.pinFile("reports/live.csv"); + await ui.reload(); + await ui.openWith("reports/live.csv", "Source \u2014 Paseo"); + await ui.closeFile("reports/live.csv"); +} finally { + await ui.close(); +} +``` + +Paths are workspace-relative, use `/`, and must not contain `.` or `..` segments. Tab helpers use the full relative path, even when the visible tab shows only its basename. `openFile` focuses an existing tab, otherwise opens through Files, scrolling long trees to find the row. Pass `panel` when a picker is expected; the helper waits up to 10 s for it even when the tab appears first, then fails with a clear error. Panel names accept a unique title or the full host label; an ambiguous title fails instead of choosing a plugin. Omit `panel` when reopening with a saved association; use `openWith` to change it. These helpers target desktop file tabs; compact file sheets can be exercised through `ui.page`. + +The CLI accepts the same opening step: `ppd web --workspace --open-file report.pdf --shot report.png`. Add `--with Viewer` for files with a panel picker. `PPD_E2E=1 npx vitest run test/file-panels-e2e.test.ts` exercises duplicate folder and file names, a file below 400 others, a nested CSV, a panel requested without a picker, remembered panel choice, rewrite, deletion, restoration, app reload and tab closure on a fresh isolated daemon; it removes the daemon and temporary workspace on failure too. + ## Fake agent Agent-facing plugins (hooks, timeline cards, injected MCP tools) need agent turns to test. `ppd daemon up --fake-agent` installs `fake-agent`, a credential-free provider plugin ([`assets/fake-agent`](assets/fake-agent)) that runs a scripted turn per prompt. It emits the timeline items real adapters produce, does the file effects for real in the agent's cwd, and calls tools on the MCP servers in its session config (what plugins inject in `before("agent.create")`), over HTTP or stdio. Paseo's own mock provider needs a development build and supports no MCP servers; this replaces it. @@ -249,7 +269,7 @@ It also has a weekly job that checks out Paseo main, sets `PASEO_SOURCE` and run ## Compatibility -Verified on macOS with Paseo 0.12.0 (desktop app and CLI). CI runs on Linux without Paseo, where daemon tests skip and `ppd check` runs as an approximation. +Verified on macOS with Paseo 0.15.3 (desktop app compiler, CLI and served web UI). CI runs on Linux without Paseo, where daemon tests skip and `ppd check` runs as an approximation. The file-panel lifecycle test uses a real isolated daemon and Chrome; it does not verify the native iOS or Android app. ### React Native, React and Dependabot @@ -288,11 +308,11 @@ Review a series upgrade explicitly when the supported host and its React/SDK con - Without the Paseo app or `PASEO_SOURCE` (Linux CI) the compile is an approximation and icon names are checked only against the plugin's own `lucide-react-native`, if any. - Time limits are 30 s per evaluated bundle and 120 s for the real compile, server evaluation included. There is no CLI flag; `runChecks` and `describeHostContract` take `evalTimeoutMs` and `compileTimeoutMs`. - The 32 MiB relay budget comes from field experience, not from Paseo source; direct connections allow 100 MiB. -- `ppd web` needs Google Chrome or a Playwright Chromium matching `playwright-core`. Its selectors follow the Paseo 0.12 web UI and may need updates when the app changes. +- `ppd web` needs Google Chrome or a Playwright Chromium matching `playwright-core`. Its selectors were exercised on Paseo 0.15.3 and may need updates when the app changes. - No iOS command: the simulator build is manual (see the skill). No multi-touch injection for Android. - `ppd release` and `ppd registry update` are tested against local Git repos and a stub validator, not yet end to end against GitHub and the live registry. - The daemon end-to-end tests are opt-in (`PPD_E2E=1 npm test`, `PPD_E2E_PORT` to pin the port) because CI has no Paseo CLI. -- macOS and Linux only. Tested on macOS with Paseo 0.12.0 (see [Compatibility](#compatibility)). +- macOS and Linux only. Tested on macOS with Paseo 0.15.3 (see [Compatibility](#compatibility)). ## Roadmap diff --git a/docs-site/src/lib/commands.json b/docs-site/src/lib/commands.json index 6e2d9b5..afc521e 100644 --- a/docs-site/src/lib/commands.json +++ b/docs-site/src/lib/commands.json @@ -47,7 +47,7 @@ "topic": "web", "usage": "ppd web", "summary": "open the web UI in Chrome, screenshot, click through", - "help": "ppd web [--shot FILE] [--viewport WxH] [--command TEXT] [--click LABEL]... [options]\n\nOpens the dev daemon's web UI in Chrome (Playwright), opens the only workspace (or --workspace), runs the\nsteps in order and prints console errors.\n\n --shot FILE save a screenshot\n --viewport WxH e.g. 390x844; widths under 768 get the compact (phone) layout with touch\n --command TEXT select a Command Center item by its exact title\n --click LABEL click an element by its accessible name (repeatable)\n --workspace ID workspace id, name or path\n --path /route open an app route instead of a workspace\n --wait MS settle time before the screenshot (default 1500)\n --full-page full-page screenshot\n --headed show the browser\n --name N target dev daemon" + "help": "ppd web [--shot FILE] [--viewport WxH] [--command TEXT] [--click LABEL]... [options]\n\nOpens the dev daemon's web UI in Chrome (Playwright), opens the only workspace (or --workspace), runs the\nsteps in order and prints console errors.\n\n --shot FILE save a screenshot\n --viewport WxH e.g. 390x844; widths under 768 get the compact (phone) layout with touch\n --command TEXT select a Command Center item by its exact title\n --open-file PATH open a workspace-relative file through Paseo's Files tree\n --with PANEL answer the panel picker with a unique panel title or full label (requires --open-file);\n fails when the file opens without a picker (saved association or single panel)\n --click LABEL click an element by its accessible name (repeatable)\n --workspace ID workspace id, name or path\n --path /route open an app route instead of a workspace\n --wait MS settle time before the screenshot (default 1500)\n --full-page full-page screenshot\n --headed show the browser\n --name N target dev daemon" }, { "topic": "android", diff --git a/docs-site/src/routes/(docs)/docs/getting-started/+page.svx b/docs-site/src/routes/(docs)/docs/getting-started/+page.svx index 9db3a33..f36f4b3 100644 --- a/docs-site/src/routes/(docs)/docs/getting-started/+page.svx +++ b/docs-site/src/routes/(docs)/docs/getting-started/+page.svx @@ -65,19 +65,19 @@ npm run check && npm test ``` ```text -PASS manifest my-plugin, requires paseo >=0.12.0 +PASS manifest my-plugin, requires paseo >=0.15.3 PASS imports client, server and shared boundaries hold PASS dependencies no runtime packages -PASS paseo-compile compilePlugin of the Paseo 0.12.0 app (/Applications/Paseo.app) accepted the plugin +PASS paseo-compile compilePlugin of the Paseo 0.15.3 app (/Applications/Paseo.app) accepted the plugin PASS client-requires client requires only host modules (@getpaseo/plugin, @getpaseo/plugin/client, react, react-native, react/jsx-runtime, zod) PASS server-requires server requires only host modules and Node built-ins PASS server-eval Paseo's evaluator ran the contribution in 0 ms; RPCs: hello.greet -PASS client-eval contributions: addWorkspacePanel, addCommandCenterItem +PASS client-eval contributions: addWorkspacePanel, addCommandCenterItem (Paseo 0.15.3 rules) PASS hermes-class no class syntax in the client bundle PASS hermes-parse hermesc compiles the client bundle PASS hermes-vm Hermes VM evaluated the bundle and ran the contribution (addWorkspacePanel, addCommandCenterItem) -PASS lucide-icons 2 icon name(s) valid against 6354 Lucide icons of the Paseo 0.12.0 app (/Applications/Paseo.app) -PASS bundle-size client 5 KiB (2 KiB gzip), budget 2.0 MiB; server 2 KiB (1 KiB gzip), eval 0 ms, budget 32.0 MiB +PASS lucide-icons 2 icon name(s) valid against 6354 Lucide icons of the Paseo 0.15.3 app (/Applications/Paseo.app) +PASS bundle-size client 3 KiB (1 KiB gzip), budget 2.0 MiB; server 2 KiB (1 KiB gzip), eval 0 ms, budget 32.0 MiB 13 passed, 0 warnings, 0 failed, 0 skipped ``` @@ -96,7 +96,7 @@ dev daemon "default" up url: http://127.0.0.1:7800 home: $TMPDIR/ppd-default-2kCaQs pid: 84941 - paseo: 0.12.0 + paseo: 0.15.3 workspace created for ~/code/my-plugin ``` diff --git a/docs-site/src/routes/+page.svelte b/docs-site/src/routes/+page.svelte index 64cee91..1906261 100644 --- a/docs-site/src/routes/+page.svelte +++ b/docs-site/src/routes/+page.svelte @@ -9,7 +9,7 @@ dev daemon "default" up url: http://127.0.0.1:7800 home: $TMPDIR/ppd-default-2kCaQs pid: 84941 - paseo: 0.12.0 + paseo: 0.15.3 workspace created for ~/code/my-plugin $ npx ppd check | tail -1 13 passed, 0 warnings, 0 failed, 0 skipped diff --git a/package-lock.json b/package-lock.json index 2c57e9f..6bd7e15 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "paseo-plugin-devkit", - "version": "0.2.0", + "version": "0.3.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "paseo-plugin-devkit", - "version": "0.2.0", + "version": "0.3.0", "license": "MIT AND Apache-2.0", "dependencies": { "esbuild": "^0.28.2", diff --git a/package.json b/package.json index 61f6d50..ba9ffc9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "paseo-plugin-devkit", - "version": "0.2.0", + "version": "0.3.0", "description": "Unofficial dev kit for Paseo plugin authors: isolated dev daemon, host-contract checks, a scripted fake agent, web UI screenshots, registry and release helpers, plus a Claude Code skill.", "keywords": [ "paseo", diff --git a/src/cli.ts b/src/cli.ts index 2b89403..a5e921d 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -100,6 +100,9 @@ steps in order and prints console errors. --shot FILE save a screenshot --viewport WxH e.g. 390x844; widths under 768 get the compact (phone) layout with touch --command TEXT select a Command Center item by its exact title + --open-file PATH open a workspace-relative file through Paseo's Files tree + --with PANEL answer the panel picker with a unique panel title or full label (requires --open-file); + fails when the file opens without a picker (saved association or single panel) --click LABEL click an element by its accessible name (repeatable) --workspace ID workspace id, name or path --path /route open an app route instead of a workspace diff --git a/src/compat.ts b/src/compat.ts index 0e66503..66da596 100644 --- a/src/compat.ts +++ b/src/compat.ts @@ -3,7 +3,7 @@ // verified on one Paseo release; a different release may move things. /** The Paseo release whose app layout, daemon flags and web UI labels ppd was verified on. */ -export const VERIFIED_PASEO = "0.12.0"; +export const VERIFIED_PASEO = "0.15.3"; export const ISSUES_URL = "https://github.com/nkwib/paseo-plugin-devkit/issues"; diff --git a/src/index.ts b/src/index.ts index a1f1429..a73265e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,6 @@ export * from "./testing.ts"; export { PaseoWeb, parseViewport } from "./web.ts"; +export type { FileOpenOptions, LaunchOptions, Viewport } from "./web.ts"; export { daemonUp, daemonDown, daemonStatus, installFakeAgent, readDaemon, requireDaemon } from "./daemon.ts"; export type { DaemonRecord } from "./daemon.ts"; export { installPlugin } from "./install.ts"; diff --git a/src/web.ts b/src/web.ts index 4103b34..942e930 100644 --- a/src/web.ts +++ b/src/web.ts @@ -46,6 +46,13 @@ export interface LaunchOptions { executablePath?: string; } +export interface FileOpenOptions { + /** Answer an expected panel picker with this unique title or full host label. Omit for a saved association. */ + panel?: string; + /** Remember the panel choice when the host shows its picker. */ + remember?: boolean; +} + const CHROME_PATHS: Record = { darwin: ["/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"], linux: ["/usr/bin/google-chrome", "/usr/bin/google-chrome-stable"], @@ -76,6 +83,11 @@ export function pluginEvaluationFailure(text: string): string | null { return match ? `${match[1]}: ${match[2]?.trim() || "unknown error"}` : null; } +function panelName(panel: string): RegExp { + const escaped = panel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); + return new RegExp(`^${escaped}(?: \\u2014 .+)?$`); +} + export class PaseoWeb { /** Console errors, page errors and plugin evaluation failures. */ readonly errors: string[] = []; @@ -110,8 +122,13 @@ export class PaseoWeb { hasTouch: compact, }); const web = new PaseoWeb(browser, page, options.url.replace(/\/$/, "")); - await web.gotoRoute("/"); - return web; + try { + await web.gotoRoute("/"); + return web; + } catch (error) { + await browser.close().catch(() => {}); + throw error; + } } /** Waits for the app shell: the sidebar on wide layouts, the menu button on compact ones. */ @@ -132,6 +149,150 @@ export class PaseoWeb { await waitForUi(this.page.getByLabel("Workspace actions", { exact: true }).first(), 'the workspace (a "Workspace actions" button)', 30_000); } + /** Open the host's Files tree in the current workspace. */ + async openFiles(): Promise { + const browse = this.page.getByRole("button", { name: "Browse workspace files", exact: true }); + if (!(await browse.isVisible())) { + await this.page.getByRole("button", { name: "Open Explorer sidebar", exact: true }).click(); + } + await browse.click(); + } + + /** A native file tab, whose accessible name is the workspace-relative path. */ + fileTab(path: string): Locator { + return this.page.getByRole("button", { name: path, exact: true }); + } + + private async fileRow(path: string, timeout = 30_000): Promise { + // Paseo's tree is a flat, virtualized list: row ids are flat indices, indentation supplies ancestry, and only rows + // near the viewport exist. Scan from the top, remembering rows by index, so ancestry survives scrolling and a + // basename never matches the same name in another folder. + const deadline = Date.now() + timeout; + const rows = new Map(); + let fromTop = true; + for (;;) { + if (fromTop) { + rows.clear(); + await this.scrollFiles("top"); + } + const view: { seen: [number, number, string][]; end: boolean } | null = await this.page.evaluate(() => { + const scroller = document.querySelector('[data-testid="file-explorer-tree-scroll"]'); + if (!scroller) return null; + const seen: [number, number, string][] = []; + for (const row of scroller.querySelectorAll('[data-testid^="file-explorer-row-"]')) { + const index = /^file-explorer-row-(\d+)$/.exec(row.dataset.testid ?? "")?.[1]; + const name = row.querySelector('[data-testid$="-name"]')?.textContent; + if (index !== undefined && name) seen.push([Number(index), Number.parseFloat(getComputedStyle(row).paddingLeft), name]); + } + return { seen, end: scroller.scrollTop + scroller.clientHeight >= scroller.scrollHeight - 1 }; + }); + for (const [index, indent, name] of view?.seen ?? []) rows.set(index, { indent, name }); + const parents: { indent: number; name: string }[] = []; + for (let index = 0; rows.has(index); index++) { + const { indent, name } = rows.get(index)!; + while (parents.length && parents.at(-1)!.indent >= indent) parents.pop(); + if ([...parents.map((parent) => parent.name), name].join("/") === path) return this.page.getByTestId(`file-explorer-row-${index}`); + parents.push({ indent, name }); + } + if (Date.now() > deadline) { + throw new Error( + `the Paseo Files tree did not list ${path} within ${timeout / 1000} s. Check that the file exists in the workspace. ppd reads the tree of the Paseo ${VERIFIED_PASEO} web UI; a different version may have changed it (please report it at ${ISSUES_URL})`, + ); + } + // Past the end, or before the tree mounts, start over: the listing may still be loading. + fromTop = !view || view.end; + if (fromTop) await this.page.waitForTimeout(250); + else await this.scrollFiles("down"); + } + } + + /** Scroll the Files tree and give the virtualized list a moment to render the new rows. */ + private async scrollFiles(to: "top" | "down"): Promise { + await this.page.evaluate((to) => { + const scroller = document.querySelector('[data-testid="file-explorer-tree-scroll"]'); + if (scroller) scroller.scrollTop = to === "top" ? 0 : scroller.scrollTop + scroller.clientHeight / 2; + }, to); + await this.page.waitForTimeout(50); + } + + /** Open a workspace-relative path through the real Files tree, never through plugin navigation. */ + async openFile(path: string, options: FileOpenOptions = {}): Promise { + const parts = path.split("/"); + if (parts.some((part) => !part || part === "." || part === "..") || path.includes("\\") || /^[a-z]:/i.test(path)) { + throw new UsageError("file path must be workspace-relative, with / separators and no . or .. segments"); + } + if (await this.fileTab(path).isVisible()) { + await this.fileTab(path).click(); + return this.fileTab(path); + } + await this.openFiles(); + for (let index = 0; index < parts.length - 1; index++) { + const folder = await this.fileRow(parts.slice(0, index + 1).join("/")); + await folder.click({ button: "right" }); + await this.page.getByRole("menuitem", { name: "Copy relative path", exact: true }).waitFor({ state: "visible" }); + const expanded = await this.page.getByRole("menuitem", { name: "Collapse folder", exact: true }).isVisible(); + await this.page.keyboard.press("Escape"); + if (!expanded) await folder.click(); + } + await (await this.fileRow(path)).dblclick(); + // The tab can mount before the file metadata and picker arrive. Wait for the actual radio, + // rather than treating an early tab as evidence that a saved association bypassed the picker. + if (options.panel) await this.chooseFilePanel(options.panel, options.remember); + const tab = this.fileTab(path); + await waitForUi(tab, `file tab ${path}`, 30_000); + return tab; + } + + /** + * Answer Paseo's panel picker. Fails within `timeoutMs` when no picker appears (a saved association or a single + * matching panel opens the file directly); change a saved association with openWith instead. + */ + async chooseFilePanel(panel: string, remember = false, timeoutMs = 10_000): Promise { + const dialog = this.page.getByRole("dialog").filter({ has: this.page.getByRole("radio") }); + try { + await dialog.first().waitFor({ timeout: timeoutMs }); + } catch (error) { + if ((error as Error).name !== "TimeoutError") throw error; + throw new Error( + `no panel picker appeared within ${timeoutMs / 1000} s, so "${panel}" was not chosen: the file opens directly with a saved association or its only panel. Omit the panel (--with), or switch panels with openWith`, + { cause: error }, + ); + } + const radio = dialog.getByRole("radio", { name: panelName(panel) }); + if ((await radio.count()) === 0) { + const offered = await dialog.getByRole("radio").evaluateAll((radios) => radios.map((radio) => radio.getAttribute("aria-label") ?? radio.textContent?.trim() ?? "")); + throw new Error(`the panel picker offers no panel named "${panel}"; it offers: ${offered.join(", ")}`); + } + await radio.click(); + await dialog.getByRole("checkbox", { name: "Don't ask me again", exact: true }).setChecked(remember); + await dialog.getByRole("button", { name: "Use", exact: true }).click(); + } + + /** Select a panel in the native tab menu, using a unique title or full host label. */ + async openWith(name: string, panel: string): Promise { + await this.fileTab(name).click({ button: "right" }); + await this.page.getByRole("menuitem", { name: "Open with…", exact: true }).hover(); + await this.page.getByRole("menuitem", { name: panelName(panel) }).click(); + } + + /** Keep a preview tab open when another file is opened. */ + async pinFile(name: string): Promise { + await this.fileTab(name).dblclick(); + } + + async closeFile(name: string): Promise { + const tab = this.fileTab(name); + await tab.hover(); + await tab.locator("..").getByRole("button", { name: "Close", exact: true }).click(); + await tab.waitFor({ state: "detached" }); + } + + /** Reload the actual app, preserving browser storage and the host's restored tabs. */ + async reload(): Promise { + await this.page.reload(); + await this.ready(); + } + /** An element by its exact accessible name, such as a plugin header button's label. */ control(label: string): Locator { return this.page.getByLabel(label, { exact: true }).first(); @@ -221,10 +382,13 @@ export async function webCommand(args: string[]): Promise { wait: { type: "string" }, headed: { type: "boolean" }, "full-page": { type: "boolean" }, + "open-file": { type: "string" }, + with: { type: "string" }, }, strict: true, }); if (values.wait !== undefined && !/^\d+$/.test(values.wait)) throw new UsageError(`--wait must be milliseconds, got ${values.wait}`); + if (values.with && !values["open-file"]) throw new UsageError("--with requires --open-file"); const daemon = requireDaemon(values.name); if (!daemon.webDist) throw new Error("this dev daemon has no web UI: restart it with `ppd daemon up --web-dist `"); const viewport = values.viewport ? parseViewport(values.viewport) : undefined; @@ -246,6 +410,7 @@ export async function webCommand(args: string[]): Promise { } } if (values.command) await web.runCommand(values.command); + if (values["open-file"]) await web.openFile(values["open-file"], { panel: values.with }); for (const label of values.click ?? []) await web.click(label); await web.page.waitForTimeout(values.wait ? Number(values.wait) : 1500); if (values.shot) console.log(`screenshot: ${await web.shot(values.shot, values["full-page"])}`); diff --git a/test/check.test.ts b/test/check.test.ts index 368c36d..ad8a979 100644 --- a/test/check.test.ts +++ b/test/check.test.ts @@ -53,7 +53,7 @@ describe("compiled fixtures", () => { "Plugin contribution must return a cleanup function", ]); const icon = await evaluateClientBundle(bundle.replace("Bad_Id", "panel"), GOOD, { icons: new Set(["Hand"]) }); - expect(icon.contractErrors).toContain("Unknown Lucide icon: HandWave"); + expect(icon.contractErrors).toContain('Workspace panel panel has an invalid icon: unknown Lucide icon "HandWave"'); }); it("throws the app's error for a module the host does not provide", async () => { diff --git a/test/file-panels-e2e.test.ts b/test/file-panels-e2e.test.ts new file mode 100644 index 0000000..6bf57c1 --- /dev/null +++ b/test/file-panels-e2e.test.ts @@ -0,0 +1,112 @@ +import { mkdirSync, rmSync, writeFileSync } from "node:fs"; +import { spawnSync } from "node:child_process"; +import { join } from "node:path"; +import { afterAll, afterEach, beforeAll, describe, expect, it } from "vitest"; +import { daemonDown, daemonUp } from "../src/daemon.ts"; +import { installPlugin } from "../src/install.ts"; +import { findPaseoBin, runPaseo } from "../src/paseo.ts"; +import { PaseoWeb } from "../src/web.ts"; +import { CLI, FIXTURES, scratch } from "./helpers.ts"; + +const enabled = process.env.PPD_E2E === "1" && findPaseoBin() !== null; +const name = `file-panels-${process.pid}`; + +describe.skipIf(!enabled)("native file-tab helpers (PPD_E2E=1)", () => { + let web: PaseoWeb | undefined; + let workspace: string; + const previousState = process.env.PPD_STATE_DIR; + const previousXdg = process.env.XDG_STATE_HOME; + + beforeAll(async () => { + process.env.PPD_STATE_DIR = scratch("ppd-file-panels-state-"); + process.env.XDG_STATE_HOME = scratch("ppd-file-panels-xdg-"); + workspace = scratch("ppd-file-panels-workspace-"); + mkdirSync(join(workspace, "reports")); + mkdirSync(join(workspace, "archive/reports"), { recursive: true }); + writeFileSync(join(workspace, "archive/reports/live.csv"), "Nested decoy,0\n"); + writeFileSync(join(workspace, "reports/live.csv"), "Before rewrite,1\n"); + writeFileSync(join(workspace, "live.csv"), "Root decoy,0\n"); + // More files than the virtualized Files tree renders at once. + for (let index = 0; index < 400; index++) writeFileSync(join(workspace, `filler-${String(index).padStart(3, "0")}.txt`), ""); + writeFileSync(join(workspace, "zz-last.csv"), "Last row,4\n"); + const daemon = await daemonUp({ name, workspace, log: () => {} }); + const cli = (args: string[]) => { + const result = runPaseo(daemon.paseoBin, daemon.home, [...args, "--json"]); + if (result.status !== 0) throw new Error(result.stderr || result.stdout); + return JSON.parse(result.stdout); + }; + expect((await installPlugin(join(FIXTURES, "file-panel"), { name, log: () => {} })).status).toBe("running"); + const { serverId } = cli(["daemon", "status"]); + const selected = cli(["workspace", "ls"]).find((entry: { cwd: string }) => entry.cwd === workspace); + expect(selected).toBeDefined(); + web = await PaseoWeb.launch({ url: daemon.url }); + await web.openWorkspace(serverId, selected.workspaceId); + }, 180_000); + + afterAll(async () => { + try { + await web?.close(); + } finally { + await daemonDown({ name, log: () => {} }); + if (previousState === undefined) delete process.env.PPD_STATE_DIR; + else process.env.PPD_STATE_DIR = previousState; + if (previousXdg === undefined) delete process.env.XDG_STATE_HOME; + else process.env.XDG_STATE_HOME = previousXdg; + } + }); + + afterEach(async (context) => { + if (context.task.result?.state === "fail" && web) { + console.error(await web.page.locator("body").ariaSnapshot()); + console.error("Plugin errors:", web.pluginErrors, "Console errors:", web.errors); + } + }); + + it("distinguishes duplicate folder and file names in a collapsed tree", async () => { + await web!.openFile("archive/reports/live.csv", { panel: "Fixture" }); + await expect.poll(() => web!.page.getByText("Nested decoy,0", { exact: true }).isVisible()).toBe(true); + await web!.closeFile("archive/reports/live.csv"); + }); + + it("finds a row beyond the rendered part of a long tree", async () => { + await web!.openFile("zz-last.csv", { panel: "Fixture" }); + await expect.poll(() => web!.page.getByText("Last row,4", { exact: true }).isVisible()).toBe(true); + await web!.closeFile("zz-last.csv"); + await expect(web!.openFile("missing.csv")).rejects.toThrow(/did not list missing\.csv/); + }, 120_000); + + it("opens a nested file, selects a panel, watches changes, restores a pinned tab, switches panels and closes it", async () => { + const ui = web!; + await expect(ui.openFile("../outside.csv")).rejects.toThrow(/workspace-relative/); + await ui.openFile("reports/live.csv", { panel: "Fixture", remember: true }); + await ui.pinFile("reports/live.csv"); + await expect.poll(() => ui.page.getByText("Before rewrite,1", { exact: true }).isVisible()).toBe(true); + writeFileSync(join(workspace, "reports/live.csv"), "After rewrite,2\n"); + await expect.poll(() => ui.page.getByText("After rewrite,2", { exact: true }).isVisible()).toBe(true); + rmSync(join(workspace, "reports/live.csv")); + await expect.poll(() => ui.page.getByText("Fixture file unavailable", { exact: true }).isVisible()).toBe(true); + writeFileSync(join(workspace, "reports/live.csv"), "Restored file,3\n"); + await expect.poll(() => ui.page.getByText("Restored file,3", { exact: true }).isVisible()).toBe(true); + await ui.reload(); + await expect.poll(() => ui.fileTab("reports/live.csv").isVisible()).toBe(true); + await expect.poll(() => ui.page.getByText("Restored file,3", { exact: true }).isVisible()).toBe(true); + await ui.openWith("reports/live.csv", "Source"); + await ui.openWith("reports/live.csv", "Fixture \u2014 file-panel-fixture"); + await expect.poll(() => ui.page.getByText("Restored file,3", { exact: true }).isVisible()).toBe(true); + await ui.closeFile("reports/live.csv"); + expect(await ui.fileTab("reports/live.csv").count()).toBe(0); + await ui.openFile("reports/live.csv"); + await expect.poll(() => ui.page.getByText("Restored file,3", { exact: true }).isVisible()).toBe(true); + expect(await ui.page.getByRole("dialog").count()).toBe(0); + await ui.closeFile("reports/live.csv"); + await expect(ui.openFile("reports/live.csv", { panel: "Fixture" })).rejects.toThrow(/no panel picker appeared/); + await ui.closeFile("reports/live.csv"); + const cli = spawnSync(process.execPath, [CLI, "web", "--name", name, "--workspace", workspace, + "--open-file", "reports/live.csv", "--with", "Fixture", "--shot", join(scratch("ppd-file-panels-shots-"), "file.png")], + { encoding: "utf8", timeout: 60_000 }); + expect(cli.status, cli.stderr || cli.stdout).toBe(0); + expect(cli.stdout).toContain("plugin evaluation errors: none"); + expect(ui.pluginErrors).toEqual([]); + expect(ui.errors).toEqual([]); + }, 120_000); +}); diff --git a/test/fixtures/file-panel/index.client.tsx b/test/fixtures/file-panel/index.client.tsx new file mode 100644 index 0000000..a81fb58 --- /dev/null +++ b/test/fixtures/file-panel/index.client.tsx @@ -0,0 +1,12 @@ +import { useFileText, type PluginClientContext, type PluginFilePanelProps } from "@getpaseo/plugin/client"; +import { Text } from "react-native"; + +function Reader({ file, theme }: PluginFilePanelProps) { + const state = useFileText(file); + return {state.status === "error" ? "Fixture file unavailable" : state.status === "ready" ? state.text : "Loading fixture"}; +} + +export default function contribute(client: PluginClientContext) { + const remove = client.addFilePanel({ id: "reader", title: "Fixture", icon: "FileText", files: { extensions: ["csv"] }, Component: Reader }); + return () => remove(); +} diff --git a/test/fixtures/file-panel/paseo-plugin.json b/test/fixtures/file-panel/paseo-plugin.json new file mode 100644 index 0000000..5bc7747 --- /dev/null +++ b/test/fixtures/file-panel/paseo-plugin.json @@ -0,0 +1,4 @@ +{ + "id": "file-panel-fixture", + "requirements": { "paseo": ">=0.13.0" } +}