mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-13 17:07:40 +00:00
test: restore doctor completion env
This commit is contained in:
@@ -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" });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user