Repository navigation
refactor(infra): split SimulationDataSeeder into per-phase partials - #1266
Merged
Merged
Conversation
Moves the 2,532-line seeder into ten partial files of the same class, one per seeding phase: the SeedAsync orchestrator and Require helpers, preflight, cast, flocks, accounts, production history, sales, inventory and expenses, manifest expectations, and the manifest with its records. Members move unchanged and in their original order. Fifteen comments that located code in another phase with "above" or "below" now name the partial it lives in. The Playwright spec comment that cited SimulationDataSeeder.cs ~L824 now cites SimulationDataSeeder.Flocks.cs ~L97. The file's FileSizeLimitTests legacy entry is removed. Part of #1215
…ion-seeder # Conflicts: # tests/Cluckwork.Application.Tests/Architecture/FileSizeLimitTests.cs
27 tasks done
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.
Part of #1215
Splits
src/Cluckwork.Infrastructure/Persistence/SimulationDataSeeder.cs(2,532 lines) into ten partial files of the same class, one per seeding phase. The type name, namespace, member names and signatures do not change. No member moved to another type, so every ledger row keyed bySimulationDataSeeder.<Member>still matches. No ledger, adapter or coupling-matrix file changed.SimulationDataSeeder.csSeedAsync,RequirehelpersSimulationDataSeeder.Preflight.csMissingBaseDataAsync,FindOwnerAsyncSimulationDataSeeder.Cast.csSimActor,SimCast,Pick,ActAs,SeedCastAsync,WorkerFor,EnsureUserAsyncSimulationDataSeeder.Flocks.csRestrictOneWorkerAsyncSimulationDataSeeder.Accounts.csSeedPrimaryTimeZoneAsync,SeedSecondAccountAsyncSimulationDataSeeder.ProductionHistory.csLiveBirdsOnDay,EggsOnDay,LoadSaleableGradesAsyncSimulationDataSeeder.Sales.csSimulationDataSeeder.Inventory.csSimulationDataSeeder.ManifestExpectations.csManifestSchemaVersion, the expected-count constants,DrainLockSweepAsync,ExpectedLockedEntryCountSimulationDataSeeder.Manifest.csEmitManifestAsync,ComputeCountsAsync,ComputeExpectedCounts,ValidateCounts, fingerprint, manifest file, and the manifest record typesMembers stay in their original order inside each file. The
FileSizeLimitTestslegacy entry for the old file is removed. One Playwright comment intools/simulation/ui/specs/named-entity-picker.spec.tscitedSimulationDataSeeder.cs ~L824. It now citesSimulationDataSeeder.Flocks.cs ~L97.Pure-move proof
A script cut the partials from
origin/main's file by line range. A second script put them back together in the original order and diffed the result againstorigin/main, ignoring blank lines. Only these lines differ:public sealed class SimulationDataSeeder(becamepublic sealed partial class SimulationDataSeeder(.Blank-line differences occur only at the seams between files. A comment sweep finds 986 of the original's 1,001 comment lines unchanged in the new files. The 15 that are missing are the 15 edited lines above.
git diff --color-moved=plain -w origin/main...HEADshows the same set: moved blocks, the partial wrappers and usings, the keyword, and those 15 comments. Each partial's usings were pruned withdotnet format style --diagnostics IDE0005, which removed onlyusinglines.Seed-dump comparison
This is supporting evidence. The source comparison above is the primary proof.
I seeded four fresh databases in one isolated Postgres container, two from
origin/main(base 1, base 2) and two from this branch (head 1, head 2). Each ranmigrate,bootstrap-admin, thenseed --profile simulationwith default options on the same UTC day. I dumped every table (43 tables, 3,889 rows each).Comparing base 1 with base 2 found the columns that change between two seeds of the same code. I normalized exactly those:
CreatedAtUtcandUpdatedAtUtc, plusAuditEvents.OccurredAtUtc,DailyEntries.LockedAtUtcandsimulation_seed_state.CompletedAtUtc. Only today's timestamps are masked. The default account's fixed 1970 value is compared as is.AuditEvents.DetailsJson, labeled the same way. The rest of the JSON is compared as is.SalesOrders.ReferenceNumber. It isSO-plus the first 8 hex digits of the random order id. The script asserts that before it masks the value.AspNetUsers.PasswordHash,SecurityStampandConcurrencyStamp, which are salted or random.EggLots.Version, plusSequenceonEggLotsandEggInventoryMovements. A per-column check misses theSequencechange, because the same values land on different rows. See the note below.Sequenceon every other table matched without normalization.Results:
8987971d…), and the four completion manifests are byte-identical.So the four runs split into the two outcomes of that tie, and each outcome includes a base run and a head run.
Guard mutations
Each guard went red on its mutation and green again after the file was restored.
ICommerceModuleparameter toSeedSecondAccountAsyncinSimulationDataSeeder.Accounts.csmadeAdapterReachRealTreeTestsreport an undeclared Commerce reach for that member. The type+member key still finds code in a partial.SimulationDataSeeder.Manifest.csto 511 lines madeFileSizeLimitTestsfail with "over the 500-line limit".FileSizeLimitTestsreads only git-tracked files, so a new file is invisible to it until it is staged.Checks run locally
dotnet build Cluckwork.slnx: 0 warnings, 0 errors.dotnet test tests/Cluckwork.Application.Tests --filter "FullyQualifiedName~FileSizeLimitTests|FullyQualifiedName~ModuleLedger|FullyQualifiedName~AdapterReach|FullyQualifiedName~TenantBypass|FullyQualifiedName~AuditVocabulary|FullyQualifiedName~CouplingMatrix|FullyQualifiedName~SeamSurface": 265 passed.dotnet test tests/Cluckwork.Api.IntegrationTests --filter "FullyQualifiedName~Simulation|FullyQualifiedName~AccessSeed|FullyQualifiedName~AccountSlugMigration": 79 passed.Pre-existing, not fixed here
EggLotRepository'sORDER BY "ProductionDate", "Id"(EggLotRepository.cs:57). The ids are random v4 Guids, so which lot an order drains first varies between seeds. In one run the 185-egg lot ends empty and the 161-egg lot keeps 94; in the other run it is the reverse. Counts, totals and the fingerprint do not change.Sequenceorder. Within oneSaveChanges, the egg lots and egg inventory movements of a daily entry are inserted in a different order on each run, so theirSequencevalues attach to different rows. Each row still gets a uniqueSequencein a given database.No UI change, so no screenshots.