From 087050fa2532c603d2922ef4943c93a989dda1d8 Mon Sep 17 00:00:00 2001 From: Eric Rakestraw Date: Sat, 24 Oct 2026 19:18:13 +0000 Subject: [PATCH] Isolate user configuration discovery tests by platform --- docs/roadmap/remediation.md | 12 +++++-- internal/engine/discovery_load_test.go | 49 +++++++++++--------------- 2 files changed, 30 insertions(+), 31 deletions(-) diff --git a/docs/roadmap/remediation.md b/docs/roadmap/remediation.md index 464c515..92afe09 100644 --- a/docs/roadmap/remediation.md +++ b/docs/roadmap/remediation.md @@ -1,6 +1,6 @@ # Configuration Discovery Review Findings -Status: findings 1–2 complete; findings 3–5 remain open. +Status: findings 1–3 complete; findings 4–5 remain open. Reviewed commit: `e50fee2`, including the discovery implementation commits after `424c897`. The review compared the implementation with the @@ -101,7 +101,15 @@ still produce no records. Revise the existing nil-primary assertion accordingly. ## 3. Isolate User-Configuration Preset Tests Using The Platform's Go Convention -Priority: P2. Status: open. +Priority: P2. Status: complete. + +**Completed:** the environment-change test selects the environment variable used +by Go on Windows, macOS/iOS, Plan 9, or other Unix hosts, and obtains both fixture +bases through `os.UserConfigDir`. It remains nonparallel and restores the +environment. The redundant relative-XDG failure assumption was removed; existing +private-helper tests retain portable failure/short-circuit coverage. Focused +tests and `./scripts/check.sh` passed on Linux. The macOS branch was checked +against Go's helper implementation; no native macOS gate was added. **Location:** [discovery_load_test.go](../../internal/engine/discovery_load_test.go), `TestSearchSourceObservesUserConfigEnvironmentChanges`, lines 231–279. diff --git a/internal/engine/discovery_load_test.go b/internal/engine/discovery_load_test.go index ff57e66..ea81e93 100644 --- a/internal/engine/discovery_load_test.go +++ b/internal/engine/discovery_load_test.go @@ -326,21 +326,29 @@ func TestSearchSourceObservesFileChangesBetweenLoads(t *testing.T) { } func TestSearchSourceObservesUserConfigEnvironmentChanges(t *testing.T) { - if runtime.GOOS == "windows" { - t.Setenv("APPDATA", filepath.Join(t.TempDir(), "first")) - } else { - t.Setenv("XDG_CONFIG_HOME", filepath.Join(t.TempDir(), "first")) + setBase := func(directory string) string { + t.Helper() + switch runtime.GOOS { + case "windows": + t.Setenv("AppData", directory) + case "darwin", "ios": + t.Setenv("HOME", directory) + case "plan9": + t.Setenv("home", directory) + default: + t.Setenv("XDG_CONFIG_HOME", directory) + } + base, err := os.UserConfigDir() + if err != nil { + t.Fatal(err) + } + return base } type config struct { Value string `yaml:"value"` } - firstBase := os.Getenv("XDG_CONFIG_HOME") - if runtime.GOOS == "windows" { - firstBase = os.Getenv("APPDATA") - } + firstBase := setBase(filepath.Join(t.TempDir(), "first")) first := writeImportFile(t, firstBase, "app/app.yml", "value: first\n") - secondBase := filepath.Join(t.TempDir(), "second") - second := writeImportFile(t, secondBase, "app/app.yml", "value: second\n") source := SearchConfig("app", UserConfigDirectory()) load := func() string { loaded, err := testLoad[config](source, Options[config]{}) @@ -352,28 +360,11 @@ func TestSearchSourceObservesUserConfigEnvironmentChanges(t *testing.T) { if value := load(); value != "first" { t.Fatalf("first user-config search value = %q (%s)", value, first) } - if runtime.GOOS == "windows" { - t.Setenv("APPDATA", secondBase) - } else { - t.Setenv("XDG_CONFIG_HOME", secondBase) - } + secondBase := setBase(filepath.Join(t.TempDir(), "second")) + second := writeImportFile(t, secondBase, "app/app.yml", "value: second\n") if value := load(); value != "second" { t.Fatalf("updated user-config search value = %q (%s)", value, second) } - - // A reached dynamic base failure is terminal, but an earlier match must - // prevent the invalid environment value from being resolved at all. - direct := writeImportFile(t, t.TempDir(), "direct.yml", "value: direct\n") - if runtime.GOOS == "windows" { - t.Setenv("APPDATA", "relative") - } else { - t.Setenv("XDG_CONFIG_HOME", "relative") - } - early := SearchConfig("app", Searches(Paths(direct), UserConfigDirectory())) - loaded, err := testLoad[config](early, Options[config]{}) - if err != nil || loaded.Config.Value != "direct" { - t.Fatalf("early match with unavailable later base = %#v, %v", loaded, err) - } } func TestSearchSourceObservesWorkingDirectoryChanges(t *testing.T) {