@@ -12,10 +12,11 @@ import {
|
12 | 12 | resetTaskRegistryForTests, |
13 | 13 | } from "../../tasks/runtime-internal.js"; |
14 | 14 | import type { TaskRecord } from "../../tasks/task-registry.types.js"; |
| 15 | +import { captureEnv, setTestEnvValue } from "../../test-utils/env.js"; |
15 | 16 | import { tasksHandlers } from "./tasks.js"; |
16 | 17 | import type { RespondFn } from "./types.js"; |
17 | 18 | |
18 | | -const ORIGINAL_STATE_DIR = process.env.OPENCLAW_STATE_DIR; |
| 19 | +const stateDirEnvSnapshot = captureEnv(["OPENCLAW_STATE_DIR"]); |
19 | 20 | type TaskResponsePayload = { |
20 | 21 | tasks?: Array<Record<string, unknown>>; |
21 | 22 | task?: Record<string, unknown>; |
@@ -35,17 +36,13 @@ function createTaskRecord(params: Parameters<typeof createTaskRecordOrNull>[0]):
|
35 | 36 | |
36 | 37 | beforeEach(async () => { |
37 | 38 | stateDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-gateway-tasks-")); |
38 | | -process.env.OPENCLAW_STATE_DIR = stateDir; |
| 39 | +setTestEnvValue("OPENCLAW_STATE_DIR", stateDir); |
39 | 40 | resetTaskRegistryForTests(); |
40 | 41 | }); |
41 | 42 | |
42 | 43 | afterEach(async () => { |
43 | 44 | resetTaskRegistryForTests(); |
44 | | -if (ORIGINAL_STATE_DIR === undefined) { |
45 | | -delete process.env.OPENCLAW_STATE_DIR; |
46 | | -} else { |
47 | | -process.env.OPENCLAW_STATE_DIR = ORIGINAL_STATE_DIR; |
48 | | -} |
| 45 | +stateDirEnvSnapshot.restore(); |
49 | 46 | await fs.rm(stateDir, { recursive: true, force: true }); |
50 | 47 | }); |
51 | 48 | |
|