A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
Content loader: enforce the schema-required fields for content loaded outside schema validation (Fixes #2588) (#2616)
Eyal Golan56231de9c511
diff --git a/changelog.d/2588-loader-required-fields.md b/changelog.d/2588-loader-required-fields.mdnew file mode 100644index 000000000..7edc8c666--- /dev/null+++ b/changelog.d/2588-loader-required-fields.md@@ -0,0 +1,3 @@+### Fixed++- Content loaded outside schema validation now rejects missing required display text, names, sources, portrait metadata, wrapper keys, and unit-order coordinates.diff --git a/sim/Statecraft.Sim.Tests/AlternateTimelineTests.cs b/sim/Statecraft.Sim.Tests/AlternateTimelineTests.csindex ac6d5aa9a..ad2d2f801 100644--- a/sim/Statecraft.Sim.Tests/AlternateTimelineTests.cs+++ b/sim/Statecraft.Sim.Tests/AlternateTimelineTests.cs@@ -12,6 +12,7 @@ title: Parenttext: 'A real decision.'from: 1948-06-01to: 1948-06-11+sources: [{ url: https://example.org/event, checked: 2026-10-18 }]options:- id: recordtext: What happened@@ -122,6 +123,7 @@ text: 'What the record says was feared.'from: 1948-06-15to: 1948-08-15requires: [{ event: parent, option: road }]+sources: [{ url: https://example.org/event, checked: 2026-10-18 }]options:- id: holdtext: Hold the course@@ -141,6 +143,7 @@ text: 'The next real decision.'from: 1948-07-01to: 1948-09-15requires: [{ event: parent, option: record }]+sources: [{ url: https://example.org/event, checked: 2026-10-18 }]options:- id: oktext: Ok@@ -202,7 +205,7 @@ options:// R-ALT-009public void OnlyAConsequenceCardRejoinsAndOnlyARoadItFollows(){- var other = "id: other\ntitle: Other\ntext: x\nfrom: 1948-06-01\noptions:\n - id: a\n text: A\n historical: true\n - id: b\n text: B\n alternative: { basis: design }\n";+ var other = "id: other\ntitle: Other\ntext: x\nfrom: 1948-06-01\nsources: [{ url: \"https://example.org/event\", checked: 2026-10-18 }]\noptions:\n - id: a\n text: A\n historical: true\n - id: b\n text: B\n alternative: { basis: design }\n";var ex = Assert.Throws<ContentException>(() => Load(("parent.yaml", Parent), ("other.yaml", other), ("after_road.yaml", WithRejoin.Replace("rejoin: parent", "rejoin: other"))));Assert.Contains("rejoins only an event whose road this card follows", ex.Message);var onRecord = RecordFollowUp.Replace(" text: Ok\n", " text: Ok\n rejoin: parent\n");@@ -358,7 +361,7 @@ options:}static string Soft(string id) =>- $"id: {id}\ntitle: {id}\ntext: 'Ordinary.'\nfrom: 1948-06-01\nto: 1948-08-15\noptions:\n - id: ok\n text: Ok\n";+ $"id: {id}\ntitle: {id}\ntext: 'Ordinary.'\nfrom: 1948-06-01\nto: 1948-08-15\nsources: [{{ url: \"https://example.org/event\", checked: 2026-10-18 }}]\noptions:\n - id: ok\n text: Ok\n";static Content WithThreeSoft() => Load(("parent.yaml", Parent), ("after_road.yaml", Consequence), ("a1.yaml", Soft("a1")), ("a2.yaml", Soft("a2")), ("a3.yaml", Soft("a3")));@@ -391,7 +394,7 @@ options:[Fact]public void OnlyAConsequenceCardFollowsAConsequenceCard(){- var historical = "id: later\ntitle: Later\ntext: x\nfrom: 1948-09-01\nrequires: [{ event: after_road, option: hold }]\noptions:\n - id: ok\n text: Ok\n";+ var historical = "id: later\ntitle: Later\ntext: x\nfrom: 1948-09-01\nrequires: [{ event: after_road, option: hold }]\nsources: [{ url: \"https://example.org/event\", checked: 2026-10-18 }]\noptions:\n - id: ok\n text: Ok\n";var ex = Assert.Throws<ContentException>(() => Load(("parent.yaml", Parent), ("after_road.yaml", Consequence), ("later.yaml", historical)));Assert.Equal("events/later.yaml", ex.File);Assert.Equal("events[later].requires[0]", ex.Field);@@ -413,7 +416,7 @@ options:[Fact]public void AConsequenceCarriesTheTagsOfEveryEventItRequires(){- var sens = "id: sens\ntitle: Sens\ntext: x\nfrom: 1948-06-01\ntags: [Massacre]\noptions:\n - id: rec\n text: Rec\n historical: true\n";+ var sens = "id: sens\ntitle: Sens\ntext: x\nfrom: 1948-06-01\ntags: [Massacre]\nsources: [{ url: \"https://example.org/event\", checked: 2026-10-18 }]\noptions:\n - id: rec\n text: Rec\n historical: true\n";var both = Consequence.Replace("requires: [{ event: parent, option: road }]", "requires: [{ event: parent, option: road }, { event: sens, option: rec }]");var ex = Assert.Throws<ContentException>(() => Load(("parent.yaml", Parent), ("sens.yaml", sens), ("after_road.yaml", both)));Assert.Equal("events[after_road].tags", ex.Field);@@ -522,6 +525,7 @@ title: The outside eventtext: 'It happened regardless.'from: 1948-07-01to: 1948-08-01+sources: [{ url: https://example.org/event, checked: 2026-10-18 }]options:- id: recordtext: As it happened@@ -554,6 +558,8 @@ variants:[InlineData(" - when: [{ event: parent, diverged: true }]", " - when: [{ event: parent, option: record }]", "variants[0].when", "a variant follows a road not taken")][InlineData(" - when: [{ event: parent, diverged: true }]", " - when: []", "variants[0].when", "a variant follows a road not taken")][InlineData(" sources: [{ url: \"https://example.org/outside\", checked: 2026-10-17 }]\n", "", "variants[0].sources", "needs at least one source")]+ [InlineData("https://example.org/outside", "http://example.org/outside", "variants[0].sources[0]", "needs an https url")]+ [InlineData(", checked: 2026-10-17", "", "variants[0].sources[0]", "needs an https url and a checked date")][InlineData("on your course, the earlier", "on your course, {nobody} and the earlier", "variants[0].text", "unknown office placeholder '{nobody}'")][InlineData(" title: The outside event, on your course\n", " title: '{nobody} on your course'\n", "variants[0].title", "unknown office placeholder '{nobody}'")][InlineData(" text: 'It happened regardless; on your course, the earlier decision went the other way.'\n", " text: ' '\n", "variants[0].text", "a variant has text")]diff --git a/sim/Statecraft.Sim.Tests/BudgetOwnersTests.cs b/sim/Statecraft.Sim.Tests/BudgetOwnersTests.csindex 44d8f1158..2bdcee33c 100644--- a/sim/Statecraft.Sim.Tests/BudgetOwnersTests.cs+++ b/sim/Statecraft.Sim.Tests/BudgetOwnersTests.cs@@ -20,6 +20,7 @@ public class BudgetOwnersTests- office: supply_ministerfrom: 1948-05-14to: 1950-01-01+ sources: [{ url: https://example.org/term, checked: 2026-10-18 }]";const string Shares = "budget_start: { finance_minister: 0.4, defense_minister: 0.4, supply: 0.2 }\n";const string Owners = "budget_owners:\n supply:\n - { from: 1948-05-15, office: supply_minister }\n - { from: 1950-01-01, office: prime_minister }\n";diff --git a/sim/Statecraft.Sim.Tests/CabinetTests.cs b/sim/Statecraft.Sim.Tests/CabinetTests.csindex 12edce8d0..9e692d5d3 100644--- a/sim/Statecraft.Sim.Tests/CabinetTests.cs+++ b/sim/Statecraft.Sim.Tests/CabinetTests.cs@@ -121,6 +121,7 @@ public class CabinetTestsoffices:- office: presidentfrom: 1948-05-14+ sources: [{ url: https://example.org/term, checked: 2026-10-18 }]- id: cosname: Cos Oneliving: false@@ -129,6 +130,7 @@ public class CabinetTestsoffices:- office: chief_of_stafffrom: 1948-05-14+ sources: [{ url: https://example.org/term, checked: 2026-10-18 }]";static readonly Content Rich = ContentLoader.Load(Fixture.Write(new Dictionary<string, string>{diff --git a/sim/Statecraft.Sim.Tests/ContentLoaderTests.cs b/sim/Statecraft.Sim.Tests/ContentLoaderTests.csindex 9aca5c6ff..a76e9c108 100644--- a/sim/Statecraft.Sim.Tests/ContentLoaderTests.cs+++ b/sim/Statecraft.Sim.Tests/ContentLoaderTests.cs@@ -194,6 +194,8 @@ targets:[InlineData(" born: [{}]\n", "people[pm_one].biography_sources.born[0]")][InlineData(" born: [{ checked: 2026-10-11 }]\n", "people[pm_one].biography_sources.born[0]")][InlineData(" born: [{ url: 'https://example.org/birth', checked: 2026-10-11 }, { url: 'https://example.org/b2' }]\n", "people[pm_one].biography_sources.born[1]")]+ [InlineData(" born: []\n", "people[pm_one].biography_sources.born")]+ [InlineData(" born: [{ url: 'http://example.org/birth', checked: 2026-10-11 }]\n", "people[pm_one].biography_sources.born[0]")]public void BadBiographySourceNamesFileAndField(string sources, string field){var ex = LoadPmOneWith(" born: 1900-01-01\n biography_sources:\n" + sources);@@ -242,6 +244,49 @@ targets:var bad = Fixture.Files["parties.yaml"].Replace("name: Beta", "nmae: Beta");var ex = Assert.Throws<ContentException>(() => ContentLoader.Load(Fixture.Write(new Dictionary<string, string> { ["parties.yaml"] = bad })));Assert.Equal("parties.yaml", ex.File);+ Assert.StartsWith("nmae (line ", ex.Field);+ Assert.EndsWith(")", ex.Field);+ }++ [Theory]+ [InlineData("offices.yaml", "offices")]+ [InlineData("parties.yaml", "parties")]+ [InlineData("people.yaml", "people")]+ public void RequiredRootListsNameTheirMissingKey(string file, string field)+ {+ var ex = Assert.Throws<ContentException>(() => ContentLoader.Load(Fixture.Write(new Dictionary<string, string> { [file] = "{}\n" })));+ Assert.Equal(file, ex.File);+ Assert.Equal(field, ex.Field);+ }++ [Theory]+ [InlineData("offices.yaml", " title: Minister of Finance\n", "", "offices[finance_minister].title")]+ [InlineData("offices.yaml", "title: Minister of Finance", "title: ' '", "offices[finance_minister].title")]+ [InlineData("parties.yaml", " name: Beta\n", "", "parties[beta].name")]+ [InlineData("parties.yaml", "name: Beta", "name: ' '", "parties[beta].name")]+ [InlineData("people.yaml", " name: Def Two\n", "", "people[def_two].name")]+ [InlineData("people.yaml", "name: Def Two", "name: ' '", "people[def_two].name")]+ public void RequiredDisplayNamesNameTheirField(string file, string from, string to, string field)+ {+ var bad = Fixture.Files[file].Replace(from, to);+ Assert.NotEqual(Fixture.Files[file], bad);+ var ex = Assert.Throws<ContentException>(() => ContentLoader.Load(Fixture.Write(new Dictionary<string, string> { [file] = bad })));+ Assert.Equal(file, ex.File);+ Assert.Equal(field, ex.Field);+ }++ [Theory]+ [InlineData(" - office: finance_minister\n from: 1948-05-14\n sources: *fixture_term_sources\n", " - office: finance_minister\n from: 1948-05-14\n", "people[def_two].offices.finance_minister.sources")]+ [InlineData(" - office: finance_minister\n from: 1948-05-14\n sources: *fixture_term_sources", " - office: finance_minister\n from: 1948-05-14\n sources: []", "people[def_two].offices.finance_minister.sources")]+ [InlineData("https://example.org/term", "http://example.org/term", "people[pm_one].offices.prime_minister.sources[0]")]+ [InlineData(", checked: 2026-10-18", "", "people[pm_one].offices.prime_minister.sources[0]")]+ public void OfficeTermSourcesAreRequiredAndComplete(string from, string to, string field)+ {+ var bad = Fixture.Files["people.yaml"].Replace(from, to);+ Assert.NotEqual(Fixture.Files["people.yaml"], bad);+ var ex = Assert.Throws<ContentException>(() => ContentLoader.Load(Fixture.Write(new Dictionary<string, string> { ["people.yaml"] = bad })));+ Assert.Equal("people.yaml", ex.File);+ Assert.Equal(field, ex.Field);}[Fact]diff --git a/sim/Statecraft.Sim.Tests/ContentWindowsTests.cs b/sim/Statecraft.Sim.Tests/ContentWindowsTests.csindex a8c5d0ddf..2fbd3e4f1 100644--- a/sim/Statecraft.Sim.Tests/ContentWindowsTests.cs+++ b/sim/Statecraft.Sim.Tests/ContentWindowsTests.cs@@ -225,7 +225,7 @@ public class ContentWindowsTestsRefused(m.Replace(" - id: rationing_food\n from: 1948-07-01\n to: 1949-01-01", " - id: rationing_food\n from: 1948-07-01\n to: 1949-01-02"), "source 'rationing' is not active");}- const string Event = "id: probe\ntitle: Probe\ntext: A probe.\nanchor: soft\nfrom: 1948-06-01\nto: 1948-12-01\n{0}options:\n - id: a\n text: Do a\n{1}";+ const string Event = "id: probe\ntitle: Probe\ntext: A probe.\nanchor: soft\nfrom: 1948-06-01\nto: 1948-12-01\n{0}options:\n - id: a\n text: Do a\n{1}sources: [{{ url: \"https://example.org/event\", checked: 2026-10-18 }}]\n";[Fact]public void AnEventConditionOnAnIndicatorThatBeginsInsideItsWindowIsRefused() =>@@ -248,7 +248,7 @@ public class ContentWindowsTests// on 12 September, after shelter (and maabarot) have left the state on 1 July.static Content LateFire(string conditions, string option) => Load(Model(m => Window(Window(m, " - id: shelter\n base: 0.3", "to: 1948-07-01"), " - id: maabarot\n default: 0.0", "to: 1948-07-01")),- events: new Dictionary<string, string> { ["probe.yaml"] = "id: probe\ntitle: Probe\ntext: A probe.\nanchor: soft\nfrom: 1948-06-20\nto: 1948-07-01\n" + conditions + "options:\n - id: a\n text: Do a\n" + option });+ events: new Dictionary<string, string> { ["probe.yaml"] = "id: probe\ntitle: Probe\ntext: A probe.\nanchor: soft\nfrom: 1948-06-20\nto: 1948-07-01\n" + conditions + "options:\n - id: a\n text: Do a\n" + option + "sources: [{ url: \"https://example.org/event\", checked: 2026-10-18 }]\n" });[Fact]public void ALateFireDoesNotReadAnIndicatorWhoseWindowHasEnded()diff --git a/sim/Statecraft.Sim.Tests/CultureTests.cs b/sim/Statecraft.Sim.Tests/CultureTests.csindex c4c7001ec..e3ff09be1 100644--- a/sim/Statecraft.Sim.Tests/CultureTests.cs+++ b/sim/Statecraft.Sim.Tests/CultureTests.cs@@ -17,6 +17,7 @@ options:effects:- target: treasurydelta: -10.5+sources: [{ url: https://example.org/event, checked: 2026-10-18 }]";static readonly Content C = ContentLoader.Load(Fixture.Write(diff --git a/sim/Statecraft.Sim.Tests/DollarsTests.cs b/sim/Statecraft.Sim.Tests/DollarsTests.csindex 78db283d7..1f166cddd 100644--- a/sim/Statecraft.Sim.Tests/DollarsTests.cs+++ b/sim/Statecraft.Sim.Tests/DollarsTests.cs@@ -186,6 +186,7 @@ options:text: The way it wenthistorical: trueset_rung: RUNG+sources: [{ url: https://example.org/event, checked: 2026-10-18 }]";// R-MONEY-004: the war is the rung the turn started at. An earlier order of the same turn that moves the rung (andiff --git a/sim/Statecraft.Sim.Tests/EnemyAITests.cs b/sim/Statecraft.Sim.Tests/EnemyAITests.csindex f838e7241..853d8f94c 100644--- a/sim/Statecraft.Sim.Tests/EnemyAITests.cs+++ b/sim/Statecraft.Sim.Tests/EnemyAITests.cs@@ -565,7 +565,8 @@ public class EnemyAITests+ " - { place: There, lon: 34.30, lat: 33.35, from: '1948-06-01', to: '1949-01-01' }\n";const string Hexes = "anchors:\n - { id: brig, anchor: 0, q: 0, r: 0 }\n - { id: brig, anchor: 1, q: 4, r: 0 }\n";static string Card(string order) => "id: probe\ntitle: Fixture\ntext: Fixture.\nfrom: 1948-05-15\noptions:\n"- + " - id: ok\n text: Accept\n historical: true\n unit_orders: [" + order + "]\n";+ + " - id: ok\n text: Accept\n historical: true\n unit_orders: [" + order + "]\n"+ + "sources: [{ url: \"https://example.org/event\", checked: 2026-10-18 }]\n";static Dictionary<string, string> Files() => Fixture.Gdd(new Dictionary<string, string>{["unit_types.yaml"] = Types, ["map/hexes.json"] = MovementTests.Board(), ["corridors.yaml"] = "corridors: []\n",@@ -579,6 +580,20 @@ public class EnemyAITestsvar invented = Refused(Files(), "{ unit: brig, q: 3, r: 0 }");Assert.Equal("events[probe].options[ok].unit_orders[0]", invented.Field);Assert.Contains("not an anchor", invented.Message);+ var missingQ = Refused(Files(), "{ unit: brig, r: 0 }");+ Assert.Equal("events[probe].options[ok].unit_orders[0].q", missingQ.Field);+ var missingR = Refused(Files(), "{ unit: brig, q: 0 }");+ Assert.Equal("events[probe].options[ok].unit_orders[0].r", missingR.Field);+ var legacyMissingQ = Assert.Throws<ContentException>(() => ContentLoader.Load(+ Fixture.Write(null, new() { ["probe.yaml"] = Card("{ unit: brig, r: 0 }") })));+ Assert.Equal("events[probe].options[ok].unit_orders[0].q", legacyMissingQ.Field);+ // R-ENEMY-005: every order names a unit row, in every ruleset (the schema requires unit, q and r).+ var missingUnit = Refused(Files(), "{ q: 4, r: 0 }");+ Assert.Equal("events[probe].options[ok].unit_orders[0].unit", missingUnit.Field);+ Assert.EndsWith(": required", missingUnit.Message);+ var legacyMissingUnit = Assert.Throws<ContentException>(() => ContentLoader.Load(+ Fixture.Write(null, new() { ["probe.yaml"] = Card("{ q: 4, r: 0 }") })));+ Assert.Equal("events[probe].options[ok].unit_orders[0].unit", legacyMissingUnit.Field);// The legacy loop reads the shared cards too: the order does not stop it loading, and it has no units to order.Assert.Empty(ContentLoader.Load(Fixture.Write(null, new() { ["probe.yaml"] = Card("{ unit: brig, q: 4, r: 0 }") })).StartingForces);@@ -672,7 +687,8 @@ public class EnemyAITests+ " - { place: There, lon: 34.30, lat: 33.35, from: '1948-05-15', to: '" + to + "' }\n";var hexes = FormattableString.Invariant($"anchors:\n - {{ id: brig, anchor: 0, q: 0, r: 0 }}\n - {{ id: brig, anchor: 1, q: {q}, r: {r} }}\n");var card = "id: probe\ntitle: Fixture\ntext: Fixture.\nfrom: 1948-05-15\noptions:\n"- + FormattableString.Invariant($" - id: ok\n text: Accept\n historical: true\n unit_orders: [{{ unit: brig, q: {q}, r: {r} }}]\n");+ + FormattableString.Invariant($" - id: ok\n text: Accept\n historical: true\n unit_orders: [{{ unit: brig, q: {q}, r: {r} }}]\n")+ + "sources: [{ url: \"https://example.org/event\", checked: 2026-10-18 }]\n";var files = Fixture.Gdd(new Dictionary<string, string>{["unit_types.yaml"] = Types, ["map/hexes.json"] = board, ["corridors.yaml"] = "corridors: []\n",@@ -721,7 +737,8 @@ public class EnemyAITests+ " order_targets:\n - { place: There, lon: 34.30, lat: 33.35" + target + " }\n";const string Hexes = "anchors:\n - { id: brig, anchor: 0, q: 0, r: 0 }\norder_targets:\n - { id: brig, target: 0, q: 4, r: 0 }\n";const string Card = "id: probe\ntitle: Fixture\ntext: Fixture.\nfrom: 1948-05-15\noptions:\n"- + " - id: ok\n text: Accept\n historical: true\n unit_orders: [{ unit: brig, q: 4, r: 0 }]\n";+ + " - id: ok\n text: Accept\n historical: true\n unit_orders: [{ unit: brig, q: 4, r: 0 }]\n"+ + "sources: [{ url: \"https://example.org/event\", checked: 2026-10-18 }]\n";var files = Fixture.Gdd(new Dictionary<string, string>{["unit_types.yaml"] = Types, ["map/hexes.json"] = MovementTests.Board(), ["corridors.yaml"] = "corridors: []\n",diff --git a/sim/Statecraft.Sim.Tests/EventRequiresTests.cs b/sim/Statecraft.Sim.Tests/EventRequiresTests.csindex 0612a3eb6..f5788bb47 100644--- a/sim/Statecraft.Sim.Tests/EventRequiresTests.cs+++ b/sim/Statecraft.Sim.Tests/EventRequiresTests.cs@@ -18,6 +18,7 @@ options:- id: staytext: Stayalternative: { basis: design }+sources: [{ url: https://example.org/event, checked: 2026-10-18 }]";const string Follow = @"@@ -29,6 +30,7 @@ requires: [{ event: first, option: go }]options:- id: oktext: Fine+sources: [{ url: https://example.org/event, checked: 2026-10-18 }]";static Content Load(string follow) =>@@ -125,6 +127,7 @@ requires: [{{ event: {other}, option: ok }}]options:- id: oktext: Fine+sources: [{{ url: https://example.org/event, checked: 2026-10-18 }}]";/// <summary>Re-review N4: a cycle of requirements could never fire; the loader names every file in it.</summary>@@ -162,6 +165,7 @@ options:- id: declinetext: Declinealternative: { basis: design }+sources: [{ url: https://example.org/event, checked: 2026-10-18 }]";const string Plain = @"@@ -174,6 +178,7 @@ options:text: One- id: twotext: Two+sources: [{ url: https://example.org/event, checked: 2026-10-18 }]";static Content LoadAll(string follow) => ContentLoader.Load(Fixture.Write(events: new Dictionary<string, string>@@ -267,7 +272,7 @@ options:[Fact]public void ACycleThroughASecondRequirementIsFound(){- var a = "id: a\ntitle: a\ntext: x\nfrom: 1948-06-01\nrequires: [{ event: first, option: go }, { event: b, option: ok }]\noptions:\n - id: ok\n text: Ok\n";+ var a = "id: a\ntitle: a\ntext: x\nfrom: 1948-06-01\nrequires: [{ event: first, option: go }, { event: b, option: ok }]\noptions:\n - id: ok\n text: Ok\nsources: [{ url: \"https://example.org/event\", checked: 2026-10-18 }]\n";var ex = Assert.Throws<ContentException>(() => ContentLoader.Load(Fixture.Write(events: new Dictionary<string, string>{["first.yaml"] = First, ["a.yaml"] = a, ["b.yaml"] = Requiring("b", "a"),diff --git a/sim/Statecraft.Sim.Tests/EventRulesGddTests.cs b/sim/Statecraft.Sim.Tests/EventRulesGddTests.csindex ea20e8d58..cfb529919 100644--- a/sim/Statecraft.Sim.Tests/EventRulesGddTests.cs+++ b/sim/Statecraft.Sim.Tests/EventRulesGddTests.cs@@ -65,7 +65,7 @@ public class EventRulesGddTestsstatic string Soft(string id, string from, string? to = null) =>$"id: {id}\ntitle: '{id}'\ntext: Something happens.\nfrom: {from}\n" +(to == null ? "" : $"to: {to}\n") +- "options:\n - id: ok\n text: Accept\n historical: true\n";+ "options:\n - id: ok\n text: Accept\n historical: true\nsources: [{ url: \"https://example.org/event\", checked: 2026-10-18 }]\n";// R-EVT-001 (#2605): red before the fix because d's finite window has closed by the second Trigger, so it is lost.// Trigger is the shared path: the same wait and once-only result holds for legacy, gdd-0.1 and gdd-0.3 identities.@@ -279,6 +279,7 @@ options:set_policy:rationing: 0.4set_rung: 3+sources: [{ url: https://example.org/event, checked: 2026-10-18 }]";static Content ChoiceContent(string anchor) =>diff --git a/sim/Statecraft.Sim.Tests/EventTests.cs b/sim/Statecraft.Sim.Tests/EventTests.csindex a36c77eab..b5edbe8ba 100644--- a/sim/Statecraft.Sim.Tests/EventTests.cs+++ b/sim/Statecraft.Sim.Tests/EventTests.cs@@ -32,6 +32,7 @@ options:text: Blame the borderalternative: { basis: design }set_rung: 3+sources: [{ url: https://example.org/event, checked: 2026-10-18 }]";static Content Load(Dictionary<string, string> events) => ContentLoader.Load(Fixture.Write(events: events));@@ -229,6 +230,7 @@ options:effects:- target: moraledelta: 0.1+sources: [{ url: https://example.org/event, checked: 2026-10-18 }]";/// <summary>Morale (base 0.5, no effect contributions) set to level via its shift, then each option chosen in turn.</summary>@@ -648,7 +650,7 @@ options:static string Simple(string id, string anchor, string from, string? to = null) =>$"id: {id}\ntitle: '{id} for {{defense_minister}}'\ntext: Something happens.\nanchor: {anchor}\nfrom: {from}\n" +(to == null ? "" : $"to: {to}\n") +- "options:\n - id: ok\n text: Accept\n historical: true\n";+ "options:\n - id: ok\n text: Accept\n historical: true\nsources: [{ url: \"https://example.org/event\", checked: 2026-10-18 }]\n";[Fact]public void ShortWindowInsideAQuarterTurnStillFires()diff --git a/sim/Statecraft.Sim.Tests/FinalWaveTests.cs b/sim/Statecraft.Sim.Tests/FinalWaveTests.csindex aa84d4b82..d8883301a 100644--- a/sim/Statecraft.Sim.Tests/FinalWaveTests.cs+++ b/sim/Statecraft.Sim.Tests/FinalWaveTests.cs@@ -73,8 +73,8 @@ public class FinalWaveTestsAssert.Empty(ReleaseGate.SensitiveUnreviewed(Real));var reviewed = Fixture.Write(events: new Dictionary<string, string>{- ["a.yaml"] = "id: a\ntitle: A\ntext: x\nfrom: 1948-06-01\ntags: [terror]\noptions:\n - id: o\n text: O\nstatus: sensitivity-reviewed\n",- ["b.yaml"] = "id: b\ntitle: B\ntext: x\nfrom: 1948-06-01\ntags: [holocaust]\noptions:\n - id: o\n text: O\nstatus: fact-checked\n",+ ["a.yaml"] = "id: a\ntitle: A\ntext: x\nfrom: 1948-06-01\ntags: [terror]\noptions:\n - id: o\n text: O\nsources: [{ url: \"https://example.org/event\", checked: 2026-10-18 }]\nstatus: sensitivity-reviewed\n",+ ["b.yaml"] = "id: b\ntitle: B\ntext: x\nfrom: 1948-06-01\ntags: [holocaust]\noptions:\n - id: o\n text: O\nsources: [{ url: \"https://example.org/event\", checked: 2026-10-18 }]\nstatus: fact-checked\n",});Assert.Equal(new[] { "b" }, ReleaseGate.SensitiveUnreviewed(ContentLoader.Load(reviewed)));}diff --git a/sim/Statecraft.Sim.Tests/Fixture.cs b/sim/Statecraft.Sim.Tests/Fixture.csindex 4132a4776..3333d76e7 100644--- a/sim/Statecraft.Sim.Tests/Fixture.cs+++ b/sim/Statecraft.Sim.Tests/Fixture.cs@@ -44,9 +44,11 @@ people:offices:- office: prime_ministerfrom: 1948-05-14+ sources: &fixture_term_sources [{ url: https://example.org/term, checked: 2026-10-18 }]- office: defense_ministerfrom: 1948-05-14to: 1949-01-01+ sources: *fixture_term_sources- id: def_twoname: Def Twoliving: false@@ -55,8 +57,10 @@ people:offices:- office: defense_ministerfrom: 1949-01-01+ sources: *fixture_term_sources- office: finance_ministerfrom: 1948-05-14+ sources: *fixture_term_sources",["legislatures.yaml"] = @"legislatures:diff --git a/sim/Statecraft.Sim.Tests/Gdd03ArmisticeOfferTests.cs b/sim/Statecraft.Sim.Tests/Gdd03ArmisticeOfferTests.csindex efbf55317..6da1651f1 100644--- a/sim/Statecraft.Sim.Tests/Gdd03ArmisticeOfferTests.cs+++ b/sim/Statecraft.Sim.Tests/Gdd03ArmisticeOfferTests.cs@@ -20,6 +20,7 @@ office: prime_ministeranchor: hardfront_quiet: {front}from: {from}+sources: [{{ url: https://example.org/event, checked: 2026-10-18 }}]options:- id: signtext: Sign the armistice@@ -35,6 +36,7 @@ title: Parenttext: 'A real decision.'from: 1948-12-01to: 1948-12-11+sources: [{ url: https://example.org/event, checked: 2026-10-18 }]options:- id: recordtext: What happened@@ -56,6 +58,7 @@ text: 'What the record says was feared.'from: 1948-12-11to: 1949-02-01requires: [{ event: parent, option: road }]+sources: [{ url: https://example.org/event, checked: 2026-10-18 }]options:- id: holdtext: Hold the course@@ -67,7 +70,7 @@ options:";// An ordinary soft event whose `from` is earlier than every armistice's, so ordering by `from` alone would put it first.- static string Soft(string id) => $"id: {id}\ntitle: {id}\ntext: 'Ordinary.'\nfrom: 1948-12-01\nto: 1949-02-01\noptions:\n - id: ok\n text: Ok\n";+ static string Soft(string id) => $"id: {id}\ntitle: {id}\ntext: 'Ordinary.'\nfrom: 1948-12-01\nto: 1949-02-01\nsources: [{{ url: \"https://example.org/event\", checked: 2026-10-18 }}]\noptions:\n - id: ok\n text: Ok\n";static Content Load(string ruleset = SaveGame.Gdd03Ruleset, string jordanFrom = "1950-01-01", bool others = true){diff --git a/sim/Statecraft.Sim.Tests/Gdd03ArmisticeQuietTests.cs b/sim/Statecraft.Sim.Tests/Gdd03ArmisticeQuietTests.csindex 942148a60..0975dbed0 100644--- a/sim/Statecraft.Sim.Tests/Gdd03ArmisticeQuietTests.cs+++ b/sim/Statecraft.Sim.Tests/Gdd03ArmisticeQuietTests.cs@@ -29,6 +29,7 @@ options:- id: hold_outtext: Refuse and keep fightingalternative: { basis: design }+sources: [{ url: https://example.org/event, checked: 2026-10-18 }]";static Content Load(string ruleset = SaveGame.Gdd03Ruleset)diff --git a/sim/Statecraft.Sim.Tests/Gdd03EventRulesTests.cs b/sim/Statecraft.Sim.Tests/Gdd03EventRulesTests.csindex f663c8ad2..a8b6e8bd3 100644--- a/sim/Statecraft.Sim.Tests/Gdd03EventRulesTests.cs+++ b/sim/Statecraft.Sim.Tests/Gdd03EventRulesTests.cs@@ -15,7 +15,8 @@ public class Gdd03EventRulesTests// turned on". These four, excluded by #1772 for their Food supply, housing and policy writes, are active again.static readonly string[] TurnedOn = { "austerity_1949", "forex_crisis_1951", "iraqi_exodus", "maabarot_policy" };static string Card(string id = "probe", string option = "") =>- $"id: {id}\ntitle: Fixture\ntext: Fixture.\nfrom: 1948-05-15\noptions:\n - id: ok\n text: Accept\n historical: true\n" + option;+ $"id: {id}\ntitle: Fixture\ntext: Fixture.\nfrom: 1948-05-15\noptions:\n - id: ok\n text: Accept\n historical: true\n" + option+ + "sources: [{ url: \"https://example.org/event\", checked: 2026-10-18 }]\n";static Dictionary<string, string> Files(bool modern = true){var f = Fixture.Gdd();@@ -465,7 +466,7 @@ public class Gdd03EventRulesTestspublic void DebtDollarsThatIsNotANumberIsRefused(bool modern){var ex = Assert.Throws<ContentException>(() => Load(Files(modern), Card(option: " debt_dollars: nope\n")));- Assert.Equal(("events/probe.yaml", "line 9"), (ex.File, ex.Field));+ Assert.Equal(("events/probe.yaml", "debt_dollars (line 9)"), (ex.File, ex.Field));Assert.Contains("nope", ex.Message);}// R-EFX-009 (#2457): on the real card, launch adds the $52m and IL 18.564m of Debt (52 x 0.357, the rate in force ondiff --git a/sim/Statecraft.Sim.Tests/MinistersGddTests.cs b/sim/Statecraft.Sim.Tests/MinistersGddTests.csindex dd0f5f7a8..2c27db78f 100644--- a/sim/Statecraft.Sim.Tests/MinistersGddTests.cs+++ b/sim/Statecraft.Sim.Tests/MinistersGddTests.cs@@ -37,6 +37,7 @@ offices:offices:- office: agriculture_ministerfrom: 1948-05-14+ sources: [{ url: https://example.org/term, checked: 2026-10-18 }]";static readonly string Lazy = @"- id: lazy_agri@@ -47,6 +48,7 @@ offices:offices:- office: agriculture_ministerfrom: 1948-05-14+ sources: [{ url: https://example.org/term, checked: 2026-10-18 }]";static readonly string AbleLabour = @"@@ -58,6 +60,7 @@ offices:offices:- office: labour_ministerfrom: 1948-05-14+ sources: [{ url: https://example.org/term, checked: 2026-10-18 }]";static readonly string Map = @"@@ -324,7 +327,7 @@ offices:[Fact]public void AChangedMinisterUpdatesTheRemainingForecastWithoutLosingCarry(){- var candidate = Lazy.Replace(" offices:\n - office: agriculture_minister\n from: 1948-05-14\n", "");+ var candidate = Lazy.Replace(" offices:\n - office: agriculture_minister\n from: 1948-05-14\n sources: [{ url: https://example.org/term, checked: 2026-10-18 }]\n", "");var c = Town(Able + candidate);var s = WithHalutz(c, out var id);var site = c.Sites.Single(x => x.Id == "site_a");diff --git a/sim/Statecraft.Sim.Tests/ObjectivesTests.cs b/sim/Statecraft.Sim.Tests/ObjectivesTests.csindex 620642440..24d6f6ad8 100644--- a/sim/Statecraft.Sim.Tests/ObjectivesTests.cs+++ b/sim/Statecraft.Sim.Tests/ObjectivesTests.cs@@ -23,6 +23,7 @@ options:- id: continuetext: Continuehistorical: true+sources: [{ url: https://example.org/event, checked: 2026-10-18 }]";const string PartsYaml = @"@@ -61,6 +62,7 @@ options:- id: continuetext: Continuehistorical: true+sources: [{{ url: https://example.org/event, checked: 2026-10-18 }}]";static Content LoadParts(string objectives = PartsYaml)@@ -763,7 +765,7 @@ eras:static string GddRules(string from, string to) => Fixture.Gdd()["rules.yaml"].Replace(from, to);- static string TwoOptions => Card + " - id: refuse\n text: Refuse\n alternative: { basis: design }\n";+ static string TwoOptions => Card.Replace("sources:", " - id: refuse\n text: Refuse\n alternative: { basis: design }\nsources:");static string Objective(string from, string to) => ObjectivesYaml.Replace(from, to);diff --git a/sim/Statecraft.Sim.Tests/OfficesTests.cs b/sim/Statecraft.Sim.Tests/OfficesTests.csindex 3becfe991..7259f1504 100644--- a/sim/Statecraft.Sim.Tests/OfficesTests.cs+++ b/sim/Statecraft.Sim.Tests/OfficesTests.cs@@ -35,7 +35,7 @@ public class OfficesTests{var offices = Fixture.Files["offices.yaml"] + " - id: minister_2\n title: Second Minister\n";var people = Fixture.Files["people.yaml"].Replace(" - office: prime_minister\n",- " - office: minister_2\n from: 1948-05-14\n - office: prime_minister\n");+ " - office: minister_2\n from: 1948-05-14\n sources: [{ url: https://example.org/term, checked: 2026-10-18 }]\n - office: prime_minister\n");var c = ContentLoader.Load(Fixture.Write(new System.Collections.Generic.Dictionary<string, string> { ["offices.yaml"] = offices, ["people.yaml"] = people }));Assert.Equal("Pm One speaks.", Offices.Fill(c, "{minister_2} speaks.", new DateTime(1949, 6, 1)));}diff --git a/sim/Statecraft.Sim.Tests/OptionEffectPreviewTests.cs b/sim/Statecraft.Sim.Tests/OptionEffectPreviewTests.csindex 0c851df9f..47dfdc409 100644--- a/sim/Statecraft.Sim.Tests/OptionEffectPreviewTests.cs+++ b/sim/Statecraft.Sim.Tests/OptionEffectPreviewTests.cs@@ -21,7 +21,7 @@ public class OptionEffectPreviewTests["cities.yaml"] = "cities:\n" + Fixture.City("town_a", 12, 8, 10, 6, "[military_camp, hakhshara]") + Fixture.City("town_b", 5, 2, 2, 1),}), new Dictionary<string, string>{- ["preview_record.yaml"] = "id: preview_record\ntitle: Recorded {prime_minister}\ntext: A fictional fixture record.\nfrom: 1950-01-01\noptions:\n - { id: keep, text: Keep, historical: true }\n",+ ["preview_record.yaml"] = "id: preview_record\ntitle: Recorded {prime_minister}\ntext: A fictional fixture record.\nfrom: 1950-01-01\noptions:\n - { id: keep, text: Keep, historical: true }\nsources: [{ url: \"https://example.org/event\", checked: 2026-10-18 }]\n",}));}diff --git a/sim/Statecraft.Sim.Tests/PlayerTextTests.cs b/sim/Statecraft.Sim.Tests/PlayerTextTests.csindex ac2a89b95..a8f33be19 100644--- a/sim/Statecraft.Sim.Tests/PlayerTextTests.cs+++ b/sim/Statecraft.Sim.Tests/PlayerTextTests.cs@@ -461,6 +461,9 @@ public class PlayerTextTests/// <summary>Playtest 2, P2-5: a portrait carries its documented focal point (the face's height as a share of the/// picture, 0..1), required, so the event card can keep the face in view.</summary>[Theory]+ [InlineData(" portrait: { license: Public domain, source: s, focus_y: 0.5 }\n", "people[pm_one].portrait.file")]+ [InlineData(" portrait: { file: a.jpg, source: s, focus_y: 0.5 }\n", "people[pm_one].portrait.license")]+ [InlineData(" portrait: { file: a.jpg, license: Public domain, focus_y: 0.5 }\n", "people[pm_one].portrait.source")][InlineData(" portrait: { file: a.jpg, license: Public domain, source: s }\n", "people[pm_one].portrait.focus_y")][InlineData(" portrait: { file: a.jpg, license: Public domain, source: s, focus_y: 1.4 }\n", "people[pm_one].portrait.focus_y")]public void APortraitNeedsItsFocalPoint(string portrait, string field)@@ -470,6 +473,15 @@ public class PlayerTextTestsAssert.Equal(field, ex.Field);}+ [Fact]+ public void PresentEmptyPortraitStringsMatchTheSchema()+ {+ var yaml = Fixture.Files["people.yaml"].Replace(" - id: pm_one\n",+ " - id: pm_one\n portrait: { file: '', license: '', source: '', focus_y: 0.5 }\n");+ var portrait = ContentLoader.Load(Fixture.Write(new Dictionary<string, string> { ["people.yaml"] = yaml })).People[0].Portrait!;+ Assert.Equal(("", "", "", 0.5), (portrait.File, portrait.License, portrait.Source, portrait.FocusY!.Value));+ }+[Fact]public void EveryRealPortraitHasAFocalPoint() =>Assert.All(Real.People.Where(p => p.Portrait != null && p.Portrait.File != ""), p => Assert.InRange(p.Portrait!.FocusY ?? -1, 0.05, 0.95));@@ -498,4 +510,3 @@ public class PlayerTextTestsAssert.Equal("Arms -2 units", PlayerText.Change(c, Pools.ArmsTarget, -2));}}-diff --git a/sim/Statecraft.Sim.Tests/PrisonersGdd03Tests.cs b/sim/Statecraft.Sim.Tests/PrisonersGdd03Tests.csindex 26655a5b7..7cead64da 100644--- a/sim/Statecraft.Sim.Tests/PrisonersGdd03Tests.cs+++ b/sim/Statecraft.Sim.Tests/PrisonersGdd03Tests.cs@@ -40,6 +40,7 @@ options:- id: continuetext: Continuehistorical: true+sources: [{ url: https://example.org/event, checked: 2026-10-18 }]";/// <summary>The fixture under the gdd-0.3 identity, with the real content's points_per_prisoner_unit_returned line indiff --git a/sim/Statecraft.Sim.Tests/PrisonersTests.cs b/sim/Statecraft.Sim.Tests/PrisonersTests.csindex e5fe36aec..2a96ace3d 100644--- a/sim/Statecraft.Sim.Tests/PrisonersTests.cs+++ b/sim/Statecraft.Sim.Tests/PrisonersTests.cs@@ -30,6 +30,7 @@ options:- id: continuetext: Continuehistorical: true+sources: [{{ url: https://example.org/event, checked: 2026-10-18 }}]";static readonly Dictionary<string, string> Cards = new Dictionary<string, string>@@ -135,7 +136,7 @@ options:public void NoEventEffectTargetsThePrisoners(string target){Assert.DoesNotContain(target, EventRules.SpecialTargets);- var card = $"id: deal\ntitle: A deal\ntext: A deal.\nfrom: 1948-05-15\noptions:\n - {{ id: a, text: A, effects: [{{ target: {target}, delta: 1 }}] }}\n";+ var card = $"id: deal\ntitle: A deal\ntext: A deal.\nfrom: 1948-05-15\noptions:\n - {{ id: a, text: A, effects: [{{ target: {target}, delta: 1 }}] }}\nsources: [{{ url: \"https://example.org/event\", checked: 2026-10-18 }}]\n";var ex = Assert.Throws<ContentException>(() => Load(new Dictionary<string, string> { ["deal.yaml"] = card }));Assert.Equal($"options[a].effects.{target}", ex.Field.Substring(ex.Field.IndexOf("options", StringComparison.Ordinal)));Assert.Contains("unknown target", ex.Message);diff --git a/sim/Statecraft.Sim.Tests/ReleaseGateTests.cs b/sim/Statecraft.Sim.Tests/ReleaseGateTests.csindex 340549dc3..9a3db671a 100644--- a/sim/Statecraft.Sim.Tests/ReleaseGateTests.cs+++ b/sim/Statecraft.Sim.Tests/ReleaseGateTests.cs@@ -18,7 +18,7 @@ public class ReleaseGateTests{var files = Fixture.Write(events: new Dictionary<string, string>{- ["displacement.yaml"] = "id: displacement\ntitle: A decision\ntext: A decision is required.\nfrom: 1948-06-01\ntags: [displacement]\noptions:\n - id: continue\n text: Continue\nstatus: fact-checked\n",+ ["displacement.yaml"] = "id: displacement\ntitle: A decision\ntext: A decision is required.\nfrom: 1948-06-01\ntags: [displacement]\noptions:\n - id: continue\n text: Continue\nsources: [{ url: \"https://example.org/event\", checked: 2026-10-18 }]\nstatus: fact-checked\n",});Assert.Equal(new[] { "displacement" }, ReleaseGate.SensitiveUnreviewed(ContentLoader.Load(files)));diff --git a/sim/Statecraft.Sim.Tests/SeveralHoldersTests.cs b/sim/Statecraft.Sim.Tests/SeveralHoldersTests.csindex dc848c020..b3a97fe3e 100644--- a/sim/Statecraft.Sim.Tests/SeveralHoldersTests.cs+++ b/sim/Statecraft.Sim.Tests/SeveralHoldersTests.cs@@ -16,6 +16,7 @@ public class SeveralHoldersTests- office: defense_ministerfrom: 1949-01-01to: 1949-06-01+ sources: [{ url: https://example.org/term, checked: 2026-10-18 }]";static Dictionary<string, string> Files(bool several) => new Dictionary<string, string>@@ -87,7 +88,7 @@ public class SeveralHoldersTests[Fact]public void AnEventPlaceholderForSuchAnOfficeFailsToLoad(){- var ev = "id: shortage\ntitle: Bread lines\ntext: '{defense_minister} reports shortages.'\nfrom: 1948-06-01\noptions:\n - id: a\n text: Ration food\n effects:\n - target: food_supply\n delta: 0.2\n";+ var ev = "id: shortage\ntitle: Bread lines\ntext: '{defense_minister} reports shortages.'\nfrom: 1948-06-01\noptions:\n - id: a\n text: Ration food\n effects:\n - target: food_supply\n delta: 0.2\nsources: [{ url: \"https://example.org/event\", checked: 2026-10-18 }]\n";var ex = Assert.Throws<ContentException>(() => ContentLoader.Load(Fixture.Write(Files(true), new Dictionary<string, string> { ["shortage.yaml"] = ev })));Assert.Contains("several holders", ex.Message);}diff --git a/sim/Statecraft.Sim.Tests/SimTests.cs b/sim/Statecraft.Sim.Tests/SimTests.csindex 1ac5761a3..2d225a330 100644--- a/sim/Statecraft.Sim.Tests/SimTests.cs+++ b/sim/Statecraft.Sim.Tests/SimTests.cs@@ -113,6 +113,7 @@ options:effects:- target: fx_reservesdelta: -10+sources: [{ url: https://example.org/event, checked: 2026-10-18 }]";const string Raid = @"@@ -132,6 +133,7 @@ options:effects:- target: moraledelta: 0.05+sources: [{ url: https://example.org/event, checked: 2026-10-18 }]";static Content WithEvents() =>@@ -313,6 +315,7 @@ options:- id: push_ontext: Push onalternative: { basis: design }+sources: [{ url: https://example.org/event, checked: 2026-10-18 }]";[Fact]@@ -348,6 +351,7 @@ from: 1948-05-22options:- id: oktext: Fine+sources: [{ url: https://example.org/event, checked: 2026-10-18 }]";[Fact]diff --git a/sim/Statecraft.Sim.Tests/StructuredEffectTests.cs b/sim/Statecraft.Sim.Tests/StructuredEffectTests.csindex a336bed6c..0cef4b3fd 100644--- a/sim/Statecraft.Sim.Tests/StructuredEffectTests.cs+++ b/sim/Statecraft.Sim.Tests/StructuredEffectTests.cs@@ -26,6 +26,7 @@ from: 1948-05-15{STRUCTURED} - id: refusetext: Refusealternative: { basis: design }+sources: [{ url: https://example.org/event, checked: 2026-10-18 }]";const string Grants = @" grant_units:diff --git a/sim/Statecraft.Sim.Tests/SwampTests.cs b/sim/Statecraft.Sim.Tests/SwampTests.csindex 428137a88..271005ddd 100644--- a/sim/Statecraft.Sim.Tests/SwampTests.cs+++ b/sim/Statecraft.Sim.Tests/SwampTests.cs@@ -44,6 +44,7 @@ options:- id: go_ontext: Go onhistorical: true+sources: [{{ url: https://example.org/event, checked: 2026-10-18 }}]";static Dictionary<string, string> Files() => Fixture.Gdd(new Dictionary<string, string> { ["sites.yaml"] = Fixture.GddSites + Marsh });diff --git a/sim/Statecraft.Sim.Tests/TranslationLoaderTests.cs b/sim/Statecraft.Sim.Tests/TranslationLoaderTests.csindex 7b1812f34..6f461c879 100644--- a/sim/Statecraft.Sim.Tests/TranslationLoaderTests.cs+++ b/sim/Statecraft.Sim.Tests/TranslationLoaderTests.cs@@ -253,7 +253,7 @@ public class TranslationLoaderTestsf["gdd03-events.yaml"] = "ruleset: gdd-0.3\nexclusions:\n - { id: probe, reason: Fixture }\n";var dir = Fixture.Write(f, new Dictionary<string, string>{- ["probe.yaml"] = "id: probe\ntitle: Fixture\ntext: Fixture.\nfrom: 1948-05-15\noptions:\n - id: ok\n text: Accept\n historical: true\n",+ ["probe.yaml"] = "id: probe\ntitle: Fixture\ntext: Fixture.\nfrom: 1948-05-15\noptions:\n - id: ok\n text: Accept\n historical: true\nsources: [{ url: \"https://example.org/event\", checked: 2026-10-18 }]\n",});var c = WithFolder(new Dictionary<string, string> { ["ro/ui.yaml"] = Ro, ["ro/events.yaml"] = RoEvent("probe", "ok") }, t => ContentLoader.Load(dir, t));Assert.DoesNotContain(c.Events, e => e.Id == "probe");diff --git a/sim/Statecraft.Sim.Tests/ValidationTests.cs b/sim/Statecraft.Sim.Tests/ValidationTests.csindex b9ea9fc67..626845492 100644--- a/sim/Statecraft.Sim.Tests/ValidationTests.cs+++ b/sim/Statecraft.Sim.Tests/ValidationTests.cs@@ -27,6 +27,7 @@ options:- id: waittext: Wait for rainalternative: { basis: design }+sources: [{ url: https://example.org/event, checked: 2026-10-18 }]status: draft";@@ -47,12 +48,39 @@ status: draftpublic void FixtureWithTheTestEventLoads() =>ContentLoader.Load(Fixture.Write(events: new Dictionary<string, string> { ["drought.yaml"] = Event }));+ [Theory]+ [InlineData("title: Drought\n", "", "events[drought].title")]+ [InlineData("title: Drought", "title: ' '", "events[drought].title")]+ [InlineData("text: '{finance_minister} reports a drought.'\n", "", "events[drought].text")]+ [InlineData("text: '{finance_minister} reports a drought.'", "text: ' '", "events[drought].text")]+ [InlineData(" text: Ration water\n", "", "events[drought].options[ration].text")]+ [InlineData(" text: Ration water", " text: ' '", "events[drought].options[ration].text")]+ public void EventDisplayTextIsRequired(string from, string to, string field)+ {+ var ex = Bad("events/drought.yaml", from, to);+ Assert.Equal("events/drought.yaml", ex.File);+ Assert.Equal(field, ex.Field);+ Assert.Contains("text shown to the player", ex.Message);+ }++ [Theory]+ [InlineData("sources: [{ url: https://example.org/event, checked: 2026-10-18 }]\n", "", "events[drought].sources")]+ [InlineData("sources: [{ url: https://example.org/event, checked: 2026-10-18 }]", "sources: []", "events[drought].sources")]+ [InlineData("https://example.org/event", "http://example.org/event", "events[drought].sources[0]")]+ [InlineData(", checked: 2026-10-18", "", "events[drought].sources[0]")]+ public void EventSourcesAreRequiredAndComplete(string from, string to, string field)+ {+ var ex = Bad("events/drought.yaml", from, to);+ Assert.Equal("events/drought.yaml", ex.File);+ Assert.Equal(field, ex.Field);+ }+// I1: a key written with no value deserialises to null.[Theory][InlineData("events/drought.yaml", "tags: [economy]", "tags:", "events[drought].tags", "must be a list")][InlineData("events/drought.yaml", "options:\n - id: ration\n text: Ration water\n historical: true\n effects:\n - target: food_supply\n delta: 0.1\n - id: wait\n text: Wait for rain\n alternative: { basis: design }\n", "options:\n", "events[drought].options", "must be a list")][InlineData("events/drought.yaml", " effects:\n - target: food_supply\n delta: 0.1\n", " effects:\n", "events[drought].options[ration].effects", "must be a list")]- [InlineData("people.yaml", " offices:\n - office: defense_minister\n from: 1949-01-01\n - office: finance_minister\n from: 1948-05-14\n", " offices:\n", "people[def_two].offices", "must be a list")]+ [InlineData("people.yaml", " offices:\n - office: defense_minister\n from: 1949-01-01\n sources: *fixture_term_sources\n - office: finance_minister\n from: 1948-05-14\n sources: *fixture_term_sources\n", " offices:\n", "people[def_two].offices", "must be a list")][InlineData("legislatures.yaml", "seats: { alpha: 4, beta: 6 }", "seats:", "legislatures[house].seats", "must be a map")][InlineData("rules.yaml", "budget_start: { finance_minister: 1.0 }", "budget_start:", "budget_start", "must be a map")][InlineData("parties.yaml", "parties:\n - id: alpha\n name: Alpha\n - id: beta\n name: Beta\n", "parties:\n", "parties", "must be a list")]@@ -254,12 +282,28 @@ status: draftAssert.Equal(field, ex.Field);}++ // A YAML parse error names the mapping key on its line, and never a scalar that merely contains a colon.+ [Theory]+ [InlineData(" seats:", "seats")]+ [InlineData(" - { id: a }", null)]+ [InlineData(" - name: Beersheba", "name")]+ [InlineData(" - https://example.org/a", null)]+ [InlineData(" - a:b", null)]+ [InlineData(" url: https://example.org", "url")]+ [InlineData(" time: 10:30", "time")]+ [InlineData(" \"campaign.play_minutes\":", "campaign.play_minutes")]+ [InlineData(" \"basis\": \"Agreed\"", "basis")]+ public void AParseErrorNamesOnlyARealKey(string sourceLine, string? key)+ {+ Assert.Equal(key, ContentLoader.KeyOnLine("first: 1\n" + sourceLine + "\n", 2));+ }[Fact]public void DuplicateKeyIsAContentError(){// YamlDotNet keeps the last of two equal keys by default, which would silently drop the first value.var ex = Bad("legislatures.yaml", " size: 10\n", " size: 10\n seats:\n");Assert.Equal("legislatures.yaml", ex.File);- Assert.StartsWith("line ", ex.Field);+ Assert.Equal("seats (line 16)", ex.Field);}}diff --git a/sim/Statecraft.Sim.Tests/WarStateTests.cs b/sim/Statecraft.Sim.Tests/WarStateTests.csindex 1d1be5dde..f92dee6c0 100644--- a/sim/Statecraft.Sim.Tests/WarStateTests.cs+++ b/sim/Statecraft.Sim.Tests/WarStateTests.cs@@ -93,6 +93,7 @@ options:text: The way it wenthistorical: trueset_rung: 3+sources: [{ url: https://example.org/event, checked: 2026-10-18 }]";// Q-WAR-4 in the slice: an event's set_rung still moves the rung in the GDD loop.diff --git a/sim/Statecraft.Sim/Content.cs b/sim/Statecraft.Sim/Content.csindex 17c71040f..cd5ceb09e 100644--- a/sim/Statecraft.Sim/Content.cs+++ b/sim/Statecraft.Sim/Content.cs@@ -206,9 +206,15 @@ namespace Statecraft.Simpublic sealed class Portrait{- public string File { get; set; } = ""; public string License { get; set; } = ""; public string Source { get; set; } = "";+ public string File { get => file ?? ""; set => file = value; }+ public string License { get => license ?? ""; set => license = value; }+ public string Source { get => source ?? ""; set => source = value; }+ [YamlIgnore] public bool FileGiven => file != null;+ [YamlIgnore] public bool LicenseGiven => license != null;+ [YamlIgnore] public bool SourceGiven => source != null;+ string? file, license, source;/// <summary>Where the face is: its centre's height as a share of the picture (0 = top, 1 = bottom), so the event card- /// can keep it in view (playtest 2, P2-5). Required for a portrait with a file.</summary>+ /// can keep it in view (playtest 2, P2-5). Required whenever a portrait object is present.</summary>public double? FocusY { get; set; }}@@ -1111,8 +1117,11 @@ namespace Statecraft.Simpublic sealed class UnitOrderEffect{public string Unit { get; set; } = "";- public int Q { get; set; }- public int R { get; set; }+ public int Q { get => q ?? 0; set => q = value; }+ public int R { get => r ?? 0; set => r = value; }+ [YamlIgnore] public bool QGiven => q.HasValue;+ [YamlIgnore] public bool RGiven => r.HasValue;+ int? q, r;}/// <summary>An option's change to one field of a city (R-EFX-004): housing_capacity or job_slots by whole units, or thediff --git a/sim/Statecraft.Sim/ContentLoader.cs b/sim/Statecraft.Sim/ContentLoader.csindex 1d0afb823..051e07a1b 100644--- a/sim/Statecraft.Sim/ContentLoader.cs+++ b/sim/Statecraft.Sim/ContentLoader.cs@@ -12,9 +12,9 @@ namespace Statecraft.Sim{public static class ContentLoader{- sealed class OfficesFile { public List<Office> Offices { get; set; } = new List<Office>(); }- sealed class PartiesFile { public List<Party> Parties { get; set; } = new List<Party>(); }- sealed class PeopleFile { public List<Person> People { get; set; } = new List<Person>(); }+ sealed class OfficesFile { public List<Office> Offices { get; set; } = null!; }+ sealed class PartiesFile { public List<Party> Parties { get; set; } = null!; }+ sealed class PeopleFile { public List<Person> People { get; set; } = null!; }sealed class LegislaturesFile { public List<Legislature> Legislatures { get; set; } = new List<Legislature>(); }sealed class ErasFile { public List<Era> Eras { get; set; } = new List<Era>(); }sealed class GovernmentsFile { public List<Government> Governments { get; set; } = new List<Government>(); }@@ -118,7 +118,7 @@ namespace Statecraft.Simreturn (sid, sname, r.TryGetValue("type", out var ty) && ty is string ts ? ts : "");}).ToList();}- catch (YamlException e) { throw new ContentException(SettlementsFileName, $"line {e.Start.Line}", e.InnerException?.Message ?? e.Message); }+ catch (YamlException e) { throw ParseError(SettlementsFileName, text, e); }}static readonly HashSet<string> SettlementKeys = new HashSet<string>@@ -181,7 +181,7 @@ namespace Statecraft.SimCheckNulls(rel, "", alone);over = NodeYaml.Deserialize<Dictionary<object, object>>(text) ?? throw new ContentException(rel, "(file)", "empty file: list the keys this era changes");}- catch (YamlException e) { throw new ContentException(rel, $"line {e.Start.Line}", e.InnerException?.Message ?? e.Message); }+ catch (YamlException e) { throw ParseError(rel, text, e); }foreach (var k in StartOnlyKeys)if (over.ContainsKey(k))throw new ContentException(rel, k, k == "start" ? "an era cannot change the start date"@@ -240,11 +240,34 @@ namespace Statecraft.Simif (text == null) throw new ContentException(relPath, "(file)", "missing file");T result;try { result = Yaml.Deserialize<T>(text) ?? throw new ContentException(relPath, "(file)", "empty file"); }- catch (YamlException e) { throw new ContentException(relPath, $"line {e.Start.Line}", e.InnerException?.Message ?? e.Message); }+ catch (YamlException e) { throw ParseError(relPath, text, e); }CheckNulls(relPath, result is GameEvent ev ? $"events[{ev.Id}]" : "", result!);return result;}+ /// <summary>A strict-YAML refusal names the mapping key on the reported source line when one is available.</summary>+ static ContentException ParseError(string file, string text, YamlException e)+ {+ var key = KeyOnLine(text, (int)e.Start.Line);+ var field = key == null ? $"line {e.Start.Line}" : $"{key} (line {e.Start.Line})";+ return new ContentException(file, field, e.InnerException?.Message ?? e.Message);+ }++ internal static string? KeyOnLine(string text, int line)+ {+ if (line < 1) return null;+ var lines = text.Replace("\r\n", "\n").Split('\n');+ if (line > lines.Length) return null;+ var source = lines[line - 1].TrimStart();+ if (source.StartsWith("- ", StringComparison.Ordinal)) source = source.Substring(2).TrimStart();+ var colon = source.IndexOf(':');+ // A mapping key's colon ends the line or is followed by a space; "https://x" is a scalar, not a key "https".+ if (colon <= 0 || (colon + 1 < source.Length && source[colon + 1] != ' ')) return null;+ var key = source.Substring(0, colon).Trim();+ if (key.Length > 1 && (key[0] == '"' || key[0] == '\'') && key[key.Length - 1] == key[0]) key = key.Substring(1, key.Length - 2); // "ruleset": in gdd03-balance.yaml+ return key.Length > 0 && key.All(ch => char.IsLetterOrDigit(ch) || ch == '_' || ch == '-' || ch == '.') ? key : null;+ }+/// <summary>A key written with no value (`tags:`) deserialises to null. Null lists and maps become load errors/// naming the field; null strings become "" (the default every check already handles). Walks nested content/// objects, naming list entries by id when they have one, else by index.</summary>@@ -653,6 +676,24 @@ namespace Statecraft.Simif (string.IsNullOrWhiteSpace(name)) throw new ContentException(file, field, "required (the name shown to the player)");}+ /// <summary>Player-facing prose required by a content schema.</summary>+ internal static void RequiredText(string file, string field, string value)+ {+ if (string.IsNullOrWhiteSpace(value)) throw new ContentException(file, field, "required (text shown to the player)");+ }++ /// <summary>A schema-required source list: at least one HTTPS URL with its checked date.</summary>+ internal static void RequiredSources(string file, string field, List<Source> sources)+ {+ if (sources.Count == 0) throw new ContentException(file, field, "needs at least one source");+ for (int i = 0; i < sources.Count; i++)+ {+ var source = sources[i];+ if (source == null || source.Url == null || !source.Url.StartsWith("https://", StringComparison.Ordinal) || source.Checked == default)+ throw new ContentException(file, FormattableString.Invariant($"{field}[{i}]"), "needs an https url and a checked date");+ }+ }+/// <summary>A row's sign-off (#375): reviewed_by and reviewed_on together, a GitHub handle, a day as YYYY-MM-DD (read as/// text, the same rule as tools/review_record.py and the map's readers). <paramref name="at"/> is the row's path, as in "people[ben_gurion]".</summary>internal static void Review(string file, string at, string by, bool byGiven, string on, bool onGiven)@@ -898,6 +939,9 @@ namespace Statecraft.SimUnique("offices.yaml", "offices", c.Offices.Select(o => o.Id));Unique("parties.yaml", "parties", c.Parties.Select(p => p.Id));Unique("people.yaml", "people", c.People.Select(p => p.Id));+ foreach (var o in c.Offices) Named("offices.yaml", $"offices[{o.Id}].title", o.Title);+ foreach (var p in c.Parties) Named("parties.yaml", $"parties[{p.Id}].name", p.Name);+ foreach (var p in c.People) Named("people.yaml", $"people[{p.Id}].name", p.Name);Unique("legislatures.yaml", "legislatures", c.Legislatures.Select(l => l.Id));Unique("governments.yaml", "governments", c.Governments.Select(g => g.Id));Unique("eras.yaml", "eras", c.Eras.Select(e => e.Id));@@ -964,8 +1008,14 @@ namespace Statecraft.Simforeach (var p in c.People){- if (p.Portrait != null && p.Portrait.File != "" && !(p.Portrait.FocusY >= 0 && p.Portrait.FocusY <= 1))- throw new ContentException("people.yaml", $"people[{p.Id}].portrait.focus_y", "required: the face's height as a share of the picture, from 0 (top) to 1 (bottom)");+ if (p.Portrait != null)+ {+ if (!p.Portrait.FileGiven) throw new ContentException("people.yaml", $"people[{p.Id}].portrait.file", "required");+ if (!p.Portrait.LicenseGiven) throw new ContentException("people.yaml", $"people[{p.Id}].portrait.license", "required");+ if (!p.Portrait.SourceGiven) throw new ContentException("people.yaml", $"people[{p.Id}].portrait.source", "required");+ if (!(p.Portrait.FocusY >= 0 && p.Portrait.FocusY <= 1))+ throw new ContentException("people.yaml", $"people[{p.Id}].portrait.focus_y", "required: the face's height as a share of the picture, from 0 (top) to 1 (bottom)");+ }if (!p.Living.HasValue) throw new ContentException("people.yaml", $"people[{p.Id}].living", "required (true or false)");if (p.Competence < 0 || p.Competence > 10) throw new ContentException("people.yaml", $"people[{p.Id}].competence", "must be 0-10");if (p.Loyalty < 0 || p.Loyalty > 10) throw new ContentException("people.yaml", $"people[{p.Id}].loyalty", "must be 0-10");@@ -982,13 +1032,12 @@ namespace Statecraft.Simif (kv.Key != "name_he" && kv.Key != "title_he_form" && kv.Key != "born" && kv.Key != "died")throw new ContentException("people.yaml", field, "unknown field (must be name_he, title_he_form, born or died)");if (kv.Value == null) throw new ContentException("people.yaml", field, "must be a list");- for (int i = 0; i < kv.Value.Count; i++)- if (kv.Value[i] == null || string.IsNullOrWhiteSpace(kv.Value[i].Url) || kv.Value[i].Checked == default)- throw new ContentException("people.yaml", FormattableString.Invariant($"{field}[{i}]"), "needs a url and a checked date");+ RequiredSources("people.yaml", field, kv.Value);}TitleHeForm(c, p);foreach (var t in p.Offices){+ RequiredSources("people.yaml", $"people[{p.Id}].offices.{t.Office}.sources", t.Sources);if (string.IsNullOrEmpty(t.Office)) throw new ContentException("people.yaml", $"people[{p.Id}].offices", "office term without an office");if (!offices.Contains(t.Office)) throw new ContentException("people.yaml", $"people[{p.Id}].offices.{t.Office}", "unknown office");if (t.From == default) throw new ContentException("people.yaml", $"people[{p.Id}].offices.{t.Office}.from", "required");diff --git a/sim/Statecraft.Sim/EventRules.cs b/sim/Statecraft.Sim/EventRules.csindex 6f634294b..b405aba7d 100644--- a/sim/Statecraft.Sim/EventRules.cs+++ b/sim/Statecraft.Sim/EventRules.cs@@ -23,6 +23,9 @@ namespace Statecraft.Simforeach (var e in c.Events){string F(string field) => $"events[{e.Id}].{field}";+ ContentLoader.RequiredText(e.File, F("title"), e.Title);+ ContentLoader.RequiredText(e.File, F("text"), e.Text);+ ContentLoader.RequiredSources(e.File, F("sources"), e.Sources);if (!Offices.OfficeId.IsMatch(e.Id)) throw new ContentException(e.File, F("id"), ContentLoader.IdRule);if (!ids.Add(e.Id)) throw new ContentException(e.File, F("id"), "duplicate event id");if (e.Anchor != "hard" && e.Anchor != "soft") throw new ContentException(e.File, F("anchor"), $"unknown anchor '{e.Anchor}' (must be hard or soft)");@@ -71,6 +74,7 @@ namespace Statecraft.Simvar optionIds = new HashSet<string>();foreach (var o in e.Options){+ ContentLoader.RequiredText(e.File, F($"options[{o.Id}].text"), o.Text);if (!Offices.OfficeId.IsMatch(o.Id)) throw new ContentException(e.File, F($"options[{o.Id}].id"), ContentLoader.IdRule);if (!optionIds.Add(o.Id)) throw new ContentException(e.File, F($"options[{o.Id}].id"), "duplicate option id");CheckPlaceholders(c, e, F($"options[{o.Id}].text"), o.Text, offices);@@ -136,6 +140,14 @@ namespace Statecraft.Sim/// same real cards but no units file, so it has nothing to check them against and no unit to order.</summary>static void CheckOrders(Content c, GameEvent e, EventOption o, Func<string, string> F){+ for (int i = 0; i < o.UnitOrders.Count; i++)+ {+ var x = o.UnitOrders[i];+ var at = F(FormattableString.Invariant($"options[{o.Id}].unit_orders[{i}]"));+ if (x.Unit.Trim() == "") throw new ContentException(e.File, at + ".unit", "required");+ if (!x.QGiven) throw new ContentException(e.File, at + ".q", "required");+ if (!x.RGiven) throw new ContentException(e.File, at + ".r", "required");+ }if (!c.IsGdd) return;for (int i = 0; i < o.UnitOrders.Count; i++){@@ -350,7 +362,7 @@ namespace Statecraft.Simif (!v.When.Any(r => IsAlternativeRoad(c, r)))throw new ContentException(e.File, F($"{at}.when"), "a variant follows a road not taken: at least one entry names an option that did not happen, or diverged: true");if (v.Text.Trim() == "") throw new ContentException(e.File, F($"{at}.text"), "a variant has text");- if (v.Sources.Count == 0) throw new ContentException(e.File, F($"{at}.sources"), "needs at least one source");+ ContentLoader.RequiredSources(e.File, F($"{at}.sources"), v.Sources);if (v.Title != "") CheckPlaceholders(c, e, F($"{at}.title"), v.Title, offices);CheckPlaceholders(c, e, F($"{at}.text"), v.Text, offices);}