test: add transport-wiring regression tests for #459#485
Conversation
The existing test_client_limits_respect_max_parallel_requests only checks the limits property, which was always computed correctly even before the fix. Add mock-capture tests that patch HTTPTransport and AsyncHTTPTransport constructors, trigger lazy init via completion() / acompletion(), and assert the constructors received the correct limits. These tests fail on the pre-fix code (assert_called_once fails because the old code never explicitly constructed the transport). Made-with: Cursor
Greptile SummaryThis PR adds two targeted regression tests ( The mock wiring is correct: the innermost
|
| Filename | Overview |
|---|---|
| packages/data-designer-engine/tests/engine/models/clients/test_native_http_clients.py | Adds two new transport-wiring regression tests and parametrizes the existing limits unit test; logic and mock ordering are correct, with one minor style inconsistency in decorator ordering. |
Sequence Diagram
sequenceDiagram
participant Test
participant patch_Transport as @patch(HTTPTransport)
participant patch_Client as @patch(httpx.Client)
participant HttpModelClient
participant mock_Transport as mock_transport_cls (MagicMock)
participant RetryTransport
participant mock_Client as mock_client_cls.return_value
Test->>HttpModelClient: client_factory(max_parallel_requests=300)
Note over HttpModelClient: _limits = Limits(max_connections=600, max_keepalive_connections=300)
Test->>HttpModelClient: client.completion(request)
HttpModelClient->>HttpModelClient: _get_sync_client()
HttpModelClient->>patch_Transport: HTTPTransport(limits=self._limits)
patch_Transport-->>HttpModelClient: mock_Transport
HttpModelClient->>RetryTransport: create_retry_transport(config, transport=mock_Transport)
RetryTransport-->>HttpModelClient: retry_transport
HttpModelClient->>patch_Client: httpx.Client(transport=retry_transport, timeout=...)
patch_Client-->>HttpModelClient: mock_client_cls.return_value
HttpModelClient->>mock_Client: client.post(url, ...)
mock_Client-->>HttpModelClient: mock_httpx_response
Test->>patch_Transport: assert_called_once()
Test->>patch_Transport: call_args.kwargs["limits"].max_connections == 600
Test->>patch_Transport: call_args.kwargs["limits"].max_keepalive_connections == 300
Prompt To Fix All With AI
This is a comment left during a code review.
Path: packages/data-designer-engine/tests/engine/models/clients/test_native_http_clients.py
Line: 311-319
Comment:
**Duplicate case list for sync/async**
`_SYNC_TRANSPORT_WIRING_CASES` and `_ASYNC_TRANSPORT_WIRING_CASES` are byte-for-byte identical. They can be unified into a single constant (e.g. `_TRANSPORT_WIRING_CASES`) and reused by both tests, keeping the file easier to maintain.
```suggestion
_TRANSPORT_WIRING_CASES = [
pytest.param(_make_openai_client, _OPENAI_MODEL, _make_openai_chat_response(), id="openai"),
pytest.param(_make_anthropic_client, _ANTHROPIC_MODEL, _make_anthropic_chat_response(), id="anthropic"),
]
```
Then reference `_TRANSPORT_WIRING_CASES` in both `@pytest.mark.parametrize` calls.
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: packages/data-designer-engine/tests/engine/models/clients/test_native_http_clients.py
Line: 366-371
Comment:
**`@pytest.mark.asyncio` placement inconsistent with rest of file**
All other async tests in this file place `@pytest.mark.asyncio` as the outermost (or second-outermost after `@pytest.mark.parametrize`) decorator. Here it is sandwiched inside the `@patch` decorators. While it works — `functools.wraps` propagates `pytestmark` through the `@patch` wrapper — the inconsistency makes the decorator stack harder to scan and could silently break if the project ever switches to `pytest-asyncio` strict mode without `functools.wraps` propagation.
The standard, consistent ordering (matching the rest of the file) would be:
```suggestion
@pytest.mark.parametrize(("client_factory", "model_name", "response_json"), _ASYNC_TRANSPORT_WIRING_CASES)
@pytest.mark.asyncio
@patch(_ASYNC_HTTP_TRANSPORT_PATCH)
@patch(_ASYNC_CLIENT_PATCH)
async def test_async_pool_limits_forwarded_to_transport(
```
The mock argument order (`mock_client_cls` first, `mock_transport_cls` second) is unaffected by moving `@pytest.mark.asyncio` outside the `@patch` decorators.
How can I resolve this? If you propose a fix, please make it concise.Reviews (3): Last reviewed commit: "Merge branch 'main' into nmulepati/fix/4..." | Re-trigger Greptile
|
@nabinchha Nice idea for these tests — verifying the transport wiring is exactly the gap in coverage for #459. A couple of issues with the current approach though: The tests will fail on the current production code. Both new tests patch
So This means one of two things needs to happen:
mock_client_cls.assert_called_once()
limits = mock_client_cls.call_args.kwargs["limits"]
assert limits.max_connections == 600
assert limits.max_keepalive_connections == 300This wouldn't prove the limits are effective (same underlying httpx issue), but it would be a passing test that catches computation regressions. Option 1 is the more complete fix. Two smaller notes:
|
Parametrize all three #459 regression tests over both OpenAICompatibleClient and AnthropicClient (wiring lives in HttpModelClient, so both subclasses need coverage). Use the existing _make_openai_client / _make_anthropic_client helpers with **kwargs instead of constructing clients directly. Move transport patch constants up with the other module-level constants. Made-with: Cursor
|
@johnnygreco Thanks for the review! Addressed your feedback in 02ccff3. Re: "The tests will fail on the current production code" — the production code does already construct Re: parametrize over AnthropicClient — done. All three regression tests now parametrize over both Re: use Also moved the transport patch constants ( |
📋 Summary
Adds the missing regression tests for #459 / #460 that verify the actual transport wiring, not just the
limitsproperty computation. Follow-up from nabinchha's review on #460.🔄 Changes
🧪 Tests
test_sync_pool_limits_forwarded_to_transport— patcheshttpx.HTTPTransport, triggers lazy init viacompletion(), asserts the constructor receivedlimits.max_connections == 600andlimits.max_keepalive_connections == 300. Fails on pre-fix code becauseHTTPTransportwas never explicitly constructed.test_async_pool_limits_forwarded_to_transport— same pattern for async: patchesAsyncHTTPTransport, triggers viaacompletion().test_client_limits_respect_max_parallel_requestskept as a unit check for thelimitsproperty computation.Context
The existing test (
test_client_limits_respect_max_parallel_requests) only assertsclient.limits.max_connections == 600, which readsself._limits— a value that was computed correctly even before the #460 fix. It passes on both the old and new code, providing no regression protection. The new tests use a mock-capture approach (per nabinchha's review suggestion) that patches the transport constructors and verifies the wiring without touching any private API.🤖 Generated with AI
Made with Cursor