antigravity-sdk-python icon indicating copy to clipboard operation
antigravity-sdk-python copied to clipboard

bug: test suite flakiness, missing optional import guard in otel_test, and mcp 2.x breaking changes

Open iamameerhamza opened this issue 3 months ago • 1 comments

Problem Description

Running pytest on a standard environment reveals a few test stability and compatibility issues:

  1. LiteRT Logging Test Flakiness:
    • LiteRTConnectionTest.test_litert_logging_defaults_to_silent in google/antigravity/connections/local/litert_connection_test.py fails if the root logger or environment has DEBUG level active. _configure_litert_logging() evaluates is_debug == True and calls set_min_log_severity(1) instead of set_min_log_severity(1000).
  2. Missing Import Guard in OpenTelemetry Tests:
    • google/antigravity/utils/otel_test.py imports opentelemetry.sdk at the top level without an import guard. Since opentelemetry-sdk is an optional dependency ([project.optional-dependencies] otel), pytest crashes during collection on base installs.
  3. Pytest Collection Warnings:
    • TestWebSocket and TestLocalHarness in google/antigravity/connections/local/test_utils.py trigger PytestCollectionWarning because their names start with Test and define __init__ constructors.
  4. MCP 2.0 Compatibility:
    • mcp 2.0.0 restructured internal submodules (from mcp.server.fastmcp import FastMCP moved to mcp.server.mcpserver). pyproject.toml pins mcp>=1.0 without an upper bound cap, causing example scripts to crash when mcp 2.0 is installed.
  5. Websocket Deprecation Warning:
    • Direct access to e.code in local_connection.py triggers DeprecationWarning: ConnectionClosed.code is deprecated; use Protocol.close_code or ConnectionClosed.rcvd.code under websockets>=13.1.

Environment

  • Python: 3.10+
  • pytest: 9.x
  • websockets: 13.x+

Suggested Fixes

  • litert_connection_test.py: Isolate logging.getLogger inside test_litert_logging_defaults_to_silent.
  • otel_test.py: Add pytest.importorskip("opentelemetry.sdk") at module level.
  • test_utils.py: Set __test__ = False on helper classes TestWebSocket and TestLocalHarness.
  • pyproject.toml & mcp_server.py: Pin mcp>=1.0,<2 in pyproject.toml and add fallback imports for FastMCP.
  • local_connection.py: Safely retrieve close_code via getattr(e, "rcvd", None) before falling back to e.code.

iamameerhamza avatar Aug 17 '26 01:08 iamameerhamza

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.getLogger mock in test_litert_logging_defaults_to_silent to prevent test flakiness when global debug logging is active.
  • OpenTelemetry Tests: Added a pytest.importorskip("opentelemetry.sdk") guard in google/antigravity/utils/otel_test.py to prevent test collection crashes on installations without optional dependencies.
  • Test Helpers: Added __test__ = False to TestWebSocket and TestLocalHarness in google/antigravity/connections/local/test_utils.py to eliminate PytestCollectionWarnings.
  • WebSockets Compatibility: Updated google/antigravity/connections/local/local_connection.py to safely inspect e.rcvd.code before falling back to e.code, avoiding deprecation warnings on websockets>=13.1.
  • MCP 2.x Forward Compatibility: Pinned mcp>=1.0,<2 in pyproject.toml and added a dynamic import fallback for FastMCP submodules in examples/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!

iamameerhamza avatar Aug 17 '26 01:08 iamameerhamza