You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ci(python-unit): narrow the driver preload; isolate the MCP user ContextVar
Addresses the first CI run and a three-lens cross-model review.
CI: the parallel step ran in 14m07s on the 4-core runners with one failure,
tests/unit_tests/mcp_service/test_middleware_logging.py (`assert 1 == 42`).
That is a leaked ContextVar, not xdist: sync tests that call
`_setup_user_context()` (test_gauge_chart's resource path resolves a real
user, id 1; six test_auth_user_resolution tests leave mocks) set
`_mcp_user_id_var` in the thread's base context and never clear it, and
pytest-asyncio copies that context into every later async test's task.
`on_call_tool`'s `finally` then overrides the patched user id with the leaked
one. It passed serially only because test_mcp_e2e_smoke sorts between leaker
and victim and exercises the real middleware, whose `finally` resets the var;
`loadfile` put that file on another worker. A per-test reset fixture in
tests/unit_tests/mcp_service/conftest.py scopes the var to each test.
Control: gauge -> middleware_logging in one process reproduces the exact
failure without the fixture and passes with it.
Review (unanimous across lenses): the session-wide `load_engine_specs()`
preload was the wrong seam -- full discovery, including third-party entry
points, in every worker and both serial coverage gates, and importing
Superset's ClickHouse spec before any app exists caches `product_name="dev"`
for the session. Narrowed to pre-importing only `clickhouse_connect`, the
third-party module that actually reads the clock at import; engine-spec
discovery itself stays lazy, so tests that exercise it still see a cold
state. Seven unit-test files combine freeze_time with engine-spec
resolution, so a narrow autouse preload beats per-test opt-in. A direct pin
of the preload's contract is added. Also from review: docstring opening line
and deferred-import justification per the constitution; explicit annotations
on the tuple constants; `--durations=0` so the pre-existing `--durations-min`
actually emits a report (it only filters an enabled one) -- which immediately
shows the critical path under loadfile: one 68s test and ~15s of
module-scoped app setup per file; and a note on `--maxfail` semantics.
Local full run, 8 workers, coverage on: 15,128 passed in 3m36s.
Co-Authored-By: Claude Code <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EA4MGEkUcDpyLReqjQBhPy
0 commit comments