rootxhacker commited on
Commit
ca6e6d9
·
verified ·
1 Parent(s): bb0e713

verify.py v0.1: run rebuild_cmds, mkdir reports, single-pass output parsing

Browse files
Files changed (1) hide show
  1. scripts/verify.py +24 -35
scripts/verify.py CHANGED
@@ -1,4 +1,4 @@
1
- """PatchBench row verification + context expansion harness (v0).
2
 
3
  For each candidate row:
4
  1. clone the repo at base_commit
@@ -16,8 +16,6 @@ import argparse, json, os, subprocess, sys, time, traceback
16
 
17
  REPO_ID = "rootxhacker/patchbench"
18
  CACHE = "/tmp/cache/repos"
19
- WORK = "/tmp/work"
20
- ROW_TIMEOUT_S = 2700 # hard cap per row so one slow repo can't eat the job
21
  CMD_TIMEOUT_S = 2100
22
  GIT_TIMEOUT_S = 900
23
  MAX_CONTEXT_LINES = 1500
@@ -74,27 +72,19 @@ def get_parser(row):
74
 
75
 
76
  def run_tests(row, repo_dir):
77
- """Run test_cmds then print_cmds, parse with the row's parser. Returns (tests_dict, raw_tail, err)."""
 
78
  parser = get_parser(row)
79
- ok, err = sh(row.get("test_cmds"), repo_dir)
80
- if not ok:
81
- pass # test cmd exit code is not authoritative; the parse decides
82
- log = ""
83
- if row.get("print_cmds"):
84
- for c in row["print_cmds"]:
85
- _, out, _ = run(c, repo_dir, 120)
86
- log += out + "\n"
87
- else:
88
- _, log, _ = run(" && ".join(row.get("test_cmds") or ["true"]), repo_dir, 120)
89
- tests = parser(log)
90
- if not tests:
91
- # last resort: parse the test_cmds output itself
92
- allout = ""
93
- for c in row.get("test_cmds") or []:
94
- _, o, _ = run(c, repo_dir, 120)
95
- allout += o + "\n"
96
- tests = parser(allout) or {}
97
- return tests, log[-3000:], err
98
 
99
 
100
  def grade(tests, want, expect):
@@ -106,7 +96,8 @@ def grade(tests, want, expect):
106
  missing.append(t)
107
  elif s != expect:
108
  wrong.append((t, s))
109
- return (not missing and not wrong), {"missing": len(missing), "wrong": wrong[:10], "missing_ids": missing[:10]}
 
110
 
111
 
112
  def touched_paths(patch):
@@ -186,13 +177,12 @@ def verify_row(row, lang):
186
  pre_runs = []
187
  for i in range(2):
188
  s = time.time()
189
- tests, tail, _ = run_tests(row, repo_dir)
190
  pre_runs.append((tests, tail))
191
  rec["timing"][f"pre_test_{i}"] = round(time.time() - s, 1)
192
- f2p_ok_pre = all(grade(t, row["fail_to_pass"], "fail")[0] for t, _ in pre_runs)
193
- rec["f2p_pre_ok"] = f2p_ok_pre
194
- rec["pre_missing"] = pre_runs[0][0].get and None # placeholder, details below
195
  pre_detail = grade(pre_runs[0][0], row["fail_to_pass"], "fail")[1]
 
 
196
 
197
  # ---- POST-FIX (twice) ----
198
  clean_state(repo_dir)
@@ -207,7 +197,7 @@ def verify_row(row, lang):
207
  post_runs = []
208
  for i in range(2):
209
  s = time.time()
210
- tests, tail, _ = run_tests(row, repo_dir)
211
  post_runs.append((tests, tail))
212
  rec["timing"][f"post_test_{i}"] = round(time.time() - s, 1)
213
  f2p_ok_post = all(grade(t, row["fail_to_pass"], "pass")[0] for t, _ in post_runs)
@@ -218,7 +208,9 @@ def verify_row(row, lang):
218
  rec["timing"]["total"] = round(time.time() - t0, 1)
219
  rec["raw_tail"] = pre_runs[0][1][-1500:]
220
 
221
- if not f2p_ok_pre:
 
 
222
  rec["status"] = "f2p_not_failing_prefix"
223
  elif not f2p_ok_post:
224
  rec["status"] = "f2p_not_passing_postfix"
@@ -262,9 +254,6 @@ def main():
262
  done = 0
263
  with open(out_path, "w") as fo, open(verified_path, "w") as fv:
264
  for row in rows[:args.limit]:
265
- if row["language"] != {"go": "go", "rust": "rust", "java": "java",
266
- "js": "javascript", "ts": "typescript"}.get(args.lang):
267
- continue
268
  try:
269
  rec = verify_row(row, row["language"])
270
  except Exception as e:
@@ -278,8 +267,8 @@ def main():
278
  fv.flush()
279
  print(f"[{row['id']}] {rec['status']} "
280
  f"pre_ok={rec.get('f2p_pre_ok')} post_ok={rec.get('f2p_post_ok')} "
281
- f"p2p_ok={rec.get('p2p_post_ok')} err={(rec.get('error') or '')[:200]}",
282
- flush=True)
283
  done += 1
284
 
285
  for path, dest in [(out_path, f"pilot/results/{args.lang}.jsonl"),
 
1
+ """PatchBench row verification + context expansion harness (v0.1).
2
 
3
  For each candidate row:
4
  1. clone the repo at base_commit
 
16
 
17
  REPO_ID = "rootxhacker/patchbench"
18
  CACHE = "/tmp/cache/repos"
 
 
19
  CMD_TIMEOUT_S = 2100
20
  GIT_TIMEOUT_S = 900
21
  MAX_CONTEXT_LINES = 1500
 
72
 
73
 
74
  def run_tests(row, repo_dir):
75
+ """Run rebuild_cmds, then test_cmds, then print_cmds; parse combined output once.
76
+ Returns (tests_dict, combined_output_tail)."""
77
  parser = get_parser(row)
78
+ sh(row.get("rebuild_cmds"), repo_dir) # env/build; failure shows up as unparseable tests
79
+ run("mkdir -p reports", repo_dir, 30) # test_cmds write reports/<lang>-test-results.json
80
+ out = ""
81
+ for c in (row.get("test_cmds") or []):
82
+ _, o, _ = run(c, repo_dir, CMD_TIMEOUT_S)
83
+ out += o + "\n"
84
+ for c in (row.get("print_cmds") or []):
85
+ _, o, _ = run(c, repo_dir, 120)
86
+ out += o + "\n"
87
+ return parser(out), out[-3000:]
 
 
 
 
 
 
 
 
 
88
 
89
 
90
  def grade(tests, want, expect):
 
96
  missing.append(t)
97
  elif s != expect:
98
  wrong.append((t, s))
99
+ return (not missing and not wrong), {"missing": len(missing), "wrong": wrong[:10],
100
+ "missing_ids": missing[:5], "parsed_count": len(tests)}
101
 
102
 
103
  def touched_paths(patch):
 
177
  pre_runs = []
178
  for i in range(2):
179
  s = time.time()
180
+ tests, tail = run_tests(row, repo_dir)
181
  pre_runs.append((tests, tail))
182
  rec["timing"][f"pre_test_{i}"] = round(time.time() - s, 1)
 
 
 
183
  pre_detail = grade(pre_runs[0][0], row["fail_to_pass"], "fail")[1]
184
+ f2p_ok_pre = all(grade(t, row["fail_to_pass"], "fail")[0] for t, _ in pre_runs)
185
+ rec["f2p_pre_ok"], rec["pre_detail"] = f2p_ok_pre, pre_detail
186
 
187
  # ---- POST-FIX (twice) ----
188
  clean_state(repo_dir)
 
197
  post_runs = []
198
  for i in range(2):
199
  s = time.time()
200
+ tests, tail = run_tests(row, repo_dir)
201
  post_runs.append((tests, tail))
202
  rec["timing"][f"post_test_{i}"] = round(time.time() - s, 1)
203
  f2p_ok_post = all(grade(t, row["fail_to_pass"], "pass")[0] for t, _ in post_runs)
 
208
  rec["timing"]["total"] = round(time.time() - t0, 1)
209
  rec["raw_tail"] = pre_runs[0][1][-1500:]
210
 
211
+ if len(pre_runs[0][0]) == 0:
212
+ rec["status"] = "no_tests_parsed"
213
+ elif not f2p_ok_pre:
214
  rec["status"] = "f2p_not_failing_prefix"
215
  elif not f2p_ok_post:
216
  rec["status"] = "f2p_not_passing_postfix"
 
254
  done = 0
255
  with open(out_path, "w") as fo, open(verified_path, "w") as fv:
256
  for row in rows[:args.limit]:
 
 
 
257
  try:
258
  rec = verify_row(row, row["language"])
259
  except Exception as e:
 
267
  fv.flush()
268
  print(f"[{row['id']}] {rec['status']} "
269
  f"pre_ok={rec.get('f2p_pre_ok')} post_ok={rec.get('f2p_post_ok')} "
270
+ f"p2p_ok={rec.get('p2p_post_ok')} parsed={rec.get('pre_detail', {}).get('parsed_count', '?')} "
271
+ f"err={(rec.get('error') or '')[:200]}", flush=True)
272
  done += 1
273
 
274
  for path, dest in [(out_path, f"pilot/results/{args.lang}.jsonl"),