mirror of
https://github.com/nomadkaraoke/karaoke-gen.git
synced 2026-11-20 13:07:57 +09:00
## Summary - **Local stack:** `scripts/local-stack.sh up --frontend` runs the **real** backend on the Firestore + GCS emulators with `FAKE_WORKERS=1`. In-process fake workers move jobs through their real states in seconds, using tiny real media, so web Playwright and mobile Maestro full-journey tests can run offline against the same endpoints. - **Email-code sign-in** (nomad-mobile spec §4.1): `POST /api/users/auth/send-code` + `verify-code`. The code logic is shared with kjbox via `LoginCodeStore`, and sends are throttled per email and per IP. - **Bug fix found by the new suite:** `confirm-duration` moved jobs to `separating_stage1`, from which they can never reach review. It now resumes at `downloading`. No prod job had taken this path yet. ## Changes - `backend/services/fake_workers/`: dispatch seam in `WorkerService.trigger_*`, plus fake search, download, checkout and outbox, scenarios, and per-user config. The real stem upload, transcode, backing-vocals analysis and preview render are reused. Every check is strict (`is True`), so a MagicMock settings object never enables the fakes, and startup **refuses FAKE_WORKERS in production**. - `/api/test/*` router (mounted only in that mode): `status`, `scenario`, `fake-config`, `emails`, `reset`, plus the fake Stripe checkout page. Paying it runs the real webhook handler. - `frontend/e2e/local-stack/` (9 specs, ~50s): - sign-up → make → review → instrumental → download - buy and cancel credits - duration confirm, failed, complete and review states - code sign-in and lockout - New required CI job `local-stack-e2e`. - Docs: TESTING.md § Local stack, DEVELOPMENT.md, API.md, README, LESSONS-LEARNED. - `MAX_SIGNUPS_PER_IP` can now be set by env. Only the local stack raises it; production keeps the default of 2. ## Testing - [x] Backend unit: 6175 passed - [x] Emulator: 152 passed - [x] Frontend Jest: 1706 passed - [x] Local-stack Playwright: 9/9 passed (CI mode) ## Review - [x] CodeRabbit CLI review completed locally. 1 minor finding declined: it suggested swallowing infrastructure errors in send-code as fake "sent" responses, which would hide real outages from users. @coderabbitai ignore --- 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01AGuxtgoscF6RJGtpjHPg3W --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
64 lines
2.6 KiB
TypeScript
64 lines
2.6 KiB
TypeScript
/**
|
|
* Email-code sign-in (POST /api/users/auth/send-code + verify-code), the login
|
|
* the mobile app uses. API-level here: there is no web UI for it yet, and the
|
|
* mobile Maestro flows drive the same endpoints against the same stack.
|
|
*/
|
|
import { test, expect } from '@playwright/test';
|
|
import { API_URL, uniqueEmail, waitForEmail } from './stack';
|
|
|
|
test('a new user signs in with an emailed 6-digit code and gets the welcome credit', async ({ request }) => {
|
|
const email = uniqueEmail('code');
|
|
|
|
const sent = await request.post(`${API_URL}/api/users/auth/send-code`, { data: { email, locale: 'en' } });
|
|
expect(sent.status()).toBe(202);
|
|
|
|
const mail = await waitForEmail(request, email, /.+/);
|
|
expect(mail.codes, 'one 6-digit code in the email').toHaveLength(1);
|
|
// The same email also carries a normal magic link.
|
|
expect(mail.links.some((l) => l.includes('/auth/verify?token='))).toBe(true);
|
|
|
|
const wrong = await request.post(`${API_URL}/api/users/auth/verify-code`, {
|
|
data: { email, code: mail.codes[0] === '000000' ? '111111' : '000000' },
|
|
});
|
|
expect(wrong.status()).toBe(401);
|
|
|
|
const verified = await request.post(`${API_URL}/api/users/auth/verify-code`, {
|
|
data: { email, code: mail.codes[0] },
|
|
});
|
|
expect(verified.status()).toBe(200);
|
|
const body = await verified.json();
|
|
expect(body.session_token).toBeTruthy();
|
|
expect(body.user.email).toBe(email);
|
|
expect(body.credits_granted).toBe(1);
|
|
|
|
const me = await request.get(`${API_URL}/api/users/me`, {
|
|
headers: { Authorization: `Bearer ${body.session_token}` },
|
|
});
|
|
expect(me.status()).toBe(200);
|
|
|
|
// Codes are single-use.
|
|
const replay = await request.post(`${API_URL}/api/users/auth/verify-code`, {
|
|
data: { email, code: mail.codes[0] },
|
|
});
|
|
expect(replay.status()).toBe(401);
|
|
});
|
|
|
|
test('five wrong guesses lock the code', async ({ request }) => {
|
|
const email = uniqueEmail('lock');
|
|
await request.post(`${API_URL}/api/users/auth/send-code`, { data: { email } });
|
|
const mail = await waitForEmail(request, email, /.+/);
|
|
const wrongCode = mail.codes[0] === '000000' ? '111111' : '000000';
|
|
|
|
const statuses: number[] = [];
|
|
for (let i = 0; i < 6; i++) {
|
|
const r = await request.post(`${API_URL}/api/users/auth/verify-code`, { data: { email, code: wrongCode } });
|
|
statuses.push(r.status());
|
|
}
|
|
expect(statuses.slice(0, 5)).toEqual([401, 401, 401, 401, 401]);
|
|
expect(statuses[5]).toBe(429);
|
|
|
|
// Even the right code no longer works once the code is burnt.
|
|
const right = await request.post(`${API_URL}/api/users/auth/verify-code`, { data: { email, code: mail.codes[0] } });
|
|
expect([401, 429]).toContain(right.status());
|
|
});
|