Skip to content

Commit 53b37e5

Browse files
fix(gateway): preserve stale channel restart diagnostics
1 parent 05974a8 commit 53b37e5

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

src/gateway/server-channels.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,40 @@ describe("server-channels auto restart", () => {
300300
expect(account?.lastError).toBeNull();
301301
});
302302

303+
it("lets stop hooks update status after aborting the running task", async () => {
304+
const startAccount = vi.fn(async (ctx: ChannelGatewayContext<TestAccount>) => {
305+
ctx.setStatus({
306+
accountId: DEFAULT_ACCOUNT_ID,
307+
running: true,
308+
connected: true,
309+
lastError: "startup warning",
310+
});
311+
await new Promise<void>((resolve) => {
312+
ctx.abortSignal.addEventListener("abort", () => resolve(), { once: true });
313+
});
314+
});
315+
const stopAccount = vi.fn(async (ctx: ChannelGatewayContext<TestAccount>) => {
316+
ctx.setStatus({
317+
accountId: DEFAULT_ACCOUNT_ID,
318+
connected: false,
319+
lastError: null,
320+
});
321+
});
322+
installTestRegistry(createTestPlugin({ startAccount, stopAccount }));
323+
const manager = createManager();
324+
325+
await manager.startChannels();
326+
await flushMicrotasks();
327+
await manager.stopChannel("discord", DEFAULT_ACCOUNT_ID);
328+
329+
const snapshot = manager.getRuntimeSnapshot();
330+
const account = snapshot.channelAccounts.discord?.[DEFAULT_ACCOUNT_ID];
331+
expect(stopAccount).toHaveBeenCalledTimes(1);
332+
expect(account?.running).toBe(false);
333+
expect(account?.connected).toBe(false);
334+
expect(account?.lastError).toBeNull();
335+
});
336+
303337
it("does not enumerate configured accounts when stopping a never-started channel", async () => {
304338
const listAccountIds = vi.fn(() => [DEFAULT_ACCOUNT_ID]);
305339
const resolveAccount = vi.fn(() => ({ enabled: true, configured: true }));

src/gateway/server-channels.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ export function createChannelManager(opts: ChannelManagerOptions): ChannelManage
825825
abortSignal: abort?.signal ?? new AbortController().signal,
826826
log,
827827
getStatus: () => getRuntime(channelId, id),
828-
setStatus: (next) => setRuntimeFromTaskStatus(channelId, id, next, abort?.signal),
828+
setStatus: (next) => setRuntime(channelId, id, next),
829829
});
830830
}
831831
const stoppedCleanly = await waitForChannelStopGracefully(

0 commit comments

Comments
 (0)