Skip to content

test(gateway): accept arbitrary kwargs in _install_fake_aiohttp to absorb trust_env - #27329

Closed
briandevans wants to merge 1 commit into
NousResearch:mainfrom
briandevans:fix/test-fake-aiohttp-trust-env-kwarg
Closed

test(gateway): accept arbitrary kwargs in _install_fake_aiohttp to absorb trust_env#27329
briandevans wants to merge 1 commit into
NousResearch:mainfrom
briandevans:fix/test-fake-aiohttp-trust-env-kwarg

Conversation

@briandevans

Copy link
Copy Markdown
Contributor

Summary

Widen the _install_fake_aiohttp helper lambdas in tests/gateway/test_google_chat.py and tests/gateway/test_teams.py to accept arbitrary keyword arguments. Currently four tests in TestGoogleChatStandaloneSend and TestTeamsStandaloneSend fail on every PR's CI run with TypeError: 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 production aiohttp.ClientSession(...) calls in both adapters:

  • plugins/platforms/google_chat/adapter.py:3249async with _aiohttp.ClientSession(timeout=..., trust_env=True)
  • plugins/platforms/teams/adapter.py:569async with _aiohttp.ClientSession(trust_env=True)

The fake aiohttp.ClientSession defined inside _install_fake_aiohttp in each test file is lambda timeout=None: session — it accepts only the timeout kwarg. When production now also passes trust_env=True, the lambda raises TypeError. The adapters catch the error in their broad try/except and surface it as the assertion mismatch in the CI log:

{'error': 'Google Chat standalone send failed: '
          '_install_fake_aiohttp.<locals>.<lambda>() got an unexpected keyword '
          "argument 'trust_env'"}

Failing tests (all four reproduce on clean origin/main):

  • tests/gateway/test_google_chat.py::TestGoogleChatStandaloneSend::test_standalone_send_refreshes_token_and_posts_message
  • tests/gateway/test_google_chat.py::TestGoogleChatStandaloneSend::test_standalone_send_propagates_api_failure
  • tests/gateway/test_teams.py::TestTeamsStandaloneSend::test_standalone_send_acquires_token_and_posts_activity
  • tests/gateway/test_teams.py::TestTeamsStandaloneSend::test_standalone_send_propagates_token_failure

The fix

Change both helper lambdas to accept and ignore arbitrary args/kwargs:

