test: restore doctor completion env

This commit is contained in:
Shakker
2026-06-20 04:37:18 +01:00
parent 9391dac56d
commit 14d362039e

View File

@@ -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" });