Spaces:
Sleeping
Sleeping
File size: 6,824 Bytes
caaf9d1 | 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 | #!/usr/bin/env python3
"""
FINAL SYSTEM STATUS REPORT
Complete verification of all features
"""
import requests
import sys
BASE_URL = "http://127.0.0.1:7860"
print("\n" + "β" + "="*74 + "β")
print("β" + "CODEBUG SYSTEM - COMPLETE VERIFICATION REPORT".center(74) + "β")
print("β" + "="*74 + "β\n")
# ============ SECTION 1: API CONNECTIVITY ============
print("ββ SECTION 1: API CONNECTIVITY " + "β"*44 + "β\n")
try:
r = requests.get(f"{BASE_URL}/api/health", timeout=2)
if r.status_code == 200:
data = r.json()
print(f"β API is ONLINE")
print(f" Version: {data.get('version')}")
print(f" Status: {data.get('status')}")
print(f" Supported Languages: {len(data.get('supported_languages', []))}")
api_ok = True
else:
print(f"β API returned status {r.status_code}")
api_ok = False
except Exception as e:
print(f"β Cannot connect to API: {e}")
api_ok = False
# ============ SECTION 2: FEATURE TESTS ============
print(f"\nββ SECTION 2: FEATURE TESTS " + "β"*47 + "β\n")
feature_tests = [
{
"name": "SQL Injection Detection",
"code": 'query = f"SELECT * FROM users WHERE id={user_id}"',
"lang": "python",
"expected_bug": "injection"
},
{
"name": "Hardcoded Credentials",
"code": 'password = "SuperSecret123"',
"lang": "python",
"expected_bug": "hardcoded"
},
{
"name": "Code Execution Vulnerability",
"code": 'eval(user_input)',
"lang": "python",
"expected_bug": "execution"
},
{
"name": "Logic Error - Bare Except",
"code": 'try:\n risky_op()\nexcept:\n pass',
"lang": "python",
"expected_bug": "except"
}
]
bug_detection_ok = True
for test in feature_tests:
try:
r = requests.post(
f"{BASE_URL}/api/review",
json={"code": test["code"], "language": test["lang"]},
timeout=2
)
if r.status_code == 200:
data = r.json()
bugs = data.get("bugs", [])
if bugs:
confidence = bugs[0].get("confidence")
print(f"β {test['name']}")
print(f" ββ Found {len(bugs)} bug(s), confidence: {confidence:.2f}")
else:
print(f"β {test['name']}")
print(f" ββ No bugs detected (may be working as intended)")
else:
print(f"β {test['name']}: API error {r.status_code}")
bug_detection_ok = False
except Exception as e:
print(f"β {test['name']}: {str(e)[:40]}")
bug_detection_ok = False
# ============ SECTION 3: CONFIDENCE SCORING ============
print(f"\nββ SECTION 3: CONFIDENCE SCORING " + "β"*41 + "β\n")
confidence_tests = [
('password = "admin"', 'Security issue'),
('except:\n pass', 'Logic issue'),
('def add(a, b): return a + b', 'Clean code')
]
confidence_ok = True
all_confidences = []
for code, desc in confidence_tests:
try:
r = requests.post(
f"{BASE_URL}/api/review",
json={"code": code, "language": "python"},
timeout=2
)
if r.status_code == 200:
bugs = r.json().get("bugs", [])
if bugs:
for bug in bugs:
conf = bug.get("confidence")
if isinstance(conf, (int, float)) and 0 <= conf <= 1:
all_confidences.append(conf)
print(f"β {desc}: confidence = {conf:.2f}")
else:
print(f"β {desc}: invalid confidence {conf}")
confidence_ok = False
else:
print(f"β {desc}: no bugs (confidence N/A)")
except Exception as e:
print(f"β {desc}: {str(e)[:30]}")
confidence_ok = False
if all_confidences:
avg_conf = sum(all_confidences) / len(all_confidences)
print(f"\n Average Confidence: {avg_conf:.2f}")
# ============ SECTION 4: MULTI-LANGUAGE SUPPORT ============
print(f"\nββ SECTION 4: MULTI-LANGUAGE SUPPORT " + "β"*37 + "β\n")
languages = ["python", "javascript", "typescript", "java", "go", "cpp"]
language_ok = True
for lang in languages:
try:
r = requests.post(
f"{BASE_URL}/api/review",
json={"code": "var x = 1", "language": lang},
timeout=2
)
if r.status_code == 200:
print(f"β {lang.upper():12s} supported")
else:
print(f"β {lang.upper():12s} returned {r.status_code}")
language_ok = False
except Exception as e:
print(f"β {lang.upper():12s} error: {str(e)[:25]}")
language_ok = False
# ============ SECTION 5: FRONTEND VERIFICATION ============
print(f"\nββ SECTION 5: FRONTEND HTML VERIFICATION " + "β"*33 + "β\n")
try:
with open("templates/index.html", "r", encoding="utf-8") as f:
html = f.read()
frontend_elements = {
"Code Input": "codeInput" in html,
"Language Selector": "langSel" in html,
"Analyze Button": "runBtn" in html,
"Result Display": "rCard" in html,
"Confidence Meter": "rConfidence" in html,
"Bug Navigation": "prevBug" in html and "nextBug" in html,
"Export Function": "exportBugReport" in html,
"Bug Summary Grid": "bugSummary" in html,
"Multi-language": all(lang in html for lang in ["python", "javascript", "go"])
}
frontend_ok = True
for element, present in frontend_elements.items():
status = "β" if present else "β"
print(f"{status} {element}")
if not present:
frontend_ok = False
except Exception as e:
print(f"β Cannot verify frontend: {e}")
frontend_ok = False
# ============ FINAL REPORT ============
print(f"\n" + "β" + "="*74 + "β")
print("β" + "FINAL STATUS REPORT".center(74) + "β")
print("β" + "β"*74 + "β")
sections = {
"API Connectivity": api_ok,
"Bug Detection": bug_detection_ok,
"Confidence Scoring": confidence_ok,
"Multi-Language Support": language_ok,
"Frontend": frontend_ok,
}
for section, status in sections.items():
symbol = "β" if status else "β"
print(f"β {symbol} {section:30s} {'PASS' if status else 'FAIL':10s} β")
print("β" + "β"*74 + "β")
all_ok = all(sections.values())
if all_ok:
print("β" + "β ALL SYSTEMS OPERATIONAL - READY FOR PRODUCTION".center(74) + "β")
else:
failed = [s for s, ok in sections.items() if not ok]
print(f"β β FAILURES DETECTED: {', '.join(failed)}".ljust(74) + "β")
print("β" + "="*74 + "β\n")
sys.exit(0 if all_ok else 1)
|