Skip to content

test(gateway): fix google_chat env-config tests under py3.11 + xdist (8/N)#14

Open
Bartok9 wants to merge 1 commit into
mainfrom
fix/google-chat-1m-xdist-availability
Open

test(gateway): fix google_chat env-config tests under py3.11 + xdist (8/N)#14
Bartok9 wants to merge 1 commit into
mainfrom
fix/google-chat-1m-xdist-availability

Conversation

@Bartok9
Copy link
Copy Markdown
Owner

@Bartok9 Bartok9 commented May 30, 2026

Summary

Follow-up to the green-up series (#6#12). The 6
tests/gateway/test_google_chat.py::TestEnvConfigLoading tests still fail
under the CI matrix
(Python 3.11, pytest -n auto) after #12.

#12 correctly fixed a Python 3.12+ enum attribute-access path
(Platform.GOOGLE_CHAT raising AttributeError). But under Python 3.11 the
failure has a different root cause, so those 6 tests remained red on CI.

Root cause (3.11 + xdist)

The plugin loader imports the bundled adapter a second time under a
synthetic namespace hermes_plugins.google_chat_platform.adapter — a distinct
module object from the plugins.platforms.google_chat.adapter copy the test
module shims to GOOGLE_CHAT_AVAILABLE=True at import.

The synthetic copy reflects whether the real google.* libs are importable
(False in CI). Under -n auto, a sibling test in the same worker can
trigger plugin discovery — importing that synthetic copy with the flag False
before this module's google mocks are installed. The stale copy is cached,
so discover_plugins() won't re-exec it. Its check_fn
(_check_for_registry, gated on GOOGLE_CHAT_AVAILABLE) then returns False,
load_gateway_config() silently skips the platform, and
cfg.platforms[Platform.GOOGLE_CHAT] raises KeyError.

I confirmed this by reproducing the CI matrix locally (uv-built Python
3.11.15 venv, .[all,dev], -n auto) and instrumenting the silent enable
pass: check_fn=False, avail=True on the shimmed copy, but the check_fn's
__module__ was hermes_plugins.google_chat_platform.adapter with its own
GOOGLE_CHAT_AVAILABLE=False.

Fix

Add an autouse fixture that forces GOOGLE_CHAT_AVAILABLE=True on every
loaded google_chat adapter copy before each test, making enablement
independent of which copy discovery imported and of cross-module import
ordering. No production code changes.

Test plan

  • Reproduced the 6 failures on main under Python 3.11 -n auto (CI config).
  • With the fix, tests/gateway/test_google_chat.py passes in isolation (153 passed).
  • Full-suite -n auto runs (×2): 0 google_chat failures (deterministic).

Made with Cursor


Note

Low Risk
Test-only change; no runtime gateway or adapter behavior is modified.

Overview
Adds an autouse pytest fixture in tests/gateway/test_google_chat.py that sets GOOGLE_CHAT_AVAILABLE = True on every loaded Google Chat adapter module in sys.modules before each test.

This fixes flaky TestEnvConfigLoading failures under Python 3.11 and pytest -n auto: plugin discovery can cache a second adapter import (hermes_plugins.google_chat_platform.adapter) with the flag still False in CI, so load_gateway_config() skips Google Chat and tests hit KeyError on cfg.platforms[Platform.GOOGLE_CHAT]. No production code changes.

Reviewed by Cursor Bugbot for commit 01df913. Bugbot is set up for automated code reviews on this repo. Configure here.

The 6 TestEnvConfigLoading tests still failed under the CI matrix (Python
3.11, pytest -n auto) after #12. #12 fixed a Python 3.12+ enum *attribute
access* path (Platform.GOOGLE_CHAT), but the 3.11 failure has a different
root cause:

The plugin loader imports the bundled adapter a second time under a synthetic
namespace (hermes_plugins.google_chat_platform.adapter) — a distinct module
object from the plugins.platforms.google_chat.adapter copy this module shims
to GOOGLE_CHAT_AVAILABLE=True at import. The synthetic copy reflects whether
the real google libs are importable (False in CI). Under -n auto a sibling
test in the same worker can trigger discovery (importing that copy with the
flag False) before this module's google mocks are installed; the stale copy
is cached, so its check_fn (_check_for_registry, gated on the flag) returns
False and load_gateway_config silently skips the platform — making
cfg.platforms[Platform.GOOGLE_CHAT] raise KeyError.

Add an autouse fixture that forces GOOGLE_CHAT_AVAILABLE=True on every loaded
google_chat adapter copy before each test, so enablement is independent of
which copy discovery imported and of cross-module import ordering. Verified
green across repeated full-suite -n auto runs.

Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions
Copy link
Copy Markdown

🔎 Lint report: fix/google-chat-1m-xdist-availability vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 7750 on HEAD, 7749 on base (🆕 +1)

🆕 New issues (4):

Rule Count
invalid-argument-type 3
unresolved-attribute 1
First entries
run_agent.py:6649: [invalid-argument-type] invalid-argument-type: Argument to function `build_anthropic_client` is incorrect: Expected `str`, found `str | dict[Unknown | str, Unknown | str | dict[str, str]] | Any | ... omitted 3 union elements`
run_agent.py:12542: [invalid-argument-type] invalid-argument-type: Argument to function `len` is incorrect: Expected `Sized`, found `(str & ~AlwaysFalsy) | (dict[Unknown | str, Unknown | str | dict[str, str]] & ~AlwaysFalsy) | (Any & ~AlwaysFalsy) | ... omitted 3 union elements`
tests/gateway/test_google_chat.py:172: [unresolved-attribute] unresolved-attribute: Unresolved attribute `GOOGLE_CHAT_AVAILABLE` on type `ModuleType`
run_agent.py:12539: [invalid-argument-type] invalid-argument-type: Argument to function `_is_oauth_token` is incorrect: Expected `str`, found `str | dict[Unknown | str, Unknown | str | dict[str, str]] | Any | ... omitted 3 union elements`

✅ Fixed issues (3):

Rule Count
invalid-argument-type 3
First entries
run_agent.py:12542: [invalid-argument-type] invalid-argument-type: Argument to function `len` is incorrect: Expected `Sized`, found `(str & ~AlwaysFalsy) | (dict[Unknown, Unknown] & ~AlwaysFalsy) | (Any & ~AlwaysFalsy) | ... omitted 3 union elements`
run_agent.py:6649: [invalid-argument-type] invalid-argument-type: Argument to function `build_anthropic_client` is incorrect: Expected `str`, found `str | dict[Unknown, Unknown] | Any | ... omitted 3 union elements`
run_agent.py:12539: [invalid-argument-type] invalid-argument-type: Argument to function `_is_oauth_token` is incorrect: Expected `str`, found `str | dict[Unknown, Unknown] | Any | ... omitted 3 union elements`

Unchanged: 4075 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

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.

1 participant