fix(test): add test environment isolation for worktree and RTK tests#3467
Open
OfficialDelta wants to merge 1 commit intogsd-build:mainfrom
Open
fix(test): add test environment isolation for worktree and RTK tests#3467OfficialDelta wants to merge 1 commit intogsd-build:mainfrom
OfficialDelta wants to merge 1 commit intogsd-build:mainfrom
Conversation
- 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
Contributor
🟡 PR Risk Report — MEDIUM
Affected Systems
File Breakdown
|
Collaborator
|
Hey @OfficialDelta — heads up that this PR currently has failing CI checks ( 🤖 Automated PR audit — 2026-04-04 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 GitServiceImpltests/integration/test-isolation.ts: Shared test isolation utilitiesWhy
These 13 tests pass in CI (clean environment) but fail on developer machines where:
git.main_branch: masterbut test repos usemainGSD_RTK_DISABLED=1is set, causing RTK snapshot tests to failVerified: 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
beforeEachand restores environment inafterEach. The_resetServiceCache()export is test-only (prefixed with underscore per convention).Note: ~40 integration tests in
tests/integration/have the samegit checkout masterissue. This PR fixes unit tests only — integration test isolation is a follow-up.