





















@@ -180,15 +180,60 @@ describe("GatewayPlugin", () => {
180180}
181181182182await vi.advanceTimersByTimeAsync(5_000);
183-expect(errorSpy).toHaveBeenCalledWith(
184-new Error("Discord gateway socket closed before IDENTIFY could be sent"),
185-);
183+expect(errorSpy).not.toHaveBeenCalled();
186184await vi.advanceTimersByTimeAsync(2_000);
187185188186expect(gateway.connectCalls).toEqual([false, false]);
189187expect(gateway.sockets).toHaveLength(2);
190188});
191189190+it("does not identify a replacement socket from a stale HELLO", async () => {
191+vi.useFakeTimers();
192+vi.setSystemTime(0);
193+await sharedGatewayIdentifyLimiter.wait({ shardId: 0, maxConcurrency: 1 });
194+const gateway = new TestGatewayPlugin({
195+autoInteractions: false,
196+url: "wss://gateway.example.test",
197+});
198+199+gateway.connect(false);
200+const originalSocket = gateway.sockets[0];
201+originalSocket?.emit("open");
202+originalSocket?.emit(
203+"message",
204+JSON.stringify({
205+op: GatewayOpcodes.Hello,
206+d: { heartbeat_interval: 45_000 },
207+s: null,
208+}),
209+);
210+originalSocket?.emit("close", 1006);
211+212+await vi.advanceTimersByTimeAsync(2_000);
213+expect(gateway.connectCalls).toEqual([false, true]);
214+const replacementSocket = gateway.sockets[1];
215+replacementSocket?.emit("open");
216+217+await vi.advanceTimersByTimeAsync(3_000);
218+expect(replacementSocket?.send).not.toHaveBeenCalledWith(
219+expect.stringContaining(`"op":${GatewayOpcodes.Identify}`),
220+);
221+222+replacementSocket?.emit(
223+"message",
224+JSON.stringify({
225+op: GatewayOpcodes.Hello,
226+d: { heartbeat_interval: 45_000 },
227+s: null,
228+}),
229+);
230+231+await vi.advanceTimersByTimeAsync(5_000);
232+expect(replacementSocket?.send).toHaveBeenCalledWith(
233+expect.stringContaining(`"op":${GatewayOpcodes.Identify}`),
234+);
235+});
236+192237it("preserves MESSAGE_CREATE author payloads for inbound dispatch", async () => {
193238const gateway = new GatewayPlugin({ autoInteractions: false });
194239const dispatchGatewayEvent = vi.fn(async (_event: string, _data: unknown) => {});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。