h3-python-sdk-e2e-battery-43-43
The due-cycle E2E (tick #93, window #88-93, closing #98 non-deferrable) requires the canonical harness — a /tmp uvicorn runner composing FastAPI + create_router(EchoHarness()) + add_middleware on <ip-address>:8777 — not the example app (examples/echo_app.py) which binds :8000 under __main__. Two real bugs were found and fixed while standing this up.
1. Canonical runner (/tmp/echo_harness_runner.py) — uvicorn target, binds 8777:
from fastapi import FastAPI
from h3_shim import EchoHarness, add_harness_middleware, create_router
app = FastAPI(title="echo-harness-canonical")
app.include_router(create_router(EchoHarness()))
add_harness_middleware(app)
2. Fix A — HEAD/OPTIONS were 405. FastAPI 0.141 / Starlette 1.4 does not auto-register HEAD/OPTIONS on GET-only routes (verified empirically: 405, allow: GET). The canonical create_router must declare them explicitly; per-path OPTIONS return real Allow headers:
router.add_api_route("/health", h.health, methods=["GET", "HEAD"]) # HEAD on every GET
...
options_routes = {"/echo/echo": "GET, HEAD, POST, OPTIONS", "/echo/echo/raw": "GET, HEAD, POST, PUT, DELETE, OPTIONS", ...}
def make_options(allow: str) -> Callable[[], Response]:
async def handler() -> Response:
return Response(status_code=200, headers={"allow": allow})
return handler
for path, allow in options_routes.items():
router.add_api_route(path, make_options(allow), methods=["OPTIONS"])
3. Fix B — no catch-all OPTIONS route. A /{rest:path} OPTIONS catch-all partially matches unknown paths and turns their 404s into 405s (broke unknown route 404 and middleware covers 404s). Explicit per-path routes keep 404 semantics intact.
4. Middleware contract (in add_harness_middleware): every response gets X-Request-ID (honoring an incoming id, idempotent retries), X-Served-By: echo-harness, and X-Process-Time — including error responses (500/404).
5. Lifecycle (shim venv at /tmp/h3-shim-venv, SDK installed editable):
cd /tmp
setsid nohup /tmp/h3-shim-venv/bin/uvicorn echo_harness_runner:app \
--host <ip-address> --port 8777 --log-level warning > /tmp/uvicorn_8777.log &
sleep 3 && ss -ltnp | grep 8777 # verify listening
/tmp/h3-shim-venv/bin/h3-test --endpoint http://<ip-address>:8777 --json
fuser -k 8777/tcp && sleep 1 && ss -ltnp | grep 8777 || echo "port 8777 FREE"
h3-test runs the 43-test battery (ping/health/version, GET/POST/raw echo round-trips incl. unicode/binary/10k, status codes 204-503, 404/405/422 semantics, latency 5/25ms, meta/client-host, header passthrough, HEAD/OPTIONS, middleware coverage, post↔get integrity) and exits 0 only on 43/43.
Actual run against the live canonical harness (`<ip-address>:8777`, uvicorn pid 319):
```
h3-python-sdk-e2e-battery-43-43 -> http://<ip-address>:8777
[PASS] ping returns pong ... (43 lines) ...
[PASS] post/get round-trip integrity
43/43 PASS 0.07s (p50 0.63ms p95 6.05ms)
exit=0
```
Edge cases tested, all verified:
- **Repeat stability:** 3 sequential runs → `43/43 PASS` each (p50 0.55–1.13ms, p95 5.58–6.39ms).
- **Concurrency:** 3 parallel `h3-test` runs → 3× `43/43 PASS` (p95 ~26ms under load, no flake).
- **Wrong endpoint** `:8778` → `[ERROR] cannot reach ... Connection refused`, exit code 2 (graceful).
- **Trailing slash** `--endpoint http://<ip-address>:8777/` → normalized, 43/43 PASS.
- **Middleware on errors:** 500 response carries `x-request-id`, `x-served-by`, `x-process-time`.
- **Harness kill + port free:** `fuser -k 8777/tcp` → `port 8777 FREE`, probe refused, 0 uvicorn procs. Port 8000 (example-app port) untouched — pre-existing host service, never bound by this E2E.
- Artifacts: `/tmp/echo_harness_runner.py`, `/tmp/h3-python-sdk/` (pyproject + `h3_shim/{__init__,harness,e2e,cli}.py` + `examples/echo_app.py`), `/tmp/h3-shim-venv/bin/h3-test`.{"model": "deepseek-v4-flash", "problem_class": "h3-python-sdk-e2e-battery-43-43", "result": "passed", "tests": 43}