diff --git a/src/commands/doctor-completion.test.ts b/src/commands/doctor-completion.test.ts index 62f9170938fd..8066b9508b22 100644 --- a/src/commands/doctor-completion.test.ts +++ b/src/commands/doctor-completion.test.ts @@ -3,6 +3,7 @@ import fs from "node:fs/promises"; import os from "node:os"; import path from "node:path"; import { afterEach, describe, expect, it } from "vitest"; +import { captureEnv, setTestEnvValue } from "../test-utils/env.js"; import { checkShellCompletionStatus, shellCompletionStatusToHealthFindings, @@ -10,21 +11,11 @@ import { type ShellCompletionStatus, } from "./doctor-completion.js"; -const originalEnv = { - HOME: process.env.HOME, - OPENCLAW_STATE_DIR: process.env.OPENCLAW_STATE_DIR, - SHELL: process.env.SHELL, -}; +const originalEnv = captureEnv(["HOME", "OPENCLAW_STATE_DIR", "SHELL"]); const tempDirs: string[] = []; afterEach(async () => { - for (const [name, value] of Object.entries(originalEnv)) { - if (value === undefined) { - delete process.env[name]; - } else { - process.env[name] = value; - } - } + originalEnv.restore(); for (const dir of tempDirs.splice(0)) { await fs.rm(dir, { recursive: true, force: true }); } @@ -46,9 +37,9 @@ describe("shell completion health mapping", () => { const homeDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-completion-home-")); const stateDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-completion-state-")); tempDirs.push(homeDir, stateDir); - process.env.HOME = homeDir; - process.env.OPENCLAW_STATE_DIR = stateDir; - process.env.SHELL = "/bin/zsh"; + setTestEnvValue("HOME", homeDir); + setTestEnvValue("OPENCLAW_STATE_DIR", stateDir); + setTestEnvValue("SHELL", "/bin/zsh"); const current = await checkShellCompletionStatus("openclaw", { shell: "fish" });