Skip to content

test(resume): pin XDG_DATA_HOME in ScopedHome to sandbox opencode - #253

Open
bdelanghe wants to merge 1 commit into
mainfrom
fix/opencode-test-xdg-isolation
Open

test(resume): pin XDG_DATA_HOME in ScopedHome to sandbox opencode#253
bdelanghe wants to merge 1 commit into
mainfrom
fix/opencode-test-xdg-isolation

Conversation

@bdelanghe

@bdelanghe bdelanghe commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

ScopedHome pins $HOME and $TOOLPATH_CONFIG_DIR, which sandboxes every reader that derives its paths from $HOME. The opencode PathResolver does not: it prefers $XDG_DATA_HOME when locating opencode.db.

On a machine that sets $XDG_DATA_HOME — common on Linux, and set on this dev box — the projector goes to the real user database. The test fails with table … already exists, and, worse, mutates live opencode data on the way.

Pinning it alongside the other two keeps every harness inside the sandbox.

Verified

file_input_explicit_opencode_projects_and_records_exec, with $XDG_DATA_HOME exported:

before    test result: FAILED. 9 passed; 1 failed
after     test result: ok.    10 passed; 0 failed

Provenance

This is the commit from #142, which was closed unmerged when the bdelanghe/toolpath fork was retired. The work was preserved beforehand as tag archive/fork/fix-opencode-test-xdg-isolation; this branch is that commit cherry-picked onto current main, unchanged apart from the rebase.

Relationship to #251

Both touch crates/path-cli/tests/support/mod.rs, and both close the same class of hole — an env var that outranks the sandboxed $HOME. They are independent fixes for different variables and different readers, so they are separate PRs; whichever lands second will want a trivial rebase, as they add adjacent fields to ScopedHome.

Together they take cargo test --workspace on a developer machine from 29 failures to 0. Neither is visible in CI, which sets neither variable.


  1. Independent PR — no bundled or speculative changes
    • Verified: one commit, one file, one concern — $XDG_DATA_HOME escaping the test sandbox. Test-support code only.
  2. Changed codepaths verified — targeted unit and full integration tests
    • Verified: cargo test -p path-cli --test resume 10/10 with the fix, 9/10 without it on the same box and the same shell; cargo fmt --all --check clean
  3. Root cause identified — every failure traced to source
    • The opencode PathResolver prefers $XDG_DATA_HOME over $HOME; ScopedHome pinned only the latter, so an exported value escaped the sandbox and reached the real opencode.db
  4. No duplication — refactoring preferred over copy/paste
    • Follows the save/restore pattern already in ScopedHome for $HOME and $TOOLPATH_CONFIG_DIR rather than adding a parallel mechanism
  5. No unrelated changes — housekeeping isolated to its own branch

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

The opencode `PathResolver` prefers `$XDG_DATA_HOME` over `$HOME` when
locating `opencode.db`. `ScopedHome` only pinned `$HOME`, so on a machine
that sets `$XDG_DATA_HOME` (common on Linux; set on this dev box) the
opencode resume test escaped its sandbox: it seeded — and the projector
wrote into — the *real* user database. The seed's `CREATE TABLE` then hit
the already-populated real DB and failed with "table project already
exists" (green in CI where XDG is unset, red locally), and a fresh-DB run
would silently mutate the user's live opencode data.

Pin `$XDG_DATA_HOME` to `<tempdir>/.local/share` in ScopedHome (restored
on drop) so every harness — opencode included — stays sandboxed.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown

🔍 Preview deployed: https://16c1cf45.toolpath.pages.dev

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