Files
karaoke-gen/scripts/e2e/update_tenant_allowlist.py
Andrew Beveridge ☄️andClaude Opus 4.8 6f86b3d901 test(e2e): rewrite tenant daily E2E as a faithful frontend journey (#873)
## Why

The daily tenant E2E (`scripts/e2e/tenant_e2e.py`) drove the whole flow
via **direct backend API calls**, bypassing the frontend. Two problems:
1. **Not representative** — it never exercised the tenant portal UI a
real operator uses.
2. **Intermittent stuck-render orphans** (Run #31 vocalstar, #32 singa)
— because it never loaded the lyrics-review page, it never fired
`encoding-worker/warmup`, so the encoder was cold when the render
started and the job orphaned in `rendering_video` (no recovery).
Root-caused this session; the fix is to make the test faithful, which
fires the warmup a real user fires.

## What

Replaces `tenant_e2e.py` with
**`frontend/e2e/production/tenant-happy-path.spec.ts`** — a Playwright
journey mirroring `happy-path-real-user.spec.ts`, run per-tenant via the
existing `e2e-tenant-daily.yml` matrix (vocalstar, singa; `max-parallel:
1`):

login (real magic-link UI) → submit track (tenant form + real audio
upload) → wait for transcription → **open review UI (fires warmup)** →
approve → wait for render → assert tenant distribution (Dropbox present,
no YouTube, downloads, `is_private`) → cleanup.

- **Tenant auth**: added `inbox.testmail.app` to both tenants'
`allowed_email_domains` (setup scripts + live GCS config via
`scripts/e2e/update_tenant_allowlist.py`) so the test signs in through
the real magic-link UI.
- **Test audio**: short 60s clips fetched from private GCS in CI
(`scripts/e2e/fetch_test_audio.sh`) — fast, reliable uploads and quick
renders.
- Workflow reworked to Node/Playwright; `tenant_e2e.py` deleted; version
`0.190.3 → 0.190.4`.

## Findings surfaced (validating the exercise)

- **Browser upload was CORS-blocked in Playwright** by the shared
config's global `x-playwright-test` header (it made the GCS signed-URL
PUT preflight request a header the bucket's CORS doesn't allow).
Verified the same PUT succeeds in a real browser — a **test-harness
artifact, not a product bug**. Worked around by stripping the header for
`storage.googleapis.com` requests. (Note: any prod E2E doing a browser
signed-URL upload is affected by this global header.)

## Verification

Both tenants run **green end-to-end against prod** locally (login →
submit → review → render → distribution; render completed without
orphaning). Reworked workflow dispatched on this branch to confirm CI
wiring (Node setup + private-audio fetch + secrets).

Test-only + CI + tenant-config change. No product code.

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

@coderabbitai ignore

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-05 02:33:20 -04:00

50 lines
1.8 KiB
Python

#!/usr/bin/env python3
"""Idempotently add the E2E email domain to a tenant's allowed_email_domains in
the live GCS config (tenants/{id}/config.json).
The setup-{tenant}-tenant.py scripts are the source of truth, but the live GCS
config must also be updated for the change to take effect (tenant config is
loaded from GCS, not re-derived from the setup scripts).
Usage: python scripts/e2e/update_tenant_allowlist.py vocalstar singa
Requires a write-capable credential (Application Default Credentials of an
account with storage.objects.create/update on the bucket). If ADC is pinned to
a read-only service account via GOOGLE_APPLICATION_CREDENTIALS, run with that
override cleared, e.g.:
env -u GOOGLE_APPLICATION_CREDENTIALS python scripts/e2e/update_tenant_allowlist.py vocalstar singa
"""
import json
import sys
from google.cloud import storage
BUCKET = "karaoke-gen-storage-nomadkaraoke"
E2E_DOMAIN = "inbox.testmail.app"
def update(tenant_id: str) -> None:
client = storage.Client(project="nomadkaraoke")
blob = client.bucket(BUCKET).blob(f"tenants/{tenant_id}/config.json")
cfg = json.loads(blob.download_as_text()) # populates blob.generation
auth = cfg.setdefault("auth", {})
domains = auth.setdefault("allowed_email_domains", [])
if E2E_DOMAIN in domains:
print(f"{tenant_id}: already allowlisted ({domains})")
return
domains.append(E2E_DOMAIN)
# Optimistic concurrency: only write if the object hasn't changed since read,
# so a parallel edit to the tenant config isn't silently clobbered.
blob.upload_from_string(
json.dumps(cfg, indent=2),
content_type="application/json",
if_generation_match=blob.generation,
)
print(f"{tenant_id}: added {E2E_DOMAIN} -> {domains}")
if __name__ == "__main__":
for t in sys.argv[1:] or ["vocalstar", "singa"]:
update(t)