# Tasks Work in this order. Finish each task's check before starting the next one. 1. **Set up (R1).** - One npm package: the Vite + React client in `src/client`, the Worker in `src/worker`, shared code in `src/shared`. - Add `wrangler.jsonc` and the scripts from `design.md` ("Cloudflare config"), then run `npm run types`. - `src/shared/settings.ts` reads `spekkr.inputs.json` at build time (the Worker imports it too). `vite.config.ts` puts `app_name` into the ``. - Add `GET /api/health`. Check: `npm run dev` serves a page titled `app_name`, and `/api/health` answers `{ ok: true }`. `npx wrangler deploy --dry-run --outdir /tmp/dry` bundles. Do not log in to Cloudflare or deploy. 2. **Shared helpers.** Write `time.ts`, `allowlist.ts`, `range.ts`, `parts.ts`, `ids.ts` and `limits.ts` from `design.md`, plus `tests/shared.test.ts`. Check: `npm test` passes every unit test named in `spec.md` "Tests" except "camera bubble" (step 5). 3. **Database and accounts (R2).** - Add `migrations/0001_init.sql`. - Passwords: PBKDF2-SHA-256 at 100000 iterations with a 16-byte salt, stored as `pbkdf2$100000$<salt b64>$<hash b64>`. - Sessions: a 32-byte token in the `sid` cookie (`HttpOnly; Secure; SameSite=Lax; Path=/; Max-Age` 30 days), stored as its SHA-256 hex. - Add the allowlist check on sign-up, on sign-in, and on every request that loads a session. Then the auth endpoints, `/api/me`, the sign-in page and the top bar. Check: the three `1-accounts` tests. Also check by hand that removing an email from `ALLOWED_EMAILS` (restart `wrangler dev` with a different `--var`) signs that account out at its next request. 4. **Upload API (R5, R16).** - Video create, parts, complete, abort, thumbnail, media (with `Range`) and thumbnail read. - Add the `Origin` check and the three rate limits. Return 507 when the storage limit is reached. - Add the stuck-upload cleanup in the library list. Check: `6-api` "cross-site writes are refused and inputs are checked". Also upload a small WebM through `page.request` in three parts and read it back with `Range: bytes=0-99` (206, 100 bytes). 5. **Recorder (R3, R4).** - `lib/recorder.ts` per `design.md` "Recording pipeline", `lib/upload.ts`, and the `/record` page: setup, the bubble, the countdown, the recording bar, upload progress, and the camera-only fallback. - Add the "camera bubble" unit test. Check: the four `2-record` tests. Then download a screen + camera recording and confirm that `ffprobe` (or a `<video>` element) reports the right duration and that the bubble appears in the frame. 6. **Share page and player (R6, R9, R10, R11).** - `Watch.tsx` and `Player.tsx`, including the speed menu, shortcuts, `?t=`, markers, the sidebar tabs, comments, reactions and views. - Add the not-found page. Check: the five `3-share` tests. 7. **Owner controls (R7, R8, R13).** - The Edit dialog with the trim preview and the chapters text box. - Copy link, download, the two switches, and delete. Check: the two `4-edit` tests. 8. **Library (R12).** The grid, skeletons, search, the card menu, and the empty state. Check: the two `5-library` tests and `6-api` "creating videos is rate limited". 9. **Themes and phones (R14, R15).** Dark colours, the toggle, and the layouts under 1080 px and 640 px. Check: `8-theme` and both `7-mobile` tests under the `iphone-13` and `pixel-7` projects. Also look at the share page at 390 × 844: nothing may overflow sideways, and every button must be at least 40 px. 10. **Review before saving (R3a, R3b, R7).** The `TrimEditor` (trim handles, one removed section, kept-only preview), the review step with title, mute, Save and Discard, edits sent with `complete`, migration `0002_edits.sql`, the player's kept timeline and cut skipping, the `getDisplayMedia` options, `CaptureController` focus, the floating controls and the shortcuts. Check: the six `9-review` tests and the unit test "removed section". 11. **Formats that play everywhere (R4, R6, R15).** MP4-first `pickMimeType`, `webm.ts` (record-time and serve-time repair), the format notice, `webkitEnterFullscreen`, and camera-only recording on phones. Check: both `10-formats` tests, `11-webkit` under the `webkit-iphone` project (`npx playwright install webkit` and its system packages first), the unit tests "webm repair" and "recording format", and `curl -r 0-1` / `curl -r 0-` against a media URL (206, `Content-Range`, `Accept-Ranges`). 12. **Real cuts (R3a, R7, R7a, R13).** `exporter.ts` (Mediabunny WebCodecs path and the real-time fallback, progress, cancel, `thumbnailOf`), Save cutting before upload in the review step, the replace API and migration `0003_real_cuts.sql`, `remapTime`/`remapChapters`/`validSpans`, the Edit video cut with its confirmation and stages, and a player that plays the file as it is (no trim, skip or mute logic; downloads equal what viewers see). Check: the R3a and R7 tests in `9-review`, `4-edit`, `7-mobile` and `11-webkit` (they need `ffmpeg` and `ffprobe` on `PATH`), the unit test "real cuts: removed parts and time remapping", and on a deployed site that a later cut leaves exactly one video object and the thumbnail under `videos/{id}/`. 13. **Finish (R17).** README, keyboard paths and focus rings, toasts, and the empty and error states. Check: `npm run typecheck`, `npm test` and `npm run e2e` all pass, and the dry-run deploy bundles. ## Testing notes - **Fake devices:** Chromium's fake camera is a moving pattern with a timer, and its fake screen (picked automatically by `--auto-select-desktop-capture-source=Entire screen`) comes back at the size you ask for, 1920 × 1080 here. Assert sizes against the `<video>` element's `videoWidth`/`videoHeight`, or an aspect ratio, not against fixed numbers. - **Secure context:** capture APIs exist only on secure origins. Run the tests against `http://127.0.0.1` or `http://localhost`, never a LAN IP. - **First frame:** the first frame of a recording can be black at 0 s. Seek the trim preview a little and give the player a poster (the thumbnail), so a paused video never shows a black box. - **Background tabs:** canvas drawing must not depend on `requestAnimationFrame`, which pauses in background tabs. Use the Web Worker ticker. - **`AUTH_LIMIT`:** cache the session per email (see `design.md` helpers), or the account tests hit 429. - **Exact matches:** match labels and buttons exactly where names overlap, for example the size radios "S", "M", "L", and "Comment" versus "Comments". - **Playback:** a chapter or comment click can start playback, so check `paused` before pressing play in a test. - **Video length:** keep recordings in tests short (2–4 s) so the whole suite runs in about 2 minutes. - **Range fill order:** each removed-section handle is clamped against the other, so fill them in an order that never crosses (for example "Remove to", then "Remove from", then "Remove to" again), with values on the 100 ms step. - **Proving a cut:** don't trust the app's own duration. Read the stored file back: `ffprobe` for duration and audio streams, and a fake screen that draws a timecode into every frame, so `ffmpeg` can show which moments survived (`e2e/media.ts`). - **Real-time cutting:** after the last frame of a file, `requestVideoFrameCallback` never fires again, so the end-of-part check also needs a timer; start or resume the recorder only after `play()` resolves, or each part begins with frozen frames. - **Document PiP needs a click:** `requestWindow` throws without user activation, which the picker usually uses up. Open it right after the picker only if `navigator.userActivation.isActive`, and keep the "Pop out controls" button. In tests where PiP isn't the subject, delete `window.documentPictureInPicture` in an init script so a stray window doesn't steal focus. - **What the fake devices can't show:** Linux WebKit plays media through GStreamer, which accepts WebM files Safari on iPhone rejects; it also has no `MediaRecorder` encoders. Bundled Chromium records MP4 with Opus (no AAC encoder on Linux), while Chrome on macOS, Windows and Android records AAC. Check the real thing on a phone when you can.