test(#1971): isolate folded CLI blocks from host ambient GSD_ env

gsd-test surfaced 9 failures: folded fix-1437 (phase.list-plans) and bug-1826
(phases clear) tests spawn gsd-tools via runGsdTools, which copies process.env into
the child. Their host suites (phase-command-router / phases-command-router) force
GSD_WORKSTREAM=test-unit at the suite level, redirecting the child's project lookup
away from each test's temp project → plan/dir counts came back 0. Clear GSD_WORKSTREAM
in each folded block's beforeEach (restoring the standalone condition) and restore in
afterEach. Also scope the folded bug-416 GSD_TEST_MODE set to a before/after hook in
health-validation (Codex review) so it no longer leaks into host child processes.
Assertions unchanged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Tom Boucher
2026-07-03 01:34:33 -04:00
parent de3ba45d00
commit 7e2f74e9a9
3 changed files with 25 additions and 2 deletions

View File

@@ -481,8 +481,14 @@ function touch(dir, ...files) {
let tmpDir;
let phaseDir;
// Consolidation #1969: the host suite forces GSD_WORKSTREAM=test-unit, which
// runGsdTools propagates into child processes and redirects the project lookup.
// Clear it for these tests (unset when this file ran standalone); restore after.
let __savedWorkstream;
beforeEach(() => {
__savedWorkstream = process.env.GSD_WORKSTREAM;
delete process.env.GSD_WORKSTREAM;
const proj = setupProject('01-feature');
tmpDir = proj.tmpDir;
phaseDir = proj.phaseDir;
@@ -490,6 +496,8 @@ beforeEach(() => {
afterEach(() => {
cleanup(tmpDir);
if (__savedWorkstream === undefined) delete process.env.GSD_WORKSTREAM;
else process.env.GSD_WORKSTREAM = __savedWorkstream;
});
describe('bug-1437 — phase.list-plans is wired in gsd-tools', () => {