File size: 5,027 Bytes
17cb132 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | """
run_checks.py — the integration test suite for the Pi Office Math bootstrap.
Runs inside the Docker container (check or run image). Verifies every
integration point between the sandbox, verifier, worker logic, and dataset
utilities — everything EXCEPT vLLM generation itself (which requires a GPU).
Exit 0 = all pass. Exit 1 = at least one failure.
"""
import json
import sys
import traceback
import day1_bootstrap as d
failures = []
total = 0
def check(label, condition, detail=""):
global total
total += 1
status = "PASS" if condition else "FAIL"
print(f"{status} | {label}")
if not condition:
failures.append(f"{label}: {detail}")
return condition
# --- postprocess_code (5 checks) ---
check("postprocess: fence strip",
d.postprocess_code("```python\nresult = 5\n```") == "result = 5")
check("postprocess: think tag strip",
d.postprocess_code("<think>let me solve</think>\nresult = 5") == "result = 5")
check("postprocess: intent-JSON degeneracy guard",
d.postprocess_code('{"solver_id": "x"}') is None)
check("postprocess: empty -> None",
d.postprocess_code("") is None)
check("postprocess: plain code passthrough",
d.postprocess_code("result = 5") == "result = 5")
check("postprocess: prose rejected (7B failure mode)",
d.postprocess_code("To find the answer, we first compute x, then y.") is None)
check("postprocess: indented code kept",
d.postprocess_code("if x == 1:\n result = 2") == "if x == 1:\n result = 2")
# --- extract_gsm8k_answer (2 checks) ---
check("gsm8k: trailing number",
d.extract_gsm8k_answer("Natalia sold 48/2 = <<48/2=24>> clips. She sold 72.") == "72")
check("gsm8k: thousand comma stripped",
d.extract_gsm8k_answer("answer: 1,250") == "1250")
# --- verify_candidate (6 checks: real sandbox + strong_compare) ---
# Load a known-verified pair from the MATH-500 bootstrap for the True case.
# In the container we don't have results/ — craft synthetic cases instead.
cases = [
("verified (real compute)",
{"code": "import sympy as sp\nx = sp.symbols('x')\nresult = sp.solve(x**2 - 5*x + 6, x)", "expected": "[2, 3]"},
True, "verified"),
("crash (division by zero)",
{"code": "result = 1/0", "expected": "5"},
False, "crash"),
("gate refusal (__import__)",
{"code": "result = __import__('os').system('ls')", "expected": "5"},
False, "gate"),
("no result (None class)",
{"code": "x = 5", "expected": "5"},
None, "no_result"),
("wrong-caught (numeric mismatch)",
{"code": "result = 30", "expected": "145"},
False, "wrong_caught"),
("word-vs-number mismatch",
{"code": "result = 5", "expected": "\\text{Evelyn}"},
False, "wrong_caught"),
]
for label, task, want_v, want_r in cases:
try:
got = d.verify_candidate(task)
ok_v = got["verdict"] is want_v
ok_r = got["reason"].startswith(want_r)
check(f"verify_candidate: {label}",
ok_v and ok_r,
f"want verdict={want_v} reason={want_r}, got verdict={got['verdict']} reason={got['reason']}")
except Exception as exc:
check(f"verify_candidate: {label}", False,
f"EXCEPTION {type(exc).__name__}: {exc}")
# --- CODEGEN_SYSTEM is the proven prompt (byte-identical) ---
try:
import benchmark_mode3_lean as b
check("CODEGEN_SYSTEM byte-identical to proven prompt",
d.CODEGEN_SYSTEM == b.CODEGEN_SYSTEM,
"prompt text drifted from benchmark_mode3_lean")
except Exception as exc:
check("CODEGEN_SYSTEM import", False, str(exc))
# --- strong_compare direct spot-checks (the authority) ---
from mode3_verify import strong_compare
check("strong_compare: degree normalization",
strong_compare("145^\\circ", "145") is True)
check("strong_compare: mixed number",
strong_compare("3\\frac{1}{2}", "7/2") is True)
check("strong_compare: imaginary unit",
strong_compare("6 - 5i", "6 - 5*I") is True)
check("strong_compare: leading zeros (AIME)",
strong_compare("025", "25") is True)
# --- dataset loading (regression: pod failure on 2026-08-04 -- hendrycks
# needs trust_remote_code; lighteval/MATH is 401-gated) ---
try:
loaded = d.load_datasets()
check("datasets: GSM8K + MATH train load",
len(loaded) > 100 and
all(p["id"] and p["problem"] and p["answer"] for p in loaded[:50]),
f"got {len(loaded)} problems; sample answers: "
f"{[p['answer'][:12] for p in loaded[:3]]}")
except Exception as exc:
check("datasets: GSM8K + MATH train load", False,
f"EXCEPTION {type(exc).__name__}: {str(exc)[:200]}")
# --- summary ---
print(f"\n{'=' * 50}")
if failures:
print(f"RESULT: {len(failures)} FAILURES out of {total} checks")
for f in failures:
print(f" FAIL: {f}")
sys.exit(1)
else:
print(f"RESULT: ALL {total} CHECKS PASS — integration verified")
print("(vLLM generation itself requires a GPU and is tested via --dry-run 20)")
sys.exit(0)
|