fix: release Pi snapshots on failed initialization

This commit is contained in:
2026-08-05 16:59:49 +02:00
parent 840db9bd4f
commit 7efaec434f
2 changed files with 25 additions and 4 deletions
+9 -1
View File
@@ -306,10 +306,18 @@ test("createFor kills a spawned child when post-spawn initialization throws", ()
child.stdout = {
on: () => { throw new Error("READER_INIT_SENTINEL"); },
};
const mgr = new PiProcessManager(loadConfig({}), { spawnFn: () => child as any });
let snapshotDir: string | undefined;
const mgr = new PiProcessManager(loadConfig({}), {
spawnFn: (_command, _args, options) => {
snapshotDir = options.env.PI_CODING_AGENT_DIR;
return child as any;
},
});
expect(() => mgr.createFor("broken-init", {})).toThrow("READER_INIT_SENTINEL");
expect(snapshotDir).toBeTruthy();
expect(existsSync(snapshotDir!)).toBe(false);
expect(child.kill).toHaveBeenCalledOnce();
expect(mgr.get("broken-init")).toBeUndefined();
expect(mgr.count()).toBe(0);