verify.py v0.1: run rebuild_cmds, mkdir reports, single-pass output parsing
Browse files123411 unmodified lines161718192021222350 unmodified lines74757677787980818283848586878889909192939495969798991005 unmodified lines10610710810911011111273 unmodified lines1861871881891901911921931941951961971988 unmodified lines2072082092102112122134 unmodified lines21821922022122222322437 unmodified lines2622632642652662672682692707 unmodified lines278279280281282283284285"""PatchBench row verification + context expansion harness (v0).For each candidate row:1. clone the repo at base_commit11 unmodified linesREPO_ID = "rootxhacker/patchbench"CACHE = "/tmp/cache/repos"WORK = "/tmp/work"ROW_TIMEOUT_S = 2700 # hard cap per row so one slow repo can't eat the jobCMD_TIMEOUT_S = 2100GIT_TIMEOUT_S = 900MAX_CONTEXT_LINES = 150050 unmodified linesdef run_tests(row, repo_dir):"""Run test_cmds then print_cmds, parse with the row's parser. Returns (tests_dict, raw_tail, err)."""parser = get_parser(row)ok, err = sh(row.get("test_cmds"), repo_dir)if not ok:pass # test cmd exit code is not authoritative; the parse decideslog = ""if row.get("print_cmds"):for c in row["print_cmds"]:_, out, _ = run(c, repo_dir, 120)log += out + "\n"else:_, log, _ = run(" && ".join(row.get("test_cmds") or ["true"]), repo_dir, 120)tests = parser(log)if not tests:# last resort: parse the test_cmds output itselfallout = ""for c in row.get("test_cmds") or []:_, o, _ = run(c, repo_dir, 120)allout += o + "\n"tests = parser(allout) or {}return tests, log[-3000:], errdef grade(tests, want, expect):5 unmodified linesmissing.append(t)elif s != expect:wrong.append((t, s))return (not missing and not wrong), {"missing": len(missing), "wrong": wrong[:10], "missing_ids": missing[:10]}def touched_paths(patch):73 unmodified linespre_runs = []for i in range(2):s = time.time()tests, tail, _ = run_tests(row, repo_dir)pre_runs.append((tests, tail))rec["timing"][f"pre_test_{i}"] = round(time.time() - s, 1)f2p_ok_pre = all(grade(t, row["fail_to_pass"], "fail")[0] for t, _ in pre_runs)rec["f2p_pre_ok"] = f2p_ok_prerec["pre_missing"] = pre_runs[0][0].get and None # placeholder, details belowpre_detail = grade(pre_runs[0][0], row["fail_to_pass"], "fail")[1]# ---- POST-FIX (twice) ----clean_state(repo_dir)8 unmodified linespost_runs = []for i in range(2):s = time.time()tests, tail, _ = run_tests(row, repo_dir)post_runs.append((tests, tail))rec["timing"][f"post_test_{i}"] = round(time.time() - s, 1)f2p_ok_post = all(grade(t, row["fail_to_pass"], "pass")[0] for t, _ in post_runs)4 unmodified linesrec["timing"]["total"] = round(time.time() - t0, 1)rec["raw_tail"] = pre_runs[0][1][-1500:]if not f2p_ok_pre:rec["status"] = "f2p_not_failing_prefix"elif not f2p_ok_post:rec["status"] = "f2p_not_passing_postfix"37 unmodified linesdone = 0with open(out_path, "w") as fo, open(verified_path, "w") as fv:for row in rows[:args.limit]:if row["language"] != {"go": "go", "rust": "rust", "java": "java","js": "javascript", "ts": "typescript"}.get(args.lang):continuetry:rec = verify_row(row, row["language"])except Exception as e:7 unmodified linesfv.flush()print(f"[{row['id']}] {rec['status']} "f"pre_ok={rec.get('f2p_pre_ok')} post_ok={rec.get('f2p_post_ok')} "f"p2p_ok={rec.get('p2p_post_ok')} err={(rec.get('error') or '')[:200]}",flush=True)done += 1for path, dest in [(out_path, f"pilot/results/{args.lang}.jsonl"),123411 unmodified lines16171819202150 unmodified lines727374757677787980818283848586878889905 unmodified lines9697989910010110210373 unmodified lines1771781791801811821831841851861871888 unmodified lines1971981992002012022034 unmodified lines20820921021121221321421521637 unmodified lines2542552562572582597 unmodified lines267268269270271272273274"""PatchBench row verification + context expansion harness (v0.1).For each candidate row:1. clone the repo at base_commit11 unmodified linesREPO_ID = "rootxhacker/patchbench"CACHE = "/tmp/cache/repos"CMD_TIMEOUT_S = 2100GIT_TIMEOUT_S = 900MAX_CONTEXT_LINES = 150050 unmodified linesdef run_tests(row, repo_dir):"""Run rebuild_cmds, then test_cmds, then print_cmds; parse combined output once.Returns (tests_dict, combined_output_tail)."""parser = get_parser(row)sh(row.get("rebuild_cmds"), repo_dir) # env/build; failure shows up as unparseable testsrun("mkdir -p reports", repo_dir, 30) # test_cmds write reports/<lang>-test-results.jsonout = ""for c in (row.get("test_cmds") or []):_, o, _ = run(c, repo_dir, CMD_TIMEOUT_S)out += o + "\n"for c in (row.get("print_cmds") or []):_, o, _ = run(c, repo_dir, 120)out += o + "\n"return parser(out), out[-3000:]def grade(tests, want, expect):5 unmodified linesmissing.append(t)elif s != expect:wrong.append((t, s))return (not missing and not wrong), {"missing": len(missing), "wrong": wrong[:10],"missing_ids": missing[:5], "parsed_count": len(tests)}def touched_paths(patch):73 unmodified linespre_runs = []for i in range(2):s = time.time()tests, tail = run_tests(row, repo_dir)pre_runs.append((tests, tail))rec["timing"][f"pre_test_{i}"] = round(time.time() - s, 1)pre_detail = grade(pre_runs[0][0], row["fail_to_pass"], "fail")[1]f2p_ok_pre = all(grade(t, row["fail_to_pass"], "fail")[0] for t, _ in pre_runs)rec["f2p_pre_ok"], rec["pre_detail"] = f2p_ok_pre, pre_detail# ---- POST-FIX (twice) ----clean_state(repo_dir)8 unmodified linespost_runs = []for i in range(2):s = time.time()tests, tail = run_tests(row, repo_dir)post_runs.append((tests, tail))rec["timing"][f"post_test_{i}"] = round(time.time() - s, 1)f2p_ok_post = all(grade(t, row["fail_to_pass"], "pass")[0] for t, _ in post_runs)4 unmodified linesrec["timing"]["total"] = round(time.time() - t0, 1)rec["raw_tail"] = pre_runs[0][1][-1500:]if len(pre_runs[0][0]) == 0:rec["status"] = "no_tests_parsed"elif not f2p_ok_pre:rec["status"] = "f2p_not_failing_prefix"elif not f2p_ok_post:rec["status"] = "f2p_not_passing_postfix"37 unmodified linesdone = 0with open(out_path, "w") as fo, open(verified_path, "w") as fv:for row in rows[:args.limit]:try:rec = verify_row(row, row["language"])except Exception as e:7 unmodified linesfv.flush()print(f"[{row['id']}] {rec['status']} "f"pre_ok={rec.get('f2p_pre_ok')} post_ok={rec.get('f2p_post_ok')} "f"p2p_ok={rec.get('p2p_post_ok')} parsed={rec.get('pre_detail', {}).get('parsed_count', '?')} "f"err={(rec.get('error') or '')[:200]}", flush=True)done += 1for path, dest in [(out_path, f"pilot/results/{args.lang}.jsonl"),
scripts/verify.py+24-35