diff --git a/src/agents/auth-profiles.store-cache.test.ts b/src/agents/auth-profiles.store-cache.test.ts index 8f03bf2fae7..81a56a5040a 100644 --- a/src/agents/auth-profiles.store-cache.test.ts +++ b/src/agents/auth-profiles.store-cache.test.ts @@ -28,14 +28,14 @@ async function loadFreshAuthProfilesModuleForTest() { await import("./auth-profiles.js")); } -function withAgentDirEnv(prefix: string, run: (agentDir: string) => void | Promise) { +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; const previousPiAgentDir = process.env.PI_CODING_AGENT_DIR; try { process.env.OPENCLAW_AGENT_DIR = agentDir; process.env.PI_CODING_AGENT_DIR = agentDir; - return run(agentDir); + await run(agentDir); } finally { if (previousAgentDir === undefined) { delete process.env.OPENCLAW_AGENT_DIR; @@ -132,31 +132,14 @@ describe("auth profile store cache", () => { }); }); - it("keeps runtime-only external auth out of persisted auth-profiles.json files", () => { - const agentDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-auth-store-missing-")); - const previousAgentDir = process.env.OPENCLAW_AGENT_DIR; - const previousPiAgentDir = process.env.PI_CODING_AGENT_DIR; + it("keeps runtime-only external auth out of persisted auth-profiles.json files", async () => { mocks.resolveExternalCliAuthProfiles.mockReturnValue([createRuntimeOnlyOverlay("access-1")]); - try { - process.env.OPENCLAW_AGENT_DIR = agentDir; - process.env.PI_CODING_AGENT_DIR = agentDir; + await withAgentDirEnv("openclaw-auth-store-missing-", (agentDir) => { const store = ensureAuthProfileStore(agentDir); expect(store.profiles["openai-codex:default"]).toMatchObject({ access: "access-1" }); expect(fs.existsSync(path.join(agentDir, "auth-profiles.json"))).toBe(false); - } finally { - if (previousAgentDir === undefined) { - delete process.env.OPENCLAW_AGENT_DIR; - } else { - process.env.OPENCLAW_AGENT_DIR = previousAgentDir; - } - if (previousPiAgentDir === undefined) { - delete process.env.PI_CODING_AGENT_DIR; - } else { - process.env.PI_CODING_AGENT_DIR = previousPiAgentDir; - } - fs.rmSync(agentDir, { recursive: true, force: true }); - } + }); }); });