
















@@ -101,17 +101,19 @@ describe("runDiscordGatewayLifecycle", () => {
101101}
102102103103function createLifecycleHarness(params?: {
104-gateway?: MockGateway;
104+gateway?: MockGateway | null;
105105isDisallowedIntentsError?: (err: unknown) => boolean;
106106pendingGatewayEvents?: DiscordGatewayEvent[];
107107}) {
108108const gateway =
109-params?.gateway ??
110-(() => {
111-const defaultGateway = createGatewayHarness().gateway;
112-defaultGateway.isConnected = true;
113-return defaultGateway;
114-})();
109+params && "gateway" in params
110+ ? params.gateway
111+ : (() => {
112+const defaultGateway = createGatewayHarness().gateway;
113+defaultGateway.isConnected = true;
114+return defaultGateway;
115+})();
116+const gatewayEmitter = gateway?.emitter ?? new EventEmitter();
115117const threadStop = vi.fn();
116118const runtimeLog = vi.fn();
117119const runtimeError = vi.fn();
@@ -130,7 +132,7 @@ describe("runDiscordGatewayLifecycle", () => {
130132return "continue";
131133}),
132134dispose: vi.fn(),
133-emitter: gateway.emitter,
135+emitter: gatewayEmitter,
134136};
135137const statusSink = vi.fn();
136138const runtime: RuntimeEnv = {
@@ -146,7 +148,7 @@ describe("runDiscordGatewayLifecycle", () => {
146148 statusSink,
147149lifecycleParams: {
148150accountId: "default",
149-gateway: gateway as unknown as MutableDiscordGateway,
151+gateway: gateway ? (gateway as unknown as MutableDiscordGateway) : undefined,
150152 runtime,
151153isDisallowedIntentsError: params?.isDisallowedIntentsError ?? (() => false),
152154voiceManager: null,
@@ -215,6 +217,38 @@ describe("runDiscordGatewayLifecycle", () => {
215217);
216218});
217219220+it("does not treat a missing gateway handle as ready", async () => {
221+vi.useFakeTimers();
222+try {
223+const { lifecycleParams, threadStop, statusSink, gatewaySupervisor } = createLifecycleHarness(
224+{
225+gateway: null,
226+},
227+);
228+229+const lifecyclePromise = runDiscordGatewayLifecycle(lifecycleParams);
230+lifecyclePromise.catch(() => {});
231+await vi.advanceTimersByTimeAsync(0);
232+await vi.advanceTimersByTimeAsync(15_500);
233+234+await expect(lifecyclePromise).rejects.toThrow(
235+"discord gateway did not reach READY within 15000ms",
236+);
237+expect(statusSink).not.toHaveBeenCalledWith(
238+expect.objectContaining({
239+connected: true,
240+}),
241+);
242+expectLifecycleCleanup({
243+ threadStop,
244+waitCalls: 0,
245+ gatewaySupervisor,
246+});
247+} finally {
248+vi.useRealTimers();
249+}
250+});
251+218252it("restarts the gateway once when startup never reaches READY, then recovers", async () => {
219253vi.useFakeTimers();
220254try {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。