mirror of
https://github.com/moltbot/moltbot.git
synced 2026-05-13 23:56:07 +00:00
test: seed image tool auth through sqlite
This commit is contained in:
@@ -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<string, { provider?: string }>;
|
||||
};
|
||||
} 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<string, { provider?: string }> },
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user