Computer use for the Pi coding agent — Windows apps, browsers and desktops through native UI trees, screenshots and real input.
TypeScript accessibilityagent-toolsai-agentbrowser-automationcomputer-usecuadesktop-automationelectronpipi-coding-agentpi-extensionpi-packageplaywrighttypescriptui-automationvisionwebview2windowswindows-automationwsl
Cover automatic runtime provisioning
alexshpunt-clanker[bot]157159be03f1
diff --git a/test/config-bundled.test.ts b/test/config-bundled.test.tsindex 864b31c..f1adf1e 100644--- a/test/config-bundled.test.ts+++ b/test/config-bundled.test.ts@@ -43,6 +43,23 @@ test("an interop override reaches the runtime lookup and the driver", async () =expect(findBundledRuntime).toHaveBeenCalledWith("/run/WSL/7_interop");});+test("a legacy automatically installed desktop driver follows the package instead of a stale path", async () => {+ vi.stubEnv("CUA_DRIVER_PATH", undefined);+ const config = { command: "/mnt/c/Users/user/AppData/Local/Programs/PiComputerUsePoC/cua-driver-0.37.0-33c4b82b/runtime/cua-driver.exe", runtime: "windows-desktop" };+ expect(await loadComputerConfig(await workspace(config))).toEqual({ command: runtime.command, bundled: runtime, runtime: "windows-desktop" });+});++test("an explicitly marked override can select a managed-looking path", async () => {+ vi.stubEnv("CUA_DRIVER_PATH", undefined);+ const command = "/mnt/c/Users/user/AppData/Local/Programs/PiComputerUsePoC/cua-driver-0.37.0-33c4b82b/runtime/cua-driver.exe";+ expect(await loadComputerConfig(await workspace({ command, runtime: "windows-desktop", driverOverride: true }))).toEqual({ command, runtime: "windows-desktop", driverOverride: true });+ expect(findBundledRuntime).not.toHaveBeenCalled();+});+test("a deliberate override is not silently replaced", async () => {+ vi.stubEnv("CUA_DRIVER_PATH", undefined);+ const config = { command: "/owned/candidate/cua-driver.exe", runtime: "windows-desktop" };+ expect(await loadComputerConfig(await workspace(config))).toEqual(config);+});test("a trusted command and its own profile replace the shipped runtime without looking it up", async () => {vi.stubEnv("CUA_DRIVER_PATH", undefined);const config = { command: "/owned/candidate/cua-driver.exe", runtime: "windows-window-management" };diff --git a/test/driver-version.test.ts b/test/driver-version.test.tsindex 04c7578..7b680b9 100644--- a/test/driver-version.test.ts+++ b/test/driver-version.test.ts@@ -75,6 +75,17 @@ test("older profiles refuse capture-bound drag before starting any native peer",} finally { await backend.close(); }}});+test("an explicit test override can run a different driver version", async () => {+ await mkdir(".tmp/native-zoom", { recursive: true });+ const cwd = await mkdtemp(path.resolve(".tmp/native-zoom/override-"));+ const log = path.join(cwd, "calls.jsonl");+ const backend = new McpDriver({ command: process.execPath, args: [path.resolve("test/fixtures/detail-driver.mjs"), log, "0.39.0", "advertise"], driverOverride: true });+ try {+ const result = await backend.call("get_desktop_state", { max_image_dimension: 500 });+ expect(result.structuredContent).toBeDefined();+ expect(await readFile(log, "utf8")).not.toBe("");+ } finally { await backend.close(); await rm(cwd, { recursive: true, force: true }); }+});test("the qualified pin rejects an older peer before native dispatch", async () => {await mkdir(".tmp/native-zoom", {recursive:true});const cwd = await mkdtemp(path.resolve(".tmp/native-zoom/version-")); const log = path.join(cwd,"calls.jsonl");diff --git a/test/fixtures/detail-driver.mjs b/test/fixtures/detail-driver.mjsindex 7511a81..dc97b2d 100644--- a/test/fixtures/detail-driver.mjs+++ b/test/fixtures/detail-driver.mjs@@ -12,7 +12,7 @@ const overview = await sharp(raw).resize(500, 400).png().toBuffer();const jpeg = await sharp(raw).extract({ left: 200, top: 160, width: 200, height: 160 }).jpeg().toBuffer();const windows = [];const server = new Server({ name: "cua-driver", version: process.argv[3] ?? "0.33.2" }, { capabilities: { tools: {} } });-server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [] }));+server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: process.argv[4] === "advertise" ? [{ name: "get_desktop_state", inputSchema: { type: "object" } }] : [] }));server.setRequestHandler(CallToolRequestSchema, async ({ params: { name, arguments: args = {} } }) => {const cursor = agentCursor(name, args); if (cursor) return cursor;appendFileSync(log, JSON.stringify({ name, arguments: args }) + "\n");diff --git a/test/remote-browser.test.ts b/test/remote-browser.test.tsnew file mode 100644index 0000000..099891a--- /dev/null+++ b/test/remote-browser.test.ts@@ -0,0 +1,99 @@+import { mkdir, mkdtemp, readFile, readdir, rm, symlink, writeFile } from "node:fs/promises";+import path from "node:path";+import { afterEach, expect, test } from "vitest";+import { localRunner } from "../src/runner.ts";+import { prepareWorkerPackage } from "../src/remote-browser.ts";++const temporary: string[] = [];+afterEach(async () => { await Promise.all(temporary.splice(0).map(dir => rm(dir, { recursive: true, force: true }))); });+async function fixture() {+ await mkdir(".tmp", { recursive: true });+ const root = await mkdtemp(path.resolve(".tmp/remote-browser-")); temporary.push(root);+ const source = path.join(root, "package"), home = path.join(root, "remote"), playwright = path.join(root, "playwright");+ await mkdir(path.join(source, "src"), { recursive: true }); await mkdir(path.join(playwright, "lib"), { recursive: true }); await mkdir(home);+ await writeFile(path.join(source, "src", "web-worker.ts"), "export const version = 1;\n");+ await writeFile(path.join(source, "package.json"), '{"type":"module"}');+ await writeFile(path.join(playwright, "package.json"), '{"name":"playwright-core"}');+ await writeFile(path.join(playwright, "lib", "code.js"), "export const x = 1;\n");+ return { source, home, playwright, runner: localRunner() };+}++test("a supplied remote Node is reused without trying to install another one", async () => {+ const { prepareRemoteBrowser } = await import("../src/remote-browser.ts");+ const f = await fixture();+ const prepareNode = async () => { throw new Error("network unavailable"); };+ const prepareWorker = async () => "/managed/worker";+ expect(await prepareRemoteBrowser(f.runner, undefined, { node: "/trusted/node.exe" }, { node: prepareNode, worker: prepareWorker }))+ .toEqual({ node: "/trusted/node.exe", package: "/managed/worker" });+});+test("an uncertain worker failure takes precedence over an ordinary Node failure", async () => {+ const { prepareRemoteBrowser } = await import("../src/remote-browser.ts");+ const { RemotePreparationUncertain } = await import("../src/remote-provision-error.ts");+ const f = await fixture();+ const uncertain = new RemotePreparationUncertain("lost response");+ await expect(prepareRemoteBrowser(f.runner, undefined, {}, {+ node: async () => { throw new Error("cancelled"); }, worker: async () => { throw uncertain; },+ })).rejects.toBe(uncertain);+});++test("a redirected worker cache parent is refused before creating files outside the home", async () => {+ const f = await fixture();+ const parent = path.join(f.home, ".local/share/pi-computer-use");+ const outside = path.join(path.dirname(f.home), "outside");+ await mkdir(path.dirname(parent), { recursive: true });+ await mkdir(outside);+ await symlink(outside, parent);+ await expect(prepareWorkerPackage(f.runner, f.source, f.playwright, f.home)).rejects.toThrow();+ expect(await readdir(outside)).toEqual([]);+});+test("remote worker is copied once, verified on reuse and refreshed to a different immutable directory after an update", async () => {+ const f = await fixture();+ const first = await prepareWorkerPackage(f.runner, f.source, f.playwright, f.home);+ const same = await prepareWorkerPackage(f.runner, f.source, f.playwright, f.home);+ expect(same).toBe(first);+ expect(await readFile(path.join(first, "node_modules/playwright-core/lib/code.js"), "utf8")).toBe("export const x = 1;\n");+ await writeFile(path.join(f.source, "src/web-worker.ts"), "export const version = 2;\n");+ const next = await prepareWorkerPackage(f.runner, f.source, f.playwright, f.home);+ expect(next).not.toBe(first);+ expect(await readFile(path.join(first, "src/web-worker.ts"), "utf8")).toBe("export const version = 1;\n");+ expect(await readFile(path.join(next, "src/web-worker.ts"), "utf8")).toBe("export const version = 2;\n");+});++test("changed remote worker files are never reused or overwritten", async () => {+ const f = await fixture();+ const worker = await prepareWorkerPackage(f.runner, f.source, f.playwright, f.home);+ const file = path.join(worker, "node_modules/playwright-core/lib/code.js");+ await writeFile(file, "changed");+ await expect(prepareWorkerPackage(f.runner, f.source, f.playwright, f.home)).rejects.toThrow();+ expect(await readFile(file, "utf8")).toBe("changed");+});++test("concurrent first use shares one complete worker; cancellation does not publish partial files", async () => {+ const f = await fixture();+ await expect(prepareWorkerPackage(f.runner, f.source, f.playwright, f.home, AbortSignal.abort())).rejects.toThrow();+ const [a, b] = await Promise.all([prepareWorkerPackage(f.runner, f.source, f.playwright, f.home), prepareWorkerPackage(f.runner, f.source, f.playwright, f.home)]);+ expect(a).toBe(b);+ expect(await readFile(path.join(a, "src/web-worker.ts"), "utf8")).toBe("export const version = 1;\n");+ expect((await readdir(path.dirname(a))).filter(name => name.startsWith(".staging-"))).toEqual([]);+});++test("cancellation during transfer leaves no published worker or staging directory", async () => {+ const f = await fixture();+ const abort = new AbortController();+ let started!: () => void;+ const dispatched = new Promise<void>(resolve => { started = resolve; });+ const runner = { ...f.runner, spawn: () => { const child = f.runner.spawn("bash", ["-c", "cat >/dev/null"]); started(); return child; } };+ const pending = prepareWorkerPackage(runner, f.source, f.playwright, f.home, abort.signal);+ await dispatched; abort.abort();+ await expect(pending).rejects.toThrow();+ expect(await readdir(path.join(f.home, ".local/share/pi-computer-use/workers"))).toEqual([]);+});+test("a link in the worker source or in an existing remote copy is refused", async () => {+ const f = await fixture();+ await symlink("web-worker.ts", path.join(f.source, "src", "link.ts"));+ await expect(prepareWorkerPackage(f.runner, f.source, f.playwright, f.home)).rejects.toThrow();+ await rm(path.join(f.source, "src", "link.ts"));+ const worker = await prepareWorkerPackage(f.runner, f.source, f.playwright, f.home);+ await symlink("web-worker.ts", path.join(worker, "src", "link.ts"));+ await expect(prepareWorkerPackage(f.runner, f.source, f.playwright, f.home)).rejects.toThrow();+});diff --git a/test/remote-machine.test.ts b/test/remote-machine.test.tsindex 4d7f8e3..e33e962 100644--- a/test/remote-machine.test.ts+++ b/test/remote-machine.test.ts@@ -1,6 +1,6 @@import { execFileSync } from "node:child_process";import sharp from "sharp";-import { mkdir, mkdtemp, writeFile } from "node:fs/promises";+import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";import { tmpdir } from "node:os";import path from "node:path";import { expect, test, vi } from "vitest";@@ -24,6 +24,59 @@ test("a remote command keeps every argument and variable exactly, whatever the rexpect(() => remoteCommand("/usr/bin/env", [], { "BAD-NAME": "x" })).toThrow(/Invalid environment variable/);});+test("remote sandbox selects its machine without resolving the local runtime", async () => {+ const dir = await mkdtemp(path.join(tmpdir(), "pi-remote-sandbox-"));+ const config = await import("../src/config.ts");+ const { sandboxFactory } = await import("../src/machine.ts");+ const { WindowsSandbox } = await import("../src/sandbox.ts");+ const failure = new Error("sandbox reached");+ const local = vi.spyOn(config, "loadComputerConfig").mockRejectedValue(new Error("local runtime unavailable"));+ const open = vi.spyOn(WindowsSandbox, "open").mockRejectedValue(failure);+ try {+ await mkdir(path.join(dir, ".pi"));+ await writeFile(path.join(dir, ".pi/computer-use.json"), JSON.stringify({ machines: { lab: { ssh: "lab-wsl", command: "/mnt/c/driver.exe" } } }));+ const factory = sandboxFactory({ settings: () => ({ kernel: "lanczos3", maxLongEdge: 1280, scale: 1, version: 0, route: "cua_native" }) });+ await expect(factory(dir, { action: "open_sandbox" }, undefined, "lab")).rejects.toBe(failure);+ expect(local).not.toHaveBeenCalled();+ expect(open).toHaveBeenCalledOnce();+ } finally { local.mockRestore(); open.mockRestore(); await rm(dir, { recursive: true, force: true }); }+});+test("browserOverride preserves a single legacy browser path", async () => {+ const dir = await mkdtemp(path.join(tmpdir(), "pi-machines-partial-"));+ try {+ await mkdir(path.join(dir, ".pi"));+ const node = "/mnt/c/Users/test/AppData/Local/Programs/PiComputerUse/node-v22.22.2-win-x64/node.exe";+ const worker = "/home/test/.local/share/pi-computer-use/package";+ await writeFile(path.join(dir, ".pi/computer-use.json"), JSON.stringify({ command: "/x/cua-driver.exe", machines: {+ nodeonly: { ssh: "node-alias", node, browserOverride: true },+ workeronly: { ssh: "worker-alias", package: worker, browserOverride: true },+ } }));+ const machines = (await loadComputerConfig(dir)).machines!;+ expect(machines.nodeonly.node).toBe(node);+ expect(machines.workeronly.package).toBe(worker);+ } finally { await rm(dir, { recursive: true, force: true }); }+});+test("a remote machine needs only its trusted SSH alias", async () => {+ const dir = await mkdtemp(path.join(tmpdir(), "pi-machines-auto-"));+ try {+ await mkdir(path.join(dir, ".pi"));+ await writeFile(path.join(dir, ".pi/computer-use.json"), JSON.stringify({ command: "/x/cua-driver.exe", machines: { lab: { ssh: "lab-wsl" } } }));+ expect((await loadComputerConfig(dir)).machines?.lab).toEqual({ ssh: "lab-wsl" });+ } finally { await rm(dir, { recursive: true, force: true }); }+});+test("legacy generated remote paths follow the package, but explicit overrides remain available", async () => {+ const dir = await mkdtemp(path.join(tmpdir(), "pi-machines-legacy-"));+ try {+ await mkdir(path.join(dir, ".pi"));+ const legacy = { ssh: "lab-wsl", command: "/mnt/c/Users/u/AppData/Local/Programs/PiComputerUse/cua-driver-0.37.0-33c4b82b/runtime/cua-driver.exe", runtime: "windows-desktop",+ node: "/mnt/c/Users/u/AppData/Local/Programs/PiComputerUse/node-v22.22.2-win-x64/node.exe", package: "/home/u/.local/share/pi-computer-use/package" };+ const write = async (machine: object) => writeFile(path.join(dir, ".pi/computer-use.json"), JSON.stringify({ command: "/x/cua-driver.exe", machines: { lab: machine } }));+ await write(legacy);+ expect((await loadComputerConfig(dir)).machines?.lab).toEqual({ ssh: "lab-wsl" });+ await write({ ...legacy, driverOverride: true, browserOverride: true });+ expect((await loadComputerConfig(dir)).machines?.lab).toEqual({ ...legacy, driverOverride: true, browserOverride: true });+ } finally { await rm(dir, { recursive: true, force: true }); }+});test("machines come only from validated configuration", async () => {const dir = await mkdtemp(path.join(tmpdir(), "pi-machines-"));await mkdir(path.join(dir, ".pi"));diff --git a/test/remote-runtime.test.ts b/test/remote-runtime.test.tsnew file mode 100644index 0000000..5c3fb6a--- /dev/null+++ b/test/remote-runtime.test.ts@@ -0,0 +1,91 @@+import { createHash } from "node:crypto";+import { mkdtemp, mkdir, readFile, readdir, rm, symlink, writeFile } from "node:fs/promises";+import { tmpdir } from "node:os";+import path from "node:path";+import { afterEach, expect, test } from "vitest";+import { localRunner, type CommandRunner } from "../src/runner.ts";+import type { BundledRuntime } from "../src/native-runtime.ts";+import { prepareRemoteRuntime } from "../src/remote-runtime.ts";++const files = ["cua-driver.exe", "cua-driver-uia.exe", "cua-cursor-theme.exe", "LICENSE.md", "THIRD_PARTY_NOTICES.md"];+const dirs: string[] = [];+afterEach(async () => { await Promise.all(dirs.splice(0).map(dir => rm(dir, { recursive: true, force: true }))); });+async function fixture() {+ const dir = await mkdtemp(path.join(tmpdir(), "pi-remote-runtime-test-")); dirs.push(dir);+ const local = path.join(dir, "local"), appData = path.join(dir, "remote user", "Local AppData");+ await mkdir(path.join(local, "runtime"), { recursive: true }); await mkdir(appData, { recursive: true });+ const hashes: Record<string, string> = {};+ for (const name of files) { const bytes = Buffer.from(`content for ${name}`); await writeFile(path.join(local, "runtime", name), bytes); hashes[name] = createHash("sha256").update(bytes).digest("hex"); }+ const runtime: BundledRuntime = { root: local, command: path.join(local, "runtime", "cua-driver.exe"), target: "win32-x64", source: "a".repeat(40), version: "1.0.0", driverVersion: "1.0.0", files: hashes };+ return { dir, runtime, runner: localRunner(), appData, deps: { localRuntime: async () => runtime, remoteLocalAppData: async (_runner: CommandRunner) => appData } };+}++test("remote runtime is installed once and every required file is verified before reuse", async () => {+ const f = await fixture();+ const command = await prepareRemoteRuntime(f.runner, undefined, f.deps);+ expect(await readFile(command, "utf8")).toBe("content for cua-driver.exe");+ expect(await prepareRemoteRuntime(f.runner, undefined, f.deps)).toBe(command);+ const extra = path.join(path.dirname(command), "LICENSE.md");+ await writeFile(extra, "modified");+ await expect(prepareRemoteRuntime(f.runner, undefined, f.deps)).rejects.toThrow();+ expect(await readFile(extra, "utf8")).toBe("modified");+});++test("concurrent installations publish one complete runtime without deleting other data", async () => {+ const f = await fixture();+ const other = path.join(f.appData, "unrelated"); await writeFile(other, "keep");+ const [first, second] = await Promise.all([prepareRemoteRuntime(f.runner, undefined, f.deps), prepareRemoteRuntime(f.runner, undefined, f.deps)]);+ expect(first).toBe(second);+ expect((await readdir(path.dirname(first))).sort()).toEqual([...files].sort());+ expect(await readFile(other, "utf8")).toBe("keep");+});++test("a symlink substituted for a published companion is refused and left untouched", async () => {+ const f = await fixture();+ const command = await prepareRemoteRuntime(f.runner, undefined, f.deps);+ const companion = path.join(path.dirname(command), "LICENSE.md");+ const outside = path.join(f.dir, "outside"); await writeFile(outside, "content for LICENSE.md");+ await rm(companion); await symlink(outside, companion);+ await expect(prepareRemoteRuntime(f.runner, undefined, f.deps)).rejects.toThrow();+ expect(await readFile(outside, "utf8")).toBe("content for LICENSE.md");+});+test("cancellation waits for a dispatched transfer before returning", async () => {+ const f = await fixture(); const controller = new AbortController();+ let started!: () => void, release!: () => void;+ const sent = new Promise<void>(resolve => { started = resolve; });+ const waiting = new Promise<void>(resolve => { release = resolve; });+ const runner: CommandRunner = { ...f.runner, async run(file, args, options) {+ if (file === "dd") {+ started();+ if (options?.signal) await Promise.race([waiting, new Promise<never>((_, reject) => options.signal!.addEventListener("abort", () => reject(new Error("transport cancelled")), { once: true }))]);+ else await waiting;+ }+ return f.runner.run(file, args, options);+ } };+ let finished = false;+ const pending = prepareRemoteRuntime(runner, controller.signal, f.deps).then(() => null, error => error).finally(() => { finished = true; });+ await sent; controller.abort(); await new Promise(resolve => setTimeout(resolve, 20));+ expect(finished).toBe(false);+ release(); expect(await pending).toBeInstanceOf(Error);+ const command = await prepareRemoteRuntime(f.runner, undefined, f.deps);+ expect((await readdir(path.dirname(command))).sort()).toEqual([...files].sort());+});+test("a lost transfer response reports uncertain remote effects", async () => {+ const f = await fixture();+ const runner: CommandRunner = { ...f.runner, async run(file, args, options) {+ if (file === "dd") throw new Error("connection lost");+ return f.runner.run(file, args, options);+ } };+ const { RemotePreparationUncertain } = await import("../src/remote-provision-error.ts");+ await expect(prepareRemoteRuntime(runner, undefined, f.deps)).rejects.toBeInstanceOf(RemotePreparationUncertain);+});+test("an interrupted transfer leaves no partial published runtime", async () => {+ const f = await fixture(); const real = f.runner; let writes = 0;+ const runner: CommandRunner = { ...real, async run(file, args, options) {+ if (file === "dd" && ++writes === 2) throw new Error("transfer interrupted");+ return real.run(file, args, options);+ } };+ await expect(prepareRemoteRuntime(runner, undefined, f.deps)).rejects.toThrow();+ const command = await prepareRemoteRuntime(f.runner, undefined, f.deps);+ expect((await readdir(path.dirname(command))).sort()).toEqual([...files].sort());+});diff --git a/test/setup-command.test.ts b/test/setup-command.test.tsindex 79f40d3..1413a66 100644--- a/test/setup-command.test.ts+++ b/test/setup-command.test.ts@@ -84,20 +84,44 @@ test("a part installs through PowerShell on the right Windows: interop from WSL,expect(viaSsh.ssh).toHaveBeenCalledWith("lab-wsl");});-test("setup refuses before any command for an unknown machine, another OS or a machine without its browser worker", async () => {+test("setup refuses before any command for an unknown machine or unsupported OS", async () => {const cwd = await project({ machines: { lab: { ssh: "lab-wsl", command: "/mnt/c/rt/cua-driver.exe" } } });const { runner, calls } = fakeRunner();const viaSsh = deps("linux", runner);await expect(runSetup({ part: "mxc", machine: "nowhere" }, cwd, { deps: viaSsh })).rejects.toThrow(SetupError);expect(viaSsh.ssh).not.toHaveBeenCalled();await expect(runSetup({ part: "mxc" }, cwd, { deps: deps("linux", runner, false) })).rejects.toThrow(/Pi on Windows or in WSL/);- await expect(runSetup({ part: "firefox", machine: "lab" }, cwd, { deps: deps("linux", runner) })).rejects.toThrow(/no browser worker yet/);await expect(runSetup({ part: "machine", ssh: "lab-wsl", name: "local" }, cwd, { deps: deps("linux", runner) })).rejects.toThrow(/not local/);// Pi on Windows runs the Playwright worker with its own Node.expect(await runSetup({ part: "browser" }, cwd, { deps: deps("win32", runner) })).toMatch(/Pi's own Node\. Nothing to install/);expect(calls).toEqual([]);});+test("explicit machine setup uses the same immutable provisioners", async () => {+ const cwd = await project();+ const runtime = await import("../src/remote-runtime.ts");+ const browser = await import("../src/remote-browser.ts");+ const prepareDriver = vi.spyOn(runtime, "prepareRemoteRuntime").mockResolvedValueOnce("/managed/driver.exe");+ const prepareBrowser = vi.spyOn(browser, "prepareRemoteBrowser").mockResolvedValueOnce({ node: "/managed/node.exe", package: "/managed/worker" });+ const { runner, calls } = fakeRunner();+ try {+ await runSetup({ part: "machine", ssh: "lab-wsl", name: "lab" }, cwd, { deps: deps("linux", runner) });+ expect(prepareDriver).toHaveBeenCalledOnce(); expect(prepareBrowser).toHaveBeenCalledOnce();+ expect(calls.some(call => call.file === "rm")).toBe(false);+ } finally { prepareDriver.mockRestore(); prepareBrowser.mockRestore(); }+});+test("remote Firefox setup prepares a missing browser worker automatically", async () => {+ const cwd = await project({ machines: { lab: { ssh: "lab-wsl" } } });+ const provision = await import("../src/remote-browser.ts");+ const prepare = vi.spyOn(provision, "prepareRemoteBrowser").mockResolvedValueOnce({ node: "/remote/node.exe", package: "/remote/package" });+ const calls: { file: string; args: readonly string[] }[] = [];+ const runner: CommandRunner = { spawn: () => { throw new Error("unexpected spawn"); }, run: async (file, args) => { calls.push({ file, args }); return file === "wslpath" ? "C:\\package\\node_modules\\playwright-core\\cli.js" : ""; } };+ try {+ await runSetup({ part: "firefox", machine: "lab" }, cwd, { deps: deps("linux", runner) });+ expect(prepare).toHaveBeenCalledOnce();+ expect(calls.some(call => call.file === "/remote/node.exe" && call.args.includes("firefox"))).toBe(true);+ } finally { prepare.mockRestore(); }+});test("/computer-setup shows the usage, reports progress in the status line and the result or failure as a notification", async () => {const commands = new Map<string, { getArgumentCompletions: (prefix: string) => unknown; handler: (args: string, ctx: unknown) => Promise<void> }>();const run = vi.fn(async (_request: unknown, _cwd: string, options?: { progress?: (step: string) => void }) => { options?.progress?.("downloading"); return "Installed."; });@@ -118,6 +142,15 @@ test("/computer-setup shows the usage, reports progress in the status line and texpect(ui.setStatus).toHaveBeenLastCalledWith("computer-setup", undefined);});+test("a missing Windows Node is installed automatically before browser use", async () => {+ const { ensureWindowsNode } = await import("../src/windows-node.ts");+ const node = await import("../src/remote-browser.ts");+ const prepare = vi.spyOn(node, "prepareWindowsNode").mockResolvedValueOnce("/managed/node.exe");+ try {+ expect(await ensureWindowsNode("socket")).toBe("/managed/node.exe");+ expect(prepare).toHaveBeenCalledOnce();+ } finally { prepare.mockRestore(); }+});test("browsers use the portable Windows Node from setup first, an installed Node next, and otherwise name the setup step", async () => {const fake = (present: string[]) => ({ localAppData: async () => "/mnt/c/Users/u/AppData/Local", exists: async (file: string) => present.includes(file) });const portable = "/mnt/c/Users/u/AppData/Local/Programs/PiComputerUse/node-v22.22.2-win-x64/node.exe";