tests: never touch the user's real config, cache, or keychain · Entire

tests: never touch the user's real config, cache, or keychain

4801b30→main·

toothbrush·1mo ago·11 files·+208 added/-5 removed

A test fixture (bob@core.example.com) leaked into a developer's real ~/.config/entire/contexts.json. Unit tests isolated config access only by per-test convention (t.Setenv), and the integration/e2e harnesses spawned the real entire binary with the developer's real environment — no ENTIRE_CONFIG_DIR, no XDG_CACHE_HOME, real HOME, real OS keychain.

Defense in depth:

Sessions

83fe3fd21287View transcript

Changes

11

171 unmodified lines

Do NOT shell out to git init/git commit directly without setting user config and --no-gpg-sign, and do NOT run lifecycle/strategy handlers from the real repo CWD in tests.

Config/Cache/Keyring Isolation in Tests

Tests must never read or write the developer's real ~/.config/entire (contexts.json, version_check.json), ~/.cache/entire (nodes.json, cluster_cores.json, api_discovery.json), or OS keychain. The developer may be using entire for real while tests run.

Spawning subprocesses in tests (TTY detection)

Tests that spawn the real entire or git binary need the child to be non-interactive so prompts don't hang on a developer terminal.

MCLAUDE.md+25

20 unmodified lines

globalConfigDirPath

// globalConfigDirPath returns the expanded path to the global config directory (~/.config/entire). // globalConfigDirPath returns the CLI's global config directory: // $ENTIRE_CONFIG_DIR if set, else ~/.config/entire. Under go test an // unset ENTIRE_CONFIG_DIR resolves to a throwaway per-process directory // instead of the real home (see internal/testdirs). func globalConfigDirPath() (string, error) { if dir := os.Getenv("ENTIRE_CONFIG_DIR"); dir != "" { return dir, nil } if dir, ok := testdirs.Dir("config"); ok { return dir, nil } home, err := os.UserHomeDir() if err != nil { return "", fmt.Errorf("getting home directory: %w", err) } return filepath.Join(home, ".config", "entire"), nil }

DefaultCacheDir

// DefaultCacheDir returns ~/.cache/entire, respecting XDG_CACHE_HOME. // Under go test an unset XDG_CACHE_HOME resolves to a throwaway // per-process directory instead of the real home (see internal/testdirs). func DefaultCacheDir() string { if xdg := os.Getenv("XDG_CACHE_HOME"); xdg != "" { return filepath.Join(xdg, "entire") } if dir, ok := testdirs.Dir("cache"); ok { return filepath.Join(dir, "entire") } home, _ := os.UserHomeDir() //nolint:errcheck // best-effort default return filepath.Join(home, ".cache", "entire") }