@@ -3,28 +3,19 @@ import fs from "node:fs/promises";
|
3 | 3 | import os from "node:os"; |
4 | 4 | import path from "node:path"; |
5 | 5 | import { afterEach, describe, expect, it } from "vitest"; |
| 6 | +import { captureEnv, setTestEnvValue } from "../test-utils/env.js"; |
6 | 7 | import { |
7 | 8 | checkShellCompletionStatus, |
8 | 9 | shellCompletionStatusToHealthFindings, |
9 | 10 | shellCompletionStatusToRepairEffects, |
10 | 11 | type ShellCompletionStatus, |
11 | 12 | } from "./doctor-completion.js"; |
12 | 13 | |
13 | | -const originalEnv = { |
14 | | -HOME: process.env.HOME, |
15 | | -OPENCLAW_STATE_DIR: process.env.OPENCLAW_STATE_DIR, |
16 | | -SHELL: process.env.SHELL, |
17 | | -}; |
| 14 | +const originalEnv = captureEnv(["HOME", "OPENCLAW_STATE_DIR", "SHELL"]); |
18 | 15 | const tempDirs: string[] = []; |
19 | 16 | |
20 | 17 | afterEach(async () => { |
21 | | -for (const [name, value] of Object.entries(originalEnv)) { |
22 | | -if (value === undefined) { |
23 | | -delete process.env[name]; |
24 | | -} else { |
25 | | -process.env[name] = value; |
26 | | -} |
27 | | -} |
| 18 | +originalEnv.restore(); |
28 | 19 | for (const dir of tempDirs.splice(0)) { |
29 | 20 | await fs.rm(dir, { recursive: true, force: true }); |
30 | 21 | } |
@@ -46,9 +37,9 @@ describe("shell completion health mapping", () => {
|
46 | 37 | const homeDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-completion-home-")); |
47 | 38 | const stateDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-completion-state-")); |
48 | 39 | tempDirs.push(homeDir, stateDir); |
49 | | -process.env.HOME = homeDir; |
50 | | -process.env.OPENCLAW_STATE_DIR = stateDir; |
51 | | -process.env.SHELL = "/bin/zsh"; |
| 40 | +setTestEnvValue("HOME", homeDir); |
| 41 | +setTestEnvValue("OPENCLAW_STATE_DIR", stateDir); |
| 42 | +setTestEnvValue("SHELL", "/bin/zsh"); |
52 | 43 | |
53 | 44 | const current = await checkShellCompletionStatus("openclaw", { shell: "fish" }); |
54 | 45 | |
|