























@@ -18,18 +18,12 @@ const {
1818 globalFetchMock,
1919 HttpsProxyAgent,
2020 getLastAgent,
21- restProxyAgentSpy,
2221 resolveDebugProxySettingsMock,
23- undiciFetchMock,
24- undiciProxyAgentSpy,
2522 resetLastAgent,
2623 webSocketSpy,
2724 wsProxyAgentSpy,
2825} = vi.hoisted(() => {
2926const wsProxyAgentSpy = vi.fn();
30-const undiciProxyAgentSpy = vi.fn();
31-const restProxyAgentSpy = vi.fn();
32-const undiciFetchMock = vi.fn();
3327const globalFetchMock = vi.fn();
3428const baseRegisterClientSpy = vi.fn();
3529const webSocketSpy = vi.fn();
@@ -86,12 +80,9 @@ const {
8680 globalFetchMock,
8781 HttpsProxyAgent,
8882getLastAgent: () => HttpsProxyAgent.lastCreated,
89- restProxyAgentSpy,
9083 captureHttpExchangeSpy,
9184 captureWsEventSpy,
9285 resolveDebugProxySettingsMock,
93- undiciFetchMock,
94- undiciProxyAgentSpy,
9586resetLastAgent: () => {
9687HttpsProxyAgent.lastCreated = undefined;
9788},
@@ -115,15 +106,6 @@ vi.mock("https-proxy-agent", () => ({
115106 HttpsProxyAgent,
116107}));
117108118-vi.mock("undici", () => ({
119-ProxyAgent: function ProxyAgent(this: { proxyUrl: string }, proxyUrl: string) {
120-this.proxyUrl = proxyUrl;
121-undiciProxyAgentSpy(proxyUrl);
122-restProxyAgentSpy(proxyUrl);
123-},
124-fetch: undiciFetchMock,
125-}));
126-127109vi.mock("ws", () => ({
128110default: function MockWebSocket(url: string, options?: { agent?: unknown }) {
129111webSocketSpy(url, options);
@@ -176,12 +158,6 @@ describe("createDiscordGatewayPlugin", () => {
176158return {
177159HttpsProxyAgentCtor:
178160HttpsProxyAgent as unknown as typeof import("https-proxy-agent").HttpsProxyAgent,
179-ProxyAgentCtor: function ProxyAgentCtor(this: { proxyUrl: string }, proxyUrl: string) {
180-this.proxyUrl = proxyUrl;
181-undiciProxyAgentSpy(proxyUrl);
182-restProxyAgentSpy(proxyUrl);
183-} as unknown as typeof import("undici").ProxyAgent,
184-undiciFetch: undiciFetchMock,
185161webSocketCtor: function WebSocketCtor(url: string, options?: { agent?: unknown }) {
186162webSocketSpy(url, options);
187163} as unknown as new (url: string, options?: { agent?: unknown }) => import("ws").WebSocket,
@@ -276,9 +252,6 @@ describe("createDiscordGatewayPlugin", () => {
276252vi.useRealTimers();
277253baseRegisterClientSpy.mockClear();
278254globalFetchMock.mockClear();
279-restProxyAgentSpy.mockClear();
280-undiciFetchMock.mockClear();
281-undiciProxyAgentSpy.mockClear();
282255wsProxyAgentSpy.mockClear();
283256webSocketSpy.mockClear();
284257captureHttpExchangeSpy.mockClear();
@@ -454,22 +427,20 @@ describe("createDiscordGatewayPlugin", () => {
454427expect(runtime.log).not.toHaveBeenCalled();
455428});
456429457-it("uses proxy fetch for gateway metadata lookup before registering", async () => {
430+it("keeps gateway metadata lookup on the guarded direct fetch when proxy is configured", async () => {
458431const runtime = createRuntime();
459432const plugin = createDiscordGatewayPlugin({
460433discordConfig: { proxy: "http://127.0.0.1:8080" },
461434 runtime,
462435__testing: createProxyTestingOverrides(),
463436});
464437465-await registerGatewayClientWithMetadata({ plugin, fetchMock: undiciFetchMock });
438+await registerGatewayClientWithMetadata({ plugin, fetchMock: globalFetchMock });
466439467-expect(restProxyAgentSpy).toHaveBeenCalledWith("http://127.0.0.1:8080");
468-expect(undiciFetchMock).toHaveBeenCalledWith(
440+expect(globalFetchMock).toHaveBeenCalledWith(
469441"https://discord.com/api/v10/gateway/bot",
470442expect.objectContaining({
471443headers: { Authorization: "Bot token-123" },
472-dispatcher: expect.objectContaining({ proxyUrl: "http://127.0.0.1:8080" }),
473444}),
474445);
475446expect(baseRegisterClientSpy).toHaveBeenCalledTimes(1);
@@ -488,7 +459,7 @@ describe("createDiscordGatewayPlugin", () => {
488459expect(captureHttpExchangeSpy).not.toHaveBeenCalled();
489460});
490461491-it("accepts IPv6 loopback proxy URLs for gateway metadata and websocket setup", async () => {
462+it("accepts IPv6 loopback proxy URLs for websocket setup", async () => {
492463const runtime = createRuntime();
493464const plugin = createDiscordGatewayPlugin({
494465discordConfig: { proxy: "http://[::1]:8080" },
@@ -499,10 +470,9 @@ describe("createDiscordGatewayPlugin", () => {
499470const createWebSocket = (plugin as unknown as { createWebSocket: (url: string) => unknown })
500471.createWebSocket;
501472createWebSocket("wss://gateway.discord.gg");
502-await registerGatewayClientWithMetadata({ plugin, fetchMock: undiciFetchMock });
473+await registerGatewayClientWithMetadata({ plugin, fetchMock: globalFetchMock });
503474504475expect(wsProxyAgentSpy).toHaveBeenCalledWith("http://[::1]:8080");
505-expect(restProxyAgentSpy).toHaveBeenCalledWith("http://[::1]:8080");
506476expect(runtime.error).not.toHaveBeenCalled();
507477});
508478此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。