Skip to content

test: add corrupted BLOB deserialization test (#2033)#2045

Merged
bug-ops merged 2 commits intomainfrom
feat/issue-2033-test-corrupted-blob
Mar 20, 2026
Merged

test: add corrupted BLOB deserialization test (#2033)#2045
bug-ops merged 2 commits intomainfrom
feat/issue-2033-test-corrupted-blob

Conversation

@bug-ops
Copy link
Copy Markdown
Owner

@bug-ops bug-ops commented Mar 20, 2026

Summary

Add 4 unit tests for graceful degradation in semantic cache when embedding BLOBs are corrupted and bytemuck deserialization fails.

Tests Added

  • test_semantic_get_corrupted_blob_odd_length: 5-byte BLOB triggers SizeMismatch → Ok(None), no panic
  • test_semantic_get_corrupted_blob_skips_to_valid: mixed corrupt (3-byte) + valid row → valid row returned, corrupt skipped
  • test_semantic_get_empty_blob: 0-byte BLOB → cosine 0.0 < threshold → Ok(None), no panic
  • test_semantic_get_all_blobs_corrupted: all 5 candidates corrupt (1,3,5,7,6 bytes) → Ok(None), no panic

Implementation Details

  • Location: crates/zeph-memory/src/response_cache.rs (test module)
  • Approach: Raw SQL INSERT to inject corrupt BLOBs, bypassing put_with_embedding
  • Isolation: :memory: SQLite per test, no state leakage
  • Coverage: Exercises the error branch at lines 102-104 of get_semantic()

Validation

  • Architect designed the test structure
  • Critic approved design (0 blockers, 2 minor recs incorporated)
  • Developer implemented all 4 tests
  • Tester validated coverage and edge cases
  • Security audited memory safety
  • Impl-critic approved code quality
  • Code reviewer approved (FMT formatting fix applied)

Test Results

  • All 688 zeph-memory tests pass
  • No regressions
  • Code: A-grade (clippy clean, fmt clean, well-commented)

Closes #2033

Add unit tests for graceful degradation in semantic cache when
bytemuck::try_cast_slice fails due to corrupted embedding BLOBs:

- test_semantic_get_corrupted_blob_odd_length: 5-byte BLOB (SizeMismatch)
- test_semantic_get_corrupted_blob_skips_to_valid: mixed corrupt+valid rows
- test_semantic_get_empty_blob: empty BLOB edge case
- test_semantic_get_all_blobs_corrupted: all candidates corrupt (REC-1: 6-byte)

Use raw SQL INSERT to inject corrupt BLOBs, bypassing put_with_embedding.
Verify: no panics, proper error handling, IEEE 754 NaN safety.

All 688 zeph-memory tests pass. Code reviewed and approved.
@github-actions github-actions bot added documentation Improvements or additions to documentation memory zeph-memory crate (SQLite) rust Rust code changes tests Test-related changes size/M Medium PR (51-200 lines) labels Mar 20, 2026
@bug-ops bug-ops enabled auto-merge (squash) March 20, 2026 14:31
@github-actions github-actions bot added tests Test-related changes and removed tests Test-related changes labels Mar 20, 2026
@bug-ops bug-ops merged commit cddd092 into main Mar 20, 2026
25 checks passed
@bug-ops bug-ops deleted the feat/issue-2033-test-corrupted-blob branch March 20, 2026 14:39
bug-ops added a commit that referenced this pull request Mar 20, 2026
…2034)

Add 3 tests for dimension mismatch handling in semantic cache:
- test_semantic_get_dimension_mismatch_returns_none: store dim=3, query dim=2
- test_semantic_get_dimension_mismatch_query_longer: store dim=2, query dim=3
- test_semantic_get_mixed_dimensions_picks_correct_match: mixed dims

Complements PR #2045 (corrupted BLOB tests). These tests verify that
cosine_similarity() and get_semantic() gracefully handle embedding dimension
mismatches using threshold=0.01 to correctly reject 0.0 scores from mismatches.

Fixes #2034. All 5533 tests pass, no regressions.
bug-ops added a commit that referenced this pull request Mar 20, 2026
…2034)

Add 3 tests for dimension mismatch handling in semantic cache:
- test_semantic_get_dimension_mismatch_returns_none: store dim=3, query dim=2
- test_semantic_get_dimension_mismatch_query_longer: store dim=2, query dim=3
- test_semantic_get_mixed_dimensions_picks_correct_match: mixed dims

Complements PR #2045 (corrupted BLOB tests). These tests verify that
cosine_similarity() and get_semantic() gracefully handle embedding dimension
mismatches using threshold=0.01 to correctly reject 0.0 scores from mismatches.

Fixes #2034. All 5533 tests pass, no regressions.
bug-ops added a commit that referenced this pull request Mar 20, 2026
…2034)

Add 3 tests for dimension mismatch handling in semantic cache:
- test_semantic_get_dimension_mismatch_returns_none: store dim=3, query dim=2
- test_semantic_get_dimension_mismatch_query_longer: store dim=2, query dim=3
- test_semantic_get_mixed_dimensions_picks_correct_match: mixed dims

Complements PR #2045 (corrupted BLOB tests). These tests verify that
cosine_similarity() and get_semantic() gracefully handle embedding dimension
mismatches using threshold=0.01 to correctly reject 0.0 scores from mismatches.

Fixes #2034. All 5533 tests pass, no regressions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation memory zeph-memory crate (SQLite) rust Rust code changes size/M Medium PR (51-200 lines) tests Test-related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test: add corrupted BLOB deserialization test

1 participant