Repository navigation
Fix #1597: sandbox the user-global agent-farm dir in the vitest harness - #1598
Merged
Merged
Conversation
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.
Fixes #1597.
What
The vitest harness (
vitest-setup.ts, the #1323 sandbox) now pinsCODEV_AGENT_FARM_DIRinto its per-run sandbox, soensureLocalKey()— reached by the e2e fetch patch,towerWsProtocols(), and any suite touching core auth — never reads or creates the developer's real~/.agent-farm/local-key.Why this is the whole fix
The redirect mechanism already existed (
CODEV_AGENT_FARM_DIR, #1515); the harness just never set it, so safety depended on each suite remembering — exactly the failure-of-omission pattern #1323 exists to prevent. Auth stays consistent end to end by construction:createIsolatedAgentFarmDir()seeds each spawned test Tower with a copy of whatever keyensureLocalKey()resolves in the test process, so client and server always share the sandbox key. No e2e opt-in is needed; exportingCODEV_AGENT_FARM_DIRremains the one named way to point suites elsewhere. Defense in depth: a stray suite fetch at a real Tower on :4100 now carries the sandbox key and 401s instead of arriving authenticated (the #1515 incident class).Ordering constraint honored: core's key path is a module-load const, so the pin must land before
@cluesmith/codev-coreis first imported.setupFilesorder guarantees that forvitest-e2e-setup.ts, and the new canary asserts the ordering held.Test adaptations
cloud-config.test.tsandtower-cloud-cli.test.tsredirected the agent-farm dir by mockingnode:os.homedir— inert now, since the env var outranks homedir. Both re-pinCODEV_AGENT_FARM_DIRto their own temp dir insidevi.hoisted(before the module graph evaluates) and restore the harness value inafterAll.New canary
bugfix-1597-local-key-isolation.test.tsproves the pin is present, that core resolvedAGENT_FARM_DIRfrom it (module-load ordering), and thatensureLocalKey()creates the key inside the sandbox and is not reading a real key file.Verification
tsc --noEmitclean.bugfix-1515-tower-isolation.e2e.test.ts) green under the pin.homedir()-literal e2e fixtures (test-workspacespaths) bypassAGENT_FARM_DIRand are unaffected — out of tunnel test suites touch the real ~/.agent-farm/local-key — pin it in vitest setup #1597's scope.