Skip to content

fix(test): add test environment isolation for worktree and RTK tests#3467

Open
OfficialDelta wants to merge 1 commit intogsd-build:mainfrom
OfficialDelta:fix/test-environment-isolation
Open

fix(test): add test environment isolation for worktree and RTK tests#3467
OfficialDelta wants to merge 1 commit intogsd-build:mainfrom
OfficialDelta:fix/test-environment-isolation

Conversation

@OfficialDelta
Copy link
Copy Markdown
Contributor

TL;DR

What: Fixes 13 test failures caused by test environment leaking into assertions.
Why: Tests read ~/.gsd/preferences.md (master vs main mismatch) and inherit GSD_RTK_DISABLED from the environment, causing failures on developer machines that pass in CI.
How: Added _resetServiceCache() for git service isolation, HOME override for preference isolation, and GSD_RTK_DISABLED cleanup in RTK tests.

What

  • worktree.ts: Added _resetServiceCache() to allow tests to clear cached GitServiceImpl
  • tests/integration/test-isolation.ts: Shared test isolation utilities
  • 5 worktree test files: Isolate from global ~/.gsd/preferences.md by resetting service cache and overriding HOME
  • 2 RTK test files: Clear GSD_RTK_DISABLED before running, restore after

Why

These 13 tests pass in CI (clean environment) but fail on developer machines where:

  • Global preferences set git.main_branch: master but test repos use main
  • GSD_RTK_DISABLED=1 is set, causing RTK snapshot tests to fail

Verified: all 13 failures are reproducible on current main and resolved by these changes.

How

Test isolation pattern: each affected test suite resets cached services in beforeEach and restores environment in afterEach. The _resetServiceCache() export is test-only (prefixed with underscore per convention).

Note: ~40 integration tests in tests/integration/ have the same git checkout master issue. This PR fixes unit tests only — integration test isolation is a follow-up.

- worktree.ts: Added _resetServiceCache() to allow tests to clear cached GitServiceImpl
- tests/integration/test-isolation.ts: Shared test isolation utilities
- 5 worktree test files: Isolate from global ~/.gsd/preferences.md by resetting service cache and overriding HOME
- 2 RTK test files: Clear GSD_RTK_DISABLED before running, restore after

These 13 tests pass in CI (clean environment) but fail on developer machines where:
- Global preferences set git.main_branch: master but test repos use main
- GSD_RTK_DISABLED=1 is set, causing RTK snapshot tests to fail
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 3, 2026

🟡 PR Risk Report — MEDIUM

Files changed 9
Systems affected 1
Overall risk 🟡 MEDIUM

Affected Systems

Risk System
🟡 medium Worktree
File Breakdown
Risk File Systems
🟡 src/resources/extensions/gsd/worktree.ts Worktree
src/resources/extensions/gsd/tests/integration/test-isolation.ts (unclassified)
src/resources/extensions/gsd/tests/stale-worktree-cwd.test.ts (unclassified)
src/resources/extensions/gsd/tests/stash-pop-gsd-conflict.test.ts (unclassified)
src/resources/extensions/gsd/tests/stash-queued-context-files.test.ts (unclassified)
src/resources/extensions/gsd/tests/worktree-integration.test.ts (unclassified)
src/resources/extensions/gsd/tests/worktree.test.ts (unclassified)
src/tests/rtk-session-stats.test.ts (unclassified)
src/tests/rtk.test.ts (unclassified)

@github-actions github-actions bot added bug Something isn't working test labels Apr 3, 2026
@jeremymcs
Copy link
Copy Markdown
Collaborator

Hey @OfficialDelta — heads up that this PR currently has failing CI checks (windows-portability). The branch will need a fix before it can merge. Let us know if you need help diagnosing the failure.

🤖 Automated PR audit — 2026-04-04

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants