Skip to content

Systematic test coverage expansion: 13% → 55-60% #252

@smithrashell

Description

@smithrashell

Context

Overall Jest test coverage is 13.5% (50 test files, 793 tests). Core services like problemService (79%) and sessionService (73%) are decent, but huge gaps exist:

Target: 55-60% overall, with 75%+ on critical business logic.

Scope: Jest unit tests only. The browser integration tests (core-business-tests.js) are complementary and remain unchanged.


Phase 1 — Critical Algorithms (13% → 25-28%)

Locks down the session assembly pipeline, enrichment fix, normalizer, and schedule service.

1.1 problemNormalizerHelpers.test.js (~14 tests)

Source: src/shared/services/problem/problemNormalizerHelpers.js (93 lines, ~0%) → target 90%

  • Pure functions, no mocks needed
  • buildSessionMetadata, buildAttemptTracking, buildSpacedRepetitionData, buildAttemptsArray, etc.

1.2 problemServiceHelpers.test.js (~28 tests)

Source: src/shared/services/problem/problemServiceHelpers.js (127 lines, 21%) → target 85%

  • enrichReviewProblem — validates the enrichment fix from the difficulty crash
  • normalizeReviewProblem — slug fallback chain, attempt_stats conversion
  • filterValidReviewProblems — validates required fields

1.3 problemNormalizer.test.js (~24 tests)

Source: src/shared/services/problem/problemNormalizer.js (221 lines, 61%) → target 85%

  • validateRawProblem — missing difficulty (the bug), missing tags, non-numeric id
  • normalizeProblem — id coercion, title case, metadata flags
  • normalizeProblems — array validation, error wrapping with index

1.4 scheduleService.test.js (~20 tests)

Source: src/shared/services/schedule/scheduleService.js (138 lines, 3%) → target 70%

  • isDueForReview — date boundaries
  • isRecentlyAttempted — box-level skip intervals, relaxation
  • getDailyReviewSchedule — sorting, limits, error handling

1.5 problemServiceSession.test.js (~50 tests)

Source: src/shared/services/problem/problemServiceSession.js (590 lines, 45%) → target 80%

  • addTriggeredReviewsToSession — validates enrichment fix, max 2 per session
  • addFallbackProblems — validates enrichment + difficulty/tags filtering fix
  • addReviewProblemsToSession, addNewProblemsToSession, addPassiveMasteredReviews
  • deduplicateById, problemSortingCriteria

Phase 2 — Data Layer & Resilience (25-28% → 38-42%)

2.1 problems.test.js (~25 tests) — src/shared/db/stores/problems.js

2.2 standard_problems.test.js (~15 tests) — src/shared/db/stores/standard_problems.js

2.3 tag_mastery.test.js (~22 tests) — src/shared/db/stores/tag_mastery.js

2.4 attempts.test.js (~16 tests) — src/shared/db/stores/attempts.js

2.5 storageService.enhanced.test.js (~22 tests) — src/shared/services/storage/storageService.js (12% → 60%)

2.6 indexedDBRetryService.test.js (~25 tests) — circuit breaker, exponential backoff, abort controller


Phase 3 — Session Features (38-42% → 48-53%)

3.1 recalibrationService.test.js (~30 tests) — decay logic, diagnostic sessions, welcome-back strategy

3.2 sessionHabitLearning.test.js (~25 tests) — streaks, cadence, circuit breaker

3.3 interviewService.test.js (~28 tests) — mode configs, readiness assessment, transfer metrics

3.4 problemServiceRetry.test.js (~18 tests) — retry wrappers, abort controller cancellation


Phase 4 — Monitoring & Infrastructure (48-53% → 55-60%)

4.1 recalibrationHelpers.test.js (~12 tests)

4.2 crashReporter.test.js (~10 tests)

4.3 ErrorReportService.test.js (~10 tests)

4.4 PerformanceMonitor.test.js (~10 tests)

4.5 logger.test.js (~8 tests)

4.6 problem_relationships.enhanced.test.js (~12 tests)


Coverage Projection

Phase New Files New Tests Cumulative Coverage
Phase 1 5 ~136 25-28%
Phase 2 6 ~125 38-42%
Phase 3 4 ~101 48-53%
Phase 4 6 ~62 55-60%
Total 21 ~424 55-60%

Shared Infrastructure

  • Extend mockDataFactories.js with createMockReviewProblem, createMockStandardProblem, createMockAttemptWithStats
  • Create dbTestHelper.js in Phase 2 for fake-indexeddb schema setup and seeding

Implementation Order (Phase 1)

  1. problemNormalizerHelpers.test.js — pure functions, zero mocks, fast start
  2. problemServiceHelpers.test.js — validates enrichment fix
  3. problemNormalizer.test.js — validates the validation layer
  4. scheduleService.test.js — small file, pure scheduling logic
  5. problemServiceSession.test.js — largest, depends on understanding helpers

Verification

After each phase:

  1. npm run test:coverage — confirm cumulative coverage meets phase target
  2. npm test — all existing + new tests pass
  3. Verify no cross-phase test dependencies

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions