Day 6:E2E Frontend-Backend Contract Testing for Streaming AI
Battle-tested daily lesson note • 100% runnable code, interview Q&A, test suite & interactive quiz
Day 6: E2E Frontend-Backend Contract Testing for Streaming AI
1. First-Principles Problem: Silent Streaming Contract Drift
In traditional REST APIs, contract testing with OpenAPI/Swagger catches schema mismatches during compilation.
In Streaming Generative UI (text/event-stream), contract drift is silent and catastrophic:
- If a backend engineer changes an SSE event payload from:
event: token\ndata: {"delta": "word"}to:event: token\ndata: {"text": "word"} - Standard HTTP status tests still pass with
200 OK. - In the browser, the chat UI silently stops displaying any text! The user sees an infinite pulsing cursor while tokens flow into a void.
2. End-to-End Contract Verification Suite
An E2E Contract Tester asserts that every SSE event emitted by the backend conforms to the exact JSON schema expected by the frontend parser:
In Simple English: Automated Streaming Contract Tests
Why do streaming chat apps break silently after tiny backend edits? Someone renames JSON field delta -> text or forgets data: [DONE]!
An E2E Streaming Contract Test parses every chunk emitted by your backend SSE stream and asserts exact schema ordering (meta -> token delta* -> citations -> usage -> [DONE]), ensuring frontend UI components never freeze waiting on missing events!