test: harden read-after-write in secret-store export/restore tests - #28
Merged
Conversation
The Keychain Export/Restore tests read back with Assert.Single(await ExportCredentialsAsync()) immediately after an Add/Restore. ExportCredentialsAsync enumerates the whole app via QueryAllItemsForApp, and a just-completed add isn't always visible to that query yet under concurrent (multi-targeted) macOS runs — so RestoreCredentialAsync_PreservesAccountIdAndSelection flaked with "Assert.Single() Failure: The collection was empty" on a macOS leg. Same add-visibility race we already fixed for the delete assertions; extend the fix to the read-after-write points. Adds RetryHelper.UntilAsync<T>(action, predicate) and wraps the six ExportCredentialsAsync read-backs across the Keychain and libsecret suites so they poll for the item to become visible. Returns the last result, so a genuine failure still surfaces via the assertion. 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.
Surfaced by PR #27's macOS leg:
KeychainCredentialManagerTests.RestoreCredentialAsync_PreservesAccountIdAndSelectionfailed withAssert.Single() Failure: The collection was empty.Cause
The Export/Restore tests read back via
Assert.Single(await ExportCredentialsAsync())right after anAdd/Restore.ExportCredentialsAsyncenumerates the whole app (QueryAllItemsForApp), and a just-completed add isn't always visible to that query yet when the two multi-targeted test processes hit one login keychain concurrently. Same add-visibility race we already fixed for the delete assertions — just not applied to these read-after-write points.Fix (test-only)
RetryHelper.UntilAsync<T>(action, predicate).ExportCredentialsAsyncread-backs (Keychain ×3, libsecret ×3) so they poll until the item is visible. Returns the last result, so a genuine failure still fails the assertion rather than timing out silently.Independent of PR #27 (editorconfig) — this is a pre-existing latent flake on
main. Once merged, I'll rebase #27 on top so its macOS leg includes the hardening.Verified: 49/49 Keychain+libsecret tests pass locally (libsecret real, Keychain vacuous on Linux).
🤖 Generated with Claude Code