From 8ee198ef02392c5a67a1776d11786d5c2af046c4 Mon Sep 17 00:00:00 2001 From: soul Date: Tue, 1 Dec 2026 07:52:07 +0100 Subject: [PATCH] Inventory grid harness: Soul's probes, the un-highlight check and six more mutants Interact gains what Soul's probes showed the harness did not reach (finding equip-flow-unpinned): a click on another cell after a double click counts 1, one hover handler per grid after repeated Display, the thermal right, top and bottom regions, and the bay-to-hull equip flow. The play capture clicks a second item and asserts the first is un-highlighted (kills unhighlight-dropped). tests/mutation_tests_inventory_grid.py --switch runs Soul's six mutants and a play kind that runs InventoryPanelsPlayCapture, so unhighlight-dropped and pulse-ignored are no longer run by hand. All 15 switch mutants exit 1 on the shipped code with the sheets still present. Co-Authored-By: Claude Sonnet 5.5 --- .../Editor/InventoryGridParityCapture.cs | 63 +++++++++++++++++++ .../Editor/InventoryPanelsPlayCapture.cs | 8 +++ tests/mutation_tests_inventory_grid.py | 43 ++++++++++--- 3 files changed, 107 insertions(+), 7 deletions(-) diff --git a/Assets/Scripts/Editor/InventoryGridParityCapture.cs b/Assets/Scripts/Editor/InventoryGridParityCapture.cs index 405ef77a1..9352154f9 100644 --- a/Assets/Scripts/Editor/InventoryGridParityCapture.cs +++ b/Assets/Scripts/Editor/InventoryGridParityCapture.cs @@ -1358,6 +1358,69 @@ public static class InventoryGridParityCapture if (!hud.Settings) hud.Settings = settings; hud.Display(ship, true); Check(!hud.Interactive && hud.Grid.GetComponents().Length == 0, "a HUD panel (Interactive false) adds no trigger component to its grid"); + + // ---- the handler paths the first checks do not reach: click state, hover subscriptions, thermal edges, the equip flow ---- + { + // click on a different cell after a double click starts again at 1 + var clicks2 = new List<(int2 cell, int count)>(); + equipment.Display(ship); + Layout(equipment); + using (equipment.OnClickAsObservable().Subscribe(e => clicks2.Add((e.data.Position, e.clickCount)))) + { + var a2 = itemCells[0]; + ExecuteEvents.Execute(grid.gameObject, Pointer(grid.gameObject, Centre(grid, a2)), ExecuteEvents.pointerClickHandler); + ExecuteEvents.Execute(grid.gameObject, Pointer(grid.gameObject, Centre(grid, a2)), ExecuteEvents.pointerClickHandler); + ExecuteEvents.Execute(grid.gameObject, Pointer(grid.gameObject, Centre(grid, other)), ExecuteEvents.pointerClickHandler); + Check(clicks2.Count == 3 && clicks2[1].count == clicks2[0].count + 1 && clicks2[2].cell.Equals(other) && clicks2[2].count == 1, $"a click on another cell after a double click counts 1 (got {string.Join(";", clicks2.Select(c => c.cell.x + "," + c.cell.y + "x" + c.count))})"); + } + // subscriptions do not accumulate over Display + int Handlers(InventoryGrid g) => ((Delegate) typeof(InventoryGrid).GetField("HoveredCellChanged", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(g))?.GetInvocationList().Length ?? 0; + equipment.Display(ship); equipment.Display(ship); equipment.Display(ship, false, true); equipment.Display(ship); + cargoPanel.Display(bay); cargoPanel.Display(bay); cargoPanel.Display(bay); + Check(Handlers(grid) == 1 && Handlers(cargoGrid) == 1, $"one hover handler per grid after repeated Display (equipment {Handlers(grid)}, cargo {Handlers(cargoGrid)})"); + // thermal: right, up and down regions toggle their neighbours + equipment.Display(ship, false, true); + Layout(equipment); + var t = hull.Shape.AllCoordinates.First(c => hull.Shape[c] && hull.Shape[new int2(c.x + 1, c.y)] && hull.Shape[new int2(c.x, c.y + 1)] && hull.Shape[new int2(c.x, c.y - 1)]); + var cr = grid.CellRect(t); + Vector2 At(float fx, float fy) => ScreenOf(grid, cr.min + new Vector2(cr.width * fx, cr.height * fy)); + var rightWas = ship.HullConductivity[t.x, t.y].x; var upWas = ship.HullConductivity[t.x, t.y].y; var downWas = ship.HullConductivity[t.x, t.y - 1].y; + ExecuteEvents.Execute(grid.gameObject, Pointer(grid.gameObject, At(.9f, .5f)), ExecuteEvents.pointerClickHandler); + Check(ship.HullConductivity[t.x, t.y].x != rightWas, "a thermal click at the right of a cell toggles the right conductivity"); + ExecuteEvents.Execute(grid.gameObject, Pointer(grid.gameObject, At(.5f, .9f)), ExecuteEvents.pointerClickHandler); + Check(ship.HullConductivity[t.x, t.y].y != upWas, "a thermal click at the top of a cell toggles the upward conductivity"); + ExecuteEvents.Execute(grid.gameObject, Pointer(grid.gameObject, At(.5f, .1f)), ExecuteEvents.pointerClickHandler); + Check(ship.HullConductivity[t.x, t.y - 1].y != downWas, "a thermal click at the bottom of a cell toggles the downward conductivity"); + equipment.Display(ship); + Layout(equipment); + // the equip flow: an item dragged from the bay onto the equipment panel + var gone = ship.TryUnequip(equipped); + Check(gone != null, "the equipped item unequips"); + if (gone != null) + { + bay.TryStore(gone); + cargoPanel.Display(bay); equipment.Display(ship); + Layout(cargoPanel); Layout(equipment); + var pos = bay.Cargo[gone]; + var gdata = fixture.Manager.ItemManager.GetData(gone); + var grab = bay.Data.InteriorShape.Inset(gdata.Shape, pos, gone.Rotation).Coordinates[0]; + var off = pos - grab; + var landing = equipped.Position - off; + var press2 = Centre(cargoGrid, grab); + ExecuteEvents.Execute(cargoGrid.gameObject, Pointer(cargoGrid.gameObject, press2), ExecuteEvents.beginDragHandler); + Check(fixture.Manager.DragObject is ItemInstanceDragObject && (cargoPanel.IgnoreOccupancy?[grab] ?? false), "a begin drag on the bay's item starts an item-instance drag and ignores its cells"); + ExecuteEvents.Execute(grid.gameObject, Pointer(grid.gameObject, Centre(grid, landing)), ExecuteEvents.pointerMoveHandler); + Check(equipment.FakeItem == gone && equipment.FakeOccupancy != null && equipment.FakeOccupancy.Coordinates.Any(), $"the pointer over a fitting hull cell sets the equipment panel's FakeOccupancy (landing {landing.x},{landing.y})"); + ExecuteEvents.Execute(grid.gameObject, Pointer(grid.gameObject, Centre(grid, landing)), ExecuteEvents.pointerExitHandler); + Check(equipment.FakeItem == null && equipment.FakeOccupancy == null, "leaving the hull clears the equipment panel's FakeOccupancy"); + ExecuteEvents.Execute(grid.gameObject, Pointer(grid.gameObject, Centre(grid, landing)), ExecuteEvents.pointerMoveHandler); + ExecuteEvents.Execute(cargoGrid.gameObject, Pointer(cargoGrid.gameObject, Centre(grid, landing), press2), ExecuteEvents.endDragHandler); + Check(cargoPanel.IgnoreOccupancy == null && fixture.Manager.DragObject == null, "an end drag in the bay clears its IgnoreOccupancy and the drag"); + Check(ship.Equipment.Any(e => e.EquippableItem == gone) && !bay.Occupancy.Cast().Any(i => i == gone), "the drop equipped the item and took it out of the bay"); + var back = hull.Shape.Inset(gdata.Shape, ship.Equipment.First(e => e.EquippableItem == gone).Position, gone.Rotation).Coordinates; + Check(back.All(v => grid.RecordAt(v).Item), "the equipment panel draws the dropped item's cells"); + } + } } finally { diff --git a/Assets/Scripts/Editor/InventoryPanelsPlayCapture.cs b/Assets/Scripts/Editor/InventoryPanelsPlayCapture.cs index 43b4ba611..339e17bb7 100644 --- a/Assets/Scripts/Editor/InventoryPanelsPlayCapture.cs +++ b/Assets/Scripts/Editor/InventoryPanelsPlayCapture.cs @@ -241,6 +241,14 @@ public static class InventoryPanelsPlayCapture $"a click on {fitted.Data.Name} highlights its {itemCells.Length} cells"); yield return Snap("highlight"); + // a click on a different item un-highlights the first: its cells draw their plain colour again, the second item's the highlight colour + var second = ship.Equipment.Where(e => e.EquippableItem != null && e.EquippableItem != fitted.EquippableItem).OrderBy(e => e.Data.Shape.Coordinates.Length).FirstOrDefault(); + Require(second != null, "a second fitted item exists to click"); + var secondCells = hull.Shape.Inset(second.Data.Shape, second.Position, second.EquippableItem.Rotation).Coordinates; + ExecuteEvents.Execute(grid.gameObject, Pointer(Centre(grid, secondCells[0])), ExecuteEvents.pointerClickHandler); + Require(itemCells.All(v => Pack(grid.RecordAt(v).Icon) == Pack(equipmentPanel.GetColor(v, false))) && secondCells.All(v => Pack(grid.RecordAt(v).Icon) == Pack(equipmentPanel.GetColor(v, true))), + $"a click on {second.Data.Name} un-highlights {fitted.Data.Name} and highlights its own {secondCells.Length} cells"); + // drag: the ghost; hover: the other panel's FakeOccupancy var press = Centre(grid, itemCells[0]); ExecuteEvents.Execute(grid.gameObject, Pointer(press), ExecuteEvents.beginDragHandler); diff --git a/tests/mutation_tests_inventory_grid.py b/tests/mutation_tests_inventory_grid.py index 748ea9993..f68969426 100644 --- a/tests/mutation_tests_inventory_grid.py +++ b/tests/mutation_tests_inventory_grid.py @@ -33,6 +33,7 @@ HARNESS = REPO_ROOT / "Assets" / "Scripts" / "Editor" / "InventoryGridParityCapt SHADER = REPO_ROOT / "Assets" / "Shaders" / "InventoryGrid.shader" GRID = REPO_ROOT / "Assets" / "Scripts" / "UI" / "Menu" / "InventoryGrid.cs" PANEL = REPO_ROOT / "Assets" / "Scripts" / "UI" / "Menu" / "InventoryPanel.cs" +MENU = REPO_ROOT / "Assets" / "Scripts" / "UI" / "Menu" / "InventoryMenu.cs" SCRATCH = REPO_ROOT / "tests" / "_scratch_inventory_grid" # name -> (harness argument or None, (file, anchor, mutated) or None, which bound kills it) @@ -56,8 +57,8 @@ MUTANTS = { # The switch's mutants (cut inventory-grid-switch): each is run with `-hullOnly -recordsIn ` and must exit 1 with a BOUND BREACHED # line. name -> (harness argument or None, (file, anchor, mutated, occurrences) or None, which check kills it). The golden is the run -# output of the first commit of the cut (`-recordsOut` at bf375bfca); `pulse-ignored` (_pulse not read) is killed only by the play -# capture's pulse assertion, run once by hand: InventoryPanelsPlayCapture. +# output of the first commit of the cut (`-recordsOut` at bf375bfca). The "play" kind runs InventoryPanelsPlayCapture (a real play session +# through MainMenu.Launch) instead of the harness: pulse-ignored (_pulse not read) and unhighlight-dropped (InventoryMenu) are play-only. SWITCH_MUTANTS = { "flip-not-derived": (None, (PANEL, "public bool Flip => Grid.Orientation == GridOrientation.UpperRight;", "public bool Flip => false;", 1), "enemy golden"), "highlight-dropped": (None, (PANEL, "Icon = GetColor(v, highlight),", "Icon = GetColor(v),", 2), "interact"), @@ -66,6 +67,13 @@ SWITCH_MUTANTS = { "ghost-full-alpha": ("ghost-full-alpha", None, "ghost pixels"), "temperature-anchor-0": (None, (PANEL, "Grid.CellRect(int2(-1, -1)).min", "Grid.CellRect(int2(0, 0)).min", 1), "golden rects"), "cargo-thermal-kept": (None, (PANEL, " Grid.Thermal = false;\n Grid.Resize(interior.Width", " Grid.Resize(interior.Width", 1), "cargo pixels after a thermal state"), + "click-count-cell-reset-dropped": (None, (PANEL, "if (!_clickCell.HasValue || !_clickCell.Value.Equals(v) || Time.time - _clickTime > DoubleClickTime)", "if (!_clickCell.HasValue || Time.time - _clickTime > DoubleClickTime)", 1), "interact"), + "hover-subscription-leak": (None, (PANEL, "_subscriptions.Add(Disposable.Create(() => Grid.HoveredCellChanged -= Hover));", ";", 2), "interact"), + "cargo-enddrag-ignore-kept": (None, (PANEL, "//Debug.Log(\"Inventory Drag End\");\n IgnoreOccupancy = null;", "//Debug.Log(\"Inventory Drag End\");", 1), "interact"), + "entity-hover-exit-dead": (None, (PANEL, "//Debug.Log(\"Entity Pointer Exit\");\n if (GameManager.DragObject is ItemDragObject)", "//Debug.Log(\"Entity Pointer Exit\");\n if (false)", 1), "interact"), + "thermal-right-toggle-dead": (None, (PANEL, "point.x > 1 - ThermalToggleRegionSize", "point.x > 1 + ThermalToggleRegionSize", 1), "interact"), + "unhighlight-dropped": (None, (MENU, "_selectedPanel?.SetHighlight(_selectedItem, false);", "", 2), "play"), + "pulse-ignored": (None, (PANEL, "Background = _pulse.TryGetValue(v, out var pulse) ? pulse : CellBackgroundColor", "Background = CellBackgroundColor", 1), "play"), } @@ -101,6 +109,18 @@ def release_lock() -> None: pass +def run_play(log: Path, png_dir: Path) -> tuple[int, str]: + take_lock() + try: + proc = subprocess.Popen([UNITY_EXE, "-batchmode", "-projectPath", str(REPO_ROOT), "-executeMethod", + "InventoryPanelsPlayCapture.Run", "-pngOut", str(png_dir), "-logFile", str(log)]) + (LOCK / "holder.txt").write_text(f"nibu-hands-invgrid-mutation {proc.pid}\n") + code = proc.wait(timeout=1500) + finally: + release_lock() + return code, log.read_text(encoding="utf-8", errors="replace") + + def run_harness(log: Path, extra: list[str]) -> tuple[int, str]: take_lock() try: @@ -162,17 +182,26 @@ def run_switch(golden: str, only: list[str]) -> int: if code != 0 or "[InventoryGridParity] PASS" not in text: failures.append("switch control: expected exit 0 and PASS on the unmutated tree") print(f"switch control: exit {code}") - for name, (arg, edit, kills) in SWITCH_MUTANTS.items(): + if not only or any(SWITCH_MUTANTS[n][2] == "play" for n in only if n in SWITCH_MUTANTS): + code, text = run_play(SCRATCH / "play-control.log", SCRATCH / "play-control") + if code != 0 or "[InventoryPanelsPlayCapture] PASS" not in text: + failures.append("play control: expected exit 0 and PASS on the unmutated tree") + print(f"play control: exit {code}") + for name, (arg, edit, kind) in SWITCH_MUTANTS.items(): if only and name not in only: continue - print(f"\n=== switch mutant {name} (killed by: {kills}) ===") + print(f"\n=== switch mutant {name} (killed by: {kind}) ===") original = replace_unique(*edit) if edit else None try: - code, text = run_harness(SCRATCH / f"switch-{name}.log", [*args, *(["-mutant", arg] if arg else [])]) + if kind == "play": + code, text = run_play(SCRATCH / f"switch-{name}.log", SCRATCH / f"play-{name}") + else: + code, text = run_harness(SCRATCH / f"switch-{name}.log", [*args, *(["-mutant", arg] if arg else [])]) finally: if edit: edit[0].write_bytes(original.encode("utf-8")) - breaches = [line for line in text.splitlines() if "BOUND BREACHED" in line] + breaches = [line for line in text.splitlines() if ("assertion failed" if kind == "play" else "BOUND BREACHED") in line + or (kind == "interact" and "FAILED interact" in line)] killed = code == 1 and bool(breaches) print(f"{name}: exit {code}, killed={killed}") for line in breaches[:3]: @@ -182,7 +211,7 @@ def run_switch(golden: str, only: list[str]) -> int: if failures: print("\nFAILURES:\n " + "\n ".join(failures)) return 1 - print("\nEvery switch mutant was killed; pulse-ignored is the play capture's.") + print("\nEvery switch mutant was killed.") return 0