Skip to content

[FIX] test isolation: suite no longer touches the real ~/.claude#20

Merged
gradyzhuo merged 1 commit into
mainfrom
fix/test-isolation-default-config-dir
Jul 7, 2026
Merged

[FIX] test isolation: suite no longer touches the real ~/.claude#20
gradyzhuo merged 1 commit into
mainfrom
fix/test-isolation-default-config-dir

Conversation

@gradyzhuo

Copy link
Copy Markdown
Member

Summary

Running swift test corrupted the developer's real ~/.claude: Tool.defaultConfigDir built ~/.claude/~/.codex/~/.gemini from FileManager.homeDirectoryForCurrentUser (which reads getpwuid and ignores env overrides), so it resolved to the real home even when withIsolatedHome had redirected ORRERY_HOME. Origin-takeover code symlinks at tool.defaultConfigDir, so a full test run repointed the real ~/.claude projects/sessions/session-env into per-test temp dirs under /var/folders — silent data-loss risk when the OS purges them. The same read (ListCommand line 42) made the "active account is marked" test flaky.

  • userHomeURL() (OrreryHome) — homeDirectoryForCurrentUser, overridable via ORRERY_USER_HOME. Tool.defaultConfigDir and orreryHomeURL()'s fallback route through it. The override is unset in production, so behavior there is unchanged.
  • withIsolatedHome sets ORRERY_USER_HOME to the temp dir. A dedicated var, not $HOME — setting $HOME breaks macOS Keychain resolution (the login keychain is located via $HOME), which fails the credential round-trip tests.
  • Added TestIsolationTests asserting defaultConfigDir stays inside the temp home under withIsolatedHome.

Test Plan

  • New isolation test: defaultConfigDir resolves under the temp home, not real ~/.claude
  • Full suite green (366/366), incl. the keychain credential round-trip (OS $HOME untouched)
  • Previously-flaky "active account is marked" ListCommand test now deterministic
  • Real ~/.claude symlinks byte-identical before/after a full swift test run (no hijack)

Note

Independent of #19 (origin bare-launch fix). Recommend merging this first — it makes the suite safe to run on any dev machine that has orrery installed.

🤖 Generated with Claude Code

`Tool.defaultConfigDir` built paths from `homeDirectoryForCurrentUser` (getpwuid
— ignores env), so it always resolved to the developer's real ~/.claude/.codex/
.gemini even when `withIsolatedHome` had redirected ORRERY_HOME. Origin-takeover
code symlinks at `tool.defaultConfigDir`, so running the suite repointed the real
~/.claude projects/sessions/session-env into per-test temp dirs (data loss risk
when /var/folders is purged). It also made the "active account is marked"
ListCommand test flaky (it reads the real ~/.claude/metadata.json).

- Add `userHomeURL()` in OrreryHome — homeDirectoryForCurrentUser, overridable
  via `ORRERY_USER_HOME`. Route `Tool.defaultConfigDir` (and orreryHomeURL's
  fallback) through it. Unset in production, so behavior is unchanged there.
- `withIsolatedHome` sets `ORRERY_USER_HOME` to the temp dir. A dedicated var,
  NOT $HOME: setting $HOME breaks macOS Keychain resolution (login keychain is
  located via $HOME), which would fail the credential round-trip tests.
- Add TestIsolationTests asserting defaultConfigDir stays inside the temp home.

Verified: full suite green (366/366), and the real ~/.claude symlinks are
byte-identical before and after a full `swift test` run (no hijack).
@gradyzhuo
gradyzhuo merged commit d936262 into main Jul 7, 2026
1 check passed
@gradyzhuo
gradyzhuo deleted the fix/test-isolation-default-config-dir branch July 7, 2026 04:06
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.

1 participant