mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 16:38:27 +00:00
refactor(test): centralize auth test env lifecycle cleanup
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user