test: make setup detection tests hermetic against host-installed apps#214
Merged
Conversation
TestNewDetectorUsesHome (internal/setup) and TestEnabledCardShowsCountsAndControls (internal/web) both exercised the real setup.NewDetector(), which roots at the actual $HOME and probes the well-known macOS store paths. On a dev box with Signal/iMessage/WhatsApp installed those paths exist, so detection reported real apps — the tests passed in CI's app-less Linux but failed on a real macOS box. - internal/setup/detect_test.go: point HOME at an empty temp dir via t.Setenv before NewDetector(), so its real-HOME read is deterministic (still asserts NewDetector picks up $HOME). - internal/web/managed_roots_test.go: inject a temp-HOME setup.Detector into the shared newManagedRootServer helper via the existing SetDetector seam. Signal still reads Enabled via store-presence, which is independent of detection, so the "All detected sources are enabled" footer renders deterministically. Verified by running both tests with HOME pointed at a fake tree containing all three apps' stores (the exact condition that broke them) — both now pass. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
What
Two tests failed on any developer machine that actually has Signal/iMessage/WhatsApp installed, because they assumed the host had none:
internal/setup/detect_test.go—TestNewDetectorUsesHomeinternal/web/disable_test.go—TestEnabledCardShowsCountsAndControlsBoth were pre-existing and environment-sensitive: they passed in CI (clean Linux, no messaging apps) but failed on a real macOS dev box.
Why they failed
Both exercised the real
setup.NewDetector(), which roots at the actual$HOMEand probes the well-known macOS store paths. On a machine with the apps installed, those paths exist, so detection reported real apps:TestNewDetectorUsesHomeasserted every source readsNotDetected— false on a real Mac.TestEnabledCardShowsCountsAndControls(using the sharednewManagedRootServerhelper, which didn't inject a detector): the extra detected apps flipped their cards to actionable, soAnyActionablebecame true and the/providersfooter rendered "Detected sources can be enabled…" instead of the expected "All detected sources are enabled".The fix
Made both hermetic using the injection patterns already in the codebase, rather than depending on host state:
internal/setup/detect_test.go—t.Setenv("HOME", t.TempDir())beforeNewDetector(), so its real-HOME read resolves to an empty tree. Still assertsNewDetectorpicks up$HOME(d.Home != "").internal/web/managed_roots_test.go— addedsrv.SetDetector(setup.Detector{Home: t.TempDir()})to the sharednewManagedRootServerhelper (the sameSetDetectorseamsetup_test.go/enable_test.goalready use). Signal still reads Enabled via store-presence, which is independent of detection.Test-only change; no production code touched.
Verification
go test ./internal/setup/ ./internal/web/→ bothok;go vetclean.HOMEpointed at a fake tree containing all three apps' well-known stores (the exact condition that broke them) — both still PASS. That state is precisely what made them fail before the fix.🤖 Generated with Claude Code