From af3bebd1190fdcb63b94401ea4b4bcbc9e537ee1 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 10 May 2026 00:18:16 +0100 Subject: [PATCH] test: seed image tool auth through sqlite --- src/agents/tools/image-tool.test.ts | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/agents/tools/image-tool.test.ts b/src/agents/tools/image-tool.test.ts index 745ea2d7c76..626f80d6579 100644 --- a/src/agents/tools/image-tool.test.ts +++ b/src/agents/tools/image-tool.test.ts @@ -1,4 +1,3 @@ -import fsSync from "node:fs"; import fs from "node:fs/promises"; import os from "node:os"; import path from "node:path"; @@ -13,6 +12,11 @@ import type { } from "../../plugin-sdk/media-understanding.js"; import { closeOpenClawStateDatabaseForTest } from "../../state/openclaw-state-db.js"; import { withFetchPreconnect } from "../../test-utils/fetch-mock.js"; +import { + loadPersistedAuthProfileStore, + savePersistedAuthProfileSecretsStore, +} from "../auth-profiles/persisted.js"; +import type { AuthProfileSecretsStore } from "../auth-profiles/types.js"; import { minimaxUnderstandImage } from "../minimax-vlm.js"; import { createOpenClawCodingTools } from "../pi-tools.js"; import type { SandboxFsBridge } from "../sandbox/fs-bridge.js"; @@ -100,21 +104,13 @@ vi.mock("../auth-profiles.js", () => ({ if (!agentDir) { return { version: 1, profiles: {} }; } - const pathname = path.join(agentDir, "auth-profiles.json"); - try { - return JSON.parse(fsSync.readFileSync(pathname, "utf8")) as { - version?: number; - profiles?: Record; - }; - } catch { - return { version: 1, profiles: {} }; - } + return loadPersistedAuthProfileStore(agentDir) ?? { version: 1, profiles: {} }; }, hasAnyAuthProfileStoreSource: (agentDir?: string) => { if (!agentDir) { return false; } - return fsSync.existsSync(path.join(agentDir, "auth-profiles.json")); + return Boolean(loadPersistedAuthProfileStore(agentDir)); }, listProfilesForProvider: ( store: { profiles?: Record }, @@ -170,13 +166,9 @@ vi.mock("../openclaw-tools.js", async () => { }; }); -async function writeAuthProfiles(agentDir: string, profiles: unknown) { +async function writeAuthProfiles(agentDir: string, profiles: AuthProfileSecretsStore) { await fs.mkdir(agentDir, { recursive: true }); - await fs.writeFile( - path.join(agentDir, "auth-profiles.json"), - `${JSON.stringify(profiles, null, 2)}\n`, - "utf8", - ); + savePersistedAuthProfileSecretsStore(profiles, agentDir); } async function createOpenClawCodingToolsWithFreshModules(options?: CreateOpenClawCodingToolsArgs) {