A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
Tests: the smoke fails fast on a disabled button or a skip that skips nothing, plus a 5-turn smoke test (#2445)
Eyal Golan3fe28db76acd
diff --git a/unity/Assets/Scripts/UI/CardVideo.cs b/unity/Assets/Scripts/UI/CardVideo.csindex 310697ec2..0ad4627b4 100644--- a/unity/Assets/Scripts/UI/CardVideo.cs+++ b/unity/Assets/Scripts/UI/CardVideo.cs@@ -42,8 +42,12 @@ namespace Statecraft.Game.UIreturn webgl ? Array.Exists(flags, f => Boot.UrlFlags.Has(url, f)) : Array.Exists(flags, f => Array.IndexOf(args, "-" + f) >= 0);}- public static bool ForcedOff() =>- ForcedOff(Application.absoluteURL, Environment.GetCommandLineArgs(), Application.platform == RuntimePlatform.WebGLPlayer);+ /// <summary>Test seam (internal; the tests see it through InternalsVisibleTo): an EditMode test cannot set the URL or the+ /// command line, so it sets this to boot as the automated runs do, with no video. Reset it after the test.</summary>+ internal static bool ForceOffForTests;++ public static bool ForcedOff() => ForceOffForTests+ || ForcedOff(Application.absoluteURL, Environment.GetCommandLineArgs(), Application.platform == RuntimePlatform.WebGLPlayer);/// <summary>The clip's URL in the build's StreamingAssets/video folder, with the build's id on the web (issue #437).</summary>public static string Url(string file) => Boot.GameInputs.WithBuildId(Application.streamingAssetsPath + "/video/" + file, Application.buildGUID);diff --git a/unity/Assets/Scripts/UI/GameRoot.cs b/unity/Assets/Scripts/UI/GameRoot.csindex e40767afe..cdc978cbb 100644--- a/unity/Assets/Scripts/UI/GameRoot.cs+++ b/unity/Assets/Scripts/UI/GameRoot.cs@@ -1202,8 +1202,7 @@ namespace Statecraft.Game.UIfor (int guard = 0; bridge.NeedsOrders.Count > 0; guard++){if (guard >= 200) { log("SMOKE FAIL unit skip loop reached 200"); yield break; }- if (!Press(root.Q<Button>("end-turn"), log)) yield break;- if (!Press(root.Q<Button>("info-skip"), log)) yield break;+ if (!SkipOneUnit(root, bridge, log)) yield break;yield return null;}int refused = 0;@@ -1260,8 +1259,7 @@ namespace Statecraft.Game.UIfor (int guard = 0; bridge.NeedsOrders.Count > 0; guard++){if (guard >= 200) { log("SMOKE FAIL unit skip loop reached 200"); yield break; }- if (!Press(root.Q<Button>("end-turn"), log)) yield break;- if (!Press(root.Q<Button>("info-skip"), log)) yield break;+ if (!SkipOneUnit(root, bridge, log)) yield break;yield return null;}if (!Press(root.Q<Button>("end-turn"), log)) yield break;@@ -1274,9 +1272,26 @@ namespace Statecraft.Game.UIlog(FormattableString.Invariant($"SMOKE ORDERS OK {bridge.TurnStart.Date:yyyy-MM-dd} {bridge.TurnStart.Hash()}"));}+ /// <summary>One pass of the smoke runs' unit loop: End Turn selects a unit that needs orders, and the unit card's Skip+ /// skips it. False, with "SMOKE FAIL info-skip skipped no unit" plus the waiting ids and the unit card's title, when no+ /// unit left the cycle (the v0.3.5 smoke spun 200 times behind a dialog, #2436).</summary>+ static bool SkipOneUnit(VisualElement root, SimBridge bridge, Action<string> log)+ {+ var before = bridge.NeedsOrders;+ if (!Press(root.Q<Button>("end-turn"), log) || !Press(root.Q<Button>("info-skip"), log)) return false;+ if (bridge.NeedsOrders.Count < before.Count) return true;+ // Smoke has no unit layer, so it names the units still waiting and the unit card's own title (the unit it shows,+ // which End Turn chose and may not be the first waiting).+ log(FormattableString.Invariant($"SMOKE FAIL info-skip skipped no unit: waiting {string.Join(",", before)}; the unit card shows '{root.Q<Label>("info-title")?.text}'"));+ return false;+ }++ /// <summary>Presses <paramref name="b"/> as keyboard Submit does. False, with a SMOKE FAIL line, when it is missing,+ /// out of reach (disabled, or under a disabled parent: Skip behind the v0.3.5 dialog took no press), or its handler throws.</summary>static bool Press(Button? b, Action<string> log){if (b == null) { log("SMOKE FAIL button missing"); return false; }+ if (!b.enabledInHierarchy) { log("SMOKE FAIL " + b.name + " is not enabled"); return false; }try{using (var e = NavigationSubmitEvent.GetPooled()) { e.target = b; b.SendEvent(e); }diff --git a/unity/Assets/Tests/EditMode/CaptureDialogTests.cs b/unity/Assets/Tests/EditMode/CaptureDialogTests.csindex 149562c57..48f103800 100644--- a/unity/Assets/Tests/EditMode/CaptureDialogTests.cs+++ b/unity/Assets/Tests/EditMode/CaptureDialogTests.cs@@ -996,4 +996,44 @@ public class CaptureDialogTestsCollectionAssert.AreEquivalent(new[] { "scale", "opacity" },card.resolvedStyle.transitionProperty.Select(x => x.ToString()), "a scale-up and a fade-in");}++ /// <summary>The smoke run (GameRoot.Smoke) fails on its first pass, naming the cause, when a dialog that End turn does not+ /// hide keeps the unit card out of reach. The v0.3.5 WebGL smoke pressed the disabled Skip 200 times behind Ramla's dialog+ /// before it failed (#2436). This rig's End turn selects no unit and hides nothing, as End turn did before #2436.</summary>+ [UnityTest]+ public IEnumerator TheSmokeFailsAtOnceWhenTheDialogKeepsTheUnitCardOutOfReach()+ {+ using (var r = new Rig(Awaiting(C, "lod")))+ {+ yield return Frames(4);+ Assert.IsTrue(r.Hud.ClassListContains(CaptureDialogPresenter.OpenClass), "precondition: the dialog is open");+ Assert.IsFalse(r.Root.Q<Button>("info-skip").enabledInHierarchy, "precondition: the dialog takes Skip out of reach");+ Assert.Greater(r.Bridge.NeedsOrders.Count, 0, "precondition: units need orders");+ var log = new List<string>();+ var run = GameRoot.Smoke(r.Root, r.Bridge, r.Card, 1, log.Add);+ while (run.MoveNext()) { }+ Assert.AreEqual("SMOKE FAIL info-skip is not enabled", log.Last(), string.Join("\n", log));+ }+ }++ /// <summary>A Skip that is in reach but skips nothing (the unit card shows no unit, InfoPanelPresenter.OrderUnit) fails the+ /// smoke run on its first pass too, instead of after 200.</summary>+ [UnityTest]+ public IEnumerator TheSmokeFailsAtOnceWhenSkipSkipsNoUnit()+ {+ using (var r = new Rig(Awaiting(C, "lod")))+ {+ yield return Frames(4);+ Press(r.Hide);+ yield return Frames(2);+ Assert.IsTrue(r.Dialog.Collapsed, "precondition: the dialog is hidden");+ Assert.IsTrue(r.Root.Q<Button>("info-skip").enabledInHierarchy, "precondition: Skip is in reach");+ Assert.Greater(r.Bridge.NeedsOrders.Count, 0, "precondition: units need orders");+ var waiting = r.Bridge.NeedsOrders.ToList();+ var log = new List<string>();+ var run = GameRoot.Smoke(r.Root, r.Bridge, r.Card, 1, log.Add);+ while (run.MoveNext()) { }+ StringAssert.StartsWith("SMOKE FAIL info-skip skipped no unit: waiting " + string.Join(",", waiting) + ";", log.Last(), string.Join("\n", log));+ }+ }}diff --git a/unity/Assets/Tests/EditMode/EndTurnCycleSceneTests.cs b/unity/Assets/Tests/EditMode/EndTurnCycleSceneTests.csindex cdadedf64..7d56a9e4e 100644--- a/unity/Assets/Tests/EditMode/EndTurnCycleSceneTests.cs+++ b/unity/Assets/Tests/EditMode/EndTurnCycleSceneTests.cs@@ -22,6 +22,7 @@ public class EndTurnCycleSceneTests[TearDown]public void DiscardScene(){+ CardVideo.ForceOffForTests = false;EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);if (ps != null) Object.DestroyImmediate(ps);if (rt != null) { rt.Release(); Object.DestroyImmediate(rt); }@@ -73,12 +74,44 @@ public class EndTurnCycleSceneTestsAssert.Greater(needs, 0, "precondition: units need orders");UiTestKit.Press(ui.Q<Button>("end-turn"));yield return null;+ Assert.IsTrue(root.Capture!.Collapsed, "End turn hid the dialog");+ Assert.IsFalse(ui.Q("root").ClassListContains(CaptureDialogPresenter.OpenClass), "the root no longer says the dialog is open");Assert.IsTrue(ui.Q("info-panel").enabledInHierarchy, "the selected unit's card takes orders");UiTestKit.Press(ui.Q<Button>("info-skip"));yield return null;Assert.AreEqual(needs - 1, bridge.NeedsOrders.Count, "Skip took the selected unit out of the cycle");- Assert.AreEqual("ramla", root.Capture!.Shown, "nothing was chosen: the capture still waits, behind Decision waiting");+ Assert.AreEqual("ramla", root.Capture.Shown, "nothing was chosen: the capture still waits, behind Decision waiting");}++ /// <summary>The 5-turn smoke as the WebGL "?golden&smoke=5" run plays it (tools/nightly_checks.py smoke_expect): the+ /// real scene on the golden seed, each unit skipped through End turn and the unit card, ending on the smoke5 hash the golden+ /// manifest pins. That run has no video (CardVideo.ForcedOff), so no outcome clip; this test boots the same way through+ /// CardVideo.ForceOffForTests, since an edit-mode run cannot set the URL.</summary>+ [UnityTest]+ public IEnumerator TheFiveTurnSmokeEndsOnTheManifestsSmoke5Hash()+ {+ dir = Path.Combine(Path.GetTempPath(), "statecraft-endturn-smoke5-" + Guid.NewGuid().ToString("N"));+ EditorSceneManager.OpenScene("Assets/Map.unity", OpenSceneMode.Single);+ var doc = Object.FindFirstObjectByType<UIDocument>();+ rt = new RenderTexture(CivMovementShots.Width, CivMovementShots.Height, 24, RenderTextureFormat.ARGB32);+ ps = Object.Instantiate(doc.panelSettings);+ ps.targetTexture = rt;+ doc.panelSettings = ps;+ var inputs = MapFocusTests.Inputs;+ Object.FindFirstObjectByType<Statecraft.Game.Map.MapScene>().Build(inputs.Map);+ var root = Object.FindFirstObjectByType<GameRoot>();+ root.Store = new SaveStore(dir);+ LogAssert.Expect(LogType.Warning, "SMOKE FAIL the smoke run needs play mode or a player");+ CardVideo.ForceOffForTests = true; // as the WebGL smoke boots: no video, so no outcome clip (reset in DiscardScene)+ root.Begin(inputs, 5);+ var ui = doc.rootVisualElement;+ for (int i = 0; i < 30 && !(ui.Q("top-bar").worldBound.height > 0); i++) yield return null;+ var smoke5 = Statecraft.Game.Boot.GoldenData.Parse(inputs.Goldens.Manifest).Single(x => x.name == "smoke5").hash;+ var log = new System.Collections.Generic.List<string>();+ yield return GameRoot.Smoke(ui, root.Bridge!, root.Card!, 5, log.Add);+ Assert.AreEqual("SMOKE OK 5 turns 1948-10-15 " + smoke5, log.Last(), string.Join("\n", log));+ }+[UnityTest]public IEnumerator BlockedEndTurnClosesDefenceAndShowsTheUnit() =>BlockedEndTurnRevealsTheUnit("defence", twoRows: false);