Skip to content

Fix failing Rust embedding service tests #343

Closed

Description

@malibio

Problem

Four Rust tests in the embedding service were failing with assertion errors:

  1. test_chunking_strategy_small
  2. test_chunking_strategy_medium
  3. test_chunking_strategy_large
  4. test_re_embed_container

Location: packages/core/src/services/embedding_service_test.rs

Error Details

All failures showed assertion mismatches where expected values didn't match actual values:

assertion \`left == right\` failed
  left: Null
 right: "complete_container" (or "container_summary")

Root Causes Identified

  1. JSON Metadata Storage Bug (3 tests)

    • store_embedding method was passing metadata as a string to json_set()
    • SQLite's json_set() requires JSON type, not string type
    • This caused properties["embedding_metadata"]["type"] to be Null instead of expected values
  2. Database Transaction Isolation Issue (1 test)

    • test_re_embed_container held a database connection across content update and re-embedding
    • This caused embeddings to appear identical when they should have been different
    • The second embedding was reading stale data from the open transaction

Solution

Fixed in PR #358:

  • Added json() wrapper to json_set() call in embedding_service.rs:678
  • Refactored test connection management to use scoped blocks with fresh connections
  • Added comprehensive inline documentation to prevent future regressions

Impact

  • Test Results: 212 passing, 4 failing (98.2% pass rate)
  • Commands Affected: bun run rust:test, bun run test:all, bun run test:all:db
  • Development Impact: Rust test suite shows failures

Acceptance Criteria

  • All 4 embedding service tests pass
  • Test expectations match current embedding service behavior
  • cargo test completes with 0 failures
  • bun run test:all passes completely

Additional Context

These were pre-existing failures discovered during TEST_USE_DATABASE feature implementation (PR #337). They were unrelated to frontend test changes but blocked clean test:all runs.

Test Command:

cargo test --lib embedding_service

Resolved: All tests now pass. Fix merged in PR #358.

Metadata

Metadata

Assignees

Labels

backendbugtesting

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions