test: centralize shell snapshot env

This commit is contained in:
Shakker
2026-06-25 09:37:55 +01:00
parent d7dff3cbf4
commit 08b7fddf80
+4 -4
View File
@@ -4,7 +4,7 @@ import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import { captureEnv } from "../test-utils/env.js";
import { captureEnv, setTestEnvValue } from "../test-utils/env.js";
import {
maybeWrapCommandWithShellSnapshot,
resetShellSnapshotCacheForTests,
@@ -40,9 +40,9 @@ function setSnapshotStateForTest(
options: { home?: string; zdotdir?: string } = {},
): void {
// Snapshot tests mutate trusted process env, not per-command untrusted env.
process.env.OPENCLAW_STATE_DIR = stateDir;
setTestEnvValue("OPENCLAW_STATE_DIR", stateDir);
if (options.home) {
process.env.HOME = options.home;
setTestEnvValue("HOME", options.home);
}
if (options.zdotdir) {
process.env.ZDOTDIR = options.zdotdir;
@@ -91,7 +91,7 @@ describe("exec shell snapshots", () => {
const home = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-snapshot-disabled-home-"));
tempDirs.push(stateDir, home);
setSnapshotStateForTest(stateDir, { home });
process.env[EXEC_SHELL_SNAPSHOT_ENV] = "0";
setTestEnvValue(EXEC_SHELL_SNAPSHOT_ENV, "0");
const command = "echo unchanged";
const wrapped = await maybeWrapCommandWithShellSnapshot({
command,