[BUG] Tests overwrite user auth.json (#10371) #7433

Closed
opened 2026-02-16 18:07:09 -05:00 by yindo · 1 comment
Owner

Originally created by @CasualDeveloper on GitHub (Jan 24, 2026).

Originally assigned to: @rekram1-node on GitHub.

Problem

Running bun run --cwd packages/opencode test overwrites the user's ~/.local/share/opencode/auth.json instead of keeping writes in a test sandbox.

Reproduction

  1. Ensure ~/.local/share/opencode/auth.json has real data.
  2. Run bun run --cwd packages/opencode test.
  3. Observe auth.json replaced with test credentials.

Root Cause

packages/opencode/test/preload.ts imports Global before XDG/OPENCODE_TEST_HOME env vars are set, so xdg-basedir resolves to the real home directory.

Proposed Fix

  • Move the Global import to after the test env vars are configured so tests write into the temp XDG data directory.
  • Add a guard to fail fast if Global.Path.data isn’t under the temp test dir.
Originally created by @CasualDeveloper on GitHub (Jan 24, 2026). Originally assigned to: @rekram1-node on GitHub. ## Problem Running `bun run --cwd packages/opencode test` overwrites the user's `~/.local/share/opencode/auth.json` instead of keeping writes in a test sandbox. ## Reproduction 1. Ensure `~/.local/share/opencode/auth.json` has real data. 2. Run `bun run --cwd packages/opencode test`. 3. Observe `auth.json` replaced with test credentials. ## Root Cause `packages/opencode/test/preload.ts` imports `Global` before XDG/OPENCODE_TEST_HOME env vars are set, so `xdg-basedir` resolves to the real home directory. ## Proposed Fix - Move the `Global` import to after the test env vars are configured so tests write into the temp XDG data directory. - Add a guard to fail fast if Global.Path.data isn’t under the temp test dir.
yindo closed this issue 2026-02-16 18:07:09 -05:00
Author
Owner

@CasualDeveloper commented on GitHub (Jan 25, 2026):

Fixed on dev by e3c1861a3 (preload no longer imports Global, so XDG is never read before test env setup). Closing as obsolete.

@CasualDeveloper commented on GitHub (Jan 25, 2026): Fixed on dev by `e3c1861a3` (preload no longer imports Global, so XDG is never read before test env setup). Closing as obsolete.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#7433