test(mcp): stay connected until the SSE reply ends; drop cross-context reset
CI / lint (push) Successful in 2s
CI / integration (push) Successful in 37s
CI / unit (push) Successful in 1m0s
CI / publish (push) Successful in 57s

The test client reported http.disconnect as soon as the request body was
read, and the SDK's SSE response cancels its stream on disconnect, so
tools/list came back 200 with an empty body. Model a real client: wait
for the response (with a 15s deadline), then disconnect.

The caller fixture reset its ContextVar from sync teardown, a different
context from the async test that set it; each async test already runs in
its own context copy, so the reset is dropped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-06 07:25:23 -04:00
co-authored by Claude Opus 5.5
parent 3984f639e8
commit 970adf41e7
2 changed files with 19 additions and 8 deletions
+5 -6
View File
@@ -26,13 +26,12 @@ OPERATOR = Caller(user_id="u1", username="ana", role=UserRole.operator, token_id
@pytest.fixture
def as_caller():
tokens = []
# Each async test runs in its own task, i.e. a copy of the context, so a
# caller set here can't leak into another test; resetting from the sync
# teardown would fail ("created in a different Context").
def _set(caller):
tokens.append(_context._caller_ctx.set(caller))
yield _set
for t in reversed(tokens):
_context._caller_ctx.reset(t)
_context._caller_ctx.set(caller)
return _set
def _server(plugins_cfg=None):