mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-21 10:16:44 +00:00
test: centralize shell snapshot env
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user