Skip to content

Commit da8b1b5

Browse files
jerryjrxieJerry Xieclaude
authored
fix: isolate diff tests from local dotfiles repo state (#22)
* fix: check all git config scopes, not just --global 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 * test: add test for git config scope fallback 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 * fix: don't check dotfiles repo state when URLs are empty 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. * fix: isolate diff tests via HOME env instead of production code guards Address PR #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 #21) - Remove TestGetGitConfig_FallsBackToAnyScope test (paired with reverted change) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Jerry Xie <jerryxie@Jerrys-MacBook-Air.local> Co-authored-by: Jerry Xie <> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 8173b04 commit da8b1b5

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

internal/diff/compare_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
11
package diff
22

33
import (
4+
"os/exec"
5+
"path/filepath"
46
"testing"
57

68
"github.com/openbootdotdev/openboot/internal/config"
79
"github.com/openbootdotdev/openboot/internal/snapshot"
810
"github.com/stretchr/testify/assert"
11+
"github.com/stretchr/testify/require"
912
)
1013

14+
// isolateHome sets HOME to a temp directory with a clean .dotfiles git repo,
15+
// so tests that call diffDotfiles() don't depend on the developer's local state.
16+
func isolateHome(t *testing.T) {
17+
t.Helper()
18+
tmpDir := t.TempDir()
19+
t.Setenv("HOME", tmpDir)
20+
dotfiles := filepath.Join(tmpDir, ".dotfiles")
21+
cmd := exec.Command("git", "init", dotfiles)
22+
require.NoError(t, cmd.Run())
23+
}
24+
1125
func TestCompareSnapshots_Identical(t *testing.T) {
26+
isolateHome(t)
1227
snap := &snapshot.Snapshot{
1328
Packages: snapshot.PackageSnapshot{
1429
Formulae: []string{"git", "curl"},
@@ -33,6 +48,7 @@ func TestCompareSnapshots_Identical(t *testing.T) {
3348
}
3449

3550
func TestCompareSnapshots_PackageDifferences(t *testing.T) {
51+
isolateHome(t)
3652
system := &snapshot.Snapshot{
3753
Packages: snapshot.PackageSnapshot{
3854
Formulae: []string{"git", "wget"},
@@ -58,6 +74,7 @@ func TestCompareSnapshots_PackageDifferences(t *testing.T) {
5874
}
5975

6076
func TestCompareSnapshots_MacOSDifferences(t *testing.T) {
77+
isolateHome(t)
6178
system := &snapshot.Snapshot{
6279
MacOSPrefs: []snapshot.MacOSPref{
6380
{Domain: "NSGlobalDomain", Key: "AppleShowAllExtensions", Value: "true"},
@@ -83,6 +100,7 @@ func TestCompareSnapshots_MacOSDifferences(t *testing.T) {
83100
}
84101

85102
func TestCompareSnapshots_DevToolDifferences(t *testing.T) {
103+
isolateHome(t)
86104
system := &snapshot.Snapshot{
87105
DevTools: []snapshot.DevTool{
88106
{Name: "go", Version: "1.22"},
@@ -111,6 +129,7 @@ func TestCompareSnapshots_DevToolDifferences(t *testing.T) {
111129
}
112130

113131
func TestCompareSnapshotToRemote(t *testing.T) {
132+
isolateHome(t)
114133
system := &snapshot.Snapshot{
115134
Packages: snapshot.PackageSnapshot{
116135
Formulae: []string{"git", "wget"},
@@ -141,6 +160,7 @@ func TestCompareSnapshotToRemote(t *testing.T) {
141160
}
142161

143162
func TestCompareSnapshotToRemote_EmptyRemote(t *testing.T) {
163+
isolateHome(t)
144164
system := &snapshot.Snapshot{
145165
Packages: snapshot.PackageSnapshot{
146166
Formulae: []string{"git"},
@@ -155,6 +175,7 @@ func TestCompareSnapshotToRemote_EmptyRemote(t *testing.T) {
155175
}
156176

157177
func TestCompareSnapshots_MacOSExtraPrefs(t *testing.T) {
178+
isolateHome(t)
158179
system := &snapshot.Snapshot{
159180
MacOSPrefs: []snapshot.MacOSPref{
160181
{Domain: "com.apple.dock", Key: "autohide", Value: "true"},
@@ -177,6 +198,7 @@ func TestCompareSnapshots_MacOSExtraPrefs(t *testing.T) {
177198
}
178199

179200
func TestCompareSnapshots_EmptySnapshots(t *testing.T) {
201+
isolateHome(t)
180202
system := &snapshot.Snapshot{}
181203
reference := &snapshot.Snapshot{}
182204

0 commit comments

Comments
 (0)