Three ADRs implemented and hardened across five rounds of adversarial review, plus the fixes that review surfaced. **ADR-280 — durable RVF metadata.** Delta-encoded generations with a snapshot every 32. The first implementation wrote a full snapshot per commit and replayed every one at open: 600 commits produced a 725 MiB file that could no longer be opened, with no repair path. Now 241 KB of META payload for the same workload, opening in ~4 ms. Review also closed: derive-children that could not be reopened, an 80-byte file driving a 512 MiB allocation, delete() rollback leaving in-memory tombstones that bricked the artifact, ten BufWriter sites discarding flush errors before sync_all, corrupt mid-chain deltas made unopenable (now recovers the longest valid prefix), and an ordering bug where recovery pruning committed without its re-anchoring snapshot so `rvf ingest` printed a repair warning and then destroyed the file. **ADR-281 — role-aware embeddings.** Query/passage routing with an attested embedding-space identity. Review found the space id hashed CARGO_PKG_VERSION, so a routine version bump would have rejected every persisted corpus and invalidated every cache key — with the test suite structurally blind to it. Now keyed on a dedicated format revision with a golden-id test. Also: three constructors that failed unconditionally with ten unmigrated callers, prompt templates applied from the attested identity rather than hardcoded strings, and ApiEmbedding no longer bypassing templating. **ADR-282 — nightly research quality gate.** Review found the gate had never completed a single run: the candidate checkout was shallow so its git diff always failed, and a jq quoting bug made the override path dead code. Check-run queries were unpaginated — on a real main commit 8 of 22 failures were invisible, so a red base could be certified green. Schemas are now load-bearing with a hashed dependency closure. **CI note.** The two red checks are both pre-existing on main, not regressions from this branch: `Tests (core-and-rest)` routinely exceeds its 4-hour window, and `Hooks CI` has failed on main since 2026-08-02 (and in May) on `cp -r node_modules $GITHUB_WORKSPACE/npm/packages/cli/` in hooks-ci.yml — this branch's one-line version sync merely re-triggered its path filter. 72 checks pass. Follow-ups filed and not blocking: #770, #771, #772. 🤖 Generated with [claude-flow](https://github.com/ruvnet/claude-flow) |
||
|---|---|---|
| .. | ||
| advanced_features_integration.rs | ||
| concurrent_tests.rs | ||
| embeddings_role_test.rs | ||
| embeddings_test.rs | ||
| hnsw_integration_test.rs | ||
| integration_tests.rs | ||
| property_tests.rs | ||
| README.md | ||
| stress_tests.rs | ||
| test_memory_pool.rs | ||
| test_quantization.rs | ||
| test_simd_correctness.rs | ||
| unit_tests.rs | ||
Ruvector Core Test Suite
Overview
This directory contains a comprehensive Test-Driven Development (TDD) test suite following the London School approach. The test suite covers unit tests, integration tests, property-based tests, stress tests, and concurrent access tests.
Test Files
1. unit_tests.rs - Unit Tests with Mocking (London School)
Comprehensive unit tests using mockall for mocking dependencies:
-
Distance Metric Tests: Tests for all 4 distance metrics (Euclidean, Cosine, Dot Product, Manhattan)
- Self-distance verification
- Symmetry properties
- Orthogonal and parallel vector cases
- Dimension mismatch error handling
-
Quantization Tests: Tests for scalar and binary quantization
- Round-trip reconstruction accuracy
- Distance calculation correctness
- Sign preservation (binary quantization)
- Hamming distance validation
-
Storage Layer Tests: Tests for VectorStorage
- Insert with explicit and auto-generated IDs
- Metadata handling
- Dimension validation
- Batch operations
- Delete operations
- Error cases (non-existent vectors, dimension mismatches)
-
VectorDB Tests: High-level API tests
- Empty database operations
- Insert/delete with len() tracking
- Search functionality
- Metadata filtering
- Batch insert operations
2. integration_tests.rs - End-to-End Integration Tests
Full workflow tests that verify all components work together:
- Complete Workflows: Insert + search + retrieve with metadata
- Large Batch Operations: 10K+ vector batch insertions
- Persistence: Database save and reload verification
- Mixed Operations: Combined insert, delete, and search operations
- Distance Metrics: Tests for all 4 metrics end-to-end
- HNSW Configurations: Different HNSW parameter combinations
- Metadata Filtering: Complex filtering scenarios
- Error Handling: Dimension validation, wrong query dimensions
3. property_tests.rs - Property-Based Tests (proptest)
Mathematical property verification using proptest:
-
Distance Metric Properties:
- Self-distance is zero
- Symmetry: d(a,b) = d(b,a)
- Triangle inequality: d(a,c) ≤ d(a,b) + d(b,c)
- Non-negativity
- Scale invariance (cosine)
- Translation invariance (Euclidean)
-
Quantization Properties:
- Round-trip reconstruction bounds
- Sign preservation (binary)
- Self-distance is zero
- Symmetry
- Distance bounds
-
Batch Operations:
- Consistency between batch and individual operations
-
Dimension Handling:
- Mismatch error detection
- Success on matching dimensions
4. stress_tests.rs - Scalability and Performance Stress Tests
Tests that push the system to its limits:
- Million Vector Insertion (ignored by default): Insert 1M vectors in batches
- Concurrent Queries: 10 threads × 100 queries each
- Concurrent Mixed Operations: Simultaneous readers and writers
- Memory Pressure: Large 2048-dimensional vectors
- Error Recovery: Invalid operations don't crash the system
- Repeated Operations: Same operation executed many times
- Extreme Parameters: k values larger than database size
5. concurrent_tests.rs - Thread-Safety Tests
Multi-threaded access patterns:
- Concurrent Reads: Multiple threads reading simultaneously
- Concurrent Writes: Non-overlapping writes from multiple threads
- Mixed Read/Write: Concurrent reads and writes
- Delete and Insert: Simultaneous deletes and inserts
- Search and Insert: Searching while inserting
- Batch Atomicity: Verifying batch operations are atomic
- Read-Write Consistency: Ensuring no data corruption
- Metadata Updates: Concurrent metadata modifications
Benchmarks
6. benches/quantization_bench.rs - Quantization Performance
Criterion benchmarks for quantization operations:
- Scalar quantization encode/decode/distance
- Binary quantization encode/decode/distance
- Compression ratio comparisons
7. benches/batch_operations.rs - Batch Operation Performance
Criterion benchmarks for batch operations:
- Batch insert at various scales (100, 1K, 10K)
- Individual vs batch insert comparison
- Parallel search performance
- Batch delete operations
Running Tests
Run All Tests
cargo test --package ruvector-core
Run Specific Test Suites
# Unit tests only
cargo test --test unit_tests
# Integration tests only
cargo test --test integration_tests
# Property tests only
cargo test --test property_tests
# Concurrent tests only
cargo test --test concurrent_tests
# Stress tests (including ignored tests)
cargo test --test stress_tests -- --ignored --test-threads=1
Run Benchmarks
# Distance metrics (existing)
cargo bench --bench distance_metrics
# HNSW search (existing)
cargo bench --bench hnsw_search
# Quantization (new)
cargo bench --bench quantization_bench
# Batch operations (new)
cargo bench --bench batch_operations
Generate Coverage Report
# Install tarpaulin if not already installed
cargo install cargo-tarpaulin
# Generate HTML coverage report
cargo tarpaulin --out Html --output-dir target/coverage
# Open coverage report
open target/coverage/index.html
Test Coverage Goals
- Target: 90%+ code coverage
- Focus Areas:
- Distance calculations
- Index operations
- Storage layer
- Error handling paths
- Edge cases
Known Issues
As of the current implementation, there are pre-existing compilation errors in the codebase that prevent some tests from running:
- HNSW Index:
DataId::newconstruction issues insrc/index/hnsw.rs - AgenticDB: Missing
Encode/Decodetrait implementations forReflexionEpisode
These issues exist in the main codebase and need to be fixed before the full test suite can execute.
Test Organization
Tests are organized by purpose and scope:
- Unit Tests: Test individual components in isolation with mocking
- Integration Tests: Test component interactions and workflows
- Property Tests: Test mathematical properties and invariants
- Stress Tests: Test performance limits and edge cases
- Concurrent Tests: Test thread-safety and concurrent access patterns
Dependencies
Test dependencies (in Cargo.toml):
[dev-dependencies]
criterion = { workspace = true }
proptest = { workspace = true }
mockall = { workspace = true }
tempfile = "3.13"
tracing-subscriber = { workspace = true }
Contributing
When adding new tests:
- Follow the existing structure and naming conventions
- Add tests to the appropriate file (unit, integration, property, etc.)
- Document the test purpose clearly
- Ensure tests are deterministic and don't depend on timing
- Use
tempdir()for database paths in tests - Clean up resources properly
CI/CD Integration
Recommended CI pipeline:
test:
script:
- cargo test --all-features
- cargo tarpaulin --out Xml
coverage: '/\d+\.\d+% coverage/'
bench:
script:
- cargo bench --no-run
Performance Expectations
Based on stress tests:
- Insert: ~10K vectors/second (batch mode)
- Search: ~1K queries/second (k=10, HNSW)
- Concurrent: 10+ threads without performance degradation
- Memory: ~4KB per 384-dim vector (uncompressed)