Skip to content

test: add unit tests for health module (#334)#347

Merged
Wirasm merged 2 commits into
mainfrom
kild/334-health-tests
Feb 11, 2026
Merged

test: add unit tests for health module (#334)#347
Wirasm merged 2 commits into
mainfrom
kild/334-health-tests

Conversation

@Wirasm

@Wirasm Wirasm commented Feb 11, 2026

Copy link
Copy Markdown
Owner

Summary

  • Health module had 537 lines across 3 files with zero test coverage
  • Added 24 unit tests covering all pure logic and filesystem persistence functions
  • Refactored storage functions to accept &Path for testability (public API unchanged)

Changes

File Change
crates/kild-core/src/health/operations.rs Added 14 tests: calculate_health_status (9), enrich_session_with_health (3), aggregate_health_stats (2)
crates/kild-core/src/health/storage.rs Added save_snapshot_to, load_history_from, cleanup_old_history_in internal variants + 10 tests for snapshot conversion, round-trip storage, cleanup, and date filtering

Testing

  • cargo test -p kild-core -- health — 24 new tests pass
  • cargo test --all — 146 tests pass, no regressions
  • cargo clippy --all -- -D warnings — clean
  • cargo fmt --check — clean

Validation

cargo test -p kild-core -- health && cargo clippy --all -- -D warnings && cargo fmt --check

Issue

Fixes #334

The health module had 537 lines of code with zero test coverage.
This adds 24 tests covering health status calculation, session
enrichment, aggregation, snapshot storage, and history cleanup.

Refactors storage functions to accept &Path parameter for testability
with tempfile::TempDir, keeping public API unchanged.

Fixes #334
@Wirasm

Wirasm commented Feb 11, 2026

Copy link
Copy Markdown
Owner Author

Self Code Review

Summary

Solid test-only PR that adds 24 unit tests covering all business logic in the health module (operations.rs + storage.rs). No behavioral changes.

Findings

Strengths

  • Covers all 3 public functions in operations.rs and all storage operations in storage.rs
  • Good edge case coverage: corrupted files, nonexistent dirs, empty inputs, boundary conditions
  • Clean refactoring: save_snapshot_to/load_history_from/cleanup_old_history_in variants follow established testability pattern
  • Uses tempfile::TempDir for filesystem isolation and Session::new_for_test helper
  • Time-based tests use 200min offsets to avoid races with parallel test execution on global AtomicU64 threshold

Scope notes (non-blocking)

  • handler.rs (94 lines) is intentionally not tested — it's pure orchestration calling sessions::handler, process, and config, which would require integration-level mocking for minimal value

Security

  • No security concerns — test-only changes with no production behavior changes

Checklist

  • Fix addresses root cause (zero test coverage → 24 tests)
  • Code follows codebase patterns
  • Tests cover the change
  • No bugs introduced (no production code behavior changes)

@Wirasm Wirasm merged commit ac0f048 into main Feb 11, 2026
6 checks passed
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.

chore: health module has zero test coverage (529 lines)

1 participant