test(gateway): accept arbitrary kwargs in _install_fake_aiohttp to absorb trust_env - #27329
test(gateway): accept arbitrary kwargs in _install_fake_aiohttp to absorb trust_env#27329briandevans wants to merge 1 commit into
Conversation
…sorb trust_env c1ae18e ("fix(gateway): add trust_env=True to aiohttp sessions in SMS, Slack, Teams, Google Chat adapters") added a trust_env=True keyword argument to the production aiohttp.ClientSession() call in both plugins/platforms/google_chat/adapter.py and plugins/platforms/teams/adapter.py. The test fakes in tests/gateway/test_google_chat.py and tests/gateway/test_teams.py define ClientSession as `lambda timeout=None: session` which only accepts the `timeout` kwarg. When the production code passes `trust_env=True`, the lambda errors with: TypeError: _install_fake_aiohttp.<locals>.<lambda>() got an unexpected keyword argument 'trust_env' Production swallows this in a broad except, returning the failure as a string in the result dict, which makes the four standalone_send tests fail with mismatched dict shapes. Widen the lambdas to `lambda *args, **kwargs: session` (and the same for ClientTimeout) so the helper is robust to future kwargs added to the production call sites. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Loosens the signatures of fake aiohttp.ClientSession and ClientTimeout constructors in two test helpers so they accept arbitrary positional and keyword arguments.
Changes:
- Accept
*args, **kwargsin fakeClientSessionlambda. - Accept
*args, **kwargsin fakeClientTimeoutlambda.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tests/gateway/test_teams.py | Make _install_fake_aiohttp tolerant of extra args. |
| tests/gateway/test_google_chat.py | Same change applied to Google Chat test helper. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This comment was marked as spam.
This comment was marked as spam.
|
CI audit — the four 10 reproduce on clean
Local repro command: |
|
Closing — teknium1 landed the same fix directly on main as 06924e8 ( |
Summary
Widen the
_install_fake_aiohttphelper lambdas intests/gateway/test_google_chat.pyandtests/gateway/test_teams.pyto accept arbitrary keyword arguments. Currently four tests inTestGoogleChatStandaloneSendandTestTeamsStandaloneSendfail on every PR's CI run withTypeError: lambda() got an unexpected keyword argument 'trust_env'.The bug
Commit c1ae18ee8 (
fix(gateway): add trust_env=True to aiohttp sessions in SMS, Slack, Teams, Google Chat adapters, merged 2026-05-17 via #27308) added a new keyword argument to the productionaiohttp.ClientSession(...)calls in both adapters:plugins/platforms/google_chat/adapter.py:3249—async with _aiohttp.ClientSession(timeout=..., trust_env=True)plugins/platforms/teams/adapter.py:569—async with _aiohttp.ClientSession(trust_env=True)The fake
aiohttp.ClientSessiondefined inside_install_fake_aiohttpin each test file islambda timeout=None: session— it accepts only thetimeoutkwarg. When production now also passestrust_env=True, the lambda raisesTypeError. The adapters catch the error in their broadtry/exceptand surface it as the assertion mismatch in the CI log:Failing tests (all four reproduce on clean
origin/main):tests/gateway/test_google_chat.py::TestGoogleChatStandaloneSend::test_standalone_send_refreshes_token_and_posts_messagetests/gateway/test_google_chat.py::TestGoogleChatStandaloneSend::test_standalone_send_propagates_api_failuretests/gateway/test_teams.py::TestTeamsStandaloneSend::test_standalone_send_acquires_token_and_posts_activitytests/gateway/test_teams.py::TestTeamsStandaloneSend::test_standalone_send_propagates_token_failureThe fix
Change both helper lambdas to accept and ignore arbitrary args/kwargs:
The fake's job is just to return the scripted session/timeout regardless of how the production code invokes it. This makes the helper resilient to future kwargs added to the production call sites without further test churn.
Test plan
c1ae18ee8landstrust_env=Truein both adapters on currentorigin/main.tests/gateway/test_google_chat.pyandtests/gateway/test_teams.pydefine a_install_fake_aiohttphelper of this shape (rg "fake_aiohttp|ClientSession=lambda" tests/finds no other call sites).(monkeypatch, session)— no caller depends on the lambda signature shape._install_fake_aiohttp.<locals>.<lambda>() got an unexpected keyword argument 'trust_env'failures.Local repro is partially blocked because my dev install lacks
google-cloud-pubsubandgoogleapiclient, so the test hitsservice_account is Nonebefore reaching the lambda. The fix is verifiable by inspection: a lambda with*args, **kwargsaccepts every shape(timeout=...)was previously called with, plus the new(trust_env=...)call.Related
trust_env=Truein the same commit but neither has a_install_fake_aiohttphelper of this shape, so no companion fix is needed for them.