From f36d5aefa82ad4d84026e5939f70a2251bd87280 Mon Sep 17 00:00:00 2001 From: mptyl Date: Wed, 5 Aug 2026 17:02:01 +0200 Subject: [PATCH] test: cover concurrent registry and close cleanup --- backend/test/pi-process-manager.test.ts | 19 +++++++++++++++++++ backend/test/workspace-registry.test.ts | 19 +++++++++++-------- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/backend/test/pi-process-manager.test.ts b/backend/test/pi-process-manager.test.ts index 4227d231..47496042 100644 --- a/backend/test/pi-process-manager.test.ts +++ b/backend/test/pi-process-manager.test.ts @@ -189,6 +189,25 @@ test("Pi receives the leased workspace runtime config and releases it on direct expect(release).toHaveBeenCalledOnce(); }); +test("a close-only child event releases its temporary Pi agent snapshot", () => { + const child = recordingChild(); + let snapshotDir: string | undefined; + const mgr = new PiProcessManager(loadConfig({}), { + spawnFn: (_command, _args, options) => { + snapshotDir = options.env.PI_CODING_AGENT_DIR; + return child as any; + }, + }); + + mgr.createFor("close-only-snapshot", {}); + expect(snapshotDir).toBeTruthy(); + expect(existsSync(snapshotDir!)).toBe(true); + + child.emit("close", 0); + expect(existsSync(snapshotDir!)).toBe(false); + mgr.teardown("close-only-snapshot"); +}); + test.each([ ["new", "auth.json", '{"deepseek":{"key":"!runtime-auth-command runtime-secret /private/runtime-auth"}}\n'], ["new", "models.json", '{"providers":{"local-qwen":{"headers":["!runtime-model-command runtime-secret /private/runtime-model"]}}}\n'], diff --git a/backend/test/workspace-registry.test.ts b/backend/test/workspace-registry.test.ts index ad427f9d..64624425 100644 --- a/backend/test/workspace-registry.test.ts +++ b/backend/test/workspace-registry.test.ts @@ -254,18 +254,21 @@ test("bootstraps a checkout and activates a validated immutable snapshot", async }); }); -test("first list lazily bootstraps a clean registry", async () => { +test("concurrent first lists lazily bootstrap a clean registry once safely", async () => { const remote = await fixture(); const root = join(remote.root, "registry"); const registry = new WorkspaceRegistry(config(root, remote.remote)); - await expect(registry.list()).resolves.toEqual([ - expect.objectContaining({ - id: "psd-clinical", - commit: remote.initialCommit, - state: "operational", - }), - ]); + const [first, second] = await Promise.all([registry.list(), registry.list()]); + for (const revisions of [first, second]) { + expect(revisions).toEqual([ + expect.objectContaining({ + id: "psd-clinical", + commit: remote.initialCommit, + state: "operational", + }), + ]); + } expect(existsSync(join(root, "state", "active.json"))).toBe(true); });