#!/usr/bin/env python3
from pathlib import Path
import argparse,subprocess,json,shutil
ap=argparse.ArgumentParser();ap.add_argument('--submission-dir',default='learner/starter');args=ap.parse_args()
root=Path(__file__).resolve().parent.parent; sub=(root/args.submission_dir).resolve(); node=shutil.which('node')
if not node: raise SystemExit('Node not found')
required=[sub/'scheduler-core.js',sub/'simulator.js']
missing=[str(p) for p in required if not p.is_file()]
if missing: raise SystemExit('Missing submission files: '+', '.join(missing))
results=[]
for mode in ['baseline','cooperative-deadline','unbounded','noncoop-timeout','serialized']:
 p=subprocess.run([node,str(root/'probe_runner.js'),str(sub),mode],text=True,capture_output=True)
 if p.returncode: raise SystemExit(p.stderr or p.stdout)
 results.append(json.loads(p.stdout.strip()))
print(json.dumps({'schema':'MAKNOW_WEB003_MUTATION_PROBE_v2','submission':str(sub),'note':'baseline/cooperative-deadline execute the supplied scheduler; unbounded/noncoop/serialized are explicit counterexample mutations beside that baseline','results':results},ensure_ascii=False,indent=2))
