Spaces:
Sleeping
Sleeping
File size: 7,962 Bytes
cb922bf | 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 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | #!/usr/bin/env python
"""
Checkpoint verification script for task 10.
This script verifies that all validator compliance requirements are met:
1. All tests pass
2. FastAPI app has /reset endpoint
3. inference.py exists and runs
4. Strict logging format is correct
"""
import subprocess
import sys
import re
import json
from pathlib import Path
def print_section(title):
"""Print a section header."""
print(f"\n{'='*60}")
print(f" {title}")
print(f"{'='*60}\n")
def run_command(cmd, description, capture_output=True, timeout=30):
"""Run a command and return result."""
print(f"Running: {description}")
print(f"Command: {' '.join(cmd)}")
try:
result = subprocess.run(
cmd,
capture_output=capture_output,
text=True,
timeout=timeout
)
return result
except subprocess.TimeoutExpired:
print(f"β TIMEOUT: Command exceeded {timeout} seconds")
return None
except Exception as e:
print(f"β ERROR: {e}")
return None
def check_tests():
"""Check that all tests pass."""
print_section("CHECKPOINT 1: Running Test Suite")
result = run_command(
["python", "-m", "pytest", "tests/", "-v", "--tb=short", "-x"],
"Running all tests",
timeout=120
)
if result is None:
return False
if result.returncode == 0:
print("β
All tests passed!")
return True
else:
print(f"β Tests failed with return code {result.returncode}")
print("\nSTDOUT:")
print(result.stdout)
print("\nSTDERR:")
print(result.stderr)
return False
def check_fastapi_reset_endpoint():
"""Check that FastAPI app has /reset endpoint."""
print_section("CHECKPOINT 2: Verifying FastAPI /reset Endpoint")
# Check that app.py exists
if not Path("app.py").exists():
print("β app.py not found")
return False
# Read app.py and verify it has FastAPI and /reset endpoint
with open("app.py", "r") as f:
content = f.read()
checks = {
"FastAPI import": "from fastapi import FastAPI" in content,
"/reset endpoint": '@app.post("/reset")' in content or "@app.post('/reset')" in content,
"Returns status ok": '{"status": "ok"}' in content or "{'status': 'ok'}" in content,
"Port 7860": "port=7860" in content or "port = 7860" in content,
"Gradio mounting": "gr.mount_gradio_app" in content
}
all_passed = True
for check_name, passed in checks.items():
status = "β
" if passed else "β"
print(f"{status} {check_name}")
if not passed:
all_passed = False
if all_passed:
print("\nβ
FastAPI integration verified!")
else:
print("\nβ FastAPI integration incomplete")
return all_passed
def check_inference_script():
"""Check that inference.py exists and runs correctly."""
print_section("CHECKPOINT 3: Verifying inference.py")
# Check that inference.py exists
if not Path("inference.py").exists():
print("β inference.py not found")
return False
print("β
inference.py exists")
# Run inference.py and capture output
print("\nRunning inference.py...")
result = run_command(
["python", "inference.py"],
"Running inference script",
timeout=30
)
if result is None or result.returncode != 0:
print(f"β inference.py failed to run")
if result:
print(f"Return code: {result.returncode}")
print(f"STDERR: {result.stderr}")
return False
print("β
inference.py ran successfully")
# Verify output format
stdout = result.stdout
lines = [line.strip() for line in stdout.strip().split('\n') if line.strip()]
if not lines:
print("β No output from inference.py")
return False
print(f"\nβ
Got {len(lines)} output lines")
# Check log patterns
start_pattern = r'^\[START\] task=\w+ env=\w+ model=[\w-]+'
step_pattern = r'^\[STEP\] step=\d+ action=[0-2] reward=-?\d+\.\d{2} done=(True|False) error=(None|.+)'
end_pattern = r'^\[END\] success=(True|False) steps=\d+ score=-?\d+\.\d{2} rewards=(-?\d+\.\d{2}(,-?\d+\.\d{2})*)?'
# Verify first line is [START]
if not re.match(start_pattern, lines[0]):
print(f"β First line is not [START]: {lines[0]}")
return False
print(f"β
[START] log: {lines[0]}")
# Verify last line is [END]
if not re.match(end_pattern, lines[-1]):
print(f"β Last line is not [END]: {lines[-1]}")
return False
print(f"β
[END] log: {lines[-1]}")
# Verify middle lines are [STEP]
step_count = 0
for i, line in enumerate(lines[1:-1], start=1):
if not re.match(step_pattern, line):
print(f"β Line {i+1} is not [STEP]: {line}")
return False
step_count += 1
print(f"β
All {step_count} [STEP] logs are correctly formatted")
# Verify no other output
print("\nβ
Clean stdout output verified (only [START], [STEP], [END])")
return True
def check_async_wrapper():
"""Check that AsyncEnvWrapper exists."""
print_section("CHECKPOINT 4: Verifying AsyncEnvWrapper")
if not Path("env/async_wrapper.py").exists():
print("β env/async_wrapper.py not found")
return False
print("β
env/async_wrapper.py exists")
# Try to import it
try:
from env.async_wrapper import AsyncEnvWrapper
print("β
AsyncEnvWrapper can be imported")
# Check it has required methods
required_methods = ['reset', 'step', 'close']
for method in required_methods:
if not hasattr(AsyncEnvWrapper, method):
print(f"β AsyncEnvWrapper missing method: {method}")
return False
print(f"β
AsyncEnvWrapper has all required methods: {', '.join(required_methods)}")
return True
except Exception as e:
print(f"β Failed to import AsyncEnvWrapper: {e}")
return False
def check_requirements():
"""Check that requirements.txt has all dependencies."""
print_section("CHECKPOINT 5: Verifying Dependencies")
if not Path("requirements.txt").exists():
print("β requirements.txt not found")
return False
with open("requirements.txt", "r") as f:
content = f.read()
required_deps = ["fastapi", "uvicorn", "gradio", "pytest", "hypothesis", "numpy"]
all_present = True
for dep in required_deps:
if dep in content:
print(f"β
{dep}")
else:
print(f"β {dep} missing")
all_present = False
return all_present
def main():
"""Run all checkpoint verifications."""
print("\n" + "="*60)
print(" FINAL CHECKPOINT - Task 10 Verification")
print(" Spec: final-submission-compliance")
print("="*60)
results = {
"Dependencies": check_requirements(),
"AsyncEnvWrapper": check_async_wrapper(),
"FastAPI /reset": check_fastapi_reset_endpoint(),
"inference.py": check_inference_script(),
"Test Suite": check_tests(),
}
# Print summary
print_section("SUMMARY")
all_passed = True
for check_name, passed in results.items():
status = "β
PASS" if passed else "β FAIL"
print(f"{status}: {check_name}")
if not passed:
all_passed = False
print("\n" + "="*60)
if all_passed:
print(" β
ALL CHECKS PASSED - READY FOR SUBMISSION")
else:
print(" β SOME CHECKS FAILED - REVIEW REQUIRED")
print("="*60 + "\n")
return 0 if all_passed else 1
if __name__ == "__main__":
sys.exit(main())
|