Skip to content

Computer use for the Pi coding agent — Windows apps, browsers and desktops through native UI trees, screenshots and real input.

Tests: a stale WSL_INTEROP gives way to a live socket (LPT-967)

alexshpunt-clanker[bot]4eb8b1190d09
diff --git a/test/config-bundled.test.ts b/test/config-bundled.test.ts
index 766ad91..864b31c 100644
--- a/test/config-bundled.test.ts
+++ b/test/config-bundled.test.ts
@@ -3,6 +3,9 @@ import path from "node:path";
import { afterEach, expect, test, vi } from "vitest";
import type { BundledRuntime } from "../src/native-runtime.ts";
+// These tests read configuration only; the live WSL interop socket of the machine running them stays out.
+vi.mock("../src/wsl-interop.ts", () => ({ liveInterop: vi.fn(async () => undefined) }));
+
// Selecting the shipped runtime needs Windows or WSL and its files; stand in for that lookup only.
const runtime: BundledRuntime = { target: "win32-x64", root: "/package/native-runtime/win32-x64", command: "/package/native-runtime/win32-x64/runtime/cua-driver.exe",
source: "a".repeat(40), version: "0.37.0", driverVersion: "0.37.0", files: {} };
diff --git a/test/config.test.ts b/test/config.test.ts
index ed16748..36d46f2 100644
--- a/test/config.test.ts
+++ b/test/config.test.ts
@@ -3,6 +3,9 @@ import path from "node:path";
import { afterEach, expect, test, vi } from "vitest";
import { loadComputerConfig } from "../src/config.ts";
+// These tests read configuration only; the live WSL interop socket of the machine running them stays out.
+vi.mock("../src/wsl-interop.ts", () => ({ liveInterop: vi.fn(async () => undefined) }));
+
const owned: string[] = [];
afterEach(async () => {
vi.unstubAllEnvs();
@@ -80,4 +83,19 @@ test("coordinate scroll is an explicit trusted artifact profile, never an implic
await writeFile(path.join(cwd, ".pi/computer-use.json"), JSON.stringify(invalid));
await expect(loadComputerConfig(cwd)).rejects.toThrow("Invalid computer-use configuration");
}
-});
\ No newline at end of file
+});
+
+// LPT-967: without a configured socket, the live one found on the machine is used; a configured socket stays as given.
+test("an unconfigured interop socket is the live one; a configured one is kept", async () => {
+ const { liveInterop } = await import("../src/wsl-interop.ts");
+ vi.mocked(liveInterop).mockResolvedValue("/run/WSL/1_interop");
+ const bare = await mkdtemp(path.join(".tmp", "config-interop-"));
+ owned.push(bare);
+ await mkdir(path.join(bare, ".pi"), { recursive: true });
+ await writeFile(path.join(bare, ".pi/computer-use.json"), JSON.stringify({ command: "/driver.exe" }));
+ expect((await loadComputerConfig(bare)).interop).toBe("/run/WSL/1_interop");
+ await writeFile(path.join(bare, ".pi/computer-use.json"), JSON.stringify({ command: "/driver.exe", interop: "/run/WSL/7_interop" }));
+ expect((await loadComputerConfig(bare)).interop).toBe("/run/WSL/7_interop");
+ vi.mocked(liveInterop).mockResolvedValue(undefined);
+});
+
diff --git a/test/wsl-interop.test.ts b/test/wsl-interop.test.ts
new file mode 100644
index 0000000..1135c05
--- /dev/null
+++ b/test/wsl-interop.test.ts
@@ -0,0 +1,39 @@
+import { mkdtemp, rm, writeFile } from "node:fs/promises";
+import { createServer, type Server } from "node:net";
+import { tmpdir } from "node:os";
+import path from "node:path";
+import { afterEach, expect, test } from "vitest";
+import { liveInterop } from "../src/wsl-interop.ts";
+
+// LPT-967: a process started from a long-lived terminal can carry WSL_INTEROP of a WSL session that has closed; its
+// socket is gone and every Windows command fails. A live socket of the same WSL is used instead.
+const servers: Server[] = [];
+let dir = "";
+afterEach(async () => {
+ await Promise.all(servers.splice(0).map(server => new Promise(resolve => server.close(resolve))));
+ if (dir) await rm(dir, { recursive: true, force: true });
+});
+async function socket(name: string) {
+ const file = path.join(dir, name);
+ const server = createServer();
+ await new Promise<void>(resolve => server.listen(file, resolve));
+ servers.push(server);
+ return file;
+}
+
+test("a live WSL_INTEROP is kept", async () => {
+ dir = await mkdtemp(path.join(tmpdir(), "interop-"));
+ const own = await socket("401_interop");
+ await socket("1_interop");
+ expect(await liveInterop(own, dir)).toBe(own);
+});
+
+test("a dead WSL_INTEROP gives way to the lowest live socket, and nothing live gives none", async () => {
+ dir = await mkdtemp(path.join(tmpdir(), "interop-"));
+ const first = await socket("1_interop");
+ await socket("17_interop");
+ await writeFile(path.join(dir, "2_interop"), "not a socket");
+ expect(await liveInterop(path.join(dir, "401_interop"), dir)).toBe(first);
+ expect(await liveInterop(undefined, dir)).toBe(first);
+ expect(await liveInterop(path.join(dir, "401_interop"), path.join(dir, "missing"))).toBeUndefined();
+});