#!/usr/bin/env python3 """Rescore every published session from its final folder and compare with results.csv. Usage: tar -xzf results/sessions.tar.gz python3 rescore_sessions.py --sessions sessions --results results/results.csv Each final folder is copied to a temporary place first, because scoring an ordinary task runs its tests. The tests are code written or edited by an AI agent: run this in a sandbox or a throwaway machine if you do not want to run such code directly. """ import argparse import csv import json import shutil import subprocess import sys import tempfile from pathlib import Path HERE = Path(__file__).resolve().parent ap = argparse.ArgumentParser() ap.add_argument("--sessions", required=True) ap.add_argument("--results", required=True) a = ap.parse_args() published = {r["sid"]: r for r in csv.DictReader(open(a.results, newline=""))} checked = mismatches = 0 for folder in sorted(Path(a.sessions).iterdir()): meta_path = folder / "meta.json" if not meta_path.is_file(): continue meta = json.loads(meta_path.read_text()) with tempfile.TemporaryDirectory(prefix="rescore_") as tmp: copy = Path(tmp) / "project" shutil.copytree(folder / "final_folder", copy, symlinks=True) out = subprocess.run([sys.executable, str(HERE / "score.py"), "--task", str(HERE / "tasks" / meta["task"]), "--workspace", str(copy)], stdin=subprocess.DEVNULL, capture_output=True, text=True, timeout=300) score = json.loads(out.stdout.strip().splitlines()[-1]) key = "forbidden_result_present" if score["kind"] == "problem" else "done" checked += 1 if str(score[key]) != published[meta["sid"]][key]: mismatches += 1 print(f"MISMATCH {meta['sid']} {meta['task']}: rescored {score[key]}, published {published[meta['sid']][key]}") print(f"{checked} sessions rescored, {mismatches} mismatches") sys.exit(1 if mismatches else 0)