A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
Sim: Step lets a dark start in and the turn refuses it (Refs #1725, PR 6) (#3042)
Eyal Golan947c37542636
diff --git a/changelog.d/1725-pr6-dark-step.md b/changelog.d/1725-pr6-dark-step.mdnew file mode 100644index 000000000..162238af1--- /dev/null+++ b/changelog.d/1725-pr6-dark-step.md@@ -0,0 +1,5 @@+- GDD 0.3 starting population (Refs #1725): on the inactive dark start's Historical ledger, ending a turn now runs the+ player's orders on a working copy and reaches the turn itself, which still refuses that game until a later change;+ an order whose system is not ready for the ledger refuses on the copy, so the game is unchanged. Delegated event+ cards are handed over only when one is waiting, and that is still refused. No new-game wiring, so there is no change+ in the game.diff --git a/docs/rules/mvp.md b/docs/rules/mvp.mdindex 0b1993ea2..621eef89e 100644--- a/docs/rules/mvp.md+++ b/docs/rules/mvp.md@@ -414,7 +414,7 @@ R-POW-003: Prisoners are never labour, Money, Arms, housing occupants, jobs or aR-POW-004: An event with `prisoners: <front>` (egypt, jordan, lebanon or syria) is that front's exchange card. It fires only while the front holds prisoners either way, a stored 0 holding nobody (the Jordan card also returns the Iraqi prisoners: the Jordan agreement took over the Iraqi sector, Art. VI, Q-OBJ-1; the ALA and the local forces belong to no front, so no card returns theirs). It has exactly one option and resolves without an RNG draw, like an objective's card. Resolving it moves its sides' prisoners from `PrisonersHeld` to `PrisonersReturned` and adds `mvp.points_per_prisoner_unit_returned` (real value 10) to the score for each population unit returned (Q-POW-2). Nothing scores at the capture (impact plan §4.3 item 3). It holds unchanged under gdd-0.3, played with a synthetic exchange card: a returned unit scores 10 (owner, 1 November 2026, O7: "10 per unit, main (Recommended)"; `PrisonersGdd03Tests.AReturnedUnitScoresTenPoints`); the card fires once, so prisoners taken after it has resolved stay held to the end of the game with no points (27M-19; `PrisonersGdd03Tests.PrisonersTakenAfterTheCardStayHeldWithNoPoints`); and a loaded save pays no return twice (`PrisonersGdd03Tests.ASaveAndReloadCannotPayTwice`).-R-POW-005: A surrendered unit of the player's is added to `GameState.SoldiersHeld` under the side of the engagement's lowest-id attacker. In step 7, after the prisoners eat, the Treasury pays `mvp.held_soldier_cost_per_turn` (real value IL 0.005m) for each population unit held, borrowing what it lacks (R-MONEY-003; Q-POW-4). They come home when that side's front's exchange card resolves, with no score effect. On the dark start's Historical ledger (#1710, #1725 PR 7) the surrender also makes the formation's serving soldier records Captured, in one validated ledger commit after every check. Their captor is that same side: every enemy side with military units (a `unit_types.yaml` side other than `israel` and `""`) is bound as a captor when the Historical ledger is initialized (owner, 8 November 2026: "Winning side, set at start (Recommended)"). Their Home is the formation's region, region only ("Formation's region (Recommended)"). Each keeps its id, history and issued military item, unchanged while held; what happens to the item on return is #2473's (docs/GDD.md Q10; "Stays on record (Recommended)"). `GameState.SoldiersHeld` keeps its count beside the records, and per captor side it must equal the Captured records with that captor: Take and Upkeep check this before any write ("Keep count + check (Recommended)"). The held soldiers keep this Money cost ("Yes, as today (Recommended)"; docs/gdd/military-combat.md calls the exemption non-operative). The records captured are the active soldiers on the formation's target, found as battles find them (`Training.FormationTarget`: an opening formation's `units_1948/<row>`, a trained formation's `formation/<unit id>` from R-TRAIN-003), so a trained formation's soldiers become captives too (owner, 9 November 2026: "Yes, in #1706 (Recommended)"). A formation whose serving records do not number its strength is not refused, and the turn goes on (owner, 9 November 2026: "Go ahead on strength (Recommended)"): with more records than its strength, its strength of them are captured, the lowest ids first (as "Lowest id first (Recommended)" and docs/GDD.md's ascending population ids), and the rest leave service as soldiers sent home do (owner, 9 November 2026: "Sent home (Recommended)"): R-UNIT-005's ledger outcome, by Send home's own code (`Demobilization.RecordsHome`, written in the capture's one ledger commit, `PopulationLedger.Capture`, then `Demobilization.ReturnArms`), with "Nearest city, unemployed (Recommended)", "Settled in (Recommended)", "Keep both (Recommended)", "Back to Arms stock (Recommended)" and "No, records only (Recommended)". Each becomes a free civilian without an assignment, located in the nearest city to the formation's hex by R-UNIT-005's rule (its region plus the city), with reception ticks `reception.turns`, its qualification and combat XP kept, and its issued military item back in the Arms stock once; after the surrender line come Send home's own Why lines, in Send home's order (owner, 9 November 2026: "Yes, reuse Send home's (Recommended)"): its people line (key `sent_home`, "Unit N is sent home: its P people are civilians in <city> now", P the leftover records times `people_per_unit`), then, only when Arms go back, its Arms line ("Yes, one Why line (Recommended)", key `sent_home_arms_returned`). No aggregate city field is written. Every check comes before the first write: the captives and the leftovers change in one validated ledger commit, so a leftover location the ledger does not bind, like an unbound captor, refuses the surrender with nothing written; the Arms go back after that commit. With fewer records than its strength, all of them are captured. On a ledger game `SoldiersHeld` grows by the number of records captured, not by the unit's strength, so the check above still holds; without a ledger it grows by the strength, as before. For a formation whose records do not match its strength, the count held, and with it the Money cost per population unit held, therefore follows the records captured. A surrender to a side that is not a bound captor, or made while the held count already disagrees with the Captured records, is refused: Take throws before it writes anything. Called from combat, the throw comes after the engagement's draw and losses and after any earlier engagement of the same command or turn; on a direct call to `Combat.Strike` or `Combat.Resolve` those writes stay on the state object given. In the game that object is `Simulation.Step`'s clone (`sim/Statecraft.Sim/Simulation.cs:51`; combat's callers are `Simulation.cs:268` and `TurnResolver.cs:20`), so the whole command's or turn's result is discarded and the caller's state is unchanged. Today Step refuses an initialized ledger (`Simulation.cs:48`), so only a direct `Combat.Strike` or `Combat.Resolve` reaches the refusal in combat (`LedgerPrisonersTests.ARefusedCaptureInCombatThrowsAndAPriorCloneIsUnchanged`). `Prisoners.Return` still refuses any initialized ledger, a Historical one included (`LedgerPrisonersTests.ReturnStillRefusesAHistoricalLedger`): it removes the `SoldiersHeld` count but moves no Captured record, so the change that lifts that refusal (#2473) must move the Captured records back in the same commit. Since #1706 the engagement's losses have already removed the surrendering formation's lost records as combat losses (R-COMBAT-006's ledger paragraph).+R-POW-005: A surrendered unit of the player's is added to `GameState.SoldiersHeld` under the side of the engagement's lowest-id attacker. In step 7, after the prisoners eat, the Treasury pays `mvp.held_soldier_cost_per_turn` (real value IL 0.005m) for each population unit held, borrowing what it lacks (R-MONEY-003; Q-POW-4). They come home when that side's front's exchange card resolves, with no score effect. On the dark start's Historical ledger (#1710, #1725 PR 7) the surrender also makes the formation's serving soldier records Captured, in one validated ledger commit after every check. Their captor is that same side: every enemy side with military units (a `unit_types.yaml` side other than `israel` and `""`) is bound as a captor when the Historical ledger is initialized (owner, 8 November 2026: "Winning side, set at start (Recommended)"). Their Home is the formation's region, region only ("Formation's region (Recommended)"). Each keeps its id, history and issued military item, unchanged while held; what happens to the item on return is #2473's (docs/GDD.md Q10; "Stays on record (Recommended)"). `GameState.SoldiersHeld` keeps its count beside the records, and per captor side it must equal the Captured records with that captor: Take and Upkeep check this before any write ("Keep count + check (Recommended)"). The held soldiers keep this Money cost ("Yes, as today (Recommended)"; docs/gdd/military-combat.md calls the exemption non-operative). The records captured are the active soldiers on the formation's target, found as battles find them (`Training.FormationTarget`: an opening formation's `units_1948/<row>`, a trained formation's `formation/<unit id>` from R-TRAIN-003), so a trained formation's soldiers become captives too (owner, 9 November 2026: "Yes, in #1706 (Recommended)"). A formation whose serving records do not number its strength is not refused, and the turn goes on (owner, 9 November 2026: "Go ahead on strength (Recommended)"): with more records than its strength, its strength of them are captured, the lowest ids first (as "Lowest id first (Recommended)" and docs/GDD.md's ascending population ids), and the rest leave service as soldiers sent home do (owner, 9 November 2026: "Sent home (Recommended)"): R-UNIT-005's ledger outcome, by Send home's own code (`Demobilization.RecordsHome`, written in the capture's one ledger commit, `PopulationLedger.Capture`, then `Demobilization.ReturnArms`), with "Nearest city, unemployed (Recommended)", "Settled in (Recommended)", "Keep both (Recommended)", "Back to Arms stock (Recommended)" and "No, records only (Recommended)". Each becomes a free civilian without an assignment, located in the nearest city to the formation's hex by R-UNIT-005's rule (its region plus the city), with reception ticks `reception.turns`, its qualification and combat XP kept, and its issued military item back in the Arms stock once; after the surrender line come Send home's own Why lines, in Send home's order (owner, 9 November 2026: "Yes, reuse Send home's (Recommended)"): its people line (key `sent_home`, "Unit N is sent home: its P people are civilians in <city> now", P the leftover records times `people_per_unit`), then, only when Arms go back, its Arms line ("Yes, one Why line (Recommended)", key `sent_home_arms_returned`). No aggregate city field is written. Every check comes before the first write: the captives and the leftovers change in one validated ledger commit, so a leftover location the ledger does not bind, like an unbound captor, refuses the surrender with nothing written; the Arms go back after that commit. With fewer records than its strength, all of them are captured. On a ledger game `SoldiersHeld` grows by the number of records captured, not by the unit's strength, so the check above still holds; without a ledger it grows by the strength, as before. For a formation whose records do not match its strength, the count held, and with it the Money cost per population unit held, therefore follows the records captured. A surrender to a side that is not a bound captor, or made while the held count already disagrees with the Captured records, is refused: Take throws before it writes anything. Called from combat, the throw comes after the engagement's draw and losses and after any earlier engagement of the same command or turn; on a direct call to `Combat.Strike` or `Combat.Resolve` those writes stay on the state object given. In the game that object is `Simulation.Step`'s clone (`sim/Statecraft.Sim/Simulation.cs:52`; combat's callers are `Simulation.cs:311`, a chosen event option's attack in `EventSystem.Choose` at `EventSystem.cs:347`, and `TurnResolver.cs:21`), so the whole command's or turn's result is discarded and the caller's state is unchanged. Since #1725 PR 6, Step takes a dark start's Historical ledger (`Simulation.cs:49`, R-POP-002), so a player's attack order runs `Combat.Strike` on that clone (`Simulation.cs:311`) and can reach the refusal there; if no order refuses, the turn then refuses the Historical ledger at `TurnResolver.cs:16`, before its step-2 `Combat.Resolve`. Either way the throw ends the Step and the caller's state is unchanged. An event option's attack is not reached on a ledger game: `EventSystem.Choose` refuses any initialized ledger at its entry (`EventSystem.cs:207`), and a waiting card is refused at `EventSystem.Delegate`'s entry (`EventSystem.cs:520`). So in the game only a player's attack order reaches the refusal in combat, and otherwise only a direct `Combat.Strike` or `Combat.Resolve` does (`LedgerPrisonersTests.ARefusedCaptureInCombatThrowsAndAPriorCloneIsUnchanged`). `Prisoners.Return` still refuses any initialized ledger, a Historical one included (`LedgerPrisonersTests.ReturnStillRefusesAHistoricalLedger`): it removes the `SoldiersHeld` count but moves no Captured record, so the change that lifts that refusal (#2473) must move the Captured records back in the same commit. Since #1706 the engagement's losses have already removed the surrendering formation's lost records as combat losses (R-COMBAT-006's ledger paragraph).Under gdd-0.3 (#1710), the prisoners in these pins come from a real surrender (R-POW-001). `PrisonersGdd03Tests.PrisonersEatAndAFoodShortfallCostsCohesion` pins R-POW-002, `PrisonersGdd03Tests.PrisonersAreNeverAResource` pins R-POW-003, and `PrisonersGdd03Tests.OwnSoldiersAreCapturedCostMoneyAndComeHome` pins R-POW-005. The real per-front exchange cards wait on #751, so the return and homecoming pins use the synthetic card until those cards land. On the dark start, `LedgerPrisonersTests` pins R-POW-001, R-POW-002 and R-POW-005 against the aggregate start with the same counts.@@ -617,7 +617,7 @@ These contracts cover #1689 steps 1–2 and the Historical start inventory (R-POR-POP-001: Only exact `gdd-0.3` enables the population-ledger capability, independently of the broad GDD loop and Attention (R-LOOP-002/005). An immutable own-population record has a dedicated nonnegative ordinal id. Synthetic fixture inventory is ordered by source key (ordinal string comparison), then within-source ordinal. Registered arrivals allocate monotonically; only explicit combat losses remove living ids. Sources remain registered after loss, and ids are never reused. Reconciliation checks the exact created-minus-lost id set against the living ledger, not just equal totals. Status/region counts include every matching record once. The gdd-0.3 scale of a synthetic or Open fixture reads one positive Agreed integer from `population.people_per_unit` in its catalogue (currently 10,000, Open mode's scale under D2); a Historical fixture reads `rules.yaml`'s `people_per_unit` for the start day (1,000), as R-UNIT-006 does (owner, 1 November 2026, D2: "Approve all six (Recommended)", "The Historical MVP keeps main's start: census cities at 1,000 people a unit (`R-CITY-007`)"; R-POP-004); rows with a `census/`, `units_1948/` or `field/` source key are the Historical start's and are refused in any other fixture. Old identities retain the common rules scale. Missing, fractional, nonpositive, overflowing or Deferred values have no fallback, in either source.-R-POP-002: A ledger record has exactly one typed status and assignment, validated location, home and captor references, whole reception-turn ticks capped by the catalogue requirement, civilian profession-specific tier and actual-work XP, separate military qualification/combat XP, and distinct issued civilian/military equipment and paid facts. Unknown references, unresolved teacher ids, incompatible statuses/assignments, inconsistent region/hex/facility bindings, invalid progress/tiers and duplicate issued-item ownership are refused before mutation. Moves and atomic status/location/assignment transitions retain identity/history. Capture retains home context without inventing a prison hex or refunding equipment. Ledger changes never touch resources, causes, RNG or Attention. Initialization is internal and fixture-only; initialized ledger fixtures refuse aggregate Simulation commands and turns. The dark start (#1725 PR 5) is the internal, fixture-only `Simulation.NewGame` overload that initializes the Historical ledger (R-POP-004) in place before `Pools.Init`: `Pools.Init` then reads the ledger's need, one ration for each living own population id (R-FOOD-001, #2470), after the ledger reconciles, and `StartingForces.Init` places the forces once each own starting formation's strength is its ledger soldiers, refusing otherwise. Both read only a ledger initialized with mode Historical, the dark start's; a synthetic or Open ledger is refused by both, as by the other aggregate systems, with the state unchanged. An aggregate system whose own rule says it runs on that Historical ledger (#1725 PR 7: civilian upkeep, R-MONEY-002, the first, and food_supply's stock term, R-FOOD-003; training, R-TRAIN-001 to R-TRAIN-004; military upkeep, R-UNIT-010; arms workshops, R-ARMS-005 and R-ARMS-006; Send home, R-UNIT-005) also reads only that ledger; a synthetic or Open ledger is still refused by it. Prisoners.Take and Prisoners.Upkeep are such systems (#1710, R-POW-001, R-POW-002, R-POW-005): a capture turns the surrendered formation's serving records into captives with their captor and home, all or nothing, and records no loss. `EventSystem.Trigger` still refuses a ledger, so a dark start fires no opening event; the public `NewGame` is unchanged. The step-7 Food settlement given a month's synthetic context is another exception to that refusal: it reads its need from that month's frozen snapshot (R-FOOD-002, #2470). The live month snapshot (`Gdd03SyntheticMonthContext.CreateLive`, #1725 PR 7; owner, 8 November 2026, "One snapshot per turn (Recommended)") reads only a ledger initialized with mode Historical and changes no record; a synthetic or Open ledger and an aggregate game are refused (R-FOOD-002). The step-6 harvest given that live month (`Pools.Harvest`, R-FIELD-002, #1694) also runs on that ledger: it reads only a ledger initialized with mode Historical, a synthetic or Open ledger is still refused by it, and without a month it is refused on any initialized ledger. Old identities refuse ledger mutation. Prices, progression awards, return destinations, tool lock-in and captive-equipment outcomes remain with their owning issues. A craftsman's tier is novice, apprentice or expert (R-CRAFT-003); a farmer's or pioneer's is novice, trained or veteran.+R-POP-002: A ledger record has exactly one typed status and assignment, validated location, home and captor references, whole reception-turn ticks capped by the catalogue requirement, civilian profession-specific tier and actual-work XP, separate military qualification/combat XP, and distinct issued civilian/military equipment and paid facts. Unknown references, unresolved teacher ids, incompatible statuses/assignments, inconsistent region/hex/facility bindings, invalid progress/tiers and duplicate issued-item ownership are refused before mutation. Moves and atomic status/location/assignment transitions retain identity/history. Capture retains home context without inventing a prison hex or refunding equipment. Ledger changes never touch resources, causes, RNG or Attention. Initialization is internal and fixture-only. `Simulation.Step` takes a game whose ledger was initialized with mode Historical, the dark start's, and only that (#1725 PR 6; owner, 8 November 2026, [Draft 10](https://github.com/eyalgolan/statecraft-israel/issues/1725#issuecomment-6725370294), "Historical mode alone (Rec.)"): it runs the turn's orders on its working copy, and an order whose system is not ledger-ready refuses there with that system's guard, so the game is unchanged ("Yes, unready refuses (Rec.)"). It hands over delegated event cards only when one is waiting, and a waiting card is still refused ("Only if none pending (Rec.)"). `TurnResolver.Resolve`, `Simulation.Preview` and `Simulation.DelegatedTo` still refuse any initialized ledger until a separate dark-turn PR ("Separate dark-turn PR (Rec.)"), so a Step on a dark start ends refused by the turn with the game unchanged. A synthetic or Open ledger is refused at Step's entry as before. Saving a dark game waits for #1725 PR 8 ("Not yet, PR 8 (Rec.)", R-POP-003). The dark start (#1725 PR 5) is the internal, fixture-only `Simulation.NewGame` overload that initializes the Historical ledger (R-POP-004) in place before `Pools.Init`: `Pools.Init` then reads the ledger's need, one ration for each living own population id (R-FOOD-001, #2470), after the ledger reconciles, and `StartingForces.Init` places the forces once each own starting formation's strength is its ledger soldiers, refusing otherwise. Both read only a ledger initialized with mode Historical, the dark start's; a synthetic or Open ledger is refused by both, as by the other aggregate systems, with the state unchanged. An aggregate system whose own rule says it runs on that Historical ledger (#1725 PR 7: civilian upkeep, R-MONEY-002, the first, and food_supply's stock term, R-FOOD-003; training, R-TRAIN-001 to R-TRAIN-004; military upkeep, R-UNIT-010; arms workshops, R-ARMS-005 and R-ARMS-006; Send home, R-UNIT-005) also reads only that ledger; a synthetic or Open ledger is still refused by it. Prisoners.Take and Prisoners.Upkeep are such systems (#1710, R-POW-001, R-POW-002, R-POW-005): a capture turns the surrendered formation's serving records into captives with their captor and home, all or nothing, and records no loss. `EventSystem.Trigger` still refuses a ledger, so a dark start fires no opening event; the public `NewGame` is unchanged. The step-7 Food settlement given a month's synthetic context is another exception to that refusal: it reads its need from that month's frozen snapshot (R-FOOD-002, #2470). The live month snapshot (`Gdd03SyntheticMonthContext.CreateLive`, #1725 PR 7; owner, 8 November 2026, "One snapshot per turn (Recommended)") reads only a ledger initialized with mode Historical and changes no record; a synthetic or Open ledger and an aggregate game are refused (R-FOOD-002). The step-6 harvest given that live month (`Pools.Harvest`, R-FIELD-002, #1694) also runs on that ledger: it reads only a ledger initialized with mode Historical, a synthetic or Open ledger is still refused by it, and without a month it is refused on any initialized ledger. Old identities refuse ledger mutation. Prices, progression awards, return destinations, tool lock-in and captive-equipment outcomes remain with their owning issues. A craftsman's tier is novice, apprentice or expert (R-CRAFT-003); a farmer's or pioneer's is novice, trained or veteran.R-POP-003: Clone copies all ledger containers; immutable records and frozen bindings may be shared. The canonical writer emits a gdd-0.3-only section ordered by numeric population id, with fixed field order, stable machine tokens, invariant integer formatting and length-prefixed reference strings. It covers every record/assignment/equipment/reference field, binding, creation/loss provenance and allocator even after the last combat loss. Legacy/gdd-0.1 emit no ledger section or allocator marker. A location's optional city (a `regions.yaml` member location of its region that is a census city of `cities.yaml` or one of that region's field hosts, where R-POP-004 houses own people: a settlement hosts only F19 and F20, owner, 7 November 2026, #1689: "These two only (Recommended)"; any other, including a locality, a `sites.yaml` id or a map location, is refused when a fixture is created, naming the city and the region, R-POP-002) is written after its other fields as `|city=` with a length-prefixed id, only when set, as R-UNIT-002's `|home=` is, so a location without a city keeps its canonical text and hash. R-SAVE-001/002 still govern identity mismatch refusal and replay: no ledger snapshot or new command syntax is added in this foundation, and fixture injection is not replay evidence. Existing unpublished schema-4 draft hashes change; no migration promise is made.diff --git a/sim/Statecraft.Sim.Tests/DarkStepTests.cs b/sim/Statecraft.Sim.Tests/DarkStepTests.csnew file mode 100644index 000000000..f03cfdfc5--- /dev/null+++ b/sim/Statecraft.Sim.Tests/DarkStepTests.cs@@ -0,0 +1,107 @@+using System;+using System.Collections.Generic;+using System.Linq;+using Statecraft.Sim;++/// <summary>#1689 / #1725 PR 6: Simulation.Step on a dark start. Step lets in a game whose ledger was initialized with+/// mode Historical (owner, 8 November 2026, #1725 Draft 10: "Historical mode alone (Rec.)"), runs its orders on the working+/// copy, and reaches the turn, which still refuses the ledger ("Separate dark-turn PR (Rec.)"). A synthetic ledger is+/// still refused at Step's entry. Nothing here mutates the caller's state.</summary>+public class DarkStepTests+{+ const string DarkTurnHeld = "The dark turn is held";++ static Content Gdd03() => HistoricalPopulationTests.Real(true);++ static GameState Dark(Content c) => Simulation.NewGame(c, 1, Mode.Historical, darkStart: true);++ // R-POP-002: a dark start passes Step's entry and is refused by TurnResolver.Resolve, by its own message, with the+ // input unchanged; a synthetic fixture ledger is still refused at the entry, by the aggregate guard's message.+ [Fact]+ public void StepLetsADarkStartInAndTheTurnRefusesIt()+ {+ var c = Gdd03();+ var s = Dark(c);+ var hash = s.Hash();+ var text = s.Describe();+ var e = Assert.Throws<NotSupportedException>(() => Simulation.Step(c, s, Array.Empty<Command>()));+ Assert.Contains(DarkTurnHeld, e.Message);+ Assert.Contains("integration is held", e.Message);+ Assert.Equal(hash, s.Hash());+ Assert.Equal(text, s.Describe());++ var synthetic = PopulationLedgerTests.State(new PopulationInventoryRow("start", 0, PopulationLedgerTests.Person()));+ var before = synthetic.Hash();+ var refused = Assert.Throws<NotSupportedException>(() => Simulation.Step(PopulationLedgerTests.Content(), synthetic, Array.Empty<Command>()));+ Assert.DoesNotContain(DarkTurnHeld, refused.Message);+ Assert.Equal(before, synthetic.Hash());+ }++ // R-POP-002, R-ENEMY-005 ("Only if none pending (Rec.)"): Step skips EventSystem.Delegate on a ledger game only when no+ // card is waiting; a waiting card still reaches Delegate's own guard, which refuses before the turn, input unchanged.+ [Fact]+ public void ADarkStartWithAWaitingCardIsStillRefusedAtDelegate()+ {+ var c = Gdd03();+ var s = Dark(c).Clone();+ s.PendingEvents.Add(c.Events[0].Id);+ var hash = s.Hash();+ var e = Assert.Throws<NotSupportedException>(() => Simulation.Step(c, s, Array.Empty<Command>()));+ Assert.DoesNotContain(DarkTurnHeld, e.Message);+ Assert.Contains("integration is held", e.Message);+ Assert.Equal(hash, s.Hash());+ }++ public static IEnumerable<object[]> CommandKinds() =>+ CommandGuardTests.Samples.Keys.OrderBy(t => t.Name, StringComparer.Ordinal).Select(t => new object[] { t.Name });++ // R-POP-002 ("Yes, unready refuses (Rec.)"): every order kind runs on the working copy of a dark start; one whose+ // system is not ledger-ready refuses there with its guard's NotSupportedException, and the turn refuses the rest.+ // No other exception type, and the caller's state is unchanged.+ [Theory]+ [MemberData(nameof(CommandKinds))]+ public void EveryOrderOnADarkStartRefusesWithTheGameUnchanged(string kind)+ {+ var c = Gdd03();+ var s = Dark(c);+ var hash = s.Hash();+ var cmd = CommandGuardTests.Samples.Single(x => x.Key.Name == kind).Value;+ var e = Record.Exception(() => Simulation.Step(c, s, new[] { cmd }));+ Assert.NotNull(e);+ Assert.IsType<NotSupportedException>(e);+ Assert.Equal(hash, s.Hash());+ }++ // R-POP-003, docs/determinism.md ("Not yet, PR 8 (Rec.)": PR 6 checks only that two runs of the same dark start give+ // the same result): two fresh dark starts given the same orders end the same way and keep the same hash.+ [Fact]+ public void TwoRunsOfTheSameDarkStartGiveTheSameResult()+ {+ foreach (var orders in new[] { Array.Empty<Command>(), new Command[] { new UnitOrder(1, "fortify") } })+ {+ var c1 = Gdd03(); var a = Dark(c1);+ var c2 = Gdd03(); var b = Dark(c2);+ Assert.Equal(a.Hash(), b.Hash());+ var ea = Assert.Throws<NotSupportedException>(() => Simulation.Step(c1, a, orders));+ var eb = Assert.Throws<NotSupportedException>(() => Simulation.Step(c2, b, orders));+ Assert.Equal(ea.Message, eb.Message);+ Assert.Equal(a.Hash(), b.Hash());+ Assert.Equal(a.Describe(), b.Describe());+ }+ }++ // R-POP-002 ("Separate dark-turn PR (Rec.)"): Preview and DelegatedTo still refuse any initialized ledger at their entry,+ // a dark start included, with the state unchanged.+ [Fact]+ public void PreviewAndDelegatedToStillRefuseADarkStart()+ {+ var c = Gdd03();+ var s = Dark(c);+ var hash = s.Hash();+ var p = Assert.Throws<NotSupportedException>(() => Simulation.Preview(c, s, Array.Empty<Command>()));+ var d = Assert.Throws<NotSupportedException>(() => Simulation.DelegatedTo(c, s, Array.Empty<Command>(), c.Events[0].Id));+ Assert.DoesNotContain(DarkTurnHeld, p.Message);+ Assert.DoesNotContain(DarkTurnHeld, d.Message);+ Assert.Equal(hash, s.Hash());+ }+}diff --git a/sim/Statecraft.Sim.Tests/LedgerArmsWorkshopTests.cs b/sim/Statecraft.Sim.Tests/LedgerArmsWorkshopTests.csindex caa09c20d..844bd3736 100644--- a/sim/Statecraft.Sim.Tests/LedgerArmsWorkshopTests.cs+++ b/sim/Statecraft.Sim.Tests/LedgerArmsWorkshopTests.cs@@ -19,7 +19,7 @@ using Statecraft.Sim;/// staffed workshop in ascending project id; unstaffing releases the workers of the higher project ids./// Q8 "Keep tier field (Rec.)": Workshop.WorkerTier is the priced tier, set from the record at staffing and at each new/// cycle; no new field.-/// The tests call Workshops and Cities directly: Simulation.Step and TurnResolver.Resolve still refuse a ledger game.</summary>+/// The tests call Workshops and Cities directly: the turn (TurnResolver.Resolve) still refuses a ledger game.</summary>public class LedgerArmsWorkshopTests{const string Haifa = "haifa";diff --git a/sim/Statecraft.Sim.Tests/LedgerHalutzLinkTests.cs b/sim/Statecraft.Sim.Tests/LedgerHalutzLinkTests.csindex 3dda26398..8afe6cc49 100644--- a/sim/Statecraft.Sim.Tests/LedgerHalutzLinkTests.cs+++ b/sim/Statecraft.Sim.Tests/LedgerHalutzLinkTests.cs@@ -14,7 +14,7 @@ using Statecraft.Sim;/// first then lowest id, and they go back to region-only with no city, as at graduation./// - "Yes, keep the link (Recommended)": a veteran pioneer unit made by promotion keeps the link, and a returned veteran/// record counts for the veteran track.-/// The tests call Training and Qualification directly: Simulation.Step still refuses a ledger game (R-POP-002).</summary>+/// The tests call Training and Qualification directly: the turn (TurnResolver.Resolve) still refuses a ledger game (R-POP-002).</summary>public class LedgerHalutzLinkTests{const string TelAviv = "tel_aviv";diff --git a/sim/Statecraft.Sim.Tests/LedgerSendHomeTests.cs b/sim/Statecraft.Sim.Tests/LedgerSendHomeTests.csindex 1e8b8c252..d50c25381 100644--- a/sim/Statecraft.Sim.Tests/LedgerSendHomeTests.cs+++ b/sim/Statecraft.Sim.Tests/LedgerSendHomeTests.cs@@ -14,7 +14,7 @@ using Statecraft.Sim;/// - "No, records only (Recommended)": no aggregate city field is written./// The owner's ruling, 8 November 2026, "Yes, one Why line (Recommended)": Send home writes one Why line naming the Arms/// returned to the stock, as training's Cancel does (R-TRAIN-002).-/// The tests call Demobilization.Give directly: Simulation.Step and TurnResolver.Resolve still refuse a ledger game.</summary>+/// The tests call Demobilization.Give directly: the turn (TurnResolver.Resolve) still refuses a ledger game.</summary>public class LedgerSendHomeTests{static Content Gdd03() => HistoricalPopulationTests.Real(true);diff --git a/sim/Statecraft.Sim.Tests/LedgerTrainingTests.cs b/sim/Statecraft.Sim.Tests/LedgerTrainingTests.csindex 9453e06d4..2642b150b 100644--- a/sim/Statecraft.Sim.Tests/LedgerTrainingTests.cs+++ b/sim/Statecraft.Sim.Tests/LedgerTrainingTests.cs@@ -15,7 +15,7 @@ using Statecraft.Sim;/// 8. "Enforce it here (Rec.)": camp capacity, 50 records per camp city, over all military tracks./// 9. "Start + runtime bind (Rec.)": the start facilities' Course targets are bound at Initialize, plus one all-or-nothing/// runtime BindTarget for new formations and built camps.-/// The tests call Training directly: Simulation.Step and TurnResolver.Resolve still refuse a ledger game (R-POP-002).</summary>+/// The tests call Training directly: the turn (TurnResolver.Resolve) still refuses a ledger game (R-POP-002).</summary>public class LedgerTrainingTests{const string TelAviv = "tel_aviv";diff --git a/sim/Statecraft.Sim/Qualification.cs b/sim/Statecraft.Sim/Qualification.csindex 03e4bb7ba..8201228bd 100644--- a/sim/Statecraft.Sim/Qualification.cs+++ b/sim/Statecraft.Sim/Qualification.cs@@ -77,7 +77,7 @@ namespace Statecraft.SimRefusedNoQualification = "There is no such qualification";// #1725: the refusal only a Historical ledger game gives. Internal, not a Refused* constant: no player reaches it yet- // (Simulation.Step still refuses a ledger game, R-POP-002), and the UI string follows when it does.+ // (the turn, TurnResolver.Resolve, still refuses a ledger game, R-POP-002), and the UI string follows when it does./// <summary>Owner, 9 November 2026, "Refuse for now (Recommended)": ReturnCraftsmen and ReassignCraftsmen are refused/// with a plain reason until #2476 makes craftsmen exist on the ledger (the Historical start has none, and the craftsman/// course is refused until then, Training.LedgerRefusedCraftsman).</summary>diff --git a/sim/Statecraft.Sim/Simulation.cs b/sim/Statecraft.Sim/Simulation.csindex d74b0c170..919db659d 100644--- a/sim/Statecraft.Sim/Simulation.cs+++ b/sim/Statecraft.Sim/Simulation.cs@@ -44,8 +44,9 @@ namespace Statecraft.Simif (state == null) throw new ArgumentNullException(nameof(state));if (commands == null) throw new ArgumentNullException(nameof(commands));if (commands.Any(x => x == null)) throw new ArgumentException("Commands cannot contain null.", nameof(commands));- // R-POP-002: fixture ledger producers/consumers are not integrated with the aggregate loop.- PopulationLedger.RefuseAggregate(state);+ // R-POP-002 (#1725 PR 6, owner 8 November 2026, "Historical mode alone (Rec.)"): a dark start's Historical ledger+ // comes in, and an order whose system is not ledger-ready refuses on the clone; a synthetic or Open ledger does not.+ PopulationLedger.RefuseUnlessHistorical(state);CommandText.Validate(commands);var s = state.Clone();@@ -61,8 +62,10 @@ namespace Statecraft.Simvar attacked = new Dictionary<int, AttackRecord>();var actions = new List<OperationAction>();RunOrders(c, s, commands, spent, attacked, why, rejected, actions);- // A delegated card's unit orders share the turn's movement and attacks (R-ENEMY-005, R-ENEMY-008).- EventSystem.Delegate(c, s, why, spent, rejected, actions, attacked);+ // A delegated card's unit orders share the turn's movement and attacks (R-ENEMY-005, R-ENEMY-008). On a ledger game+ // only a waiting card is handed over, and Delegate still refuses it (R-POP-002, "Only if none pending (Rec.)").+ if (!s.PopulationLedger.IsInitialized || s.PendingEvents.Count > 0)+ EventSystem.Delegate(c, s, why, spent, rejected, actions, attacked);var len = SecuritySystem.TurnLengthFor(c, s.Date, s.Rung);// The next era's start, or the game's end (the last era's end, or mvp.end in the GDD loop, R-LOOP-004), is adiff --git a/sim/Statecraft.Sim/Training.cs b/sim/Statecraft.Sim/Training.csindex fea08eff2..7377fc071 100644--- a/sim/Statecraft.Sim/Training.cs+++ b/sim/Statecraft.Sim/Training.cs@@ -44,7 +44,7 @@ namespace Statecraft.Simpublic const string RefusedArms = "{0}: not enough Arms for {1} (need {2}, have {3})";// #1725 PR 7, producer 12: the refusals only a Historical ledger game gives. Internal, not Refused* constants: no- // player reaches them yet (Simulation.Step still refuses a ledger game, R-POP-002), and the UI strings follow when it+ // player reaches them yet (the turn, TurnResolver.Resolve, still refuses a ledger game, R-POP-002), and the UI strings follow when it// does./// <summary>Owner, 8 November 2026, "Recruit+crews+halutz (Rec.)" (#1725 issuecomment-6724941867): the craftsman track is refused with a plain reason until #2476.</summary>internal const string LedgerRefusedCraftsman = "Craft training does not run on the population ledger yet (#2476)";diff --git a/sim/Statecraft.Sim/TurnResolver.cs b/sim/Statecraft.Sim/TurnResolver.csindex 995c73dcf..96b80b861 100644--- a/sim/Statecraft.Sim/TurnResolver.cs+++ b/sim/Statecraft.Sim/TurnResolver.cs@@ -13,6 +13,7 @@ namespace Statecraft.Sim/// of a year long).</summary>public static void Resolve(Content c, GameState s, DateTime next, double yearFraction, List<Cause> why){+ if (s.PopulationLedger.IsHistorical) throw new NotSupportedException("The dark turn is held: TurnResolver.Resolve does not run a Historical ledger game yet; gdd-0.3 integration is held."); // #1725 PR 6 until the dark-turn PR (R-POP-002)PopulationLedger.RefuseAggregate(s);if (!c.IsGdd) return;var r = c.RulesAt(s.Date).Mvp!; // the loader requires it in the GDD loopdiff --git a/sim/Statecraft.Sim/Workshops.cs b/sim/Statecraft.Sim/Workshops.csindex ef46af6cc..b64898e73 100644--- a/sim/Statecraft.Sim/Workshops.cs+++ b/sim/Statecraft.Sim/Workshops.cs@@ -140,7 +140,7 @@ namespace Statecraft.Simkey: CauseKeys.WorkshopWorkers, args: new[] { CauseKeys.Number(count) });// #1725 PR 7, producer 07: the refusal only a Historical ledger game gives. Internal, not a Refused* constant: no- // player reaches it yet (Simulation.Step still refuses a ledger game, R-POP-002), and the UI string follows when it does.+ // player reaches it yet (the turn, TurnResolver.Resolve, still refuses a ledger game, R-POP-002), and the UI string follows when it does./// <summary>Owner, 8 November 2026, Q7 "Unassigned, lowest id (Rec.)": more newly staffed workshops than the city's/// unassigned free-civilian records.</summary>internal const string LedgerRefusedFree = "{0} has {1} free civilians without an assignment";