test(e2e): isolate HOME in Setup Journey + Init Edge Cases blocks#205
Open
orendi84 wants to merge 1 commit intogarrytan:masterfrom
Open
test(e2e): isolate HOME in Setup Journey + Init Edge Cases blocks#205orendi84 wants to merge 1 commit intogarrytan:masterfrom
orendi84 wants to merge 1 commit intogarrytan:masterfrom
Conversation
The Setup Journey block runs `gbrain init --non-interactive --url $DATABASE_URL`
in a subprocess that inherits the real HOME. On init, gbrain calls saveConfig()
which writes the test URL into the developer's real ~/.gbrain/config.json,
clobbering their prod Supabase URL + any API keys stored there.
On a developer machine running `DATABASE_URL=postgresql://postgres:postgres@localhost:5434/gbrain_test bun run test:e2e`
(the exact command in CONTRIBUTING.md), the test replaces the live config with:
{"engine":"postgres","database_url":"postgresql://postgres:postgres@localhost:5434/gbrain_test"}
Same latent bug in Init Edge Cases (though the one existing test there strips
DATABASE_URL so it doesn't actually hit saveConfig, applied the fix defensively).
Fix: override process.env.HOME to a fresh mkdtempSync() dir in beforeAll, restore
in afterAll, and pass HOME explicitly to spawned subprocesses. Matches the
pattern used in test/e2e/migration-flow.test.ts (the only other e2e test that
had the discipline to do this correctly).
No production code changes. No new dependencies. +36/-4 lines.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
The
E2E: Setup Journeyblock intest/e2e/mechanical.test.tsrunsgbrain init --non-interactive --url $DATABASE_URLin a subprocess that inherits the realHOMEenv var.gbrain initcallssaveConfig()(src/commands/init.ts:198) which writes to~/.gbrain/config.jsonin whateverhomedir()returns - i.e. the developer's real home directory.Run this exact command from
CONTRIBUTING.md:...and your real
~/.gbrain/config.jsongets silently overwritten with:{"engine":"postgres","database_url":"postgresql://postgres:postgres@localhost:5434/gbrain_test"}Any Supabase URL and API keys that were in the config are gone. The gbrain CLI then fails with
28P01 password authentication failedon the next real-brain query.I hit this on my 13k-page brain today running migrations. Cost ~90 minutes of debugging before we realized tests had clobbered the config.
The fix
Override
process.env.HOMEto a freshmkdtempSync()dir inbeforeAll, restore inafterAll, and passHOMEexplicitly to spawned subprocesses. This is the same pattern already used intest/e2e/migration-flow.test.ts(see lines 62-73, 80-90) - that file is the only other e2e test that had the discipline to isolate HOME correctly.Applied the same fix defensively to
E2E: Init Edge Caseseven though its current test stripsDATABASE_URLbefore spawning. If a future test in that block callsgbrain initwith a URL, the isolation is already there.Scope
test/e2e/mechanical.test.tsmkdtempSync,rmSync,tmpdir,joinalready imported)Verification
Locally: file builds clean via
bun build, matches the migration-flow.test.ts pattern which is already known-good in the existing E2E suite.