Scrum4Me/scripts
Madhura68 847fc84faf fix(M8): make SSE-stream survive Solo Paneel mutations
Symptoom op feat/ST-801-realtime-triggers initial implementation:
elke task-update sloot de open SSE-stream af en triggerde een
herverbinding met backoff. In de tussentijd gemiste events.

Oorzaak: Server Actions in App Router doen een impliciete
route-tree refresh die client components remount; daarmee killt
React de useEffect die de EventSource beheert.

Fix in twee delen:

1. Hef de realtime-hook op naar de (app)-layout via een nieuwe
   `SoloRealtimeBridge`-component. Layouts overleven Server-
   Action-refreshes beter dan pages, en de bridge leest het
   product-id uit de URL via usePathname. Connection-status
   (status, showConnectingIndicator) gaat naar de solo-store
   zodat SoloBoard 'm uit een gedeelde plek kan lezen.

2. Vervang updateTaskStatusAction en updateTaskPlanAction in de
   Solo-componenten door fetch naar de bestaande Route Handler
   `PATCH /api/tasks/[id]`. Route Handlers triggeren geen
   page-refresh, dus de SSE-stream blijft staan. lib/api-auth.ts
   accepteert nu naast Bearer-tokens ook iron-session cookies
   zodat browser-fetches zonder token werken.

Bijkomend: actions/tasks.ts laat /solo bewust niet meer
revalideren (wordt nu via realtime gedekt). Sprint/planning blijft
wel revalidaten — geen realtime daar.

Toegevoegd:
- components/solo/realtime-bridge.tsx — mount in (app) layout
- scripts/realtime-mutate.ts — handige test-helper voor externe
  mutaties (alsof MCP/REST schrijft) tijdens acceptance

Debug-logs in app/api/realtime/solo/route.ts staan nog aan voor
ST-806 acceptance; worden later gestript.

Bekend issue: Chrome op localhost (HTTP/1.1) cycle't EventSource
om de paar seconden vanwege de 6-connectie-limiet en retry-
heuristiek. Safari werkt stabiel. Productie op Vercel (HTTP/2
multiplexing) zou beide browsers stabiel moeten houden — Vercel
preview test is volgende stap.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-27 04:35:12 +02:00
..
insert-milestone.ts feat(tooling): add db:insert-milestone for idempotent backlog inserts (#7) 2026-04-27 01:25:05 +02:00
README.md docs(scripts): add scripts/README.md with token and ID setup instructions 2026-04-25 18:36:18 +02:00
realtime-mutate.ts fix(M8): make SSE-stream survive Solo Paneel mutations 2026-04-27 04:35:12 +02:00
test-api.sh chore: update API test script base URL and IDs; add ST-313 to backlog 2026-04-25 22:53:50 +02:00

API Test Scripts

test-api.sh

Runs curl-based tests against all 7 Scrum4Me API endpoints. Covers happy paths, auth (401), demo-block (403), and input validation (400).

Prerequisites

What How
Database seeded npx prisma db seed
Dev server running npm run dev
curl installed curl --version

Step 1 — Get a token for lars

  1. Open http://localhost:3000 in your browser
  2. Log in as lars / scrum4me123
  3. Go to Settings → API Tokens
  4. Click New token, give it any label
  5. Copy the token — it is shown only once

Open scripts/test-api.sh and paste it into TOKEN="".

Step 2 — Find your IDs

You need four IDs. The easiest way is to use the API itself:

# 1. Get PRODUCT_ID — run this after setting TOKEN
curl -s -H "Authorization: Bearer <TOKEN>" http://localhost:3000/api/products | grep -o '"id":"[^"]*"' | head -1

# 2. SPRINT_ID — look in the database or the UI (Sprint → copy ID from the URL)
# 3. STORY_ID  — open a story in the Sprint Board, copy the ID from the URL or the activity log
# 4. TASK_ID   — open a task, copy its ID

Or query the database directly:

# With psql / Neon CLI:
SELECT id FROM "Sprint" WHERE status = 'ACTIVE' LIMIT 1;
SELECT id FROM "Story"  WHERE status = 'IN_SPRINT' LIMIT 1;
SELECT id FROM "Task"   WHERE story_id = '<story-id>' LIMIT 1;

Paste the four values into the variables at the top of test-api.sh.

Step 3 — (Optional) Get a demo token for 403 tests

The 403 demo-block tests are skipped unless you set DEMO_TOKEN.

  1. Log out, log in as demo / demo1234
  2. Go to Settings → API Tokens, create a token
  3. Paste it into DEMO_TOKEN="" in test-api.sh

Step 4 — Run

bash scripts/test-api.sh

Expected output when all IDs are set and a demo token is provided:

============================================================
  Scrum4Me API Test Suite
  Base URL : http://localhost:3000
  Token    : scrum4me... (lars)
  Demo     : demo1234... (403 tests active)
============================================================

── GET /api/products ──────────────────────────────────────────────
  PASS  TC-P-09  happy path (lars)
  PASS  TC-P-01  no token → 401
  PASS  TC-P-02  invalid token → 401

── GET /api/products/:id/next-story ───────────────────────────────
  PASS  TC-NS-08  happy path (lars, 200 or 404 both valid)
  PASS  TC-NS-01  no token → 401
  ...

============================================================
  Results: 30 passed, 0 failed
============================================================

Notes

  • product_id is required for POST /api/todos. The Zod schema enforces z.string().min(1). Sending a todo without a product_id returns 400.
  • TC-NS-08 accepts both 200 and 404. After a fresh seed lars has no active sprint, so 404 is the expected response unless you create a sprint and add stories to it.
  • Reorder test (TC-RO-10) uses a single task ID. A reorder with one element is valid (sort_order is updated to 1).
  • The todos happy-path test appends $(date +%s) to the title to avoid duplicate-title issues on repeated runs.