mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 22:48:27 +00:00
refactor(test): centralize auth test agent-dir helpers
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import type { WizardPrompter } from "../wizard/prompts.js";
|
||||
import type { AuthChoice } from "./onboard-types.js";
|
||||
@@ -11,9 +10,11 @@ import {
|
||||
ZAI_CODING_GLOBAL_BASE_URL,
|
||||
} from "./onboard-auth.js";
|
||||
import {
|
||||
authProfilePathForAgent,
|
||||
createExitThrowingRuntime,
|
||||
createWizardPrompter,
|
||||
readAuthProfilesForAgent,
|
||||
requireOpenClawAgentDir,
|
||||
setupAuthTestEnv,
|
||||
} from "./test-wizard-helpers.js";
|
||||
|
||||
@@ -31,14 +32,6 @@ vi.mock("../plugins/providers.js", () => ({
|
||||
resolvePluginProviders,
|
||||
}));
|
||||
|
||||
const authProfilePathFor = (agentDir: string) => path.join(agentDir, "auth-profiles.json");
|
||||
const requireAgentDir = () => {
|
||||
const agentDir = process.env.OPENCLAW_AGENT_DIR;
|
||||
if (!agentDir) {
|
||||
throw new Error("OPENCLAW_AGENT_DIR not set");
|
||||
}
|
||||
return agentDir;
|
||||
};
|
||||
type StoredAuthProfile = {
|
||||
key?: string;
|
||||
access?: string;
|
||||
@@ -75,7 +68,7 @@ describe("applyAuthChoice", () => {
|
||||
async function readAuthProfiles() {
|
||||
return await readAuthProfilesForAgent<{
|
||||
profiles?: Record<string, StoredAuthProfile>;
|
||||
}>(requireAgentDir());
|
||||
}>(requireOpenClawAgentDir());
|
||||
}
|
||||
async function readAuthProfile(profileId: string) {
|
||||
return (await readAuthProfiles()).profiles?.[profileId];
|
||||
@@ -521,8 +514,7 @@ describe("applyAuthChoice", () => {
|
||||
await setupTempState();
|
||||
process.env.LITELLM_API_KEY = "sk-litellm-test";
|
||||
|
||||
const authProfilePath = authProfilePathFor(requireAgentDir());
|
||||
await fs.mkdir(path.dirname(authProfilePath), { recursive: true });
|
||||
const authProfilePath = authProfilePathForAgent(requireOpenClawAgentDir());
|
||||
await fs.writeFile(
|
||||
authProfilePath,
|
||||
JSON.stringify(
|
||||
|
||||
Reference in New Issue
Block a user