settings: refuse test writes to the account's real stores - #468
Merged
Merged
Conversation
setSetting and unsetSetting now throw before touching a store under the account's real ~/.mattstack when the process is a test run (NODE_ENV=test, VITEST, or a test file as Bun.main). The account home comes from the user database, because bun's os.homedir() and os.userInfo().homedir both report the HOME the process started with. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Warning Review limit reachedNext included review available in 46 minutes. View limit detailsLimit details: You’ve used the included review currently available. Your 85 included PR review attempts over the past 7 days set your current allowance at 1 review per hour. Your organization has reached its usage spending cap. Adjust your spending cap in the billing tab. Review configuration: ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (14)
Comment |
The refusal now says which signal made the process a test run. Team join (its clone brings settings.team.jsonc) and the home-repo init seam (its clone brings the user and machine stores) refuse the account's real ~/.mattstack in a test run, like team create. A child-process test proves the account home is not read from HOME, and the daemon sync-exec gate allowlists test-isolation.ts, whose one spawn only runs in a test run. Co-Authored-By: Claude Opus 5.5 <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.
Summary
On 2026-09-25 around 09:03 a test run wrote into Matt's real settings stores:
rt.apiPort=50489,rt.repoRoots=[]in the machine store,chat.viewerUrl="",chat.humanHandle="matt", and notification toggles. The daemon then bound 50489 instead of 9401 and the tray lost it. This PR makes that write impossible from a test run.What changed
packages/rt-client/src/test-isolation.ts:assertNotRealStoreInTest(path)throws when a test run targets anything under the account's real~/.mattstack. The rule is two pure functions (testRunSignal,realStoreRefusal), each with its own tests. The error names the signal that tripped (NODE_ENV=test,VITEST set, orentry module <Bun.main>).setSetting/unsetSettingcall it before touching a store, so no dirs get created and no file gets edited.rt team create(hand-writessettings.team.jsonc),rt team join(its clone bringssettings.team.jsonc), and the home-repo init seamcreateRealExecSeam(its clone brings the user and machine stores).lib/__tests__/no-daemon-sync-exec.test.tsallowliststest-isolation.ts: its one spawn (id -P) only runs in a test run.docs/settings-architecture.md: bun readsbunfig.tomlonly from the cwd, plus the two escapes that happen with the preload loaded. Nested bunfigs can't make the preload location-independent (bun never walks up), so this is documented instead.Detection signal
NODE_ENV=test, ORBun.mainis a test file, ORVITESTis set.bun testsets NODE_ENV=test only when NODE_ENV is unset, soBun.main(the running test file) covers a preset NODE_ENV. NODE_ENV also reaches children, includingBun.spawnchildren that get the startup env. bun sets no other marker (no BUN_* var, and the globals are identical).id -Pon macOS,getent passwdelsewhere). It's memoized and only looked up during a test run. A child-process test pins this: aNODE_ENV=testchild started with a scratch HOME writes its own store, and fails if the account home follows HOME. Under bun,os.userInfo().homedirandos.homedir()both return the HOME the process started with. Using them would refuse an e2e child spawned withHOME=<temp>and the inherited NODE_ENV when it writes its own temp store.<account home>/.mattstackis refused, so a scratch HOME nested inside the account home still works.Root cause
bun test --parallel=2 lib/daemon/__tests__/api-server.test.ts lib/__tests__/cd.test.tsfrom eored's root) doesn't reproduce. I ran it on its commit (e8e9af4) with a fake account home, inside a sandbox that denies writes to the real~/.mattstack, and every write landed in the preload's scratch HOME.lib/__tests__/cd.test.tsdoesn't exist on that commit, so only api-server.test.ts ran. The full unit suite under--parallel=4on that commit is clean too.--parallelresets the env and re-runs the preload for every file.undefined/tree written at 09:02:32 by a broader run (bundle, secrets, team join, chat and notifier tests). So HOME was corrupted mid-run there: the RT-302 failure mode, fixed on main at 10:43. The leaked keys come from several files (api-server*,chat-handlers,chat-delivery,notifier*,*repo-root*). That fits a stretch of a run where HOME resolved to the account, not a single test.bunfig.tomlonly from the cwd. On e8e9af4, running the two api-server tests from another directory rewrote the fake account's store (their unset deleted itsrt.apiPort).process.env.HOME ?? homedir()falls back to bun's frozen startup HOME, which is the real one, even with the preload loaded.Bun.spawn/Bun.spawnSyncwithoutenv: the child gets the startup env (real HOME, noRT_TEST_FORBID_SOCKS), though it does get NODE_ENV=test."undefined"variant.Tests
Targeted runs only:
packages/rt-clientsuite, dist freshness included: 398 pass.Publishing
This bumps
@mattstack/rt-clientto 0.31.2. Publishing is a separate release-class step, done frommainafter merge (see AGENTS.md). The version is shared, so whoever merges second renumbers.🤖 Generated with Claude Code