Skip to content

test(conversation-memory): improve test coverage for embeddings, summarizer, and MCP handlers - #483

Merged
baleen37 merged 1 commit into
mainfrom
feat/conversation-memory-test-coverage
Feb 12, 2026
Merged

test(conversation-memory): improve test coverage for embeddings, summarizer, and MCP handlers#483
baleen37 merged 1 commit into
mainfrom
feat/conversation-memory-test-coverage

Conversation

@baleen37

@baleen37 baleen37 commented Feb 12, 2026

Copy link
Copy Markdown
Owner

Summary

Improved test coverage for conversation-memory plugin by creating comprehensive unit tests for three key modules that previously had 0% coverage.

Changes

1. Refactored src/mcp/server.ts

  • Exported handler functions for testability:
    • handleSearch() - Search handler with db parameter
    • handleGetObservations() - Observations handler with ID conversion
    • handleRead() - Read handler with pagination
    • handleError() - Error formatting utility

2. New src/core/embeddings.test.ts (33 tests, 100% coverage)

  • Mocked @huggingface/transformers to test actual code execution
  • Tests for initEmbeddings(), generateEmbedding(), generateExchangeEmbedding()
  • Covers prefix formatting, truncation, singleton pattern, and error handling

3. New src/core/summarizer.test.ts (30 tests, 91.08% coverage)

  • Mocked LLM config and provider for controlled testing
  • Tests for trivial conversation detection, short/long summarization
  • Tests for token tracking, hierarchical summarization, and error handling

4. New src/mcp/server.handler.test.ts (27 tests)

  • Tests for all exported handler functions
  • Covers ID conversion, pagination, error cases

Coverage Results

File Before After
embeddings.ts 0% 100%
summarizer.ts 0% 91.08%
server.ts (handlers) 0% 42.54%*
Overall 70.17% 84.58%

*Handler functions fully covered; MCP infrastructure code requires integration testing.

Testing

  • Test count: 762 → 815 (+53 tests)
  • All 815 tests pass
  • No regressions introduced

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Introduced handler functions for search, observations retrieval, and file reading operations with improved error handling.
  • Tests

    • Significantly expanded test coverage for embeddings, summarization, and server request handlers with comprehensive mocking and isolation strategies.
  • Chores

    • Updated .gitignore to exclude coverage directory.

…arizer, and MCP handlers

- Refactor server.ts to export handler functions for testability
  - handleSearch(), handleGetObservations(), handleRead(), handleError()

- Add comprehensive embeddings.test.ts (33 tests, 100% coverage)
  - Mock @huggingface/transformers to test actual code execution
  - Tests for initEmbeddings(), generateEmbedding(), generateExchangeEmbedding()

- Add comprehensive summarizer.test.ts (30 tests, 91.08% coverage)
  - Mock LLM config and provider
  - Tests for trivial conversation detection, short/long summarization
  - Tests for token tracking and error handling

- Add server.handler.test.ts (27 tests)
  - Tests for all exported handler functions
  - Tests for ID conversion, pagination, error cases

Coverage improvements:
- embeddings.ts: 0% → 100%
- summarizer.ts: 0% → 91.08%
- server.ts handlers: 0% → 42.54% (handlers fully covered)
- Overall: 70.17% → 84.58%

Test count: 762 → 815 (+53 tests)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Feb 12, 2026

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

This PR adds comprehensive test coverage to the conversation-memory plugin, refactoring the MCP server to extract handler functions for better testability. It introduces new mocking strategies for embeddings and LLM modules, extensive test scenarios for summarization and search workflows, and handler abstractions in the server with corresponding test suites.

Changes

Cohort / File(s) Summary
Configuration
plugins/conversation-memory/.gitignore
Added coverage/ directory to ignore patterns.
Embeddings Testing
plugins/conversation-memory/src/core/embeddings.test.ts
Rewrote test suite with full mocking of @huggingface/transformers pipeline. Added 324 lines covering initEmbeddings initialization, singleton behavior, generateEmbedding text prefixing/truncation (8000 chars), and generateExchangeEmbedding formatting with proper User/Assistant labels and tools section handling.
Summarization Testing
plugins/conversation-memory/src/core/summarizer.test.ts
Expanded test coverage by 552 lines with comprehensive scenarios for formatConversationText, summarizeConversation trivial/non-trivial detection, hierarchical summarization for long conversations (>15 exchanges), token tracking utilities, LLM error handling, and multi-stage synthesis workflows with mocked LLM provider.
MCP Server Handler Testing
plugins/conversation-memory/src/mcp/server.handler.test.ts
Added 383 lines of new test suite validating handleSearch (result shaping, ID formatting, pagination), handleGetObservations (ID conversion, field validation), handleRead (content retrieval, pagination, error handling), and handleError (consistent error formatting).
MCP Server Implementation
plugins/conversation-memory/src/mcp/server.ts
Extracted and exported three handler functions (handleSearch, handleGetObservations, handleRead) wrapping core module calls with result transformation logic. Added public interfaces SearchResult and ObservationOutput. Exposed handleError utility for external use. Refactored request handler to delegate to new helpers.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • #463: Touches the same conversation-memory MCP tool surface and server-side handler logic for search/get_observations/read operations.
  • #363: Modifies the embeddings implementation (768-dimensional vectors, caching, truncation) that the PR's new embeddings test suite validates.
  • #474: Modifies the same plugins/conversation-memory/src/mcp/server.ts file and search/get_observations handling logic that this PR refactors with new handler exports.

Suggested labels

enhancement

Poem

🐰 Testing whiskers twitch with glee,
Mocks and stubs dance wild and free,
Handlers bundled, handlers bound,
Eight-thousand chars, embeddings found!
Coverage blooms in .gitignore's keep,
While summarizers count sheep. 📊

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/conversation-memory-test-coverage

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@baleen37
baleen37 enabled auto-merge (squash) February 12, 2026 04:44
@baleen37
baleen37 merged commit 06cb8ef into main Feb 12, 2026
4 of 5 checks passed
@baleen37
baleen37 deleted the feat/conversation-memory-test-coverage branch February 12, 2026 04:45
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