Files
odysseus/tests/test_stream_disconnect_middleware.py
T
pewdiepie-archdaemonandClaude Opus 5.5 364229f2dc feat(harness): authority, turn contract, tools, clean_agent_preview
Chat/agent harness work: request-authority model, turn contract, tool
policy/parsing/execution, clean_agent_preview streaming/thinking, ask_user
persistence, session probes, and scheduler.

Source: vendor/photocraft (ad1cff44) harness files, 3-way merged onto
upstream/dev (a8c147b2). Harness core files were independently developed
in both lineages; resolution policy documented in pr_work/C_conflicts.md
(vendor kept where ahead, upstream kept where vendor is behind; full delta
preserved in pr_work/C_upstream_delta.patch).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 13:41:53 +00:00

34 lines
1.1 KiB
Python

"""Health audit: SSE client disconnects (e.g. /api/editor/bridge/events) surface
as anyio.EndOfStream through Starlette's BaseHTTPMiddleware. The slow-request
middleware must map that to a client-side 499, not a logged 500 traceback."""
import asyncio
import anyio
from starlette.requests import Request
from app import _SlowRequestLogMiddleware
def _request(path):
return Request({"type": "http", "method": "GET", "path": path, "headers": []})
def test_stream_disconnect_is_mapped_to_499():
async def call_next(_request):
raise anyio.EndOfStream
mw = _SlowRequestLogMiddleware(lambda *a: None)
resp = asyncio.run(mw.dispatch(_request("/api/editor/bridge/events"), call_next))
assert resp.status_code == 499
def test_real_responses_pass_through():
from starlette.responses import JSONResponse
async def call_next(_request):
return JSONResponse({"ok": True}, status_code=200)
mw = _SlowRequestLogMiddleware(lambda *a: None)
resp = asyncio.run(mw.dispatch(_request("/api/health"), call_next))
assert resp.status_code == 200