[08/10] refactor: separate weather adapters - #99
Conversation
📝 WalkthroughWalkthroughThis PR organizes weather contracts, provider adapters, composition, document conversion, and reference data under ChangesWeather package extraction
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
|
/agentic_review |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #99 +/- ##
========================================
Coverage 99.81% 99.82%
========================================
Files 76 86 +10
Lines 9358 9470 +112
Branches 554 563 +9
========================================
+ Hits 9341 9453 +112
Misses 12 12
Partials 5 5 ☔ View full report in Codecov by Harness. |
Code Review by Qodo
1. QWeather JSON unchecked
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
PR Summary by QodoRefactor weather providers into dedicated weather package with compat exports
AI Description
Diagram
High-Level Assessment
Files changed (19)
|
|
Code review by qodo was updated up to the latest commit 3a9f3a0 |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
weather_briefing/weather/open_meteo.py (1)
26-26: 🩺 Stability & Availability | 🔵 Trivial | 💤 Low valueDocument the Open-Meteo reference-data warm-up.
The module imports and calls
open_meteo_weather_code_descriptions(), so a missing/malformedopen_meteo_weather_codes.jsoncan raiseReferenceDataErrorbefore any Open-Meteo provider is used. Add a short comment on line 26 stating this is intentional fail-fast reference-data validation.🤖 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 `@weather_briefing/weather/open_meteo.py` at line 26, Add a short comment immediately above the module-level call to open_meteo_weather_code_descriptions() explaining that it intentionally warms up and fail-fast validates the Open-Meteo reference data before provider use, allowing missing or malformed data to raise ReferenceDataError during import.
🤖 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.
Inline comments:
In `@weather_briefing/weather/base.py`:
- Around line 78-84: Update the WeatherContextError handling around the logger
call to stop passing exc as the reason value, which implicitly logs its
provider-supplied message. Replace it with a stable, non-sensitive error
category while preserving the existing provider name and duration fields.
---
Nitpick comments:
In `@weather_briefing/weather/open_meteo.py`:
- Line 26: Add a short comment immediately above the module-level call to
open_meteo_weather_code_descriptions() explaining that it intentionally warms up
and fail-fast validates the Open-Meteo reference data before provider use,
allowing missing or malformed data to raise ReferenceDataError during import.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 46c1ab66-d7bd-4c76-918a-16bde8c1a53f
📒 Files selected for processing (19)
tests/test_capabilities.pytests/test_languages.pytests/test_reference_data.pytests/test_regional_weather.pytests/test_weather_context.pyweather_briefing/capabilities.pyweather_briefing/reference_data.pyweather_briefing/regional_weather.pyweather_briefing/weather/__init__.pyweather_briefing/weather/base.pyweather_briefing/weather/composition.pyweather_briefing/weather/documents.pyweather_briefing/weather/jma.pyweather_briefing/weather/nea.pyweather_briefing/weather/open_meteo.pyweather_briefing/weather/open_meteo_reference.pyweather_briefing/weather/qweather.pyweather_briefing/weather/regional_errors.pyweather_briefing/weather_context.py
b6983cc to
4b0c1a8
Compare
3a9f3a0 to
1b67126
Compare
0a6e946 to
a5dbf7c
Compare
|
/agentic_review |
1b67126 to
c16e5b2
Compare
|
Code review by qodo was updated up to the latest commit c16e5b2 |
|
/agentic_review |
|
Code review by qodo was updated up to the latest commit c16e5b2 |
|
/agentic_review |
|
Code review by qodo was updated up to the latest commit 35d616f |
|
/agentic_review |
|
Code review by qodo was updated up to the latest commit b9c7d30 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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.
Inline comments:
In `@tests/test_weather_context.py`:
- Around line 663-694: Update
test_open_meteo_current_enrichment_rejects_non_object_payload to use neutral
synthetic coordinates, preferably the existing fixture values 1 and 2, when
calling _fetch_air_quality_and_allergen; leave the mocked payload and assertions
unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: ac74aa74-6f3f-4285-92c4-52340bb4d801
📒 Files selected for processing (19)
tests/test_capabilities.pytests/test_languages.pytests/test_reference_data.pytests/test_regional_weather.pytests/test_weather_context.pyweather_briefing/capabilities.pyweather_briefing/reference_data.pyweather_briefing/regional_weather.pyweather_briefing/weather/__init__.pyweather_briefing/weather/base.pyweather_briefing/weather/composition.pyweather_briefing/weather/documents.pyweather_briefing/weather/jma.pyweather_briefing/weather/nea.pyweather_briefing/weather/open_meteo.pyweather_briefing/weather/open_meteo_reference.pyweather_briefing/weather/qweather.pyweather_briefing/weather/regional_errors.pyweather_briefing/weather_context.py
🚧 Files skipped from review as they are similar to previous changes (15)
- weather_briefing/weather/open_meteo_reference.py
- tests/test_languages.py
- weather_briefing/weather/init.py
- weather_briefing/regional_weather.py
- weather_briefing/weather/composition.py
- weather_briefing/weather/documents.py
- weather_briefing/weather/regional_errors.py
- tests/test_reference_data.py
- tests/test_regional_weather.py
- weather_briefing/weather/jma.py
- weather_briefing/weather/nea.py
- weather_briefing/weather/base.py
- weather_briefing/weather_context.py
- weather_briefing/weather/qweather.py
- weather_briefing/weather/open_meteo.py
| @pytest.mark.parametrize( | ||
| ("payload", "reason"), | ||
| ( | ||
| ([], "air-quality response must be an object"), | ||
| ({"current": []}, "current air quality must be an object"), | ||
| ), | ||
| ) | ||
| async def test_open_meteo_current_enrichment_rejects_non_object_payload( | ||
| caplog, | ||
| payload: object, | ||
| reason: str, | ||
| ) -> None: | ||
| async with httpx.AsyncClient( | ||
| transport=httpx.MockTransport(lambda request: httpx.Response(200, json=payload)) | ||
| ) as client: | ||
| provider = OpenMeteoProvider( | ||
| client, | ||
| air_quality_base_url="https://air.example.invalid", | ||
| ) | ||
|
|
||
| with caplog.at_level("WARNING", logger="weather_briefing.weather_context"): | ||
| air_quality, allergen = await provider._fetch_air_quality_and_allergen( | ||
| 39.9, | ||
| 116.3, | ||
| forecast_date=None, | ||
| ) | ||
|
|
||
| assert air_quality is None | ||
| assert allergen is None | ||
| assert f"operation=air-quality reason={reason}" in caplog.text | ||
|
|
||
|
|
There was a problem hiding this comment.
🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win
Use synthetic coordinates in the mocked test.
The test passes the real location 39.9, 116.3, although the mocked response does not depend on geography. Replace it with neutral fixture values such as the existing 1, 2 inputs.
As per coding guidelines, “Never commit real credentials, locations, coordinates, private source URLs, generated content, or runtime state; use runtime configuration, ignored state paths, and public test data.”
🤖 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 663 - 694, Update
test_open_meteo_current_enrichment_rejects_non_object_payload to use neutral
synthetic coordinates, preferably the existing fixture values 1 and 2, when
calling _fetch_air_quality_and_allergen; leave the mocked payload and assertions
unchanged.
Source: Coding guidelines
|
Code review by qodo was updated up to the latest commit b9c7d30 |
Summary
Dependency
Based on #95 because weather metadata migration follows the delivery-owned reference split. Merge as step 08 after #95.
Verification
prek run --all-filesSummary by CodeRabbit
New Features
Compatibility