E2E Testing Architecture
Overview
End-to-end smoke tests validate the critical user journey across the video stack: branded-video-flow ā video processing ā library. Tests run on staging after deployment, gating production releases.
Tech Stack:
- Playwright (Chromium only, for speed)
- GitHub Actions (CI/CD integration)
- Clerk API (programmatic authentication)
High-Level Test Flow
Test Phases
| Phase | Status | Purpose |
|---|---|---|
| Phase 1: Deployment Verification | ā Complete | Poll /api/info endpoints, verify SHA matches |
| Phase 2: Clerk Authentication | š² Pending | Create test session via Clerk API, inject cookies |
| Phase 3: Video Upload Flow | š² Pending | Upload test video via BVF, submit form |
| Phase 4: Library Verification | š² Pending | Find video in Library, verify playable |
| Phase 5: Cleanup | š² Pending | Delete test video to leave clean state |
| Phase 6: Rollback Automation | š² Pending | Auto-rollback staging on test failure |
Architecture Diagram
Clerk Authentication Strategy
Approach: API Token Session Injection
Rather than automating UI login (slow, flaky), we create a Clerk session programmatically and inject it into Playwright's browser context.
Required Secrets
| Secret | Purpose | Where Used |
|---|---|---|
CLERK_SECRET_KEY | API authentication | Fixture creation |
E2E_TEST_USER_ID | Test user identifier | Session creation |
BVF_STAGING_URL | BVF base URL | Test navigation |
LIBRARY_STAGING_URL | Library base URL | Test navigation |
VERCEL_AUTOMATION_BYPASS_SECRET | Skip Vercel auth | Protected deployments |
Test User Requirements
Create a dedicated test user in Clerk dashboard:
- Email:
e2e-test@happyclient.internal(or similar) - Assigned to a test organization with known
orgId - Has permissions to view/delete videos
- Should NOT be a real user account
Video Upload Strategy
Current State: No Upload Mode
The branded-video-flow app currently only supports webcam recording, not file uploads. For CI/headless testing, we need an alternative.
Options Comparison
| Option | Complexity | Reliability | Speed |
|---|---|---|---|
| A: Add upload mode to BVF | Medium | High | Fast |
| B: Direct API upload + mock form | Low | Medium | Fast |
| C: WebRTC mock (fake camera) | High | Low | Slow |
Recommended: Option A - Upload Mode
Add a query parameter to enable file upload in BVF:
/flows/sanity-smoke?uploadMode=true&testMode=true
When enabled:
- Show file input instead of camera UI
- Accept video file from disk
- Upload via existing
/api/blob/upload - Continue with normal submission flow
Guard: Only enabled when both:
?uploadMode=truein URLDEPLOYMENT_ENVIRONMENTisstagingorlocal(never production)
Test Flow Configuration
Dedicated Test Flow: sanity-smoke
Create a minimal flow specifically for e2e testing:
// packages/app-video-flow/src/server/flows/configurations/sanity-smoke.ts
export const sanitySmokeFlow: FlowConfig = {
id: "sanity-smoke",
name: "E2E Smoke Test Flow",
slug: "sanity-smoke",
orgId: "org_e2e_test", // Dedicated test org
questions: [
{
id: "q1",
type: "video",
text: { en: "Please share a brief test message." },
required: true,
},
],
// Minimal config for fast tests
settings: {
allowSkip: false,
requireName: true,
requireEmail: false,
},
// Test-specific flags
__testConfig: {
uploadModeAllowed: true,
cleanupAfterSubmit: false, // Let test handle cleanup
},
};
Flow Availability
Complete Test Sequence
File Organization
tests/e2e/
āāā playwright.config.ts # Playwright configuration
āāā package.json # E2E-specific dependencies
āāā tsconfig.json # TypeScript config
āāā specs/
ā āāā smoke.spec.ts # Main smoke test (deployment + flow)
ā āāā helpers/
ā āāā polling.ts # Retry/polling utilities
āāā fixtures/
ā āāā auth.ts # Clerk session fixture
ā āāā test-data.ts # Test video metadata
ā āāā sanity-smoke.mp4 # Small test video (~100KB)
āāā test-results/ # Playwright artifacts (gitignored)
packages/ci-scripts/
āāā src/
āāā cleanup-e2e-session.ts # Fallback cleanup script
CI/CD Integration
Workflow Outputs
| Job | Output | Used By |
|---|---|---|
deploy-staging | bvf_url, library_url | e2e-smoke-test |
e2e-smoke-test | result: success|failure | deploy-production, rollback-staging |
Environment Configuration
Staging-Only Features
| Feature | Flag/Check | Purpose |
|---|---|---|
| Upload mode in BVF | ?uploadMode=true + env check | Enable file upload for CI |
| Test flows visible | DEPLOYMENT_ENVIRONMENT !== 'prod' | Expose sanity-smoke flow |
| Cleanup endpoint | DEPLOYMENT_ENVIRONMENT === 'staging' | Allow test data deletion |
Secrets Required in GitHub
# .github/workflows/e2e-smoke-test.yml
env:
BVF_STAGING_URL: ${{ secrets.BVF_STAGING_URL }}
LIBRARY_STAGING_URL: ${{ secrets.LIBRARY_STAGING_URL }}
CLERK_SECRET_KEY: ${{ secrets.E2E_CLERK_SECRET_KEY }}
E2E_TEST_USER_ID: ${{ secrets.E2E_TEST_USER_ID }}
E2E_TEST_ORG_ID: ${{ secrets.E2E_TEST_ORG_ID }}
VERCEL_AUTOMATION_BYPASS_SECRET: ${{ secrets.VERCEL_AUTOMATION_BYPASS_SECRET }}
Error Handling & Artifacts
On Failure
- Screenshot: Captured at failure point
- HTML snapshot: DOM state preserved
- Video recording: Full test session video
- Trace file: Playwright trace for debugging
- Correlation ID: Links to app logs (if implemented)
Artifact Retention
- Pass: Artifacts deleted after 1 day
- Fail: Artifacts retained for 7 days
Monitoring & Alerts
Test Metrics
| Metric | Target | Alert Threshold |
|---|---|---|
| Test duration | < 3 min | > 5 min |
| Success rate | > 99% | < 95% over 7 days |
| Flake rate | < 2% | > 5% over 7 days |
On Repeated Failures
- First failure: Retry (built into Playwright config)
- Second failure: Mark as failed, upload artifacts
- Third consecutive failure: Alert team via Slack webhook
Key Files Reference
| File | Purpose |
|---|---|
tests/e2e/playwright.config.ts | Playwright configuration |
tests/e2e/specs/smoke.spec.ts | Main smoke test spec |
tests/e2e/fixtures/auth.ts | Clerk authentication fixture |
.github/workflows/e2e-smoke-test.yml | CI workflow |
.github/workflows/deployment-pipeline.yml | Main pipeline (calls e2e) |
apps/branded-video-flow/app/api/info/route.ts | Deployment version endpoint |
apps/library/app/api/info/route.ts | Deployment version endpoint |
Related Documentation
- E2E Sanity PRD - Original requirements
- CI/CD Architecture - Deployment pipeline details
- Authentication - Clerk auth patterns