Skip to content

test: add integration tests for MCP server tools (closes #5)#7

Open
clawtom wants to merge 1 commit intoraphasouthall:mainfrom
clawtom:test/mcp-server-integration
Open

test: add integration tests for MCP server tools (closes #5)#7
clawtom wants to merge 1 commit intoraphasouthall:mainfrom
clawtom:test/mcp-server-integration

Conversation

@clawtom
Copy link

@clawtom clawtom commented Mar 14, 2026

Closes #5.

Adds tests/test_server_integration.py covering the three MCP tools from the issue: vault_stats, vault_prediction_errors, and vault_search.

Approach

The tests call tool functions directly as plain Python callables — no stdio or network transport needed. Each test patches neurostack.schema.DB_PATH to point to a hermetic temp-file database. This works because each tool imports DB_PATH lazily inside its function body, so the patch is visible at call time.

A server_db fixture creates a temp DB via get_db() (which runs all schema migrations) and inserts two notes, two chunks, and one prediction error — enough for all tools to return non-trivial results.

Coverage

  • TestVaultStats (5 tests): valid JSON, required keys, counts match test data, stale-summary detection, empty vault
  • TestVaultPredictionErrors (6 tests): valid JSON, required keys, returns inserted error, error-type filter, resolve clears error, empty vault
  • TestVaultSearch (5 tests): valid JSON, keyword FTS finds matching note, result fields, no-match returns empty list, top_k limit

vault_search uses mode="keyword" (pure FTS5) throughout — no Ollama embedding service needed, consistent with the issue requirement.

🤖 Generated with Claude Code

Closes raphasouthall#5.

Adds `tests/test_server_integration.py` covering the three MCP tools
identified in the issue: `vault_stats`, `vault_prediction_errors`, and
`vault_search`.

## Approach

The tests call tool functions directly as plain Python callables (no
stdio or network transport required), patching `neurostack.schema.DB_PATH`
to point to a hermetic temp-file database. This works because each tool
imports `DB_PATH` lazily inside its function body, so the patch is
visible at call time.

A `server_db` fixture creates a temp DB via `get_db()` (which runs all
schema migrations) and inserts two notes, two chunks, and one prediction
error -- enough for all tools to return non-trivial results.

## Coverage

- `TestVaultStats` (5 tests): valid JSON, required keys, counts match
  test data, stale-summary detection, empty vault
- `TestVaultPredictionErrors` (6 tests): valid JSON, required keys,
  returns inserted error, error-type filter, resolve clears error, empty vault
- `TestVaultSearch` (5 tests): valid JSON, keyword FTS finds matching
  note, result fields, no-match returns empty list, top_k limit

`vault_search` uses `mode="keyword"` (pure FTS5) throughout -- this
avoids needing the Ollama embedding service, consistent with the
issue's "tests don't need to run over the network" requirement.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add integration test that starts the MCP server and calls tools

1 participant