feat(realtime): full Fase 2b.0 test suite + infra hardening
Extend the 2b.0 red-phase coverage: presence, RLS isolation, offline-queue
contract, and Playwright scaffolds for the shopping-session UX. Only the
presence test is blocked on an upstream Realtime bug (documented below); all
other Realtime paths are proven end-to-end.
Tests
- realtime-postgres-changes.test.ts: now uses afterEach socket disconnect
(Vitest singleFork kept Phoenix sockets alive between files, leaking state)
- realtime-isolation.test.ts (new): R-I-01 David (guest, same collective)
receives events; R-I-02 Eva (non-member) receives NONE — RLS is enforced
server-side per subscribed JWT
- realtime-presence.test.ts (new, describe.skip): two-client roster + leave
assertions ready, gated on upstream bug
- sync-queue.test.ts (new, describe.skip): 7 placeholders pinning the
apps/web/src/lib/sync/queue.ts contract (Q-01..Q-04 enqueue / in-order
flush / retry; F-01..F-03 online-event flush + last-write-wins)
- apps/web/tests/e2e/{session,realtime,offline}.test.ts (new, describe.skip):
S-01..S-03, R-E-01, R-E-02, O-01, O-02 pinning the Modo Compra UI contract
- vitest.config.ts: fileParallelism=false, drop singleFork so each file gets
a fresh worker fork — prevents RealtimeClient singleton leakage
Infra
- db-init/00-role-passwords.sh: pre-create `realtime` schema with
AUTHORIZATION supabase_admin. Realtime's per-tenant migrator creates tables
INSIDE the schema but does not create the schema itself; without this the
first tenant connect fails with "schema realtime does not exist"
- docker-compose.dev.yml: adopt the upstream supabase/supabase Realtime env
shape — SEED_SELF_HOST=true + RUN_JANITOR=true + RLIMIT_NOFILE=10000 +
drop the custom `command: eval seeds` (that bypasses the normal supervisor
startup and was observed to cause GenServer crashes under load).
Version pinned to v2.76.5 to match the official docker-compose.
Known upstream bug
- Realtime v2.76.5 and v2.83.0 both crash on presence_diff:
`(UndefinedFunctionError) RealtimeChannel.handle_out/3 is undefined`.
postgres_changes + isolation unaffected (they don't traverse handle_out).
Presence tests stay `describe.skip` until a fixed upstream is released.
Totals: 59 Vitest passed (+ 9 skipped awaiting implementation/upstream),
16 pgTAP, 15 Playwright (+ 7 E2E scaffolded for 2b UI) = 90 green.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
24
apps/web/tests/e2e/offline.test.ts
Normal file
24
apps/web/tests/e2e/offline.test.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* O-series — Fase 2b.2 (offline-first)
|
||||
*
|
||||
* Verifies the optimistic queue + post-reconnect flush flow. Uses Playwright's
|
||||
* `context.setOffline(true)` to simulate a dropped connection. Skipped until
|
||||
* the sync module + offline banner exist.
|
||||
*/
|
||||
import { test } from '@playwright/test';
|
||||
|
||||
test.describe.skip('Offline queue + reconnect flush (pending sync module)', () => {
|
||||
test('O-01: mutations while offline stay locally and show the "offline" banner', async () => {
|
||||
// Given Borja is on /lists/[id] with real network
|
||||
// When context.setOffline(true) + add two items
|
||||
// Then both items render locally and a "sin conexión / offline" banner is visible
|
||||
});
|
||||
|
||||
test('O-02: going back online flushes pending_ops and hides the banner', async () => {
|
||||
// Given Borja is offline with 2 pending items in the queue
|
||||
// When context.setOffline(false)
|
||||
// Then within 5s: the banner disappears, both items exist on the server
|
||||
// (verified via a second authenticated context that re-fetches the list),
|
||||
// and pending_ops is empty (checked via a page.evaluate reading IDB).
|
||||
});
|
||||
});
|
||||
23
apps/web/tests/e2e/realtime.test.ts
Normal file
23
apps/web/tests/e2e/realtime.test.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* R-E2E series — Fase 2b.1 (dual-browser-context Realtime)
|
||||
*
|
||||
* Exercises the end-to-end Realtime sync path through the actual SvelteKit app.
|
||||
* Skipped until the app wires up the Realtime subscription in `/lists/[id]`.
|
||||
*/
|
||||
import { test } from '@playwright/test';
|
||||
|
||||
test.describe.skip('Realtime sync between two user sessions (pending UI)', () => {
|
||||
test('R-E-01: Ana adds an item → Borja sees it without refreshing', async () => {
|
||||
// Given two browser contexts: Ana and Borja, both on /lists/[id]
|
||||
// When Ana adds "Milk" via her sticky-form
|
||||
// Then Borja's item list shows "Milk" within 2s (no page reload)
|
||||
});
|
||||
|
||||
test('R-E-02: Presence avatar — Borja sees Ana\'s avatar when she joins', async () => {
|
||||
// Given Borja is on /lists/[id]/session
|
||||
// When Ana opens the same list in her own browser
|
||||
// Then Borja's presence indicator shows Ana's avatar
|
||||
// When Ana leaves
|
||||
// Then Ana's avatar disappears from Borja's indicator within 3s
|
||||
});
|
||||
});
|
||||
28
apps/web/tests/e2e/session.test.ts
Normal file
28
apps/web/tests/e2e/session.test.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* S-series (Modo Compra) — Fase 2b.3
|
||||
*
|
||||
* These tests describe the shopping-session UX contract for `/lists/[id]/session`.
|
||||
* Skipped until the route exists. Unskip one by one as the UI is implemented.
|
||||
*/
|
||||
import { test } from '@playwright/test';
|
||||
|
||||
test.describe.skip('Shopping session — full-screen mode (pending UI)', () => {
|
||||
test('S-01: /lists/[id]/session renders full-screen with no sidebar', async () => {
|
||||
// Given Borja is logged in and on the seed list
|
||||
// When he enters /lists/[id]/session
|
||||
// Then the app sidebar is hidden and the layout fills the viewport
|
||||
});
|
||||
|
||||
test('S-02: checking an item slides it into the CHECKED section with animation', async () => {
|
||||
// Given at least one unchecked item
|
||||
// When Borja taps its checkbox
|
||||
// Then the item appears in the CHECKED section and is no longer in TO BUY
|
||||
// (a `flip` animation is used but we only verify final state)
|
||||
});
|
||||
|
||||
test('S-03: "Finish shopping" confirms → list.status = completed → redirect to /lists', async () => {
|
||||
// Given a list in session with some items checked
|
||||
// When Borja taps "Finish shopping" and confirms
|
||||
// Then the URL returns to /lists and the list card shows the "completed" badge
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user