diff --git a/src/tasks/task-flow-registry.maintenance.test.ts b/src/tasks/task-flow-registry.maintenance.test.ts index d769207a0363..45d0011daf40 100644 --- a/src/tasks/task-flow-registry.maintenance.test.ts +++ b/src/tasks/task-flow-registry.maintenance.test.ts @@ -1,5 +1,6 @@ // Covers maintenance reconciliation for managed task-flow records. import { afterEach, describe, expect, it } from "vitest"; +import { captureEnv } from "../test-utils/env.js"; import { withOpenClawTestState } from "../test-utils/openclaw-test-state.js"; import { createRunningTaskRun as createRunningTaskRunOrNull } from "./task-executor.js"; import { @@ -22,7 +23,7 @@ import { } from "./task-registry.js"; import type { TaskRecord } from "./task-registry.types.js"; -const ORIGINAL_STATE_DIR = process.env.OPENCLAW_STATE_DIR; +const ORIGINAL_ENV = captureEnv(["OPENCLAW_STATE_DIR"]); function createFlowRecord(params: Parameters[0]): TaskFlowRecord { const flow = createFlowRecordOrNull(params); @@ -77,11 +78,7 @@ async function withTaskFlowMaintenanceStateDir( describe("task-flow-registry maintenance", () => { afterEach(() => { - if (ORIGINAL_STATE_DIR === undefined) { - delete process.env.OPENCLAW_STATE_DIR; - } else { - process.env.OPENCLAW_STATE_DIR = ORIGINAL_STATE_DIR; - } + ORIGINAL_ENV.restore(); resetTaskRegistryDeliveryRuntimeForTests(); resetTaskRegistryForTests(); resetTaskFlowRegistryForTests();