fix: make session resume atomic across restarts

This commit is contained in:
User
2026-07-15 00:42:35 +02:00
parent 2b4797f133
commit 08b1f4909e
12 changed files with 1082 additions and 107 deletions
+30
View File
@@ -84,6 +84,36 @@ function recordingChild() {
return ch;
}
test("createFor kills a spawned child when post-spawn initialization throws", () => {
const child = recordingChild();
child.kill = vi.fn();
child.stdout = {
on: () => { throw new Error("READER_INIT_SENTINEL"); },
};
const mgr = new PiProcessManager(loadConfig({}), { spawnFn: () => child as any });
expect(() => mgr.createFor("broken-init", {})).toThrow("READER_INIT_SENTINEL");
expect(child.kill).toHaveBeenCalledOnce();
expect(mgr.get("broken-init")).toBeUndefined();
expect(mgr.count()).toBe(0);
});
test("createFor kills a spawned child when spawn boundary initialization throws", () => {
const child = recordingChild();
child.kill = vi.fn();
child.stderr = {
on: () => { throw new Error("STDERR_INIT_SENTINEL"); },
};
const mgr = new PiProcessManager(loadConfig({}), { spawnFn: () => child as any });
expect(() => mgr.createFor("broken-spawn-init", {})).toThrow("STDERR_INIT_SENTINEL");
expect(child.kill).toHaveBeenCalledOnce();
expect(mgr.get("broken-spawn-init")).toBeUndefined();
expect(mgr.count()).toBe(0);
});
test("un exit INATTESO del child notifica il client (info error + agent_end)", async () => {
const cfg = loadConfig({});
const child = recordingChild();