Files
collective-lists/plan/fase-3-tareas-notas.md
Oier Bravo Urtasun f396897cb5 test: full test suite (Vitest + pgTAP + Playwright) + TDD plan restructure
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>
2026-04-13 01:40:16 +02:00

3.3 KiB
Raw Blame History

Fase 3 — Tareas y Notas

Estado: Pendiente Duración estimada: 12 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_by y completed_at se fijan al marcar; se limpian al desmarcar
    • T-04: aislamiento cross-collective (Ana no ve tareas del colectivo de Eva)
  • rls-notes.test.ts — N-series:
    • N-01/N-02: CRUD por rol en notes
    • N-03: notas archivadas siguen siendo legibles; las deleted_at pasan a papelera
    • N-04: aislamiento cross-collective

pgTAP (supabase/tests/):

  • 005_tasks_rls.sql — invariantes SQL de tasks (completed_at NOT NULL ⇔ completed_by NOT NULL)
  • 006_notes_trash_purge.sql — simular pg_cron job: insertar nota con deleted_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 crear
  • notes.test.ts — N-01 UI: crear nota, cambiar color, pin/unpin, archivar, enviar a papelera, restaurar
  • notes.test.ts — N-02 UI: editor Markdown básico (bold/italic), autosave tras 500ms
  • notes.test.ts — N-03 UI: guest ve notas pero no puede editar

3.1 Tareas

  • Migración: tablas task_lists y tasks con 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 notes con color, is_pinned, is_archived, deleted_at + RLS
  • Job pg_cron: borrado definitivo de notas en papelera con deleted_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/archive y /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.