Skip to content

Commit a67b2e1

Browse files
authored
feat: certify over-cap simulation fixture bands (#633)
* feat(simulation): certify over-cap fixture bands with exact manifest counts #627 — the simulation fixture now holds more than one page on the three surfaces a farm user walks, and the manifest certifies the exact bands instead of a floor: - 101 customers (3 lifecycle + 97 fillers + lexically-last sentinel) - 102 flocks split 100 Active / 1 Depleted / 1 Archived; the 100-row picker catalog sorts AFTER the two operational houses ("Sim Z …") so the houses stay inside the first 100 BY NAME picker rows and the sentinel sits alone on page two - 55 bird movements: the automatic-mortality baseline (an explicit day loop, 2 per flock on the 12-day test fixture) plus 51 explicit adjustments on Sim House A, natural-keyed (FlockId, Date) - 122 inventory movements account-wide: exactly 120 on the feed item (10 pre-existing + a 110-row +1 adjustment band natural-keyed (InventoryLotId, Date), seeded AFTER the usages/discard so the lot is drawn below its received quantity first) and 2 on the bedding item Manifest schema 2: adds Customers/BirdMovements counts and the Flocks lifecycle split, with exact fail-closed checks, a flock-state reconciliation sum, and states.Flocks folded into the fingerprint. Also re-points the two pre-existing db.Roles line numbers in the tenant-bypass filter-free-set baseline (mechanical, owner-approved). Closes #627 * test(e2e): prove the over-cap fixture's second pages render #627 — three independent Load-more acceptance tests against the certified fixture: the customer book's page-two sentinel customer, Sim House A's bird-movement ledger sentinel (quantity rendered in the flock ledger's Unicode minus form), and the feed item's movement-ledger sentinel ("+1 kg"). Each proves the sentinel is absent on the first page, clicks the surface's translated Load-more exactly once, then asserts the sentinel row with its fixture detail. The absence-before-click assertion is load-bearing: a sentinel on page one means the page size, ordering, or the seeder's counts drifted. Closes #627
1 parent 062a55c commit a67b2e1

6 files changed

Lines changed: 905 additions & 68 deletions

File tree

‎src/Cluckwork.Infrastructure/Persistence/SimulationDataSeeder.cs‎

Lines changed: 418 additions & 26 deletions
Large diffs are not rendered by default.

‎tests/Cluckwork.Api.IntegrationTests/SimulationCrossDayRerunTests.cs‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,12 @@ public async Task Rerun_AfterUtcDayRollover_ConvergesToAlreadySeeded_WithUnchang
179179
}
180180

181181
// Row counts for every date-relative fixture the anchor drives — a shifted
182-
// re-run would inflate at least the daily-entry, egg-lot, and order counts.
183-
private async Task<(int Accounts, int DailyEntries, int EggLots, int SalesOrders)> SnapshotAsync()
182+
// re-run would inflate at least the daily-entry, egg-lot, and order
183+
// counts. #627 extended the snapshot with the over-cap bands (customers,
184+
// flocks, bird movements, inventory movements): a re-run that re-derived
185+
// the earlier placement/opening anchors would duplicate the date-keyed
186+
// rows in exactly these bands.
187+
private async Task<(int Accounts, int DailyEntries, int EggLots, int SalesOrders, int Customers, int Flocks, int BirdMovements, int InventoryMovements)> SnapshotAsync()
184188
{
185189
using var scope = factory.Services.CreateScope();
186190
var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
@@ -191,7 +195,15 @@ public async Task Rerun_AfterUtcDayRollover_ConvergesToAlreadySeeded_WithUnchang
191195
.CountAsync(l => l.AccountId == SeedDefaults.AccountId);
192196
var salesOrders = await db.SalesOrders.IgnoreQueryFilters()
193197
.CountAsync(o => o.AccountId == SeedDefaults.AccountId);
194-
return (accounts, dailyEntries, eggLots, salesOrders);
198+
var customers = await db.Customers.IgnoreQueryFilters()
199+
.CountAsync(c => c.AccountId == SeedDefaults.AccountId);
200+
var flocks = await db.Flocks.IgnoreQueryFilters()
201+
.CountAsync(f => f.AccountId == SeedDefaults.AccountId);
202+
var birdMovements = await db.BirdMovements.IgnoreQueryFilters()
203+
.CountAsync(m => m.AccountId == SeedDefaults.AccountId);
204+
var inventoryMovements = await db.InventoryMovements.IgnoreQueryFilters()
205+
.CountAsync(m => m.AccountId == SeedDefaults.AccountId);
206+
return (accounts, dailyEntries, eggLots, salesOrders, customers, flocks, birdMovements, inventoryMovements);
195207
}
196208
}
197209

