Skip to content

test:improving test coverage for corpus server app

Vaishnavi requested to merge test/streak into test_cases

Title (semantic) refactor(streak-service): fix combined streak calculation and add 100% test coverage

Description

This merge request refactors and tests the StreakService module.

Changes:

 1. Bug fix — `_calculate_combined_streak`: Removed invalid .distinct() call on CompoundSelect. UNION already deduplicates
    rows, so .distinct() was redundant and caused an AttributeError at runtime.

 2. SQLAlchemy deprecation fix: Replaced direct .c access on Select objects with explicit .subquery() calls to align with
    SQLAlchemy 2.0 conventions.

 3. New test file: Added tests/unit/services/test_streak_service.py with 24 unit tests covering:
    - Empty streak data structure
    - Streak calculation from date lists (single, consecutive, non-consecutive, multiple streaks)
    - Current streak computation (today, yesterday, broken streak)
    - Longest streak computation
    - Contributions, edits, and combined streak methods
    - Daily activity counts retrieval

 4. pyproject.toml: Added filterwarnings to suppress Pydantic deprecation noise in test output.

Result: streak_service.py now has 100% test coverage (112 statements, 0 missed), all 24 tests pass with zero warnings.

Checklist

 - [x] Code has been refactored for clarity, maintainability, or performance.
 - [x] No functional changes have been introduced.
 - [x] All existing tests are passing.
 - [x] Code adheres to project coding standards.

Related Issue(s)

Closes #109

Merge request reports

Loading