Skip to content

test: expand coverage and harden regression checks - #12

Merged
IceCodeNew merged 3 commits into
masterfrom
test/coverage
Jul 14, 2026
Merged

test: expand coverage and harden regression checks#12
IceCodeNew merged 3 commits into
masterfrom
test/coverage

Conversation

@IceCodeNew

@IceCodeNew IceCodeNew commented Jul 14, 2026

Copy link
Copy Markdown
Owner

Summary

  • expand coverage across air quality, CLI, configuration, geocoding, reference data, service, time utilities, and weather context behavior
  • make the unknown-feed forecast regression test depend on the actual classification outcome
  • make the Nominatim rate-limit test deterministic by isolating its monotonic clock
  • autosquash review corrections into the commits that introduced the affected tests

Why

The added coverage exercises remaining validation and guardrail paths. Review found that one service test could pass without proving the intended forecast classification and that one timing assertion depended on real scheduler latency. These changes make both tests behavior-sensitive and deterministic.

Validation

  • full test suite at each rewritten commit snapshot
  • final test suite: 301 passed
  • ruff check .
  • prek run --all-files
  • git diff --check

Summary by CodeRabbit

  • Tests
    • Expanded coverage for air-quality parsing, guidance validation, and missing observation times.
    • Added geocoding tests for retries, rate limits, caching, API errors, and location precision handling.
    • Added validation tests for invalid coordinates, reference data, timestamps, forecasts, and oversized briefings.
    • Added coverage for provider failures, malformed weather data, missing air-quality details, and precision-reduced location alerts.

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Expanded regression coverage for malformed reference data, air-quality and weather parsing, geocoding providers, caching, configuration, service validation, datetime parsing, and precision-reduced location alerts.

Changes

Robustness Regression Coverage

Layer / File(s) Summary
Air-quality parsing and guidance validation
tests/test_air_quality.py
Tests missing AQICN timestamps, invalid guidance-band structures and bounds, and selection of the required unbounded final band.
Geocoding providers, caching, and geography rules
tests/test_geocoding.py
Covers API response validation, retries, rate limiting, precision reduction, cache handling, directory creation, and geography reference-data validation.
Weather provider and snapshot parsing
tests/test_weather_context.py
Tests provider failures, API-key propagation, optional documents, and malformed forecast, lifestyle, and air-quality payloads.
CLI, service, and configuration validation
tests/test_cli.py, tests/test_config.py, tests/test_service.py
Validates precision-reduced location alerts, coordinate errors, briefing length limits, and unknown-feed filtering.
Reference-data and datetime validation
tests/test_reference_data.py, tests/test_time_utils.py
Tests rejection of non-object reference data and date-only parser results where datetimes are required.

Estimated code review effort: 4 (Complex) | ~45 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the change set: expanded test coverage and stronger regression checks.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/coverage

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.98271% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 99.17%. Comparing base (76c20c9) to head (74cde09).
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
tests/test_weather_context.py 95.12% 5 Missing and 3 partials ⚠️
tests/test_geocoding.py 96.42% 3 Missing and 2 partials ⚠️
tests/test_cli.py 99.61% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #12      +/-   ##
==========================================
+ Coverage   94.60%   99.17%   +4.56%     
==========================================
  Files          34       34              
  Lines        3170     3862     +692     
  Branches      201      232      +31     
==========================================
+ Hits         2999     3830     +831     
+ Misses        123       21     -102     
+ Partials       48       11      -37     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@IceCodeNew
IceCodeNew marked this pull request as ready for review July 14, 2026 02:49
@IceCodeNew
IceCodeNew requested a review from Copilot July 14, 2026 02:49

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR expands the automated test suite across multiple subsystems (weather context providers, air quality, CLI wiring, configuration validation, geocoding behavior, reference data loading, time parsing, and service behavior) to better exercise validation/guardrail paths and to harden previously flaky regression checks.

