Skip to content

test: fix CLI test typing errors - #15

Merged
IceCodeNew merged 4 commits into
masterfrom
fix/ty-err
Jul 14, 2026
Merged

test: fix CLI test typing errors#15
IceCodeNew merged 4 commits into
masterfrom
fix/ty-err

Conversation

@IceCodeNew

@IceCodeNew IceCodeNew commented Jul 14, 2026

Copy link
Copy Markdown
Owner

Summary

  • expose the OpenAI-compatible provider base URL through a read-only property for adapter-specific assertions
  • use an AnyIO async client fixture for provider factories while letting CLI run tests own their client lifecycle
  • replace SimpleNamespace-based Settings fakes with real dataclass instances built via dataclasses.replace

Why

The CLI tests passed structurally similar objects where provider factories require concrete Settings and httpx.AsyncClient values. Adapter tests also inspected a private field on a value returned as the general LLMProvider protocol. These changes make the tests satisfy the real boundaries without casts or broader production typing, and ensure each test client is closed exactly once by its owning async context.

Validation

  • 312 tests passed with branch coverage enabled
  • focused CLI tests passed with ResourceWarning promoted to an error
  • ty, Ruff, and all prek hooks passed
  • coverage did not decrease: lines changed from 4060/4079 on master to 4062/4081; branches remain 471/482

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

CLI tests now use a shared httpx.AsyncClient fixture and real typed Settings instances. Provider tests were rewired to the shared client, and the LLM provider exposes its configured base_url.

Changes

CLI test migration

Layer / File(s) Summary
Settings and async client fixtures
tests/test_cli.py, weather_briefing/llm.py
Centralized test settings now produce typed Settings objects, a shared async client fixture manages HTTP clients, and the LLM provider exposes base_url.
CLI run flow tests
tests/test_cli.py
Run tests now use LocationSpec settings, injected async clients, and resolver cache-state results.
Provider construction tests
tests/test_cli.py
LLM, delivery, weather-context, weather-provider, and AQICN tests now use the shared async client and public provider attributes.

Estimated code review effort: 3 (Moderate) | ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: fixing CLI and provider test typing issues.
✨ 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 fix/ty-err

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

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.26%. Comparing base (236575f) to head (12e63fe).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master      #15   +/-   ##
=======================================
  Coverage   99.26%   99.26%           
=======================================
  Files          34       34           
  Lines        4079     4081    +2     
  Branches      241      241           
=======================================
+ Hits         4049     4051    +2     
  Misses         19       19           
  Partials       11       11           

☔ 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.

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 updates the CLI/provider test scaffolding to satisfy stricter typing (Settings dataclass instances and concrete httpx.AsyncClient), and exposes the OpenAI-compatible provider base URL so tests no longer need to inspect private state.

Changes:

  • Expose base_url on OpenAICompatibleChatCompletionsProvider and use it when constructing the request URL.
  • Narrow the CLI LLM provider factory typing and adjust imports accordingly.
  • Refactor CLI tests to build real Settings instances via dataclasses.replace and introduce an httpx.AsyncClient-typed test double.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
weather_briefing/llm.py Makes provider base URL accessible and uses it when constructing the chat completions endpoint.
weather_briefing/cli.py Updates the LLM provider factory typing/imports in support of the provider/test changes.
tests/test_cli.py Replaces structural fakes with real Settings instances and a typed httpx.AsyncClient test double; updates assertions to use base_url.

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

Comment thread weather_briefing/cli.py Outdated
Comment thread tests/test_cli.py Outdated

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread weather_briefing/llm.py
Expose the endpoint on the OpenAI-compatible adapter while keeping the provider factory typed to the general LLMProvider protocol. Adapter-focused tests narrow the returned value before inspecting the endpoint.
Use a real httpx.AsyncClient in provider factory tests and close it during fixture teardown. This satisfies the factory annotations without relying on casts or leaking client resources.
Replace the SimpleNamespace-based _make_fake_settings with a
module-level _DEFAULT_SETTINGS constant and dataclasses.replace().
Parameters are explicitly typed; locations uses tuple[LocationSpec, ...]
instead of Any. Three integration tests refactored to put LocationSpec
in settings.locations and return pre-made ResolvedLocation from the
resolver.

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

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

