Skip to content

Improve backend test coverage and add coverage tooling#35

Merged
patchmemory merged 4 commits into
mainfrom
feat/backend-test-coverage-improvements
Feb 5, 2026
Merged

Improve backend test coverage and add coverage tooling#35
patchmemory merged 4 commits into
mainfrom
feat/backend-test-coverage-improvements

Conversation

@patchmemory

Copy link
Copy Markdown
Owner

Summary

  • Added coverage>=7.4 to dev dependencies for local coverage testing
  • Added 18 new backend tests targeting low-coverage modules
  • Improved overall backend coverage from 67% to 68%
  • Added comprehensive coverage documentation to dev/prompts.md

Coverage Improvements

Module Before After Change Impact
api_interpreters.py 29% 60% +31% Toggle/debug endpoints now tested
api_providers.py 20% 33% +13% Provider roots & rclone validation tested
api_chat.py 34% 37% +3% GraphRAG endpoints & observability tested
registry.py 88% 94% +6% Improved via interpreter tests
Overall 67% 68% +1% 197 tests passing (up from 179)

New Tests Added

test_chat_api.py (+7 tests)

  • test_api_chat_missing_message - Validates error handling
  • test_api_chat_history - Tests chat history endpoint
  • test_api_chat_capabilities - Tests capabilities endpoint
  • test_api_chat_graphrag_disabled_by_default - Tests GraphRAG disabled state
  • test_api_chat_graphrag_missing_message - Tests GraphRAG error handling
  • test_api_chat_context_refresh_disabled - Tests context refresh disabled
  • test_api_chat_observability_graphrag - Tests observability endpoint

test_interpreters_registry_api.py (+4 tests)

  • test_api_interpreters_effective_debug - Tests debug endpoint
  • test_api_interpreters_toggle_enable - Tests enabling interpreters
  • test_api_interpreters_toggle_disable - Tests disabling interpreters
  • test_api_interpreters_toggle_default_enabled - Tests default toggle behavior

test_providers_api.py (+6 tests)

  • test_provider_roots_default - Tests default provider roots
  • test_provider_roots_specific_provider - Tests specific provider query
  • test_provider_roots_invalid_provider - Tests error handling
  • test_rclone_mounts_list - Tests mount listing
  • test_rclone_mounts_create_missing_rclone - Tests rclone validation
  • test_rclone_mounts_create_missing_remote - Tests remote validation
  • test_rclone_mounts_create_missing_name - Tests name validation

Coverage Tooling

Added to dependencies:

  • coverage>=7.4 in pyproject.toml and requirements.txt

Local usage:

# Install dependencies
pip install -r requirements.txt

# Run tests with coverage
python -m coverage run -m pytest tests/

# View terminal report
python -m coverage report

# Generate interactive HTML report
python -m coverage html
# Then open: htmlcov/index.html

Documentation:

  • Added comprehensive "Backend (pytest) Coverage" section to dev/prompts.md
  • Documents standard commands, usage patterns, and coverage targets
  • Explains how to read HTML reports (green/red line highlighting)
  • Sets target coverage levels: 90%+ for critical, 70%+ for core, 60%+ for API routes

Remaining Low Coverage Areas

Future work to reach 70%+ overall:

  • api_files.py (37%) - Complex file operations
  • link_service.py (40%) - Preview/execute workflows
  • api_graph.py (42%) - Graph query endpoints
  • label_service.py (50%) - Label CRUD operations

Test plan

  • All 197 tests passing locally
  • Coverage improved in targeted modules
  • Documentation added to dev/prompts.md
  • Dev submodule updated and pushed
  • Dependencies added to pyproject.toml and requirements.txt

🤖 Generated with Claude Code

- Add coverage>=7.4 to dev dependencies (pyproject.toml, requirements.txt)
- Add 18 new backend tests for low-coverage modules
- Improve api_interpreters.py coverage: 29% → 60% (+31%)
- Improve api_providers.py coverage: 20% → 33% (+13%)
- Improve api_chat.py coverage: 34% → 37% (+3%)
- Overall coverage: 67% → 68%

New tests added:
- test_chat_api.py: 7 new tests (GraphRAG endpoints, history, capabilities)
- test_interpreters_registry_api.py: 4 new tests (toggle, debug endpoints)
- test_providers_api.py: 6 new tests (provider roots, rclone validation)

Coverage tooling:
- Enables local coverage reports: python -m coverage run -m pytest
- Interactive HTML reports: python -m coverage html (htmlcov/index.html)
- Documentation added to dev/prompts.md

Total: 197 tests passing (up from 179)
- Ignore .coverage file and .coverage.* parallel mode files
- Ignore htmlcov/ directory (HTML coverage reports)
- Ignore coverage.xml and *.cover files
- Add monkeypatch to mock shutil.which for rclone tests
- Fixes CI failure where rclone is not installed
- Tests now properly validate input validation logic
- All 9 provider tests passing
@patchmemory patchmemory merged commit ac3fbf3 into main Feb 5, 2026
2 checks passed
@patchmemory patchmemory deleted the feat/backend-test-coverage-improvements branch February 5, 2026 16:44
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.

1 participant