Changes:

  • Added comprehensive negative/edge-case tests for QWeather/Open-Meteo weather context and AQICN air quality parsing/validation.
  • Hardened determinism in tests by isolating monotonic timing for Nominatim rate-limit behavior and making the unknown-feed forecast regression behavior-sensitive.
  • Expanded coverage for configuration and time utility parsing error paths, plus CLI provider-building and run/daemon behavior.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/test_weather_context.py Adds extensive coverage for QWeather/Open-Meteo success and failure paths, plus snapshot document conversion behavior.
tests/test_time_utils.py Adds tests ensuring parsing helpers reject non-datetime parse results.
tests/test_service.py Adds service-level regression tests (briefing size validation, unknown-feed forecast behavior).
tests/test_reference_data.py Adds coverage for invalid reference data root types and cache clearing behavior.
tests/test_geocoding.py Adds coverage for Open-Meteo API key passing, Nominatim behaviors (rate limiting, invalid responses), precision reduction, caching, and mainland-China reference rules validation.
tests/test_config.py Adds configuration validation test for non-numeric coordinates in locations file.
tests/test_cli.py Adds tests for CLI construction helpers, weather provider selection/config validation, run/daemon behavior, and alerting on precision reduction.
tests/test_air_quality.py Adds AQICN observed-at edge cases and validates air-quality guidance/reference-data validation behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@IceCodeNew
IceCodeNew merged commit 9dfbe76 into master Jul 14, 2026
21 of 22 checks passed
@IceCodeNew
IceCodeNew deleted the test/coverage branch July 14, 2026 02:53

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
tests/test_weather_context.py (1)

556-589: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Extract the repeated QWeather payload boilerplate into a shared fixture/helper.

The same ~20-line weather-forecast JSON blob and {"code": "200", "daily": []} indices payload are copy-pasted verbatim across roughly a dozen new tests in this range. A small helper (e.g. _qweather_weather_response(fx_link=None) / a module-level constant) that each handler reuses would cut this duplication drastically and make future payload-shape changes a one-line edit instead of a dozen.

♻️ Example helper
_QWEATHER_DAILY_ITEM = {
    "fxDate": "2026-07-13",
    "textDay": "晴",
    "textNight": "晴",
    "tempMin": "20",
    "tempMax": "30",
    "windDirDay": "南风",
    "windScaleDay": "3-4",
    "humidity": "60",
    "precip": "0.0",
}


def _qweather_weather_response(*, fx_link: str | None = None) -> httpx.Response:
    payload = {"code": "200", "updateTime": "2026-07-13T08:00", "daily": [_QWEATHER_DAILY_ITEM]}
    if fx_link:
        payload["fxLink"] = fx_link
    return httpx.Response(200, json=payload)

Also applies to: 717-755, 758-816, 818-859, 898-932, 935-985, 988-1043, 1046-1103, 1106-1163, 1166-1223, 1226-1283

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/test_weather_context.py` around lines 556 - 589, Extract the duplicated
QWeather forecast payload and successful indices payload used across the
affected tests into module-level shared fixtures or helpers, such as a
daily-item constant and weather-response helper supporting optional fxLink.
Update each handler in the listed test ranges, including
test_qweather_rejects_non_success_indices_status, to reuse them while preserving
each test’s request-specific behavior and response status.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@tests/test_weather_context.py`:
- Around line 556-589: Extract the duplicated QWeather forecast payload and
successful indices payload used across the affected tests into module-level
shared fixtures or helpers, such as a daily-item constant and weather-response
helper supporting optional fxLink. Update each handler in the listed test
ranges, including test_qweather_rejects_non_success_indices_status, to reuse
them while preserving each test’s request-specific behavior and response status.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 239c46eb-61d8-4e2e-ad42-5a6a41a1cf93

📥 Commits

Reviewing files that changed from the base of the PR and between ed0207b and 74cde09.

📒 Files selected for processing (8)
  • tests/test_air_quality.py
  • tests/test_cli.py
  • tests/test_config.py
  • tests/test_geocoding.py
  • tests/test_reference_data.py
  • tests/test_service.py
  • tests/test_time_utils.py
  • tests/test_weather_context.py

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.

2 participants