Skip to content

test(engines): add comprehensive unit and property-based tests for core engines#36

Merged
NP-compete merged 1 commit intomainfrom
feature/engine-unit-tests
Mar 5, 2026
Merged

test(engines): add comprehensive unit and property-based tests for core engines#36
NP-compete merged 1 commit intomainfrom
feature/engine-unit-tests

Conversation

@NP-compete
Copy link
Copy Markdown
Owner

Summary

Adds comprehensive unit tests and property-based tests (Hypothesis) for all core engines, raising engine test coverage from 81% to 96%.

  • Property-based tests using Hypothesis verify mathematical invariants:
    • Decay is monotonically decreasing without rehearsal
    • Strength always bounded by [min_strength, 1.0]
    • Pinned memories never decay
    • Importance always in [0, 1]
    • Frequency/emotional scores are monotonic w.r.t. inputs
  • Unit test gap coverage for from_config, apply_rehearsal_in_place, naive datetime handling, invalid metadata, edge cases in threshold estimation, and MMR diversity

Coverage Improvement

Engine Before After
decay.py 82% 95%
importance.py 92% 100%
retrieval.py 94% 97%
consolidation.py 95% 95%
working_memory.py 35%* 95%
TOTAL 81% 96%

* working_memory was undercounted (test file excluded from prior run)

Files Changed

File Change
tests/property/__init__.py New property test package
tests/property/test_decay_properties.py 6 property tests (~1,070 examples)
tests/property/test_importance_properties.py 7 property tests (~970 examples)
tests/unit/test_decay.py +14 tests (from_config, rehearsal, naive dt, edge cases)
tests/unit/test_importance.py +10 tests (from_config, naive dt, invalid metadata)
tests/unit/test_retrieval.py +8 tests (from_config, edges, naive dt, MMR)

Test plan

  • 338 total tests pass (176 engine-specific)
  • Ruff lint + format clean
  • Property tests verify invariants across randomized inputs
  • All from_config class methods tested
  • Naive datetime handling tested for all engines
  • Edge cases tested (zero strength, threshold boundaries, empty inputs)

Closes #14

Adds property-based tests (Hypothesis) and fills coverage gaps:

- tests/property/test_decay_properties.py: monotonicity, bounds,
  pinned invariant, rehearsal effect, decay factor properties
- tests/property/test_importance_properties.py: bounds, monotonicity,
  recency decay, source multiplier, explicit override

Adds missing unit tests for coverage gaps:
- DecayEngine: from_config, apply_rehearsal_in_place, naive datetime,
  edge cases (threshold estimation, unknown time units)
- ImportanceEngine: from_config, naive datetime, invalid metadata,
  batch/filter default time
- RetrievalEngine: from_config, empty after threshold, empty embedding,
  naive datetime, MMR edge cases

Engine coverage: 81% -> 96% (target was >80%)

Closes #14
@NP-compete NP-compete merged commit 41a511a into main Mar 5, 2026
6 checks passed
@NP-compete NP-compete deleted the feature/engine-unit-tests branch March 5, 2026 19:22
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.

Add unit tests for core engines

1 participant