Asilarkness commited on
Commit
9dc3143
·
verified ·
1 Parent(s): 14d8558
Files changed (1) hide show
  1. harness/run_refs.py +38 -0
harness/run_refs.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """run_refs.py [task ids]: every reference solution must PASS its verifier, and an empty script must FAIL it (checks that the verifiers are neither broken nor trivial).
2
+ env BLENDER = path to the blender executable."""
3
+ import json, os, subprocess, sys, tempfile
4
+
5
+ HERE = os.path.dirname(os.path.abspath(__file__))
6
+ BLENDER = os.environ.get("BLENDER", r"D:\Blender\blender-5.2.2-windows-x64\blender.exe")
7
+ sys.path.insert(0, HERE)
8
+
9
+
10
+ def run(code, tid, timeout=180):
11
+ d = tempfile.mkdtemp()
12
+ cf, oj = os.path.join(d, "c.py"), os.path.join(d, "o.json")
13
+ open(cf, "w", encoding="utf-8").write(code)
14
+ env = dict(os.environ, BA_DIR=HERE)
15
+ try:
16
+ subprocess.run([BLENDER, "-b", "--factory-startup", "-P", os.path.join(HERE, "bl_runner.py"), "--", cf, tid, oj], capture_output=True, timeout=timeout, env=env)
17
+ return json.load(open(oj))
18
+ except Exception as e:
19
+ return dict(exec_ok=False, error=f"{type(e).__name__}: {e}", passed=False, score=0, checks=[], summary="")
20
+
21
+
22
+ if __name__ == "__main__":
23
+ import tasks
24
+ ids = sys.argv[1:] or list(tasks.TASKS)
25
+ bad = 0
26
+ for tid in ids:
27
+ ref = run(tasks.TASKS[tid]["ref"], tid)
28
+ neg = run("pass", tid)
29
+ good = ref.get("passed") and not neg.get("passed")
30
+ bad += not good
31
+ fails = [m for c, m in ref.get("checks", []) if not c]
32
+ print(f"{'OK ' if good else 'FAIL'} L{tasks.TASKS[tid]['level']} {tid:18s} ref passed={ref.get('passed')} score={ref.get('score', 0):.2f} exec_ok={ref.get('exec_ok')} | empty-script passed={neg.get('passed')} | {ref.get('seconds')} s", flush=True)
33
+ if not good:
34
+ if ref.get("error"):
35
+ print(" error:", ref["error"][-400:].replace(chr(10), " | "))
36
+ for m in fails[:4]:
37
+ print(" check failed:", m[:200])
38
+ print(f"{len(ids) - bad}/{len(ids)} tasks have a valid reference and a non-trivial verifier")