























@@ -66,6 +66,22 @@ vi.mock("./gateway.js", () => ({
6666readGatewayCallOptions: vi.fn(() => ({})),
6767}));
686869+function requireRestartSentinelPayload(): RestartSentinelPayload {
70+const payload = writeRestartSentinelMock.mock.calls.at(-1)?.[0];
71+if (!payload) {
72+throw new Error("expected restart sentinel payload");
73+}
74+return payload;
75+}
76+77+function requireScheduledRestartArgs(): NonNullable<ScheduleGatewayRestartArgs> {
78+const args = scheduleGatewaySigusr1RestartMock.mock.calls.at(-1)?.[0];
79+if (!args) {
80+throw new Error("expected scheduled restart args");
81+}
82+return args;
83+}
84+6985describe("gateway tool restart continuation", () => {
7086beforeEach(() => {
7187isRestartEnabledMock.mockReset();
@@ -125,32 +141,26 @@ describe("gateway tool restart continuation", () => {
125141const scheduledArgs = scheduleGatewaySigusr1RestartMock.mock.calls.at(-1)?.[0];
126142await scheduledArgs?.emitHooks?.beforeEmit?.();
127143128-expect(writeRestartSentinelMock).toHaveBeenCalledWith(
129-expect.objectContaining({
130-kind: "restart",
131-status: "ok",
132-sessionKey: "agent:main:main",
133-deliveryContext: {
134-channel: "slack",
135-to: "slack:C123",
136-accountId: "workspace-1",
137-},
138-threadId: "thread-42",
139-message: "Gateway restarting now",
140-continuation: {
141-kind: "agentTurn",
142-message: "Reply with exactly: Yay! I did it!",
143-},
144-}),
145-);
146-expect(scheduleGatewaySigusr1RestartMock).toHaveBeenCalledWith({
147-delayMs: 250,
148-reason: "continue after reboot",
149-emitHooks: expect.objectContaining({
150-beforeEmit: expect.any(Function),
151-afterEmitRejected: expect.any(Function),
152-}),
144+const payload = requireRestartSentinelPayload();
145+expect(payload.kind).toBe("restart");
146+expect(payload.status).toBe("ok");
147+expect(payload.sessionKey).toBe("agent:main:main");
148+expect(payload.deliveryContext).toEqual({
149+channel: "slack",
150+to: "slack:C123",
151+accountId: "workspace-1",
152+});
153+expect(payload.threadId).toBe("thread-42");
154+expect(payload.message).toBe("Gateway restarting now");
155+expect(payload.continuation).toEqual({
156+kind: "agentTurn",
157+message: "Reply with exactly: Yay! I did it!",
153158});
159+const restartArgs = requireScheduledRestartArgs();
160+expect(restartArgs.delayMs).toBe(250);
161+expect(restartArgs.reason).toBe("continue after reboot");
162+expect(typeof restartArgs.emitHooks?.beforeEmit).toBe("function");
163+expect(typeof restartArgs.emitHooks?.afterEmitRejected).toBe("function");
154164expect(result?.details).toEqual({ scheduled: true, delayMs: 250 });
155165});
156166@@ -169,14 +179,10 @@ describe("gateway tool restart continuation", () => {
169179const scheduledArgs = scheduleGatewaySigusr1RestartMock.mock.calls.at(-1)?.[0];
170180await scheduledArgs?.emitHooks?.beforeEmit?.();
171181172-expect(writeRestartSentinelMock).toHaveBeenCalledWith(
173-expect.objectContaining({
174-continuation: {
175-kind: "agentTurn",
176-message: "Reply after restart",
177-},
178-}),
179-);
182+expect(requireRestartSentinelPayload().continuation).toEqual({
183+kind: "agentTurn",
184+message: "Reply after restart",
185+});
180186});
181187182188it("defaults session-scoped restarts to a success continuation", async () => {
@@ -196,15 +202,12 @@ describe("gateway tool restart continuation", () => {
196202const scheduledArgs = scheduleGatewaySigusr1RestartMock.mock.calls.at(-1)?.[0];
197203await scheduledArgs?.emitHooks?.beforeEmit?.();
198204199-expect(writeRestartSentinelMock).toHaveBeenCalledWith(
200-expect.objectContaining({
201-sessionKey: "agent:main:main",
202-continuation: {
203-kind: "agentTurn",
204-message: DEFAULT_RESTART_SUCCESS_CONTINUATION_MESSAGE,
205-},
206-}),
207-);
205+const payload = requireRestartSentinelPayload();
206+expect(payload.sessionKey).toBe("agent:main:main");
207+expect(payload.continuation).toEqual({
208+kind: "agentTurn",
209+message: DEFAULT_RESTART_SUCCESS_CONTINUATION_MESSAGE,
210+});
208211});
209212210213it("removes the prepared sentinel when restart emission is rejected", async () => {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。