mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 17:34:35 +00:00
refactor(test): share auth test env/profile helpers
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { vi } from "vitest";
|
||||
import type { RuntimeEnv } from "../runtime.js";
|
||||
import type { WizardPrompter } from "../wizard/prompts.js";
|
||||
import { makeTempWorkspace } from "../test-helpers/workspace.js";
|
||||
|
||||
export const noopAsync = async () => {};
|
||||
export const noop = () => {};
|
||||
@@ -31,3 +34,24 @@ export function createWizardPrompter(
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
export async function setupAuthTestEnv(
|
||||
prefix = "openclaw-auth-",
|
||||
options?: { agentSubdir?: string },
|
||||
): Promise<{
|
||||
stateDir: string;
|
||||
agentDir: string;
|
||||
}> {
|
||||
const stateDir = await makeTempWorkspace(prefix);
|
||||
const agentDir = path.join(stateDir, options?.agentSubdir ?? "agent");
|
||||
process.env.OPENCLAW_STATE_DIR = stateDir;
|
||||
process.env.OPENCLAW_AGENT_DIR = agentDir;
|
||||
process.env.PI_CODING_AGENT_DIR = agentDir;
|
||||
await fs.mkdir(agentDir, { recursive: true });
|
||||
return { stateDir, agentDir };
|
||||
}
|
||||
|
||||
export async function readAuthProfilesForAgent<T>(agentDir: string): Promise<T> {
|
||||
const raw = await fs.readFile(path.join(agentDir, "auth-profiles.json"), "utf8");
|
||||
return JSON.parse(raw) as T;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user