Skip to content

test: harden read-after-write in secret-store export/restore tests - #28

Merged
StuartMeeks merged 1 commit into
mainfrom
fix/flaky-keychain-export-tests
Aug 21, 2026
Merged

test: harden read-after-write in secret-store export/restore tests#28
StuartMeeks merged 1 commit into
mainfrom
fix/flaky-keychain-export-tests

Conversation

@StuartMeeks

Copy link
Copy Markdown
Owner

Surfaced by PR #27's macOS leg: KeychainCredentialManagerTests.RestoreCredentialAsync_PreservesAccountIdAndSelection failed with Assert.Single() Failure: The collection was empty.

Cause

The Export/Restore tests read back via Assert.Single(await ExportCredentialsAsync()) right after an Add/Restore. ExportCredentialsAsync enumerates 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)

  • Add RetryHelper.UntilAsync<T>(action, predicate).
  • Wrap the six ExportCredentialsAsync read-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

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>
@StuartMeeks
StuartMeeks merged commit 3cb9f44 into main Aug 21, 2026
9 checks passed
@StuartMeeks
StuartMeeks deleted the fix/flaky-keychain-export-tests branch August 21, 2026 05:22
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