Skip to content

A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.

feat(sim): arms workshops run on a Historical ledger game (#1725 PR 7, producer 07) (#2966)

Eyal Golana425310a9424
diff --git a/changelog.d/1725-pr7-arms-workshops.md b/changelog.d/1725-pr7-arms-workshops.md
new file mode 100644
index 000000000..6ff476919
--- /dev/null
+++ b/changelog.d/1725-pr7-arms-workshops.md
@@ -0,0 +1,5 @@
+- GDD 0.3 starting population (Refs #1725): on the inactive dark start's Historical ledger, the arms workshop staffing
+ order and the monthly workshop step now run on people records: each newly staffed workshop takes the city's
+ lowest-id free civilian with no assignment, who works it on a workshop target of its own, and a cycle is priced at
+ that worker's tier (a craftsman apprentice or expert pays less). A workshop whose worker is gone waits. No new-game
+ wiring, so there is no change in the game.
diff --git a/docs/rules/mvp.md b/docs/rules/mvp.md
index 52924431e..4ded41e4c 100644
--- a/docs/rules/mvp.md
+++ b/docs/rules/mvp.md
@@ -94,7 +94,7 @@ R-SAVE-005: Since #2605 the state records the soft events the cap left waiting (
Each GDD turn resolves in the order of the approved plan's section 2.3 (decision D-A6): production, then housing and Social cohesion, then arrivals.
-R-CITY-001: Under legacy/gdd-0.1, `AssignWorkers(city, role, n)` sets how many of the city's people work in `role` (only `job` exists: a craftsman fills an ordinary job slot, R-CRAFT-002). It is refused, with the state unchanged and the Attention refunded, when the city or role is unknown, `n` is negative, or `n` is above the city's jobs or its civilians and craftsmen. An accepted order turns the city's job default off (R-CITY-009). The legacy loop refuses it before charging Attention. The gdd-0.3 population foundation uses one typed assignment per ledger id (R-POP-002); initialized ledger fixtures refuse this aggregate command path, pending producer integration. Under gdd-0.3 the role `workshop` staffs the city's arms workshops instead (R-ARMS-005), and a `job` count is refused above the city's civilians and craftsmen less its staffed workshops and its builders (R-CITY-011), whose workers hold no job; the job default (R-CITY-009) fills to the same number. Under gdd-0.3 the role `build` puts builders on the city's projects being built (R-CITY-011).
+R-CITY-001: Under legacy/gdd-0.1, `AssignWorkers(city, role, n)` sets how many of the city's people work in `role` (only `job` exists: a craftsman fills an ordinary job slot, R-CRAFT-002). It is refused, with the state unchanged and the Attention refunded, when the city or role is unknown, `n` is negative, or `n` is above the city's jobs or its civilians and craftsmen. An accepted order turns the city's job default off (R-CITY-009). The legacy loop refuses it before charging Attention. The gdd-0.3 population foundation uses one typed assignment per ledger id (R-POP-002); initialized ledger fixtures refuse this aggregate command path, pending producer integration (on a Historical ledger the `workshop` role excepted, R-ARMS-005; #1725 PR 7). Under gdd-0.3 the role `workshop` staffs the city's arms workshops instead (R-ARMS-005), and a `job` count is refused above the city's civilians and craftsmen less its staffed workshops and its builders (R-CITY-011), whose workers hold no job; the job default (R-CITY-009) fills to the same number. Under gdd-0.3 the role `build` puts builders on the city's projects being built (R-CITY-011).
R-CITY-002: Each turn every city's employed units add `employed * income_per_job_per_year * the turn's share of a year` to the Treasury (an employed craftsman earns more, R-CRAFT-002). The gdd-0.3 catalogue's `industry.income` tiers (ordinary or novice / apprentice / expert: 1 / 2 / 3) are multiples of this per-unit rate (owner, 1 November 2026: "Main's base x 0.3's tiers (Recommended)"; #2112). The inactive synthetic fixtures (`Gdd03AssignmentFixture.IndustryRate`, `Gdd03CraftArithmetic`) quote the catalogue multiple itself, not Money; `Gdd03IndustryRates.MoneyPerTurn` converts it, and no live system reads either. A staffed arms workshop's worker is not employed and earns nothing here (R-ARMS-005).
@@ -468,11 +468,11 @@ R-ARMS-003: Recruit training (R-TRAIN-001) takes `arms_per_recruit_group` (1) Ar
R-ARMS-004: Under gdd-0.3 only, the arms workshop (`projects.yaml` `arms_workshop`, #1701) is a city project kind: `StartProject` builds it as R-PROJ-001 to R-PROJ-003 build any kind, for IL 15m and 3 turns (owner, 2 November 2026, #1701 OQ2: "IL 15m, 3 turns (Recommended)"; the gdd-0.3 catalogue's `arms_workshop` cost 15 and work 3). Built, it gives one workshop worker slot (`worker_slots: 1`, the catalogue's `arms_workshop.parts.worker_slots`) and adds no housing, condition or job slots: a workshop gives no Industry job (`docs/gdd/cities.md`, "Arms workshops"). Its row carries `rulesets: [gdd-0.3]`, and the loader leaves it out of every other ruleset's kinds, so a gdd-0.1 game neither lists nor starts it (`StartProject` refuses it as an unknown kind) and its state does not change; the row still moves the content hash. The loader refuses an unknown ruleset id in `rulesets`, `worker_slots` other than 0 or 1, a kind with a worker slot that has capacity, condition or job slots or is not limited to exactly gdd-0.3, and, under gdd-0.3, an `arms_workshop` whose worker slots differ from the catalogue's. It pays no upkeep: R-MONEY-002 has no rate for it (the catalogue's 0.50 is a Default). Its Hebrew name סדנת נשק remains a draft until a native speaker, or an AI-assisted contributor who discloses it, has read it (`name_he_review: agent-checked`, #564; owner, 2 November 2026, #1701 OQ8; owner, 4 November 2026: "AI-assisted can clear it").
-R-ARMS-005: Under gdd-0.3, `AssignWorkers(city, "workshop", n)` is a standing order that staffs the city's first `n` built arms workshops, in ascending project id, and leaves the rest unstaffed (27M-13, owner-approved 1 November 2026: "Any free civilian. The cost tier follows the worker (novice or ordinary / apprentice / expert)."). A newly staffed workshop takes one of the city's civilians and craftsmen who hold no job; the worker stays one of them, with no job, profession or qualification change, is not employed (R-CITY-001) and earns no job income (R-CITY-002). On the aggregate cities every worker is priced at the ordinary or novice tier until the population ledger's tiers are live (owner, 2 November 2026, #1701 OQ6: "Accept all four (Recommended)"; R-POP-004). It is refused, state unchanged, for an unknown city, a negative count, more than the city's built workshops ("Town A has 1 arms workshop"), or more newly staffed workshops than the city's people without a job ("... civilians and craftsmen without a job"); under gdd-0.1 the `workshop` role is refused as "There is no such role", and the legacy loop refuses the order before charging Attention ("That order is not available in this game", R-CITY-001). While the city's job default is on (R-CITY-009), a newly staffed workshop may take its worker from the default's jobs instead: the order is refused only past the city's civilians and craftsmen less its staffed workshops and builders (R-CITY-011) ("... civilians and craftsmen"), the city's employed falls to at most its civilians and craftsmen less the staffed workshops and builders (a `city` cause, "Town: N groups in work"), and the default stays on, filling one job fewer (R-CITY-001; #2270 review fix, 2 November 2026). A number of jobs the player set (default off) is never lowered: there the order needs people without a job. A builder (R-CITY-011) is not one of the city's people without a job for this order. A staffed workshop's worker is not idle: `Train` (R-TRAIN-001) and `ReassignPioneers` (R-QUAL-005) cannot take them, and the Train panel's limit (`Training.Available`) counts a pending `workshop` order's newly staffed workers, never as jobs. An unstaffed workshop keeps its record, paid cost and progress (a pause, R-ARMS-007). There is no limit on workshops per city beyond one project a hex and the starts a turn (R-PROJ-001; #1701 OQ7). `GameState.Workshops` holds every workshop ever staffed, by project id, and is hashed as `wshop[...]` only when it has one (R-LOOP-002). The hex panel of a built workshop (#1722, #1701 slice E) queues it: `Workshops.Check(city, n, pending)` gives the order's own refusal and, with this turn's queue, also counts the city's pending `job` order and its Train and reassignment orders, so a count it accepts is accepted whichever runs first; the jobs stepper's limit (`Cities.MaxWorkers` with the queue) counts a pending `workshop` order's newly staffed workers, as `Training.Available` does. The panel's next-cycle price is `Workshops.NextCyclePrice`, what the production step would charge (R-ARMS-006), shown for a workshop never staffed too, at the ordinary or novice tier, and its cycle length is `Workshops.CycleMonths`. A jobs order past the city's civilians and craftsmen less its staffed workshops is refused with the staffing order's people format, "Town A has N civilians and craftsmen" (#1722 review).
+R-ARMS-005: Under gdd-0.3, `AssignWorkers(city, "workshop", n)` is a standing order that staffs the city's first `n` built arms workshops, in ascending project id, and leaves the rest unstaffed (27M-13, owner-approved 1 November 2026: "Any free civilian. The cost tier follows the worker (novice or ordinary / apprentice / expert)."). A newly staffed workshop takes one of the city's civilians and craftsmen who hold no job; the worker stays one of them, with no job, profession or qualification change, is not employed (R-CITY-001) and earns no job income (R-CITY-002). On the aggregate cities every worker is priced at the ordinary or novice tier until the population ledger's tiers are live (owner, 2 November 2026, #1701 OQ6: "Accept all four (Recommended)"; R-POP-004). It is refused, state unchanged, for an unknown city, a negative count, more than the city's built workshops ("Town A has 1 arms workshop"), or more newly staffed workshops than the city's people without a job ("... civilians and craftsmen without a job"); under gdd-0.1 the `workshop` role is refused as "There is no such role", and the legacy loop refuses the order before charging Attention ("That order is not available in this game", R-CITY-001). While the city's job default is on (R-CITY-009), a newly staffed workshop may take its worker from the default's jobs instead: the order is refused only past the city's civilians and craftsmen less its staffed workshops and builders (R-CITY-011) ("... civilians and craftsmen"), the city's employed falls to at most its civilians and craftsmen less the staffed workshops and builders (a `city` cause, "Town: N groups in work"), and the default stays on, filling one job fewer (R-CITY-001; #2270 review fix, 2 November 2026). A number of jobs the player set (default off) is never lowered: there the order needs people without a job. A builder (R-CITY-011) is not one of the city's people without a job for this order. A staffed workshop's worker is not idle: `Train` (R-TRAIN-001) and `ReassignPioneers` (R-QUAL-005) cannot take them, and the Train panel's limit (`Training.Available`) counts a pending `workshop` order's newly staffed workers, never as jobs. An unstaffed workshop keeps its record, paid cost and progress (a pause, R-ARMS-007). There is no limit on workshops per city beyond one project a hex and the starts a turn (R-PROJ-001; #1701 OQ7). `GameState.Workshops` holds every workshop ever staffed, by project id, and is hashed as `wshop[...]` only when it has one (R-LOOP-002). The hex panel of a built workshop (#1722, #1701 slice E) queues it: `Workshops.Check(city, n, pending)` gives the order's own refusal and, with this turn's queue, also counts the city's pending `job` order and its Train and reassignment orders, so a count it accepts is accepted whichever runs first; the jobs stepper's limit (`Cities.MaxWorkers` with the queue) counts a pending `workshop` order's newly staffed workers, as `Training.Available` does. The panel's next-cycle price is `Workshops.NextCyclePrice`, what the production step would charge (R-ARMS-006), shown for a workshop never staffed too, at the ordinary or novice tier, and its cycle length is `Workshops.CycleMonths`. A jobs order past the city's civilians and craftsmen less its staffed workshops is refused with the staffing order's people format, "Town A has N civilians and craftsmen" (#1722 review). On a game with an initialized Historical ledger (the dark start, R-POP-002; #1725 PR 7) the same order runs on the people records, under the owner's rulings (owner, 8 November 2026): "Keep existing order (Rec.)": `AssignWorkers(city, "workshop", n)` is the order there too, and the order picks the records; every other role is still refused. "Unassigned, lowest id (Rec.)": a workshop no longer staffed first releases its worker record, an unassigned free civilian again in place; then each newly staffed workshop, in ascending project id, takes the city's unassigned free-civilian record (located in the city) with the lowest population id, so the Haifa teacher, the city's last record, is taken last. "Work assignment (Rec.)": that record holds a Work assignment on the target `workshop/<project id>` in the city's region, bound the first time the workshop is staffed (owner, 8 November 2026: "At first staffing (Recommended)"), in the same all-or-nothing ledger commit as the records; it keeps its status, place, profession, tier and XP (Q55). "Keep tier field (Rec.)": the workshop's `WorkerTier` is the record's priced tier (R-ARMS-006), with no new field. The order is refused, state unchanged, for an unknown city, a negative count and more than the city's built workshops as above, and for more newly staffed workshops than those records ("Haifa has N free civilians without an assignment"). "Wait for Industry records (Rec.)": no count of the city's people without a job is made, and no city field is read or written, so the job default's path above (a worker taken from the city's jobs) waits for #1725 PR 3's Industry records. A city with builders (R-CITY-011) is refused, state unchanged and nothing thrown, since builders are not records yet (owner, 8 November 2026: "Refuse with a reason (Recommended)"), with "Haifa has builders on city projects, who are not on the population ledger yet"; this internal English text gets its Hebrew with the UI wiring PR. `Workshops.Check` and the panel's limits are the aggregate game's and are not used there: they still read the city counts, and the workshop UI PR makes them read the records (owner, 8 November 2026: "Fix in the UI PR (Recommended)").
-R-ARMS-006: On step 6 of the turn, after the cities' job income, in ascending project id, each staffed arms workshop under gdd-0.3 works this month when its city is not held (R-CITY-010) and one of the city's people without a job is left for it once step 5's builders have taken theirs (R-CITY-011; each workshop of the city takes one, in ascending project id; when none is left for it, it waits, and the Why screen says so). A workshop with no cycle under way first pays for one there (27M-11: "At the monthly production step."), at its worker's tier from the gdd-0.3 catalogue: `workshop.cost` IL 5m / 4m / 3m (ordinary or novice / apprentice / expert; `docs/GDD.md`'s balance ruling: "`workshop.cost` is Money per Arms and stays."), beside the IL 1m an Arms of R-ARMS-002 (owner, 2 November 2026, #1701 OQ1: "Keep as ruled"). A short Treasury borrows the rest (R-MONEY-003; 27M-12: "Automatic each month while the workshop is staffed, paid like any GDD cost."), but a cycle whose borrowing would take the debt past `debt_ceiling` is not paid: the workshop waits that month, the turn report says why (below), and nothing is borrowed (owner, 2 November 2026, #1701 OQ4: "Refuse past the ceiling (Recommended)"; exactly at the ceiling is allowed, and a Treasury that pays in full is never refused, as in R-ARMS-002). The month a cycle is paid is its first staffed month (#1701 OQ3: "Accept all four (Recommended)"). After `workshop.staffed_turns` (3) staffed months the cycle adds 1 Arms to the stock (R-ARMS-001) and ends, and the next month starts the next one by itself, with no order. When the Arms stock is `int.MaxValue`, a finished cycle waits silently at its completed, paid progress, keeps its worker, and adds no Arms or Why line. A worker change keeps the cycle's paid cost and progress; only the next cycle is priced at the new worker's tier (27M-13). An unstaffed workshop, or one in a held city, keeps its cycle as it is and is not charged. The turn-report panel lists, in a row of its own after the stocks, each Arms a workshop made ("Workshop in Town: +1 Arms") and each ceiling pause ("Workshop in Town paused: debt ceiling") (owner, 2 November 2026, #1701 A1: "Yes, in the panel (Recommended)", the option "The turn-report panel shows 'Workshop in <city>: +1 Arms' and 'Workshop in <city> paused: debt ceiling'."); a no-worker pause is on the Why screen only. A city's Arms are one line and its ceiling pauses another, each with its count when there are two or more ("Workshops in Town (2): +2 Arms", "Workshops in Town (2) paused: debt ceiling"), in the order each first appears among the turn's causes (owner, 2 November 2026: "Combine per city (Recommended)", the option "'Workshops in Tel Aviv (6): +6 Arms'; pauses likewise combined with a count."). The option gives no wording for one workshop, so a city with one keeps A1's line. The count is the number of the sim's causes; the UI computes nothing else.
+R-ARMS-006: On step 6 of the turn, after the cities' job income, in ascending project id, each staffed arms workshop under gdd-0.3 works this month when its city is not held (R-CITY-010) and one of the city's people without a job is left for it once step 5's builders have taken theirs (R-CITY-011; each workshop of the city takes one, in ascending project id; when none is left for it, it waits, and the Why screen says so). A workshop with no cycle under way first pays for one there (27M-11: "At the monthly production step."), at its worker's tier from the gdd-0.3 catalogue: `workshop.cost` IL 5m / 4m / 3m (ordinary or novice / apprentice / expert; `docs/GDD.md`'s balance ruling: "`workshop.cost` is Money per Arms and stays."), beside the IL 1m an Arms of R-ARMS-002 (owner, 2 November 2026, #1701 OQ1: "Keep as ruled"). A short Treasury borrows the rest (R-MONEY-003; 27M-12: "Automatic each month while the workshop is staffed, paid like any GDD cost."), but a cycle whose borrowing would take the debt past `debt_ceiling` is not paid: the workshop waits that month, the turn report says why (below), and nothing is borrowed (owner, 2 November 2026, #1701 OQ4: "Refuse past the ceiling (Recommended)"; exactly at the ceiling is allowed, and a Treasury that pays in full is never refused, as in R-ARMS-002). The month a cycle is paid is its first staffed month (#1701 OQ3: "Accept all four (Recommended)"). After `workshop.staffed_turns` (3) staffed months the cycle adds 1 Arms to the stock (R-ARMS-001) and ends, and the next month starts the next one by itself, with no order. When the Arms stock is `int.MaxValue`, a finished cycle waits silently at its completed, paid progress, keeps its worker, and adds no Arms or Why line. A worker change keeps the cycle's paid cost and progress; only the next cycle is priced at the new worker's tier (27M-13). An unstaffed workshop, or one in a held city, keeps its cycle as it is and is not charged. The turn-report panel lists, in a row of its own after the stocks, each Arms a workshop made ("Workshop in Town: +1 Arms") and each ceiling pause ("Workshop in Town paused: debt ceiling") (owner, 2 November 2026, #1701 A1: "Yes, in the panel (Recommended)", the option "The turn-report panel shows 'Workshop in <city>: +1 Arms' and 'Workshop in <city> paused: debt ceiling'."); a no-worker pause is on the Why screen only. A city's Arms are one line and its ceiling pauses another, each with its count when there are two or more ("Workshops in Town (2): +2 Arms", "Workshops in Town (2) paused: debt ceiling"), in the order each first appears among the turn's causes (owner, 2 November 2026: "Combine per city (Recommended)", the option "'Workshops in Tel Aviv (6): +6 Arms'; pauses likewise combined with a count."). The option gives no wording for one workshop, so a city with one keeps A1's line. The count is the number of the sim's causes; the UI computes nothing else. On a game with an initialized Historical ledger (R-POP-002; #1725 PR 7) a staffed workshop works when its own worker record (R-ARMS-005) is still a free civilian of the workshop's city on its target; a builder never takes that record (R-CITY-011), so no count of the city's people without a job is read (owner, 8 November 2026: "Wait for Industry records (Rec.)"). "Waits, stays staffed (Rec.)": a workshop whose worker is gone waits with the no-worker Why line, stays staffed and is given no other record. "Only craftsmen discount (Rec.)": a new cycle is priced at the record's tier, IL 4m for a craftsman apprentice and IL 3m for an expert, and IL 5m for every other record (profession none, a farmer or pioneer at any tier, a craftsman novice); "Keep tier field (Rec.)": the tier is written to `WorkerTier` when that cycle is priced, and a cycle under way keeps its paid cost. The held-city pause, the payment, the borrowing, the ceiling, the Arms and the Why lines are as above. A synthetic or Open ledger is still refused.
-R-ARMS-007: A workshop's cycle progress is lost and its Money is not refunded on a destructive cancellation, destruction or transfer of the workshop (27M-14, owner-approved 1 November 2026: "Cycle progress is lost and the Money paid is not refunded."). The MVP has none (owner, 2 November 2026, #1701 OQ5: "Accept all four (Recommended)"): a built project cannot be cancelled (R-PROJ-002), a held city pauses (R-CITY-010) and unstaffing pauses (R-ARMS-005), and each keeps the cycle; a later mechanism that destroys or transfers a workshop applies this rule. Workshop work changes no qualification, profession or craftsman count (Q55, owner-approved 1 November 2026: "No. Only the stated apprentice-to-expert progression counts").
+R-ARMS-007: A workshop's cycle progress is lost and its Money is not refunded on a destructive cancellation, destruction or transfer of the workshop (27M-14, owner-approved 1 November 2026: "Cycle progress is lost and the Money paid is not refunded."). The MVP has none (owner, 2 November 2026, #1701 OQ5: "Accept all four (Recommended)"): a built project cannot be cancelled (R-PROJ-002), a held city pauses (R-CITY-010) and unstaffing pauses (R-ARMS-005), and each keeps the cycle; a later mechanism that destroys or transfers a workshop applies this rule. Workshop work changes no qualification, profession or craftsman count (Q55, owner-approved 1 November 2026: "No. Only the stated apprentice-to-expert progression counts"). On a Historical ledger game workshop months give no record work XP yet (owner, 8 November 2026: "Not in this change (Rec.)"); the craft work-XP producer adds them.
## Defeat
@@ -605,7 +605,7 @@ These contracts cover #1689 steps 1–2 and the Historical start inventory (R-PO
R-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) 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). 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; 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) 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). 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/LedgerArmsWorkshopTests.cs b/sim/Statecraft.Sim.Tests/LedgerArmsWorkshopTests.cs
new file mode 100644
index 000000000..caa09c20d
--- /dev/null
+++ b/sim/Statecraft.Sim.Tests/LedgerArmsWorkshopTests.cs
@@ -0,0 +1,454 @@
+using Statecraft.Sim;
+
+/// <summary>#1725 PR 7, producer 07: arms workshops (R-ARMS-005 to R-ARMS-007) staff and produce on a game with an
+/// initialized Historical ledger, the dark start (R-POP-002). A workshop's worker is one named free-civilian record with a
+/// Work assignment on the workshop's own target; the aggregate city fields are neither read nor written. The owner's
+/// rulings, owner, 8 November 2026, each the recommended option of the plan's section 7:
+/// Q1 "Work assignment (Rec.)": the worker holds a Work assignment on a target workshop/&lt;project id&gt;, bound at
+/// runtime, all or nothing (PopulationLedger.Commit, #2964).
+/// Q2 "Keep existing order (Rec.)": AssignWorkers(city, "workshop", n) staffs on a ledger game; the order picks the records.
+/// Q3 "Wait for Industry records (Rec.)": a count of the people without a job waits for PR 3's Industry records, so no such
+/// count is read here: a workshop works when its own bound worker is there (Q6), and staffing takes only records with no
+/// assignment (Q7).
+/// Q4 "Only craftsmen discount (Rec.)": only a craftsman apprentice or expert lowers the price; every other worker pays the
+/// ordinary IL 5m.
+/// Q5 "Not in this change (Rec.)": workshop months give no record work XP.
+/// Q6 "Waits, stays staffed (Rec.)": a staffed workshop whose bound worker is gone waits with the no_worker line, stays
+/// staffed, and is not given another worker.
+/// Q7 "Unassigned, lowest id (Rec.)": the city's unassigned free civilians in ascending population id, one per newly
+/// 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>
+public class LedgerArmsWorkshopTests
+{
+ const string Haifa = "haifa";
+
+ static Content Gdd03() => HistoricalPopulationTests.Real(true);
+
+ static GameState Dark(Content c)
+ {
+ var s = Simulation.NewGame(c, 1, Mode.Historical, darkStart: true);
+ s.Arms = 10; s.Treasury = 100; s.Debt = 0;
+ return s;
+ }
+
+ static GameState Aggregate(Content c)
+ {
+ var s = Simulation.NewGame(c, 1, Mode.Historical);
+ s.Arms = 10; s.Treasury = 100; s.Debt = 0;
+ return s;
+ }
+
+ // A built arms workshop in the city at its settlement hex, as ArmsWorkshopTests injects one. Returns its project id.
+ static int Built(Content c, GameState s, string city)
+ {
+ var h = c.SettlementHexes.First(x => x.Id == city);
+ var id = s.NextId++;
+ s.CityProjects.Add(id, new CityProject(id, Workshops.ArmsWorkshop, city, h.Q, h.R, 0, s.Date));
+ return id;
+ }
+
+ // Q7: the city's free-civilian records with no assignment, ascending id.
+ static List<PopulationUnit> Free(GameState s, string city) => s.PopulationLedger.Units
+ .Where(p => p.Status == PopulationStatus.FreeCivilian && p.Assignment.Kind == PopulationAssignmentKind.Unassigned && p.Location?.City == city)
+ .OrderBy(p => p.Id).ToList();
+
+ static string Target(int project) => "workshop/" + project;
+
+ static List<PopulationUnit> On(GameState s, int project) => s.PopulationLedger.Units
+ .Where(p => p.Assignment.Target == Target(project)).ToList();
+
+ static bool Bound(GameState s, string id) => s.PopulationLedger.Canonical().Any(line =>
+ line.StartsWith("6:target|", StringComparison.Ordinal) && line.Contains(":" + id.Length + ":" + id + "|", StringComparison.Ordinal));
+
+ static string CityText(GameState s) => string.Join(";", s.Cities.Values.Select(x => x.Canonical()));
+
+ static IEnumerable<(string, string, double, string, string)> Lines(IEnumerable<Cause> why) => why.Select(x => (x.System, x.Target, x.Delta, x.Message, x.Key));
+
+ // A record replaced in the ledger with a craftsman's profession and tier (a fixture: no craftsman exists at the dark start).
+ static void MakeCraftsman(GameState s, int id, CivilianTier tier)
+ {
+ var p = s.PopulationLedger.Get(id);
+ s.PopulationLedger.Commit(new[] { new PopulationUnit(p.Id, p.Status, p.ReceptionTicks, p.Location, p.Assignment,
+ CivilianProfession.Craftsman, tier, 0, p.Qualification, p.CombatXp, p.Equipment, p.Captor, p.Home) }, Array.Empty<PopulationTarget>());
+ }
+
+ static (GameState S, int Project, int Worker) Staffed(Content c)
+ {
+ var s = Dark(c);
+ var project = Built(c, s, Haifa);
+ var worker = Free(s, Haifa)[0].Id;
+ Assert.Null(Cities.Assign(c, s, Haifa, Workshops.Role, 1, new List<Cause>()));
+ return (s, project, worker);
+ }
+
+ // Q2 "Keep existing order (Rec.)", Q7 "Unassigned, lowest id (Rec.)", Q1 "Work assignment (Rec.)", Q8 "Keep tier field
+ // (Rec.)" (owner, 8 November 2026): AssignWorkers(haifa, "workshop", 1) staffs the built workshop with the lowest-id
+ // unassigned free civilian of Haifa, now on a Work assignment to workshop/<project id>, bound in the same commit. The
+ // record keeps its place, profession, tier and XP (R-ARMS-005, Q55); the workshop is staffed at the record's tier. No city
+ // field is written, no id is made or lost, and the Why line is the aggregate game's staffing line.
+ [Fact]
+ public void StaffingTakesTheLowestIdUnassignedFreeCivilian()
+ {
+ var c = Gdd03();
+ var s = Dark(c); var twin = Aggregate(c);
+ var project = Built(c, s, Haifa); Assert.Equal(project, Built(c, twin, Haifa));
+ var before = Free(s, Haifa)[0];
+ var cities = CityText(s); var next = s.PopulationLedger.NextPopulationId; var count = s.PopulationLedger.Units.Count;
+ Assert.False(Bound(s, Target(project)));
+ var why = new List<Cause>(); var twinWhy = new List<Cause>();
+
+ Assert.Null(Cities.Assign(c, s, Haifa, Workshops.Role, 1, why));
+ Assert.Null(Cities.Assign(c, twin, Haifa, Workshops.Role, 1, twinWhy));
+
+ var p = s.PopulationLedger.Get(before.Id);
+ Assert.Equal((PopulationStatus.FreeCivilian, PopulationAssignmentKind.Work, Target(project)), (p.Status, p.Assignment.Kind, p.Assignment.Target));
+ Assert.Equal(before.Location!.Canonical(), p.Location!.Canonical());
+ Assert.Equal((before.Profession, before.Tier, before.WorkXp, before.Qualification, before.ReceptionTicks), (p.Profession, p.Tier, p.WorkXp, p.Qualification, p.ReceptionTicks));
+ Assert.True(Bound(s, Target(project)));
+ Assert.Equal(new[] { before.Id }, On(s, project).Select(x => x.Id));
+ Assert.Equal($"{project}:on,Ordinary", s.Workshops[project].Canonical());
+ Assert.Equal(twin.Workshops[project].Canonical(), s.Workshops[project].Canonical());
+ Assert.Equal(cities, CityText(s));
+ Assert.Equal(Lines(twinWhy.Where(x => x.Key == CauseKeys.WorkshopWorkers)), Lines(why));
+ Assert.Equal((next, count), (s.PopulationLedger.NextPopulationId, s.PopulationLedger.Units.Count));
+ s.PopulationLedger.Reconcile();
+ }
+
+ // R-ARMS-005: a staffed workshop's worker is not idle, so Train cannot take them (Training's idle records are the
+ // unassigned ones); re-issuing the same order changes nothing.
+ [Fact]
+ public void TheWorkerIsNotIdleAndTheSameOrderChangesNothing()
+ {
+ var c = Gdd03();
+ var (s, project, worker) = Staffed(c);
+ Assert.DoesNotContain(worker, Free(s, Haifa).Select(x => x.Id));
+ var ledger = s.PopulationLedger.Canonical().ToList(); var shop = s.Workshops[project].Canonical();
+ Assert.Null(Cities.Assign(c, s, Haifa, Workshops.Role, 1, new List<Cause>()));
+ Assert.Equal(ledger, s.PopulationLedger.Canonical());
+ Assert.Equal(shop, s.Workshops[project].Canonical());
+ }
+
+ // Q7 "Unassigned, lowest id (Rec.)" (owner, 8 November 2026): two workshops take the two lowest-id records, in ascending
+ // project id. Lowering the order to 1 releases the higher project's worker, who is an unassigned free civilian again in
+ // place; the workshop keeps its record, paid cost and progress (a pause, R-ARMS-007), and its target stays bound.
+ [Fact]
+ public void TwoWorkshopsTakeTwoRecordsAndUnstaffingReleasesTheHigherProjectsWorker()
+ {
+ var c = Gdd03();
+ var s = Dark(c);
+ var first = Built(c, s, Haifa); var second = Built(c, s, Haifa);
+ var free = Free(s, Haifa).Take(2).ToList();
+ Assert.Null(Cities.Assign(c, s, Haifa, Workshops.Role, 2, new List<Cause>()));
+ Assert.Equal(new[] { free[0].Id }, On(s, first).Select(x => x.Id));
+ Assert.Equal(new[] { free[1].Id }, On(s, second).Select(x => x.Id));
+ Workshops.Produce(c, s, new List<Cause>());
+ var paid = s.Workshops[second];
+ Assert.Equal((5m, 1), (paid.PaidCost, paid.Progress));
+
+ Assert.Null(Cities.Assign(c, s, Haifa, Workshops.Role, 1, new List<Cause>()));
+
+ Assert.Equal(new[] { free[0].Id }, On(s, first).Select(x => x.Id));
+ Assert.Empty(On(s, second));
+ var back = s.PopulationLedger.Get(free[1].Id);
+ Assert.Equal((PopulationAssignmentKind.Unassigned, free[1].Location!.Canonical()), (back.Assignment.Kind, back.Location!.Canonical()));
+ Assert.Equal($"{second}:off,Ordinary/5,1", s.Workshops[second].Canonical());
+ Assert.True(Bound(s, Target(second)));
+ s.PopulationLedger.Reconcile();
+ }
+
+ // R-ARMS-005's refusals on the ledger, each with the state, the ledger and the Why list unchanged: no such city, a negative
+ // count, more than the city's built workshops (the aggregate game's words), and more newly staffed workshops than the
+ // city's unassigned free-civilian records.
+ [Fact]
+ public void RefusalsChangeNothing()
+ {
+ var c = Gdd03();
+ var s = Dark(c);
+ Built(c, s, Haifa);
+ var why = new List<Cause>();
+ string Refusal(string city, int n)
+ {
+ var before = s.Describe(); var hash = s.Hash(); var ledger = s.PopulationLedger.Canonical().ToList();
+ var r = Cities.Assign(c, s, city, Workshops.Role, n, why);
+ Assert.Equal(before, s.Describe()); Assert.Equal(hash, s.Hash()); Assert.Equal(ledger, s.PopulationLedger.Canonical());
+ return r!;
+ }
+ Assert.Equal("There is no such city", Refusal("missing", 1));
+ Assert.Equal(Cities.RefusedNegativeWorkers, Refusal(Haifa, -1));
+ Assert.Equal("Haifa has 1 arms workshop", Refusal(Haifa, 2));
+ Assert.Empty(why);
+
+ // One workshop staffed, then one more built workshop than Haifa has unassigned records left: the order for all of
+ // them is refused with the records' count, and the order for one fewer takes every one of them.
+ var free = Free(s, Haifa);
+ Built(c, s, Haifa);
+ Assert.Null(Cities.Assign(c, s, Haifa, Workshops.Role, 1, why));
+ why.Clear();
+ var left = Free(s, Haifa).Count;
+ for (int i = 0; i < left; i++) Built(c, s, Haifa);
+ Assert.Equal($"Haifa has {left} free civilians without an assignment", Refusal(Haifa, left + 2));
+ Assert.Empty(why);
+ Assert.Null(Cities.Assign(c, s, Haifa, Workshops.Role, left + 1, why));
+ Assert.Empty(Free(s, Haifa));
+ Assert.True(free.Count > left);
+ s.PopulationLedger.Reconcile();
+ }
+
+ // Owner, 8 November 2026: "Refuse with a reason (Recommended)". R-CITY-011's builders are city counts, not records, so a
+ // staffing order in a city with a builder is refused with a shown reason before any write; nothing throws, and the state,
+ // the ledger and the hash are unchanged.
+ [Fact]
+ public void ACityWithABuilderIsRefusedWithAReason()
+ {
+ var c = Gdd03();
+ var s = Dark(c);
+ Built(c, s, Haifa);
+ var h = c.SettlementHexes.First(x => x.Id == Haifa);
+ var site = s.NextId++;
+ s.CityProjects.Add(site, new CityProject(site, "housing", Haifa, h.Q, h.R + 1, 2, builder: true));
+ Assert.Equal(1, Projects.Builders(s, Haifa));
+ var why = new List<Cause>();
+ var before = s.Describe(); var hash = s.Hash(); var ledger = s.PopulationLedger.Canonical().ToList();
+ Assert.Equal("Haifa has builders on city projects, who are not on the population ledger yet", Cities.Assign(c, s, Haifa, Workshops.Role, 1, why));
+ Assert.Equal(before, s.Describe()); Assert.Equal(hash, s.Hash()); Assert.Equal(ledger, s.PopulationLedger.Canonical());
+ Assert.Empty(why);
+ s.PopulationLedger.Reconcile();
+ }
+
+ // R-ARMS-006 (27M-11: "At the monthly production step."; Q4 "Only craftsmen discount (Rec.)", owner, 8 November 2026): the
+ // dark start's workshop, worked by a census record (profession None), pays IL 5m for its first cycle and counts the month.
+ [Fact]
+ public void TheDarkStartsWorkshopPaysAndAdvancesACycle()
+ {
+ var c = Gdd03();
+ var (s, project, _) = Staffed(c);
+ var why = new List<Cause>();
+ Workshops.Produce(c, s, why);
+ Assert.Equal((95.0, 0.0, 10), (s.Treasury, s.Debt, s.Arms));
+ Assert.Equal($"{project}:on,Ordinary/5,1", s.Workshops[project].Canonical());
+ s.PopulationLedger.Reconcile();
+ }
+
+ // R-ARMS-006 (workshop.staffed_turns 3) and Q5 "Not in this change (Rec.)" (owner, 8 November 2026): three staffed months
+ // make 1 Arms and end the cycle; the next month starts the next one by itself. No record changes (no work XP).
+ [Fact]
+ public void ThreeStaffedMonthsMakeOneArms()
+ {
+ var c = Gdd03();
+ var (s, project, _) = Staffed(c);
+ var ledger = s.PopulationLedger.Canonical().ToList();
+ var why = new List<Cause>();
+ for (int i = 0; i < 3; i++) Workshops.Produce(c, s, why);
+ Assert.Equal((11, 95.0), (s.Arms, s.Treasury));
+ Assert.Equal($"{project}:on,Ordinary", s.Workshops[project].Canonical());
+ Assert.Single(why, x => x.Key == CauseKeys.WorkshopArms);
+ Assert.Equal(ledger, s.PopulationLedger.Canonical());
+ Workshops.Produce(c, s, why);
+ Assert.Equal((90.0, $"{project}:on,Ordinary/5,1"), (s.Treasury, s.Workshops[project].Canonical()));
+ }
+
+ // R-MONEY-003 and #1701 OQ4 (owner, 2 November 2026: "Refuse past the ceiling (Recommended)"): a short Treasury borrows
+ // the rest; a cycle whose borrowing would pass mvp.debt_ceiling waits with the debt_ceiling line and nothing borrowed;
+ // exactly at the ceiling is allowed.
+ [Fact]
+ public void AShortTreasuryBorrowsAndThePastCeilingCycleWaits()
+ {
+ var c = Gdd03();
+ var ceiling = c.RulesAt(Dark(c).Date).Mvp!.DebtCeiling!.Value;
+
+ var (s, project, _) = Staffed(c);
+ s.Treasury = 2; s.Debt = 0;
+ Workshops.Produce(c, s, new List<Cause>());
+ Assert.Equal((0.0, 3.0, 1), (s.Treasury, s.Debt, s.Workshops[project].Progress));
+
+ (s, project, _) = Staffed(c);
+ s.Treasury = 2; s.Debt = ceiling - 3;
+ Workshops.Produce(c, s, new List<Cause>());
+ Assert.Equal((0.0, ceiling, 1), (s.Treasury, s.Debt, s.Workshops[project].Progress));
+
+ (s, project, _) = Staffed(c);
+ s.Treasury = 2; s.Debt = ceiling - 2;
+ var shop = s.Workshops[project].Canonical();
+ var why = new List<Cause>();
+ Workshops.Produce(c, s, why);
+ Assert.Equal((2.0, ceiling - 2, shop), (s.Treasury, s.Debt, s.Workshops[project].Canonical()));
+ var line = Assert.Single(why);
+ Assert.Equal((CauseKeys.WorkshopPaused, Workshops.DebtCeiling), (line.Key, line.Args![0]));
+ }
+
+ // R-CITY-010: a workshop in a city the enemy holds is not charged and makes no progress; its cycle is kept.
+ [Fact]
+ public void AHeldCityPausesItsWorkshop()
+ {
+ var c = Gdd03();
+ var (s, project, _) = Staffed(c);
+ Workshops.Produce(c, s, new List<Cause>());
+ var shop = s.Workshops[project].Canonical(); var treasury = s.Treasury;
+ var h = c.SettlementHexes.First(x => x.Id == Haifa);
+ var enemy = s.NextId++;
+ s.Units[enemy] = new Unit(enemy, "enemy", h.Q, h.R, side: "egypt", strength: 1);
+ var why = new List<Cause>();
+ Workshops.Produce(c, s, why);
+ Assert.Equal((treasury, shop), (s.Treasury, s.Workshops[project].Canonical()));
+ Assert.Empty(why);
+ }
+
+ // Q6 "Waits, stays staffed (Rec.)" and Q3 "Wait for Industry records (Rec.)" (owner, 8 November 2026): a staffed workshop
+ // whose bound worker is gone waits with the existing no_worker line, stays staffed, is not charged, and takes no other
+ // record, even with free civilians in the city (no count of people without a job is read).
+ [Fact]
+ public void AWorkshopWhoseWorkerIsGoneWaitsAndStaysStaffed()
+ {
+ var c = Gdd03();
+ var (s, project, worker) = Staffed(c);
+ var p = s.PopulationLedger.Get(worker);
+ s.PopulationLedger.Commit(new[] { p.WithPlacement(p.Status, p.Location, PopulationAssignment.Unassigned, p.Captor, p.Home) }, Array.Empty<PopulationTarget>());
+ var ledger = s.PopulationLedger.Canonical().ToList(); var treasury = s.Treasury;
+ Assert.NotEmpty(Free(s, Haifa).Skip(1));
+ var why = new List<Cause>();
+
+ Workshops.Produce(c, s, why);
+
+ var line = Assert.Single(why);
+ Assert.Equal((CauseKeys.WorkshopPaused, Workshops.NoWorker, project.ToString()), (line.Key, line.Args![0], line.Args![1]));
+ Assert.Equal($"{project}:on,Ordinary", s.Workshops[project].Canonical());
+ Assert.Equal(treasury, s.Treasury);
+ Assert.Equal(ledger, s.PopulationLedger.Canonical());
+ }
+
+ // Q4 "Only craftsmen discount (Rec.)" and Q8 "Keep tier field (Rec.)" (owner, 8 November 2026): the worker record's tier
+ // prices the cycle: a craftsman apprentice IL 4m, an expert IL 3m; a craftsman novice and every other profession pay the
+ // ordinary IL 5m (the Haifa teacher, a veteran pioneer, too).
+ [Theory]
+ [InlineData(CivilianTier.Apprentice, "Apprentice", 4.0)]
+ [InlineData(CivilianTier.Expert, "Expert", 3.0)]
+ [InlineData(CivilianTier.Novice, "Ordinary", 5.0)]
+ public void ACraftsmanWorkersTierSetsThePrice(CivilianTier tier, string priced, double price)
+ {
+ var c = Gdd03();
+ var s = Dark(c);
+ var project = Built(c, s, Haifa);
+ MakeCraftsman(s, Free(s, Haifa)[0].Id, tier);
+ Assert.Null(Cities.Assign(c, s, Haifa, Workshops.Role, 1, new List<Cause>()));
+ Assert.Equal($"{project}:on,{priced}", s.Workshops[project].Canonical());
+ Workshops.Produce(c, s, new List<Cause>());
+ Assert.Equal(100 - price, s.Treasury);
+ }
+
+ [Fact]
+ public void AVeteranPioneerPaysTheOrdinaryPrice()
+ {
+ var c = Gdd03();
+ var s = Dark(c);
+ var teacher = Free(s, Haifa).Single(p => p.Profession == CivilianProfession.Pioneer);
+ Assert.Equal(CivilianTier.Veteran, teacher.Tier);
+ var count = Free(s, Haifa).Count;
+ Assert.Equal(teacher.Id, Free(s, Haifa).Last().Id); // "Takeable, but last": the ascending order reaches it last
+ var shops = Enumerable.Range(0, count).Select(_ => Built(c, s, Haifa)).ToList();
+ Assert.Null(Cities.Assign(c, s, Haifa, Workshops.Role, count, new List<Cause>()));
+ Assert.Equal(new[] { teacher.Id }, On(s, shops.Last()).Select(x => x.Id));
+ Assert.Equal($"{shops.Last()}:on,Ordinary", s.Workshops[shops.Last()].Canonical());
+ }
+
+ // 27M-13 (owner-approved 1 November 2026: "The cost tier follows the worker") with Q8 "Keep tier field (Rec.)": a cycle
+ // under way keeps its paid cost when the worker's tier changes; only the next cycle is priced at the new tier.
+ [Fact]
+ public void ATierChangeKeepsTheCycleUnderWayAndPricesTheNext()
+ {
+ var c = Gdd03();
+ var s = Dark(c);
+ var project = Built(c, s, Haifa);
+ var worker = Free(s, Haifa)[0].Id;
+ MakeCraftsman(s, worker, CivilianTier.Apprentice);
+ Assert.Null(Cities.Assign(c, s, Haifa, Workshops.Role, 1, new List<Cause>()));
+ Workshops.Produce(c, s, new List<Cause>());
+ Assert.Equal($"{project}:on,Apprentice/4,1", s.Workshops[project].Canonical());
+ MakeCraftsman(s, worker, CivilianTier.Expert);
+ Workshops.Produce(c, s, new List<Cause>()); Workshops.Produce(c, s, new List<Cause>());
+ Assert.Equal((96.0, 11, $"{project}:on,Apprentice"), (s.Treasury, s.Arms, s.Workshops[project].Canonical()));
+ Workshops.Produce(c, s, new List<Cause>());
+ Assert.Equal((93.0, $"{project}:on,Expert/3,1"), (s.Treasury, s.Workshops[project].Canonical()));
+ }
+
+ // Parity: an ordinary worker's workshop moves the Treasury, the Debt, the Arms and the Why lines exactly as the aggregate
+ // game's workshop does, month by month, through a cycle and into the next.
+ [Fact]
+ public void DarkAndAggregateMatchForOrdinaryWorkers()
+ {
+ var c = Gdd03();
+ var s = Dark(c); var twin = Aggregate(c);
+ var project = Built(c, s, Haifa); Built(c, twin, Haifa);
+ Assert.Null(Cities.Assign(c, s, Haifa, Workshops.Role, 1, new List<Cause>()));
+ Assert.Null(Cities.Assign(c, twin, Haifa, Workshops.Role, 1, new List<Cause>()));
+ s.Treasury = twin.Treasury = 7; s.Debt = twin.Debt = 0;
+ for (int i = 0; i < 5; i++)
+ {
+ var why = new List<Cause>(); var twinWhy = new List<Cause>();
+ Workshops.Produce(c, s, why); Workshops.Produce(c, twin, twinWhy);
+ Assert.Equal(Lines(twinWhy), Lines(why));
+ Assert.Equal((twin.Treasury, twin.Debt, twin.Arms), (s.Treasury, s.Debt, s.Arms));
+ Assert.Equal(twin.Workshops[project].Canonical(), s.Workshops[project].Canonical());
+ }
+ }
+
+ // R-ARMS-004 worker_slots 1 (#1725 PR 7 review S2): a corrupted ledger with two worker records on one workshop's target
+ // throws before step 6 writes anything. The first workshop in ascending project id is valid, yet it is not paid or
+ // advanced: Treasury, Debt, Arms, every workshop and the ledger are unchanged, and no Why line is added.
+ [Fact]
+ public void ASecondWorkerRecordOnALaterWorkshopThrowsBeforeAnyWrite()
+ {
+ var c = Gdd03();
+ var s = Dark(c);
+ var first = Built(c, s, Haifa); var second = Built(c, s, Haifa);
+ Assert.True(first < second);
+ Assert.Null(Cities.Assign(c, s, Haifa, Workshops.Role, 2, new List<Cause>()));
+ var p = Free(s, Haifa)[0]; // a fixture: a second record on the second workshop's (already bound) target
+ s.PopulationLedger.Commit(new[] { p.WithPlacement(p.Status, p.Location, new PopulationAssignment(PopulationAssignmentKind.Work, Target(second)), p.Captor, p.Home) }, Array.Empty<PopulationTarget>());
+ Assert.Equal((1, 2), (On(s, first).Count, On(s, second).Count));
+ var ledger = s.PopulationLedger.Canonical().ToList();
+ var shops = s.Workshops.Values.Select(w => w.Canonical()).ToList();
+ var money = (s.Treasury, s.Debt, s.Arms);
+ var why = new List<Cause>();
+
+ Assert.Contains("more than one worker record", Assert.Throws<InvalidOperationException>(() => Workshops.Produce(c, s, why)).Message);
+
+ Assert.Equal(money, (s.Treasury, s.Debt, s.Arms));
+ Assert.Equal(shops, s.Workshops.Values.Select(w => w.Canonical()).ToList());
+ Assert.Equal(ledger, s.PopulationLedger.Canonical());
+ Assert.Empty(why);
+ }
+
+ // R-POP-002: on a Historical ledger only the "workshop" role runs; "job" and "build" are still refused before any write.
+ [Theory]
+ [InlineData("job")] [InlineData(Projects.BuildRole)]
+ public void OtherRolesAreStillRefusedOnTheLedger(string role)
+ {
+ var c = Gdd03();
+ var s = Dark(c);
+ var hash = s.Hash();
+ Assert.Contains("integration is held", Assert.Throws<NotSupportedException>(() => Cities.Assign(c, s, Haifa, role, 1, new List<Cause>())).Message);
+ Assert.Equal(hash, s.Hash());
+ }
+
+ // R-POP-002 (#1725 PR 7 review S2): only a ledger initialized with mode Historical is let through. An initialized Open
+ // ledger, like a synthetic one (no mode), is still refused by both entry points, with the state unchanged.
+ [Theory]
+ [InlineData(true, true)] [InlineData(false, true)] [InlineData(true, false)] [InlineData(false, false)]
+ public void AnOpenOrSyntheticLedgerIsStillRefused(bool open, bool produce)
+ {
+ var c = PopulationLedgerTests.Content();
+ var s = PopulationLedger.CreateFixture(c, PopulationLedgerTests.Bindings(),
+ new[] { new PopulationInventoryRow("fixture", 0, PopulationLedgerTests.Person()) }, mode: open ? Mode.Open : null);
+ Assert.Equal((true, false), (s.PopulationLedger.IsInitialized, s.PopulationLedger.IsHistorical));
+ s.CityProjects.Add(0, new CityProject(0, Workshops.ArmsWorkshop, "missing", 0, 0, 0, s.Date));
+ s.Workshops.Add(0, new Workshop(0, true, SyntheticWorkshopTier.Ordinary));
+ s.Treasury = 23; s.Arms = 5;
+ var why = new List<Cause>();
+ var before = s.Describe(); var hash = s.Hash();
+ Action call = produce ? () => Workshops.Produce(c, s, why) : () => Cities.Assign(c, s, "missing", Workshops.Role, 1, why);
+ Assert.Contains("integration is held", Assert.Throws<NotSupportedException>(call).Message);
+ Assert.Equal(before, s.Describe()); Assert.Equal(hash, s.Hash()); Assert.Empty(why);
+ }
+}
diff --git a/sim/Statecraft.Sim/Cities.cs b/sim/Statecraft.Sim/Cities.cs
index 7f2d870ca..e592b9401 100644
--- a/sim/Statecraft.Sim/Cities.cs
+++ b/sim/Statecraft.Sim/Cities.cs
@@ -94,7 +94,9 @@ namespace Statecraft.Sim
/// the job slots or above the civilians and craftsmen. Step has already refused it in the legacy loop.</summary>
public static string? Assign(Content c, GameState s, string city, string role, int count, List<Cause> why)
{
- PopulationLedger.RefuseAggregate(s);
+ // #1725 PR 7, producer 07 (owner, 8 November 2026, Q2 "Keep existing order (Rec.)"): on a Historical ledger game
+ // only the "workshop" role runs (Workshops.Staff picks the records); every other role is still refused (R-POP-002).
+ if (!(s.PopulationLedger.IsHistorical && role == Workshops.Role)) PopulationLedger.RefuseAggregate(s);
if (!s.Cities.TryGetValue(city, out var x)) return "There is no such city";
// R-ARMS-005: under gdd-0.3 the "workshop" role staffs the city's arms workshops.
if (role == Workshops.Role && c.Ruleset == SaveGame.Gdd03Ruleset) return Workshops.Staff(c, s, city, count, why);
diff --git a/sim/Statecraft.Sim/Workshops.cs b/sim/Statecraft.Sim/Workshops.cs
index a899c7b87..ef46af6cc 100644
--- a/sim/Statecraft.Sim/Workshops.cs
+++ b/sim/Statecraft.Sim/Workshops.cs
@@ -111,7 +111,8 @@ namespace Statecraft.Sim
/// for a negative count, more than the city's built workshops, or more newly staffed than its people without a job.</summary>
internal static string? Staff(Content c, GameState s, string city, int count, List<Cause> why)
{
- PopulationLedger.RefuseAggregate(s);
+ PopulationLedger.RefuseUnlessHistorical(s); // #1725 PR 7: on a Historical ledger the workers are records
+ if (s.PopulationLedger.IsHistorical) return LedgerStaff(c, s, city, count, why);
if (Check(c, s, city, count, Array.Empty<Command>()) is string refused) return refused;
var name = PlayerText.Settlement(c, city);
var built = BuiltIn(c, s, city);
@@ -129,8 +130,115 @@ namespace Statecraft.Sim
if (s.Workshops.TryGetValue(built[i].Id, out var w)) { if (w.Staffed != on) s.Workshops[w.Project] = w.WithStaffed(on); }
else if (on) s.Workshops.Add(built[i].Id, new Workshop(built[i].Id, true, AggregateTier));
}
- why.Add(new Cause("city", city, count - staffed, FormattableString.Invariant($"{name}: arms workshops staffed: {count}"),
- key: CauseKeys.WorkshopWorkers, args: new[] { CauseKeys.Number(count) }));
+ why.Add(StaffedLine(city, name, count - staffed, count));
+ return null;
+ }
+
+ /// <summary>R-ARMS-005: a staffing order's Why line, the same for the aggregate cities and a Historical ledger game.</summary>
+ static Cause StaffedLine(string city, string name, int delta, int count) =>
+ new Cause("city", city, delta, FormattableString.Invariant($"{name}: arms workshops staffed: {count}"),
+ key: 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.
+ /// <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";
+
+ /// <summary>Owner, 8 November 2026, "Refuse with a reason (Recommended)": a staffing order in a city with builders
+ /// (R-CITY-011), which are city counts and not records yet.</summary>
+ internal const string LedgerRefusedBuilders = "{0} has builders on city projects, who are not on the population ledger yet";
+
+ /// <summary>Owner, 8 November 2026, Q1 "Work assignment (Rec.)": the Work target a workshop's worker record holds.</summary>
+ internal static string WorkerTarget(int project) => "workshop/" + project.ToString(System.Globalization.CultureInfo.InvariantCulture);
+
+ /// <summary>Owner, 8 November 2026, Q7 "Unassigned, lowest id (Rec.)": the city's free-civilian records with no
+ /// assignment, located in the city, ascending id. A worker (Industry or a workshop), a farmer on a field, a teacher, a
+ /// trainee and a refugee are not among them.</summary>
+ static List<PopulationUnit> LedgerFree(GameState s, string city) => s.PopulationLedger.Units
+ .Where(p => p.Status == PopulationStatus.FreeCivilian && p.Assignment.Kind == PopulationAssignmentKind.Unassigned
+ && string.Equals(p.Location?.City, city, StringComparison.Ordinal)).ToList(); // Units is ascending id
+
+ /// <summary>The records on the workshop's Work target, ascending id: its worker, or none.</summary>
+ static List<PopulationUnit> OnTarget(GameState s, int project)
+ {
+ var target = WorkerTarget(project);
+ return s.PopulationLedger.Units.Where(p => p.Assignment.Kind == PopulationAssignmentKind.Work
+ && string.Equals(p.Assignment.Target, target, StringComparison.Ordinal)).ToList();
+ }
+
+ /// <summary>Owner, 8 November 2026, Q6 "Waits, stays staffed (Rec.)": the workshop's bound worker when it is still a
+ /// free civilian of the workshop's city on its target, else null (the worker is gone and the workshop waits).</summary>
+ static PopulationUnit? LedgerWorker(GameState s, int project, string city)
+ {
+ var on = OnTarget(s, project);
+ if (on.Count > 1) throw new InvalidOperationException("Arms workshop " + project.ToString(System.Globalization.CultureInfo.InvariantCulture) + " has more than one worker record (R-ARMS-004, worker_slots 1).");
+ var p = on.FirstOrDefault();
+ return p != null && p.Status == PopulationStatus.FreeCivilian && string.Equals(p.Location?.City, city, StringComparison.Ordinal) ? p : null;
+ }
+
+ /// <summary>Owner, 8 November 2026, Q4 "Only craftsmen discount (Rec.)": only a craftsman apprentice or expert lowers
+ /// the price; every other record (profession None, a farmer or pioneer at any tier, a craftsman novice) is priced
+ /// Ordinary, IL 5m.</summary>
+ static SyntheticWorkshopTier TierOf(PopulationUnit p) => p.Profession != CivilianProfession.Craftsman ? AggregateTier
+ : p.Tier == CivilianTier.Apprentice ? SyntheticWorkshopTier.Apprentice
+ : p.Tier == CivilianTier.Expert ? SyntheticWorkshopTier.Expert : AggregateTier;
+
+ /// <summary>R-ARMS-005 on a Historical ledger game (#1725 PR 7, producer 07). Owner, 8 November 2026: Q2 "Keep existing
+ /// order (Rec.)", Q7 "Unassigned, lowest id (Rec.)", Q1 "Work assignment (Rec.)", Q8 "Keep tier field (Rec.)". The
+ /// same standing order: the city's first <paramref name="count"/> built workshops, in ascending id, are staffed. A
+ /// workshop no longer staffed releases its worker record (an unassigned free civilian again, in place); then each
+ /// newly staffed workshop, in ascending project id, takes the lowest-id unassigned free civilian of the city, who
+ /// holds a Work assignment on <see cref="WorkerTarget"/> (bound now if it is not yet) with no profession, tier or XP
+ /// change (Q55), and the workshop is priced at that record's tier (<see cref="TierOf"/>), its cycle kept. Every check
+ /// comes before the first write, and the records and targets are one validated commit. No city field is read or
+ /// written: Q3 "Wait for Industry records (Rec.)", so no count of people without a job is made here.</summary>
+ static string? LedgerStaff(Content c, GameState s, string city, int count, List<Cause> why)
+ {
+ if (!s.Cities.ContainsKey(city)) return Training.RefusedNoCity;
+ if (c.Ruleset != SaveGame.Gdd03Ruleset) return Cities.RefusedNoRole;
+ if (count < 0) return Cities.RefusedNegativeWorkers;
+ var name = PlayerText.Settlement(c, city);
+ var built = BuiltIn(c, s, city);
+ if (count > built.Count) return built.Count == 1 ? Refused(RefusedBuiltOne, name) : Refused(RefusedBuilt, name, built.Count);
+ // R-CITY-011's builders are city counts (CityProject.Builder), not records, so which records they are is not known.
+ // Refused with a reason before any write rather than guessed (owner, 8 November 2026: "Refuse with a reason (Recommended)").
+ if (Projects.Builders(s, city) > 0) return Refused(LedgerRefusedBuilders, name);
+ var on = new List<int>(); var off = new List<int>();
+ for (int i = 0; i < built.Count; i++)
+ {
+ s.Workshops.TryGetValue(built[i].Id, out var w);
+ var staff = i < count;
+ if (staff && w?.Staffed != true) on.Add(built[i].Id);
+ else if (!staff && w?.Staffed == true) off.Add(built[i].Id);
+ }
+ var released = new SortedDictionary<int, PopulationUnit>();
+ foreach (var project in off)
+ foreach (var p in OnTarget(s, project))
+ released[p.Id] = p.WithPlacement(p.Status, p.Location, PopulationAssignment.Unassigned, p.Captor, p.Home);
+ var free = LedgerFree(s, city).Concat(released.Values.Where(p => p.Status == PopulationStatus.FreeCivilian
+ && string.Equals(p.Location?.City, city, StringComparison.Ordinal))).OrderBy(p => p.Id).ToList();
+ if (on.Count > free.Count) return Refused(LedgerRefusedFree, name, free.Count);
+ var region = c.PlayerRegions.AtLocation(city)?.Id
+ ?? throw new InvalidOperationException("No region in regions.yaml for " + city + " (R-POP-004).");
+ var changed = new SortedDictionary<int, PopulationUnit>(released);
+ var bind = new List<PopulationTarget>();
+ var tiers = new Dictionary<int, SyntheticWorkshopTier>();
+ for (int i = 0; i < on.Count; i++)
+ {
+ var p = free[i]; var target = WorkerTarget(on[i]);
+ if (s.PopulationLedger.Target(target) == null) bind.Add(new PopulationTarget(target, PopulationAssignmentKind.Work, region));
+ changed[p.Id] = p.WithPlacement(p.Status, p.Location, new PopulationAssignment(PopulationAssignmentKind.Work, target), p.Captor, p.Home);
+ tiers[on[i]] = TierOf(p);
+ }
+ var staffed = Staffed(s, city);
+ s.PopulationLedger.Commit(changed.Values.ToList(), bind);
+ foreach (var project in off) s.Workshops[project] = s.Workshops[project].WithStaffed(false);
+ foreach (var project in on)
+ s.Workshops[project] = s.Workshops.TryGetValue(project, out var w)
+ ? new Workshop(project, true, tiers[project], w.PaidCost, w.Progress)
+ : new Workshop(project, true, tiers[project]);
+ why.Add(StaffedLine(city, name, count - staffed, count));
return null;
}
@@ -147,29 +255,50 @@ namespace Statecraft.Sim
public static void Produce(Content c, GameState s, List<Cause> why)
{
if (c.Ruleset != SaveGame.Gdd03Ruleset || s.Workshops.Count == 0) return;
- PopulationLedger.RefuseAggregate(s);
+ PopulationLedger.RefuseUnlessHistorical(s); // #1725 PR 7: on a Historical ledger each workshop has its worker record
+ var ledger = s.PopulationLedger.IsHistorical;
var rules = Rules(c);
var ceiling = c.RulesAt(s.Date).Mvp!.DebtCeiling!.Value;
var held = Cities.Held(c, s);
var working = new Dictionary<string, int>(StringComparer.Ordinal);
+ // #1725 PR 7 review S2: on a Historical ledger every workshop the loop reaches has its worker records checked
+ // first, in the loop's own order, so a corrupted ledger (more than one record on a target) throws before any write.
+ if (ledger)
+ foreach (var w in s.Workshops.Values)
+ {
+ if (!w.Staffed) continue;
+ var city = s.CityProjects[w.Project].City;
+ if (!held.Contains(city)) LedgerWorker(s, w.Project, city);
+ }
foreach (var w in s.Workshops.Values.ToList())
{
if (!w.Staffed) continue;
var city = s.CityProjects[w.Project].City;
if (held.Contains(city)) continue;
var name = PlayerText.Settlement(c, city);
- var x = s.Cities[city];
- // R-CITY-011: step 5's builders took their people first.
- if (!working.TryGetValue(city, out var taken)) taken = Projects.Builders(s, city);
- if (taken >= x.Civilians + x.Craftsmen - x.Employed)
+ // #1725 PR 7, producer 07 (owner, 8 November 2026, Q6 "Waits, stays staffed (Rec.)"; Q3 "Wait for Industry
+ // records (Rec.)"): on a Historical ledger the workshop works when its own bound worker is there, a named
+ // record no builder can take (R-CITY-011), so no count of the city's people without a job is read.
+ var worker = ledger ? LedgerWorker(s, w.Project, city) : null;
+ var noWorker = ledger && worker == null;
+ if (!ledger)
+ {
+ var x = s.Cities[city];
+ // R-CITY-011: step 5's builders took their people first.
+ if (!working.TryGetValue(city, out var taken)) taken = Projects.Builders(s, city);
+ noWorker = taken >= x.Civilians + x.Craftsmen - x.Employed;
+ if (!noWorker) working[city] = taken + 1;
+ }
+ if (noWorker)
{
why.Add(new Cause("city", city, 0, $"{name}: an arms workshop has no worker without a job this month", key: CauseKeys.WorkshopPaused, args: new[] { NoWorker, w.Project.ToString(System.Globalization.CultureInfo.InvariantCulture) }));
continue;
}
- working[city] = taken + 1;
var cycle = w;
if (cycle.PaidCost == null)
{
+ // Q8 "Keep tier field (Rec.)": a new cycle is priced at the worker record's tier, kept in WorkerTier.
+ if (worker != null) cycle = new Workshop(cycle.Project, cycle.Staffed, TierOf(worker));
var price = Price(rules, cycle);
var left = s.Treasury - (double)price; // R-MONEY-003's debt after: the debt plus what the Treasury lacks
if (left < 0 && s.Debt - left > ceiling)