Skip to content

Fix #1597: sandbox the user-global agent-farm dir in the vitest harness - #1598

Merged
amrmelsayed merged 2 commits into
mainfrom
fix/1597-vitest-local-key-pin
Sep 3, 2026
Merged

amrmelsayed merged 2 commits into
mainfrom
fix/1597-vitest-local-key-pin

Conversation

@amrmelsayed

Copy link
Copy Markdown
Collaborator

Fixes #1597.

What

The vitest harness (vitest-setup.ts, the #1323 sandbox) now pins CODEV_AGENT_FARM_DIR into its per-run sandbox, so ensureLocalKey() — 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 key ensureLocalKey() resolves in the test process, so client and server always share the sandbox key. No e2e opt-in is needed; exporting CODEV_AGENT_FARM_DIR remains 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-core is first imported. setupFiles order guarantees that for vitest-e2e-setup.ts, and the new canary asserts the ordering held.

Test adaptations

cloud-config.test.ts and tower-cloud-cli.test.ts redirected the agent-farm dir by mocking node:os.homedir — inert now, since the env var outranks homedir. Both re-pin CODEV_AGENT_FARM_DIR to their own temp dir inside vi.hoisted (before the module graph evaluates) and restore the harness value in afterAll.

New canary

bugfix-1597-local-key-isolation.test.ts proves the pin is present, that core resolved AGENT_FARM_DIR from it (module-load ordering), and that ensureLocalKey() creates the key inside the sandbox and is not reading a real key file.

Verification

@amrmelsayed
amrmelsayed merged commit db297f7 into main Sep 3, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tunnel test suites touch the real ~/.agent-farm/local-key — pin it in vitest setup

1 participant