mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 01:21:25 +00:00
refactor(test): simplify state dir env helpers
This commit is contained in:
@@ -1,26 +1,11 @@
|
||||
type StateDirEnvSnapshot = {
|
||||
openclawStateDir: string | undefined;
|
||||
clawdbotStateDir: string | undefined;
|
||||
};
|
||||
import { captureEnv } from "../test-utils/env.js";
|
||||
|
||||
export function snapshotStateDirEnv(): StateDirEnvSnapshot {
|
||||
return {
|
||||
openclawStateDir: process.env.OPENCLAW_STATE_DIR,
|
||||
clawdbotStateDir: process.env.CLAWDBOT_STATE_DIR,
|
||||
};
|
||||
export function snapshotStateDirEnv() {
|
||||
return captureEnv(["OPENCLAW_STATE_DIR", "CLAWDBOT_STATE_DIR"]);
|
||||
}
|
||||
|
||||
export function restoreStateDirEnv(snapshot: StateDirEnvSnapshot): void {
|
||||
if (snapshot.openclawStateDir === undefined) {
|
||||
delete process.env.OPENCLAW_STATE_DIR;
|
||||
} else {
|
||||
process.env.OPENCLAW_STATE_DIR = snapshot.openclawStateDir;
|
||||
}
|
||||
if (snapshot.clawdbotStateDir === undefined) {
|
||||
delete process.env.CLAWDBOT_STATE_DIR;
|
||||
} else {
|
||||
process.env.CLAWDBOT_STATE_DIR = snapshot.clawdbotStateDir;
|
||||
}
|
||||
export function restoreStateDirEnv(snapshot: ReturnType<typeof snapshotStateDirEnv>): void {
|
||||
snapshot.restore();
|
||||
}
|
||||
|
||||
export function setStateDirEnv(stateDir: string): void {
|
||||
|
||||
Reference in New Issue
Block a user