fix(FN-3610): isolate test home for changed-package test runs
- Create a disposable HOME/USERPROFILE env for scripts/test-changed.mjs execution - Run isolation guard checks with the same isolated env, including cache-hit no-op paths - Clean up temp HOME after test execution to avoid residue - Update test coverage and contributing docs for the shared isolation behavior Fusion-Task-Id: FN-3610
This commit is contained in:
@@ -3,7 +3,7 @@ import assert from "node:assert/strict";
|
||||
import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { spawnSync, spawn } from "node:child_process";
|
||||
|
||||
const scriptPath = path.resolve("scripts/check-test-isolation.mjs");
|
||||
|
||||
@@ -82,3 +82,36 @@ test("fails when protected .fusion existence changes after baseline", () => {
|
||||
assert.match(after.stderr, /protected live \.fusion data changed/i);
|
||||
});
|
||||
});
|
||||
|
||||
test("passes when HOME .fusion is externally active during baseline and check", () => {
|
||||
withFixture(({ cwd, home }) => {
|
||||
const churnScript = `
|
||||
const fs = require("node:fs");
|
||||
const path = require("node:path");
|
||||
const home = process.argv[2];
|
||||
const target = path.join(home, ".fusion", "external-churn.txt");
|
||||
let n = 0;
|
||||
const timer = setInterval(() => {
|
||||
fs.writeFileSync(target, String(n++));
|
||||
}, 120);
|
||||
setTimeout(() => {
|
||||
clearInterval(timer);
|
||||
process.exit(0);
|
||||
}, 3500);
|
||||
`;
|
||||
|
||||
const churn = spawn(process.execPath, ["-e", churnScript, home], {
|
||||
cwd,
|
||||
env: { ...process.env, HOME: home, USERPROFILE: home },
|
||||
stdio: "ignore",
|
||||
});
|
||||
|
||||
const before = runScript(["--before"], { cwd, home });
|
||||
assert.equal(before.status, 0);
|
||||
const after = runScript([], { cwd, home });
|
||||
assert.equal(after.status, 0);
|
||||
|
||||
churn.kill("SIGTERM");
|
||||
rmSync(path.join(home, ".fusion", "external-churn.txt"), { force: true });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -26,7 +26,7 @@ const expectedSections = [
|
||||
"Example Plugins",
|
||||
"Registering Skills",
|
||||
"Registering Workflow Steps",
|
||||
"Plugin Prompt Contributions",
|
||||
"Contributing Prompt Modifications",
|
||||
"Plugin Binary Setup Hooks",
|
||||
];
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
cacheFilePath,
|
||||
shouldRunIsolationGuard,
|
||||
defaultTestWorkerBudget,
|
||||
createIsolatedHomeEnv,
|
||||
} from "../test-changed.mjs";
|
||||
|
||||
import { mkdirSync, writeFileSync, mkdtempSync, rmSync } from "node:fs";
|
||||
@@ -625,3 +626,16 @@ test("defaultTestWorkerBudget: uses CPU-aware defaults and clamps concurrency",
|
||||
assert.ok(budget.totalWorkers <= 12);
|
||||
assert.equal(budget.concurrency, budget.totalWorkers);
|
||||
});
|
||||
|
||||
test("createIsolatedHomeEnv: returns temp HOME/USERPROFILE pair without mutating input", () => {
|
||||
const baseEnv = { PATH: process.env.PATH || "" };
|
||||
const { env, isolatedHome } = createIsolatedHomeEnv(baseEnv);
|
||||
|
||||
assert.equal(env.HOME, isolatedHome);
|
||||
assert.equal(env.USERPROFILE, isolatedHome);
|
||||
assert.equal(baseEnv.HOME, undefined);
|
||||
assert.equal(baseEnv.USERPROFILE, undefined);
|
||||
assert.match(isolatedHome, /fusion-test-home-root-/);
|
||||
|
||||
rmSync(isolatedHome, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user