Skip to content

Commit d13b58a

Browse files
Merge pull request #302 from tina4stack/fix/ai-context-route-example-braces
fix(ai): context route example passes a dict to response()
2 parents 15cf8a8 + b0c9930 commit d13b58a

6 files changed

Lines changed: 29 additions & 10 deletions

File tree

‎.clinerules‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ from tina4_python.core.router import get, post, noauth, secured
99

1010
@get("/api/users")
1111
async def list_users(request, response):
12-
return response({{"users": []}})
12+
return response({"users": []})
1313

1414
@post("/api/users")
1515
@noauth()
1616
async def create_user(request, response):
17-
return response({{"created": request.body["name"]}}, 201)
17+
return response({"created": request.body["name"]}, 201)
1818
```
1919

2020
```python

‎.windsurfrules‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ from tina4_python.core.router import get, post, noauth, secured
99

1010
@get("/api/users")
1111
async def list_users(request, response):
12-
return response({{"users": []}})
12+
return response({"users": []})
1313

1414
@post("/api/users")
1515
@noauth()
1616
async def create_user(request, response):
17-
return response({{"created": request.body["name"]}}, 201)
17+
return response({"created": request.body["name"]}, 201)
1818
```
1919

2020
```python

‎AGENTS.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ from tina4_python.core.router import get, post, noauth, secured
2727

2828
@get("/api/users")
2929
async def list_users(request, response):
30-
return response({{"users": []}})
30+
return response({"users": []})
3131

3232
@post("/api/users")
3333
@noauth()
3434
async def create_user(request, response):
35-
return response({{"created": request.body["name"]}}, 201)
35+
return response({"created": request.body["name"]}, 201)
3636
```
3737

3838
## ORM Pattern

‎CONVENTIONS.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ from tina4_python.core.router import get, post, noauth, secured
1919

2020
@get("/api/users")
2121
async def list_users(request, response):
22-
return response({{"users": []}})
22+
return response({"users": []})
2323

2424
@post("/api/users")
2525
@noauth()
2626
async def create_user(request, response):
27-
return response({{"created": request.body["name"]}}, 201)
27+
return response({"created": request.body["name"]}, 201)
2828
```
2929

3030
## ORM Pattern

‎tests/test_ai.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,22 @@ def test_contains_skills_table(self):
164164
def test_contains_feature_info(self):
165165
ctx = generate_context()
166166
assert "GraphQL" in ctx or "WebSocket" in ctx or "ORM" in ctx
167+
168+
@pytest.mark.parametrize("tool", [t["name"] for t in AI_TOOLS])
169+
def test_route_example_passes_a_dict(self, tool):
170+
"""The route example's response(...) argument must be a dict literal.
171+
172+
A doubled brace ({{...}}) left in a plain string survives the f-string it is
173+
inserted into, and becomes a set holding a dict: TypeError when the copied
174+
route runs.
175+
"""
176+
import ast
177+
import re
178+
179+
ctx = generate_context(tool)
180+
calls = re.findall(r"^[ \t]+return response\((.*)\)[ \t]*$", ctx, re.M)
181+
assert calls, f"{tool}: no route example found"
182+
for call in calls:
183+
arg = ast.parse(call, mode="eval").body
184+
first = arg.elts[0] if isinstance(arg, ast.Tuple) else arg
185+
assert not isinstance(first, ast.Set), f"{tool}: response({call}) passes a set"

‎tina4_python/ai/__init__.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,12 +495,12 @@ def generate_context(tool_name: str = "claude-code") -> str:
495495
496496
@get("/api/users")
497497
async def list_users(request, response):
498-
return response({{"users": []}})
498+
return response({"users": []})
499499
500500
@post("/api/users")
501501
@noauth()
502502
async def create_user(request, response):
503-
return response({{"created": request.body["name"]}}, 201)'''
503+
return response({"created": request.body["name"]}, 201)'''
504504

505505
_orm_example = '''from tina4_python.orm import ORM, IntegerField, StringField
506506

0 commit comments

Comments
 (0)