@IceCodeNew
IceCodeNew marked this pull request as ready for review July 14, 2026 07:05
@IceCodeNew IceCodeNew changed the title Fix ty errors in CLI tests test: fix CLI test typing errors Jul 14, 2026

@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_cli.py (1)

381-387: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

async_client teardown relies on httpx's internal close-state guard rather than an idiomatic async fixture.

The async with httpx.AsyncClient(...) as client: block inside run() (see weather_briefing/cli.py) will transition the shared fixture client to its closed state during the test itself when httpx.AsyncClient is monkeypatched to return async_client. The teardown's asyncio.run(client.aclose()) then runs a second, effectively no-op close (httpx guards against re-closing) in a brand-new event loop. This works today, but it depends on an implementation detail of httpx.AsyncClient (idempotent aclose() / "cannot reopen once closed" state machine) rather than a documented public contract, and it doesn't match idiomatic pytest-asyncio fixture patterns already used elsewhere in this suite (the file already has native async def test_... functions).

Since the project clearly already supports async tests, a plain async generator fixture would be more idiomatic and avoid coupling to httpx internals:

♻️ Suggested idiomatic async fixture
-@pytest.fixture
-def async_client() -> Iterator[httpx.AsyncClient]:
-    client = httpx.AsyncClient()
-    try:
-        yield client
-    finally:
-        asyncio.run(client.aclose())
+@pytest.fixture
+async def async_client() -> AsyncIterator[httpx.AsyncClient]:
+    async with httpx.AsyncClient() as client:
+        yield client

Please confirm the pytest-asyncio mode (asyncio_mode) configured for this project (e.g., in pyproject.toml/pytest.ini/conftest.py) supports plain @pytest.fixture async generators, since that determines whether this simplification is a drop-in change.

🤖 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_cli.py` around lines 381 - 387, Update the async_client fixture to
use an async generator with async def and await client.aclose() in teardown,
matching the suite’s existing native async tests. Before applying this change,
verify the project’s pytest-asyncio asyncio_mode configuration supports plain
`@pytest.fixture` async generators; preserve the fixture’s shared
httpx.AsyncClient behavior used by the CLI tests.
🤖 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_cli.py`:
- Around line 381-387: Update the async_client fixture to use an async generator
with async def and await client.aclose() in teardown, matching the suite’s
existing native async tests. Before applying this change, verify the project’s
pytest-asyncio asyncio_mode configuration supports plain `@pytest.fixture` async
generators; preserve the fixture’s shared httpx.AsyncClient behavior used by the
CLI tests.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 90cf7eb7-a8a0-41ce-9a9f-a19ae388e466

📥 Commits

Reviewing files that changed from the base of the PR and between 4367619 and f9a3ca3.

📒 Files selected for processing (2)
  • tests/test_cli.py
  • weather_briefing/llm.py

Use an AnyIO async fixture for provider factory tests and let CLI run tests construct their own clients. Each client is now closed exactly once by the context that owns it.
@IceCodeNew

Copy link
Copy Markdown
Owner Author

Addressed the async client lifecycle review in 12e63fe. Provider factory tests now use an AnyIO async fixture, while CLI run tests let run() construct and close its own client, so no client is closed twice. Validation: 57 focused tests passed with ResourceWarning treated as an error, all 312 tests passed with branch coverage, and ty, Ruff, and prek passed.

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

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

@IceCodeNew
IceCodeNew merged commit 8f74d10 into master Jul 14, 2026
22 checks passed
@IceCodeNew
IceCodeNew deleted the fix/ty-err branch July 14, 2026 07:27
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