File size: 1,858 Bytes
eb3f11e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import fs from "node:fs";
import path from "node:path";
import { afterEach, describe, expect, it } from "vitest";
import { useAutoCleanupTempDirTracker } from "../../../test/helpers/temp-dir.js";
import { runCliProcessChild } from "../cli-process-child.test-helpers.js";

const tempDirs = useAutoCleanupTempDirTracker(afterEach);

describe("update config snapshot isolation", () => {
  it.each(["home", "state", "explicit", "profile"] as const)(
    "snapshots the current %s selection after importing under another home",
    async (selection) => {
      const root = fs.realpathSync(tempDirs.make("openclaw-update-snapshot-"));
      const homeA = path.join(root, "A");
      const support = new URL("./update-command-config-snapshot.test-support.ts", import.meta.url);
      const result = await runCliProcessChild({
        nodeArgs: [
          "--import",
          "tsx",
          "--input-type=module",
          "--eval",
          `const { runUpdateSnapshotIsolationProof } = await import(${JSON.stringify(support.href)});
           await runUpdateSnapshotIsolationProof(${JSON.stringify(root)}, ${JSON.stringify(selection)});`,
        ],
        // No inherited OpenClaw selectors, credentials, NODE_OPTIONS, or fast-test shortcuts.
        env: {
          PATH: process.env.PATH,
          SystemRoot: process.env.SystemRoot,
          HOME: homeA,
          USERPROFILE: homeA,
          OPENCLAW_HOME: homeA,
          OPENCLAW_STATE_DIR: path.join(homeA, ".openclaw"),
          OPENCLAW_CONFIG_PATH: path.join(homeA, ".openclaw", "openclaw.json"),
          TMPDIR: root,
          TMP: root,
          TEMP: root,
          TSX_DISABLE_CACHE: "1",
          ESBUILD_WORKER_THREADS: "0",
        },
      });
      expect(result.code, `${result.stdout}\n${result.stderr}`).toBe(0);
      expect(result.signal).toBeNull();
    },
  );
});