refactor(test): share auth test env/profile helpers

This commit is contained in:
Peter Steinberger
2026-02-16 15:25:23 +00:00
parent 1d37389490
commit 94f455c693
4 changed files with 79 additions and 69 deletions

View File

@@ -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;
}