Repository navigation
fix(test): assert unlock persistence, not the keychain fallback file - #31
Merged
bsreeram08 merged 1 commit intoSep 18, 2026
Conversation
TestCollectionMigrateCommandCanPassphraseProtectFiles asserted that a local collection.key exists after UnlockCollection. That file is only written when caching the derived key in the OS keychain fails, so the assertion fails on any machine with a working keychain and `go test ./...` is red on macOS. CI never caught it: the only workflow running the suite is review.yml on ubuntu-latest, where the keychain call fails, the fallback writes the file, and the test passes. Assert what both paths guarantee instead -- a freshly constructed FileStore reads the collection and its decrypted secrets without the passphrase. That holds for the keychain path and the local-key fallback alike, so the suite is green on both platforms without weakening the check. Issue: bsreeram08#30
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.
Summary
go test ./...is red on macOS on a cleanmastercheckout. This makes it green on bothplatforms without weakening the test.
TestCollectionMigrateCommandCanPassphraseProtectFilesasserted that a localcollection.keyfile exists afterUnlockCollection. That file is only written on thekeychain-unavailable fallback path —
internal/storage/collection_crypto.go:151:So on any machine with a working OS keychain the key is cached there, no file is written,
and the assertion fails:
Why CI stayed green. The only workflow that runs the suite is
review.ymlonubuntu-latest. There the keychain call fails, the fallback fires,collection.keyiswritten, and the test passes. The failure is only visible to someone running the suite on a
Mac — which is what
CONTRIBUTING.mdtells contributors to do.The test predates the keychain cache (#27) and encodes the old persistence mechanism.
The change. Assert the contract rather than the implementation: after
UnlockCollection,a freshly constructed
FileStorereads the collection and its decrypted secrets without thepassphrase. That is true on both paths — keychain on macOS, local key file on Linux.
No coverage is lost, and none was unique to this test. The keychain/fallback branching is
already tested deterministically at the layer that owns it, using the project's existing
in-memory keyring stub (
withMemoryCollectionKeyring/withFailingSetCollectionKeyringininternal/storage/collection_crypto_test.go):TestFileStoreUnlockCachesPassphraseKey— the keychain-success pathTestFileStoreUnlockFallsBackToLocalKeyWhenKeychainUnavailable— the fallback path, including the localcollection.keyassertionThose pin the keyring explicitly, so they verify both branches on every platform. The
command-level test was duplicating that assertion one layer up without the stub, which is
why it was at the mercy of whatever the host's keychain happened to do. Removing the
duplicated assertion leaves the mechanism covered where it is covered properly, and leaves
the command test asserting what a command test should: the user-visible outcome.
Deliberately unchanged: the earlier assertion that
collection.keyis absent beforeunlock (correct on both platforms), and all production code. The keychain-first design looks
right; only the test's expectation was wrong.
Fixes #30
Testing
macOS 15.7.5 arm64, go1.26.3 darwin/arm64.
Before, on
master:After, targeted:
Full suite, plus formatting and vet:
I could not directly verify the Linux fallback path on this machine — I have no Linux box
here. The reasoning is that
saveCollectionWithLocalKeyFallbackclearsEncryptionandsaves the collection with a local key, so
GetCollectionByNamefrom a fresh store succeedsthere too; the
review.ymlrun on this PR should confirm it onubuntu-latest.