Skip to content

Commit afb916b

Browse files
committed
Improve test coverage
1 parent 8d7ef0b commit afb916b

7 files changed

+736
-143
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
# Icon must end with two \r
1111
Icon
1212

13-
1413
# Thumbnails
1514
._*
1615

@@ -164,6 +163,7 @@ venv/
164163
ENV/
165164
env.bak/
166165
venv.bak/
166+
.venv/
167167

168168
# Spyder project settings
169169
.spyderproject

codebase.pdf

370 KB
Binary file not shown.

improving_test_coverage.md

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# ✅ Test Coverage Improvement Plan
2+
3+
NOTE: Keep track of your work at the end of the file after "PROGRESS ON WORK."
4+
NOTE: The command to run coverage is: `uv run pytest --cov agent_memory_server --cov-report=term-missing --run-api-tests`
5+
6+
## 🎯 Goal
7+
Increase total coverage from **51% to 75%** with minimal disruption and maximum impact.
8+
9+
---
10+
11+
## 🔝 Priority Targets (Uncovered Critical Logic)
12+
13+
### 1. `cli.py` (0%)
14+
- **Tests to write:**
15+
- `version`, `api`, `mcp`, `schedule_task`, `task_worker`, `migrate_memories`, `rebuild_index`
16+
- **Approach:** Use `click.testing.CliRunner`. Mock Redis and async functions.
17+
18+
### 2. `long_term_memory.py` (46%)
19+
- **Tests to write:**
20+
- `promote_working_memory_to_long_term`, `index_long_term_memories`, `search_memories`
21+
- **Approach:** Parametrize edge cases (no matches, Redis down, invalid filter). Mock Redis and vector indexing.
22+
23+
### 3. `summarization.py` (14%)
24+
- **Tests to write:**
25+
- `_incremental_summary`, edge cases for token limits and empty input
26+
- **Approach:** Mock LLM client. Use short token windows to force edge behavior.
27+
28+
### 4. `docket_tasks.py` (0%)
29+
- **Tests to write:**
30+
- Task registration, task collection membership, verify Redis URL use
31+
- **Approach:** Mock Docket client, test task registration logic
32+
33+
---
34+
35+
## ⚙️ Medium-Priority
36+
37+
### 5. `filters.py` (51%)
38+
- **Tests to write:**
39+
- Each filter type (`eq`, `gt`, `between`, etc.)
40+
- **Approach:** Use parametric testing, validate Redis query expressions
41+
42+
### 6. `llms.py` (66%)
43+
- **Tests to write:**
44+
- Model selection logic, token limit behaviors, prompt formatting
45+
- **Approach:** Mock OpenAI and Anthropic clients
46+
47+
### 7. `mcp.py` (66%)
48+
- **Tests to write:**
49+
- Tool interface dispatch, SSE vs stdio routing
50+
- **Approach:** Patch `run_stdio_async`, `run_sse_async`, assert logs and Redis effects
51+
52+
---
53+
54+
## 🧹 Low-Hanging Fruit (Fast Wins)
55+
56+
### 8. `utils/api_keys.py` (0%)
57+
- **Add tests for:** key parsing, fallback logic
58+
59+
### 9. `logging.py` (50%)
60+
- **Add tests for:** `configure_logging`, custom level configs
61+
62+
### 10. `dependencies.py` (92%)
63+
- **Add tests for:** `add_task` fallback path (no Docket)
64+
65+
---
66+
67+
## 🧪 Integration Tests
68+
69+
- Test full flow:
70+
- POST to `working_memory` → promotion task triggers → data lands in `long_term_memory`
71+
- GET from memory search endpoint returns expected result
72+
73+
---
74+
75+
## 🗂️ Progress Tracking Template
76+
77+
| File | Coverage Before | Target | Status |
78+
|------|------------------|--------|--------|
79+
| `cli.py` | 0% | 80%+ | ⬜️ |
80+
| `long_term_memory.py` | 46% | 70%+ | ⬜️ |
81+
| `summarization.py` | 14% | 60%+ | ⬜️ |
82+
| `filters.py` | 51% | 75% | ⬜️ |
83+
| `llms.py` | 66% | 80% | ⬜️ |
84+
| `docket_tasks.py` | 0% | 80% | ⬜️ |
85+
| `mcp.py` | 66% | 85% | ⬜️ |
86+
| `api_keys.py` | 0% | 100% | ⬜️ |
87+
| `logging.py` | 50% | 100% | ⬜️ |
88+
| `dependencies.py` | 92% | 100% | ⬜️ |
89+
90+
---
91+
92+
## 🧰 Tools & Tips
93+
94+
- Use `pytest-cov` with `--cov-report=term-missing`
95+
- Use `pytest --durations=10` to find slow tests
96+
- Group new tests by file in `tests/unit` or `tests/integration`
97+
98+
---
99+
100+
## 📈 Exit Criteria
101+
102+
- At least **75%** overall test coverage
103+
- 80%+ coverage on top priority files
104+
- All major logic paths exercised with mocks or real integration
105+
106+
---
107+
108+
## PROGRESS ON WORK

pytest.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ filterwarnings =
77
ignore::DeprecationWarning
88
ignore::PendingDeprecationWarning
99
asyncio_mode = auto
10-
asyncio_default_fixture_loop_scope = session
10+
asyncio_default_fixture_loop_scope = function

tests/conftest.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import asyncio
21
import contextlib
32
import os
43
import time
@@ -32,11 +31,6 @@
3231
load_dotenv()
3332

3433

35-
@pytest.fixture(scope="session")
36-
def event_loop(request):
37-
return asyncio.get_event_loop()
38-
39-
4034
@pytest.fixture()
4135
def memory_message():
4236
"""Create a sample memory message"""

0 commit comments

Comments
 (0)