diff --git a/src/commands/flows.test.ts b/src/commands/flows.test.ts index 2f2c64ace441..17a36f7aecd0 100644 --- a/src/commands/flows.test.ts +++ b/src/commands/flows.test.ts @@ -1,5 +1,5 @@ // Flows command tests cover task creation, task execution, and runtime command output. -import { afterEach, describe, expect, it, vi } from "vitest"; +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import type { RuntimeEnv } from "../runtime.js"; import { createRunningTaskRun as createRunningTaskRunOrNull } from "../tasks/task-executor.js"; import { @@ -12,6 +12,7 @@ import { resetTaskRegistryForTests, } from "../tasks/task-registry.js"; import type { TaskRecord } from "../tasks/task-registry.types.js"; +import { captureEnv } from "../test-utils/env.js"; import { withOpenClawTestState } from "../test-utils/openclaw-test-state.js"; import { flowsCancelCommand, flowsListCommand, flowsShowCommand } from "./flows.js"; @@ -20,8 +21,6 @@ vi.mock("../config/config.js", () => ({ loadConfig: vi.fn(() => ({})), })); -const ORIGINAL_STATE_DIR = process.env.OPENCLAW_STATE_DIR; - function jsonRoundTrip(value: T): T { const serialized = JSON.stringify(value); return JSON.parse(serialized) as T; @@ -84,12 +83,14 @@ async function withTaskFlowCommandStateDir(run: (root: string) => Promise) } describe("flows commands", () => { + let envSnapshot: ReturnType; + + beforeEach(() => { + envSnapshot = captureEnv(["OPENCLAW_STATE_DIR"]); + }); + afterEach(() => { - if (ORIGINAL_STATE_DIR === undefined) { - delete process.env.OPENCLAW_STATE_DIR; - } else { - process.env.OPENCLAW_STATE_DIR = ORIGINAL_STATE_DIR; - } + envSnapshot.restore(); resetTaskRegistryDeliveryRuntimeForTests(); resetTaskRegistryForTests({ persist: false }); resetTaskFlowRegistryForTests({ persist: false });