diff --git a/extensions/discord/src/probe.intents.test.ts b/extensions/discord/src/probe.intents.test.ts index 59dc01a349f..e3a802d0e9b 100644 --- a/extensions/discord/src/probe.intents.test.ts +++ b/extensions/discord/src/probe.intents.test.ts @@ -1,5 +1,5 @@ import { withFetchPreconnect } from "openclaw/plugin-sdk/test-env"; -import { describe, expect, it } from "vitest"; +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import { fetchDiscordApplicationId, fetchDiscordApplicationSummary, @@ -8,6 +8,14 @@ import { import { jsonResponse } from "./test-http-helpers.js"; describe("resolveDiscordPrivilegedIntentsFromFlags", () => { + beforeEach(() => { + vi.useRealTimers(); + }); + + afterEach(() => { + vi.useRealTimers(); + }); + it("reports disabled when no bits set", () => { expect(resolveDiscordPrivilegedIntentsFromFlags(0)).toEqual({ presence: "disabled", diff --git a/extensions/discord/src/proxy-request-client.test.ts b/extensions/discord/src/proxy-request-client.test.ts index 6faceebf97f..dbaa9dba029 100644 --- a/extensions/discord/src/proxy-request-client.test.ts +++ b/extensions/discord/src/proxy-request-client.test.ts @@ -1,4 +1,4 @@ -import { describe, expect, it, vi } from "vitest"; +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import { createAbortableFetchMock, createJsonResponse, @@ -21,6 +21,14 @@ async function expectAbortError(promise: Promise) { } describe("createDiscordRequestClient", () => { + beforeEach(() => { + vi.useRealTimers(); + }); + + afterEach(() => { + vi.useRealTimers(); + }); + it("preserves the REST client's abort signal for proxied fetch calls", async () => { const fetchSpy = vi.fn(async (_input: string | URL | Request, init?: RequestInit) => { if (!(init?.signal instanceof AbortSignal)) { @@ -41,6 +49,7 @@ describe("createDiscordRequestClient", () => { it("lets the REST client abort hanging proxied requests after its timeout", async () => { const { fetch: fetchSpy } = createAbortableFetchMock(); + vi.useFakeTimers(); const client = createDiscordRequestClient("Bot test-token", { fetch: fetchSpy as never, @@ -48,7 +57,12 @@ describe("createDiscordRequestClient", () => { timeout: 20, }); - await expectAbortError(client.get("/channels/123/messages")); + const request = client.get("/channels/123/messages"); + const abortExpectation = expectAbortError(request); + await Promise.resolve(); + expect(fetchSpy).toHaveBeenCalledTimes(1); + await vi.advanceTimersByTimeAsync(20); + await abortExpectation; }, 1_000); it("lets abortAllRequests cancel active proxied fetches", async () => {