#!/usr/bin/env python3 """Dev evaluator for dev-echo (public because the task is dev-set; real evaluators live in the private benchmark repository and sandbox the code they run). usage: evaluator.py WORKSPACE LANGUAGE TASK_DIR -> JSON verdict on stdout """ import json, os, subprocess, sys ws, lang = sys.argv[1], sys.argv[2] REPO = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) AJI = os.path.join(REPO, "zig-out", "bin", "aji") cases = ["", "hello", "x" * 64, "line one\nline two\n"] gates = {} def build(): if lang == "rust": return subprocess.run(["cargo", "build", "-q", "--offline"], cwd=ws, capture_output=True).returncode == 0 if lang == "zig": return subprocess.run(["zig", "build-exe", "main.zig"], cwd=ws, capture_output=True).returncode == 0 return subprocess.run([AJI, "check", "main.air"], cwd=ws, capture_output=True).returncode == 0 def run(inp): if lang == "aji_air": p = subprocess.run([AJI, "run", "--grant", "in=io.read", "--grant", "out=io.write", "--stdin", inp, "main.air"], cwd=ws, capture_output=True, text=True, timeout=60) try: rec = json.loads(p.stdout) except json.JSONDecodeError: return None return rec.get("stdout") if rec.get("status") == "returned" else None exe = "./target/debug/echo" if lang == "rust" else "./main" p = subprocess.run([exe], cwd=ws, input=inp, capture_output=True, text=True, timeout=60) return p.stdout if p.returncode == 0 else None gates["builds"] = build() gates["functional"] = gates["builds"] and all(run(c) == c for c in cases) print(json.dumps({"accepted": all(gates.values()), "gates": gates}))