antigravity-sdk-python
antigravity-sdk-python copied to clipboard
bug: test suite flakiness, missing optional import guard in otel_test, and mcp 2.x breaking changes
Problem Description
Running pytest on a standard environment reveals a few test stability and compatibility issues:
- LiteRT Logging Test Flakiness:
LiteRTConnectionTest.test_litert_logging_defaults_to_silentingoogle/antigravity/connections/local/litert_connection_test.pyfails if the root logger or environment hasDEBUGlevel active._configure_litert_logging()evaluatesis_debug == Trueand callsset_min_log_severity(1)instead ofset_min_log_severity(1000).
- Missing Import Guard in OpenTelemetry Tests:
google/antigravity/utils/otel_test.pyimportsopentelemetry.sdkat the top level without an import guard. Sinceopentelemetry-sdkis an optional dependency ([project.optional-dependencies] otel),pytestcrashes during collection on base installs.
- Pytest Collection Warnings:
TestWebSocketandTestLocalHarnessingoogle/antigravity/connections/local/test_utils.pytriggerPytestCollectionWarningbecause their names start withTestand define__init__constructors.
- MCP 2.0 Compatibility:
mcp 2.0.0restructured internal submodules (from mcp.server.fastmcp import FastMCPmoved tomcp.server.mcpserver).pyproject.tomlpinsmcp>=1.0without an upper bound cap, causing example scripts to crash whenmcp 2.0is installed.
- Websocket Deprecation Warning:
- Direct access to
e.codeinlocal_connection.pytriggersDeprecationWarning: ConnectionClosed.code is deprecated; use Protocol.close_code or ConnectionClosed.rcvd.codeunderwebsockets>=13.1.
- Direct access to
Environment
- Python: 3.10+
- pytest: 9.x
- websockets: 13.x+
Suggested Fixes
litert_connection_test.py: Isolatelogging.getLoggerinsidetest_litert_logging_defaults_to_silent.otel_test.py: Addpytest.importorskip("opentelemetry.sdk")at module level.test_utils.py: Set__test__ = Falseon helper classesTestWebSocketandTestLocalHarness.pyproject.toml&mcp_server.py: Pinmcp>=1.0,<2inpyproject.tomland add fallback imports forFastMCP.local_connection.py: Safely retrieveclose_codeviagetattr(e, "rcvd", None)before falling back toe.code.
Hi maintainers,
I investigated these issues and prepared a verified patch in my fork branch: https://github.com/iamameerhamza/antigravity-sdk-python/tree/fix-mcp-2x-examples
Summary of Fixes (Commit f28a2af)
- LiteRT Connection Test: Isolated
logging.getLoggermock intest_litert_logging_defaults_to_silentto prevent test flakiness when global debug logging is active. - OpenTelemetry Tests: Added a
pytest.importorskip("opentelemetry.sdk")guard ingoogle/antigravity/utils/otel_test.pyto prevent test collection crashes on installations without optional dependencies. - Test Helpers: Added
__test__ = FalsetoTestWebSocketandTestLocalHarnessingoogle/antigravity/connections/local/test_utils.pyto eliminatePytestCollectionWarnings. - WebSockets Compatibility: Updated
google/antigravity/connections/local/local_connection.pyto safely inspecte.rcvd.codebefore falling back toe.code, avoiding deprecation warnings onwebsockets>=13.1. - MCP 2.x Forward Compatibility: Pinned
mcp>=1.0,<2inpyproject.tomland added a dynamic import fallback forFastMCPsubmodules inexamples/resources/mcp_server.py.
Verification
Ran the test suite locally: 840 passed, 1 skipped, 0 failures.
Feel free to pull from this branch or let me know if you would like any adjustments!