From 7b5b21c0e1aea2d5ad930d14c9f2acfcb96a272b Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Thu, 23 Apr 2026 11:33:56 +0100 Subject: [PATCH] test(agents): avoid auth cache module resets --- src/agents/auth-profiles.store-cache.test.ts | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/agents/auth-profiles.store-cache.test.ts b/src/agents/auth-profiles.store-cache.test.ts index 81a56a5040a..ea23d9c490b 100644 --- a/src/agents/auth-profiles.store-cache.test.ts +++ b/src/agents/auth-profiles.store-cache.test.ts @@ -2,6 +2,7 @@ import fs from "node:fs"; import os from "node:os"; import path from "node:path"; import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; +import { clearRuntimeAuthProfileStoreSnapshots, ensureAuthProfileStore } from "./auth-profiles.js"; import { AUTH_STORE_VERSION } from "./auth-profiles/constants.js"; import type { OAuthCredential } from "./auth-profiles/types.js"; @@ -19,15 +20,6 @@ vi.mock("../plugins/provider-runtime.js", () => ({ resolveExternalAuthProfilesWithPlugins: () => [], })); -let clearRuntimeAuthProfileStoreSnapshots: typeof import("./auth-profiles.js").clearRuntimeAuthProfileStoreSnapshots; -let ensureAuthProfileStore: typeof import("./auth-profiles.js").ensureAuthProfileStore; - -async function loadFreshAuthProfilesModuleForTest() { - vi.resetModules(); - ({ clearRuntimeAuthProfileStoreSnapshots, ensureAuthProfileStore } = - await import("./auth-profiles.js")); -} - async function withAgentDirEnv(prefix: string, run: (agentDir: string) => void | Promise) { const agentDir = fs.mkdtempSync(path.join(os.tmpdir(), prefix)); const previousAgentDir = process.env.OPENCLAW_AGENT_DIR; @@ -75,14 +67,15 @@ function writeAuthStore(agentDir: string, key: string) { } describe("auth profile store cache", () => { - beforeEach(async () => { - await loadFreshAuthProfilesModuleForTest(); + beforeEach(() => { + clearRuntimeAuthProfileStoreSnapshots(); + mocks.resolveExternalCliAuthProfiles.mockReset(); + mocks.resolveExternalCliAuthProfiles.mockReturnValue([]); }); afterEach(() => { vi.useRealTimers(); clearRuntimeAuthProfileStoreSnapshots(); - vi.clearAllMocks(); }); function createRuntimeOnlyOverlay(access: string): RuntimeOnlyOverlay {