
























@@ -124,6 +124,24 @@ async function waitForMicrotaskCondition(
124124throw new Error(message);
125125}
126126127+function firstSleepWithAbortCall(): [number, AbortSignal | undefined] {
128+const call = hoisted.sleepWithAbort.mock.calls.at(0);
129+if (!call) {
130+throw new Error("expected sleepWithAbort call");
131+}
132+return call as [number, AbortSignal | undefined];
133+}
134+135+function firstStartAccountContext(
136+startAccount: ReturnType<typeof vi.fn>,
137+): ChannelGatewayContext<TestAccount> {
138+const ctx = startAccount.mock.calls.at(0)?.at(0);
139+if (!ctx || typeof ctx !== "object") {
140+throw new Error("expected channel start context");
141+}
142+return ctx as ChannelGatewayContext<TestAccount>;
143+}
144+127145function installTestRegistry(
128146 ...plugins: Array<
129147ChannelPlugin<TestAccount> | { plugin: ChannelPlugin<TestAccount>; origin: string }
@@ -395,11 +413,9 @@ describe("server-channels auto restart", () => {
395413() => hoisted.sleepWithAbort.mock.calls.length > 0,
396414"expected recovery restart backoff to be scheduled",
397415);
398-const sleepCall = hoisted.sleepWithAbort.mock.calls[0] as
399-| [number, AbortSignal | undefined]
400-| undefined;
401-expect(sleepCall?.[0]).toBe(10);
402-expect(sleepCall?.[1]).toBeInstanceOf(AbortSignal);
416+const sleepCall = firstSleepWithAbortCall();
417+expect(sleepCall[0]).toBe(10);
418+expect(sleepCall[1]).toBeInstanceOf(AbortSignal);
403419404420await manager.stopChannel("discord", DEFAULT_ACCOUNT_ID);
405421await vi.advanceTimersByTimeAsync(10);
@@ -455,7 +471,7 @@ describe("server-channels auto restart", () => {
455471456472await manager.startChannels();
457473expect(startAccount).toHaveBeenCalledTimes(1);
458-const [ctx] = startAccount.mock.calls[0] ?? [];
474+const ctx = firstStartAccountContext(startAccount);
459475expect((ctx?.channelRuntime as { marker?: string } | undefined)?.marker).toBe(
460476"channel-runtime",
461477);
@@ -476,7 +492,7 @@ describe("server-channels auto restart", () => {
476492await manager.startChannel("slack");
477493478494expect(startAccount).toHaveBeenCalledTimes(1);
479-const [ctx] = startAccount.mock.calls[0] ?? [];
495+const ctx = firstStartAccountContext(startAccount);
480496expect(ctx?.log).toBe(channelLogs.slack);
481497expect(ctx?.runtime).toBe(channelRuntimeEnvs.slack);
482498expect((ctx?.log as SubsystemLogger | undefined)?.subsystem).toBe("channels/slack");
@@ -548,7 +564,7 @@ describe("server-channels auto restart", () => {
548564549565expect(resolveChannelRuntime).toHaveBeenCalledTimes(1);
550566expect(startAccount).toHaveBeenCalledTimes(1);
551-const [ctx] = startAccount.mock.calls[0] ?? [];
567+const ctx = firstStartAccountContext(startAccount);
552568expect((ctx?.channelRuntime as { marker?: string } | undefined)?.marker).toBe(
553569"lazy-channel-runtime",
554570);
@@ -576,7 +592,7 @@ describe("server-channels auto restart", () => {
576592expect(resolveStartupChannelRuntime).toHaveBeenCalledTimes(1);
577593expect(resolveChannelRuntime).not.toHaveBeenCalled();
578594expect(startAccount).toHaveBeenCalledTimes(1);
579-const [ctx] = startAccount.mock.calls[0] ?? [];
595+const ctx = firstStartAccountContext(startAccount);
580596expect((ctx?.channelRuntime as { marker?: string } | undefined)?.marker).toBe(
581597"startup-channel-runtime",
582598);
@@ -603,7 +619,7 @@ describe("server-channels auto restart", () => {
603619604620expect(resolveStartupChannelRuntime).not.toHaveBeenCalled();
605621expect(resolveChannelRuntime).toHaveBeenCalledTimes(1);
606-const [ctx] = startAccount.mock.calls[0] ?? [];
622+const ctx = firstStartAccountContext(startAccount);
607623expect((ctx?.channelRuntime as { marker?: string } | undefined)?.marker).toBe(
608624"full-channel-runtime",
609625);
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。