|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
5 | 5 | import shutil |
| 6 | +from collections.abc import Mapping |
6 | 7 | from pathlib import Path |
7 | 8 |
|
8 | 9 | import pytest |
|
12 | 13 | FIXTURES = Path(__file__).parent / "fixtures" |
13 | 14 |
|
14 | 15 |
|
15 | | -@pytest.fixture |
16 | | -def client(tmp_path): |
17 | | - """Flask test client with two seeded sessions in 'test-project'.""" |
18 | | - project_dir = tmp_path / "test-project" |
19 | | - project_dir.mkdir(parents=True) |
20 | | - shutil.copy(FIXTURES / "session_minimal.jsonl", project_dir / "session_abc123.jsonl") |
21 | | - shutil.copy(FIXTURES / "session_with_tools.jsonl", project_dir / "session_def456.jsonl") |
| 16 | +def _make_test_client(tmp_path, session_files: Mapping[str, str] | None = None): |
| 17 | + """Build a Flask test client, optionally seeding session JSONL files under test-project.""" |
| 18 | + if session_files: |
| 19 | + project_dir = tmp_path / "test-project" |
| 20 | + project_dir.mkdir(parents=True) |
| 21 | + for dest_name, fixture_name in session_files.items(): |
| 22 | + shutil.copy(FIXTURES / fixture_name, project_dir / dest_name) |
22 | 23 | app = create_app(base_dir=str(tmp_path)) |
23 | 24 | app.config["TESTING"] = True |
24 | 25 | return app.test_client() |
25 | 26 |
|
26 | 27 |
|
| 28 | +@pytest.fixture |
| 29 | +def client(tmp_path): |
| 30 | + """Flask test client with two seeded sessions in 'test-project'.""" |
| 31 | + return _make_test_client( |
| 32 | + tmp_path, |
| 33 | + { |
| 34 | + "session_abc123.jsonl": "session_minimal.jsonl", |
| 35 | + "session_def456.jsonl": "session_with_tools.jsonl", |
| 36 | + }, |
| 37 | + ) |
| 38 | + |
| 39 | + |
27 | 40 | @pytest.fixture |
28 | 41 | def client_single(tmp_path): |
29 | 42 | """Flask test client with one seeded session — for search/limit tests.""" |
30 | | - project_dir = tmp_path / "test-project" |
31 | | - project_dir.mkdir(parents=True) |
32 | | - shutil.copy(FIXTURES / "session_minimal.jsonl", project_dir / "session_abc123.jsonl") |
33 | | - app = create_app(base_dir=str(tmp_path)) |
34 | | - app.config["TESTING"] = True |
35 | | - return app.test_client() |
| 43 | + return _make_test_client(tmp_path, {"session_abc123.jsonl": "session_minimal.jsonl"}) |
36 | 44 |
|
37 | 45 |
|
38 | 46 | @pytest.fixture |
39 | 47 | def client_empty(tmp_path): |
40 | 48 | """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() |
| 49 | + return _make_test_client(tmp_path) |
44 | 50 |
|
45 | 51 |
|
46 | 52 | @pytest.fixture |
47 | 53 | def client_thinking(tmp_path): |
48 | 54 | """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() |
| 55 | + return _make_test_client( |
| 56 | + tmp_path, {"session_think001.jsonl": "session_with_thinking.jsonl"} |
| 57 | + ) |
0 commit comments