Skip to content

fix(tests): clear agent root env vars once in the vitest setup file - #936

Merged
jeff-r2026 merged 1 commit into
Tencent:mainfrom
SaulMoro:fix/self-mode-agents-claude-config-dir
Oct 1, 2026
Merged

jeff-r2026 merged 1 commit into
Tencent:mainfrom
SaulMoro:fix/self-mode-agents-claude-config-dir

Conversation

@SaulMoro

@SaulMoro SaulMoro commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

teamai intentionally honors three variables that move an agent's root: CLAUDE_CONFIG_DIR (#728), COPILOT_HOME and OPENCLAW_STATE_DIR. Tests that stub only HOME still 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 for CLAUDE_CONFIG_DIR in 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.env with restore, or an explicit spawn env).

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature causing existing behavior to change)
  • Documentation only
  • Refactor / internal cleanup

Test Plan

Before (origin/main df940cd), with each variable pointed at a directory that exists:

Variable Effect
CLAUDE_CONFIG_DIR self-mode-agents.test.ts: FAIL detectHomeInstalledAgents > returns [] when no candidate tool dir exists under HOME, with AssertionError: expected [ 'claude' ] to deeply equal []. This is the only test in the suite that differs from an unset run.
COPILOT_HOME 5 or 6 failures across self-mode-agents, agent-model-aliases and dashboard-report-scope. The suite also writes skills/teamai/SKILL.md, agents/implementer.agent.md, copilot-instructions.md and hooks/teamai.json into that directory.
OPENCLAW_STATE_DIR The suite passes, but uninstall.test.ts deletes hooks/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 + uninstall fail 3 tests and rewrite a seeded $CLAUDE_CONFIG_DIR/settings.json with test values ("model": "personal-model", ANTHROPIC_AUTH_TOKEN, ...). With this PR, those files pass 121/121 and leave the seeded settings.json and CLAUDE.md byte-identical.

After:

  • npx vitest run gives 358 files, 6654 passed | 1 skipped (6655) in each of these runs:

    • with nothing set
    • with CLAUDE_CONFIG_DIR set (to both a real directory and a seeded one)
    • with COPILOT_HOME set
    • with OPENCLAW_STATE_DIR set
  • Fresh and seeded directories for each variable are unchanged after the full suite.

  • The setup file is shared with e2e. With CLAUDE_CONFIG_DIR set, 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 --noEmit passes

  • npm run lint passes

  • npx vitest run passes (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_HOME and XDG_CONFIG_HOME the 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.

@SaulMoro
SaulMoro force-pushed the fix/self-mode-agents-claude-config-dir branch from a6614a5 to 984c1cc Compare September 30, 2026 15:54
@SaulMoro SaulMoro changed the title fix(tests): isolate CLAUDE_CONFIG_DIR and COPILOT_HOME from self-mode agent detection tests fix(tests): clear CLAUDE_CONFIG_DIR and COPILOT_HOME in the vitest setup file Sep 30, 2026
@SaulMoro
SaulMoro force-pushed the fix/self-mode-agents-claude-config-dir branch from 984c1cc to bd4291b Compare September 30, 2026 16:37
@SaulMoro SaulMoro changed the title fix(tests): clear CLAUDE_CONFIG_DIR and COPILOT_HOME in the vitest setup file fix(tests): clear agent root env vars in the vitest setup file Sep 30, 2026
@SaulMoro
SaulMoro force-pushed the fix/self-mode-agents-claude-config-dir branch from bd4291b to 0d1c385 Compare September 30, 2026 17:14
@SaulMoro SaulMoro changed the title fix(tests): clear agent root env vars in the vitest setup file fix(tests): clear agent root env vars once in the vitest setup file Sep 30, 2026
@jeff-r2026 jeff-r2026 self-assigned this Oct 1, 2026
@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown

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
jeff-r2026 merged commit 9d8ef7d into Tencent:main Oct 1, 2026
15 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.

2 participants