Skip to content

test(resume): sandbox opencode by pinning XDG_DATA_HOME in ScopedHome#142

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

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

Conversation

@bdelanghe

@bdelanghe bdelanghe commented Jul 23, 2026

Copy link
Copy Markdown

Problem

file_input_explicit_opencode_projects_and_records_exec fails locally with:

SqlInputError … "table project already exists"

(green in CI, red on dev machines).

Root cause

The opencode PathResolver prefers $XDG_DATA_HOME over $HOME when locating opencode.db. ScopedHome only pinned $HOME, so on any machine that sets $XDG_DATA_HOME (common on Linux; set on this dev box) the test escaped its sandbox:

  • it seeded — and the projector wrote into — the real user opencode.db;
  • the seed's CREATE TABLE then hit the already-populated real DB and failed;
  • on a machine with a fresh/empty real DB it would instead silently mutate the user's live opencode data.

CI passes only because $XDG_DATA_HOME is typically unset there, so the resolver falls back to the scoped $HOME.

Fix

Pin $XDG_DATA_HOME to <tempdir>/.local/share in ScopedHome (saved + restored on drop), so every harness — opencode included — resolves inside the sandbox.

Verification

cargo test -p path-cli --test resume → all 12 pass, including file_input_explicit_opencode_*.

Versioning

None — test-harness isolation only, no crate or public-API changes.


Stack (review bottom-up): #141 empty-seed projection fix → #142 opencode test isolation → #145 path resume --remote.


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>
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