cli: isolate the token store in tests so spawned binaries skip the keychain - #1450
Merged
Conversation
…ychain The cli package TestMain mocked the in-process zalando keyring, but several tests spawn the real entire binary (or a git hook that invokes it). testing.Testing() is false in that child, so neither the in-memory keyring mock nor the internal/testdirs fallback applies, and the child's tokenstore default backend reaches the developer's real OS keychain — triggering a macOS unlock prompt during `go test ./cmd/entire/cli/`. Set ENTIRE_TOKEN_STORE=file (plus an isolated token/auth/config/cache path) process-wide in TestMain before m.Run, so spawned children inherit file-backed isolation. Mirrors the integration and e2e TestMains. The in-memory keyring mock stays for in-process legacy auth.NewStore paths. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Entire-Checkpoint: 66eeae1e1ece
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the cmd/entire/cli package’s TestMain to ensure that tests spawning a real entire subprocess don’t fall back to the OS keychain, by enforcing a file-backed token store and isolating config/cache directories under a temp directory.
Changes:
- Configure
ENTIRE_TOKEN_STORE=file(and related env vars/paths) process-wide inTestMainso spawned binaries inherit file-backed isolation. - Add cleanup for the isolation temp directory after tests complete.
- Minor refactor to avoid reusing the
erridentifier for the go-git plugin registration call.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
The deferred os.RemoveAll never ran because TestMain ends with os.Exit(code); the same cleanup already runs explicitly just before the exit. Removing it clears the gocritic exitAfterDefer lint failure. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Entire-Checkpoint: 438e4b46f73c
pfleidi
approved these changes
Jun 17, 2026
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.
https://entire.io/gh/entireio/cli/trails/594
Problem
Running
go test ./cmd/entire/cli/triggers a macOS keychain unlock prompt.The cli package
TestMainmocks the in-process zalando keyring (keyring.MockInit()), but several tests in this package spawn the realentirebinary (or a git hook that invokes it).testing.Testing()is false in that child process, so neither the in-memory keyring mock nor theinternal/testdirsfallback applies there — and the child's tokenstore default backend reaches the developer's real OS keychain.Fix
Set
ENTIRE_TOKEN_STORE=file(plus an isolated token / auth / config / cache path under a temp dir) process-wide inTestMainbeforem.Run, so spawned children inherit file-backed isolation. This mirrors what the integration and e2eTestMains already do. The in-processkeyring.MockInit()stays for legacyauth.NewStorepaths.Verification
go test ./cmd/entire/cli/passes with the external token env vars explicitly unset (env -u ENTIRE_TOKEN_STORE ...), relying solely on theTestMainchange — and no keychain prompt.mise run lint: 0 issues.🤖 Generated with Claude Code
Note
Low Risk
Test-only harness changes with no production code paths; aligns cli package TestMain with existing integration/e2e isolation patterns.
Overview
Fixes macOS keychain unlock prompts when running
go test ./cmd/entire/cli/by extendingTestMainso child processes spawned by tests (realentirebinary or git hooks) no longer hit the OS keychain.In-process
keyring.MockInit()only applies inside the test process; spawned children still used the default token store.TestMainnow creates a temp isolation directory and setsENTIRE_TOKEN_STORE=fileplus paths for token store, auth store, config, and cache beforem.Run(), matching integration and e2e harnesses. The temp dir is removed after tests finish. Plugin registration error handling is slightly refactored to avoid shadowing the newerrfromMkdirTemp.Reviewed by Cursor Bugbot for commit 6a2ed44. Configure here.