coderMayank69 commited on
Commit
aa3997c
·
1 Parent(s): 1abf21a

debugged again

Browse files
Files changed (1) hide show
  1. debug_boundary.py +70 -0
debug_boundary.py ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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")