perf(test): shorten Slack startup auth regression (#124404)

This commit is contained in:
Peter Steinberger
2026-08-15 21:16:31 -07:00
committed by GitHub
parent a54caf0a66
commit e4aaef4660
2 changed files with 27 additions and 12 deletions
+2 -8
View File
@@ -77,7 +77,6 @@ type SlackTestState = {
>;
socketModeLogger?: { error: (...args: unknown[]) => void };
createSlackStartupAuthClientMock: Mock<SlackStartupAuthClientFactory>;
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<typeof import("./client.js")>("./client.js");
slackTestState.createSlackStartupAuthClientActual = actual.createSlackStartupAuthClient;
return {
...actual,
createSlackStartupAuthClient: (...args: Parameters<SlackStartupAuthClientFactory>) =>
@@ -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({