harness v0.9: java report collection (surefire/gradle XML + gradle HTML), du-based container disk guard, rust du watchdog
Browse files- scripts/verify.py +96 -30
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
|
|
@@ -18,8 +18,9 @@ they are not evaluable natively, not regressions.
|
|
| 18 |
Native (non-Docker) reproduction of the upstream env:
|
| 19 |
- toolchain dirs are prepended to PATH per language
|
| 20 |
- the upstream /testbed convention is rewritten to the local checkout path
|
| 21 |
-
- after test_cmds, the harness
|
| 22 |
-
reports/
|
|
|
|
| 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 AND all builds go to one shared
|
|
@@ -28,23 +29,24 @@ Native (non-Docker) reproduction of the upstream env:
|
|
| 28 |
v0.7: TimeoutExpired.stdout/stderr can be bytes (python quirk under capture_output) --
|
| 29 |
decode before concatenating. This crashed slow maven builds at the 2100s timeout.
|
| 30 |
v0.8: disk guard. Three rust jobs died on the 50G ephemeral-storage quota mid-row.
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
the next quota failure is diagnosable from the log.
|
| 35 |
|
| 36 |
Usage (inside a job with the right language toolchain image):
|
| 37 |
python verify.py --lang go --file pilot/candidates/go.jsonl --limit 6
|
| 38 |
"""
|
| 39 |
-
import argparse, json, os, subprocess, sys, time, traceback
|
| 40 |
|
| 41 |
REPO_ID = "rootxhacker/patchbench"
|
| 42 |
CACHE = "/tmp/cache/repos"
|
| 43 |
CMD_TIMEOUT_S = 2100
|
| 44 |
GIT_TIMEOUT_S = 900
|
| 45 |
MAX_CONTEXT_LINES = 1500
|
| 46 |
-
|
| 47 |
-
|
|
|
|
|
|
|
| 48 |
RUST_SHARED_TARGET = "/tmp/pb-cargo-target"
|
| 49 |
|
| 50 |
LANG_PATH_PREPEND = {
|
|
@@ -84,19 +86,22 @@ def sh(cmds, cwd, timeout=CMD_TIMEOUT_S):
|
|
| 84 |
return True, ""
|
| 85 |
|
| 86 |
|
| 87 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
try:
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
return 1 << 62
|
| 93 |
|
| 94 |
|
| 95 |
def log_disk(tag):
|
| 96 |
-
_, out, _ = run("
|
| 97 |
-
"
|
| 98 |
-
|
| 99 |
-
|
| 100 |
|
| 101 |
|
| 102 |
def reclaim_disk():
|
|
@@ -105,12 +110,16 @@ def reclaim_disk():
|
|
| 105 |
|
| 106 |
|
| 107 |
def disk_guard(tag):
|
| 108 |
-
"""Raise instead of
|
| 109 |
-
|
| 110 |
-
|
|
|
|
|
|
|
|
|
|
| 111 |
reclaim_disk()
|
| 112 |
-
|
| 113 |
-
|
|
|
|
| 114 |
f"(tag={tag}); aborting row to save the remaining rows")
|
| 115 |
|
| 116 |
|
|
@@ -162,25 +171,80 @@ def ensure_js_deps(repo_dir):
|
|
| 162 |
return None if ok else f"js deps install failed: {err}"
|
| 163 |
|
| 164 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
def run_tests(row, repo_dir, lang, phase_tag=""):
|
| 166 |
-
"""Run rebuild_cmds, test_cmds, print_cmds, then
|
| 167 |
-
|
|
|
|
| 168 |
disk_guard(f"{phase_tag}-pre")
|
| 169 |
parser = get_parser(row)
|
| 170 |
dep_err = ensure_js_deps(repo_dir)
|
| 171 |
-
|
|
|
|
|
|
|
| 172 |
run("mkdir -p reports", repo_dir, 30)
|
| 173 |
out = ""
|
| 174 |
if dep_err:
|
| 175 |
out += dep_err + "\n"
|
| 176 |
for c in (row.get("test_cmds") or []):
|
| 177 |
-
_, o, _ = run(c, repo_dir, CMD_TIMEOUT_S)
|
| 178 |
out += o + "\n"
|
| 179 |
for c in (row.get("print_cmds") or []):
|
| 180 |
_, o, _ = run(c, repo_dir, 120)
|
| 181 |
out += o + "\n"
|
| 182 |
-
|
| 183 |
-
|
| 184 |
log_disk(f"{phase_tag}-post")
|
| 185 |
return parser(out), out[-3000:]
|
| 186 |
|
|
@@ -383,6 +447,8 @@ def main():
|
|
| 383 |
f"pre_ok={rec.get('f2p_pre_ok')} post_ok={rec.get('f2p_post_ok')} "
|
| 384 |
f"p2p_ok={rec.get('p2p_post_ok')} parsed={rec.get('pre_detail', {}).get('parsed_count', '?')} "
|
| 385 |
f"err={(rec.get('error') or '')[:200]}", flush=True)
|
|
|
|
|
|
|
| 386 |
done += 1
|
| 387 |
|
| 388 |
for path, dest in [(out_path, f"pilot/results/{args.lang}.jsonl"),
|
|
|
|
| 1 |
+
"""PatchBench row verification + context expansion harness (v0.9).
|
| 2 |
|
| 3 |
For each candidate row:
|
| 4 |
1. clone the repo at base_commit
|
|
|
|
| 18 |
Native (non-Docker) reproduction of the upstream env:
|
| 19 |
- toolchain dirs are prepended to PATH per language
|
| 20 |
- the upstream /testbed convention is rewritten to the local checkout path
|
| 21 |
+
- after test_cmds, the harness collects the report files the frameworks wrote
|
| 22 |
+
(surefire/gradle XML, gradle HTML, reports/* go-json dumps) and feeds them to
|
| 23 |
+
the parser alongside console output; the row's print_cmds list is often empty
|
| 24 |
- JS/TS: if package.json exists without node_modules, deps are installed with the
|
| 25 |
repo's own package manager (detected from lockfile)
|
| 26 |
- rust: cargo target dirs are wiped between rows AND all builds go to one shared
|
|
|
|
| 29 |
v0.7: TimeoutExpired.stdout/stderr can be bytes (python quirk under capture_output) --
|
| 30 |
decode before concatenating. This crashed slow maven builds at the 2100s timeout.
|
| 31 |
v0.8: disk guard. Three rust jobs died on the 50G ephemeral-storage quota mid-row.
|
| 32 |
+
v0.9: java report files (surefire/gradle XML + gradle HTML) are collected and fed
|
| 33 |
+
to the parser; disk guard is du-based (container quota) and rust builds run under
|
| 34 |
+
a du watchdog so a runaway build kills the row, not the pod.
|
|
|
|
| 35 |
|
| 36 |
Usage (inside a job with the right language toolchain image):
|
| 37 |
python verify.py --lang go --file pilot/candidates/go.jsonl --limit 6
|
| 38 |
"""
|
| 39 |
+
import argparse, json, os, shlex, subprocess, sys, time, traceback
|
| 40 |
|
| 41 |
REPO_ID = "rootxhacker/patchbench"
|
| 42 |
CACHE = "/tmp/cache/repos"
|
| 43 |
CMD_TIMEOUT_S = 2100
|
| 44 |
GIT_TIMEOUT_S = 900
|
| 45 |
MAX_CONTEXT_LINES = 1500
|
| 46 |
+
# The 50G limit is a per-container ephemeral-storage quota. df/statvfs report the
|
| 47 |
+
# host filesystem and never see it, so disk accounting must be du-based.
|
| 48 |
+
CONTAINER_QUOTA_BYTES = 50 * 1024**3
|
| 49 |
+
DU_LIMIT_BYTES = 42 * 1024**3
|
| 50 |
RUST_SHARED_TARGET = "/tmp/pb-cargo-target"
|
| 51 |
|
| 52 |
LANG_PATH_PREPEND = {
|
|
|
|
| 86 |
return True, ""
|
| 87 |
|
| 88 |
|
| 89 |
+
def used_bytes():
|
| 90 |
+
"""Bytes used in the du-monitored dirs. df/statvfs see the host fs, not the
|
| 91 |
+
per-container ephemeral-storage quota, so du is the only honest measure."""
|
| 92 |
+
_, out, _ = run("du -sb /tmp /usr/local/cargo /root/.cache /var/tmp 2>/dev/null "
|
| 93 |
+
"| awk '{s+=$1} END {print s+0}'", "/tmp", 300)
|
| 94 |
try:
|
| 95 |
+
return int(out.strip().splitlines()[-1])
|
| 96 |
+
except (ValueError, IndexError):
|
| 97 |
+
return 0
|
|
|
|
| 98 |
|
| 99 |
|
| 100 |
def log_disk(tag):
|
| 101 |
+
_, out, _ = run("du -sb /tmp/pb-cargo-target /tmp/cache /usr/local/cargo/registry "
|
| 102 |
+
"2>/dev/null", "/tmp", 120)
|
| 103 |
+
print(f"[disk:{tag}] container_used={used_bytes() >> 30}G | {out.strip()[:400]}",
|
| 104 |
+
flush=True)
|
| 105 |
|
| 106 |
|
| 107 |
def reclaim_disk():
|
|
|
|
| 110 |
|
| 111 |
|
| 112 |
def disk_guard(tag):
|
| 113 |
+
"""Raise instead of blowing the container's ephemeral-storage quota -- an
|
| 114 |
+
eviction loses all remaining rows."""
|
| 115 |
+
u = used_bytes()
|
| 116 |
+
if u > DU_LIMIT_BYTES:
|
| 117 |
+
print(f"[disk:{tag}] used={u >> 30}G > limit={DU_LIMIT_BYTES >> 30}G, "
|
| 118 |
+
"reclaiming shared target dir", flush=True)
|
| 119 |
reclaim_disk()
|
| 120 |
+
u = used_bytes()
|
| 121 |
+
if u > CONTAINER_QUOTA_BYTES - 2 * 1024**3:
|
| 122 |
+
raise RuntimeError(f"disk_pressure: used={u >> 30}G after reclaim "
|
| 123 |
f"(tag={tag}); aborting row to save the remaining rows")
|
| 124 |
|
| 125 |
|
|
|
|
| 171 |
return None if ok else f"js deps install failed: {err}"
|
| 172 |
|
| 173 |
|
| 174 |
+
DEFAULT_REPORT_FINDS = [r'for f in reports/*; do [ -f "$f" ] && cat "$f"; done']
|
| 175 |
+
REPORT_FINDS = {
|
| 176 |
+
"java": DEFAULT_REPORT_FINDS + [
|
| 177 |
+
r'find . \( -path "*surefire-reports*" -o -path "*failsafe-reports*" '
|
| 178 |
+
r'-o -path "*build/test-results*" \) -name "*.xml" -type f '
|
| 179 |
+
r'| sort | head -400 | while read -r f; do cat "$f"; done',
|
| 180 |
+
r'find . -path "*reports/tests*" -name "*.html" -type f '
|
| 181 |
+
r'| sort | head -200 | while read -r f; do cat "$f"; done',
|
| 182 |
+
],
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
def collect_reports(repo_dir, lang):
|
| 187 |
+
"""Cat the report files the test frameworks wrote (per-language find commands)
|
| 188 |
+
into the output stream the log parser sees. Each output capped at 8M chars."""
|
| 189 |
+
outs = []
|
| 190 |
+
for cmd in REPORT_FINDS.get(lang, DEFAULT_REPORT_FINDS):
|
| 191 |
+
_, o, _ = run(cmd, repo_dir, 300)
|
| 192 |
+
if o.strip():
|
| 193 |
+
outs.append(o[:8_000_000])
|
| 194 |
+
return "\n".join(outs)
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
WATCHDOG_LANGS = {"rust"}
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
def watchdog_wrap(cmd):
|
| 201 |
+
"""Run cmd in its own process group under a du watchdog. setsid is critical:
|
| 202 |
+
without it cargo survives `kill -9 -- -$pid` and keeps writing to the quota.
|
| 203 |
+
Build runs in FOREGROUND; the du monitor polls in BACKGROUND; `wait $pid`
|
| 204 |
+
decides the exit code (avoids the kill -0 zombie-hang on fast commands)."""
|
| 205 |
+
limit = DU_LIMIT_BYTES
|
| 206 |
+
q = shlex.quote(cmd)
|
| 207 |
+
return (
|
| 208 |
+
f"printf %s {q} > /tmp/pb_cmd.sh\n"
|
| 209 |
+
"setsid bash /tmp/pb_cmd.sh & pid=$!\n"
|
| 210 |
+
"( while kill -0 $pid 2>/dev/null; do\n"
|
| 211 |
+
" used=$(du -sb /tmp /usr/local/cargo 2>/dev/null "
|
| 212 |
+
"| awk '{s+=$1} END {print s+0}')\n"
|
| 213 |
+
f" if [ \"$used\" -gt {limit} ]; then\n"
|
| 214 |
+
" kill -9 -- -$pid 2>/dev/null\n"
|
| 215 |
+
" echo \"[DISK_WATCHDOG] killed build: container=${used}B\"\n"
|
| 216 |
+
" exit 0\n"
|
| 217 |
+
" fi\n"
|
| 218 |
+
" sleep 60 >/dev/null 2>&1\n"
|
| 219 |
+
" done ) & mon=$!\n"
|
| 220 |
+
"wait $pid; rc=$?\n"
|
| 221 |
+
"kill $mon 2>/dev/null\n"
|
| 222 |
+
"exit $rc\n"
|
| 223 |
+
)
|
| 224 |
+
|
| 225 |
+
|
| 226 |
def run_tests(row, repo_dir, lang, phase_tag=""):
|
| 227 |
+
"""Run rebuild_cmds, test_cmds, print_cmds, then collect the report files the
|
| 228 |
+
test frameworks wrote (surefire/gradle XML, gradle HTML, reports/*) and feed
|
| 229 |
+
them to the log parser. Returns (tests_dict, combined_output_tail)."""
|
| 230 |
disk_guard(f"{phase_tag}-pre")
|
| 231 |
parser = get_parser(row)
|
| 232 |
dep_err = ensure_js_deps(repo_dir)
|
| 233 |
+
wrap = watchdog_wrap if lang in WATCHDOG_LANGS else (lambda c: c)
|
| 234 |
+
for c in (row.get("rebuild_cmds") or []):
|
| 235 |
+
run(wrap(c), repo_dir, CMD_TIMEOUT_S)
|
| 236 |
run("mkdir -p reports", repo_dir, 30)
|
| 237 |
out = ""
|
| 238 |
if dep_err:
|
| 239 |
out += dep_err + "\n"
|
| 240 |
for c in (row.get("test_cmds") or []):
|
| 241 |
+
_, o, _ = run(wrap(c), repo_dir, CMD_TIMEOUT_S)
|
| 242 |
out += o + "\n"
|
| 243 |
for c in (row.get("print_cmds") or []):
|
| 244 |
_, o, _ = run(c, repo_dir, 120)
|
| 245 |
out += o + "\n"
|
| 246 |
+
out += collect_reports(repo_dir, lang) + "\n"
|
| 247 |
+
disk_guard(f"{phase_tag}-post")
|
| 248 |
log_disk(f"{phase_tag}-post")
|
| 249 |
return parser(out), out[-3000:]
|
| 250 |
|
|
|
|
| 447 |
f"pre_ok={rec.get('f2p_pre_ok')} post_ok={rec.get('f2p_post_ok')} "
|
| 448 |
f"p2p_ok={rec.get('p2p_post_ok')} parsed={rec.get('pre_detail', {}).get('parsed_count', '?')} "
|
| 449 |
f"err={(rec.get('error') or '')[:200]}", flush=True)
|
| 450 |
+
if row["language"] == "rust":
|
| 451 |
+
run(f"rm -rf {RUST_SHARED_TARGET}", "/tmp", 600)
|
| 452 |
done += 1
|
| 453 |
|
| 454 |
for path, dest in [(out_path, f"pilot/results/{args.lang}.jsonl"),
|