Chessistics/tools/automation/run_game.py
Samuel Bouchet f86b9abecd Add file-IPC automation harness for autonomous game testing
Launching Godot with --automation=<dir> activates an AutomationHarness
node that polls <dir>/inbox/ for JSON command files, executes them via
a thin facade over existing public surfaces (GameSim, InputMapper,
EventAnimator, ControlBar, PieceStockPanel), and writes results plus
screenshots back to disk. The black-box simulation boundary is not
crossed — every command routes through the same signals/methods a real
player would trigger.

A stdlib-only Python helper (tools/automation/harness.py) wraps the
protocol for test scripts and interactive REPLs. Smoke test passes
end-to-end: load mission, place a piece, step 10 turns, capture 14
1280x720 PNGs, handle rejections, quit cleanly. Existing 102 engine
unit tests still green.
2026-04-16 22:34:56 +02:00

33 lines
841 B
Python

"""Launch a Chessistics build with the automation harness enabled and drop
into an interactive Python REPL.
python tools/automation/run_game.py
Then at the prompt: `h.load_mission()`, `h.state()`, `h.screenshot("foo")`...
"""
from __future__ import annotations
import code
import sys
from harness import Harness
def main() -> None:
h = Harness.launch(run_name="repl")
try:
print(f"\nHarness launched. Working directory: {h.root}")
print("Ready-to-use object: `h` (see harness.py for the full API)\n")
banner = "Chessistics automation REPL — type h.<tab> for commands. Ctrl-D to quit."
local = {"h": h}
code.interact(banner=banner, local=local)
finally:
h.close()
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
sys.exit(130)