test(gateway): fix google_chat env-config tests under py3.11 + xdist (8/N)#14
Open
Bartok9 wants to merge 1 commit into
Open
test(gateway): fix google_chat env-config tests under py3.11 + xdist (8/N)#14Bartok9 wants to merge 1 commit into
Bartok9 wants to merge 1 commit into
Conversation
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>
🔎 Lint report:
|
| 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to the green-up series (#6–#12). The 6
tests/gateway/test_google_chat.py::TestEnvConfigLoadingtests still failunder the CI matrix (Python 3.11,
pytest -n auto) after #12.#12 correctly fixed a Python 3.12+ enum attribute-access path
(
Platform.GOOGLE_CHATraisingAttributeError). But under Python 3.11 thefailure 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 distinctmodule object from the
plugins.platforms.google_chat.adaptercopy the testmodule shims to
GOOGLE_CHAT_AVAILABLE=Trueat 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 cantrigger 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. Itscheck_fn(
_check_for_registry, gated onGOOGLE_CHAT_AVAILABLE) then returnsFalse,load_gateway_config()silently skips the platform, andcfg.platforms[Platform.GOOGLE_CHAT]raisesKeyError.I confirmed this by reproducing the CI matrix locally (uv-built Python
3.11.15 venv,
.[all,dev],-n auto) and instrumenting the silent enablepass:
check_fn=False,avail=Trueon the shimmed copy, but the check_fn's__module__washermes_plugins.google_chat_platform.adapterwith its ownGOOGLE_CHAT_AVAILABLE=False.Fix
Add an autouse fixture that forces
GOOGLE_CHAT_AVAILABLE=Trueon everyloaded 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
mainunder Python 3.11-n auto(CI config).tests/gateway/test_google_chat.pypasses in isolation (153 passed).-n autoruns (×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.pythat setsGOOGLE_CHAT_AVAILABLE = Trueon every loaded Google Chatadaptermodule insys.modulesbefore each test.This fixes flaky
TestEnvConfigLoadingfailures under Python 3.11 andpytest -n auto: plugin discovery can cache a second adapter import (hermes_plugins.google_chat_platform.adapter) with the flag stillFalsein CI, soload_gateway_config()skips Google Chat and tests hitKeyErroroncfg.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.