1243 unmodified lines
Expand all
expect(fakeClient.closeCount).toBe(1);
expect(fakeClient.reconnectCount).toBe(1);
});
it("keeps reconnecting when the supervisor shutdown follows an update session notice", async () => {
const fakeClient = new FakeDaemonClient();
fakeClient.updateRestartSessions = [
{
id: "active-restored",
activeSessionId: "active-restored",
sessionId: "session-current",
sessionFile: "/tmp/session-current.jsonl",
},
];
fakeClient.attachResultFactory = (command) =>
createAttachResult(command.activeSessionId, command.clientId, command.capabilities, 1, {
state: createConnectionState(command.activeSessionId, "session-current"),
});
const connection = new DaemonAgentConnection(asDaemonClient(fakeClient), "active-original");
const closedEvents: AgentConnectionEvent[] = [];
const restored = new Promise<AgentConnectionEvent>((resolve) => {
connection.subscribe((event) => {
if (event.type === "closed") closedEvents.push(event);
if (event.type === "session_resynced") resolve(event);
});
});
await connection.attach();
fakeClient.emitMessage({
type: "session_closed",
activeSessionId: "active-original",
reason: "update",
});
// The coordinator currently stops the prepared supervisor with the generic
// shutdown command after workers have already published their update notice.
fakeClient.emitClose(new DaemonSocketClosedError("/tmp/prime-agent.sock", "shutdown"));
await expect(restored).resolves.toMatchObject({
type: "session_resynced",
snapshot: { state: { activeSessionId: "active-restored", sessionId: "session-current" } },
});
expect(fakeClient.reconnectCount).toBe(1);
expect(closedEvents).toEqual([]);
});
it("does not reconnect after an explicit shutdown session close", async () => {
const fakeClient = new FakeDaemonClient();
const connection = new DaemonAgentConnection(asDaemonClient(fakeClient), "active-original");
const closedEvents: AgentConnectionEvent[] = [];
1765 unmodified lines
Expand all