From 06715db218fb9426b1b9e82f888d9070b728be58 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Tue, 14 Apr 2026 23:59:13 +0100 Subject: [PATCH] test(gateway): avoid startup auth module reset churn --- src/gateway/startup-auth.test.ts | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/gateway/startup-auth.test.ts b/src/gateway/startup-auth.test.ts index 0cae79a21b8..0c9f9c1d447 100644 --- a/src/gateway/startup-auth.test.ts +++ b/src/gateway/startup-auth.test.ts @@ -1,6 +1,11 @@ import { beforeEach, describe, expect, it, vi } from "vitest"; import type { OpenClawConfig } from "../config/config.js"; import { expectGeneratedTokenPersistedToGatewayAuth } from "../test-utils/auth-token-assertions.js"; +import { + assertGatewayAuthNotKnownWeak, + assertHooksTokenSeparateFromGatewayAuth, + ensureGatewayStartupAuth, +} from "./startup-auth.js"; const mocks = vi.hoisted(() => ({ replaceConfigFile: vi.fn(async (_params: { nextConfig: OpenClawConfig }) => {}), @@ -14,19 +19,6 @@ vi.mock("../config/config.js", async () => { }; }); -let assertGatewayAuthNotKnownWeak: typeof import("./startup-auth.js").assertGatewayAuthNotKnownWeak; -let assertHooksTokenSeparateFromGatewayAuth: typeof import("./startup-auth.js").assertHooksTokenSeparateFromGatewayAuth; -let ensureGatewayStartupAuth: typeof import("./startup-auth.js").ensureGatewayStartupAuth; - -async function loadFreshStartupAuthModuleForTest() { - vi.resetModules(); - ({ - assertGatewayAuthNotKnownWeak, - assertHooksTokenSeparateFromGatewayAuth, - ensureGatewayStartupAuth, - } = await import("./startup-auth.js")); -} - describe("ensureGatewayStartupAuth", () => { async function expectEphemeralGeneratedTokenWhenOverridden(cfg: OpenClawConfig) { const result = await ensureGatewayStartupAuth({ @@ -43,10 +35,9 @@ describe("ensureGatewayStartupAuth", () => { expect(mocks.replaceConfigFile).not.toHaveBeenCalled(); } - beforeEach(async () => { + beforeEach(() => { vi.restoreAllMocks(); mocks.replaceConfigFile.mockClear(); - await loadFreshStartupAuthModuleForTest(); }); async function expectNoTokenGeneration(cfg: OpenClawConfig, mode: string) { @@ -476,8 +467,9 @@ describe("ensureGatewayStartupAuth", () => { }); describe("assertGatewayAuthNotKnownWeak", () => { - beforeEach(async () => { - await loadFreshStartupAuthModuleForTest(); + beforeEach(() => { + vi.restoreAllMocks(); + mocks.replaceConfigFile.mockClear(); }); it("throws on the known-weak token sentinel", () => {