From e4aaef466023719fb25de5688d2b0922fa6f75f9 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 15 Aug 2026 21:16:31 -0700 Subject: [PATCH] perf(test): shorten Slack startup auth regression (#124404) --- extensions/slack/src/monitor.test-helpers.ts | 10 ++----- .../monitor/provider.auth-test-token.test.ts | 29 ++++++++++++++++--- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/extensions/slack/src/monitor.test-helpers.ts b/extensions/slack/src/monitor.test-helpers.ts index ecd358ab26ba..62dbf3e792d3 100644 --- a/extensions/slack/src/monitor.test-helpers.ts +++ b/extensions/slack/src/monitor.test-helpers.ts @@ -77,7 +77,6 @@ type SlackTestState = { >; socketModeLogger?: { error: (...args: unknown[]) => void }; createSlackStartupAuthClientMock: Mock; - createSlackStartupAuthClientActual?: SlackStartupAuthClientFactory; }; // globalThis-backed singleton: with isolate=false, a vi.resetModules() in any @@ -110,12 +109,8 @@ const slackTestState: SlackTestState = vi.hoisted(() => { export const getSlackTestState = (): SlackTestState => slackTestState; -export function useRealSlackStartupAuthClientOnce(): void { - const actual = slackTestState.createSlackStartupAuthClientActual; - if (!actual) { - throw new Error("real Slack WebClient factory is unavailable"); - } - slackTestState.createSlackStartupAuthClientMock.mockImplementationOnce(actual); +export function useSlackStartupAuthClientOnce(factory: SlackStartupAuthClientFactory): void { + slackTestState.createSlackStartupAuthClientMock.mockImplementationOnce(factory); } type SlackClient = { @@ -426,7 +421,6 @@ vi.mock("./resolve-users.js", () => ({ vi.mock("./client.js", async () => { const actual = await vi.importActual("./client.js"); - slackTestState.createSlackStartupAuthClientActual = actual.createSlackStartupAuthClient; return { ...actual, createSlackStartupAuthClient: (...args: Parameters) => diff --git a/extensions/slack/src/monitor/provider.auth-test-token.test.ts b/extensions/slack/src/monitor/provider.auth-test-token.test.ts index a04ffd4cbfb4..313dd5ae4d6d 100644 --- a/extensions/slack/src/monitor/provider.auth-test-token.test.ts +++ b/extensions/slack/src/monitor/provider.auth-test-token.test.ts @@ -1,6 +1,7 @@ // Slack tests cover auth.test token handling during provider boot. import { createServer } from "node:http"; import type { AddressInfo } from "node:net"; +import { WebClient } from "@slack/web-api"; import { createDeferred } from "openclaw/plugin-sdk/extension-shared"; import type { OpenKeyedStoreOptions } from "openclaw/plugin-sdk/plugin-state-runtime"; import { createPluginStateSyncKeyedStoreForTests } from "openclaw/plugin-sdk/plugin-state-test-runtime"; @@ -17,7 +18,7 @@ import { resetSlackTestState, startSlackMonitor as startSlackMonitorUntracked, stopSlackMonitor, - useRealSlackStartupAuthClientOnce, + useSlackStartupAuthClientOnce, } from "../monitor.test-helpers.js"; import { getSlackRuntime } from "../runtime.js"; @@ -60,6 +61,26 @@ const PROXY_ENV_KEYS = [ "NO_PROXY", "no_proxy", ] as const; +const SLACK_TEST_STARTUP_AUTH_TIMEOUT_MS = 100; + +function useShortSlackStartupAuthClientOnce(): void { + useSlackStartupAuthClientOnce( + (token, options) => + new WebClient(token, { + ...options, + // Production timeout and retry policy are pinned in client owner tests. This provider + // regression keeps the real SDK/transport while shortening only its test-owned clock. + retryConfig: { + retries: 2, + factor: 1, + minTimeout: 1, + maxTimeout: 1, + randomize: false, + }, + timeout: SLACK_TEST_STARTUP_AUTH_TIMEOUT_MS, + }), + ); +} async function startStalledSlackApiServer(events: string[]) { let requestCount = 0; @@ -266,7 +287,7 @@ describe("auth.test boot call", () => { } const server = await startStalledSlackApiServer(events); vi.stubEnv("SLACK_API_URL", server.apiUrl); - useRealSlackStartupAuthClientOnce(); + useShortSlackStartupAuthClientOnce(); const runtimeLog = vi.fn((...args: unknown[]) => { const message = args[0]; @@ -282,7 +303,7 @@ describe("auth.test boot call", () => { runtime: { log: runtimeLog, error: vi.fn(), exit: vi.fn() }, }); try { - await vi.waitFor(() => expect(appStartMock).toHaveBeenCalledTimes(1), { timeout: 35_000 }); + await vi.waitFor(() => expect(appStartMock).toHaveBeenCalledTimes(1), { timeout: 2_000 }); await vi.waitFor(() => expect(events).toContain("socket-closed"), { timeout: 1_000 }); expect(server.requestCount).toBe(3); @@ -297,7 +318,7 @@ describe("auth.test boot call", () => { await monitor.run; await server.close(); } - }, 40_000); + }, 5_000); it("preserves workspace startup when auth.test omits app_id", async () => { getSlackClient().auth.test.mockResolvedValueOnce({