rootxhacker commited on
Commit
647916c
·
verified ·
1 Parent(s): 5c391df

verify.py v0.6: JS/TS dependency install (lockfile-detected), rust target cleanup, keep upstream conventions

Browse files
Files changed (1) hide show
  1. scripts/verify.py +38 -9
scripts/verify.py CHANGED
@@ -1,4 +1,4 @@
1
- """PatchBench row verification + context expansion harness (v0.5).
2
 
3
  For each candidate row:
4
  1. clone the repo at base_commit
@@ -20,6 +20,10 @@ Native (non-Docker) reproduction of the upstream env:
20
  - the upstream /testbed convention is rewritten to the local checkout path
21
  - after test_cmds, the harness cats reports/* (rows redirect `go test -json >
22
  reports/<lang>-test-results.json`; the row's print_cmds list is often empty)
 
 
 
 
23
 
24
  Usage (inside a job with the right language toolchain image):
25
  python verify.py --lang go --file pilot/candidates/go.jsonl --limit 6
@@ -78,8 +82,11 @@ def apply_patch(text, cwd):
78
  return (out + out2)[-2000:]
79
 
80
 
81
- def clean_state(repo_dir):
82
  run("git checkout -f HEAD -- . && git clean -fdxq", repo_dir, 120)
 
 
 
83
 
84
 
85
  def get_parser(row):
@@ -90,13 +97,36 @@ def get_parser(row):
90
  return ns["parser"]
91
 
92
 
93
- def run_tests(row, repo_dir):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
  """Run rebuild_cmds, test_cmds, print_cmds, then surface any reports/* the test
95
  commands wrote. Returns (tests_dict, combined_output_tail)."""
96
  parser = get_parser(row)
 
97
  sh(row.get("rebuild_cmds"), repo_dir)
98
  run("mkdir -p reports", repo_dir, 30)
99
  out = ""
 
 
100
  for c in (row.get("test_cmds") or []):
101
  _, o, _ = run(c, repo_dir, CMD_TIMEOUT_S)
102
  out += o + "\n"
@@ -199,7 +229,7 @@ def verify_row(row, lang):
199
  rec["timing"]["setup"] = round(time.time() - t0, 1)
200
 
201
  # ---- PRE-FIX (twice) ----
202
- clean_state(repo_dir)
203
  err = apply_patch(row["test_patch"], repo_dir)
204
  if err:
205
  rec["error"] = f"test_patch failed to apply: {err}"
@@ -207,7 +237,7 @@ def verify_row(row, lang):
207
  pre_runs = []
208
  for i in range(2):
209
  s = time.time()
210
- tests, tail = run_tests(row, repo_dir)
211
  pre_runs.append((tests, tail))
212
  rec["timing"][f"pre_test_{i}"] = round(time.time() - s, 1)
213
  pre_detail = grade(pre_runs[0][0], row["fail_to_pass"], "fail", allow_missing=True)[1]
@@ -217,11 +247,10 @@ def verify_row(row, lang):
217
  # P2P scoped to this environment: keep only tests that pass in BOTH pre-fix runs
218
  p2p_scoped = [t for t in row["pass_to_pass"]
219
  if pre_runs[0][0].get(t) == "pass" and pre_runs[1][0].get(t) == "pass"]
220
- rec["p2p_env_dropped"] = [t for t in row["pass_to_pass"] if t not in set(p2p_scoped)]
221
- rec["p2p_scoped_count"] = len(p2p_scoped)
222
 
223
  # ---- POST-FIX (twice) ----
224
- clean_state(repo_dir)
225
  err = apply_patch(row["test_patch"], repo_dir)
226
  if err:
227
  rec["error"] = f"test_patch re-apply failed: {err}"
@@ -233,7 +262,7 @@ def verify_row(row, lang):
233
  post_runs = []
234
  for i in range(2):
235
  s = time.time()
236
- tests, tail = run_tests(row, repo_dir)
237
  post_runs.append((tests, tail))
238
  rec["timing"][f"post_test_{i}"] = round(time.time() - s, 1)
239
  f2p_ok_post = all(grade(t, row["fail_to_pass"], "pass")[0] for t, _ in post_runs)
 
1
+ """PatchBench row verification + context expansion harness (v0.6).
2
 
3
  For each candidate row:
4
  1. clone the repo at base_commit
 
20
  - the upstream /testbed convention is rewritten to the local checkout path
21
  - after test_cmds, the harness cats reports/* (rows redirect `go test -json >
22
  reports/<lang>-test-results.json`; the row's print_cmds list is often empty)
23
+ - JS/TS: if package.json exists without node_modules, deps are installed with the
24
+ repo's own package manager (detected from lockfile)
25
+ - rust: cargo target dirs are wiped between rows to stay inside the ephemeral
26
+ storage quota
27
 
28
  Usage (inside a job with the right language toolchain image):
29
  python verify.py --lang go --file pilot/candidates/go.jsonl --limit 6
 
82
  return (out + out2)[-2000:]
83
 
84
 
85
+ def clean_state(repo_dir, lang=None):
86
  run("git checkout -f HEAD -- . && git clean -fdxq", repo_dir, 120)
87
+ if lang == "rust":
88
+ # cargo target dirs can be 10-30GB per repo; the job has 50G ephemeral storage
89
+ run("find . -name target -type d -prune -exec rm -rf {} +", repo_dir, 300)
90
 
91
 
92
  def get_parser(row):
 
97
  return ns["parser"]
98
 
99
 
100
+ def ensure_js_deps(repo_dir):
101
+ """Upstream JS/TS images ship node_modules; natively we must install them.
102
+ Detect the package manager from the lockfile. Returns error string or None."""
103
+ if not os.path.exists(os.path.join(repo_dir, "package.json")):
104
+ return None
105
+ if os.path.exists(os.path.join(repo_dir, "node_modules")):
106
+ return None
107
+ if os.path.exists(os.path.join(repo_dir, "pnpm-lock.yaml")):
108
+ cmds = ["corepack enable 2>/dev/null; corepack prepare pnpm@latest --activate 2>/dev/null || npm install -g pnpm",
109
+ "pnpm install --frozen-lockfile || pnpm install"]
110
+ elif os.path.exists(os.path.join(repo_dir, "yarn.lock")):
111
+ cmds = ["yarn install --frozen-lockfile || yarn install"]
112
+ elif os.path.exists(os.path.join(repo_dir, "package-lock.json")):
113
+ cmds = ["npm ci || npm install"]
114
+ else:
115
+ cmds = ["npm install"]
116
+ ok, err = sh(cmds, repo_dir, 1800)
117
+ return None if ok else f"js deps install failed: {err}"
118
+
119
+
120
+ def run_tests(row, repo_dir, lang):
121
  """Run rebuild_cmds, test_cmds, print_cmds, then surface any reports/* the test
122
  commands wrote. Returns (tests_dict, combined_output_tail)."""
123
  parser = get_parser(row)
124
+ dep_err = ensure_js_deps(repo_dir)
125
  sh(row.get("rebuild_cmds"), repo_dir)
126
  run("mkdir -p reports", repo_dir, 30)
127
  out = ""
128
+ if dep_err:
129
+ out += dep_err + "\n"
130
  for c in (row.get("test_cmds") or []):
131
  _, o, _ = run(c, repo_dir, CMD_TIMEOUT_S)
132
  out += o + "\n"
 
229
  rec["timing"]["setup"] = round(time.time() - t0, 1)
230
 
231
  # ---- PRE-FIX (twice) ----
232
+ clean_state(repo_dir, lang)
233
  err = apply_patch(row["test_patch"], repo_dir)
234
  if err:
235
  rec["error"] = f"test_patch failed to apply: {err}"
 
237
  pre_runs = []
238
  for i in range(2):
239
  s = time.time()
240
+ tests, tail = run_tests(row, repo_dir, lang)
241
  pre_runs.append((tests, tail))
242
  rec["timing"][f"pre_test_{i}"] = round(time.time() - s, 1)
243
  pre_detail = grade(pre_runs[0][0], row["fail_to_pass"], "fail", allow_missing=True)[1]
 
247
  # P2P scoped to this environment: keep only tests that pass in BOTH pre-fix runs
248
  p2p_scoped = [t for t in row["pass_to_pass"]
249
  if pre_runs[0][0].get(t) == "pass" and pre_runs[1][0].get(t) == "pass"]
250
+ rec["p2p_env_dropped_count"] = len(row["pass_to_pass"]) - len(p2p_scoped)
 
251
 
252
  # ---- POST-FIX (twice) ----
253
+ clean_state(repo_dir, lang)
254
  err = apply_patch(row["test_patch"], repo_dir)
255
  if err:
256
  rec["error"] = f"test_patch re-apply failed: {err}"
 
262
  post_runs = []
263
  for i in range(2):
264
  s = time.time()
265
+ tests, tail = run_tests(row, repo_dir, lang)
266
  post_runs.append((tests, tail))
267
  rec["timing"][f"post_test_{i}"] = round(time.time() - s, 1)
268
  f2p_ok_post = all(grade(t, row["fail_to_pass"], "pass")[0] for t, _ in post_runs)