‎tests/Cluckwork.Api.IntegrationTests/SimulationSeedCommandTests.cs‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,21 +117,31 @@ public async Task SeedCommand_Simulation_SeedsDataWritesCompleteManifest_AndIsId
117117
var manifest = await ReadManifestAsync(manifestPath);
118118
Assert.True(manifest.Complete);
119119
Assert.False(string.IsNullOrWhiteSpace(manifest.Fingerprint));
120+
// #627 — the on-disk manifest carries schema 2 and every exact
121+
// over-cap band (12-day shallow HistoryDays: automatic mortality
122+
// is 2 per operational flock over days 2..12 where d % 5 == 0,
123+
// so birds = 4 + 51 = 55).
124+
Assert.Equal(2, manifest.SchemaVersion);
125+
AssertManifestBandsExact(manifest);
120126

121127
using var scope = _factory.Services.CreateScope();
122128
var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
123129
var accountCount = await db.Accounts.IgnoreQueryFilters().CountAsync();
124130
Assert.Equal(2, accountCount); // primary + the deterministic second sim account.
125131

126132
// Idempotent through the SAME CLI path — a rerun converges (exit 0),
127-
// never mints a third account, and re-writes an identical manifest.
133+
// never mints a third account, and re-writes an identical manifest
134+
// with the SAME exact bands and fingerprint.
128135
var (exitCode2, stdout2, stderr2) = await RunSeedCommandAsync(manifestPath: manifestPath);
129136
Assert.True(0 == exitCode2, $"expected exit 0 on rerun, got {exitCode2}. stdout={stdout2} stderr={stderr2}");
130137
var accountCountAfterRerun = await db.Accounts.IgnoreQueryFilters().CountAsync();
131138
Assert.Equal(2, accountCountAfterRerun);
132139

133140
var manifestAfterRerun = await ReadManifestAsync(manifestPath);
141+
Assert.Equal(2, manifestAfterRerun.SchemaVersion);
142+
AssertManifestBandsExact(manifestAfterRerun);
134143
Assert.Equal(manifest.Fingerprint, manifestAfterRerun.Fingerprint);
144+
Assert.Equal(manifest.Counts, manifestAfterRerun.Counts);
135145
}
136146
finally
137147
{
@@ -180,4 +190,21 @@ private static async Task<SimulationManifest> ReadManifestAsync(string path)
180190
stream, new JsonSerializerOptions(JsonSerializerDefaults.Web));
181191
return manifest ?? throw new InvalidOperationException($"Failed to deserialize manifest at {path}.");
182192
}
193+
194+
// #627 — the exact bands the simulation seed must certify on disk at this
195+
// fixture's shallow 12-day HistoryDays (automatic mortality: 2 per
196+
// operational flock for d in 3..12 with d % 5 == 0).
197+
private static void AssertManifestBandsExact(SimulationManifest manifest)
198+
{
199+
Assert.Equal(101, manifest.Counts.Customers);
200+
Assert.Equal(102, manifest.Counts.Flocks);
201+
Assert.Equal(100, manifest.LifecycleStates.Flocks.Active);
202+
Assert.Equal(1, manifest.LifecycleStates.Flocks.Depleted);
203+
Assert.Equal(1, manifest.LifecycleStates.Flocks.Archived);
204+
Assert.Equal(55, manifest.Counts.BirdMovements);
205+
Assert.Equal(122, manifest.Counts.InventoryMovementsTotal);
206+
Assert.Equal(2 + 110, manifest.LifecycleStates.InventoryMovements.Adjustment
207+
+ manifest.LifecycleStates.InventoryMovements.Discard);
208+
Assert.Equal(2 * 4, manifest.LifecycleStates.InventoryMovements.Usage);
209+
}
183210
}

0 commit comments

Comments
 (0)