fix: serialize session lifecycle transitions

This commit is contained in:
User
2026-07-15 01:37:42 +02:00
parent 08b1f4909e
commit 6747f6f8a0
10 changed files with 1402 additions and 101 deletions
+21
View File
@@ -66,6 +66,27 @@ test("l'exit del VECCHIO child non elimina il nuovo runtime (exit identity-check
mgr.teardown("respawn-id");
});
test("identity-checked teardown cannot kill a replacement runtime", () => {
const cfg = loadConfig({ THT_HARNESS_DIR: "../harness" });
const firstChild = recordingChild();
const secondChild = recordingChild();
firstChild.kill = vi.fn();
secondChild.kill = vi.fn();
const children = [firstChild, secondChild];
const mgr = new PiProcessManager(cfg, { spawnFn: () => children.shift() as any });
const first = mgr.createFor("replace-id", {});
mgr.teardown("replace-id");
const second = mgr.createFor("replace-id", {});
expect(mgr.teardownIfCurrent("replace-id", first)).toBe(false);
expect(mgr.get("replace-id")).toBe(second);
expect(secondChild.kill).not.toHaveBeenCalled();
expect(mgr.teardownIfCurrent("replace-id", second)).toBe(true);
expect(mgr.get("replace-id")).toBeUndefined();
expect(secondChild.kill).toHaveBeenCalledOnce();
});
test("oltre maxPiProcesses solleva errore", async () => {
const cfg = { ...loadConfig({}), maxPiProcesses: 1 };
const mgr = new PiProcessManager(cfg, { spawnFn: () => spawn("node", [FAKE, SCRIPT]) as any });