verify.py v0.1: run rebuild_cmds, mkdir reports, single-pass output parsing
Browse files1123411 unmodified lines161718192019202150 unmodified lines7273747775767779808182838485868788899091929394959697787980818283848586878889905 unmodified lines9697981099910010110210373 unmodified lines1771781791891801811821921931941831841851861871888 unmodified lines1971981992102002012022034 unmodified lines20820921021121222121321421521637 unmodified lines2542552562652662672572582597 unmodified lines267268269281282270271272273274"""PatchBench row verification + context expansion harness (v0)."""PatchBench row verification + context expansion harness (v0.1).
For each candidate row: 1. clone the repo at base_commit11 unmodified lines
REPO_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 lines
def run_tests(row, repo_dir): """Run test_cmds then print_cmds, parse with the row's parser. Returns (tests_dict, raw_tail, err).""" """Run rebuild_cmds, then test_cmds, then print_cmds; parse combined output once. Returns (tests_dict, combined_output_tail).""" 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 decides log = "" 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 itself allout = "" 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:], err sh(row.get("rebuild_cmds"), repo_dir) # env/build; failure shows up as unparseable tests run("mkdir -p reports", repo_dir, 30) # test_cmds write reports/<lang>-test-results.json out = "" 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 lines missing.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]} 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 lines pre_runs = [] for i in range(2): s = time.time() tests, tail, _ = run_tests(row, repo_dir) 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_pre rec["pre_missing"] = pre_runs[0][0].get and None # placeholder, details below 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 lines post_runs = [] for i in range(2): s = time.time() tests, tail, _ = run_tests(row, repo_dir) 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 lines rec["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" if not f2p_ok_pre: elif not f2p_ok_pre: rec["status"] = "f2p_not_failing_prefix" elif not f2p_ok_post: rec["status"] = "f2p_not_passing_postfix"37 unmodified lines done = 0 with 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): continue try: rec = verify_row(row, row["language"]) except Exception as e:7 unmodified lines fv.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) 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 += 1
for path, dest in [(out_path, f"pilot/results/{args.lang}.jsonl"),scripts/verify.py+24-35