ClientSession=lambda *args, **kwargs: session,
ClientTimeout=lambda *args, **kwargs: None,

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

  • Confirmed c1ae18ee8 lands trust_env=True in both adapters on current origin/main.
  • Confirmed only tests/gateway/test_google_chat.py and tests/gateway/test_teams.py define a _install_fake_aiohttp helper of this shape (rg "fake_aiohttp|ClientSession=lambda" tests/ finds no other call sites).
  • Verified all 6 call sites in both files pass exactly (monkeypatch, session) — no caller depends on the lambda signature shape.
  • CI repro on every recent PR (e.g. #27316 run 25983241078) — four _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-pubsub and googleapiclient, so the test hits service_account is None before reaching the lambda. The fix is verifiable by inspection: a lambda with *args, **kwargs accepts every shape (timeout=...) was previously called with, plus the new (trust_env=...) call.

Related

  • Production change: c1ae18ee8 (merged in #27308)
  • SMS and Slack adapters also gained trust_env=True in the same commit but neither has a _install_fake_aiohttp helper of this shape, so no companion fix is needed for them.

…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>
Copilot AI review requested due to automatic review settings May 17, 2026 07:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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, **kwargs in fake ClientSession lambda.
  • Accept *args, **kwargs in fake ClientTimeout lambda.

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.

@alt-glitch alt-glitch added type/test Test coverage or test infrastructure P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery labels May 17, 2026
@cardtest15-coder

This comment was marked as spam.

@briandevans

Copy link
Copy Markdown
Contributor Author

CI audit — the four trust_env failures this PR targets (TestGoogleChatStandaloneSend::test_standalone_send_refreshes_token_and_posts_message, ::test_standalone_send_propagates_api_failure, TestTeamsStandaloneSend::test_standalone_send_acquires_token_and_posts_activity, ::test_standalone_send_propagates_token_failure) all pass in this run. The 14 remaining failures are pre-existing baselines unrelated to this PR's scope (tests/gateway/test_google_chat.py, tests/gateway/test_teams.py).

10 reproduce on clean origin/main at 519657aa9 with identical error text; 2 are CI-only (PermissionError on /root/.hermes/... which only triggers under root); 2 (test_transcription_dotenv_fallback) fail identically across other open PRs and don't reproduce locally — environment artifact, not in this diff.

Test Symptom Root cause on main
tests/acp/test_registry_manifest.py::test_agent_json_version_matches_pyproject '0.13.0' == '0.14.0' plugins/acp/manifest/agent.json version field lags pyproject.toml bump to 0.14.0
tests/acp/test_registry_manifest.py::test_agent_json_pins_uvx_package_to_pyproject_version 'hermes-agent[acp]==0.13.0' == '...==0.14.0' same manifest staleness
tests/gateway/test_background_command.py::TestRunBackgroundTask::test_telegram_dm_topic_completion_preserves_reply_anchor_metadata {'direct_message...} == {'telegram_dm...} metadata-key shape mismatch after recent reply-anchor refactor
tests/gateway/test_telegram_thread_fallback.py::test_gateway_runner_busy_ack_replies_to_triggering_message_for_telegram_dm_topic same same
tests/gateway/test_voice_command.py::TestSendVoiceReply::test_auto_voice_reply_uses_thread_metadata_helper same same
tests/hermes_cli/test_model_switch_custom_providers.py::test_list_groups_same_name_custom_providers_into_one_row hardcoded model list diverges from current catalog catalog grew but test expectations weren't refreshed
tests/hermes_cli/test_startup_plugin_gating.py::test_builtin_set_covers_every_registered_subcommand _BUILTIN_SUBCOMMANDS is missing ['send'] send subcommand was registered without being added to hermes_cli/main.py::_BUILTIN_SUBCOMMANDS
tests/run_agent/test_deepseek_reasoning_content_echo.py::TestNeedsKimiToolReasoning::test_non_kimi_provider assert True is False _needs_kimi_tool_reasoning heuristic widened past test's expectations
tests/run_agent/test_provider_parity.py::TestAuxiliaryClientProviderPriority::test_openrouter_always_wins 'google/gemini-2.5-flash' == 'google/gemini-2.5-flash-preview' OpenRouter default model id moved; assertion not refreshed
tests/tools/test_voice_cli_integration.py::TestVprintForceParameter::test_error_messages_use_force_in_run_agent Expected at least one _vprint with force=True for error messages run_agent.py error-message branch no longer routes through _vprint(..., force=True)
tests/hermes_cli/test_gateway_service.py::TestSystemUnitHermesHome::test_system_unit_uses_target_user_home_not_calling_user PermissionError: '/root/.hermes/node/bin' CI-only — test attempts a real mkdir outside HERMES_HOME when running as root
tests/hermes_cli/test_gateway_service.py::TestSystemUnitHermesHome::test_system_unit_remaps_profile_to_target_user PermissionError: '/root/.hermes/profiles/coder/node/bin' same
tests/tools/test_transcription_dotenv_fallback.py::TestProviderSelectionGate::test_explicit_xai_sees_dotenv 'none' == 'xai' passes locally on clean origin/main; CI-only environment difference (not in this PR's scope)
tests/tools/test_transcription_dotenv_fallback.py::TestEndToEndRegressionGuard::test_xai_key_only_in_dotenv_before_fix assert False is True same — passes locally on clean origin/main

Local repro command:

uv run --python 3.11 --with pytest --with pytest-xdist --with pytest-asyncio python3 -m pytest <test_path> -v

@briandevans

Copy link
Copy Markdown
Contributor Author

Closing — teknium1 landed the same fix directly on main as 06924e8 (test(gateway): accept trust_env in fake aiohttp ClientSession lambdas) on 2026-05-17. Thanks for picking it up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists type/test Test coverage or test infrastructure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants