feat: streaming API backend, Streamlit integration, and E2E infra#51
feat: streaming API backend, Streamlit integration, and E2E infra#51
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a real-time streaming API backend with FastAPI, integrates it into the Streamlit UI via a unified API client, and updates the end-to-end testing infrastructure (Playwright and helper scripts) to validate both standard and streaming chat flows.
- Added FastAPI WebSocket (
/ws/chat) and REST (/api/chat) endpoints with CORS support - Integrated streaming API into
app.pywith fallback to REST and a minimal Playwright-friendly UI - Updated E2E tests, helpers, and Playwright config to launch both backend and frontend and verify streaming completion
Reviewed Changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/e2e/specs/basic-e2e.spec.ts | Added E2E tests for standard and streaming chat interactions |
| tests/e2e/helpers/chat-helpers.ts | Refactored waitForAppLoad, adjusted timeouts, and enhanced logging |
| playwright.config.ts | Configured two webServer entries to start API backend and Streamlit |
| scripts/e2e_local.sh | Overhauled local E2E startup: strict flags, process management, tests |
| app.py | Introduced APIChatClient, streaming UI, and Playwright-friendly input |
| backend/main.py | New FastAPI app with /ws/chat, /api/chat, /health, /api/models |
Comments suppressed due to low confidence (2)
app.py:781
- The
requestsmodule is used here but not imported in this file, which will raise aNameError. Addimport requestsat the top.
try:
tests/e2e/helpers/chat-helpers.ts:7
- [nitpick] The retry loop and automatic reloads were removed, which may lead to flakiness if the app load is slow or intermittent. Consider reintroducing retries or a reload strategy to improve stability.
async waitForAppLoad() {
| # 3. Run health check | ||
| function run_health_check() { | ||
| echo -e "${YELLOW}🩺 Running health check...${NC}" | ||
| if ! poetry run python scripts/e2e_health_check.py; then |
There was a problem hiding this comment.
The script references scripts/e2e_health_check.py, but the health check file is named production_health_check.py. Update the path or filename to match the actual script.
| if ! poetry run python scripts/e2e_health_check.py; then | |
| if ! poetry run python scripts/production_health_check.py; then |
app.py
Outdated
|
|
||
| # Consistent rendering of chat messages | ||
| for i, msg in enumerate(st.session_state.messages): | ||
| st.markdown(f'<div class="chat-message" id="chat-message-{i}">{msg["content"]}</div>', unsafe_allow_html=True) |
There was a problem hiding this comment.
E2E tests look for elements with data-testid="stChatMessage", but this custom UI renders <div class="chat-message"> without that attribute. Either add data-testid to these divs or update the tests to target the new selector.
| st.markdown(f'<div class="chat-message" id="chat-message-{i}">{msg["content"]}</div>', unsafe_allow_html=True) | |
| st.markdown(f'<div class="chat-message" id="chat-message-{i}" data-testid="stChatMessage">{msg["content"]}</div>', unsafe_allow_html=True) |
| import { ChatHelper } from '../helpers/chat-helpers'; | ||
|
|
||
| // Utility to print debug info on failure | ||
| async function printDebugInfo(page) { |
There was a problem hiding this comment.
[nitpick] The printDebugInfo helper is defined but never used in the tests. Consider invoking it in a test.afterEach or within a catch block to capture state on failure.
🚀 Pull Request
Summary
Type of Change
Checklist
Testing
Screenshots (UI changes only)
Notes