Webhook lab
Prove behavior with deterministic tests
Executable checks prove verify HMAC signature + timestamp skew ≤ 5m; enqueue idempotent by event_id on fixtures — including the known misshape behind HOOK-SIG-OFF-16.
1Try it yourself
Decision drill
Webhook lab
Webhooks push events — polling pulls. Verify signatures before acting.
1/3Nightly index job finished.
2Learn the idea
Read
Schema and policy checks
Add executable validation at the trust boundaries of FastAPI receiver for batch-index completion events → durable queue. Reject unknown fields where they matter, bound string sizes, and coerce only after auth/signature checks when raw bytes are security-relevant. Invariant under test: verify HMAC signature + timestamp skew ≤ 5m; enqueue idempotent by event_id. A TypeScript type or Python annotation is not runtime validation — pair them with parsers.
Read
Golden and adversarial fixtures
Automate the fixtures from setup, including a recreation of HOOK-SIG-OFF-16. Assert both the visible error and the absence of side effects (no provider call, no queue write, no flag flip). Where metrics matter, assert label enums stay bounded.
Read
Implementation artifact
with pytest.raises(HTTPException):
receive(forged_request, body)
Read
Gate semantics
Document which failures are client mistakes (4xx) versus operator/config mistakes (5xx/503). Oracle still stands: valid event → 202 + one queue message; replay same event_id → 202 no duplicate work. Validation should make accidental “success with empty body” impossible for indexer worker waiting on provider batch.completed callbacks.
Read
Stage depth
Property ideas: shuffled field order, Unicode edges, maximum-length strings, and replayed timestamps. Where money, identity, or citations matter, assertion messages should cite the field name. Do not snapshot entire provider payloads in tests; assert semantically. If validation fails open “to keep the demo working,” you have inverted the lab. Tie at least one CI job to the HOOK-SIG-OFF-16 fixture so main cannot regress silently. Re-read verify HMAC signature + timestamp skew ≤ 5m; enqueue idempotent by event_id after each new parser — convenience helpers love to bypass it.
Read
Field notes for `webhook-lab` / `validation`
Table-drive status codes and error codes so reviewers see coverage at a glance. Include a Unicode normalization case if user text is accepted. Verify that oversized bodies fail before CPU-heavy work. Where digests or versions are pinned, assert mismatch behavior. Keep golden files small enough to read in review. CI should fail on skipped tests that mark the incident fixture as xfail without a ticket link. In this chapter the product is FastAPI receiver for batch-index completion events → durable queue, the human stakeholder is indexer worker waiting on provider batch.completed callbacks, and the incident id you design against is HOOK-SIG-OFF-16. Re-state the oracle in your notes — valid event → 202 + one queue message; replay same event_id → 202 no duplicate work — and keep the invariant visible: verify HMAC signature + timestamp skew ≤ 5m; enqueue idempotent by event_id. Track webhook_accept_total and duplicate_suppressed_total as the scoreboard. Surface under change control: POST /webhooks/batch-index. If you only have forty minutes, finish the fixture for signature optional in staging config accidentally shipped to prod before polishing UI. Promotion language stays ternary: promote, hold, or roll back based on evidence, not hope.
Go deeper
Before you start
Why this matters
List three fixtures: one golden success, one schema/auth reject, and one regression for HOOK-SIG-OFF-16. For each, write the exact assertion (status, code, metric, or citation) that must turn red if broken.
Related lessons
Check your understanding
Page assessment
Answer from memory. Completion is saved from this evidence, not from opening the next page.
All responses are required.