Skip to content

fix: isolate diff tests from local dotfiles repo state#22

Merged
fullstackjam merged 4 commits intoopenbootdotdev:mainfrom
jerryjrxie:fix/diff-test-isolation
Apr 1, 2026
Merged

fix: isolate diff tests from local dotfiles repo state#22
fullstackjam merged 4 commits intoopenbootdotdev:mainfrom
jerryjrxie:fix/diff-test-isolation

Conversation

@jerryjrxie
Copy link
Copy Markdown
Contributor

@jerryjrxie jerryjrxie commented Mar 29, 2026

Summary

Fixes test isolation issue where diff tests failed depending on the user's local ~/.dotfiles git state.

Problem

diffDotfiles() always checks the actual ~/.dotfiles git repository for uncommitted changes. Tests calling CompareSnapshots or CompareSnapshotToRemote would fail unpredictably depending on the developer's local dotfiles state.

Solution

Isolate tests by redirecting HOME to a temp directory with a clean .dotfiles git repo, rather than modifying production code to skip code paths. This ensures all production code paths are fully exercised while keeping tests deterministic.

Also reverts the GetGitConfig() fallback change (belongs in separate PR #21).

Changes

  • Remove early return guard from diffDotfiles() — production code should not be modified for test convenience
  • Add isolateHome() test helper using t.TempDir() + t.Setenv("HOME", tmpDir) + git init
  • Call isolateHome(t) in all diff tests that invoke snapshot comparison functions
  • Revert GetGitConfig() to original form (only --global, no fallback to bare git config)
  • Remove TestGetGitConfig_FallsBackToAnyScope test (paired with reverted change)

Testing

  • All tests pass: make test-unit
  • Verified tests are deterministic regardless of local dotfiles state

🤖 Generated with Claude Code

Jerry Xie and others added 3 commits March 28, 2026 22:31
The previous implementation only checked --global git config, but users
may have their git identity configured in:
- Local repository config (.git/config)
- System config (/etc/gitconfig)
- Other scopes

This change first tries --global, then falls back to checking all scopes
if --global returns empty. This ensures we detect git configuration
regardless of where it's set.

Closes git config detection issue
Adds TestGetGitConfig_FallsBackToAnyScope to verify that GetGitConfig
checks all git config scopes (global, local, system) when looking for
user.name and user.email, not just --global.

Related to git config detection issue
The diffDotfiles function was always checking the local ~/.dotfiles git
state, even when comparing snapshots with empty dotfiles URLs. This
caused test failures when the user's actual dotfiles repo had uncommitted
changes.

Fix: Only check dotfiles repo state if at least one URL is configured.
If both system and reference have empty dotfiles URLs, skip the git state
check entirely.

This makes the tests deterministic and not dependent on the user's local
dotfiles repo state.
@github-actions
Copy link
Copy Markdown

👋 Thanks for opening this pull request!

🎉 This is your first PR to OpenBoot — welcome!

Before merging:

  • Code follows existing patterns in the codebase
  • go build ./... and go vet ./... pass
  • Commit message is clear and descriptive

@fullstackjam will review this soon. Thanks for contributing! 🚀

Copy link
Copy Markdown
Collaborator

@fullstackjam fullstackjam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The goal of isolating tests from local state is correct, but the fix is incomplete:

[HIGH] Early return only handles the all-empty case
The guard only kicks in when both URLs are empty. If one side has a URL configured, the function still reads the real ~/.dotfiles git state, so the test isolation problem isn't fully solved.

[HIGH] The fix should be at the test level, not in production code
The right approach is to isolate the tests themselves: use t.Setenv("HOME", tmpDir) to redirect HOME, then git init a clean fake .dotfiles repo under tmpDir. This gives full control over the test environment without bypassing any production code paths.

[MEDIUM] The system.go change should be a separate PR
The GetGitConfig fallback change is unrelated to test isolation. It's a reasonable fix on its own, but bundling it here makes both changes harder to review and revert independently.

[MEDIUM] assert.IsType(t, "", value) adds no value
The Go type system already guarantees the return type at compile time. Replace this with an assertion on the actual returned value.

@fullstackjam fullstackjam added bug Something isn't working tests Tests only labels Mar 30, 2026
Address PR openbootdotdev#22 review feedback:
- Remove early return guard from diffDotfiles() that bypassed production
  code paths when both URLs are empty
- Add isolateHome() test helper that sets HOME to a temp dir with a clean
  .dotfiles git repo, giving full test isolation without modifying prod code
- Revert GetGitConfig() fallback change (belongs in separate PR openbootdotdev#21)
- Remove TestGetGitConfig_FallsBackToAnyScope test (paired with reverted change)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@fullstackjam fullstackjam merged commit da8b1b5 into openbootdotdev:main Apr 1, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working tests Tests only

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants