rootxhacker commited on
Commit
6df6a13
·
verified ·
1 Parent(s): c29f5b5

verify.py v0.2: per-language PATH fix, /testbed rewrite, record test cmds

Browse files
Files changed (1) hide show
  1. scripts/verify.py +28 -10
scripts/verify.py CHANGED
@@ -1,4 +1,4 @@
1
- """PatchBench row verification + context expansion harness (v0.1).
2
 
3
  For each candidate row:
4
  1. clone the repo at base_commit
@@ -9,8 +9,12 @@ For each candidate row:
9
  4. slice a 500-1500 line context window around the buggy files
10
  5. write a result record; verified rows additionally carry the full patchbench schema
11
 
 
 
 
 
12
  Usage (inside a job with the right language toolchain image):
13
- python verify.py --lang go --file pilot/candidates/go.jsonl --limit 8
14
  """
15
  import argparse, json, os, subprocess, sys, time, traceback
16
 
@@ -20,13 +24,22 @@ CMD_TIMEOUT_S = 2100
20
  GIT_TIMEOUT_S = 900
21
  MAX_CONTEXT_LINES = 1500
22
 
 
 
 
 
 
 
 
 
23
  EXTS = {"go": [".go"], "rust": [".rs"], "java": [".java"],
24
  "javascript": [".js", ".mjs"], "typescript": [".ts", ".tsx"]}
25
  SKIP_DIRS = {".git", "node_modules", "vendor", "target", "dist", "build", "__pycache__", ".idea"}
26
 
 
 
27
 
28
  def run(cmd, cwd, timeout):
29
- """cmd: string -> bash -c. Returns (returncode, combined_output, duration)."""
30
  t0 = time.time()
31
  try:
32
  p = subprocess.run(["bash", "-c", cmd], cwd=cwd, capture_output=True,
@@ -46,7 +59,6 @@ def sh(cmds, cwd, timeout=CMD_TIMEOUT_S):
46
 
47
 
48
  def apply_patch(text, cwd):
49
- """Try git apply, then patch -p1. Returns error string or None."""
50
  pf = os.path.join(cwd, ".pb_patch")
51
  with open(pf, "w") as f:
52
  f.write(text)
@@ -75,8 +87,8 @@ 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)
@@ -88,7 +100,6 @@ def run_tests(row, repo_dir):
88
 
89
 
90
  def grade(tests, want, expect):
91
- """Return (ok, details). want: list of test ids, expect: 'pass'|'fail'."""
92
  missing, wrong = [], []
93
  for t in want:
94
  s = tests.get(t)
@@ -124,7 +135,7 @@ def collect_context(repo_dir, buggy_paths, test_paths, lang, cap=MAX_CONTEXT_LIN
124
  n = sum(1 for _ in open(os.path.join(repo_dir, p), errors="replace"))
125
  except OSError:
126
  continue
127
- if n > 600: # skip giant files entirely; they blow the window
128
  continue
129
  if p in buggy_paths:
130
  prio["buggy"].append(p)
@@ -166,6 +177,14 @@ def verify_row(row, lang):
166
  if rc != 0:
167
  rec["error"] = f"checkout failed: {out[-500:]}"
168
  return rec
 
 
 
 
 
 
 
 
169
  rec["timing"]["setup"] = round(time.time() - t0, 1)
170
 
171
  # ---- PRE-FIX (twice) ----
@@ -219,7 +238,6 @@ def verify_row(row, lang):
219
  else:
220
  rec["status"] = "verified"
221
 
222
- # context expansion only for rows worth publishing
223
  if rec["status"] == "verified":
224
  buggy = touched_paths(row["gold_patch"])
225
  tfiles = touched_paths(row["test_patch"])
@@ -239,7 +257,7 @@ def main():
239
  ap = argparse.ArgumentParser()
240
  ap.add_argument("--lang", required=True)
241
  ap.add_argument("--file", required=True)
242
- ap.add_argument("--limit", type=int, default=8)
243
  ap.add_argument("--out", default=None)
244
  args = ap.parse_args()
245
 
 
1
+ """PatchBench row verification + context expansion harness (v0.2).
2
 
3
  For each candidate row:
4
  1. clone the repo at base_commit
 
9
  4. slice a 500-1500 line context window around the buggy files
10
  5. write a result record; verified rows additionally carry the full patchbench schema
11
 
12
+ Native (non-Docker) reproduction of the upstream env: toolchain dirs are prepended
13
+ to PATH per language, and the upstream /testbed convention is rewritten to the
14
+ local checkout path.
15
+
16
  Usage (inside a job with the right language toolchain image):
17
+ python verify.py --lang go --file pilot/candidates/go.jsonl --limit 6
18
  """
19
  import argparse, json, os, subprocess, sys, time, traceback
20
 
 
24
  GIT_TIMEOUT_S = 900
25
  MAX_CONTEXT_LINES = 1500
26
 
27
+ # toolchain dirs that login-shell /etc/profile resets away, or that images install off-PATH
28
+ LANG_PATH_PREPEND = {
29
+ "go": ["/usr/local/go/bin"],
30
+ "rust": ["/usr/local/cargo/bin", "/usr/local/rustup/bin"],
31
+ "java": [],
32
+ "javascript": [],
33
+ "typescript": [],
34
+ }
35
  EXTS = {"go": [".go"], "rust": [".rs"], "java": [".java"],
36
  "javascript": [".js", ".mjs"], "typescript": [".ts", ".tsx"]}
37
  SKIP_DIRS = {".git", "node_modules", "vendor", "target", "dist", "build", "__pycache__", ".idea"}
38
 
39
+ TESTBED = "/testbed"
40
+
41
 
42
  def run(cmd, cwd, timeout):
 
43
  t0 = time.time()
44
  try:
45
  p = subprocess.run(["bash", "-c", cmd], cwd=cwd, capture_output=True,
 
59
 
60
 
61
  def apply_patch(text, cwd):
 
62
  pf = os.path.join(cwd, ".pb_patch")
63
  with open(pf, "w") as f:
64
  f.write(text)
 
87
  """Run rebuild_cmds, then test_cmds, then print_cmds; parse combined output once.
88
  Returns (tests_dict, combined_output_tail)."""
89
  parser = get_parser(row)
90
+ sh(row.get("rebuild_cmds"), repo_dir)
91
+ run("mkdir -p reports", repo_dir, 30)
92
  out = ""
93
  for c in (row.get("test_cmds") or []):
94
  _, o, _ = run(c, repo_dir, CMD_TIMEOUT_S)
 
100
 
101
 
102
  def grade(tests, want, expect):
 
103
  missing, wrong = [], []
104
  for t in want:
105
  s = tests.get(t)
 
135
  n = sum(1 for _ in open(os.path.join(repo_dir, p), errors="replace"))
136
  except OSError:
137
  continue
138
+ if n > 600:
139
  continue
140
  if p in buggy_paths:
141
  prio["buggy"].append(p)
 
177
  if rc != 0:
178
  rec["error"] = f"checkout failed: {out[-500:]}"
179
  return rec
180
+
181
+ # native env fixes: toolchain PATH + /testbed convention
182
+ os.environ["PATH"] = ":".join(LANG_PATH_PREPEND.get(lang, [])) + ":" + os.environ["PATH"]
183
+ def tb(cmds):
184
+ return [c.replace(TESTBED, repo_dir) for c in (cmds or [])]
185
+ row = {**row, "test_cmds": tb(row["test_cmds"]), "rebuild_cmds": tb(row.get("rebuild_cmds")),
186
+ "print_cmds": tb(row.get("print_cmds"))}
187
+ rec["test_cmds"] = row["test_cmds"]
188
  rec["timing"]["setup"] = round(time.time() - t0, 1)
189
 
190
  # ---- PRE-FIX (twice) ----
 
238
  else:
239
  rec["status"] = "verified"
240
 
 
241
  if rec["status"] == "verified":
242
  buggy = touched_paths(row["gold_patch"])
243
  tfiles = touched_paths(row["test_patch"])
 
257
  ap = argparse.ArgumentParser()
258
  ap.add_argument("--lang", required=True)
259
  ap.add_argument("--file", required=True)
260
+ ap.add_argument("--limit", type=int, default=6)
261
  ap.add_argument("--out", default=None)
262
  args = ap.parse_args()
263