-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify_demo.py
More file actions
59 lines (48 loc) · 2.04 KB
/
verify_demo.py
File metadata and controls
59 lines (48 loc) · 2.04 KB
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
"""
Script to verify the CodeShield demo scenarios by calling the Backend API.
"""
import requests
import json
import os
API_URL = "http://localhost:8000"
def test_trustgate():
print("\n--- Testing TrustGate (Verification) ---")
with open("examples/broken_code.py", "r") as f:
code = f.read()
print("Sending broken code...")
response = requests.post(f"{API_URL}/api/verify", json={"code": code, "auto_fix": True})
if response.status_code == 200:
result = response.json()
print(f"Confidence: {result.get('confidence')}")
print(f"Issues found: {len(result.get('issues', []))}")
for issue in result.get('issues', []):
print(f" - [{issue['type']}] {issue['message']}")
if result.get('fixed_code'):
print("\nAuto-fixed code generated!")
# print(result['fixed_code'])
else:
print(f"Error: {response.status_code} - {response.text}")
def test_styleforge():
print("\n--- Testing StyleForge (Conventions) ---")
with open("examples/broken_code.py", "r") as f:
code = f.read()
# Use the examples directory as the codebase to scan
codebase_path = os.path.abspath("examples")
print(f"Checking style against codebase at: {codebase_path}")
response = requests.post(f"{API_URL}/api/style", json={"code": code, "codebase_path": codebase_path})
if response.status_code == 200:
result = response.json()
print(f"Matches convention: {result.get('matches_convention')}")
print(f"Suggestions: {len(result.get('suggestions', []))}")
for suggestion in result.get('suggestions', []):
print(f" - {suggestion}")
else:
print(f"Error: {response.status_code} - {response.text}")
if __name__ == "__main__":
try:
# Check if server is online
requests.get(API_URL)
test_trustgate()
test_styleforge()
except requests.exceptions.ConnectionError:
print("Backend is offline. Please start it with 'python -m codeshield.api_server'")