Repository navigation
fix(tests): clear agent root env vars once in the vitest setup file - #936
Merged
jeff-r2026 merged 1 commit intoOct 1, 2026
Merged
Conversation
SaulMoro
force-pushed
the
fix/self-mode-agents-claude-config-dir
branch
from
September 30, 2026 15:54
a6614a5 to
984c1cc
Compare
SaulMoro
force-pushed
the
fix/self-mode-agents-claude-config-dir
branch
from
September 30, 2026 16:37
984c1cc to
bd4291b
Compare
SaulMoro
force-pushed
the
fix/self-mode-agents-claude-config-dir
branch
from
September 30, 2026 17:14
bd4291b to
0d1c385
Compare
|
No findings. The PR description documents sufficient testing. This is a tests-only change, so a real-CLI end-to-end record is not required under the repository’s review rules. |
jeff-r2026
approved these changes
Oct 1, 2026
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
teamai intentionally honors three variables that move an agent's root:
CLAUDE_CONFIG_DIR(#728),COPILOT_HOMEandOPENCLAW_STATE_DIR. Tests that stub onlyHOMEstill inherit them from the developer's shell. When one is exported, those tests read, write, or delete files in the developer's real agent root. #890 fixed this forCLAUDE_CONFIG_DIRin two files. This PR instead clears all three variables once, in the vitest setup file that the unit and e2e configs already load (it already clears agent session ids for the same reason), and removes the two per-file stubs it replaces.// src/__tests__/helpers/clear-agent-session-env.ts for (const name of AGENT_SESSION_ENV) { delete process.env[name]; } + +for (const name of ['CLAUDE_CONFIG_DIR', 'COPILOT_HOME', 'OPENCLAW_STATE_DIR']) { + delete process.env[name]; +} // src/__tests__/local-agent-model-config.test.ts (back to its pre-#890 shape) - vi.stubEnv('CLAUDE_CONFIG_DIR', undefined); - vi.unstubAllEnvs(); // src/__tests__/uninstall.test.ts - vi.stubEnv('CLAUDE_CONFIG_DIR', undefined);No assertions change, and the production code is unchanged. A test that needs one of these variables still sets it itself (
vi.stubEnv,process.envwith restore, or an explicit spawnenv).Type of Change
Test Plan
Before (
origin/maindf940cd), with each variable pointed at a directory that exists:CLAUDE_CONFIG_DIRself-mode-agents.test.ts:FAIL detectHomeInstalledAgents > returns [] when no candidate tool dir exists under HOME, withAssertionError: expected [ 'claude' ] to deeply equal []. This is the only test in the suite that differs from an unset run.COPILOT_HOMEself-mode-agents,agent-model-aliasesanddashboard-report-scope. The suite also writesskills/teamai/SKILL.md,agents/implementer.agent.md,copilot-instructions.mdandhooks/teamai.jsoninto that directory.OPENCLAW_STATE_DIRuninstall.test.tsdeleteshooks/teamai-status-report/from that directory.The setup file now also covers the #890 case. With the #890 stubs removed and the setup-file change reverted,
local-agent-model-config+uninstallfail 3 tests and rewrite a seeded$CLAUDE_CONFIG_DIR/settings.jsonwith test values ("model": "personal-model",ANTHROPIC_AUTH_TOKEN, ...). With this PR, those files pass 121/121 and leave the seededsettings.jsonandCLAUDE.mdbyte-identical.After:
npx vitest rungives 358 files, 6654 passed | 1 skipped (6655) in each of these runs:CLAUDE_CONFIG_DIRset (to both a real directory and a seeded one)COPILOT_HOMEsetOPENCLAW_STATE_DIRsetFresh and seeded directories for each variable are unchanged after the full suite.
The setup file is shared with e2e. With
CLAUDE_CONFIG_DIRset, the e2e files that use these variables pass (7 files, 18 tests):copilot-agents,copilot-mcp,copilot-pre-push-sync,env-exec-signals,model-aliases-stateful,model-cli-switch,hooks-team-e2e.The change touches tests only, so there is no real-CLI e2e record (per CLAUDE.md).
npx tsc --noEmitpassesnpm run lintpassesnpx vitest runpasses (with and without each variable)Added/updated tests for the change
Related Issues
Supersedes the per-file stubs from #890.
Notes for Reviewers
Door: two-way. It touches test files only, and reverting restores the old behavior.
Blast Radius: test-only. A test that silently relied on an ambient value would now fail. None does: every run above passes.
I probed
CODEX_HOMEandXDG_CONFIG_HOMEthe same way, with both fresh and seeded directories (config.toml,opencode/opencode.json). Neither leaks: there are no failures, no writes, and the seeded files are unchanged. So I left them out of the list.