test(mcp-kb): Add database layer tests - currently 0% coverage on 775 lines #76

Open
opened 2026-01-03 23:57:02 +00:00 by cardosofelipe · 0 comments

Issue Description

The Knowledge Base MCP server has 0% test coverage on the database layer (database.py - 775 lines). This is a critical gap as the database layer is the core of the KB functionality.

Current State

  • database.py: 775 lines, 0% coverage
  • No integration tests with actual PostgreSQL
  • No tests for vector search functionality

Required Tests

  1. Connection Management

    • Test pool creation/cleanup
    • Test connection lifecycle
    • Test error handling on connection failure
  2. Document Operations

    • CRUD operations for documents
    • Batch insert operations
    • Transaction handling
  3. Search Operations

    • Semantic search with embeddings
    • Keyword search with ts_rank
    • Hybrid search with RRF
    • Filter combinations
  4. Collection Operations

    • Create/update/delete collections
    • Collection statistics
  5. Edge Cases

    • Empty results
    • Large documents
    • Unicode content
    • NULL handling

Test Infrastructure Needed

  • fakeredis for Redis mocking (already in deps)
  • PostgreSQL test container or mock
  • Vector embedding mocks

Coverage Target

  • Minimum 90% on database.py
  • Found during PR #72 deep review
  • Issue #57 (Knowledge Base MCP Server)
## Issue Description The Knowledge Base MCP server has 0% test coverage on the database layer (`database.py` - 775 lines). This is a critical gap as the database layer is the core of the KB functionality. ### Current State - `database.py`: 775 lines, 0% coverage - No integration tests with actual PostgreSQL - No tests for vector search functionality ### Required Tests 1. **Connection Management** - Test pool creation/cleanup - Test connection lifecycle - Test error handling on connection failure 2. **Document Operations** - CRUD operations for documents - Batch insert operations - Transaction handling 3. **Search Operations** - Semantic search with embeddings - Keyword search with ts_rank - Hybrid search with RRF - Filter combinations 4. **Collection Operations** - Create/update/delete collections - Collection statistics 5. **Edge Cases** - Empty results - Large documents - Unicode content - NULL handling ### Test Infrastructure Needed - `fakeredis` for Redis mocking (already in deps) - PostgreSQL test container or mock - Vector embedding mocks ### Coverage Target - Minimum 90% on database.py ### Related - Found during PR #72 deep review - Issue #57 (Knowledge Base MCP Server)
Sign in to join this conversation.