Skip to content

test: make setup detection tests hermetic against host-installed apps#214

Merged
joestump merged 1 commit into
mainfrom
claude/heuristic-goldberg-da54e3
Jul 12, 2026
Merged

test: make setup detection tests hermetic against host-installed apps#214
joestump merged 1 commit into
mainfrom
claude/heuristic-goldberg-da54e3

Conversation

@joestump

Copy link
Copy Markdown
Owner

What

Two tests failed on any developer machine that actually has Signal/iMessage/WhatsApp installed, because they assumed the host had none:

  1. internal/setup/detect_test.goTestNewDetectorUsesHome
  2. internal/web/disable_test.goTestEnabledCardShowsCountsAndControls

Both 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 $HOME and probes the well-known macOS store paths. On a machine with the apps installed, those paths exist, so detection reported real apps:

  • TestNewDetectorUsesHome asserted every source reads NotDetected — false on a real Mac.
  • TestEnabledCardShowsCountsAndControls (using the shared newManagedRootServer helper, which didn't inject a detector): the extra detected apps flipped their cards to actionable, so AnyActionable became true and the /providers footer 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.got.Setenv("HOME", t.TempDir()) before NewDetector(), so its real-HOME read resolves to an empty tree. Still asserts NewDetector picks up $HOME (d.Home != "").
  • internal/web/managed_roots_test.go — added srv.SetDetector(setup.Detector{Home: t.TempDir()}) to the shared newManagedRootServer helper (the same SetDetector seam setup_test.go/enable_test.go already 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/ → both ok; go vet clean.
  • Adversarial proof of hermeticity: ran both tests with HOME pointed 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

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>
@joestump joestump merged commit 7cbbe3a into main Jul 12, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant