Files
karaoke-gen/backend/tests/fixtures/encoding
Andrew Beveridge ☄️andClaude Opus 4.8 ed7c6006be Incident hardening: encode→publish seam test + typed contract + guard discipline (T1/P3/P1/P2) (#986)
Part 2 of 3 of the **Incident hardening (post-NOMAD-1632)** initiative
(plan: `docs/archive/2026-09-12-incident-hardening-plan.md`). Both
incident bugs lived in the **encode→publish seam**, yet no test composed
the *real* `GCEEncodingBackend.encode()` with the *real* orchestrator —
so green mocked unit tests gave false confidence in both directions.

## T1 — composed encode→publish seam integration test
New `TestEncodePublishSeam` in
`backend/tests/test_video_worker_orchestrator.py` runs the **real**
backend through the **real** orchestrator `_run_encoding`, patching only
the network boundary (`encode_videos`) and storage. Asserts all four
shapes:
- **empty** `output_files` → completeness guard does **NOT** trip →
orchestrator downloads 0 → raises "stale" → **re-encodes** and recovers
(the Failure-B path the original fix broke);
- **partial** (720p missing) → guard trips → job fails loud (the
Failure-A defense);
- **complete** → success, all result attrs populated (uses the
NOMAD-1632 "Portrait of Jennie" title so the 720p classifies correctly);
- **malformed** (stray/wrong-extension names) → classified out, treated
as empty (no mis-slotting, no crash).

## P3 — kill mock drift: fixtures + typed contract
- Golden fixtures under `backend/tests/fixtures/encoding/`
(`success`/`cached`/`empty`/`partial`/`malformed`) + README.
- Typed `GceEncodeResponse` (TypedDict) in `encoding_interface.py`,
shared by producer (`EncodingService.encode_videos`) and consumer
(`GCEEncodingBackend.encode`) — type-only import, no runtime cost/cycle.
- `backend/tests/test_encoding_contract.py` replays every fixture
through `classify_encoded_output` / `encode()` and validates the schema.
The "empty" shape that hid Failure B is now in the corpus.

## P1/P2 — process docs
`docs/TESTING.md`: **"New Guard / New Enforcement Checklist"**
(recoverable ≠ wrong, fail-open on uncertainty, test
empty/partial/malformed/complete, shadow-first, composed integration
test) and a **"Critical-Path Change Tier"** note + blameless post-mortem
template.

## Tests
`138 passed` locally — new seam tests + contract tests + existing
orchestrator/interface regression. No behavior change to app code (typed
annotation only).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-09-12 21:48:55 +00:00
..

GCE encode worker — golden response fixtures

Real-shaped responses returned by the GCE encoding worker's encode_videos (the value GCEEncodingBackend.encode() consumes), captured/authored as golden JSON so the encode→publish seam is tested against the actual contract rather than hand-authored per-test mocks. Each conforms to the GceEncodeResponse TypedDict in backend/services/encoding_interface.py.

Fixture Shape What it exercises
success.json complete, all 4 requested formats Happy path. Uses the NOMAD-1632 title ("Portrait of Jennie") so classification must key off the trailing format tag, not the title text.
cached.json complete, full set incl. portrait/with-vocals/title/end/CDG A cached hit returning every additive final; exercises every classifier branch.
empty.json complete, output_files: [] Stale/cached-but-deleted job. Must be treated as recoverable (re-encode), NOT a partial/defective result. This shape caused Failure B.
partial.json complete, missing mp4_720p Failure A: the completeness guard must trip and refuse to publish.
malformed.json complete, stray / wrong-extension names Nothing classifies into a slot → treated as empty (not crash, not mis-slotted).

Replayed by backend/tests/test_encoding_contract.py (contract test) and driven through the real orchestrator by TestEncodePublishSeam in backend/tests/test_video_worker_orchestrator.py.