Skip to content

test(cli): the sandbox holds when CLAUDE_CONFIG_DIR is set - #251

Open
bdelanghe wants to merge 1 commit into
mainfrom
fix/test-claude-config-isolation
Open

test(cli): the sandbox holds when CLAUDE_CONFIG_DIR is set#251
bdelanghe wants to merge 1 commit into
mainfrom
fix/test-claude-config-isolation

Conversation

@bdelanghe

@bdelanghe bdelanghe commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Tests pin $HOME to a tempdir, which sandboxes every reader that derives its paths from it. The Claude reader does not derive from $HOME: since b31f2c5 it prefers $CLAUDE_CONFIG_DIR, and the child process inherits that from whoever ran cargo.

On a machine that exports it — every Claude Code user, since that variable is how a custom config root gets selected at all — the CLI walks straight out of the sandbox:

Error: Conversation not found: /Users/bobby/.config/claude/projects/-tmp-.../session-abc.jsonl
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^ should have been the test's temp HOME

CI never sees this; it exports no such variable. Locally it is 28 failures:

cargo test -p path-cli --test integration               20 failed
cargo test -p path-cli --test query                      8 failed
env -u CLAUDE_CONFIG_DIR cargo test -p path-cli ...      all pass

The fix

Remove the variable in the three places each suite already builds its sandboxed command — integration.rs's cmd(), query.rs's cmd() and its two direct Command::cargo_bin call sites — and in ScopedHome, beside $HOME and $TOOLPATH_CONFIG_DIR.

Removed, not pinned: the point is to restore the reader's $HOME-relative default so the HOME the test already sets is the one that counts. ScopedHome restores the previous value on drop like the others. A test that wants to exercise the override sets it on its own command.

After this, one failure remains — deliberately

file_input_explicit_opencode_projects_and_records_exec still fails. It is the same shape of escape through a different variable: the opencode PathResolver prefers $XDG_DATA_HOME over $HOME, so it finds the developer's real opencode.db. The fix is a separate one-liner in ScopedHome — it was #142, whose branch died with the fork; the commit survives as tag archive/fork/fix-opencode-test-xdg-isolation and is a clean cherry-pick onto main.

Kept out of this PR: different variable, different reader, its own review.


  1. Independent PR — no bundled or speculative changes
    • Verified: one concern — $CLAUDE_CONFIG_DIR escaping the test sandbox. Test files only, no production code.
  2. Changed codepaths verified — targeted unit and full integration tests
    • Verified: cargo test -p path-cli --test integration 62/62 and --test query 37/37, run with CLAUDE_CONFIG_DIR still exported — the condition that previously failed. cargo test --workspace goes from 29 failures to 1. cargo fmt --all --check clean.
  3. Root cause identified — every failure traced to source
    • b31f2c5 taught the reader to prefer $CLAUDE_CONFIG_DIR; the test harness sandboxes $HOME only, so the variable was inherited and outranked the sandbox. Confirmed by env -u flipping every failure to a pass.
  4. No duplication — refactoring preferred over copy/paste
    • Removed at the points that already assemble the sandbox rather than adding a new helper; ScopedHome follows the save/restore pattern already there for $HOME and $TOOLPATH_CONFIG_DIR.
  5. No unrelated changes — housekeeping isolated to its own branch
    • The $XDG_DATA_HOME escape is left failing for its own PR

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Tests pin $HOME to a tempdir, which sandboxes every reader that derives
its paths from it. The Claude reader does not derive from $HOME: since
b31f2c5 it prefers $CLAUDE_CONFIG_DIR, which the child process inherits
from whoever ran cargo. On a machine that exports it — every Claude Code
user, since that variable is how a custom config root gets selected at
all — the CLI walks out of the sandbox and reads the developer's real
config, so the fixture session is reported missing.

28 of 29 failures on this box, none of them visible in CI, which exports
no such variable:

    cargo test -p path-cli --test integration              20 failed
    cargo test -p path-cli --test query                     8 failed
    env -u CLAUDE_CONFIG_DIR cargo test ...                 all pass

Remove the variable where each suite already builds its sandboxed
command, and in ScopedHome beside $HOME and $TOOLPATH_CONFIG_DIR. A
test that wants to exercise the override can set it on its own command.

One failure is left after this, and it is a different escape of the same
shape: file_input_explicit_opencode_projects_and_records_exec follows
$XDG_DATA_HOME to the real opencode database.
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown

🔍 Preview deployed: https://41a4bcfe.toolpath.pages.dev

@bdelanghe
bdelanghe marked this pull request as ready for review September 1, 2026 18:33
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