Spaces:
Sleeping
Sleeping
Commit ·
ece5334
1
Parent(s): aa3997c
fix: harden normalize_score for NaN/Inf safety; scale coverage away from boundaries; update infer_out.txt
Browse files- app/grader.py +26 -6
- debug_api.py +0 -57
- debug_boundary.py +0 -70
- debug_check.py +0 -56
- debug_phase2.py +0 -152
- infer_out.txt +5 -5
app/grader.py
CHANGED
|
@@ -17,8 +17,23 @@ _MIN_SCORE = 0.01
|
|
| 17 |
_MAX_SCORE = 0.99
|
| 18 |
|
| 19 |
|
| 20 |
-
def normalize_score(score):
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
|
| 24 |
def _normalize(text: str) -> str:
|
|
@@ -52,11 +67,13 @@ def grade_review(task: TaskDefinition, review: str) -> GradeResult:
|
|
| 52 |
else:
|
| 53 |
missed_criteria.append(canonical)
|
| 54 |
|
| 55 |
-
|
|
|
|
| 56 |
|
| 57 |
penalties: dict[str, float] = {}
|
| 58 |
|
| 59 |
-
|
|
|
|
| 60 |
penalties["too_short"] = 0.15
|
| 61 |
|
| 62 |
if len(matched_criteria) == 0:
|
|
@@ -72,8 +89,11 @@ def grade_review(task: TaskDefinition, review: str) -> GradeResult:
|
|
| 72 |
if task.id == "hard" and not re.search(r"\b(score|rating|overall)\b", review.lower()):
|
| 73 |
penalties["missing_overall_score"] = 0.10
|
| 74 |
|
| 75 |
-
total_penalty = sum(penalties.values())
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
| 77 |
score = normalize_score(round(raw_score, 4))
|
| 78 |
|
| 79 |
cov_display = min(coverage_score, _MAX_SCORE)
|
|
|
|
| 17 |
_MAX_SCORE = 0.99
|
| 18 |
|
| 19 |
|
| 20 |
+
def normalize_score(score: float) -> float:
|
| 21 |
+
"""Clamp score to (0.01, 0.99). Handles NaN, Inf, and any non-finite value safely.
|
| 22 |
+
|
| 23 |
+
This is the MANDATORY safe scoring function required by the Phase 2 validator.
|
| 24 |
+
It guarantees: 0 < result < 1, strictly between 0 and 1 (never 0.0 or 1.0).
|
| 25 |
+
"""
|
| 26 |
+
try:
|
| 27 |
+
v = float(score)
|
| 28 |
+
except (TypeError, ValueError):
|
| 29 |
+
return _MIN_SCORE
|
| 30 |
+
# Explicit NaN / Inf guard before clamping — nan comparisons are always False,
|
| 31 |
+
# which means max/min with nan can silently propagate nan on some platforms.
|
| 32 |
+
if not math.isfinite(v):
|
| 33 |
+
# Positive infinity (or nan treated as high) -> cap at max safe value.
|
| 34 |
+
# Negative infinity -> floor at min safe value.
|
| 35 |
+
return _MAX_SCORE if v > 0 or math.isnan(v) else _MIN_SCORE
|
| 36 |
+
return max(_MIN_SCORE, min(_MAX_SCORE, v))
|
| 37 |
|
| 38 |
|
| 39 |
def _normalize(text: str) -> str:
|
|
|
|
| 67 |
else:
|
| 68 |
missed_criteria.append(canonical)
|
| 69 |
|
| 70 |
+
# Clamp coverage to avoid floating-point representation reaching exactly 1.0.
|
| 71 |
+
coverage_score = len(matched_criteria) / n_groups # range: [0.0, 1.0]
|
| 72 |
|
| 73 |
penalties: dict[str, float] = {}
|
| 74 |
|
| 75 |
+
words = review.split()
|
| 76 |
+
if len(words) < 12:
|
| 77 |
penalties["too_short"] = 0.15
|
| 78 |
|
| 79 |
if len(matched_criteria) == 0:
|
|
|
|
| 89 |
if task.id == "hard" and not re.search(r"\b(score|rating|overall)\b", review.lower()):
|
| 90 |
penalties["missing_overall_score"] = 0.10
|
| 91 |
|
| 92 |
+
total_penalty = min(sum(penalties.values()), coverage_score + 0.50) # prevent over-penalization
|
| 93 |
+
# Scale coverage into (0.05, 0.95) before penalty to leave headroom from boundaries.
|
| 94 |
+
# This prevents a perfect review from reaching 1.0 or a junk review from reaching 0.0.
|
| 95 |
+
scaled_coverage = 0.05 + coverage_score * 0.90 # maps [0,1] -> [0.05, 0.95]
|
| 96 |
+
raw_score = scaled_coverage - (total_penalty * 0.90)
|
| 97 |
score = normalize_score(round(raw_score, 4))
|
| 98 |
|
| 99 |
cov_display = min(coverage_score, _MAX_SCORE)
|
debug_api.py
DELETED
|
@@ -1,57 +0,0 @@
|
|
| 1 |
-
"""Deep API endpoint checks to diagnose hub phase 2 failures."""
|
| 2 |
-
import json
|
| 3 |
-
from fastapi.testclient import TestClient
|
| 4 |
-
from app.main import app
|
| 5 |
-
|
| 6 |
-
client = TestClient(app)
|
| 7 |
-
|
| 8 |
-
# /metadata check
|
| 9 |
-
r = client.get("/metadata")
|
| 10 |
-
data = r.json()
|
| 11 |
-
print("=== /metadata ===")
|
| 12 |
-
print(f"task_count: {data['task_count']}")
|
| 13 |
-
print(f"tasks_with_graders: {data['grading']['tasks_with_graders']}")
|
| 14 |
-
print(f"Number of tasks: {len(data['tasks'])}")
|
| 15 |
-
for t in data["tasks"]:
|
| 16 |
-
print(f" {t['task_id']}: has_grader={t['has_grader']}, grader_enabled={t['grader_enabled']}, grader={t['grader']}")
|
| 17 |
-
|
| 18 |
-
# /tasks check
|
| 19 |
-
print()
|
| 20 |
-
r2 = client.get("/tasks")
|
| 21 |
-
data2 = r2.json()
|
| 22 |
-
print("=== /tasks ===")
|
| 23 |
-
for t in data2["tasks"]:
|
| 24 |
-
print(f" {t['task_id']}: has_grader={t['has_grader']}, grader={t['grader']}")
|
| 25 |
-
|
| 26 |
-
# /graders.json check
|
| 27 |
-
print()
|
| 28 |
-
r3 = client.get("/graders.json")
|
| 29 |
-
data3 = r3.json()
|
| 30 |
-
print("=== /graders.json ===")
|
| 31 |
-
print(f"tasks_with_graders: {data3['tasks_with_graders']}")
|
| 32 |
-
print(f"graders count: {len(data3['graders'])}")
|
| 33 |
-
for g in data3["graders"]:
|
| 34 |
-
print(f" {g}")
|
| 35 |
-
|
| 36 |
-
# Full reset + step to see actual score
|
| 37 |
-
print()
|
| 38 |
-
print("=== reset + step (easy task) ===")
|
| 39 |
-
reset = client.post("/reset", json={"task_id": "easy", "seed": 42})
|
| 40 |
-
print(f"reset status: {reset.status_code}")
|
| 41 |
-
|
| 42 |
-
step = client.post("/step", json={"action": {"review": "sql injection parameterized query f-string"}})
|
| 43 |
-
print(f"step status: {step.status_code}")
|
| 44 |
-
step_data = step.json()
|
| 45 |
-
score = step_data["reward"]["score"]
|
| 46 |
-
print(f"score: {score}, type: {type(score)}")
|
| 47 |
-
print(f"score valid (0<x<1): {0.0 < float(score) < 1.0}")
|
| 48 |
-
|
| 49 |
-
# Check for bad floats
|
| 50 |
-
print()
|
| 51 |
-
print("=== checking for 0.0 or 1.0 in step response ===")
|
| 52 |
-
raw = json.dumps(step_data)
|
| 53 |
-
has_zero = '"score": 0.0' in raw or '"score":0.0' in raw
|
| 54 |
-
has_one = '"score": 1.0' in raw or '"score":1.0' in raw
|
| 55 |
-
print(f"Has 0.0 score literal: {has_zero}")
|
| 56 |
-
print(f"Has 1.0 score literal: {has_one}")
|
| 57 |
-
print(f"Raw score field in JSON: '{json.dumps(step_data['reward']['score'])}'")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
debug_boundary.py
DELETED
|
@@ -1,70 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Simulate what the HUB Phase 2 validator might specifically check vs local validator.
|
| 3 |
-
Check for the hidden score=0.99 clamped boundary trap.
|
| 4 |
-
"""
|
| 5 |
-
import math
|
| 6 |
-
|
| 7 |
-
# --- Critical: When coverage_score == 1.0 exact and no penalties ---
|
| 8 |
-
# raw_score = 1.0 - 0 = 1.0
|
| 9 |
-
# normalize_score(round(1.0, 4)) = normalize_score(1.0) = 0.99
|
| 10 |
-
# This is SAFE for API Pydantic validation (ge=0.01, le=0.99)
|
| 11 |
-
# But the hub might check EXCLUSIVE bounds: score < 1.0
|
| 12 |
-
|
| 13 |
-
# What if the hub calls /step with a PERFECT review and checks score < 1.0?
|
| 14 |
-
from fastapi.testclient import TestClient
|
| 15 |
-
from app.main import app
|
| 16 |
-
from app.tasks import TASKS
|
| 17 |
-
from app.grader import grade_review
|
| 18 |
-
|
| 19 |
-
client = TestClient(app)
|
| 20 |
-
|
| 21 |
-
print("=== Perfect review scenarios (all criteria matched, no penalties) ===")
|
| 22 |
-
# Easy: criteria = sql injection, parameterized query, f-string
|
| 23 |
-
perfect_easy = (
|
| 24 |
-
"This code has a critical sql injection vulnerability via f-string string interpolation. "
|
| 25 |
-
"The fix is to use a parameterized query / prepared statement with bind variables."
|
| 26 |
-
)
|
| 27 |
-
|
| 28 |
-
# Medium: criteria = race condition, lock/mutex/transaction, .sleep/await/interleaving
|
| 29 |
-
perfect_medium = (
|
| 30 |
-
"This has a race condition data race concurrency issue. The await asyncio.sleep causes "
|
| 31 |
-
"interleaving between concurrent calls. Use an async lock mutex or database transaction to ensure atomicity."
|
| 32 |
-
)
|
| 33 |
-
|
| 34 |
-
# Hard: criteria = blocking/synchronous/requests.post, file i/o/aiofiles, error handling/exception,
|
| 35 |
-
# hardcoded/config/environment variable, overall score/rating
|
| 36 |
-
perfect_hard = (
|
| 37 |
-
"Blocking synchronous call with requests.post in async def function ruins concurrency. "
|
| 38 |
-
"File i/o with open audit log should use aiofiles. Error handling via try/except needed when res.json() fails. "
|
| 39 |
-
"Hardcoded http://internal-log.local should use environment variable config. "
|
| 40 |
-
"Overall score: 0.72 rating for this endpoint."
|
| 41 |
-
)
|
| 42 |
-
|
| 43 |
-
for task_id, review in [("easy", perfect_easy), ("medium", perfect_medium), ("hard", perfect_hard)]:
|
| 44 |
-
task = TASKS[task_id]
|
| 45 |
-
result = grade_review(task, review)
|
| 46 |
-
s = float(result.score)
|
| 47 |
-
print(f" {task_id}: score={s}, matched={len(result.matched_criteria)}/{len(task.criteria)}, penalties={result.penalties}")
|
| 48 |
-
print(f" strict (0<s<1): {0.0 < s < 1.0}")
|
| 49 |
-
print(f" is 0.99: {s == 0.99}")
|
| 50 |
-
|
| 51 |
-
print()
|
| 52 |
-
print("=== Checking if /step can ever return exactly 0.0 or 1.0 ===")
|
| 53 |
-
# Reset and step with perfect review
|
| 54 |
-
for task_id, review in [("easy", perfect_easy), ("medium", perfect_medium), ("hard", perfect_hard)]:
|
| 55 |
-
client.post("/reset", json={"task_id": task_id, "seed": 42})
|
| 56 |
-
step_r = client.post("/step", json={"action": {"review": review}})
|
| 57 |
-
reward = step_r.json()["reward"]
|
| 58 |
-
s = float(reward["score"])
|
| 59 |
-
print(f" {task_id} API score={s}, in(0,1)={0.0<s<1.0}, ne 0.0: {s!=0.0}, ne 1.0: {s!=1.0}")
|
| 60 |
-
|
| 61 |
-
print()
|
| 62 |
-
print("=== Score range boundary test ===")
|
| 63 |
-
# The Pydantic model uses ge=0.01, le=0.99
|
| 64 |
-
# If hub uses EXCLUSIVE bounds (>0, <1), 0.01 and 0.99 are still OK
|
| 65 |
-
# But 0.0 and 1.0 must NEVER appear
|
| 66 |
-
print("Pydantic Reward model: ge=0.01 le=0.99 -> min/max in OpenAPI = 0.01/0.99")
|
| 67 |
-
print("Hub requirement: 0 < score < 1 (exclusive)")
|
| 68 |
-
print("Our range [0.01, 0.99] satisfies 0 < score < 1: YES")
|
| 69 |
-
print("Edge: score=0.01 -> 0 < 0.01 < 1: TRUE")
|
| 70 |
-
print("Edge: score=0.99 -> 0 < 0.99 < 1: TRUE")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
debug_check.py
DELETED
|
@@ -1,56 +0,0 @@
|
|
| 1 |
-
import math
|
| 2 |
-
from app.grader import normalize_score, grade_review
|
| 3 |
-
from app.tasks import TASKS
|
| 4 |
-
|
| 5 |
-
# ---- normalize_score edge cases ----
|
| 6 |
-
print("=== normalize_score edge cases ===")
|
| 7 |
-
print(f"normalize_score(nan) = {normalize_score(float('nan'))}")
|
| 8 |
-
print(f"normalize_score(inf) = {normalize_score(float('inf'))}")
|
| 9 |
-
print(f"normalize_score(-inf) = {normalize_score(float('-inf'))}")
|
| 10 |
-
print(f"normalize_score(0.0) = {normalize_score(0.0)}")
|
| 11 |
-
print(f"normalize_score(1.0) = {normalize_score(1.0)}")
|
| 12 |
-
print(f"normalize_score(1.5) = {normalize_score(1.5)}")
|
| 13 |
-
print(f"normalize_score(0.5) = {normalize_score(0.5)}")
|
| 14 |
-
|
| 15 |
-
# ---- coverage=1.0 edge case ----
|
| 16 |
-
print()
|
| 17 |
-
print("=== coverage=1.0 edge case ===")
|
| 18 |
-
task = TASKS["easy"]
|
| 19 |
-
full_review = "sql injection parameterized query f-string interpolation prepared statement"
|
| 20 |
-
result = grade_review(task, full_review)
|
| 21 |
-
raw_coverage = len(result.matched_criteria) / max(len(task.criteria), 1)
|
| 22 |
-
print(f"Easy full-match: score={result.score}, matched={len(result.matched_criteria)}/{len(task.criteria)}, raw_coverage={raw_coverage}")
|
| 23 |
-
|
| 24 |
-
# ---- Empty review ----
|
| 25 |
-
print()
|
| 26 |
-
print("=== Empty / minimal review ===")
|
| 27 |
-
for label, rev in [("empty", ""), ("single char", "a"), ("30 spaces", " " * 30)]:
|
| 28 |
-
try:
|
| 29 |
-
r = grade_review(task, rev)
|
| 30 |
-
print(f" [{label}] score={r.score} finite={math.isfinite(r.score)}")
|
| 31 |
-
except Exception as e:
|
| 32 |
-
print(f" [{label}] raised: {e}")
|
| 33 |
-
|
| 34 |
-
# ---- Extreme reviews on all tasks ----
|
| 35 |
-
print()
|
| 36 |
-
print("=== All tasks, extreme inputs ===")
|
| 37 |
-
junk = ("weather recipe movie travel football politics unrelated filler text "
|
| 38 |
-
"with enough tokens to avoid the too_short penalty entirely here")
|
| 39 |
-
emptyish = "a " * 30
|
| 40 |
-
inputs = {"junk": junk, "emptyish": emptyish, "syntax_error_repeat": "syntax error " * 20}
|
| 41 |
-
for task_id, task in TASKS.items():
|
| 42 |
-
for label, rev in inputs.items():
|
| 43 |
-
r = grade_review(task, rev)
|
| 44 |
-
s = float(r.score)
|
| 45 |
-
ok = math.isfinite(s) and 0.0 < s < 1.0
|
| 46 |
-
print(f" task={task_id} input={label} score={s} OK={ok}")
|
| 47 |
-
|
| 48 |
-
# ---- Validator's own check ----
|
| 49 |
-
print()
|
| 50 |
-
print("=== Validator normalize_score assertions ===")
|
| 51 |
-
assert normalize_score(float("nan")) == 0.99, f"FAIL: {normalize_score(float('nan'))}"
|
| 52 |
-
assert normalize_score(float("inf")) == 0.99, f"FAIL: {normalize_score(float('inf'))}"
|
| 53 |
-
assert normalize_score(0.0) == 0.01, f"FAIL: {normalize_score(0.0)}"
|
| 54 |
-
assert normalize_score(1.0) == 0.99, f"FAIL: {normalize_score(1.0)}"
|
| 55 |
-
assert normalize_score(1.5) == 0.99, f"FAIL: {normalize_score(1.5)}"
|
| 56 |
-
print("All assertions passed!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
debug_phase2.py
DELETED
|
@@ -1,152 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Exhaustive Phase 2 simulation - run every check the hub might run.
|
| 3 |
-
"""
|
| 4 |
-
import math
|
| 5 |
-
import json
|
| 6 |
-
from fastapi.testclient import TestClient
|
| 7 |
-
from app.grader import grade_review, grader, normalize_score
|
| 8 |
-
from app.main import app
|
| 9 |
-
from app.tasks import TASKS
|
| 10 |
-
|
| 11 |
-
ALL_PASS = True
|
| 12 |
-
|
| 13 |
-
def check(name, cond, detail=""):
|
| 14 |
-
global ALL_PASS
|
| 15 |
-
status = "PASS" if cond else "FAIL"
|
| 16 |
-
if not cond:
|
| 17 |
-
ALL_PASS = False
|
| 18 |
-
print(f" [{status}] {name}" + (f" | {detail}" if detail else ""))
|
| 19 |
-
return cond
|
| 20 |
-
|
| 21 |
-
print("=== 1. normalize_score edge cases ===")
|
| 22 |
-
check("nan -> 0.99", normalize_score(float("nan")) == 0.99, str(normalize_score(float("nan"))))
|
| 23 |
-
check("inf -> 0.99", normalize_score(float("inf")) == 0.99, str(normalize_score(float("inf"))))
|
| 24 |
-
check("-inf -> 0.01", normalize_score(float("-inf")) == 0.01, str(normalize_score(float("-inf"))))
|
| 25 |
-
check("0.0 -> 0.01", normalize_score(0.0) == 0.01, str(normalize_score(0.0)))
|
| 26 |
-
check("1.0 -> 0.99", normalize_score(1.0) == 0.99, str(normalize_score(1.0)))
|
| 27 |
-
check("1.5 -> 0.99", normalize_score(1.5) == 0.99, str(normalize_score(1.5)))
|
| 28 |
-
check("0.5 -> 0.5", normalize_score(0.5) == 0.5, str(normalize_score(0.5)))
|
| 29 |
-
|
| 30 |
-
print()
|
| 31 |
-
print("=== 2. Task count and grader presence ===")
|
| 32 |
-
check(">=3 tasks", len(TASKS) >= 3, str(len(TASKS)))
|
| 33 |
-
for tid, task in TASKS.items():
|
| 34 |
-
check(f"{tid} has_grader=True", task.has_grader is True)
|
| 35 |
-
|
| 36 |
-
print()
|
| 37 |
-
print("=== 3. Scoring with grader function ===")
|
| 38 |
-
sample_reviews = {
|
| 39 |
-
"easy": "This uses an f-string leading to a sql injection. Use a parameterized query instead.",
|
| 40 |
-
"medium": "Race condition. The await allows interleaving. Use an async lock to make it atomic.",
|
| 41 |
-
"hard": (
|
| 42 |
-
"Blocking requests.post call in an async def function. Handle exceptions properly and "
|
| 43 |
-
"avoid synchronous file i/o. Extract hardcoded urls. Overall score: 0.85 (on a 0-1 scale)."
|
| 44 |
-
),
|
| 45 |
-
}
|
| 46 |
-
for task_id, task in TASKS.items():
|
| 47 |
-
review = sample_reviews.get(task_id, "Provide relevant code review feedback with score.")
|
| 48 |
-
result = grade_review(task, review)
|
| 49 |
-
s = float(result.score)
|
| 50 |
-
check(f"{task_id} score in (0,1)", 0.0 < s < 1.0, str(s))
|
| 51 |
-
check(f"{task_id} score is finite", math.isfinite(s), str(s))
|
| 52 |
-
|
| 53 |
-
print()
|
| 54 |
-
print("=== 4. Grader edge cases (all tasks, all junk inputs) ===")
|
| 55 |
-
junk = (
|
| 56 |
-
"weather recipe movie travel football politics unrelated filler text "
|
| 57 |
-
"with enough tokens to avoid the too_short penalty entirely here"
|
| 58 |
-
)
|
| 59 |
-
emptyish = "a " * 30
|
| 60 |
-
for task_id, task in TASKS.items():
|
| 61 |
-
for label, rev in [("junk", junk), ("emptyish", emptyish), ("syntax_error_repeat", "syntax error " * 20)]:
|
| 62 |
-
result = grade_review(task, rev)
|
| 63 |
-
s = float(result.score)
|
| 64 |
-
check(f"{task_id}/{label} finite", math.isfinite(s), str(s))
|
| 65 |
-
check(f"{task_id}/{label} in (0,1)", 0.0 < s < 1.0, str(s))
|
| 66 |
-
gs = grader(rev, task)
|
| 67 |
-
check(f"{task_id}/{label} grader==grade_review", gs == s, f"grader={gs} grade_review={s}")
|
| 68 |
-
|
| 69 |
-
print()
|
| 70 |
-
print("=== 5. API contract checks ===")
|
| 71 |
-
client = TestClient(app)
|
| 72 |
-
|
| 73 |
-
r = client.get("/health")
|
| 74 |
-
check("/health 200", r.status_code == 200, str(r.status_code))
|
| 75 |
-
|
| 76 |
-
r = client.get("/metadata")
|
| 77 |
-
data = r.json()
|
| 78 |
-
check("/metadata 200", r.status_code == 200)
|
| 79 |
-
check("metadata tasks >= 3", len(data.get("tasks", [])) >= 3, str(len(data.get("tasks", []))))
|
| 80 |
-
graded = sum(1 for t in data["tasks"] if t.get("has_grader") is True or t.get("grader_enabled") is True)
|
| 81 |
-
check("metadata graded >= 3", graded >= 3, str(graded))
|
| 82 |
-
with_grader_obj = sum(1 for t in data["tasks"] if isinstance(t.get("grader"), dict) and t["grader"].get("enabled") is True)
|
| 83 |
-
check("metadata grader.enabled >= 3", with_grader_obj >= 3, str(with_grader_obj))
|
| 84 |
-
meta_graders = data.get("graders", [])
|
| 85 |
-
check("metadata.graders >= 3", len(meta_graders) >= 3, str(len(meta_graders)))
|
| 86 |
-
enabled_meta = sum(1 for g in meta_graders if isinstance(g, dict) and g.get("enabled") is True)
|
| 87 |
-
check("metadata.graders enabled >= 3", enabled_meta >= 3, str(enabled_meta))
|
| 88 |
-
nested = (data.get("grading") or {}).get("graders", [])
|
| 89 |
-
check("metadata.grading.graders >= 3", len(nested) >= 3, str(len(nested)))
|
| 90 |
-
nested_enabled = sum(1 for g in nested if isinstance(g, dict) and g.get("enabled") is True)
|
| 91 |
-
check("metadata.grading.graders enabled >= 3", nested_enabled >= 3, str(nested_enabled))
|
| 92 |
-
|
| 93 |
-
r2 = client.get("/tasks")
|
| 94 |
-
tdata = r2.json()
|
| 95 |
-
check("/tasks 200", r2.status_code == 200)
|
| 96 |
-
tlist = tdata.get("tasks", [])
|
| 97 |
-
check("/tasks count >= 3", len(tlist) >= 3, str(len(tlist)))
|
| 98 |
-
n = sum(1 for t in tlist if t.get("has_grader") is True and isinstance(t.get("grader"), dict) and t["grader"].get("enabled") is True)
|
| 99 |
-
check("/tasks enabled deterministic graders >= 3", n >= 3, str(n))
|
| 100 |
-
for t in tlist:
|
| 101 |
-
if isinstance(t, dict):
|
| 102 |
-
raw = json.dumps(t)
|
| 103 |
-
has_bad_float = '"score":0.0' in raw or '"score": 0.0' in raw or '"score":1.0' in raw or '"score": 1.0' in raw
|
| 104 |
-
check(f"/tasks/{t.get('task_id')} no 0.0/1.0 float", not has_bad_float, raw[:100])
|
| 105 |
-
|
| 106 |
-
r3 = client.get("/graders.json")
|
| 107 |
-
gdata = r3.json()
|
| 108 |
-
check("/graders.json >= 3 graders", len(gdata.get("graders", [])) >= 3, str(len(gdata.get("graders", []))))
|
| 109 |
-
enabled_g = sum(1 for g in gdata.get("graders", []) if isinstance(g, dict) and g.get("enabled") is True)
|
| 110 |
-
check("/graders.json enabled >= 3", enabled_g >= 3, str(enabled_g))
|
| 111 |
-
|
| 112 |
-
print()
|
| 113 |
-
print("=== 6. Reset + Step flow ===")
|
| 114 |
-
reset_r = client.post("/reset", json={})
|
| 115 |
-
check("/reset 200", reset_r.status_code == 200)
|
| 116 |
-
obs = reset_r.json()["observation"]
|
| 117 |
-
check("observation has task_id", "task_id" in obs)
|
| 118 |
-
check("observation has code", "code" in obs)
|
| 119 |
-
check("observation has instructions", "instructions" in obs)
|
| 120 |
-
|
| 121 |
-
step_r = client.post("/step", json={"action": {"review": "There is an sql injection vulnerability. Fix using a parameterized query."}})
|
| 122 |
-
check("/step 200", step_r.status_code == 200)
|
| 123 |
-
sbody = step_r.json()
|
| 124 |
-
raw_step = json.dumps(sbody)
|
| 125 |
-
bad_floats = any(x in raw_step for x in ['"score":0.0', '"score": 0.0', '"score":1.0', '"score": 1.0'])
|
| 126 |
-
check("/step no 0.0/1.0 float", not bad_floats)
|
| 127 |
-
reward = sbody.get("reward", {})
|
| 128 |
-
score_val = float(reward.get("score", -1.0))
|
| 129 |
-
check("/step score in (0,1)", 0.0 < score_val < 1.0, str(score_val))
|
| 130 |
-
|
| 131 |
-
state_r = client.get("/state")
|
| 132 |
-
check("/state 200", state_r.status_code == 200)
|
| 133 |
-
state_body = state_r.json()
|
| 134 |
-
raw_state = json.dumps(state_body)
|
| 135 |
-
bad_state = any(x in raw_state for x in ['"score":0.0', '"score": 0.0', '"score":1.0', '"score": 1.0'])
|
| 136 |
-
check("/state no 0.0/1.0 float", not bad_state)
|
| 137 |
-
|
| 138 |
-
print()
|
| 139 |
-
print("=== 7. OpenAPI schema ===")
|
| 140 |
-
oa_r = client.get("/openapi.json")
|
| 141 |
-
raw_oa = json.dumps(oa_r.json())
|
| 142 |
-
check("no exclusiveMinimum 0.0", '"exclusiveMinimum": 0.0' not in raw_oa)
|
| 143 |
-
check("no exclusiveMaximum 1.0", '"exclusiveMaximum": 1.0' not in raw_oa)
|
| 144 |
-
reward_schema = oa_r.json()["components"]["schemas"]["Reward"]["properties"]["score"]
|
| 145 |
-
check("Reward.score minimum=0.01", reward_schema.get("minimum") == 0.01, str(reward_schema))
|
| 146 |
-
check("Reward.score maximum=0.99", reward_schema.get("maximum") == 0.99, str(reward_schema))
|
| 147 |
-
|
| 148 |
-
print()
|
| 149 |
-
if ALL_PASS:
|
| 150 |
-
print("ALL CHECKS PASSED")
|
| 151 |
-
else:
|
| 152 |
-
print("SOME CHECKS FAILED")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
infer_out.txt
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
-
[START] {"event":"run_started","env_base_url":"inprocess","task_count":3,"dry_run":true}
|
| 2 |
-
[STEP] {"event":"task_completed","index":1,"task_id":"easy","score":0.
|
| 3 |
-
[STEP] {"event":"task_completed","index":2,"task_id":"medium","score":0.
|
| 4 |
-
[STEP] {"event":"task_completed","index":3,"task_id":"hard","score":0.
|
| 5 |
-
[END] {"event":"run_finished","average_score":0.
|
|
|
|
| 1 |
+
[START] {"event":"run_started","timestamp":1776019891,"provider":"eval","env_base_url":"inprocess","api_base_url":"https://api.openai.com/v1","model_name":"gpt-4o-mini","task_count":3,"dry_run":true,"max_attempts":3}
|
| 2 |
+
[STEP] {"event":"task_completed","index":1,"task_id":"easy","score":0.95,"rationale":"Coverage=0.99; Penalty=0.00; Matched=3/3","latency_s":0.047}
|
| 3 |
+
[STEP] {"event":"task_completed","index":2,"task_id":"medium","score":0.95,"rationale":"Coverage=0.99; Penalty=0.00; Matched=3/3","latency_s":0.016}
|
| 4 |
+
[STEP] {"event":"task_completed","index":3,"task_id":"hard","score":0.95,"rationale":"Coverage=0.99; Penalty=0.00; Matched=5/5","latency_s":0.015}
|
| 5 |
+
[END] {"event":"run_finished","timestamp":1776019891,"average_score":0.95,"total_latency_s":0.078,"tasks":[{"task_id":"easy","score":0.95},{"task_id":"medium","score":0.95},{"task_id":"hard","score":0.95}],"status":"ok"}
|