Nanda Kumar Kondreddy commited on
Commit ·
cf1808d
1
Parent(s): 5e5a089
CRITICAL FIX: Wrappers now return full tuples (reward, error, bugs) instead of just floats - fixes env.py unpacking
Browse files- server/env.py +7 -7
- server/graders/grader_api.py +52 -7
- test_grader_audit.py +104 -0
server/env.py
CHANGED
|
@@ -207,13 +207,13 @@ def metadata():
|
|
| 207 |
"version": "1.0.0",
|
| 208 |
"description": "Config file debugging environment",
|
| 209 |
"tasks": [
|
| 210 |
-
{"id": "task1_json", "name": "JSON Config Debug", "difficulty": "easy", "num_bugs": 2, "has_grader": True, "grader": "server.graders.
|
| 211 |
-
{"id": "task2_yaml", "name": "YAML Config Debug", "difficulty": "easy", "num_bugs": 2, "has_grader": True, "grader": "server.graders.
|
| 212 |
-
{"id": "task3_dockerfile", "name": "Dockerfile Debug", "difficulty": "medium", "num_bugs": 3, "has_grader": True, "grader": "server.graders.
|
| 213 |
-
{"id": "task4_compose", "name": "Docker Compose Debug", "difficulty": "medium", "num_bugs": 4, "has_grader": True, "grader": "server.graders.
|
| 214 |
-
{"id": "task5_k8s", "name": "Kubernetes Config Debug", "difficulty": "hard", "num_bugs": 5, "has_grader": True, "grader": "server.graders.
|
| 215 |
-
{"id": "task6_github_actions", "name": "GitHub Actions Debug", "difficulty": "hard", "num_bugs": 5, "has_grader": True, "grader": "server.graders.
|
| 216 |
-
{"id": "task7_nginx", "name": "Nginx Config Debug", "difficulty": "very_hard", "num_bugs": 6, "has_grader": True, "grader": "server.graders.
|
| 217 |
],
|
| 218 |
"action_model": "ConfigDebugAction",
|
| 219 |
"observation_model": "ConfigDebugObservation",
|
|
|
|
| 207 |
"version": "1.0.0",
|
| 208 |
"description": "Config file debugging environment",
|
| 209 |
"tasks": [
|
| 210 |
+
{"id": "task1_json", "name": "JSON Config Debug", "difficulty": "easy", "num_bugs": 2, "has_grader": True, "grader": "server.graders.grader_api:grade_task1"},
|
| 211 |
+
{"id": "task2_yaml", "name": "YAML Config Debug", "difficulty": "easy", "num_bugs": 2, "has_grader": True, "grader": "server.graders.grader_api:grade_task2"},
|
| 212 |
+
{"id": "task3_dockerfile", "name": "Dockerfile Debug", "difficulty": "medium", "num_bugs": 3, "has_grader": True, "grader": "server.graders.grader_api:grade_task3"},
|
| 213 |
+
{"id": "task4_compose", "name": "Docker Compose Debug", "difficulty": "medium", "num_bugs": 4, "has_grader": True, "grader": "server.graders.grader_api:grade_task4"},
|
| 214 |
+
{"id": "task5_k8s", "name": "Kubernetes Config Debug", "difficulty": "hard", "num_bugs": 5, "has_grader": True, "grader": "server.graders.grader_api:grade_task5"},
|
| 215 |
+
{"id": "task6_github_actions", "name": "GitHub Actions Debug", "difficulty": "hard", "num_bugs": 5, "has_grader": True, "grader": "server.graders.grader_api:grade_task6"},
|
| 216 |
+
{"id": "task7_nginx", "name": "Nginx Config Debug", "difficulty": "very_hard", "num_bugs": 6, "has_grader": True, "grader": "server.graders.grader_api:grade_task7"},
|
| 217 |
],
|
| 218 |
"action_model": "ConfigDebugAction",
|
| 219 |
"observation_model": "ConfigDebugObservation",
|
server/graders/grader_api.py
CHANGED
|
@@ -55,46 +55,91 @@ def grade_task1(x):
|
|
| 55 |
"""Task 1 (JSON) grader wrapper with strict bounds enforcement."""
|
| 56 |
print("[VALIDATOR] grade_task1 called")
|
| 57 |
raw = _g1(x)
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
|
| 61 |
def grade_task2(x):
|
| 62 |
"""Task 2 (YAML) grader wrapper with strict bounds enforcement."""
|
| 63 |
print("[VALIDATOR] grade_task2 called")
|
| 64 |
raw = _g2(x)
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
|
| 68 |
def grade_task3(x):
|
| 69 |
"""Task 3 (Dockerfile) grader wrapper with strict bounds enforcement."""
|
| 70 |
print("[VALIDATOR] grade_task3 called")
|
| 71 |
raw = _g3(x)
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
|
| 75 |
def grade_task4(x):
|
| 76 |
"""Task 4 (Docker Compose) grader wrapper with strict bounds enforcement."""
|
| 77 |
print("[VALIDATOR] grade_task4 called")
|
| 78 |
raw = _g4(x)
|
| 79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
|
| 82 |
def grade_task5(x):
|
| 83 |
"""Task 5 (Kubernetes) grader wrapper with strict bounds enforcement."""
|
| 84 |
print("[VALIDATOR] grade_task5 called")
|
| 85 |
raw = _g5(x)
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
|
| 89 |
def grade_task6(x):
|
| 90 |
"""Task 6 (GitHub Actions) grader wrapper with strict bounds enforcement."""
|
| 91 |
print("[VALIDATOR] grade_task6 called")
|
| 92 |
raw = _g6(x)
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
|
| 96 |
def grade_task7(x):
|
| 97 |
"""Task 7 (Nginx) grader wrapper with strict bounds enforcement."""
|
| 98 |
print("[VALIDATOR] grade_task7 called")
|
| 99 |
raw = _g7(x)
|
| 100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
"""Task 1 (JSON) grader wrapper with strict bounds enforcement."""
|
| 56 |
print("[VALIDATOR] grade_task1 called")
|
| 57 |
raw = _g1(x)
|
| 58 |
+
# Raw grader returns (reward, error_msg, bugs_fixed)
|
| 59 |
+
# Normalize the reward but preserve the full tuple structure
|
| 60 |
+
if isinstance(raw, tuple) and len(raw) >= 3:
|
| 61 |
+
reward, error_msg, bugs_fixed = raw[0], raw[1], raw[2]
|
| 62 |
+
normalized_reward = normalize_reward(reward)
|
| 63 |
+
return normalized_reward, error_msg, bugs_fixed
|
| 64 |
+
else:
|
| 65 |
+
# Fallback: if structure unexpected, normalize and return minimal tuple
|
| 66 |
+
normalized_reward = normalize_reward(raw)
|
| 67 |
+
return normalized_reward, "Error: unexpected grader output structure", []
|
| 68 |
|
| 69 |
|
| 70 |
def grade_task2(x):
|
| 71 |
"""Task 2 (YAML) grader wrapper with strict bounds enforcement."""
|
| 72 |
print("[VALIDATOR] grade_task2 called")
|
| 73 |
raw = _g2(x)
|
| 74 |
+
if isinstance(raw, tuple) and len(raw) >= 3:
|
| 75 |
+
reward, error_msg, bugs_fixed = raw[0], raw[1], raw[2]
|
| 76 |
+
normalized_reward = normalize_reward(reward)
|
| 77 |
+
return normalized_reward, error_msg, bugs_fixed
|
| 78 |
+
else:
|
| 79 |
+
normalized_reward = normalize_reward(raw)
|
| 80 |
+
return normalized_reward, "Error: unexpected grader output structure", []
|
| 81 |
|
| 82 |
|
| 83 |
def grade_task3(x):
|
| 84 |
"""Task 3 (Dockerfile) grader wrapper with strict bounds enforcement."""
|
| 85 |
print("[VALIDATOR] grade_task3 called")
|
| 86 |
raw = _g3(x)
|
| 87 |
+
if isinstance(raw, tuple) and len(raw) >= 3:
|
| 88 |
+
reward, error_msg, bugs_fixed = raw[0], raw[1], raw[2]
|
| 89 |
+
normalized_reward = normalize_reward(reward)
|
| 90 |
+
return normalized_reward, error_msg, bugs_fixed
|
| 91 |
+
else:
|
| 92 |
+
normalized_reward = normalize_reward(raw)
|
| 93 |
+
return normalized_reward, "Error: unexpected grader output structure", []
|
| 94 |
|
| 95 |
|
| 96 |
def grade_task4(x):
|
| 97 |
"""Task 4 (Docker Compose) grader wrapper with strict bounds enforcement."""
|
| 98 |
print("[VALIDATOR] grade_task4 called")
|
| 99 |
raw = _g4(x)
|
| 100 |
+
if isinstance(raw, tuple) and len(raw) >= 3:
|
| 101 |
+
reward, error_msg, bugs_fixed = raw[0], raw[1], raw[2]
|
| 102 |
+
normalized_reward = normalize_reward(reward)
|
| 103 |
+
return normalized_reward, error_msg, bugs_fixed
|
| 104 |
+
else:
|
| 105 |
+
normalized_reward = normalize_reward(raw)
|
| 106 |
+
return normalized_reward, "Error: unexpected grader output structure", []
|
| 107 |
|
| 108 |
|
| 109 |
def grade_task5(x):
|
| 110 |
"""Task 5 (Kubernetes) grader wrapper with strict bounds enforcement."""
|
| 111 |
print("[VALIDATOR] grade_task5 called")
|
| 112 |
raw = _g5(x)
|
| 113 |
+
if isinstance(raw, tuple) and len(raw) >= 3:
|
| 114 |
+
reward, error_msg, bugs_fixed = raw[0], raw[1], raw[2]
|
| 115 |
+
normalized_reward = normalize_reward(reward)
|
| 116 |
+
return normalized_reward, error_msg, bugs_fixed
|
| 117 |
+
else:
|
| 118 |
+
normalized_reward = normalize_reward(raw)
|
| 119 |
+
return normalized_reward, "Error: unexpected grader output structure", []
|
| 120 |
|
| 121 |
|
| 122 |
def grade_task6(x):
|
| 123 |
"""Task 6 (GitHub Actions) grader wrapper with strict bounds enforcement."""
|
| 124 |
print("[VALIDATOR] grade_task6 called")
|
| 125 |
raw = _g6(x)
|
| 126 |
+
if isinstance(raw, tuple) and len(raw) >= 3:
|
| 127 |
+
reward, error_msg, bugs_fixed = raw[0], raw[1], raw[2]
|
| 128 |
+
normalized_reward = normalize_reward(reward)
|
| 129 |
+
return normalized_reward, error_msg, bugs_fixed
|
| 130 |
+
else:
|
| 131 |
+
normalized_reward = normalize_reward(raw)
|
| 132 |
+
return normalized_reward, "Error: unexpected grader output structure", []
|
| 133 |
|
| 134 |
|
| 135 |
def grade_task7(x):
|
| 136 |
"""Task 7 (Nginx) grader wrapper with strict bounds enforcement."""
|
| 137 |
print("[VALIDATOR] grade_task7 called")
|
| 138 |
raw = _g7(x)
|
| 139 |
+
if isinstance(raw, tuple) and len(raw) >= 3:
|
| 140 |
+
reward, error_msg, bugs_fixed = raw[0], raw[1], raw[2]
|
| 141 |
+
normalized_reward = normalize_reward(reward)
|
| 142 |
+
return normalized_reward, error_msg, bugs_fixed
|
| 143 |
+
else:
|
| 144 |
+
normalized_reward = normalize_reward(raw)
|
| 145 |
+
return normalized_reward, "Error: unexpected grader output structure", []
|
test_grader_audit.py
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Runtime audit of all graders - test actual outputs without validator.
|
| 4 |
+
Tests what the validator will actually receive.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import sys
|
| 8 |
+
from server.graders.grader_api import (
|
| 9 |
+
grade_task1, grade_task2, grade_task3, grade_task4,
|
| 10 |
+
grade_task5, grade_task6, grade_task7,
|
| 11 |
+
)
|
| 12 |
+
from server.tasks import (
|
| 13 |
+
task1_json, task2_yaml, task3_dockerfile,
|
| 14 |
+
task4_compose, task5_k8s, task6_github_actions, task7_nginx
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
# Test data
|
| 18 |
+
TESTS = [
|
| 19 |
+
(1, grade_task1, task1_json.BROKEN_CONFIG, "JSON"),
|
| 20 |
+
(2, grade_task2, task2_yaml.BROKEN_CONFIG, "YAML"),
|
| 21 |
+
(3, grade_task3, task3_dockerfile.BROKEN_CONFIG, "Dockerfile"),
|
| 22 |
+
(4, grade_task4, task4_compose.BROKEN_CONFIG, "Compose"),
|
| 23 |
+
(5, grade_task5, task5_k8s.BROKEN_CONFIG, "K8s"),
|
| 24 |
+
(6, grade_task6, task6_github_actions.BROKEN_CONFIG, "GitHub Actions"),
|
| 25 |
+
(7, grade_task7, task7_nginx.BROKEN_CONFIG, "Nginx"),
|
| 26 |
+
]
|
| 27 |
+
|
| 28 |
+
print("=" * 80)
|
| 29 |
+
print("GRADER RUNTIME AUDIT - ALL GRADERS WITH BROKEN CONFIGS")
|
| 30 |
+
print("=" * 80)
|
| 31 |
+
print()
|
| 32 |
+
|
| 33 |
+
failures = []
|
| 34 |
+
all_valid = True
|
| 35 |
+
|
| 36 |
+
for task_num, grader_func, broken_config, name in TESTS:
|
| 37 |
+
task_id = f"task{task_num}_{name.lower().replace(' ', '_')}"
|
| 38 |
+
|
| 39 |
+
print(f"Testing Task {task_num} ({name})...")
|
| 40 |
+
print(f" Grader: {grader_func.__name__}")
|
| 41 |
+
|
| 42 |
+
try:
|
| 43 |
+
result = grader_func(broken_config)
|
| 44 |
+
|
| 45 |
+
# Analyze output structure
|
| 46 |
+
result_type = type(result).__name__
|
| 47 |
+
print(f" Output type: {result_type}")
|
| 48 |
+
|
| 49 |
+
if isinstance(result, tuple) and len(result) >= 3:
|
| 50 |
+
reward, error_msg, bugs_fixed = result[0], result[1], result[2]
|
| 51 |
+
print(f" Reward: {reward}")
|
| 52 |
+
print(f" Error msg: {error_msg}")
|
| 53 |
+
print(f" Bugs fixed: {bugs_fixed}")
|
| 54 |
+
|
| 55 |
+
# Validate reward
|
| 56 |
+
if isinstance(reward, float):
|
| 57 |
+
is_valid = 0 < reward < 1
|
| 58 |
+
|
| 59 |
+
print(f" Reward is float: True")
|
| 60 |
+
print(f" In bounds (0, 1): {is_valid}")
|
| 61 |
+
print(f" Exactly 0.0: {reward == 0.0}")
|
| 62 |
+
print(f" Exactly 1.0: {reward == 1.0}")
|
| 63 |
+
print(f" NaN check: {reward != reward}")
|
| 64 |
+
print(f" Inf check: {abs(reward) > 1e308}")
|
| 65 |
+
|
| 66 |
+
if not is_valid:
|
| 67 |
+
all_valid = False
|
| 68 |
+
failures.append(f"Task {task_num}: Reward {reward} NOT in (0, 1)")
|
| 69 |
+
print(f" ❌ INVALID: Reward {reward} is not in (0, 1) range")
|
| 70 |
+
else:
|
| 71 |
+
print(f" ✅ Valid")
|
| 72 |
+
else:
|
| 73 |
+
all_valid = False
|
| 74 |
+
failures.append(f"Task {task_num}: Reward is {type(reward).__name__}, not float")
|
| 75 |
+
print(f" ❌ INVALID: Reward is {type(reward).__name__}, expected float")
|
| 76 |
+
else:
|
| 77 |
+
all_valid = False
|
| 78 |
+
failures.append(f"Task {task_num}: Expected tuple(reward, error, bugs), got {result_type}")
|
| 79 |
+
print(f" ❌ INVALID: Expected tuple(reward, error_msg, bugs_fixed), got {result_type}")
|
| 80 |
+
print(f" Value: {result}")
|
| 81 |
+
|
| 82 |
+
except Exception as e:
|
| 83 |
+
all_valid = False
|
| 84 |
+
failures.append(f"Task {task_num}: Exception - {type(e).__name__}: {str(e)}")
|
| 85 |
+
print(f" ❌ EXCEPTION: {type(e).__name__}: {str(e)}")
|
| 86 |
+
|
| 87 |
+
print()
|
| 88 |
+
|
| 89 |
+
print("=" * 80)
|
| 90 |
+
print("SUMMARY")
|
| 91 |
+
print("=" * 80)
|
| 92 |
+
print(f"All graders valid: {all_valid}")
|
| 93 |
+
print(f"Total tests: {len(TESTS)}")
|
| 94 |
+
print(f"Passed: {len(TESTS) - len(failures)}")
|
| 95 |
+
print(f"Failed: {len(failures)}")
|
| 96 |
+
|
| 97 |
+
if failures:
|
| 98 |
+
print("\nFailures:")
|
| 99 |
+
for failure in failures:
|
| 100 |
+
print(f" - {failure}")
|
| 101 |
+
sys.exit(1)
|
| 102 |
+
else:
|
| 103 |
+
print("\n✅ All graders produce valid outputs!")
|
| 104 |
+
sys.exit(0)
|