refactor(test): centralize auth test env lifecycle cleanup

This commit is contained in:
Peter Steinberger
2026-02-16 16:09:22 +00:00
parent 9a1e168685
commit 110b1cf46f
5 changed files with 48 additions and 49 deletions

View File

@@ -4,6 +4,7 @@ import { vi } from "vitest";
import type { RuntimeEnv } from "../runtime.js";
import type { WizardPrompter } from "../wizard/prompts.js";
import { makeTempWorkspace } from "../test-helpers/workspace.js";
import { captureEnv } from "../test-utils/env.js";
export const noopAsync = async () => {};
export const noop = () => {};
@@ -51,6 +52,28 @@ export async function setupAuthTestEnv(
return { stateDir, agentDir };
}
export type AuthTestLifecycle = {
setStateDir: (stateDir: string) => void;
cleanup: () => Promise<void>;
};
export function createAuthTestLifecycle(envKeys: string[]): AuthTestLifecycle {
const envSnapshot = captureEnv(envKeys);
let stateDir: string | null = null;
return {
setStateDir(nextStateDir: string) {
stateDir = nextStateDir;
},
async cleanup() {
if (stateDir) {
await fs.rm(stateDir, { recursive: true, force: true });
stateDir = null;
}
envSnapshot.restore();
},
};
}
export function requireOpenClawAgentDir(): string {
const agentDir = process.env.OPENCLAW_AGENT_DIR;
if (!agentDir) {