test(#1970): scope HOME/USERPROFILE in folded bug-130/bug-410 blocks
Adversarial review (Codex) surfaced a latent cross-suite leak: the folded bug-130 and bug-410 install.test.cjs blocks set process.env.HOME/USERPROFILE to a temp home at collection time and never restored — harmless when each ran as its own process, but after consolidation it leaked into sibling folded suites in the same process. Scope both mutations to before()/after() hooks that restore the prior values, matching the save/restore pattern used elsewhere in the file. Assertions unchanged. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -4094,8 +4094,21 @@ const ROOT = path.join(__dirname, '..');
|
|||||||
// Point HOME at a temp dir so configureOpencodePermissions can't write to
|
// Point HOME at a temp dir so configureOpencodePermissions can't write to
|
||||||
// the real ~/.config/opencode/ even if the guard is missing.
|
// the real ~/.config/opencode/ even if the guard is missing.
|
||||||
const FAKE_HOME = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-130-test-'));
|
const FAKE_HOME = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-130-test-'));
|
||||||
process.env.HOME = FAKE_HOME;
|
// Consolidation #1969: scope the HOME/USERPROFILE mutation to before/after so it
|
||||||
process.env.USERPROFILE = FAKE_HOME;
|
// does not leak into sibling folded suites (was process-isolated when standalone).
|
||||||
|
const { before: __foldBefore, after: __foldAfter } = require('node:test');
|
||||||
|
const __savedHome = process.env.HOME;
|
||||||
|
const __savedUserProfile = process.env.USERPROFILE;
|
||||||
|
__foldBefore(() => {
|
||||||
|
process.env.HOME = FAKE_HOME;
|
||||||
|
process.env.USERPROFILE = FAKE_HOME;
|
||||||
|
});
|
||||||
|
__foldAfter(() => {
|
||||||
|
if (__savedHome === undefined) delete process.env.HOME;
|
||||||
|
else process.env.HOME = __savedHome;
|
||||||
|
if (__savedUserProfile === undefined) delete process.env.USERPROFILE;
|
||||||
|
else process.env.USERPROFILE = __savedUserProfile;
|
||||||
|
});
|
||||||
|
|
||||||
// The opencode config dir that configureOpencodePermissions would use for a
|
// The opencode config dir that configureOpencodePermissions would use for a
|
||||||
// global install when configDir=null: <HOME>/.config/opencode/
|
// global install when configDir=null: <HOME>/.config/opencode/
|
||||||
@@ -4183,8 +4196,21 @@ const ROOT = path.join(__dirname, '..');
|
|||||||
// finishInstall's path.join(os.homedir(), '.gsd') resolves into FAKE_HOME
|
// finishInstall's path.join(os.homedir(), '.gsd') resolves into FAKE_HOME
|
||||||
// on every platform. Node docs: https://nodejs.org/docs/latest-v22.x/api/os.html#oshomedir
|
// on every platform. Node docs: https://nodejs.org/docs/latest-v22.x/api/os.html#oshomedir
|
||||||
const FAKE_HOME = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-410-test-'));
|
const FAKE_HOME = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-410-test-'));
|
||||||
process.env.HOME = FAKE_HOME;
|
// Consolidation #1969: scope the HOME/USERPROFILE mutation to before/after so it
|
||||||
process.env.USERPROFILE = FAKE_HOME;
|
// does not leak into sibling folded suites (was process-isolated when standalone).
|
||||||
|
const { before: __foldBefore, after: __foldAfter } = require('node:test');
|
||||||
|
const __savedHome = process.env.HOME;
|
||||||
|
const __savedUserProfile = process.env.USERPROFILE;
|
||||||
|
__foldBefore(() => {
|
||||||
|
process.env.HOME = FAKE_HOME;
|
||||||
|
process.env.USERPROFILE = FAKE_HOME;
|
||||||
|
});
|
||||||
|
__foldAfter(() => {
|
||||||
|
if (__savedHome === undefined) delete process.env.HOME;
|
||||||
|
else process.env.HOME = __savedHome;
|
||||||
|
if (__savedUserProfile === undefined) delete process.env.USERPROFILE;
|
||||||
|
else process.env.USERPROFILE = __savedUserProfile;
|
||||||
|
});
|
||||||
|
|
||||||
// The path that finishInstall would write to for a non-Claude runtime.
|
// The path that finishInstall would write to for a non-Claude runtime.
|
||||||
const GSD_DIR = path.join(FAKE_HOME, '.gsd');
|
const GSD_DIR = path.join(FAKE_HOME, '.gsd');
|
||||||
|
|||||||
Reference in New Issue
Block a user