Skip to content

Commit 19941df

Browse files
test: address timon0305 PR review feedback
Add client_empty and client_thinking fixtures, exercise thinking blocks via session detail API, preserve ValueError cause in _parse_limit, and remove .coverage from git tracking (already in .gitignore). Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 449a117 commit 19941df

4 files changed

Lines changed: 34 additions & 9 deletions

File tree

.coverage

-52 KB
Binary file not shown.

api/search.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ def _parse_limit(raw: str | None) -> int:
2020
return _DEFAULT_LIMIT
2121
try:
2222
n = int(raw.strip())
23-
except ValueError:
24-
raise ValueError("limit must be a positive integer") from None
23+
except ValueError as exc:
24+
raise ValueError("limit must be a positive integer") from exc
2525
if n < 1:
2626
raise ValueError("limit must be a positive integer")
2727
return min(n, _MAX_LIMIT)

tests/conftest.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,22 @@ def client_single(tmp_path):
3333
app = create_app(base_dir=str(tmp_path))
3434
app.config["TESTING"] = True
3535
return app.test_client()
36+
37+
38+
@pytest.fixture
39+
def client_empty(tmp_path):
40+
"""Flask test client with an empty projects directory."""
41+
app = create_app(base_dir=str(tmp_path))
42+
app.config["TESTING"] = True
43+
return app.test_client()
44+
45+
46+
@pytest.fixture
47+
def client_thinking(tmp_path):
48+
"""Flask test client with a session containing thinking content blocks."""
49+
project_dir = tmp_path / "test-project"
50+
project_dir.mkdir(parents=True)
51+
shutil.copy(FIXTURES / "session_with_thinking.jsonl", project_dir / "session_think001.jsonl")
52+
app = create_app(base_dir=str(tmp_path))
53+
app.config["TESTING"] = True
54+
return app.test_client()

tests/test_api_integration.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44
Covers /api/projects, /api/projects/<name>/sessions, /api/sessions/<name>/<id>,
55
and /api/search (Week 3 Tuesday, 8pt).
66
7-
The `client` fixture (two seeded sessions) is provided by tests/conftest.py.
7+
Fixtures (`client`, `client_empty`, `client_thinking`) live in tests/conftest.py.
88
"""
99

1010
from __future__ import annotations
1111

12-
from app import create_app
13-
1412

1513
def _assert_error_shape(resp):
1614
body = resp.get_json()
@@ -33,10 +31,8 @@ def test_projects_returns_list(client):
3331
assert "path" in project
3432

3533

36-
def test_projects_empty_base_dir(tmp_path):
37-
app = create_app(base_dir=str(tmp_path))
38-
app.config["TESTING"] = True
39-
resp = app.test_client().get("/api/projects")
34+
def test_projects_empty_base_dir(client_empty):
35+
resp = client_empty.get("/api/projects")
4036
assert resp.status_code == 200
4137
assert resp.get_json() == []
4238

@@ -79,6 +75,16 @@ def test_session_detail_not_found(client):
7975
_assert_error_shape(resp)
8076

8177

78+
def test_session_detail_includes_thinking_blocks(client_thinking):
79+
resp = client_thinking.get("/api/sessions/test-project/session_think001")
80+
assert resp.status_code == 200
81+
session = resp.get_json()
82+
assert "messages" in session
83+
assistant_msgs = [m for m in session["messages"] if m.get("role") == "assistant"]
84+
assert len(assistant_msgs) >= 1
85+
assert assistant_msgs[0].get("thinking") == "Considering options carefully."
86+
87+
8288
# --- /api/search ---
8389

8490

0 commit comments

Comments
 (0)