Add a 4-layer test stack covering RLS, triggers, and UI flows for Fases 0–2a, then restructure every plan file so future fases start with tests and end with a verification gate. Test suite - packages/test-utils: Vitest integration tests signing HS256 JWTs via jose so each test acts as a specific seed user (createClientAs + createAdminClient) - supabase/tests: pgTAP for accept_invitation(), item_frequency trigger, and promote-on-admin-leave; each file self-installs pgtap extension - apps/web/tests: Playwright E2E with live Keycloak login per test (storageState caching doesn't rehydrate Supabase's session state reliably) - just test-all chains the three suites; test-db forwards POSTGRES_PASSWORD as PGPASSWORD with ON_ERROR_STOP=1 so failures abort the chain Supabase auth gotcha - PostgREST queries inside onAuthStateChange deadlock on GoTrue's navigator.locks auth lock (getAccessToken → getSession → initializePromise waits on the same lock that's held during event dispatch). Fix is two defenses: a pass-through lock in $lib/supabase, and a setTimeout(0) defer in root +layout.svelte to push loadUserCollectives out of the callback's microtask chain. Either alone is insufficient; both together unblock the Playwright suite. Env key rotation - apps/web/.env.development had a stale demo anon key signed with a different secret than root .env; Vite inlined that into the browser bundle so Kong (which uses the root .env value) rejected every request with 401. Aligned the two files and added a memory entry to flag this for the next rotation. Plan restructure (TDD) - Every fase now opens with X.0 Tests primero and closes with X.Z Verificación final. Completed fases (0, 1, 2a) show the pattern retroactively with the tests that currently cover them; pending fases (2b, 3, 4) list the tests to write before implementation. Docs - CLAUDE.md status line reports 54 + 12 + 15 = 81 green tests, adds gotchas #11 (auth-lock deadlock) and #12 (no storageState caching) - README.md adds a TDD methodology section and the test-all command - .gitignore excludes Playwright's generated reports and auth state 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
3.3 KiB
3.3 KiB
Fase 3 — Tareas y Notas
Estado: ⏳ Pendiente
Duración estimada: 1–2 semanas
Objetivo: completar los módulos secundarios.
Esta fase sigue TDD: primero los tests, al final la verificación. Ninguna tarea de implementación se da por hecha hasta que todos los tests pasan (just test-all).
3.0 Tests primero — escribir antes de implementar
Vitest (packages/test-utils/tests/):
rls-tasks.test.ts— T-series:- T-01/T-02: miembro y admin pueden CRUD en
tasks; guest solo lee; Eva (no miembro) ve 0 filas - T-03:
completed_byycompleted_atse fijan al marcar; se limpian al desmarcar - T-04: aislamiento cross-collective (Ana no ve tareas del colectivo de Eva)
- T-01/T-02: miembro y admin pueden CRUD en
rls-notes.test.ts— N-series:- N-01/N-02: CRUD por rol en
notes - N-03: notas archivadas siguen siendo legibles; las
deleted_atpasan a papelera - N-04: aislamiento cross-collective
- N-01/N-02: CRUD por rol en
pgTAP (supabase/tests/):
005_tasks_rls.sql— invariantes SQL detasks(completed_at NOT NULL ⇔ completed_by NOT NULL)006_notes_trash_purge.sql— simularpg_cronjob: insertar nota condeleted_at = now() - interval '8 days'→ ejecutar el SQL del job → la nota ya no existe
Playwright (apps/web/tests/e2e/):
tasks.test.ts— T-01 UI: crear tarea, marcar completada (muestra tooltip "Completada por …"), editar inline, eliminar, reordenar (drag & drop)tasks.test.ts— T-02 UI: guest (David) ve tareas pero no puede crearnotes.test.ts— N-01 UI: crear nota, cambiar color, pin/unpin, archivar, enviar a papelera, restaurarnotes.test.ts— N-02 UI: editor Markdown básico (bold/italic), autosave tras 500msnotes.test.ts— N-03 UI: guest ve notas pero no puede editar
3.1 Tareas
- Migración: tablas
task_listsytaskscon RLS - Pantalla
/tasks— listado de listas de tareas - Vista de lista de tareas:
- Añadir tarea (input rápido)
- Checkbox de completado (registra
completed_by+completed_at) - Tooltip "Completada por [Nombre] el [fecha]"
- Edición inline del título
- Swipe para eliminar
- Drag & drop para reordenar
- Tareas completadas al fondo (no se ocultan)
- Sincronización vía polling a intervalos de 5 segundos cuando la vista está activa
3.2 Notas
- Migración: tabla
notesconcolor,is_pinned,is_archived,deleted_at+ RLS - Job
pg_cron: borrado definitivo de notas en papelera condeleted_at> 7 días - Pantalla
/notes— tablero tipo masonry:- Notas fijadas en bloque superior
- Notas activas en rejilla de colores
- Editor de nota (
/notes/[id]):- Editor de texto con Markdown básico (negrita, cursiva, listas, cabeceras)
- Guardado automático con debounce de 500ms
- Selector de color (8 opciones predefinidas)
- Opciones: fijar, archivar, mover a papelera, duplicar
- Archivo y papelera accesibles desde
/notes/archivey/notes/trash - Sincronización vía polling a intervalos de 30 segundos
3.Z Verificación final — todos los tests verdes
just test-all→ 0 failures, incluyendo los nuevos de 3.0
Criterio de aceptación: CRUD completo de tareas y notas por UI con cobertura E2E en Playwright y RLS en Vitest/pgTAP. Papelera y archive operativos. Toda la suite pasa con just test-all.