From 5232f042fff4689dcead3f676bcbf9bd752d7ae3 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 10 May 2026 02:44:49 +0100 Subject: [PATCH] test: remove stale json auth session fixtures --- extensions/qa-lab/src/gateway-child.test.ts | 41 ++++++++----------- .../agent-runner.runreplyagent.e2e.test.ts | 13 +----- 2 files changed, 17 insertions(+), 37 deletions(-) diff --git a/extensions/qa-lab/src/gateway-child.test.ts b/extensions/qa-lab/src/gateway-child.test.ts index 267c0debe72..b722134085d 100644 --- a/extensions/qa-lab/src/gateway-child.test.ts +++ b/extensions/qa-lab/src/gateway-child.test.ts @@ -3,6 +3,7 @@ import { lstat, mkdir, mkdtemp, readFile, readdir, rm, symlink, writeFile } from import os from "node:os"; import path from "node:path"; import { pathToFileURL } from "node:url"; +import { loadAuthProfileStoreWithoutExternalProfiles } from "openclaw/plugin-sdk/agent-runtime"; import { afterEach, describe, expect, it, vi } from "vitest"; import { __testing, @@ -31,6 +32,13 @@ vi.mock("./node-exec.js", () => ({ const cleanups: Array<() => Promise> = []; +function readQaAuthProfiles(stateDir: string, agentId: string) { + return loadAuthProfileStoreWithoutExternalProfiles( + path.join(stateDir, "agents", agentId, "agent"), + { env: { ...process.env, OPENCLAW_STATE_DIR: stateDir } }, + ); +} + afterEach(async () => { fetchWithSsrFGuardMock.mockReset(); resolveQaNodeExecPathMock.mockReset(); @@ -392,11 +400,7 @@ describe("buildQaRuntimeEnv", () => { provider: "anthropic", mode: "token", }); - const storeRaw = await readFile( - path.join(stateDir, "agents", "main", "agent", "auth-profiles.json"), - "utf8", - ); - expect(JSON.parse(storeRaw)).toMatchObject({ + expect(readQaAuthProfiles(stateDir, "main")).toMatchObject({ profiles: { "anthropic:qa-setup-token": { type: "token", @@ -429,11 +433,7 @@ describe("buildQaRuntimeEnv", () => { }); for (const agentId of ["main", "qa"]) { - const storeRaw = await readFile( - path.join(stateDir, "agents", agentId, "agent", "auth-profiles.json"), - "utf8", - ); - expect(JSON.parse(storeRaw)).toMatchObject({ + expect(readQaAuthProfiles(stateDir, agentId)).toMatchObject({ profiles: { "qa-live-openai-env": { type: "api_key", @@ -470,16 +470,11 @@ describe("buildQaRuntimeEnv", () => { displayName: "QA mock anthropic credential", }); - // Store side: each agent dir should have its own auth-profiles.json - // containing the placeholder credential for each staged provider. This - // is what the scenario runner actually reads when it resolves auth - // before calling the mock. + // Store side: each agent should have a SQLite auth profile entry for each + // staged provider. This is what the scenario runner actually reads when it + // resolves auth before calling the mock. for (const agentId of ["main", "qa"]) { - const storeRaw = await readFile( - path.join(stateDir, "agents", agentId, "agent", "auth-profiles.json"), - "utf8", - ); - const parsed = JSON.parse(storeRaw) as { + const parsed = readQaAuthProfiles(stateDir, agentId) as { profiles: Record; }; expect(parsed.profiles["qa-mock-openai"]).toMatchObject({ @@ -515,9 +510,7 @@ describe("buildQaRuntimeEnv", () => { // Anthropic should NOT be staged when the caller restricts providers. expect(cfg.auth?.profiles?.["qa-mock-anthropic"]).toBeUndefined(); - const qaStore = JSON.parse( - await readFile(path.join(stateDir, "agents", "qa", "agent", "auth-profiles.json"), "utf8"), - ) as { profiles: Record }; + const qaStore = readQaAuthProfiles(stateDir, "qa") as { profiles: Record }; expect(qaStore.profiles["qa-mock-openai"]).toMatchObject({ provider: "openai", type: "api_key", @@ -525,9 +518,7 @@ describe("buildQaRuntimeEnv", () => { expect(qaStore.profiles["qa-mock-anthropic"]).toBeUndefined(); // main/agent should not exist because it wasn't in the agentIds list. - await expect( - readFile(path.join(stateDir, "agents", "main", "agent", "auth-profiles.json"), "utf8"), - ).rejects.toThrow(/ENOENT/); + expect(readQaAuthProfiles(stateDir, "main").profiles).toEqual({}); }); it("allows loopback gateway health probes through the SSRF guard", async () => { diff --git a/src/auto-reply/reply/agent-runner.runreplyagent.e2e.test.ts b/src/auto-reply/reply/agent-runner.runreplyagent.e2e.test.ts index 2bf3ba7d95f..0e5c728d172 100644 --- a/src/auto-reply/reply/agent-runner.runreplyagent.e2e.test.ts +++ b/src/auto-reply/reply/agent-runner.runreplyagent.e2e.test.ts @@ -1173,7 +1173,7 @@ describe("runReplyAgent typing (heartbeat)", () => { } }); - it("does not persist fallback state for an equivalent CLI runtime alias", async () => { + it("clears fallback notice state for an equivalent CLI runtime alias", async () => { const sessionEntry: SessionEntry = { sessionId: "session", updatedAt: Date.now(), @@ -1182,9 +1182,6 @@ describe("runReplyAgent typing (heartbeat)", () => { fallbackNoticeReason: "selected model unavailable", }; const sessionStore = { main: sessionEntry }; - const dir = await mkdtemp(join(tmpdir(), "openclaw-agent-runner-cli-alias-")); - const storePath = join(dir, "sessions.json"); - await writeFile(storePath, JSON.stringify({ main: sessionEntry }), "utf8"); state.runEmbeddedPiAgentMock.mockResolvedValue({ payloads: [{ text: "final" }], @@ -1201,7 +1198,6 @@ describe("runReplyAgent typing (heartbeat)", () => { sessionEntry, sessionStore, sessionKey: "main", - storePath, runOverrides: { provider: "anthropic", model: "claude-opus-4-7", @@ -1218,15 +1214,8 @@ describe("runReplyAgent typing (heartbeat)", () => { }); await run(); - const stored = JSON.parse(await readFile(storePath, "utf8")).main as SessionEntry; expect(sessionEntry.fallbackNoticeSelectedModel).toBeUndefined(); expect(sessionEntry.fallbackNoticeActiveModel).toBeUndefined(); - expect(stored.fallbackNoticeSelectedModel).toBeUndefined(); - expect(stored.fallbackNoticeActiveModel).toBeUndefined(); - expect(stored.modelProvider).toBe("claude-cli"); - expect(stored.model).toBe("claude-opus-4-7"); - expect(stored.totalTokens).toBe(36_000); - expect(stored.totalTokensFresh).toBe(true); }); it("surfaces overflow fallback when embedded run returns empty payloads", async () => {