fix(test): gstack-config tests must win the state-dir precedence race - #2480
Open
tranthanhnhatkhoa wants to merge 1 commit into
Open
fix(test): gstack-config tests must win the state-dir precedence race#2480tranthanhnhatkhoa wants to merge 1 commit into
tranthanhnhatkhoa wants to merge 1 commit into
Conversation
browse/test/gstack-config.test.ts drives GSTACK_STATE_DIR, which is the LOWEST-priority of the four state-dir sources bin/gstack-config reads: GSTACK_STATE_ROOT > GSTACK_HOME > GSTACK_STATE_DIR > $HOME/.gstack The helper spreads ...process.env into the spawn env, so if either higher-priority variable is set in the parent process it silently outranks the temp dir and the script reads somewhere else. Every case that asserts on fixture content then sees an empty config. That is not hypothetical. Five suites assign GSTACK_HOME at MODULE scope and never restore it: browse/test/telemetry.test.ts:11 browse/test/cdp-e2e.test.ts:21 browse/test/domain-skills-storage.test.ts:7 browse/test/domain-skills-e2e.test.ts:20 test/helpers/budget-override.test.ts:18 bun shares one process across files, so whether these pass depends on file ordering. Alone: 26 pass. In the suite: 17 pass, 9 fail. Fix is in the harness rather than the leaking suites: a test that spawns a subprocess should fully specify the env it depends on instead of inheriting whatever ran first. Dropping the two higher-priority names makes the cases immune to any leaker, including ones added later. GSTACK_STATE_DIR stays the knob so the legacy alias keeps its coverage, and the per-case extraEnv override at line 106 is unaffected. Verified: clean env 26 pass 0 fail GSTACK_HOME poisoned 26 pass 0 fail (was 17 pass, 9 fail) GSTACK_STATE_ROOT poison 26 pass 0 fail full suite 32 fails -> 23 (all 9 gstack-config gone)
|
Merging to
After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
browse/test/gstack-config.test.tsdrivesGSTACK_STATE_DIR— the lowest-priority of the four state-dir sourcesbin/gstack-config:17reads:The helper spreads
...process.envinto the spawn env, so if either higher-priority variable is set in the parent process, it silently outranks the temp dir and the script reads somewhere else. Every case asserting on fixture content then sees an empty config.Not hypothetical — five suites assign
GSTACK_HOMEat module scope and never restore it:bunshares one process across files, so whether these pass depends on file ordering:bun test browse/test/gstack-config.test.tsbun run testThe fix
In the harness, not the leaking suites. A test that spawns a subprocess should fully specify the env it depends on rather than inherit whatever ran first — that makes it immune to any leaker, including ones added later. Patching the five would fix today and regress the first time someone adds a sixth.
GSTACK_STATE_DIRstays the knob, so the legacy alias keeps its coverage, and the per-caseextraEnvoverride at line 106 is unaffected.Verified
Environment: bun 1.3.14, Ubuntu 24.04.4 LTS,
main@960c3a8d(v1.60.2.0).Two things found alongside, not fixed here
The module-scope leaks are still there. This PR makes one harness immune; it doesn't stop the pollution. Anything reading
GSTACK_HOMEin-process (not via a spawned CLI) is still exposed. Worth a separate pass moving those five intobeforeAll/afterAllwith restore.The remaining 23 failures are unrelated to this. 15 of them (
gstack-team-init,gstack-session-update) are environmental: those casesgit initand commit into temp repos, and fail withAuthor identity unknownon a machine with no globaluser.name/user.email. SupplyingGIT_AUTHOR_*takestest/team-mode.test.tsfrom 9 pass / 15 fail to 24 pass / 0 fail. That may be worth a fixture-level identity so the suite doesn't depend on the developer's global git config — happy to send that separately if you want it.I also hit #2435 while doing this (suite exits 0 with failures) and left a repro there.