"""Node: executor. Writes the edit pair in one transaction and runs the suite. The executor is the only node that writes. Everything it does is recorded so the two independent checkers can re-derive the result instead of trusting it. """ import json import os import sys ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.insert(0, ROOT) from lingologos_thinkingpython import session # noqa: E402 def main() -> int: task = json.load(sys.stdin) workspace = task["workspace"] plan = task["plan"] cwd = os.getcwd() os.chdir(workspace) try: receipt = session.apply_pair(workspace, plan) suite = session.run_suite(workspace) finally: os.chdir(cwd) status = "ok" if receipt.get("applied") else "refused" print(json.dumps({"node": "executor", "status": status, "receipt": receipt, "suite": suite["status"], "output": suite["output"]})) return 0 if status == "ok" else 1 if __name__ == "__main__": raise SystemExit(main())