Inventory grid mutants: the switch's seven (six by exit 1 on the parity harness, pulse-ignored by the play capture); the cargo state follows a thermal view on the same panel

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
soul 2026-12-01 05:11:37 +01:00
commit 99d4a817b4

View file

@ -13,6 +13,7 @@ side. A mutant whose reading is not 1.2 above the bound is recorded as UNCLAIMED
One Unity batch instance runs on Starfire at a time, so each launch takes the lock directory F:/aeth-wt/unity.lock.d first.
Run from the repo root: python tests/mutation_tests_inventory_grid.py
The switch's mutants (SWITCH_MUTANTS) run with: python tests/mutation_tests_inventory_grid.py --switch <golden.json>
Exit code 0 only if the control passes, every claimed mutant is killed, and the bound sits where the margin rule puts it.
"""
from __future__ import annotations
@ -31,6 +32,7 @@ LOCK = Path("F:/aeth-wt/unity.lock.d")
HARNESS = REPO_ROOT / "Assets" / "Scripts" / "Editor" / "InventoryGridParityCapture.cs"
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"
SCRATCH = REPO_ROOT / "tests" / "_scratch_inventory_grid"
# name -> (harness argument or None, (file, anchor, mutated) or None, which bound kills it)
@ -52,6 +54,21 @@ MUTANTS = {
}
# The switch's mutants (cut inventory-grid-switch): each is run with `-hullOnly -recordsIn <golden>` 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.
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"),
"hover-exit-silent": (None, (GRID, "public void OnPointerExit(PointerEventData data) => SetHovered(null);", "public void OnPointerExit(PointerEventData data) => _hovered = null;", 1), "interact"),
"press-cell-from-release": (None, (PANEL, "Grid.CellAt(data.position, data.pressEventCamera, out cell, out _) && cell.Equals(pressed);", "Grid.CellAt(data.position, data.pressEventCamera, out cell, out _);", 1), "interact"),
"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"),
}
def pid_alive(pid: int) -> bool:
out = subprocess.run(["tasklist", "/FI", f"PID eq {pid}", "/NH"], capture_output=True, text=True).stdout
return str(pid) in out
@ -125,16 +142,51 @@ def summary(text: str) -> tuple[int, int, float, int, int, float]:
return int(m.group(1)), int(m.group(2)), float(m.group(3)), int(m.group(5)), int(m.group(6)), float(m.group(4))
def replace_unique(path: Path, anchor: str, mutated: str) -> str:
def replace_unique(path: Path, anchor: str, mutated: str, occurrences: int = 1) -> str:
original = path.read_bytes().decode("utf-8")
if "\r\n" in original:
anchor, mutated = anchor.replace("\n", "\r\n"), mutated.replace("\n", "\r\n")
count = original.count(anchor)
if count != 1:
raise SystemExit(f"{path}: anchor must occur exactly once, found {count}\n---\n{anchor}")
if count != occurrences:
raise SystemExit(f"{path}: anchor must occur {occurrences} time(s), found {count}\n---\n{anchor}")
path.write_bytes(original.replace(anchor, mutated).encode("utf-8"))
return original
def run_switch(golden: str) -> int:
SCRATCH.mkdir(parents=True, exist_ok=True)
args = ["-hullOnly", "-recordsIn", golden]
failures: list[str] = []
print("\n=== switch control: unmutated tree ===")
code, text = run_harness(SCRATCH / "switch-control.log", args)
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():
print(f"\n=== switch mutant {name} (killed by: {kills}) ===")
original = replace_unique(*edit) if edit else None
try:
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]
killed = code == 1 and bool(breaches)
print(f"{name}: exit {code}, killed={killed}")
for line in breaches[:3]:
print(" " + line.split("[InventoryGridParity] ")[-1][:200])
if not killed:
failures.append(f"{name}: not killed (exit {code})")
if failures:
print("\nFAILURES:\n " + "\n ".join(failures))
return 1
print("\nEvery switch mutant was killed; pulse-ignored is the play capture's.")
return 0
def main() -> int:
if len(sys.argv) == 3 and sys.argv[1] == "--switch":
return run_switch(sys.argv[2])
SCRATCH.mkdir(parents=True, exist_ok=True)
failures: list[str] = []
readings: dict[str, tuple[int, float]] = {}