From 10fc9803d7d1cd8c4324635720fefa1c119130a0 Mon Sep 17 00:00:00 2001 From: Heimdall Date: Sat, 14 Nov 2026 04:59:44 +0000 Subject: [PATCH] Account merge ledger: test the migration's duplicate current Patron snapshot dedupe Co-Authored-By: Claude Sonnet 5.5 --- .../AccountMergePostgresTests.cs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/Bifrost.Web.Tests/AccountMergePostgresTests.cs b/tests/Bifrost.Web.Tests/AccountMergePostgresTests.cs index db8ecd9..0ec037d 100644 --- a/tests/Bifrost.Web.Tests/AccountMergePostgresTests.cs +++ b/tests/Bifrost.Web.Tests/AccountMergePostgresTests.cs @@ -498,6 +498,29 @@ public sealed class AccountMergePostgresTests(MergePostgres postgres) : IClassFi Assert.Equal(2, snapshots.Count); // the winner's, demoted by the retry, and the retry's own } + [PostgresFact] + public async Task The_migration_keeps_only_the_newest_of_duplicate_current_patron_snapshots_before_it_builds_the_index() + { + var world = await postgres.NewWorldAsync(); + var patron = await world.AccountAsync("patron"); + await using var db = world.Db(); + await db.GetService().MigrateAsync("20261113120000_AddPasskeyCredentials"); // the index does not exist yet + var membership = await db.Memberships.SingleAsync(x => x.UserAccountId == patron.Id); + TierSnapshot Snapshot(string label, int minutes) => new() + { + MembershipId = membership.Id, Kind = TierSnapshotKind.Patron, Label = label, Weight = 1m, IsCurrent = true, + EffectiveFromUtc = AccountMergeLedgerTests.T0, CapturedAtUtc = AccountMergeLedgerTests.T0.AddMinutes(minutes) + }; + db.TierSnapshots.AddRange(Snapshot("older", 0), Snapshot("newer", 5)); + await db.SaveChangesAsync(); + + await db.GetService().MigrateAsync(); + + await using var read = world.Db(); + Assert.Equal("newer", (await read.TierSnapshots.SingleAsync(x => x.IsCurrent)).Label); + Assert.Equal(2, await read.TierSnapshots.CountAsync()); + } + [PostgresFact] public async Task A_journalled_patron_intake_takes_the_next_seq_after_the_commits_entries_and_is_idempotent() {