File size: 1,808 Bytes
aea1555
 
 
 
 
 
 
 
 
 
 
 
aa22482
aea1555
aa22482
aea1555
 
 
 
 
aa22482
aea1555
aa22482
aea1555
 
aa22482
aea1555
 
 
 
 
 
 
 
 
 
 
 
aa22482
aea1555
aa22482
aea1555
 
 
 
 
aa22482
aea1555
aa22482
aea1555
 
aa22482
aea1555
 
 
 
 
 
 
 
 
 
aa22482
aea1555
aa22482
aea1555
 
 
 
 
aa22482
aea1555
aa22482
aea1555
 
aa22482
aea1555
 
 
 
 
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
import requests
import json

# Test 1: Simple code with bare except
code1 = """try:
    x = int("abc")
except:
    pass

print(x)"""

print("Test 1: Simple code with bare except")
print("-" * 60)
print(code1)
print("-" * 60)

try:
    response = requests.post(
        "http://127.0.0.1:7860/api/review",
        json={"code": code1, "language": "python"},
        timeout=3,
    )

    data = response.json()
    print(f"Bugs found: {data['bugs_found']}")
    for i, bug in enumerate(data["bugs"], 1):
        print(f"{i}. {bug['comment'][:60]} (confidence: {bug['confidence']})")
except Exception as e:
    print(f"Error: {e}")

print("\n")

# Test 2: Type error
code2 = """a = "5"
b = 10
result = a + b"""

print("Test 2: Type error")
print("-" * 60)
print(code2)
print("-" * 60)

try:
    response = requests.post(
        "http://127.0.0.1:7860/api/review",
        json={"code": code2, "language": "python"},
        timeout=3,
    )

    data = response.json()
    print(f"Bugs found: {data['bugs_found']}")
    for i, bug in enumerate(data["bugs"], 1):
        print(f"{i}. {bug['comment'][:60]} (confidence: {bug['confidence']})")
except Exception as e:
    print(f"Error: {e}")

print("\n")

# Test 3: SQL injection
code3 = """query = f'SELECT * FROM users WHERE id={user_id}'"""

print("Test 3: SQL Injection")
print("-" * 60)
print(code3)
print("-" * 60)

try:
    response = requests.post(
        "http://127.0.0.1:7860/api/review",
        json={"code": code3, "language": "python"},
        timeout=3,
    )

    data = response.json()
    print(f"Bugs found: {data['bugs_found']}")
    for i, bug in enumerate(data["bugs"], 1):
        print(f"{i}. {bug['comment'][:60]} (confidence: {bug['confidence']})")
except Exception as e:
    print(f"Error: {e}")

print("\n✓ All tests completed")