analyst-workbench / v13 /scripts /local_check.py
ajinkyamulay's picture
Add v13 shell environment
10f3201 verified
Raw History Blame Contribute Delete
2.49 kB
"""Check v13 tasks without Docker: the reference solution must pass the hidden tests, an
untouched work folder must fail them, and solution/strawman.py (required) must fail them.
scripts/py scripts/local_check.py tasks [task_id ...]
"""
import os, shutil, subprocess, sys, tempfile, tomllib
from pathlib import Path
DOMAINS = {"software-engineering", "industrial-physical-systems", "natural-science", "office-white-collar",
"finance-economics", "mathematics-or-formal-reasoning", "cybersecurity", "media-content-production"}
def tests_pass(task, work):
env = dict(os.environ, TASK_WORK=str(work), TASK_DATA=str(task / "data"))
r = subprocess.run([sys.executable, "-m", "pytest", "-q", "-p", "no:cacheprovider", str(task / "tests/test_outputs.py")],
env=env, capture_output=True, text=True, timeout=300)
return r.returncode == 0, r.stdout[-600:]
def run(task, script):
work = Path(tempfile.mkdtemp()) / task.name
shutil.copytree(task / "data", work)
if script:
r = subprocess.run([sys.executable, str(script)], cwd=work, capture_output=True, text=True, timeout=300)
if r.returncode:
return False, "script failed: " + r.stderr[-400:]
return tests_pass(task, work)
root = Path(sys.argv[1]).resolve()
ids = sys.argv[2:] or sorted(p.name for p in root.iterdir() if (p / "instruction.md").exists())
bad = 0
for t in ids:
task = root / t; problems = []
meta = tomllib.loads((task / "task.toml").read_text())
if meta.get("metadata", {}).get("domain") not in DOMAINS:
problems.append("task.toml domain missing or unknown")
for f in ["instruction.md", "data", "tests/test.sh", "tests/test_outputs.py", "solution/solve.py", "solution/strawman.py", "notes/gen.py"]:
if not (task / f).exists():
problems.append("missing " + f)
n = len((task / "instruction.md").read_text())
if n > 2000:
problems.append(f"instruction is {n} chars (max 2000)")
if not problems:
ok, out = run(task, task / "solution/solve.py")
if not ok: problems.append("reference fails: " + out)
ok, out = run(task, None)
if ok: problems.append("untouched work folder passes")
ok, out = run(task, task / "solution/strawman.py")
if ok: problems.append("strawman passes")
bad += bool(problems)
print(("OK " if not problems else "BAD ") + t + ("" if not problems else ": " + " | ".join(problems)))
sys.exit(1 if bad else 0)