File size: 3,683 Bytes
2692c5d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import json

def write_file(path, content):
    os.makedirs(os.path.dirname(path), exist_ok=True)
    with open(path, "w") as f:
        f.write(content.strip() + "\n")

# EASY
write_file("datasets/easy_01/repo/main.py", '''
from utils import calculate_discount

def checkout(price):
    return calculate_discount(price)

if __name__ == "__main__":
    print(checkout(100))
''')
write_file("datasets/easy_01/repo/utils.py", '''
def calculate_discount(price):
    discount = 0.1
    return price - (price * discount * 10)  # BUG: extra *10
''')
write_file("datasets/easy_01/logs.txt", '''
Running checkout...
Expected output: 90
Actual output: 0
AssertionError: Discount calculation incorrect
''')
write_file("datasets/easy_01/tests.txt", '''
test_checkout:
input: 100
expected: 90
''')
write_file("datasets/easy_01/metadata.json", json.dumps({
  "bug_location": ["utils.py"],
  "bug_type": "logic_error",
  "difficulty": "easy"
}, indent=2))

# MEDIUM
write_file("datasets/medium_01/repo/app.py", '''
from parser import parse_input
from validator import validate

def process(data):
    parsed = parse_input(data)
    if validate(parsed):
        return parsed["value"]
    return None
''')
write_file("datasets/medium_01/repo/parser.py", '''
def parse_input(data):
    return {
        "value": int(data),
        "status": "ok"
    }
''')
write_file("datasets/medium_01/repo/validator.py", '''
def validate(data):
    return data["status"] == "valid"
''')
write_file("datasets/medium_01/logs.txt", '''
Validation failed: status not valid
Check validator logic
''')
write_file("datasets/medium_01/tests.txt", '''
input: "10"
expected output: 10
''')
write_file("datasets/medium_01/metadata.json", json.dumps({
  "bug_location": ["parser.py"],
  "bug_type": "semantic_error",
  "difficulty": "medium",
  "misleading_logs": True
}, indent=2))

# HARD
write_file("datasets/hard_01/repo/main.py", '''
from service import get_user_score

print(get_user_score("alice"))
''')
write_file("datasets/hard_01/repo/db.py", '''
DATABASE = {
    "alice": {"score": 50}
}

def fetch_user(name):
    return DATABASE.get(name)
''')
write_file("datasets/hard_01/repo/service.py", '''
from db import fetch_user

def get_user_score(name):
    user = fetch_user(name)
    return user["points"] * 2  # BUG: wrong key ("points")
''')
write_file("datasets/hard_01/logs.txt", '''
KeyError: 'points'
Occurred in service layer
''')
write_file("datasets/hard_01/tests.txt", '''
input: "alice"
expected: 100
''')
write_file("datasets/hard_01/metadata.json", json.dumps({
  "bug_location": ["service.py"],
  "bug_type": "key_error",
  "difficulty": "hard"
}, indent=2))

# EXTREME
write_file("datasets/extreme_01/repo/engine.py", '''
from cache import get_cache

def compute(x):
    cache = get_cache()
    if x in cache:
        return cache[x]
    return x * 2
''')
write_file("datasets/extreme_01/repo/cache.py", '''
_cache = {}

def get_cache():
    return _cache

def update_cache(key, value):
    _cache[key] = value
''')
write_file("datasets/extreme_01/repo/api.py", '''
from engine import compute
from cache import update_cache

def handler(x):
    result = compute(x)
    update_cache(x, result + 1)  # BUG: corrupt cache
    return result
''')
write_file("datasets/extreme_01/logs.txt", '''
Inconsistent outputs detected
Same input produces different results
''')
write_file("datasets/extreme_01/tests.txt", '''
input: 5
run1: 10
run2: 11  <-- ERROR
''')
write_file("datasets/extreme_01/metadata.json", json.dumps({
  "bug_location": ["api.py"],
  "bug_type": "state_corruption",
  "difficulty": "extreme",
  "non_deterministic": True
}, indent=2))

print("Datasets generated successfully.")