File size: 1,039 Bytes
4bc63c7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""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())