File size: 9,936 Bytes
5cf6185
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Task fixtures for the API Contract Debugger environment.

Each task is a dict with:
  - name: str
  - description: str
  - broken_endpoints: list[dict]   β€” what the agent starts with
  - golden_endpoints: list[dict]   β€” the correct spec the grader checks against
  - max_steps: int

Endpoint schema:
  {
    "method": str,
    "path": str,
    "status_code": int,
    "request_body": {
        "<field>": {"type": str, "required": bool, "description": str}
    },
    "response_body": {
        "<field>": {"type": str, "required": bool, "description": str}
    }
  }
"""

from __future__ import annotations

import copy
from typing import Any, Dict, List

# ---------------------------------------------------------------------------
# Task 1 β€” EASY
# Single endpoint. One missing required field in the response.
# ---------------------------------------------------------------------------

_TASK1_GOLDEN: List[Dict[str, Any]] = [
    {
        "method": "POST",
        "path": "/users/register",
        "status_code": 201,
        "request_body": {
            "username": {"type": "string", "required": True,  "description": "Desired username"},
            "email":    {"type": "string", "required": True,  "description": "User email address"},
            "password": {"type": "string", "required": True,  "description": "Plaintext password"},
        },
        "response_body": {
            "user_id":    {"type": "integer", "required": True,  "description": "Created user ID"},
            "username":   {"type": "string",  "required": True,  "description": "Confirmed username"},
            "created_at": {"type": "string",  "required": True,  "description": "ISO-8601 timestamp"},
        },
    }
]

# Break it: remove "created_at" from response
_TASK1_BROKEN: List[Dict[str, Any]] = copy.deepcopy(_TASK1_GOLDEN)
del _TASK1_BROKEN[0]["response_body"]["created_at"]

TASK_EASY: Dict[str, Any] = {
    "name": "easy",
    "description": (
        "A user registration endpoint is missing a required field in its response. "
        "The response should include user_id (integer), username (string), and "
        "created_at (string). Find and add the missing field."
    ),
    "broken_endpoints": _TASK1_BROKEN,
    "golden_endpoints": _TASK1_GOLDEN,
    "max_steps": 5,
}


# ---------------------------------------------------------------------------
# Task 2 β€” MEDIUM
# Three endpoints. Type mismatches and a wrong status code.
# ---------------------------------------------------------------------------

_TASK2_GOLDEN: List[Dict[str, Any]] = [
    {
        "method": "GET",
        "path": "/products/{id}",
        "status_code": 200,
        "request_body": {},
        "response_body": {
            "product_id": {"type": "integer", "required": True,  "description": "Product ID"},
            "name":        {"type": "string",  "required": True,  "description": "Product name"},
            "price":       {"type": "number",  "required": True,  "description": "Price in USD"},
            "in_stock":    {"type": "boolean", "required": True,  "description": "Availability"},
        },
    },
    {
        "method": "POST",
        "path": "/orders",
        "status_code": 201,
        "request_body": {
            "product_id": {"type": "integer", "required": True,  "description": "Product to order"},
            "quantity":   {"type": "integer", "required": True,  "description": "Number of units"},
            "customer_id":{"type": "integer", "required": True,  "description": "Buyer ID"},
        },
        "response_body": {
            "order_id":   {"type": "integer", "required": True,  "description": "Created order ID"},
            "total_price":{"type": "number",  "required": True,  "description": "Total cost"},
            "status":     {"type": "string",  "required": True,  "description": "Order status"},
        },
    },
    {
        "method": "DELETE",
        "path": "/orders/{id}",
        "status_code": 204,
        "request_body": {},
        "response_body": {},
    },
]

# Break it:
# 1. product_id type: integer β†’ string   (GET /products/{id} response)
# 2. quantity type:   integer β†’ string   (POST /orders request)
# 3. DELETE status_code: 204 β†’ 200
_TASK2_BROKEN: List[Dict[str, Any]] = copy.deepcopy(_TASK2_GOLDEN)
_TASK2_BROKEN[0]["response_body"]["product_id"]["type"] = "string"   # violation 1
_TASK2_BROKEN[1]["request_body"]["quantity"]["type"] = "string"       # violation 2
_TASK2_BROKEN[2]["status_code"] = 200                                  # violation 3

TASK_MEDIUM: Dict[str, Any] = {
    "name": "medium",
    "description": (
        "An e-commerce API has three endpoints with contract violations: "
        "(1) GET /products/{id} returns product_id as string instead of integer, "
        "(2) POST /orders accepts quantity as string instead of integer, "
        "(3) DELETE /orders/{id} returns status 200 instead of 204. "
        "Fix all three violations."
    ),
    "broken_endpoints": _TASK2_BROKEN,
    "golden_endpoints": _TASK2_GOLDEN,
    "max_steps": 10,
}


# ---------------------------------------------------------------------------
# Task 3 β€” HARD
# Multi-endpoint API. Missing required fields, type errors, wrong status code,
# AND a forbidden extra field that must be removed.
# ---------------------------------------------------------------------------

_TASK3_GOLDEN: List[Dict[str, Any]] = [
    {
        "method": "POST",
        "path": "/auth/login",
        "status_code": 200,
        "request_body": {
            "email":    {"type": "string", "required": True,  "description": "User email"},
            "password": {"type": "string", "required": True,  "description": "User password"},
        },
        "response_body": {
            "access_token":  {"type": "string",  "required": True,  "description": "JWT token"},
            "refresh_token": {"type": "string",  "required": True,  "description": "Refresh token"},
            "expires_in":    {"type": "integer", "required": True,  "description": "TTL in seconds"},
        },
    },
    {
        "method": "GET",
        "path": "/users/{id}/profile",
        "status_code": 200,
        "request_body": {},
        "response_body": {
            "user_id":    {"type": "integer", "required": True,  "description": "User ID"},
            "email":      {"type": "string",  "required": True,  "description": "User email"},
            "full_name":  {"type": "string",  "required": True,  "description": "Display name"},
            "role":       {"type": "string",  "required": True,  "description": "User role"},
            "created_at": {"type": "string",  "required": True,  "description": "ISO-8601 timestamp"},
        },
    },
    {
        "method": "PATCH",
        "path": "/users/{id}/profile",
        "status_code": 200,
        "request_body": {
            "full_name": {"type": "string", "required": False, "description": "Updated name"},
            "email":     {"type": "string", "required": False, "description": "Updated email"},
        },
        "response_body": {
            "user_id":   {"type": "integer", "required": True, "description": "User ID"},
            "full_name": {"type": "string",  "required": True, "description": "Updated name"},
            "email":     {"type": "string",  "required": True, "description": "Updated email"},
            "updated_at":{"type": "string",  "required": True, "description": "ISO-8601 timestamp"},
        },
    },
    {
        "method": "POST",
        "path": "/auth/refresh",
        "status_code": 200,
        "request_body": {
            "refresh_token": {"type": "string", "required": True, "description": "Refresh token"},
        },
        "response_body": {
            "access_token": {"type": "string",  "required": True, "description": "New JWT token"},
            "expires_in":   {"type": "integer", "required": True, "description": "TTL in seconds"},
        },
    },
]

_TASK3_BROKEN: List[Dict[str, Any]] = copy.deepcopy(_TASK3_GOLDEN)
# Violation 1: missing refresh_token in /auth/login response
del _TASK3_BROKEN[0]["response_body"]["refresh_token"]
# Violation 2: expires_in type integer β†’ string in /auth/login response
_TASK3_BROKEN[0]["response_body"]["expires_in"]["type"] = "string"
# Violation 3: missing created_at in /users/{id}/profile response
del _TASK3_BROKEN[1]["response_body"]["created_at"]
# Violation 4: extra forbidden field "password_hash" in /users/{id}/profile response
_TASK3_BROKEN[1]["response_body"]["password_hash"] = {
    "type": "string", "required": False, "description": "Hashed password β€” MUST NOT be exposed"
}
# Violation 5: PATCH /users/{id}/profile status_code 200 β†’ 500 (regression)
_TASK3_BROKEN[2]["status_code"] = 500
# Violation 6: missing updated_at in PATCH response
del _TASK3_BROKEN[2]["response_body"]["updated_at"]

TASK_HARD: Dict[str, Any] = {
    "name": "hard",
    "description": (
        "An authentication + profile API has 6 contract violations across 4 endpoints: "
        "(1) POST /auth/login is missing refresh_token in response, "
        "(2) POST /auth/login returns expires_in as string instead of integer, "
        "(3) GET /users/{id}/profile is missing created_at in response, "
        "(4) GET /users/{id}/profile exposes a forbidden password_hash field that must be removed, "
        "(5) PATCH /users/{id}/profile returns status 500 instead of 200, "
        "(6) PATCH /users/{id}/profile is missing updated_at in response. "
        "Fix all violations."
    ),
    "broken_endpoints": _TASK3_BROKEN,
    "golden_endpoints": _TASK3_GOLDEN,
    "max_steps": 15,
}


# ---------------------------------------------------------------------------
# Registry
# ---------------------------------------------------------------------------

TASKS: Dict[str, Dict[str, Any]] = {
    "easy":   TASK_EASY,
    "medium": TASK_MEDIUM,
    "hard":   TASK_HARD,
}