Skip to content

Stream broker responses through and add pytest coverage#126

Merged
adamcohenhillel merged 2 commits into
mainfrom
feat/broker-streaming-and-tests
Jul 6, 2026
Merged

Stream broker responses through and add pytest coverage#126
adamcohenhillel merged 2 commits into
mainfrom
feat/broker-streaming-and-tests

Conversation

@adamcohenhillel

Copy link
Copy Markdown
Contributor

Summary

  • The model broker now detects streaming requests (Accept: text/event-stream or "stream": true in the JSON payload) and relays the upstream body chunk-by-chunk with a read1() loop and per-chunk flushes, mirroring the upstream Content-Type and closing the connection to delimit the response. Auth, rate-limit, model-allowlist, and privacy checks still run before any bytes are proxied; the non-streaming path is unchanged.
  • New pytest suite at services/model-broker/tests/ covering signed-token expiry and bit-flipped tampering, wrong HMAC key versions, device-attestation clock-skew boundaries (inside vs outside the accept window), rate limiter concurrency (16 threads hammering allow(), exactly max_events admitted) and stale-key eviction, admin/static token compare_digest paths, and adversarial count_input_images payloads.
  • CI's repo-checks job now installs pytest and runs the suite; the broker smoke test gained an SSE case that asserts chunks arrive incrementally rather than as one buffered response.

Closes #81
Closes #87

Test plan

  • ./scripts/check.sh passes locally (includes the broker smoke test with the new streaming case)
  • python3 -m pytest services/model-broker/tests -q — 39 passed
  • CI green on this PR

🤖 Generated with Claude Code

adamcohenhillel and others added 2 commits July 5, 2026 18:07
Detect streaming requests via Accept: text/event-stream or "stream": true
and relay the upstream body chunk-by-chunk with per-chunk flushes, closing
the connection to delimit the response. Auth, rate-limit, and privacy
checks still run before proxying; the smoke test now covers an SSE case
against the fake provider and asserts chunks arrive incrementally.

Closes #81

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Cover signed-token expiry and tampering, wrong HMAC key versions, device
attestation clock-skew boundaries, rate limiter concurrency and stale-key
eviction, admin/static token compare_digest paths, and adversarial
count_input_images payloads. Wire the suite into the repo-checks CI job.

Closes #87

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@vercel

vercel Bot commented Jul 6, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
openphone-docs Ready Ready Preview, Comment Jul 6, 2026 1:09am

Request Review

@adamcohenhillel adamcohenhillel merged commit ca22c32 into main Jul 6, 2026
3 checks passed
@adamcohenhillel adamcohenhillel deleted the feat/broker-streaming-and-tests branch July 6, 2026 22:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add pytest coverage for broker auth/token/attestation/limits Broker: stream responses through instead of buffering the full body

1 participant