Compare commits

...
Sign in to create a new pull request.

281 commits

Author SHA1 Message Date
Janpeter Visser
973ff93d0c
docs(PBI-91): fix broken file:line links in hergebruik-sectie (#212)
URL-deel van markdown-links mag geen :lineNumber-suffix bevatten —
de check-doc-links.mjs (en standaard markdown) zoekt dan naar een
bestand `selectors.ts:166` dat niet bestaat. Label behoudt :N voor
leesbaarheid; alleen het URL-deel verwijst nu naar het werkelijke
bestand.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-15 11:09:11 +02:00
Janpeter Visser
00af559726
Sprint: ideeen aanpassen (#211)
* feat(user-settings): voeg IdeasListPrefs schema toe met filterStatuses

Nieuw IdeasListPrefs-subschema met filterStatuses (array van IdeaStatusApi-waarden),
ingehangen als views.ideasList in ViewsPrefs. Testdekking voor geldig, ongeldig en
leeg filterStatuses.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* refactor: extraheer MultiFilterPills naar backlog-filter-popover

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(ideas): voeg IdeasFilterPopover component toe

Nieuwe client-component met multi-select statusfilter popover voor het
Ideeënscherm; hergebruikt MultiFilterPills uit backlog-filter-popover.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(ideas): vervang inline statuschips door IdeasFilterPopover met user-settings persistentie

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* test(ideas): voeg componenttests toe voor IdeasFilterPopover en persistentie

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(ideas): voeg activeProductId-prop toe aan IdeaList

IdeaListProps uitgebreid met activeProductId: string | null.
Create-form initialiseert en reset naar het actieve product na aanmaken.
Tests en page.tsx bijgewerkt (page.tsx krijgt echte waarde in volgende taak).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(ideas): resolve active_product_id en geef door aan IdeaList

Haalt active_product_id op via prisma.user.findUnique en resolveert
het tegen de al opgehaalde toegankelijke productenlijst (AC4). Geeft
het resultaat als prop door aan IdeaList in plaats van hardcoded null.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(ideas): stuur activeProductId mee bij snel idee aanmaken

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* test(ideas): voeg component-tests toe voor activeProductId-voorvulling

AC1: "Nieuw idee"-select voorgevuld met activeProductId
AC2: "Nieuw idee"-select leeg bij activeProductId=null
AC3: "Snel idee" stuurt product_id=activeProductId mee bij createIdeaAction

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(notifications): toon textarea altijd in answer-modal naast opties

Vervang opties-XOR-textarea door twee onafhankelijke blokken: opties
alleen wanneer aanwezig, vrij tekstveld altijd zichtbaar. Bij opties
een visuele scheiding (border-t) en label 'Of typ een eigen antwoord'.
Verstuur-knop nu altijd in footer zichtbaar (was verborgen bij opties).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* refactor(notifications): gebruik question.options?.length als conditie

Gebruik de kortere optional chaining variant consistent, conform plan.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* test(notifications): voeg component-tests toe voor AnswerModal

Dekt: optieknoppen + textarea + Verstuur zichtbaar met opties,
submit via optieknop, submit via vrij tekstveld, disabled Verstuur
bij leeg veld, en demo-modus (textarea + Verstuur disabled).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* docs(notifications): werk answer-modal spec bij voor vrije tekstveld naast opties

Beschrijft dat textarea + Verstuur altijd zichtbaar zijn in multiple-choice
mode. Corrigeert de Cmd/Ctrl+Enter-bullet: shortcut werkt nu ook daar.
Bijgewerkt naar 2026-05-15.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 07:28:36 +02:00
Janpeter Visser
3d5c22382c
feat(PBI-91): expliciete schermstaat + draft-zichtbaarheid PB-page (#210)
* docs(ST-1369): plan PBI-91 — expliciete schermstaat + draft-zichtbaarheid

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(ST-1369): screen-state module — ScreenState + deriveScreenState()

Pure afleidingslaag die de verspreide schermstaat-derivatie van de Product
Backlog page consolideert tot één testbaar ScreenState-model. Nog geen
consumers — die volgen in T-1035/T-1036.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* test(ST-1369): unit-tests voor deriveScreenState()

Dekt alle vier de kinds (NO_SPRINT, DRAFT, ACTIVE, EDITING), de building-flag
en de draft-voorrang boven een actieve sprint.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(ST-1369): SprintSwitcher op deriveScreenState + draft op trigger (G5)

De trigger-knop toont nu de concept-sprint zodra er een sprint-draft loopt,
niet langer alleen de (disabled) dropdown-regel. Schermstaat-afleiding loopt
via de pure deriveScreenState() i.p.v. losse flags.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(ST-1369): NewSprintTrigger achter isActiveProduct-gate (G6)

De "Nieuwe sprint"-knop rendert niet langer op een niet-actief product —
een sprint-draft starten daar was verwarrend. page.tsx geeft de bestaande
isActiveProduct-flag door.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* test(ST-1369): component-tests voor draft-op-trigger (G5) en isActiveProduct-gate (G6)

sprint-switcher: trigger toont concept-sprint bij een pending draft, en geen
concept-label zonder draft. new-sprint-trigger: nieuw testbestand — rendert
niet op een niet-actief product, wel op een actief product zonder draft.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-15 01:45:35 +02:00
Janpeter Visser
2a6386163c
Sprint: Jobs scherm (#209)
* refactor(jobs): extraheer job-mapper naar lib/jobs-mapper.ts + voeg breadcrumb-velden toe

Verplaatst JobWithRelations, JOB_INCLUDE, RawJob, PriceRow, pickDescription,
computeCost en mapJob naar lib/jobs-mapper.ts (zonder 'use server'). Voegt
buildPriceMap helper toe en breidt de types uit met productCode, storyCode en
pbiCode via task->story->pbi en product.code includes.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(jobs): voeg GET /api/jobs/[id] route toe + tests

* feat(jobs): useJobsRealtime fetch-on-unknown met dedup-Set

Wanneer een SSE-event een onbekend job_id bevat, haalt de hook de volledige
job op via GET /api/jobs/[id] en upsert die in de store. Een inFlight-Set
voorkomt gelijktijdige dubbele fetches voor hetzelfde job_id. Bekende jobs
blijven de bestaande partial-upsert gebruiken. Zelfde logica in jobs_initial.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(jobs): JobCard breadcrumb + datum-fallback per kind

Voeg productCode/pbiCode/storyCode/startedAt/finishedAt toe aan
JobCardProps; bouw breadcrumb per job-kind en toon finishedAt → startedAt
→ createdAt als datum. JobsColumn geeft de nieuwe velden door.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* test(jobs): JobCard breadcrumb + datum-fallback tests

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 01:25:20 +02:00
Janpeter Visser
3d52fe4958
docs: Product Backlog page workflow & states (PBI-88) (#208)
* docs(T-1014): PB-workflow doc — skelet + as-is architectuur-lagen en stores

Eerste laag van het Product Backlog page workflow-doc (PBI-88 / ST-1363):
frontmatter, Context & scope, de architectuur-lagen (PG-triggers -> SSE ->
Zustand -> React) en de drie voedende Zustand-stores.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* docs(T-1015): PB-workflow doc — as-is workflow-states, transitions en diagram

Tweede laag van het Product Backlog page workflow-doc (PBI-88 / ST-1363):
de zeven impliciete workflow-states met preconditie en UI-gedrag, de
transition-tabel, en een Mermaid stateDiagram-v2.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* docs(T-1016): PB-workflow doc — to-be expliciete state machine

Derde laag van het Product Backlog page workflow-doc (PBI-88 / ST-1363):
canonieke state-set met mapping op de as-is werkelijkheid, transitietabel,
en het ontwerp van een dunne deriveScreenState()-afleidingslaag bovenop de
bestaande PBI-74 stores (geen nieuwe store).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* docs(T-1017): PB-workflow doc — gap-analyse, aanbevelingen en docs-wiring

Slotlaag van het Product Backlog page workflow-doc (PBI-88 / ST-1363):
gap-analyse (G1-G6, incl. de oorspronkelijke switcher-FOUT), niet-bindende
aanbevelingen, en verwante-docs sectie. Haakt het doc in via de
architecture.md breadcrumb en een cross-link vanuit functional.md F-04.
npm run docs groen: INDEX geregenereerd, alle doc-links valide.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-14 22:31:36 +02:00
Janpeter Visser
8287509c7c
Sprint: ll (#207)
* feat(PBI-ll): voeg lib/product-switch-path.ts toe met resolveProductSwitchTarget

Pure helper die doel-URL bij product-wissel bepaalt; unit-tests dekken alle pad-gevallen.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* test(product-switch-path): dek alle pad-categorieën en null-terugval af

* feat(nav-bar): gebruik resolveProductSwitchTarget bij product-wissel

Vervang router.refresh() door gerichte navigatie via resolveProductSwitchTarget,
zodat product/sprint/solo-pagina's direct naar het nieuwe product navigeren.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* test(nav-bar): voeg navigatie-assertions toe voor product-wissel

Voeg 4 tests toe die verifiëren dat NavBar na product-wissel naar de
juiste URL navigeert: /products/B, /products/B/sprint, /products/B/solo,
en router.refresh() op niet-product-pagina's.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-14 22:06:32 +02:00
Janpeter Visser
3ad352c10f
Sprint: ll (#206)
* feat(jobs): voeg lib/jobs-time-filter.ts toe met tijdvenster-predikaat

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(user-settings): voeg views.jobs.timeFilter toe aan UserSettingsSchema

Breidt ViewsPrefs uit met een jobs-object (JobsViewPrefs) dat timeFilter
accepteert met waarden '1h' | '24h' | 'all'. ViewsPrefs blijft .strict().

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* test(jobs-time-filter): voeg unit-tests toe voor isWithinTimeWindow en UserSettings-schema

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(jobs-time-filter): voeg JobsTimeFilterControl component toe

Nieuw client-component dat views.jobs.timeFilter leest/schrijft
via useUserSettingsStore met pill-stijl (MD3-tokens).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(jobs): wire JobsTimeFilter in jobs page header

Plaatst het tijdfilter-component rechts van de Jobs-kop via justify-between op de header-div.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(jobs): pas tijdvenster-filter toe in JobsColumn

Lees views.jobs.timeFilter uit de store en filter jobs op createdAt via isWithinTimeWindow, als eerste check vóór de bestaande kind/status-filters.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-14 21:06:59 +02:00
Janpeter Visser
ea28a62973
fix(prisma): migratie voor ontbrekende IdeaLogType.PLAN_REVIEW_RESULT (#205)
schema.prisma declareert IdeaLogType.PLAN_REVIEW_RESULT, maar geen
migratie voegde de enum-waarde toe aan de DB — de migratie
20260514000000_add_review_plan_support deed alleen IdeaStatus +
ClaudeJobKind. Schema-drift: prisma migrate status ziet het niet (die
checkt alleen of migratie-files zijn toegepast, niet schema-vs-DB).

Gevolg: de scrum4me-mcp tool update_idea_plan_reviewed crasht runtime
op prisma.ideaLog.create({ type: 'PLAN_REVIEW_RESULT' }) met
"invalid input value for enum IdeaLogType" — geverifieerd op de
zelf-gehoste DB (pg_enum mist de waarde).

Deze migratie voegt de waarde alsnog toe (ALTER TYPE ADD VALUE),
zelfde stijl als 20260514000000.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-14 19:40:53 +02:00
Janpeter Visser
b6bad83319
fix(ST-1359): docs-index generator hardenen + dode INDEX-link weg (#204)
* fix(ST-1359): docs-index generator indexeert alleen git-tracked bestanden

scripts/generate-docs-index.mjs walkte de docs/-map op schijf en
indexeerde elk .md-bestand — ook ongetrackte scratch-bestanden. Daardoor
kon een tijdelijk review-bestand van een Claude-worktree-sessie een link
in de gegenereerde INDEX.md krijgen die dood achterbleef nadat de
worktree was opgeruimd.

Vervangen door een `git ls-files -z docs`-listing: alleen getrackte (en
gestagede) .md-bestanden komen nog in de index. EXCLUDE_PATTERNS en de
archived-filter blijven ongewijzigd erbovenop werken; git ls-files is
recursief en werkt correct binnen git-worktrees.

Verificatie: npm run lint groen; regressietest met een ongetrackt
docs/-bestand bevestigt dat het niet meer in INDEX.md belandt.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* docs(ST-1359): regenereer INDEX.md — verwijder dode reviews-link

npm run docs:check-links faalde op een dode link naar
docs/reviews/onderzoek-wat-er-gedaan-quirky-mist-review.md — een
review-bestand dat nooit in git is gecommit. INDEX.md is geregenereerd
met de geharde generator uit de vorige commit; de stale regel valt
daardoor vanzelf weg (1 regel verwijderd, verder geen wijzigingen).

Verificatie: npm run docs → docs:check-links ✓ All doc links valid
(119 files checked).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-14 19:15:12 +02:00
Janpeter Visser
ff22196714
Sprint: Stories en taken krijgen één voorspelbare volgorde gekoppeld aan hun code; drag-and-drop herordening voor stories/taken verdwijnt, priority wordt puur label. (#201)
* feat(code): add parseCodeNumber helper to lib/code.ts

Pure helper that extracts the trailing numeric sequence from a code string
(ST-007 → 7, T-42 → 42). Non-conforming codes fall back to Number.MAX_SAFE_INTEGER
so they sort to the end. Includes 5 unit tests.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(tasks): add code field to BacklogTask type and all task selects

Adds `code: string | null` to BacklogTask interface and includes it in
all Prisma task.findMany selects (backlog API, stories tasks API, page
hydration routes). Updates coerceTaskPayload and test fixtures to match.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(sort-order): derive story/task sort_order from parseCodeNumber(code)

All create paths (createStoryAction, saveTask, createTaskAction,
materializeIdeaPlanAction) and code-edit paths (updateStoryAction, saveTask
update) now set sort_order = parseCodeNumber(code) instead of last+1.
Removes stale last-record queries from create paths.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(sort-order): decouple sprint membership actions from sort_order

createSprintAction and addStoryToSprintAction no longer write sort_order
when adding stories to a sprint. sort_order is derived from code via
parseCodeNumber, so membership should only set sprint_id + status.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* refactor(ordering): remove priority from all story/task orderBy

Story- en taak-ordering is nu puur sort_order asc (created_at als
tiebreaker). PBI-ordering (priority + sort_order) blijft ongewijzigd.

Gewijzigd: backlog/route, pbis/stories/route, claude-context/route,
next-story/route, workspace/route, tasks/route, sprint-runs (query +
in-memory sort), solo-workspace-server, page.tsx (app + mobile + sprint),
store compareStory, actions/sprints story-query, next-story test.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* refactor(dnd): remove drag-and-drop reorder for stories and tasks

- Remove reorderStoriesAction, reorderTasksAction, reorderSprintStoriesAction
- Delete REST route app/api/stories/[id]/tasks/reorder/route.ts
- Remove DnD from backlog story-panel and task-panel (flat list)
- Remove reorder-within-sprint branch from sprint-board-client handleDragEnd
- Switch SortableSprintRow to plain SprintRow using useDraggable (membership drag kept)
- Remove all DnD from task-list (status toggle + edit kept)
- Remove story-order/task-order/sprint-story-order/sprint-task-order mutation types and store handlers
- Remove related tests for deleted reorder route; fix sprint store tests

* feat(backlog): toon code-badge op backlog-taakkaarten

Geeft code={task.code} door aan <BacklogCard> in TaskCard (task-panel.tsx).
BacklogCard rendert de CodeBadge al conditionally — alleen de prop ontbrak.

* feat(migration): backfill story/task sort_order from code numeric suffix

One-time Prisma migration that sets sort_order = trailing numeric part
of code for all existing stories and tasks, consistent with
parseCodeNumber (fallback = Number.MAX_SAFE_INTEGER for non-conforming
codes). PBIs are intentionally excluded.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* docs+tests(sort-order): update for code-binding order on stories/tasks

- Rewrite docs/patterns/sort-order.md: float-insertion PBI only; story/task
  sort_order = parseCodeNumber(code), never drag/membership mutated
- Update plan-to-pbi-flow.md: sort_order auto, sprint_id param, priority=label
- Update make-plan.md: priority=label, array order = execution order
- Update rest-contract.md: fix sprint-tasks ordering, remove reorder endpoint
- Add ADR-0011: code is bindende volgordesleutel voor stories/taken
- Regenerate docs/INDEX.md via npm run docs
- Remove reorderStoriesAction/reorderTasksAction mocks from backlog tests
- Remove dnd-kit mocks from task-panel test (panel no longer uses dnd)
- Extend materializeIdeaPlanAction test: assert sort_order=parseCodeNumber(code)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-14 19:02:36 +02:00
Janpeter Visser
b6249a41c0
feat(PBI-67): IDEA_REVIEW_PLAN + geconsolideerde WIP-fixes (#203)
* fix(ci): docs:check-links groen — exclude docs/old/ + archiveer stale plans

CI faalde sinds #191 (docs cleanup) op pre-existing broken links:
- docs/old/ bevat archief-docs met by-design stale paden
- docs/plans/PBI-79*, M9*, M11* hadden geprojecteerde paden naar
  ../backlog/index.md (verplaatst naar docs/old/backlog/) en naar
  app-bestanden die nooit met de juiste relatieve prefix waren geschreven
- docs/adr/0000* verwees naar docs-restructure-ai-lookup.md (verplaatst)
- docs/glossary.md verwees naar /docs/backlog/index.md (verplaatst)

Fixes:
- scripts/check-doc-links.mjs: skip docs/old/ recursief
- Move docs/plans/{PBI-79,M9,M11}*.md → docs/old/plans/ (allemaal merged PBIs;
  plans waren historisch)
- docs/adr/0000-record-architecture-decisions.md: update pad naar archief
- docs/glossary.md: verwijder dode "backlog index"-link

Verificatie: `npm run docs:check-links` → ✓ All doc links valid (105 files)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(sprint-conflicts): stories uit CLOSED/ARCHIVED/FAILED sprints zijn weer eligible

Bug: bij sprint-aanmaken (en story-toevoegen aan een actieve sprint) gaf de
backend "Geen eligible stories voor deze sprint" zodra je stories aanvinkte
die ooit in een sprint hadden gezeten — ook als die sprint allang gesloten
of gearchiveerd was. partitionByEligibility checkte alleen story.sprint_id,
nooit sprint.status, terwijl getBlockingSprintMap in dezelfde file wél al
filterde op sprint: { status: 'OPEN' }. Inconsistent.

Fix: partitionByEligibility en isEligibleForSprint wegen nu sprint.status
mee. Een story blokkeert alleen als hij in een ANDERE sprint zit DIE NOG
OPEN is. Stories uit CLOSED/ARCHIVED/FAILED sprints worden weer vrij voor
planning — story.sprint_id blijft als historische referentie staan tot de
volgende updateMany hem overschrijft naar de nieuwe sprint.

Neveneffect: een DONE story in een gesloten sprint krijgt nu reason='DONE'
i.p.v. het misleidende reason='IN_OTHER_SPRINT'.

Tests: 3 nieuwe scenario's in __tests__/lib/sprint-conflicts.test.ts
(CLOSED/ARCHIVED/FAILED → eligible, DONE-in-CLOSED → reason=DONE).
De oude test 'does NOT mark crossSprint for stories in CLOSED other sprint'
is vervangen omdat hij het bug-gedrag vastlegde.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* test(sprint-switcher): repareer mock om CI te unblocken

Twee pre-existing mock-bugs die op main al rood waren maar geen gevolgen
hadden tot de CI-monitor erop sloeg in deze PR:

1. Mock-state miste `entities.settings`. Sinds PBI-79 (commit d587be2)
   selecteert SprintSwitcher ook `s.entities.settings.workflow?.pendingSprintDraft?.[productId]?.goal`,
   maar de testmock leverde alleen `{ context }`. → undefined-crash op
   `entities.settings` reading.

2. Mock factory exporteerde alleen `setActiveSprintAction`, maar de
   productie roept `switchActiveSprintAction` aan. Door `vi.mock` werden
   alle andere exports `undefined`, waardoor `actionMock` nooit kon
   triggeren.

Out-of-scope-fix t.o.v. de sprint-eligibility-fix in dit PR — apart commit
zodat reviewer dit als losse cleanup kan zien. CI is nu groen lokaal:
3/3 sprint-switcher tests + 839/839 full suite.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(ideas): upload-plan knop — short-circuit van Make-Plan AI-flow

Voegt een 'Upload plan' knop toe in idea-row-actions (verschijnt in zowel
list als idea-detail). Klik → file picker → kies .md → server-side parse +
opslaan; idea-status springt naar PLAN_READY. Vandaaruit de bestaande
'Maak PBI' knop voor materialize.

Server (uploadPlanMdAction):
- Toegestaan vanuit DRAFT, GRILLED, PLAN_FAILED, PLAN_READY
- DRAFT → skip-grill: status gaat direct naar PLAN_READY
- PLAN_READY overschrijft het bestaande plan (consistent met
  updatePlanMdAction, geen confirmation)
- Geblokkeerd in GRILLING/PLANNING (job loopt), PLANNED (al gematerialiseerd)
- Parse-failure → 422 + details (NIET opslaan, zodat een onparseerbaar plan
  nooit in de DB belandt)
- Empty / >100k chars → 422
- Schrijft IdeaLog NOTE met from_status + length
- Rate-limit + demo-guard + ownership-check via loadOwnedIdea (zelfde
  patroon als updatePlanMdAction)

UI (idea-row-actions.tsx):
- Hidden <input type=file accept=".md,.markdown,text/markdown,text/plain">
- FileReader → text → action
- Toast bij success + router.refresh()
- Blocked-tooltip in andere statussen

Tests: 10 nieuwe in __tests__/actions/ideas-crud.test.ts dekkend voor:
happy paths (DRAFT/GRILLED/PLAN_READY-overwrite/PLAN_FAILED), blocks
(PLANNED/GRILLING), validation (empty/oversized/parse-fail), 404.
Full suite groen: 849/849.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* Add reviews for Bootstrap-wizard plans v3.2 to v3.4

- Review v3.2: Addressed executor model, fire-and-forget issues, and PAT handling.
- Review v3.3: Improved transaction handling, stale recovery, and ID generation.
- Review v3.4: Finalized GitHub permissions, catalog versioning, and E2E verification queries.
- Updated recommendations for each version to enhance implementation readiness.

* fix(ideas): respecteer YAML-volgorde bij plan-materialize

Tasks erven nu story-priority i.p.v. eigen task.priority bij
materializeIdeaPlanAction. Worker sorteert op `priority ASC, sort_order ASC`;
gemixte task-priorities binnen één story zouden anders de YAML-volgorde
verstoren (e.g. tasks met priority 1/1/1/2/1/2 → worker-volgorde 1,2,3,5,4,6
i.p.v. 1,2,3,4,5,6).

- actions/ideas.ts: priority = s.priority bij task-create
- lib/schemas/idea.ts: task.priority optional (geaccepteerd, genegeerd)
- lib/idea-prompts/make-plan.md: documenteer dat task.priority genegeerd wordt
- __tests__/lib/idea-schemas.test.ts: test dat omitted task.priority slaagt

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* docs(make-plan): documenteer backtick-format voor implementation_plan-paden

verify_task_against_plan extraheert paden uit implementation_plan via twee
regex-patronen (backticks + bullet). Paden inline in genummerde tekst-stappen
worden niet herkend → planPaths.length=0 → bij diff >50 regels DIVERGENT.

Voeg sectie "Bestandspaden in implementation_plan — verplicht format" toe
die uitlegt welke formats werken (backticks, bullets) en welke niet (inline).
Plus verband met verify_required-keuze: default ALIGNED_OR_PARTIAL behouden
voor ADR-stubs en multi-file edits.

Voorkomt herhaling van T-963 cancelled_by_self-symptoom waar implementatie
slaagde maar verifier DIVERGENT teruggaf.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* docs(plans): M8 bootstrap-wizard upload-variant v1.4 — backtick-paden

Upload-variant van het volledige technische plan (docs/plans/M8-bootstrap-wizard.md),
bedoeld voor de "Upload plan"-functie. Genereert 1 PBI + 4 Stories + 22 Tasks
via materializeIdeaPlanAction.

v1.4-aanpassingen tov eerdere generatie-iteratie:
- Alle bestandspaden in implementation_plan in backticks (path-extractor matchen)
- Expliciete "Bestanden:" blok per task vóór de stappen
- Alle tasks op verify_required: ALIGNED_OR_PARTIAL (was deels ALIGNED — te strict
  voor ADR-stubs en multi-file edits)

Fixt forward-only: T-963 cancelled_by_self door DIVERGENT verifier-verdict.
Re-upload van dit bestand produceert tasks die door verify_task_against_plan
als ALIGNED of PARTIAL geclassificeerd kunnen worden.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* PBI-67: Add review-plan support to Idea model and job config

- Add plan_review_log and reviewed_at fields to Idea model
- Add REVIEWING_PLAN, PLAN_REVIEW_FAILED, PLAN_REVIEWED to IdeaStatus enum
- Add IDEA_REVIEW_PLAN to ClaudeJobKind enum
- Add IDEA_REVIEW_PLAN config to job-config.ts with model=opus, thinking_budget=6000
- Create migration record for schema changes (applied via db push)

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>

* PBI-67 Phase 2: Add update-idea-plan-reviewed MCP tool

- Create src/tools/update-idea-plan-reviewed.ts: saves review-log and transitions idea status to PLAN_REVIEWED
- Add PLAN_REVIEW_RESULT to IdeaLogType enum (both repos)
- Register tool in src/index.ts
- Update Prisma schemas (both repos): add plan_review_log and reviewed_at fields to Idea model
- Add REVIEWING_PLAN, PLAN_REVIEW_FAILED, PLAN_REVIEWED to IdeaStatus enum (MCP schema)
- Add IDEA_REVIEW_PLAN to ClaudeJobKind enum (MCP schema)
- Tool includes transaction safety and convergence metrics logging

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>

* feat(PBI-67): IDEA_REVIEW_PLAN Phases 3-6 — server actions, UI components, prompt & tests

- Phase 3: startReviewPlanJobAction, cancelIdeaJobAction, status transitions
  (REVIEWING_PLAN / PLAN_REVIEWED / PLAN_REVIEW_FAILED), status colors,
  job-card/jobs-column filters, idea-list status tabs
- Phase 4: review-plan-job.md prompt (multi-model orchestration with codex
  injection + active plan revision via update_idea_plan_md after each round),
  runbook, 13 unit tests
- Phase 5: ReviewLogViewer component (rounds, convergence, approval, issues),
  idea-detail integration, proper ReviewLog TypeScript types exported from component
- Phase 6.1: wait-for-job discriminator wired (IDEA_REVIEW_PLAN), plan-revision
  step made mandatory in prompt (was previously optional/missing)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-14 17:59:27 +02:00
Janpeter Visser
1de872298d
docs(plans): PBI-84 plan — code als bindende volgorde voor stories & taken (#202)
Goedgekeurd plan voor PBI-84: code wordt de bindende sorteersleutel voor
stories/taken, drag-and-drop herordening verdwijnt. Herzien na multi-model
review (P0/P1/P2) + onderzoek van het plan->onderdelen-mechanisme.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-14 16:30:53 +02:00
Janpeter Visser
7bb252c528
fix(ideas): make nextIdeaCode self-correcting against counter drift (#200)
Fixes a P2002 unique constraint crash on (user_id, code) when
idea_code_counter on the User is behind the actual codes in the ideas
table (e.g. after direct DB inserts during development).

After incrementing the counter the function now queries
MAX(CAST(SUBSTRING(code FROM 6) AS INTEGER)) via raw SQL and takes
max(counter, maxExisting + 1) as the next code. String MAX was not
safe above IDEA-999, hence the numeric cast. If the counter lagged it
is updated in-place to stay in sync.

No schema change, no migration, no changes outside idea-code-server.ts.

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-14 12:46:47 +02:00
Janpeter Visser
d84cdf664f
feat(PBI-67): IDEA_REVIEW_PLAN — iterative multi-model plan review (#199)
* feat(ideas): upload-plan knop — short-circuit van Make-Plan AI-flow

Voegt een 'Upload plan' knop toe in idea-row-actions (verschijnt in zowel
list als idea-detail). Klik → file picker → kies .md → server-side parse +
opslaan; idea-status springt naar PLAN_READY. Vandaaruit de bestaande
'Maak PBI' knop voor materialize.

Server (uploadPlanMdAction):
- Toegestaan vanuit DRAFT, GRILLED, PLAN_FAILED, PLAN_READY
- DRAFT → skip-grill: status gaat direct naar PLAN_READY
- PLAN_READY overschrijft het bestaande plan (consistent met
  updatePlanMdAction, geen confirmation)
- Geblokkeerd in GRILLING/PLANNING (job loopt), PLANNED (al gematerialiseerd)
- Parse-failure → 422 + details (NIET opslaan, zodat een onparseerbaar plan
  nooit in de DB belandt)
- Empty / >100k chars → 422
- Schrijft IdeaLog NOTE met from_status + length
- Rate-limit + demo-guard + ownership-check via loadOwnedIdea (zelfde
  patroon als updatePlanMdAction)

UI (idea-row-actions.tsx):
- Hidden <input type=file accept=".md,.markdown,text/markdown,text/plain">
- FileReader → text → action
- Toast bij success + router.refresh()
- Blocked-tooltip in andere statussen

Tests: 10 nieuwe in __tests__/actions/ideas-crud.test.ts dekkend voor:
happy paths (DRAFT/GRILLED/PLAN_READY-overwrite/PLAN_FAILED), blocks
(PLANNED/GRILLING), validation (empty/oversized/parse-fail), 404.
Full suite groen: 849/849.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* Add reviews for Bootstrap-wizard plans v3.2 to v3.4

- Review v3.2: Addressed executor model, fire-and-forget issues, and PAT handling.
- Review v3.3: Improved transaction handling, stale recovery, and ID generation.
- Review v3.4: Finalized GitHub permissions, catalog versioning, and E2E verification queries.
- Updated recommendations for each version to enhance implementation readiness.

* docs(plans): M8 bootstrap-wizard upload-variant v1.4 — backtick-paden

Upload-variant van het volledige technische plan (docs/plans/M8-bootstrap-wizard.md),
bedoeld voor de "Upload plan"-functie. Genereert 1 PBI + 4 Stories + 22 Tasks
via materializeIdeaPlanAction.

v1.4-aanpassingen tov eerdere generatie-iteratie:
- Alle bestandspaden in implementation_plan in backticks (path-extractor matchen)
- Expliciete "Bestanden:" blok per task vóór de stappen
- Alle tasks op verify_required: ALIGNED_OR_PARTIAL (was deels ALIGNED — te strict
  voor ADR-stubs en multi-file edits)

Fixt forward-only: T-963 cancelled_by_self door DIVERGENT verifier-verdict.
Re-upload van dit bestand produceert tasks die door verify_task_against_plan
als ALIGNED of PARTIAL geclassificeerd kunnen worden.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* PBI-67: Add review-plan support to Idea model and job config

- Add plan_review_log and reviewed_at fields to Idea model
- Add REVIEWING_PLAN, PLAN_REVIEW_FAILED, PLAN_REVIEWED to IdeaStatus enum
- Add IDEA_REVIEW_PLAN to ClaudeJobKind enum
- Add IDEA_REVIEW_PLAN config to job-config.ts with model=opus, thinking_budget=6000
- Create migration record for schema changes (applied via db push)

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>

* PBI-67 Phase 2: Add update-idea-plan-reviewed MCP tool

- Create src/tools/update-idea-plan-reviewed.ts: saves review-log and transitions idea status to PLAN_REVIEWED
- Add PLAN_REVIEW_RESULT to IdeaLogType enum (both repos)
- Register tool in src/index.ts
- Update Prisma schemas (both repos): add plan_review_log and reviewed_at fields to Idea model
- Add REVIEWING_PLAN, PLAN_REVIEW_FAILED, PLAN_REVIEWED to IdeaStatus enum (MCP schema)
- Add IDEA_REVIEW_PLAN to ClaudeJobKind enum (MCP schema)
- Tool includes transaction safety and convergence metrics logging

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>

* feat(PBI-67): IDEA_REVIEW_PLAN Phases 3-6 — server actions, UI components, prompt & tests

- Phase 3: startReviewPlanJobAction, cancelIdeaJobAction, status transitions
  (REVIEWING_PLAN / PLAN_REVIEWED / PLAN_REVIEW_FAILED), status colors,
  job-card/jobs-column filters, idea-list status tabs
- Phase 4: review-plan-job.md prompt (multi-model orchestration with codex
  injection + active plan revision via update_idea_plan_md after each round),
  runbook, 13 unit tests
- Phase 5: ReviewLogViewer component (rounds, convergence, approval, issues),
  idea-detail integration, proper ReviewLog TypeScript types exported from component
- Phase 6.1: wait-for-job discriminator wired (IDEA_REVIEW_PLAN), plan-revision
  step made mandatory in prompt (was previously optional/missing)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-14 03:35:02 +02:00
Janpeter Visser
b8e22539f6
fix(ideas): plan-upload task-volgorde + verifier-pad-format docs (#198)
* fix(ideas): respecteer YAML-volgorde bij plan-materialize

Tasks erven nu story-priority i.p.v. eigen task.priority bij
materializeIdeaPlanAction. Worker sorteert op `priority ASC, sort_order ASC`;
gemixte task-priorities binnen één story zouden anders de YAML-volgorde
verstoren (e.g. tasks met priority 1/1/1/2/1/2 → worker-volgorde 1,2,3,5,4,6
i.p.v. 1,2,3,4,5,6).

- actions/ideas.ts: priority = s.priority bij task-create
- lib/schemas/idea.ts: task.priority optional (geaccepteerd, genegeerd)
- lib/idea-prompts/make-plan.md: documenteer dat task.priority genegeerd wordt
- __tests__/lib/idea-schemas.test.ts: test dat omitted task.priority slaagt

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* docs(make-plan): documenteer backtick-format voor implementation_plan-paden

verify_task_against_plan extraheert paden uit implementation_plan via twee
regex-patronen (backticks + bullet). Paden inline in genummerde tekst-stappen
worden niet herkend → planPaths.length=0 → bij diff >50 regels DIVERGENT.

Voeg sectie "Bestandspaden in implementation_plan — verplicht format" toe
die uitlegt welke formats werken (backticks, bullets) en welke niet (inline).
Plus verband met verify_required-keuze: default ALIGNED_OR_PARTIAL behouden
voor ADR-stubs en multi-file edits.

Voorkomt herhaling van T-963 cancelled_by_self-symptoom waar implementatie
slaagde maar verifier DIVERGENT teruggaf.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-14 02:26:39 +02:00
Janpeter Visser
76c2efd27c
feat(ideas): upload-plan knop — short-circuit van Make-Plan AI-flow (#197)
Voegt een 'Upload plan' knop toe in idea-row-actions (verschijnt in zowel
list als idea-detail). Klik → file picker → kies .md → server-side parse +
opslaan; idea-status springt naar PLAN_READY. Vandaaruit de bestaande
'Maak PBI' knop voor materialize.

Server (uploadPlanMdAction):
- Toegestaan vanuit DRAFT, GRILLED, PLAN_FAILED, PLAN_READY
- DRAFT → skip-grill: status gaat direct naar PLAN_READY
- PLAN_READY overschrijft het bestaande plan (consistent met
  updatePlanMdAction, geen confirmation)
- Geblokkeerd in GRILLING/PLANNING (job loopt), PLANNED (al gematerialiseerd)
- Parse-failure → 422 + details (NIET opslaan, zodat een onparseerbaar plan
  nooit in de DB belandt)
- Empty / >100k chars → 422
- Schrijft IdeaLog NOTE met from_status + length
- Rate-limit + demo-guard + ownership-check via loadOwnedIdea (zelfde
  patroon als updatePlanMdAction)

UI (idea-row-actions.tsx):
- Hidden <input type=file accept=".md,.markdown,text/markdown,text/plain">
- FileReader → text → action
- Toast bij success + router.refresh()
- Blocked-tooltip in andere statussen

Tests: 10 nieuwe in __tests__/actions/ideas-crud.test.ts dekkend voor:
happy paths (DRAFT/GRILLED/PLAN_READY-overwrite/PLAN_FAILED), blocks
(PLANNED/GRILLING), validation (empty/oversized/parse-fail), 404.
Full suite groen: 849/849.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-13 15:56:16 +02:00
Janpeter Visser
551550791e
fix(sprint-conflicts): free stories from inactive sprints (CLOSED/ARCHIVED/FAILED) (#196)
* fix(sprint-conflicts): stories uit CLOSED/ARCHIVED/FAILED sprints zijn weer eligible

Bug: bij sprint-aanmaken (en story-toevoegen aan een actieve sprint) gaf de
backend "Geen eligible stories voor deze sprint" zodra je stories aanvinkte
die ooit in een sprint hadden gezeten — ook als die sprint allang gesloten
of gearchiveerd was. partitionByEligibility checkte alleen story.sprint_id,
nooit sprint.status, terwijl getBlockingSprintMap in dezelfde file wél al
filterde op sprint: { status: 'OPEN' }. Inconsistent.

Fix: partitionByEligibility en isEligibleForSprint wegen nu sprint.status
mee. Een story blokkeert alleen als hij in een ANDERE sprint zit DIE NOG
OPEN is. Stories uit CLOSED/ARCHIVED/FAILED sprints worden weer vrij voor
planning — story.sprint_id blijft als historische referentie staan tot de
volgende updateMany hem overschrijft naar de nieuwe sprint.

Neveneffect: een DONE story in een gesloten sprint krijgt nu reason='DONE'
i.p.v. het misleidende reason='IN_OTHER_SPRINT'.

Tests: 3 nieuwe scenario's in __tests__/lib/sprint-conflicts.test.ts
(CLOSED/ARCHIVED/FAILED → eligible, DONE-in-CLOSED → reason=DONE).
De oude test 'does NOT mark crossSprint for stories in CLOSED other sprint'
is vervangen omdat hij het bug-gedrag vastlegde.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* test(sprint-switcher): repareer mock om CI te unblocken

Twee pre-existing mock-bugs die op main al rood waren maar geen gevolgen
hadden tot de CI-monitor erop sloeg in deze PR:

1. Mock-state miste `entities.settings`. Sinds PBI-79 (commit d587be2)
   selecteert SprintSwitcher ook `s.entities.settings.workflow?.pendingSprintDraft?.[productId]?.goal`,
   maar de testmock leverde alleen `{ context }`. → undefined-crash op
   `entities.settings` reading.

2. Mock factory exporteerde alleen `setActiveSprintAction`, maar de
   productie roept `switchActiveSprintAction` aan. Door `vi.mock` werden
   alle andere exports `undefined`, waardoor `actionMock` nooit kon
   triggeren.

Out-of-scope-fix t.o.v. de sprint-eligibility-fix in dit PR — apart commit
zodat reviewer dit als losse cleanup kan zien. CI is nu groen lokaal:
3/3 sprint-switcher tests + 839/839 full suite.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-13 15:42:02 +02:00
Janpeter Visser
91190a5804
Sprint: kkkk (#195)
* feat(PBI-82): vervang inline checkboxlijst door Popover in idea-detail-layout

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(test): update sprint-switcher mock for renamed action + entities.settings shape

switchActiveSprintAction (renamed from setActiveSprintAction) and the new
entities.settings selector were added in PBI-82 but the test mock was not
updated, causing 3 test failures.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-13 15:39:23 +02:00
Janpeter Visser
2b4b5bf719
feat(PBI-80): demo-user mag eigen UI-voorkeuren wijzigen (#194)
* feat(PBI-80): SprintSwitcher demo-fork (ST-1345)

Demo-sessies navigeren bij sprint-wissel direct via router.push, zonder
de geblokkeerde setActiveSprintAction aan te roepen. De server-action
behoudt zijn 403-guard als defense in depth.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(PBI-80): NavBar demo-fork + URL-derived actief product (ST-1346)

Demo: product-switch in de NavBar navigeert direct via router.push zonder
setActiveProductAction. Voor de weergave (label + dropdown-highlight +
nav-links) leiden we voor demo de actieve product af uit pathname, zodat
de UI consistent is met de URL — de server-render houdt de seed-default
prop maar die wordt voor demo overschreven.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* docs(PBI-80): ADR-0006 addendum + demo-client-state patroon (ST-1347)

ADR-0006 krijgt een "Updated 2026-05-12"-sectie die de PBI-80-uitzondering
documenteert: client-side UI-prefs (filters, sort, layout, scope-keuze) zijn
voor demo toegestaan via in-memory store, terwijl alle data-mutaties three-layer
beschermd blijven. Patroon-doc beschrijft wanneer en hoe `isDemo` te gebruiken
in nieuwe componenten. CLAUDE.md quickref + docs/INDEX.md ge-update.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-12 20:03:40 +02:00
Janpeter Visser
2bef1a4c20
fix(ci): docs:check-links groen — exclude docs/old/ + archiveer stale plans (#193)
CI faalde sinds #191 (docs cleanup) op pre-existing broken links:
- docs/old/ bevat archief-docs met by-design stale paden
- docs/plans/PBI-79*, M9*, M11* hadden geprojecteerde paden naar
  ../backlog/index.md (verplaatst naar docs/old/backlog/) en naar
  app-bestanden die nooit met de juiste relatieve prefix waren geschreven
- docs/adr/0000* verwees naar docs-restructure-ai-lookup.md (verplaatst)
- docs/glossary.md verwees naar /docs/backlog/index.md (verplaatst)

Fixes:
- scripts/check-doc-links.mjs: skip docs/old/ recursief
- Move docs/plans/{PBI-79,M9,M11}*.md → docs/old/plans/ (allemaal merged PBIs;
  plans waren historisch)
- docs/adr/0000-record-architecture-decisions.md: update pad naar archief
- docs/glossary.md: verwijder dode "backlog index"-link

Verificatie: `npm run docs:check-links` → ✓ All doc links valid (105 files)

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-11 21:33:47 +02:00
Janpeter Visser
0a842e6841
docs(PBI-12 + /init): sprint-lifecycle runbook + MCP-tools plan + CLAUDE.md fixes (#192)
* docs(PBI-12 T-54): voeg sprint-tools toe aan mcp-integration.md

Documenteert mcp__scrum4me__create_sprint en mcp__scrum4me__update_sprint
onder de Authoring-sectie, met verwijzing naar plan-to-pbi-flow.md voor
de werkwijze.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* docs(PBI-12 T-55): promote plan-to-pbi-flow.md naar active

- frontmatter status: draft → active
- ⚠️-tooling-banner verwijderd; tools live sinds adbea3f in scrum4me-mcp
- korte note die naar mcp-integration.md verwijst voor tool-reference

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* docs(CLAUDE.md): /init improvements (scripts, proxy hardstop, versies)

- Stack-tabel: exacte versies Next.js 16.2, React 19.2, Tailwind v4, Prisma v7.8
- Hardstop bullet voor proxy.ts (géén middleware.ts, demo-write blokkering)
- MCP-sectie: bewuste duplicatie van lib/job-config.ts ↔ scrum4me-mcp toegelicht
- Verificatie-sectie: npm scripts-tabel (dev/test/seed/create-admin/docs/diagrams)
  + Vitest exclude + server-only mock note
- Orientatie-tabel: verwijzing toegevoegd naar docs/runbooks/plan-to-pbi-flow.md
- frontmatter last_updated: 2026-05-11

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* docs(PBI-12): implementatieplan voor sprint MCP-tools

Plan-file voor de twee tools (create_sprint + update_sprint) die de
sprint-lifecycle uit plan-to-pbi-flow.md ondersteunen. Beslissingen:
- Eén generieke update_sprint (geen losse close/fail/archive tools)
- Géén state-machine validatie (resubmit-mechanisme zit elders)
- Auto-end_date bij CLOSED/FAILED/ARCHIVED
- Cron + create_story sprint-param uit scope (apart later)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-11 21:13:06 +02:00
Janpeter Visser
b39c3ec2e1
docs(cleanup): archief verouderde plannen, backlog en root-duplicaten (#191)
* docs(cleanup): archief verouderde plannen, backlog en root-duplicaten

- 6 plans naar docs/old/plans/ (PBI-11/75/78, user-settings-store, Local github setup, lees-de-readme — laatste was verkeerde repo)
- docs/backlog/ naar docs/old/backlog/ (pre-MCP statische registry; live werk loopt via Scrum4Me-MCP)
- 6 root-level duplicaten naar docs/old/ (functional, {pbi,story,task}-dialog, product-backlog, backlog)
- 2 landing plans (niet uitgevoerd) krijgen archived: true frontmatter — blijven op plek maar uit INDEX
- scripts/generate-docs-index.mjs: skip docs/old/** + skip archived: true
- CLAUDE.md: rijen docs/backlog/, docs/plans/<key>-*.md, docs/manual/ weg; Track B-sectie verwijderd
- README.md / CHANGELOG.md / docs/plans/v1-readiness.md: link-fixes naar nieuwe locaties

Verify groen (lint + typecheck + 718 tests). docs/INDEX.md geregenereerd.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* docs(cleanup): registreer handmatige verplaatsingen en fix referenties

- 4 plans verplaatst naar docs/old/plans/ (M10-qr-pairing-login, auto-pr-deploy-sync, docs-restructure-ai-lookup, v1-readiness)
- 3 archive-plans verplaatst naar docs/old/plans/ (archive-map nu leeg)
- ST-1114-copilot-reviews + 3 research-docs naar nieuwe docs/Ideas/ map
- Duplicaat docs/old/2026-04-27-m8-realtime-solo.md verwijderd (origineel zit in docs/old/plans/)
- Link-fixes naar nieuwe locaties:
  - CHANGELOG.md → docs/old/plans/v1-readiness.md
  - docs/runbooks/deploy-control.md → docs/old/plans/auto-pr-deploy-sync.md (2x)
  - docs/runbooks/worker-idempotency.md → docs/old/plans/auto-pr-deploy-sync.md
  - docs/plans/docs-restructure-pbi-spec.md → docs/old/plans/docs-restructure-ai-lookup.md (4x text + 2x href)
- docs/INDEX.md geregenereerd (96 docs, was 100)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-11 19:46:00 +02:00
Janpeter Visser
d587be2fb3
feat(PBI-79): Product Backlog sprint-membership via vinkjes (#190)
* feat(PBI-79/ST-1333): active-sprint null-contract + clearActiveSprintAction

- lib/user-settings.ts: activeSprints values nullable in Zod-schema.
  Key-aanwezigheid heeft nu betekenis (key+null = bewust geen sprint;
  key ontbreekt = fallback-cascade).
- lib/active-sprint.ts: nieuwe readStoredActiveSprintState helper +
  resolveActiveSprint respecteert expliciet 'cleared' state zonder fallback.
  clearActiveSprintInSettings schrijft null i.p.v. de key te verwijderen.
- actions/active-sprint.ts: nieuwe clearActiveSprintAction met auth +
  membership-check.
- components/shared/sprint-switcher.tsx: '— Geen actieve sprint —'-optie
  in dropdown, disabled wanneer er geen actieve sprint is.
- Tests: nieuwe active-sprint.test.ts (resolver-paden + clear),
  active-sprint-action.test.ts (action-laag), uitbreiding user-settings.test.ts.

Plan: docs/plans/PBI-79-backlog-sprint-workflow.md

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(PBI-79/ST-1334): user-settings pendingSprintDraft-slot

- lib/user-settings.ts: nieuw workflow.pendingSprintDraft veld met
  compacte intent-shape (pbiIntent + per-PBI storyOverrides).
- actions/sprint-draft.ts: setPendingSprintDraftAction +
  clearPendingSprintDraftAction met product-membership-check + Zod-validatie.
- stores/user-settings/store.ts: setPendingSprintDraft / clearPendingSprintDraft
  optimistic acties + fine-grained mutators upsertPbiIntent / upsertStoryOverride.
  Sprint-draft actions worden dynamisch geïmporteerd zodat jsdom-tests
  zonder DATABASE_URL niet falen.
- Tests: nieuwe sprint-draft.test.ts (action-laag), uitbreiding
  user-settings store-tests (5 nieuwe cases) en schema-tests (4 cases).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(PBI-79/ST-1343): sprint-conflicts helper-library

- lib/sprint-conflicts.ts: drie pure/server-side helpers voor eligibility
  + cross-sprint detectie.
  - isEligibleForSprint(story): sprint_id IS NULL en status != DONE
  - partitionByEligibility(prisma, storyIds, excludeSprintId): split in
    eligible / notEligible / crossSprint met reden per story
  - getBlockingSprintMap(prisma, productId, storyIds, excludeSprintId):
    map storyId → { sprintId, sprintName } voor stories in andere OPEN sprint
- Tests: __tests__/lib/sprint-conflicts.test.ts (16 cases) — alle eligibility
  paden + cross-sprint scoping + CLOSED-sprint filtering.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(PBI-79/ST-1335): sprint-membership-summary + cross-sprint-blocks endpoints

Twee nieuwe GET-route handlers, beide verplicht gescoped op pbiIds (geen
product-brede aanroepen).

- app/api/products/[id]/sprint-membership-summary/route.ts
  Response: { [pbiId]: { total, inSprint } } via twee prisma.groupBy calls
  (totaal + binnen actieve sprint). Voor state-B tri-state.

- app/api/products/[id]/cross-sprint-blocks/route.ts
  Response: { [storyId]: { sprintId, sprintName } } voor stories in andere
  OPEN sprints. UX-hint voor disabled-vinkjes; commit-acties blijven
  autoritatief.

Tests: 13 cases dekken happy path, 400 zonder pbiIds, 400 zonder sprintId,
404 zonder product-access, auth-fail, en NOT-clause voor excludeSprintId.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(PBI-79/ST-1336): product-workspace sprint-membership slice + selectors

Datalaag voor de vinkje-UI van state A′ en state B.

types.ts:
- PbiSummaryEntry, CrossSprintBlock, SprintMembershipSlice toegevoegd.

store.ts:
- Nieuwe slice `sprintMembership` met pbiSummary, crossSprintBlocks,
  pending: { adds[], removes[] }, loadedSummaryForSprintId.
- Acties: setPbiSummary, setCrossSprintBlocks, toggleStorySprintMembership
  (cancel-out logic), resetSprintMembershipPending, fetchSprintMembershipSummary,
  fetchCrossSprintBlocks.
- hydrateSnapshot reset óók de membership-slice.

selectors.ts:
- selectPbiTriState (aggregate-only zolang stories niet geladen; rekent
  pending mee bij loaded PBI's).
- selectStoryEffectiveInSprint (DB ⊕ pending).
- selectStoryIsBlocked (cross-sprint hint).
- selectIsDirty, selectPendingCount.

Tests: 25 cases in nieuwe sprint-membership.test.ts dekken alle selector-
paden, toggle-cancel-out, fetch-helpers, en pbiId-scoping.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(PBI-79/ST-1337): state A′ UI — metadata dialog + sticky banner + PbiList ombouw

UI-laag voor de sprint-definitie-flow (state A′).

Nieuw:
- NewSprintMetadataDialog (stap 1): sprint_goal + optionele dates;
  'Verder' schrijft via useUserSettingsStore.setPendingSprintDraft.
- SprintDefinitionBanner (sticky): toont doel + X PBI's / Y stories teller;
  'Annuleren' → AlertDialog confirm → clearPendingSprintDraft;
  'Sprint aanmaken' nog niet aangesloten (wacht op ST-1339).
- NewSprintTrigger: button in page header die de metadata-dialog opent;
  verbergt zichzelf zolang er al een draft loopt.
- SprintDraftBanner: client-wrapper, rendert banner alleen als draft bestaat.

Wijzigingen:
- lib/user-settings.ts: pendingSprintDraft startAt/endAt → z.string().date().
- PbiList: oude selectionMode + selectedIds + NewSprintDialog vervangen door
  hasDraft-afgeleide A′-mode met tri-state vinkjes; togglen muteert
  upsertPbiIntent('all'|'none') en wist storyOverrides per PBI.
- StoryPanel: in A′-mode toont elke story een cherrypick-checkbox die
  upsertStoryOverride('add'/'remove'/'clear') aanroept; cross-sprint-blocked
  stories krijgen disabled-icoon met sprint-naam tooltip.
- app/(app)/products/[id]/page.tsx: StartSprintButton vervangen door
  NewSprintTrigger; SprintDraftBanner gepositioneerd boven split-pane.

Tests: bestaande tests blijven groen (806 cases) — UI-specifieke component
tests volgen later. ST-1339 sluit createSprintWithSelectionAction aan.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(PBI-79/ST-1339): createSprintWithSelectionAction + banner wire-up

actions/sprints.ts:
- Nieuwe createSprintWithSelectionAction(productId, metadata, pbiIntent,
  storyOverrides).
- Server-side intent-resolve:
  1. Voor elke PBI met intent='all': fetch child-story-IDs minus
     storyOverrides[pbi].remove.
  2. Plus storyOverrides[*].add (cross-PBI cherrypick toegestaan).
- Eligibility-filter via partitionByEligibility (sprint_id IS NULL + status
  != DONE; stories in andere OPEN sprint → conflicts.crossSprint).
- Transactie wrapt sprint.create + story.updateMany (status='IN_SPRINT') +
  task.updateMany (sprint_id cascade) — alles atomair.
- setActiveSprintInSettings na success.
- Return: { success, sprintId, affectedStoryIds, affectedPbiIds,
  affectedTaskIds, conflicts: { notEligible, crossSprint } } of error.

components/backlog/sprint-definition-banner.tsx:
- 'Sprint aanmaken'-knop sluit aan op createSprintWithSelectionAction;
  toast bij conflicts, success-toast anders, router.refresh() voor SSR
  cycle. Pending draft wordt door de action zelf nog niet expliciet gewist
  — dat gebeurt via revalidatePath en kan in ST-1340 finetuned worden.

Tests: __tests__/actions/create-sprint-with-selection.test.ts (6 cases)
dekken intent-resolve, override-respect, cross-sprint conflict, transactie-
binding van story.status + task.sprint_id, return-shape, en error-pad.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(PBI-79/ST-1340): commitSprintMembershipAction + gerichte client-store patches

actions/sprints.ts:
- Nieuwe commitSprintMembershipAction(activeSprintId, adds[], removes[]).
- Eligibility-filter voor adds via partitionByEligibility (sprint_id IS NULL
  en niet DONE; cross-sprint conflicts → notEligible).
- Race-safety voor removes: alleen stories met huidige sprint_id ==
  activeSprintId; rest → conflicts.alreadyRemoved.
- Transactie wrapt twee updateMany-paren (story status mee, task.sprint_id
  cascade). Update-paren overgeslagen wanneer leeg.
- Return: { success, affectedStoryIds, affectedPbiIds, affectedTaskIds,
  conflicts: { notEligible, alreadyRemoved } }.

stores/product-workspace/store.ts:
- applyMembershipCommitResult({ activeSprintId, addedStoryIds,
  removedStoryIds }) patcht entities.storiesById met juiste sprint_id +
  status; ledigt sprintMembership.pending. Geen task-veld omdat
  BacklogTask geen sprint_id-kolom heeft in de store.

Tests: __tests__/actions/commit-sprint-membership.test.ts (8 cases) — happy
path, DONE-conflict, cross-sprint, race-safety voor removes, transactie-
inhoud (status='IN_SPRINT'/'OPEN'), task-cascade, return-shape, auth-fail.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(PBI-79/ST-1338): state B vinkjes-UI + 'Sprint opslaan'-knop met teller

State B (actieve sprint geselecteerd, geen draft) hangt nu aan dezelfde
vinkje-UI als state A′, maar muteert de transient pending-buffer in plaats
van de draft.

- PbiList: nieuwe prop activeSprintId. selectionMode = hasDraft ||
  stateBMode. togglePbiInDraft routeert naar upsertPbiIntent (A′) of bulk-
  toggleStorySprintMembership over eligible child-stories (B, skip blocked).
- StoryPanel: idem prop activeSprintId. StoryBlockWithCherrypick muteert
  draft via upsertStoryOverride in A′ of pending buffer via
  toggleStorySprintMembership in B (cross-sprint blocked = disabled).
- SaveSprintButton (nieuw): client component in page header, alleen
  zichtbaar als er een actieve sprint is. Disabled bij clean buffer,
  enabled met teller bij dirty. Klikken calls commitSprintMembershipAction
  → applyMembershipCommitResult gericht in store + toast bij conflicts.
- page.tsx: activeSprintItem.id wordt doorgegeven aan PbiList, StoryPanel
  en SaveSprintButton.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(PBI-79/ST-1341+ST-1342): SprintEditDialog metadata-edit + multi-OPEN sprints

ST-1341 (T-946):
- actions/sprints.ts: nieuwe updateSprintAction(sprintId, fields) — JSON
  input, accepteert optionele goal/startAt/endAt; auth + product-access
  check, prisma.sprint.update, revalidatePath. Type-safe return.
- components/backlog/sprint-edit-dialog.tsx: Entity-Dialog-pattern voor
  metadata-edit van een sprint. Velden: sprint_goal, start_date, end_date.
  Link 'Sprint afronden… →' naar bestaande /products/[id]/sprint/[sprintId]
  zodat de completion-flow (per-story DONE/OPEN beslissing + PBI-promotie)
  niet wordt geduplicereerd. useDirtyCloseGuard.

ST-1342 (T-947):
- actions/sprints.ts: OPEN-uniqueness check in createSprintAction
  verwijderd. Een product mag nu meerdere OPEN sprints tegelijk hebben;
  cross-sprint-conflicts per story worden afgevangen door
  partitionByEligibility in de membership-commit-flow.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* test(PBI-79/ST-1344): updateSprintAction regression coverage

Audits van de geplande non-regressie-tests laten zien dat alle invarianten
uit het ST-1344 plan reeds gedekt zijn door eerder toegevoegde tests:

- clearActiveSprintAction null-not-delete → __tests__/lib/active-sprint.test.ts
  + __tests__/actions/active-sprint-action.test.ts
- Endpoints rejecten zonder pbiIds (400) → __tests__/api/sprint-membership-summary.test.ts
  + __tests__/api/cross-sprint-blocks.test.ts
- Status-mutaties story.status=IN_SPRINT/OPEN met task.sprint_id cascade
  in dezelfde transactie → __tests__/actions/create-sprint-with-selection.test.ts
  + __tests__/actions/commit-sprint-membership.test.ts
- Cross-sprint conflicts + DONE-eligibility → __tests__/lib/sprint-conflicts.test.ts

Nieuw: __tests__/actions/update-sprint.test.ts (6 cases) dekt
updateSprintAction die nog geen tests had — goal alleen, dates alleen,
null-clear, 403 zonder access, lege goal weigering, leeg fields-object
weigering.

Handmatige E2E checklist (T-949) blijft staan voor menselijke browser-
validatie tijdens PR-review.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(PBI-79): PBI-rij selecteert weer in A′/B-modus; vinkje is aparte trigger

Voor PBI-79 maakte het hele PBI-kaartje in selectionMode (state A′ én B)
de toggle. Daardoor:
- klik op rij = bulk-toggle stories (teller liep op);
- geen setActivePbi, dus StoryPanel kreeg geen content.

Fix: in selectionMode wordt onClick = onSelect (PBI activeren → stories
laden) en de tri-state-iconen verhuizen naar een eigen <button> in de
actions-slot met stopPropagation. Toggle gedrag (bulk add/remove in B,
upsertPbiIntent in A′) blijft ongewijzigd via die knop.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(PBI-79): cascade-restore alleen als hint-story bij nieuwe PBI hoort

Bug: setActivePbi reset activeStoryId/activeTaskId, maar het cascade-
restore-pad zette daarna een hint-story actief zonder te valideren of die
story bij de nieuw-geselecteerde PBI hoort. Bij PBI-switch bleef daardoor
de task-kolom de taken van de vorige story tonen.

Fix: alleen setActiveStory(hint) als entities.storiesById[hint].pbi_id ===
pbiId. Bij mismatch blijft activeStoryId null en is de task-kolom leeg
totdat de gebruiker een story uit de nieuwe PBI kiest.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(PBI-79): sprint-switch auto-select PBI/story + user-settings persist

Bij sprint-switch wordt de sprint-content server-side opgevraagd. Wanneer
de sprint precies één PBI (en die PBI exact één story binnen de sprint)
heeft, worden PBI en story automatisch geselecteerd. Alle drie keuzes
(sprint, pbi, story) worden atomair in user-settings opgeslagen zodat ze
cross-device blijven hangen.

- lib/user-settings.ts: layout krijgt nullable activePbis +
  activeStories per product.
- lib/active-sprint.ts: setActiveSelectionInSettings schrijft de drie
  keys atomair + notify pg_notify.
- actions/active-sprint.ts: switchActiveSprintAction(productId, sprintId)
  doet de server-side auto-select-resolutie (single PBI → single story)
  en returnt { sprintId, pbiId, storyId }.
- components/shared/sprint-switcher.tsx: handleSwitchSprint roept de
  nieuwe action aan en synchroniseert de workspace-store gelijk zodat
  de UI geen flash krijgt voor de SSR-refresh.
- components/backlog/active-selection-hydrator.tsx (nieuw): client-side
  effect dat user-settings.activePbis/activeStories naar workspace-store
  spiegelt; wint van de localStorage hint-restore.
- app/(app)/products/[id]/page.tsx: ActiveSelectionHydrator gemount
  binnen BacklogHydrationWrapper.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* docs(PBI-79): plan-update met implementatie-stand + scope-aanpassing

Documenteert wat er sinds de eerste implementatie-pass is gebeurd:
- Tabel van 14 commits met hun rol.
- Twee bugs die tijdens testen boven kwamen (PBI-rij-klik, cascade-restore).
- Nieuwe feature sprint-switch auto-select (server resolveert single-PBI/
  single-story; user-settings persist).

En kondigt scope-aanpassing aan voor de volgende implementatie-ronde:
- pendingSprintDraft wordt session-only (geen server-persist meer).
- useDirtyCloseGuard wist draft op leave-with-confirm.
- Sprint-switcher krijgt concept-entry zolang er een draft loopt.

De rest van het plan beneden blijft van kracht behalve waar deze sectie
het overruled.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(PBI-79): pendingSprintDraft session-only + concept-entry + leave-guard

Scope-aanpassing uit plan-revisie: drafts persisten niet meer server-side.

Wijzigingen:
- stores/user-settings/store.ts:
  - hydrate() strip nu workflow.pendingSprintDraft uit serverstate
    (legacy DB-entries blijven harmless aanwezig maar worden niet
    gehydreerd → effectief unreachable voor de UI).
  - setPendingSprintDraft / clearPendingSprintDraft worden lokale-only;
    geen import van sprint-draft-actions, geen server-roundtrip.
  - upsertPbiIntent / upsertStoryOverride blijven via setPendingSprintDraft
    routeren → ook session-only.
- components/shared/sprint-switcher.tsx: leest draft-goal uit user-settings
  store en toont '⚙ Concept — [goal]' als niet-selecteerbare entry
  bovenaan de dropdown zolang er een draft loopt.
- components/backlog/sprint-draft-leave-guard.tsx (nieuw): registreert
  een beforeunload-listener zolang er een draft is. Browser-refresh,
  tab-close en back-navigatie tonen daarmee de standaard confirm. In-app
  route-changes blijven via de banner-Annuleren-knop lopen.
- app/(app)/products/[id]/page.tsx: SprintDraftLeaveGuard gemount naast
  de banner.
- Tests: user-settings store-tests aangepast (geen server-call assert
  meer, hydrate strip-assert toegevoegd; upsert-tests seed nu via
  setPendingSprintDraft i.p.v. legacy hydrate).

setPendingSprintDraftAction + clearPendingSprintDraftAction blijven bestaan
voor eventuele toekomstige opruim-flows, maar worden niet meer aangeroepen
vanuit de UI.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* docs(PBI-79): mark scope-aanpassing afgerond + localStorage overzicht

- Drie open punten uit plan-revisie afgevinkt (commit 2a4ee6a).
- Sectie 'Bewust niet geïmplementeerd': server-persist van manuele
  PBI/story-klikken — op vraag van user nu out-of-scope voor deze PR.
- Tabel localStorage-gebruik in de codebase voor toekomstige referentie.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-11 18:56:46 +02:00
Janpeter Visser
bf7162a5fc
feat(PBI-76): migrate cookie-based prefs to user-settings (Phase 2) (#189)
* feat(PBI-76): extend UserSettings schema with layout

Adds layout.splitPanePositions and layout.activeSprints. These will
hold values currently kept in client-side and server-side cookies
(Phase 2). Two new tests cover the shape.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(PBI-76): migrate SplitPane positions to user-settings store

Outside of a drag the store is the source of truth (cross-tab
updates flow in for free). During a drag we keep splits in local
state so mousemove does not round-trip through the store. On
mouseup we persist the final splits via setPref. Removes
document.cookie reads/writes — cookieKey is reused as the
store-key for backwards compat.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(PBI-76): resolveActiveSprint reads from User.settings

lib/active-sprint:
- New helpers: getActiveSprintIdFromSettings, setActiveSprintInSettings,
  clearActiveSprintInSettings — all read/write user.settings.layout.activeSprints.
- resolveActiveSprint(productId, userId) — userId now required, falls back
  to first OPEN, then most recent CLOSED sprint.
- Cookie helpers (getActiveSprintIdFromCookie/setActiveSprintCookie/
  clearActiveSprintCookie) removed.

Callers updated to pass session.userId. The cookie-based fallback path
is gone — `actions/active-sprint.ts` and `actions/sprints.ts` will be
updated in the next commit (T-917).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(PBI-76): rewrite setActiveSprint callers to use settings

setActiveSprintAction, syncActiveSprintCookieAction, and the two
sprint-creation paths in actions/sprints.ts now write through
setActiveSprintInSettings (which also emits pg_notify for cross-tab
sync) instead of dropping a cookie. The action names keep the
'cookie' suffix in the user-visible API for now — clean rename can
come later.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(PBI-76): migration helper v2 — handle legacy cookies

Bumps marker version to 'v2'. buildMigrationPatch now also scans
document.cookie for `sp:*` (split-pane positions) and
`active_sprint_*` (active sprint per product) and lifts them into
layout.splitPanePositions / layout.activeSprints. clearLegacyStorage
replaces clearLegacyLocalStorage and clears both keys and cookies.
clearLegacyLocalStorage stays as a deprecated alias so the bridge
upgrade is a single rename.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* test(PBI-76): align tests with new SplitPane and active-sprint flow

- split-pane.test.tsx: seed positions via Zustand store instead of
  document.cookie; mock @/actions/user-settings so the prisma client
  is not transitively initialised in jsdom.
- backlog-split-pane.test.tsx: same action mock.
- sprint-dates.test.ts: add user.findUnique/update + $executeRaw
  mocks because createSprintAction now writes to user-settings.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-10 21:20:29 +02:00
Janpeter Visser
852945efa3
feat(PBI-76): migrate localStorage prefs to user-settings store (Phase 1) (#188)
* feat(PBI-76): one-shot localStorage→user-settings migration helper

Reads all legacy keys (sprint_pb_*, pbi_*, story_sort, debug-mode,
and dynamic *_filter_kind/*_filter_status for jobs columns) and
returns a typed UserSettings patch plus the keys to clear.
Idempotent via scrum4me:settings_migrated=v1 marker. Skips invalid
values silently so existing corrupt entries do not block migration.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(PBI-76): bridge runs one-shot localStorage migration

After hydrate, scans legacy localStorage keys via buildMigrationPatch
and, if any data is found, pushes one bulk patch to the server,
applies it locally, then removes the legacy keys. Demo accounts skip
the migration entirely. Cancellable on unmount to avoid setState on
unmounted component.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(PBI-76): migrate sprint-backlog to user-settings store

Replaces six useState+useEffect+localStorage flows with selectors
from useUserSettingsStore. Defaults are applied at the selector
level (filterStatus 'OPEN', sort 'code', etc) so the component
matches its previous behaviour. The collapsed Set is derived from
the persisted array, falling back to auto-collapse-DONE when no
preference exists yet. setPref calls are fire-and-forget — the
optimistic flow handles the local state update.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(PBI-76): migrate pbi-list to user-settings store

Same pattern as sprint-backlog: replaces local useState +
localStorage hydration/persist with selectors from
useUserSettingsStore. filterPopoverOpen blijft lokaal — die
was nooit gepersisteerd in pbi-list.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(PBI-76): migrate story-panel sort to user-settings store

Single pref (sortMode) — replaces sync localStorage useState
initializer with a selector. Default 'priority' applied at
the read site.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(PBI-76): migrate jobs-column to user-settings store

Per-instance filter state (kinds + statuses) now lives under
views.jobsColumns[storageKeyPrefix] in user-settings. Removes
the local CSV-encoding helpers — store keeps arrays natively.
A single persist() call writes both fields together so the
two arrays cannot drift in optimistic mid-flight updates.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(PBI-76): migrate debug-mode to user-settings store

DebugToggle reads debugMode from user-settings.devTools and
toggles via setPref. Removes the standalone stores/debug-store.ts
(no consumers left). Body classlist update only fires after the
store is hydrated to avoid a flash on initial paint.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* chore(PBI-76): remove unused readLocalStoragePref helper

No consumers left after migrating sprint-backlog, pbi-list,
story-panel, jobs-column, and debug-store to user-settings.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* test(PBI-76): mock user-settings action in backlog integration test

PbiList now imports the user-settings store, which transitively
loads actions/user-settings.ts → lib/prisma. The vitest jsdom
environment has no DATABASE_URL, so we add a mock alongside the
existing action mocks.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(docs): allow balanced parens in markdown link URLs

Previously the link-checker regex stopped at the first ')',
breaking on Next.js route-group paths like `app/(app)/...`. The
new regex matches one level of balanced parens inside the URL.

Caught by CI on PR #188 — pre-existing breakage from PBI-78 plan
doc that was already merged on main.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-10 15:13:39 +02:00
Janpeter Visser
a1e6ec35e5
feat(PBI-78): cost-analysis widget on insights page (#187)
* feat(PBI-78): cost-analysis data layer (T-902)

- New lib/insights/cost-analysis.ts with 5 query functions:
  getCostKpi, getCostByDay, getCostByModel, getCostByKind, getCacheEfficiency
- Period type: 7d | 30d | 90d | mtd
- Cost formula reused from token-stats.ts (input + output + cache + thinking)
- Cache savings: cache_read_tokens × (input_price - cache_read_price) / 1M
- Plan: docs/plans/PBI-78-cost-analysis-widget.md

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(PBI-78): cost-analysis UI component (T-903)

- New app/(app)/insights/components/cost-analysis.tsx
- Period selector (7d/30d/90d/MTD) via URL ?period= with useTransition + router.replace
- KPI strip: total cost, avg per day, cache savings, top model
- 2x2 chart grid: daily cost (BarChart), per-model + per-kind (vertical BarCharts), cache efficiency (PieChart)
- Empty state for kpi.jobCount === 0
- Uses MD3 tokens (var(--chart-N), var(--status-done))

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(PBI-78): wire CostAnalysisCard onto insights page (T-904)

- Parse ?period= from searchParams (default 30d, validates against 7d/30d/90d/mtd)
- Parallel-fetch 5 cost queries via Promise.all alongside existing widgets
- New "Cost analyse" section between Sprint Health and Plan-quality
- Existing TokenUsageCard ("Token gebruik" section) stays as sprint detail

verify (lint+typecheck+test) and build pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-10 12:59:45 +02:00
Janpeter Visser
f8693d126b
refactor(PBI-77): standaardiseer loading-skeletons rond shadcn Skeleton (#186)
* refactor(PBI-77): align TaskDialogSkeleton with entity-dialog-layout (T-899)

Use entityDialogContentClasses/HeaderClasses/BodyClasses/FooterClasses from
components/shared/entity-dialog-layout.ts instead of hand-copied class strings.
Header, body, and footer skeletons now mimic the actual TaskDialog form fields
(code, title, description, plan, priority, status, delete + cancel/save buttons).

Fixes mobile layout-shift: the shared content-classes include max-sm: fullscreen
modifiers that the previous hand-rolled subset missed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* refactor(PBI-77): extract BacklogPageSkeleton from 3 identical loadings (T-900)

The loading.tsx files for products/[id], sprint/[sprintId], and
sprint/[sprintId]/planning were 100% identical hand-rolled animate-pulse markup.
Extract the shape into components/loading/backlog-page-skeleton.tsx using the
shadcn <Skeleton> component, and re-export it from the three loading files.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* refactor(PBI-77): dashboard + settings loading on shadcn Skeleton (T-901)

Replace hand-rolled animate-pulse + bg-border divs with the shadcn <Skeleton>
component for consistent bg-muted color and pulse timing across all five
loading.tsx files. No layout-shift: heights, widths, and rounded radii are
preserved.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-10 12:59:08 +02:00
Janpeter Visser
a0e5867857
feat(PBI-76): user-settings DB-store infrastructure (Phase 0) (#185)
* docs(PBI-76): plan for user-settings DB-store

Persists view/filter prefs in User.settings (Json) instead of
localStorage. SSR-correct hydration, cross-tab sync via
LISTEN/NOTIFY + SSE, cross-device persistence.

Phased: 0=infra, 1=migrate flicker sources, 2=cookie consolidation.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(PBI-76): User.settings json column + migration

Adds JSONB column to users table for persistent user prefs.
Idempotent SQL — safe on databases where column already exists.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(PBI-76): user-settings types and merge helpers

Zod schema for User.settings shape (views/devTools), deep-merge
helper that replaces arrays and merges nested objects, and a
safe parser that returns defaults on invalid input.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(PBI-76): updateUserSettingsAction with notify

Validates patch via Zod, deep-merges with current settings in
a transaction, persists to DB, and emits pg_notify on
scrum4me_changes for cross-tab/cross-device sync. Demo accounts
get 403, unauthenticated 401, invalid input 422.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(PBI-76): user-settings zustand store with optimistic flow

Hydrate from prop (SSR-correct), setPref via path with optimistic
update + rollback on server error, applyServerPatch for SSE-driven
cross-tab updates. Demo accounts skip server-write entirely.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(PBI-76): SSE route for user-settings

User-scoped /api/realtime/user-settings stream that filters
scrum4me_changes notifications on kind=user_settings and matching
userId. Forwards the patch as a data: event so other tabs can
applyServerPatch without re-fetching settings.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(PBI-76): user-settings bridge mounted in app layout

Hydrates the zustand store with the user's persisted settings via
prop (SSR-correct, no flicker). Opens an EventSource to
/api/realtime/user-settings so changes from other tabs/devices
flow into the same store. Demo accounts skip the SSE subscription.

Layout now selects user.settings alongside the other user fields,
no extra DB roundtrip.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* test(PBI-76): user-settings lib/action/store coverage

22 vitest cases covering merge semantics (no mutation, array
replace, nested merge), Zod schema strictness, server action
auth/demo/validation paths, and the optimistic store flow
including rollback and demo-mode skip.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* chore(PBI-76): sync package-lock to v1.3.3

Lockfile drifted after @prisma/client reinstall during the
schema regenerate. No dependency changes — just the version
field tracking package.json bumped in #184.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-10 12:44:32 +02:00
Janpeter Visser
1f8cbacb0a
feat: shared backlog filter popover + sprint header polish (v1.3.3) (#184)
- Move sprint switcher into sprint header, centered between title and actions
- Extract BacklogFilterPopover as shared component used by sprint and product backlog
- Add sort options (code/priority/status) with single-pill asc/desc toggle
- Default sprint backlog status filter to OPEN, remove "alleen niet klaar" button
- Persist collapsed state and filter popover open in localStorage
- Fix hydration flicker: defer localStorage read to useEffect with prefsLoaded gate for writes
- Increase sprint switcher text size for readability

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-10 11:12:04 +02:00
Janpeter Visser
a9b53dedf0
feat(PBI-75): sprint task-edit client-side via workspace-store (#183)
Klik op een taak in het sprint-scherm opent de edit-dialog nu
client-side via setActiveTask op de sprint-workspace-store.
Geen URL-navigatie, geen volledige server re-render — alleen
GET /api/tasks/{id} voor het detail. SSE propageert server-saves
automatisch terug.

- TaskDialog: optionele onClose/onSaved callbacks (closePath
  optional gemaakt — backwards compatible)
- SprintTaskDialogMount: nieuwe client-component die
  selectActiveTask consumeert en TaskDialog rendert
- SprintUrlTaskSync: deeplink (?editTask=<id>) → store
- Sprint page: mounts toegevoegd, editTask searchParam +
  EditTaskLoader-Suspense verwijderd
- TaskList.openEditDialog roept setActiveTask aan ipv router.push
- Vitest integratie-test voor SprintTaskDialogMount

Out-of-scope (follow-up PBIs): newTask-flow, mobile, product-backlog.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-10 08:21:42 +02:00
Janpeter Visser
3b5cee823c
Load/render workspace alignment (#182)
* docs: plan load render workspace alignment

* fix: normalize workspace status hydration

* fix: avoid duplicate backlog hydration load

* refactor: use sprint store active story

* refactor: migrate solo to workspace store

* chore: stabilize verification ignores
2026-05-10 07:34:58 +02:00
Janpeter Visser
98ee05d458
feat(PBI-74): sprint-workspace-store (Story 9) (#181)
* feat(PBI-74): sprint-workspace-store skelet (Story 9 / T-879)

- stores/sprint-workspace/{types,store,selectors,restore}.ts conform
  product-workspace blueprint
- ContextSlice: activeProduct, activeSprintId, activeStoryId, activeTaskId
- EntitiesSlice: sprintsById, storiesById, tasksById
- RelationsSlice: sprintIdsByProduct, storyIdsBySprint, taskIdsByStory
- LoadingSlice met activeRequestId voor race-safe ensure*Loaded
- SyncSlice: realtimeStatus, lastResyncAt, resyncReason
- Realtime applyRealtimeEvent voor sprint/story/task entities + unknown-event
  fallback, parent-move handling, child-cleanup bij D op sprint/story
- Optimistic mutations: sprint-story-order, sprint-task-order, entity-patch
- LocalStorage hints (storage key sprint-workspace-hints) per product/sprint
- 45 unit-tests groen — verplicht 13 cases uit workspace-store.md §Tests

* feat(PBI-74): sprint hydratie + realtime SSE (Story 9 / T-880)

- app/api/realtime/sprint/route.ts: SSE-stream LISTEN/NOTIFY op
  scrum4me_changes, filter entity ∈ {sprint, story, task} per product_id;
  ready-event, heartbeat 25s, hard-close 240s
- lib/realtime/use-sprint-realtime.ts: client-hook met backoff-reconnect;
  ready-cycle telt; geen close op hidden; setRealtimeStatus
- lib/realtime/use-sprint-workspace-resync.ts: visibility + online triggers
  resyncActiveScopes('visible' | 'reconnect')
- components/sprint/sprint-hydration-wrapper.tsx: hydrateSnapshot via
  useEffect met fingerprint-check; mount realtime + resync
- app/(app)/products/[id]/sprint/[sprintId]/page.tsx: wrap SprintBoardClient
  in SprintHydrationWrapper; bouw SprintWorkspaceTask-shape voor
  tasksByStoryWorkspace en SprintHydrationData voor de wrapper

Schaduw-fase: useSprintStore blijft parallel werken in board components
totdat T-881 die migreert en T-883 de oude store opruimt.

* feat(PBI-74): migreer sprint-board componenten naar workspace-store (Story 9 / T-881)

- TaskList: leest tasks via selectTasksForStory met useShallow; DnD via
  applyOptimisticMutation('sprint-task-order') + settle/rollback
- SprintBacklogLeft: leest stories via selectStoriesForActiveSprint met
  useShallow; props 'stories' verwijderd
- SprintBoardClient: leest sprintStories uit selector i.p.v. lokale state;
  add/remove via direct setState met manuele snapshot-rollback;
  reorder via applyOptimisticMutation('sprint-story-order'); assignee-
  change via store entity-mutation; tasksByStory en sprintStoryIdList
  props weg
- app/(app)/.../sprint/[sprintId]/page.tsx: bouwt SprintHydrationData voor
  wrapper; geeft alleen non-store props door aan SprintBoardClient

useSprintStore wordt nergens meer geïmporteerd — alleen comment-referentie
in SprintHydrationWrapper. Cleanup van het bestand zelf in T-883.

Verify groen (671 tests, typecheck, lint clean).

* feat(PBI-74): read-routes voor sprint-workspace + cache-headers (Story 9 / T-882)

- GET /api/products/[id]/sprints — lijst sprints per product
  (ensureProductSprintsLoaded). force-dynamic, productAccessFilter,
  start_date/end_date naar ISO-date string.
- GET /api/sprints/[id]/workspace — sprint snapshot met sprint-meta,
  stories (incl. taskCount/doneCount/assignee), tasks gegroepeerd per
  story (ensureSprintLoaded). force-dynamic, productAccessFilter via
  product, status-vertaling via taskStatusToApi/storyStatusToApi.

Race-safe loaders (activeRequestId-guard), restore-flow (cascade-restore
via writeProductHint/writeSprintHint/writeStoryHint/writeTaskHint),
resync-laag (useSprintWorkspaceResync visibility + online), unknown-event
filter (isUnknownEntityEvent → resyncActiveScopes('unknown-event')) zijn
allemaal in T-879/T-880 al ingebouwd; T-882 sluit het loop met de
ontbrekende API-endpoints + cache-headers (cache: 'no-store' op fetches,
force-dynamic op routes).

* feat(PBI-74): cleanup oude sprint-store (Story 9 / T-883)

- rm stores/sprint-store.ts — alle componenten lezen nu via
  useSprintWorkspaceStore (T-881 voltooide imports-migratie)
- update SprintHydrationWrapper-comment: schaduw-fase referenties
  verwijderd

Verify: 671 tests groen, typecheck clean, build groen.
Grep useSprintStore = 0.

* docs(PBI-74): update Story 9 status in implementatieplan (T-884)

- Frontmatter: ready-to-execute → in-progress; revision 1 → 2;
  last_updated 2026-05-09 → 2026-05-10
- Stories-tabel: kolom Status toegevoegd (Stories 1-8 DONE via PR #180,
  Story 9 met T-884 op review)
- §Story 9: per-taak status + acceptatie-checklist voor T-884 manuele
  staging-checks
- Aanbeveling-blokje: noteert dat Story 9 vroeger gestart is dan het
  ontwerpdoc adviseerde
2026-05-10 06:53:04 +02:00
Janpeter Visser
5df04feb11
feat(PBI-74): Zustand product-workspace rearchitecture (Stories 1-8) (#180)
* feat(PBI-74): product-workspace store skelet + test-infra (Story 1)

Skelet voor de nieuwe `product-workspace-store` die op termijn de gefragmenteerde
`backlog-store`/`planner-store`/`selection-store`/`product-store` vervangt. Deze
PR levert alleen het skelet + tests; UI-consumers worden in latere stories
omgezet.

- vitest naar jsdom + tests/setup.ts (MemoryStorage, default fetch-stub) — G6/G8
- stores/product-workspace/{types,store,selectors,restore}.ts — immer-middleware,
  alle slices en acties (hydrate, setActive*, ensure*Loaded met activeRequestId-
  guard, applyRealtimeEvent, resyncActiveScopes/loadedScopes, optimistic
  mutations). Restore-wiring in setters volgt in Story 4 (T-857/T-858).
- selectors gebruiken module-level EMPTY refs (G1) en documenteren useShallow-
  vereiste (G2)
- 34 nieuwe unit-tests dekken §Testing setup-checklist uit het ontwerp:
  hydrateSnapshot, selection-cascade, applyRealtimeEvent (I/U/D + parent-move +
  ander-product + unknown-entity → resync), delete-cleanup, race-safe loaders,
  ensureTaskLoaded _detail-flag, resyncActiveScopes ensure-keten, restore-hints
  read/write/clear, optimistic mutation rollback/settle/SSE-echo idempotent
- docs/api/rest-contract.md: audit-sectie met de vier ontbrekende
  ensure*Loaded-endpoints (worden toegevoegd in Story 7 / T-870)

Refs: PBI-74, ST-1318, T-837..T-843
Bron-ontwerp: docs/plans/zustand-store-rearchitecture.md
Implementatieplan: docs/plans/zustand-workspace-store-implementation.md

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(PBI-74): dual-dispatch hydratie + realtime naar workspace-store (Story 2)

Story 2 — schaduw-fase: BacklogHydrationWrapper en useBacklogRealtime voeden
nu ook de nieuwe product-workspace-store, terwijl de oude useBacklogStore /
useProductStore leidend blijft voor componenten. Story 3 verschuift consumers
één voor één; Story 8 ruimt de oude stores op.

- T-844: BacklogHydrationWrapper roept naast useBacklogStore.setInitialData
  ook useProductWorkspaceStore.hydrateSnapshot aan. Productname-prop optioneel
  toegevoegd voor activeProduct-context.
- T-845: useBacklogRealtime onmessage dispatcht events naar zowel oude store
  (applyChange) als nieuwe store (applyRealtimeEvent). Geen wijziging aan
  reconnect/visibility — Story 5.
- T-846: dev-only logWorkspaceFingerprint helper vergelijkt counts tussen
  oude en nieuwe store na hydrate en na elk realtime-event. console.warn bij
  mismatch; opt-in debug log via NEXT_PUBLIC_DEBUG_WORKSPACE_FINGERPRINT=1.
  Bestand TODO-marked voor verwijdering in Story 8 (T-878).
- T-847: SetCurrentProduct schrijft naast oude useProductStore ook
  useProductWorkspaceStore.setActiveProduct({id, name}); cleanup cleart beide.
  setActiveProduct triggert ensureProductLoaded — fetch-stub tot Story 7
  (T-870) de LIST-endpoints toevoegt.

Verify: lint+typecheck clean, 636/636 tests groen (geen UI-regressie omdat
oude store leidend blijft).

Refs: PBI-74, ST-1319, T-844..T-847

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(PBI-74): migreer backlog-componenten naar workspace-store (Story 3)

Story 3 verplaatst alle UI-consumers van de oude vier stores
(useBacklogStore/usePlannerStore/useSelectionStore/useProductStore) naar de
nieuwe product-workspace-store. De oude stores blijven nog bestaan voor
hydration-wrapper en realtime-hook (dual-dispatch); Story 8 ruimt ze op.

- T-848 backlog-split-pane.tsx: leest activePbiId/activeStoryId uit
  context-slice (primitives, geen useShallow nodig).
- T-849 pbi-list.tsx: selectVisiblePbis(useShallow); DnD via
  applyOptimisticMutation('pbi-order' + optionele 'entity-patch' bij
  cross-priority drag), met settle/rollback per server-result.
- T-850 story-panel.tsx: selectStoriesForActivePbi(useShallow); DnD via
  applyOptimisticMutation('story-order' + entity-patch bij priority change).
- T-851 task-panel.tsx: selectTasksForActiveStory(useShallow); DnD via
  applyOptimisticMutation('task-order'); detail-view (ensureTaskLoaded +
  isDetail) zit in de task-dialog (apart component, niet in deze lijst).
- T-852 start-sprint-button.tsx: selectActivePbi + selectStoriesForActivePbi
  voor free-story count.
- T-853 set-current-product.tsx: alleen workspace-store.setActiveProduct
  (oude useProductStore-import verwijderd).
- T-854 G1/G2-audit: alle nieuwe selectors gebruiken module-level EMPTY
  refs (G1) en useShallow voor lijsten (G2). Geen 'Maximum update depth'-
  warnings tijdens npm test.
- T-855 tests bijgewerkt: backlog-split-pane.test, task-panel.test,
  integration.test gebruiken nu setState op workspace-store (helpers
  resetWorkspace/setActiveStoryAndTasks/selectPbi/selectStory).

Verify: lint+typecheck clean, 636/636 tests groen. UI-consumers van
oude stores zijn nu nul (uitgezonderd dual-dispatch in hydration-wrapper en
realtime-hook + dev-fingerprint-helper, die in Story 8/T-873/T-878 verdwijnen).

Refs: PBI-74, ST-1320, T-848..T-855

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(PBI-74): race-safe loaders + restore-hints + URL-prioriteit (Story 4)

- T-856: activeRequestId-guard zat al in store.ts uit Story 1; bevestigd door
  de race-safety test (in-flight ensurePbiLoaded mag niet overschrijven).
- T-857: restore-hint flow toegevoegd in setActiveProduct/setActivePbi/
  setActiveStory. Async chain: await ensureXxxLoaded → guard check →
  readHints → valideer hint via entities.byId → setActiveYyy(hint).
  Geen setTimeout-trick — chain is alleen await-based.
- T-858: writeProductHint/writePbiHint/writeStoryHint/writeTaskHint
  aangeroepen direct na set(...) zodat de hint-persistentie altijd
  consistent is met de in-store selectie.
- T-859: nieuwe components/backlog/url-task-sync.tsx — leest
  ?editTask=&lt;id&gt; uit useSearchParams, schrijft de hint en roept
  setActiveTask aan zodat de URL wint boven een eerder gepersisteerde
  task-hint. Gemount in beide product-pages (desktop + mobile) binnen
  BacklogHydrationWrapper.
- T-860: 6 nieuwe vitest-cases — 4 voor hint-persist per setter, 2 voor de
  restore-flow chain (hint die niet in entities zit wordt genegeerd; hint
  die wel in entities zit wordt toegepast). Bestaande race-safety test
  blijft groen.

Verify: lint+typecheck clean, 642/642 tests groen.

Refs: PBI-74, ST-1321, T-856..T-860

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(PBI-74): hidden-tab + reconnect resync (Story 5)

Per ontwerp samen in één commit zodat geen vangnet wegvalt zonder vervanging.

- T-861: useBacklogRealtime sluit niet meer op visibilitychange hidden;
  EventSource blijft open zolang browser/netwerk dit toelaten. Reconnect bij
  netwerkfout blijft via backoff. visibilitychange fungeert nog wel als
  re-connect-trigger als de stream tussentijds is gesloten (b.v. 240s
  hard-close server-side).
- T-862: 'ready'-event-handler telt connect-cycles. De eerste 'ready' is de
  initial connect (geen resync). Bij latere 'ready' (post-reconnect) wordt
  resyncActiveScopes('reconnect') aangeroepen om gemiste events op te halen.
- T-863: nieuwe lib/realtime/use-workspace-resync.ts — luistert op
  document.visibilitychange (hidden→visible) en window.online; dispatcht
  resyncActiveScopes('visible') resp. 'reconnect'. Mounted in
  BacklogHydrationWrapper na useBacklogRealtime.
- T-864: 4 nieuwe vitest-cases voor useWorkspaceResync (jsdom): visible→
  visible event, online event, hidden negeren, cleanup-bij-unmount.

Daarnaast lint-cleanup: ongebruikte 'order'-variabelen in pbi-list en
story-panel weggehaald.

Verify: lint+typecheck clean, 646/646 tests groen.

Refs: PBI-74, ST-1322, T-861..T-864

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(PBI-74): unknown-event fallback tests (Story 6)

T-865 (isUnknownEntityEvent filter) en T-866 (resync-trigger in
applyRealtimeEvent) zijn al in Story 1 geïmplementeerd in store.ts;
deze story breidt de test-coverage uit met expliciete negatieve cases
voor het type-veld noise pattern.

T-867 — 5 nieuwe vitest-cases:
- unknown entity met ANDER product_id → geen resync
- claude_job_status (type) → geen resync
- worker_heartbeat (type) → geen resync
- claude_job_enqueued (type) → geen resync
- payload zonder entity en zonder type → genegeerd
- question-entity (entity-veld, geen type, niet pbi/story/task) → resync trigger

Verify: lint+typecheck clean, 651/651 tests groen.

Refs: PBI-74, ST-1323, T-865..T-867

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(PBI-74): cache-headers + LIST endpoints (Story 7)

- T-868: cache: 'no-store' was al ingebouwd in fetchJson helper (Story 1).
  Bevestigd door bestaande ensureProductLoaded test die de fetch-init
  controleert.
- T-869: force-dynamic toegevoegd op alle vier nieuwe LIST-endpoints.
- T-870: vier nieuwe routes voor ensure*Loaded:
  - GET /api/products/:id/backlog → ProductBacklogSnapshot
  - GET /api/pbis/:id/stories → BacklogStory[]
  - GET /api/stories/:id/tasks → BacklogTask[]
  - GET /api/tasks/:id (nieuwe handler naast bestaande PATCH) → TaskDetail
    met _detail: true marker
  Auth via authenticateApiRequest (Bearer of iron-session); access-control
  via productAccessFilter (gebruiker is owner of member van het product).
  Statussen worden via taskStatusToApi/storyStatusToApi/pbiStatusToApi
  vertaald naar lowercase API-vorm.
- T-871: SSE-route /api/realtime/backlog stuurt al ready-event direct na
  LISTEN (regel 106) — geen wijziging nodig.

Verify: lint+typecheck clean, 651/651 tests groen.

Refs: PBI-74, ST-1324, T-868..T-871

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(PBI-74): oude stores opruimen (Story 8)

Workspace-store is nu de enige bron voor product-backlog client-state. De
vier voorgangers en de dual-dispatch-infrastructuur zijn verwijderd.

- T-872: grep over codebase op useBacklogStore/usePlannerStore/
  useSelectionStore/useProductStore is leeg.
- T-873..T-876: stores/{backlog,planner,selection,product}-store.ts deleted.
- T-877: __tests__/realtime/payload-contract.test.ts en
  __tests__/api/backlog-realtime.test.ts deleted — pbi/story/task I|U|D
  payload-handling wordt al gedekt door
  __tests__/stores/product-workspace/store.test.ts (incl. parent-move,
  idempotent inserts, delete-cleanup).
- T-878: lib/realtime/dev-workspace-fingerprint.ts deleted, dual-dispatch
  uit BacklogHydrationWrapper en lib/realtime/use-backlog-realtime.ts
  weggehaald. stores/products-store.ts (lijst van producten ≠ active
  product) blijft ongewijzigd.

Bijwerkingen:
- BacklogPbi en BacklogStory types in components/backlog/story-panel.tsx en
  components/sprint/sprint-backlog.tsx krijgen sort_order zodat ze met de
  workspace-types overeenkomen.
- Server-pages /products/[id]/page.tsx (desktop+mobile) en
  /products/[id]/sprint/[sprintId]/page.tsx selecteren sort_order op story
  en mappen het door in de hydration-payload.

Verify: lint+typecheck clean, 626/626 tests groen (verlies van 25 redundante
oude-store tests; workspace-store tests dekken hetzelfde gedrag).

Refs: PBI-74, ST-1325, T-872..T-878

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* docs(PBI-74): richtlijn workspace-store + realtime patroon

Documenteert het patroon dat in Stories 1-8 is opgeleverd, zodat een
volgende workspace-store (sprint, of een nieuwe bounded context) hetzelfde
recept volgt.

- docs/patterns/workspace-store.md (nieuw): wanneer een workspace-store, de
  vijf state-slices, selectors-regels (G1/G2), race-safe ensure*Loaded met
  activeRequestId-guard (G4), SSE-hook + applyRealtimeEvent met
  unknown-event filter, hidden-tab + reconnect resync via
  useWorkspaceResync, restore-hint flow met await-chain en URL-prioriteit,
  optimistic mutations (applyOptimisticMutation/rollback/settle), API
  endpoint-vereisten (force-dynamic, cache: no-store), test-setup met
  MemoryStorage + originalActions snapshot + mockImplementation, gotchas
  G1-G8 als comment-template, en het 8-staps migratiepad.
- docs/patterns/zustand-optimistic.md: bijgewerkt voor de nieuwe
  workspace-store API; verwijst voor het bredere patroon naar
  workspace-store.md. Voorbeelden voor pbi-order + entity-patch.
- CLAUDE.md: patterns quickref aangevuld met workspace-store-rij.

Verify: typecheck clean.

Refs: PBI-74

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(PBI-74): solo + notifications hooks volgen ook hidden-tab/resync patroon

Het uitgangspunt van PBI-74 (robuust tegen gemiste SSE-events, hidden tabs
en onbekende notify-vormen) gold universeel — niet alleen voor
product-workspace. use-solo-realtime en use-notifications-realtime hadden
nog dezelfde bug die use-backlog-realtime in Story 5 al opgelost kreeg:
sluit stream op hidden, geen resync.

Reproductie (zoals gemeld): solo-screen open in tab A, product-backlog
open in tab B; bewerk task-title in tab B → tab A's solo-SSE was gesloten
(hidden) en kreeg het NOTIFY-event nooit. Tab terug naar solo →
EventSource reconnect maar geen resync → oude title persisteert. Postgres
NOTIFY heeft geen replay, dus zonder resync zijn die events permanent
verloren.

Fix in beide hooks (zelfde patroon als Story 5 voor backlog):
- Stream blijft open op visibilitychange hidden — geen close() meer.
- Bij hidden→visible én bij window 'online': router.refresh() zodat de
  server-component opnieuw fetcht en de initial-state-prop ververst (wat
  voor solo de tasks-record reset via initTasks; voor notifications de
  questions-bel-state).
- Bij latere 'ready'-events na reconnect (use-solo-realtime): zelfde
  router.refresh() trigger zodat we niet vertrouwen op alleen het
  visibility-pad.

Verify: lint + typecheck clean, 626/626 tests groen.

Refs: PBI-74

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* docs: fix broken links in research-repo plan

docs/plans/lees-de-readme-md-validated-book.md beschrijft een research-
repo migratiepad. De links waren geschreven vanuit het research-repo-
perspectief (paden als stores/data-store.ts, ../Scrum4Me/CLAUDE.md,
docs/plans/zustand-store-rearchitecture.md zonder relative-prefix), wat
de doc-link-checker hier laat falen.

- Header-note toegevoegd dat het document voor de research-repo is.
- Interne refs (zustand-store-rearchitecture.md, CLAUDE.md) → relatieve
  paden die in deze repo wél resolven (./zustand-..., ../../CLAUDE.md).
- Research-repo-only refs (stores/data-store.ts,
  hooks/use-event-stream.ts, components/*-select.tsx, etc.) → inline
  code-tags met "(research-repo)" suffix; de link-checker slaat ze over
  en de leesbaarheid blijft.

Verify: npm run docs:check-links → ✓ All doc links valid (118 files).

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-10 02:25:19 +02:00
0d126695db docs: add plans and recommendations
- docs/plans/Local github setup.md
- docs/plans/lees-de-readme-md-validated-book.md
- docs/plans/zustand-store-rearchitecture.md
- docs/recommendations/beelink-ubuntu-scrum4me-server-caveman-plan.md
- docs/recommendations/claude-vm-job-flow-git-strategy.md
- docs/INDEX.md updated

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 22:54:23 +02:00
Janpeter Visser
d292e445d9
Sprint: Verbeteren debug mode (#179)
* feat(PBI-49): add debugProps helper + Vitest test

Adds lib/debug.ts with debugProps(id, component, file) that returns
data-debug-id and data-debug-label attrs in dev mode, empty object in
production. Adds __tests__/lib/debug.test.ts covering both modes.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* docs(PBI-49): add debug-id pattern doc + CLAUDE.md reference

Adds docs/patterns/debug-id.md documenting the named-component boundary
rule (6 punten), helper-voorbeeld, skip-criteria en motivatie voor
handmatige pad-argumenten. Voegt verwijzing toe aan CLAUDE.md
patterns-tabel.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* refactor(PBI-49): migrate 17 shared/ components to debugProps helper

Replace hardcoded data-debug-id + data-debug-label attribute pairs with
{...debugProps(id, component, file)} spread in all 17 components/shared/
files. Existing debug-ids preserved unchanged.

* feat(PBI-49): add debugProps to backlog/, sprint/, solo/ components

* feat(PBI-49): add debugProps to jobs/ + ideas/ components

* feat(PBI-49): add debugProps to products/ + settings/ + notifications/ components

* feat(PBI-49): add debugProps to admin/ + dashboard/ + dialogs/ + mobile/ + split-pane/

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(PBI-49): use attr(data-debug-id) for debug tooltip in globals.css

* refactor(PBI-49): remove data-debug-label from debugProps helper + test

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* refactor(PBI-49): strip unused component/file args from debugProps in shared/

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(PBI-49): add BEM sub-element data-debug-id to StatusBar, NavBar, PanelNavBar

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(PBI-49): add BEM sub-element data-debug-id to components/sprint/*

- new-sprint-dialog: __submit on submit button
- sprint-backlog: __list on SprintBacklogLeft + SprintBacklogRight scroll areas
- sprint-board-client: root wrapper div (display:contents) + __drag-overlay
- sprint-header: __title on goal button, __dates on dates button, __actions on action cluster
- sprint-run-controls: root on controls div, __start/__cancel on action buttons; __blockers-dialog on dialog content
- start-sprint-button: root on trigger button, __dialog on dialog content, __submit on submit button
- sync-active-sprint-cookie: no debug-id (returns null, side-effect only), comment added

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(PBI-49): add BEM sub-element data-debug-id to components/backlog/*

* feat(PBI-49): add BEM sub-element data-debug-id to components/ideas/*

* feat(PBI-49): add BEM sub-element data-debug-id to components/dashboard/* + components/markdown.tsx

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(PBI-49): add BEM sub-element data-debug-id to new-product-button

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(PBI-49): add BEM sub-element data-debug-id to components/solo/*

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(PBI-49): add BEM sub-elements to nav-status-indicators

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(PBI-49): add BEM sub-element data-debug-id to components/jobs/*

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(PBI-49): add BEM sub-element data-debug-id to components/products/*

* feat(PBI-49): add BEM sub-element data-debug-id to components/notifications/*

- answer-modal: __content (scroll area), __submit (footer)
- notifications-bridge: skip comment (bridge, non-rendering wrapper)
- notifications-realtime-mount: skip comment (returns null)
- notifications-sheet: __header, __items (questions list)
- push-toggle: __switch (button), __label (button text) on subscribed/unsubscribed states

* feat(PBI-49): add BEM sub-element data-debug-id to components/settings/*

- leave-product-button: root only (single-button component)
- min-quota-editor: __input (number input), __save (save button)
- profile-editor: __username (bio/short-description input), __save (submit)
- role-manager: __roles (checkbox list), __add (save button)
- token-manager: __tokens (active tokens list), __generate (create button)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(PBI-49): add BEM sub-element data-debug-id to admin, auth, dialogs, entity-dialog, mobile, split-pane

* docs(PBI-49): add debug-labels BEM pattern doc + CLAUDE.md entry

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-09 22:46:29 +02:00
Janpeter Visser
ce43f7720a
chore: bump 1.3.1 → 1.3.2 (#177)
* chore: bump 1.3.0 → 1.3.1 (force Vercel-redeploy)

Triggert Vercel-rebuild zodat lib/job-config.ts (KIND_DEFAULTS uit #171
en permission_mode-fix uit #172) actief wordt in de live webapp. De
enqueue-laag (lib/job-config-snapshot.ts) snapshot dan correct
permission_mode='acceptEdits' voor idea-kinds + PLAN_CHAT.

Symptoom dat dit oplost: in een lokale smoke-test (na merge van #171
en #172) bleek dat een vers enqueued IDEA_MAKE_PLAN-job nog
requested_permission_mode='plan' kreeg — wat duidt op een Vercel-deploy
die nog op de oude bundle stond. Met deze bump wordt de redeploy
geforceerd.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* chore: bump 1.3.1 → 1.3.2

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 17:22:32 +02:00
Janpeter Visser
6756450131
Sprint: rerun jobs (#176)
* feat(PBI-jobs): voeg isDemo-prop door aan JobsBoard en JobDetailPane

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(PBI-jobs): voeg 'Opnieuw starten'-knop toe aan JobDetailPane

Toont een restart-knop voor jobs met status FAILED, CANCELLED of SKIPPED.
Gebruikt useTransition voor loading-state en DemoTooltip voor demo-modus.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* test(PBI-jobs): voeg component-test toe voor JobDetailPane restart-knop

Test: knop zichtbaar voor FAILED, verborgen voor DONE, aanroep met juist id, disabled in demo-modus.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* docs(PBI-jobs): voeg F-14 restart-acceptatiecriteria toe aan functional.md

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-09 17:19:47 +02:00
Janpeter Visser
71319e629d
feat(PBI-71): UX-fix 'lege sprint' + sprint-switch data-refresh (#175)
- StartSprintButton dialog toont 3-state banner: info met accurate vrije-
  stories count + PBI-context, of waarschuwing als geen PBI geselecteerd
  is, of waarschuwing als de geselecteerde PBI 0 vrije stories heeft
- Voeg sprint_id toe aan BacklogStory/Story/SprintStory + select in PB-
  pagina's en sprint-board mappings, zodat de banner accuraat kan tellen
- createSprintAction: revalidatePath met 'layout' flag voor consistency
  met createSprintWithPbisAction (top-nav 'Sprint' link ververst direct)

Sprint-switch data-refresh op alle relevante pagina's:

- BacklogHydrationWrapper: fingerprint-based re-hydratie zodat PB-data
  na router.refresh opnieuw uit nieuwe initialData komt (was: useEffect
  met lege deps draaide alleen 1x)
- SprintBoardClient: key={sprint.id} forceert remount bij sprint-switch
  zodat lokale sprintStories/sprintStoryIds-state vers ge-init wordt
- Solo (desktop + mobile): gebruik resolveActiveSprint(id) ipv eerste
  OPEN-sprint, plus key={sprint.id} op SoloBoard voor remount

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 16:27:24 +02:00
Janpeter Visser
35e37dac09
feat(ST-006): voeg restartClaudeJobAction toe aan actions/claude-jobs.ts (#174)
- Exporteert restartClaudeJobAction(jobId) die FAILED/CANCELLED/SKIPPED jobs atomair reset naar QUEUED
- Valideert auth, demo-blokkade, ownership en restartbare status
- Gebruikt prisma.$transaction: claudeJob.updateMany + conditionale sprintTaskExecution.updateMany reset
- Verstuurt pg_notify claude_job_status zodat Jobs-pagina via SSE ververst
- Unit-tests: happy-path (FAILED/CANCELLED/SKIPPED), demo-blokkade, not-found, niet-restartbare status, race-conditie en sprint sub-task reset
2026-05-09 13:59:06 +02:00
Janpeter Visser
3c773421da
chore: bump 1.3.0 → 1.3.1 (force Vercel-redeploy) (#173)
Triggert Vercel-rebuild zodat lib/job-config.ts (KIND_DEFAULTS uit #171
en permission_mode-fix uit #172) actief wordt in de live webapp. De
enqueue-laag (lib/job-config-snapshot.ts) snapshot dan correct
permission_mode='acceptEdits' voor idea-kinds + PLAN_CHAT.

Symptoom dat dit oplost: in een lokale smoke-test (na merge van #171
en #172) bleek dat een vers enqueued IDEA_MAKE_PLAN-job nog
requested_permission_mode='plan' kreeg — wat duidt op een Vercel-deploy
die nog op de oude bundle stond. Met deze bump wordt de redeploy
geforceerd.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 12:47:38 +02:00
Janpeter Visser
c2633695d2
fix(KIND_DEFAULTS): permission_mode acceptEdits voor idea-kinds + PLAN_CHAT (#172)
* fix(KIND_DEFAULTS): permission_mode acceptEdits voor idea-kinds + PLAN_CHAT

Spiegel van scrum4me-mcp PR #40. Symptoom: IDEA_GRILL job IDEA-047 werd
3x geclaimd, Claude liep telkens succesvol (exit 0 na 600-900s) maar
deed nooit update_job_status('done'). Lease verliep, retry_count >= 2 →
status FAILED met "agent did not complete job within 2 attempts".

Root cause: KIND_DEFAULTS.permission_mode='plan' voor idea-kinds en
PLAN_CHAT. In autonome batch-mode wacht plan-mode op een human "go" na
elke planning-fase — geen mens in de loop in deze runner-context.

Fix:
- IDEA_GRILL.permission_mode: plan → acceptEdits
- IDEA_MAKE_PLAN.permission_mode: plan → acceptEdits
- PLAN_CHAT.permission_mode: plan → acceptEdits
- PLAN_CHAT.allowed_tools krijgt mcp__scrum4me__update_job_status (ontbrak)

De allowed_tools-lijsten doen de echte sandboxing (geen Bash, geen Edit
voor IDEA_GRILL/PLAN_CHAT). Plan-mode's "veiligheid" wordt al door
tool-allowlists geleverd; acceptEdits is hier puur om Claude door zijn
eigen update_job_status loop te laten lopen zonder approval-wachttijd.

Plus: docs/runbooks/{job-model-selection,worker-idempotency}.md tabellen
bijgewerkt. last_updated note in job-model-selection.md.

Verify: 587 tests in 78 files passed (incl. nieuwe lib/job-config tests).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* chore: remove .claude/scheduled_tasks.lock per ongeluk meegecommit

Lokale tooling-lock-file van de cowork-skills, hoort niet in de repo.

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 11:33:03 +02:00
Janpeter Visser
00c5045558
feat(PBI-4/ST-006): mirror job-config naar webapp + runbook-fix CLI-flags (#171)
Spiegelt de scrum4me-mcp wijzigingen naar de Scrum4Me web-app zodat
enqueue-laag (lib/job-config-snapshot.ts) en claim-laag dezelfde
defaults gebruiken. Plus runbook-correctie van een eerder gedocumenteerde
maar niet-bestaande Claude CLI-flag.

- T-25: lib/job-config.ts — mapBudgetToEffort export + KIND_DEFAULTS
  .allowed_tools voor TASK/SPRINT/IDEA_GRILL/IDEA_MAKE_PLAN omgezet
  naar expliciete lijsten zonder wait_for_job/check_queue_empty/
  get_idea_context. Comment-block over CLI-flag-mapping en sync met
  scrum4me-mcp.
- T-26: docs/runbooks/worker-idempotency.md sectie "Config doorgeven aan
  Claude Code (PBI-67)" herschreven. --thinking-budget vervangen door
  --effort (mapping-tabel toegevoegd); --max-turns geschrapt (CLI heeft
  die flag niet — audit-only). Sectie "Wie doet wat in de runner-
  architectuur" toegevoegd.
- T-27: docs/runbooks/job-model-selection.md — notes over max_turns,
  thinking_budget en allowed_tools onder de matrix. Nieuwe sectie
  "Runner-architectuur" met verwijzing naar plan + worker-idempotency.
- T-28: __tests__/lib/job-config.test.ts (nieuw) — 22 tests:
  mapBudgetToEffort grenswaarden + KIND_DEFAULTS.allowed_tools structurele
  checks + cascade regression.

Plus: docs/plans/queue-loop-extraction.md (geschreven in plan-mode,
nu gepubliceerd in repo).

Verify: lint OK, typecheck OK, 587 tests in 78 files passed.
Build niet lokaal uitgevoerd (vereist DATABASE_URL voor "Collecting page
data" — diff raakt geen API-route).

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 07:11:52 +02:00
10c52e8b8f chore: remove prisma-erd-generator and stale erd refs
Vercel detecteert @prisma/client en runt automatisch `prisma generate`
zonder --generator filter. Daardoor probeerde de erd-generator op Vercel
te draaien en faalde op libnss3.so (puppeteer/Chrome niet beschikbaar in
de build container). Cascading: de Prisma-client werd niet ge-update,
runtime kreeg oude enum-waarden (ACTIVE i.p.v. OPEN).

ERD is dev-only documentatie en niet meer in productie nodig. Generator
+ dependency + npm scripts + de gegenereerde svg verwijderd. README,
prisma-client pattern en architecture docs bijgewerkt.

Build script blijft `prisma generate && next build` zodat de client ook
bij Vercel build-cache-hits opnieuw wordt gegenereerd.
2026-05-08 14:45:39 +02:00
Janpeter Visser
79005dc777
Sprint: regril (#170)
* ST-cmowjelb1: Parser: bestand-relatieve regel + hint-detectie in YAMLParseError-tak

- Voeg `hint?: string` toe aan PlanParseError type
- Bereken bestand-relatief regelnummer (yamlLine + 1 voor de openings-`---`)
- Detecteer markdown-patronen (numbered/bullet lijst) op de offending regel
- Zet Nederlandstalige hint bij markdown-match
- Render hint als "Tip: …" onder het foutbericht in IdeaMdEditor

* ST-cmowjeq3q: UI: render hint apart onder error-message in IdeaMdEditor

Vervang <span block mt-0.5 text-status-blocked/80> door <div mt-1 text-foreground/80>
voor de Tip-hint per plan-spec (MD3-token, geen status-kleur).

* ST-cmowjewfg: Test: parser geeft hint bij markdown-in-frontmatter

Voeg twee Vitest-cases toe:
- hints when markdown sneaks into frontmatter: fixture met [unclosed op
  een genummerde markdown-regel triggert YAMLParseError op die regel
  (plain lijst zonder unclosed flow parset als geldig YAML)
- omits hint for non-markdown yaml errors: unclosed bracket zonder
  markdown-patroon geeft geen hint
2026-05-08 13:22:10 +02:00
Janpeter Visser
8c63ba377d
feat(PBI-67): model + mode-selectie per ClaudeJob-kind (#169)
* feat(PBI-67/ST-1297): datamodel-velden voor job-model-selectie

Voegt 8 nieuwe optionele velden toe verspreid over Product, Task en
ClaudeJob ten dienste van de override-cascade:

  task.requires_opus → job.requested_* → product.preferred_* → kind-default

Bestaande rijen krijgen NULL (Product/ClaudeJob) of false (Task) en
vallen daarmee terug op de kind-defaults uit de resolver (ST-1298).

Migration is additief: alleen ALTER TABLE ADD COLUMN, geen RENAME of
DROP. Bestaande factories en seed-script blijven werken zonder
aanpassing omdat alle nieuwe velden default-waardes hebben.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(PBI-67/ST-1299): job-config snapshot bij enqueue + worker-flag-runbook

T-789: Snapshot van resolved JobConfig in ClaudeJob.requested_*
bij elke job-creatie. Helper in lib/job-config-snapshot.ts laadt
product (preferred_*) en task (requires_opus) en draait de resolver
uit lib/job-config.ts (mirror van scrum4me-mcp/src/lib/job-config.ts —
zelfde matrix, sync-comment in bestand). Toegepast op alle 5
enqueue-locaties:

  - actions/user-questions.ts          (PLAN_CHAT)
  - actions/sprint-runs.ts × 3         (SPRINT_IMPLEMENTATION x2,
                                        TASK_IMPLEMENTATION loop)
  - actions/ideas.ts                   (IDEA_GRILL / IDEA_MAKE_PLAN)

Test-mocks uitgebreid met product.findUnique en task.findUnique zodat
de helper bij unit tests veilig terugvalt op kind-defaults (alle 563
tests groen).

T-790: Sectie 'Config doorgeven aan Claude Code' toegevoegd aan
docs/runbooks/worker-idempotency.md met CLI-flag-mapping en de
verwachte aanroep per kind. Forward-link naar
docs/runbooks/job-model-selection.md (volgt in T-794).

Plus: docs/plans/job-model-selection.md (de approved plan-doc).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(PBI-67/ST-1300): cost-attribution voor thinking-tokens + admin UI

T-792: token-stats + token-history rekenen actual_thinking_tokens nu
mee in de totale kosten (tegen input-rate, conform Anthropic billing).
COALESCE-veilig zodat oude rijen 0 bijdragen i.p.v. NaN. Nieuwe export
`getTokenStatsByKind` aggregeert tokens en kosten per ClaudeJob.kind
zodat we relatieve uitgaven van IDEA_GRILL/IDEA_MAKE_PLAN/PLAN_CHAT/
TASK_IMPLEMENTATION/SPRINT_IMPLEMENTATION kunnen zien.

T-793: admin/jobs Kosten-tabel toont:
  - Nieuwe kolom 'Thinking' (aantal verbruikte thinking-tokens)
  - Mismatch-marker (rood) als requested_model afwijkt van actuele
    model_id — duidt op een worker die de CLI-flag niet doorgaf.
    Tooltip toont aangevraagd model. Geen Sentry/log-noise.

Page-level cost-berekening volgt dezelfde formule (input_price ×
thinking_tokens). 563 tests groen.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* docs(PBI-67/ST-1301): runbook + CLAUDE.md updates voor model/mode-selectie

T-794: Nieuwe runbook docs/runbooks/job-model-selection.md met
override-cascade, kind-default-matrix, override-voorbeelden,
auditspoor en cost-attribution-formule. 107 regels.

T-795: CLAUDE.md hardstop-bullet voor 'Model/mode per ClaudeJob'
(verwijst naar nieuwe runbook) + patterns-quickref-rij voor
job-config resolver. CLAUDE.md blijft 139 regels (≤ 150).

T-796: docs:check-links groen — 108 files, geen broken links. Twee
externe-repo verwijzingen (scrum4me-mcp/...) ge-de-linked tot plain
text omdat de check-links script de zustertree niet traverseert; de
referenties blijven leesbaar.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-08 11:20:10 +02:00
Janpeter Visser
f233dd815e
docs: CLAUDE.md gap-fixes — adr/manual/architecture refs, npm run verify, MCP & cron sectie (#168)
Why: bij /init bleek CLAUDE.md ~95% accuraat maar miste verwijzingen naar docs/adr,
docs/manual en docs/architecture; verify-command was incompleet (typecheck ontbrak);
worker/job-systeem en cron-schedule waren niet zichtbaar zonder config-files te lezen.

- Orientatie: 3 nieuwe pointers (adr/manual/architecture)
- Hoe werk vinden + Verificatie + Deployment: `npm run verify && npm run build`
- Stack: Vitest-rij toegevoegd
- Hardstop: ClaudeJob queue lifecycle bullet
- Patterns quickref: realtime-notify-payload, story-with-ui-component, web-push
- Nieuwe sectie 'MCP & cron': externe MCP-server, cron-schedules, realtime-kanaal
- Env vars: verwijzing naar VAPID/Sentry/Anthropic in .env.example
- Frontmatter last_updated -> 2026-05-08

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-08 10:07:58 +02:00
Janpeter Visser
eaabec8471
feat(PBI-66): wekelijkse sync van model_prices via Anthropic /v1/models (#167)
Nieuw script `npm run db:sync-model-prices` haalt de actuele Claude 4.x
modellijst op bij de Anthropic API en upsert prijzen in `model_prices`.
Anthropic biedt geen prijs-API, dus prijzen blijven onderhouden in een
PRICE_TABLE constante in het script. Cache-tier-prijzen worden afgeleid
via vaste multipliers (read 0.1x, write 1.25x). Nieuwe Claude 4.x modellen
worden gedetecteerd en gelogd als warning zodat duidelijk is wanneer de
tabel handmatig moet worden bijgewerkt.

- scripts/sync-model-prices.ts: idempotent upsert, --dry-run, retry op 5xx
- ANTHROPIC_API_KEY als optional env-var (.env.example, lib/env.ts)
- scripts/README.md: gebruiksinstructies + edge cases
- docs/plans/sync-model-prices.md: ontwerpdocument

Verificatie: `npm run lint`, `vitest` (563/563), TypeScript clean.
Echt gedraaid tegen DB: 3 created (eerste run) -> 3 unchanged (tweede run).

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-08 09:38:33 +02:00
Janpeter Visser
8a6b2d2cb3
chore: ignore .claude/worktrees in git (#166)
Voorkomt dat lokale worktree-mappen per ongeluk als submodule-pointers
worden gecommit (gebeurde in 4ff5b64).

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-08 09:29:59 +02:00
Janpeter Visser
a16988b957
Sprint: debug, zichtbaarheid componenten (#165)
* feat(debug-store): Zustand store met hydration-flag voor debug-modus

* feat(status-bar): dev-only debug-toggle via geïsoleerde sub-component

* feat(globals.css): debug-mode overlay CSS voor data-debug-id elementen

* feat(shared): data-debug-id+label op navigatie-componenten

* feat(shared): data-debug-id+label op form/select-componenten

* feat(shared): data-debug-id+label op display-componenten
2026-05-08 08:55:43 +02:00
Janpeter Visser
f7464db837
docs: sync data-model, glossary en specs met huidig schema (#164)
Brengt de docs gelijk met de werkelijkheid na PBI-46/47/50/58/59/61/63
en M12. Belangrijkste fixes:

- data-model.md herschreven naar prisma/schema.prisma: nieuwe entiteiten
  (Idea, IdeaLog, IdeaProduct, UserQuestion, ClaudeQuestion, ClaudeJob,
  SprintRun, SprintTaskExecution, ClaudeWorker, LoginPairing,
  PushSubscription, ModelPrice, ProductMember), nieuwe enums
  (FAILED/EXCLUDED, OPEN/CLOSED/ARCHIVED, ADMIN, etc.) en codes
  (PBI/ST/T/SP-N) toegevoegd; verwijderde todos-tabel verwijderd.
- glossary.md: Sprint zonder "max 1 actief" (PBI-63), Story/Task incl.
  FAILED/EXCLUDED, Todo verwijderd, Idea/SprintRun/ClaudeJob/
  verify_result toegevoegd.
- project-structure.md: app/(app)/todos vervangen door
  ideas/insights/jobs/manual/admin/solo; api-tree volledig.
- overview.md: "geen realtime in v1" en Docker-rationale herschreven —
  Postgres LISTEN/NOTIFY + SSE, claude_jobs als queue, opt-in
  Docker-deploy-flow.
- functional.md: F-08 Todo-lijst -> Ideeen-laag, F-09 multi-sprint,
  F-10 Task-status incl. FAILED/EXCLUDED, F-11 endpoint-lijst,
  navigatiestructuur, datamodel-schets en Flow 3 bijgewerkt.
- README.md API-tabel: /api/todos weg, ideas/jobs/users/profile/health
  toegevoegd, kort over realtime/auth-pair/internal/cron.
- patterns + mcp-integration runbook: Todo-/ACTIVE-references vervangen
  door Idea/OPEN; create_todo MCP-tool note over verwijdering.

Linkcheck groen (105 files), INDEX hergegenereerd (98 docs).

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-08 08:16:44 +02:00
Janpeter Visser
3842c05ae9
feat: sprint-switcher overal + PBI auto-toevoeging + cleanups (#163)
* refactor: verplaats sprint-switcher van NavBar naar product-header

Sprint-pulldown zit nu in de bestaande balk op de product backlog
(naast Sprint starten / Instellingen) i.p.v. in het midden van de
NavBar. Alleen zichtbaar wanneer het product ook het actieve product
van de gebruiker is.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* chore: sync package-lock.json version naar 1.2.0

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* refactor: centreer sprint-switcher en verwijder badges uit dropdown items

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* refactor: vervang sprint-status badge door subtle tekst

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat: toon code + titel + status in sprint-switcher dropdown items

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix: cookie-write uit Server Component (Next.js 16 verbiedt dit)

setActiveSprintCookie werd direct aangeroepen in app/(app)/products/[id]/sprint/[sprintId]/page.tsx,
wat in Next.js 16 een runtime-error oplevert ('Cookies can only be modified in a Server Action
or Route Handler'). Vervangen door een client-side bridge die syncActiveSprintCookieAction
aanroept na mount, zodat de active-sprint cookie nog steeds gesynced blijft met de URL.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat: filter 'toon afgeronde sprints' in sprint-switcher dropdown

Default verbergt de switcher gesloten/gearchiveerde/mislukte sprints
(toont alleen open + de huidige actieve sprint). Toggle bovenaan de
lijst om alle sprints te tonen.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat: nieuwe sprint wordt direct geselecteerd zonder redirect

createSprintAction zet nu de active-sprint cookie naar de zojuist
aangemaakte sprint, en de StartSprintButton refresht de huidige
pagina i.p.v. te redirecten naar /sprint. Resultaat: gebruiker blijft
op de product backlog en ziet de nieuwe sprint direct geselecteerd
in de sprint-pulldown.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* refactor: verplaats Manual en Admin naar user-menu dropdown

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat: voeg geselecteerde PBI automatisch toe aan nieuwe sprint

Bij sprint-aanmaak wordt de pbi_id uit de selection-store als hidden
form-field meegestuurd. Server-side worden alle stories van die PBI
(zonder sprint) en hun taken aan de nieuwe sprint gekoppeld; stories
krijgen status IN_SPRINT met incrementele sort_order.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat: sprint-switcher op solo- en sprint-board pagina's

Sprint-switcher is nu beschikbaar op de drie hoofdpagina's: product
backlog, solo board en sprint board. Allen renderen 'm in een
gecentreerde balk net onder de NavBar. Sprint-data via gedeelde helper
getSprintSwitcherData.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-08 02:32:50 +02:00
Janpeter Visser
a4a7ef9b8b
refactor: sprint-switcher van NavBar naar product-header (#162)
* refactor: verplaats sprint-switcher van NavBar naar product-header

Sprint-pulldown zit nu in de bestaande balk op de product backlog
(naast Sprint starten / Instellingen) i.p.v. in het midden van de
NavBar. Alleen zichtbaar wanneer het product ook het actieve product
van de gebruiker is.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* chore: sync package-lock.json version naar 1.2.0

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-08 01:05:39 +02:00
Janpeter Visser
4a9db57e94
feat(PBI-63): meerdere sprints per product + EXCLUDED + sprint-switcher (#161)
- Sprint lifecycle: ACTIVE→OPEN, COMPLETED→CLOSED, +ARCHIVED (FAILED behouden)
- TaskStatus: +EXCLUDED (overgeslagen door agent-loop via bestaande TO_DO filter)
- Cookie-gebaseerde actieve sprint per product (lib/active-sprint.ts)
- Route splitsen: /products/[id]/sprint/[sprintId] + /sprint redirect-page
- NavBar: gestapelde product/sprint dropdowns + BUILDING-badge derivatie
- Backlog selectie-modus + nieuwe-sprint-dialog (createSprintWithPbisAction)
- Migratie 20260507210000_sprint_lifecycle: ALTER TYPE RENAME (geen data-rewrite)
- Version bump 1.0.0 → 1.2.0

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-08 00:15:04 +02:00
Janpeter Visser
d68aa1e5e6
Sprint: pbi-55 (#160)
* fix(input): border-border bg-input-background voor light-mode zichtbaarheid

* fix(select): border-border bg-input-background voor light-mode zichtbaarheid
2026-05-07 22:57:57 +02:00
Janpeter Visser
10bf25dadd
feat(PBI-61): multi-select op kind- en status-filter (#159)
- Filter-pills zijn nu toggle-knoppen; meerdere waardes per dimensie selecteerbaar
- "Alle"-pill wist de selectie binnen die dimensie
- Eén active-badge per geselecteerde waarde, klikbaar om losse selectie te wissen
- localStorage formaat is nu CSV met whitelist-validatie (oude 'all'-waarde valt vanzelf weg → leeg = geen filter)
- Filtercount in trigger toont som van actieve selecties

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-07 22:21:09 +02:00
Janpeter Visser
e8371b9f95
feat(PBI-61): filter popover + created_at op job-kaart (#158)
- Nieuwe JobsColumn met Kind/Status filter-popover per kolom (Actief/Klaar)
- Filterstate persistent in localStorage (whitelist-validatie tegen corrupte waardes)
- Active-filter badges in kolomheader, klikbaar om te wissen
- Aanmaakdatum + tijd rechtsonder op elke JobCard (nl-NL short formaat)

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-07 21:52:27 +02:00
Janpeter Visser
7ae8a24372
Sprint: pbi-55 (#156)
* ST-cmovs79lt: Schema + migratie PushSubscription model

Voeg PushSubscription model toe aan prisma/schema.prisma met
snake_case-conventie, relation field op User, en bijbehorende
migratie (push_subscriptions tabel, FK + index op user_id).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* ST-cmovs7e3o: web-push dependency + VAPID env vars feature-gated

Voeg web-push + @types/web-push toe aan package.json.
Registreer NEXT_PUBLIC_VAPID_PUBLIC_KEY, VAPID_PRIVATE_KEY,
VAPID_SUBJECT en INTERNAL_PUSH_SECRET als .optional() in lib/env.ts.
Documenteer alle vier in .env.example en README.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* ST-cmovs7jgr: lib/push-server.ts met sendPushToUser + stale-cleanup

Server-only push-lib met VAPID feature-gate, send naar alle
subscriptions van een user, en automatische cleanup bij 404/410.
Unit tests: success-pad, 410 verwijdert sub, 404 verwijdert sub,
andere errors loggen zonder delete.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* ST-cmovs7ouz: lib/push-client.ts client-side push helpers + stub actions/push.ts

Client-side helpers: isPushSupported, isIOSSafari, isStandalonePWA,
urlBase64ToUint8Array, subscribeToPush, unsubscribeFromPush.
Stub actions/push.ts zodat imports resolven (implementatie volgt
in volgende taak). Unit tests voor urlBase64ToUint8Array.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* ST-cmovs7ut4: actions/push.ts subscribeToPushAction + unsubscribeFromPushAction

Vervangt stub met volledige implementatie: requireUser via getSession,
demo-block, Zod-validatie, upsert met user_id-scoping en user-scoped
deleteMany. Tests (8): idempotentie, demo-block, unauthenticated, invalid input.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* ST-cmovs80c1: POST /api/internal/push/send met constant-time Bearer check

Route: 503 als INTERNAL_PUSH_SECRET uitstaat, 401 bij verkeerd secret
(timingSafeEqual), 400 bij invalid JSON, 422 bij Zod-fout, 204 bij succes.
push-server.ts: env-import vervangen door process.env om SESSION_SECRET
validatie tijdens build te omzeilen. Tests aangepast.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* ST-cmovs862j: Admin test-send route + public/sw.js service worker

POST /api/internal/push/test-send: requireAdmin check (redirect bij
niet-admin), optioneel body met defaults, roept sendPushToUser aan, 204.
public/sw.js: push-handler met showNotification, notificationclick met
same-origin guard, focus bestaand venster of openWindow.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* ST-cmovs8jvq: PushToggle component met 3 states + iOS-banner

Client component met states loading/unsupported/ios-needs-install/
denied/subscribed/unsubscribed. useEffect detecteert initial status,
permission-prompt alleen via user-click. iOS-banner NL, denied-uitleg,
subscribe/unsubscribe knoppen met sonner-toasts.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* ST-cmovs8psg: notifications-sheet + iOS meta-tags in layout

notifications-sheet.tsx: PushToggle onderin met sectie
'Notificatie-instellingen' en visuele scheidslijn.
app/layout.tsx: appleWebApp.capable, statusBarStyle en
mobile-web-app-capable meta-tags toegevoegd via Next.js Metadata API.
manifest.json had al display: standalone.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* ST-cmovs8vxj: docs/patterns/web-push.md pattern-documentatie

Architectuur-diagram, payload-shape, foutcodes, VAPID-config,
iOS-quirks, demo-users blokkade, trigger-voorbeelden (server +
HTTP) en admin-testroute curl-voorbeeld.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-07 21:46:01 +02:00
Janpeter Visser
25bd59c0b9
fix(PBI-59): jobs sorted newest-first, unified on created_at (#157)
- actions/jobs-page.ts: beide kolommen orderBy created_at desc
- stores/jobs-store.ts: nieuwe actieve jobs unshift (top) i.p.v. push (bottom)

Hiermee komen nieuw aangemaakte QUEUED/CLAIMED jobs bovenaan in de
linker kolom, in plaats van onderaan waar ze buiten het scrollbare deel
kunnen vallen.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-07 20:58:27 +02:00
Janpeter Visser
883534a521
fix(PBI-59): map jobs_initial SSE payload by job_id, not id (#155)
De server-route stuurt JobPayload[] (met `job_id`), maar de client deed
`initJobs(jobs, ...)` waardoor alle entries in activeJobs `id: undefined`
kregen — wat React-key warnings opleverde:

  Each child in a list should have a unique "key" prop.

Fix: SSE jobs_initial niet meer als overwrite gebruiken; SSR-fetch heeft
de volledige JobWithRelations al in de store gezet. We reconcileren nu
per job met upsertJob (status/branch/error/summary updaten van bekende
jobs, onbekende jobs als partials toevoegen — zelfde gedrag als gewone
'message' SSE events).

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-07 20:22:07 +02:00
Janpeter Visser
00dbbb4f94
chore(ci): gate auto-deploy behind AUTO_DEPLOY_ENABLED repo-variable (#154)
Voorkomt automatische Vercel-deploys op PR-preview en push-naar-main
zolang \`vars.AUTO_DEPLOY_ENABLED == 'true'\` ontbreekt. Default-staat:
auto-deploy UIT, scheelt Actions-minuten op het free-plan.

Handmatig deployen blijft werken via workflow_dispatch (Actions tab →
"Run workflow" → kies preview of production). Die job (\`deploy-manual\`)
is niet aan de flag gebonden.

Aanzetten van auto-deploy: Settings → Secrets and variables → Actions
→ Variables → New repository variable: \`AUTO_DEPLOY_ENABLED\` = \`true\`.

\`changes\` job (path-filter) staat ook achter de flag — die wordt alleen
gebruikt door de twee auto-deploy jobs.

Runbook bijgewerkt met de nieuwe default + uitleg.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-07 20:17:15 +02:00
Janpeter Visser
a268df3680
feat(PBI-59): Sprint.code (SP-N sequentieel per product) (#153)
Voegt een verplicht code-veld toe aan Sprint, sequentieel per product
(consistent met PBI-N, ST-NNN, T-N).

- **Schema** — `Sprint.code String @db.VarChar(30)` + `@@unique([product_id, code])`
- **Migratie** — voegt kolom toe als nullable, backfillt bestaande sprints
  via `ROW_NUMBER() OVER (PARTITION BY product_id ORDER BY created_at)`
  als `SP-N`, en zet daarna NOT NULL + UNIQUE.
- **Generator** — `generateNextSprintCode(productId)` in lib/code-server.ts
  volgt het patroon van story/pbi/task; createSprintAction gebruikt
  `createWithCodeRetry` voor race-bescherming.
- **Seed** — sprint-counter per product (`SP-1`, `SP-2`, ...).

Zichtbaar in:
- Sprint-header (`Product › Sprint actief · SP-3`)
- JobCard + JobDetailPane voor SPRINT_IMPLEMENTATION jobs
- Insights: VelocityChart x-axis (compacter dan goal-truncated),
  AlignmentTrend tooltip, SprintInfoStrip
- actions/jobs-page.ts: `sprintCode` is weer een echte code i.p.v. null

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-07 20:10:16 +02:00
Janpeter Visser
16f01283ef
feat(PBI-59): add Detail/Usage view-switch on /jobs (#152)
Splits het middenpaneel van de jobs-pagina in twee views (zoals admin/jobs):

- **Detail** — alle metadata (status, kind, product, branch, PR, dates,
  errors, summary, verify-result) plus een kind-aware beschrijving:
  TASK → implementation_plan, IDEA_GRILL → grill_md, IDEA_MAKE_PLAN →
  plan_md, PLAN_CHAT → idea.description.
- **Usage** — model, tokens (in/uit/cache/totaal), berekende kosten in
  USD via ModelPrice-tabel, en duur (started→finished).

SprintSubTasksPane blijft als sticky header boven beide views.

Server action `fetchJobsPageData` haalt nu ook ModelPrices op en
selecteert task.{description,implementation_plan} +
idea.{description,grill_md,plan_md} zodat de description en costUsd in
JobWithRelations gevuld kunnen worden.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-07 19:51:53 +02:00
Janpeter Visser
a7e9ca1c35
fix(PBI-59): drop invalid Sprint.code select in fetchJobsPageData (#151)
Sprint heeft geen `code` veld; de query crashte met
PrismaClientValidationError zodra /jobs werd geopend. sprintCode blijft
in JobWithRelations als string|null voor UI-compat (JobCard.titleText
fallback) maar is nu altijd null.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-07 19:24:21 +02:00
Janpeter Visser
f166186374
feat(PBI-59): Jobs-pagina UI (vervolg na #149) (#150)
* feat(PBI-58): Vitest-tests voor SoloTaskCard veldmapping en 4-regels layout

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(PBI-59): server action fetchJobsPageData voor jobs-pagina

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(PBI-59): SSE-route /api/realtime/jobs voor user-scoped job-events

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(PBI-59): JobCard component voor jobs-pagina

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(PBI-59): JobDetailPane component voor jobs-pagina

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(PBI-59): API route GET /api/jobs/[id]/sub-tasks voor sprint task executions

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(PBI-59): SprintSubTasksPane component voor jobs-pagina

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(PBI-59): Zustand store useJobsStore voor jobs-pagina

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(PBI-59): useJobsRealtime hook met SSE-verbinding en store-updates

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(PBI-59): JobsBoard 3-kolom SplitPane client component

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(PBI-59): /jobs server page met JobsBoard

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(PBI-59): Jobs nav-link toevoegen aan NavBar

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-07 19:16:20 +02:00
Janpeter Visser
4a63b4b01f
Sprint: UI taken/ (#149)
* feat(PBI-58): Vitest-tests voor SoloTaskCard veldmapping en 4-regels layout

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(PBI-59): server action fetchJobsPageData voor jobs-pagina

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(PBI-59): SSE-route /api/realtime/jobs voor user-scoped job-events

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(PBI-59): JobCard component voor jobs-pagina

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(PBI-59): JobDetailPane component voor jobs-pagina

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(PBI-59): API route GET /api/jobs/[id]/sub-tasks voor sprint task executions

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-07 18:41:19 +02:00
Janpeter Visser
bd7478861b
PBI-58: Developer manual + in-app /manual page (#148)
* docs(PBI-58): add developer manual chapters under docs/manual/

Adds a 7-file English-language manual targeted at new human contributors:
index, overview, statuses & transitions (with mermaid state diagrams),
git workflow, MCP integration, docker, and troubleshooting. The manual
is the *map* — it cross-references existing runbooks/ADRs/architecture
docs rather than duplicating their content.

Regenerates docs/INDEX.md and validates with check-doc-links.mjs.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* chore(PBI-58): add markdown rendering deps + manual:build script

Adds mermaid, rehype-slug, rehype-autolink-headings for the in-app
/manual page. Wires manual:build into prebuild so production builds
always regenerate the chapter TOC.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(PBI-58): codegen script for in-app manual TOC

scripts/build-manual.mjs walks docs/manual/, parses YAML front-matter,
strips it from the body, and emits lib/manual.generated.ts with a typed
ManualEntry[] containing slug, title, description, filePath, and the
embedded markdown body. Pure Node 20, mirrors generate-docs-index.mjs.

Inlining the markdown at build time keeps runtime serverless functions
free of filesystem reads, which avoids whole-project NFT tracing.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(PBI-58): /manual route renders developer manual chapters in-app

Catch-all route at app/(app)/manual/[[...slug]]/page.tsx with
generateStaticParams covering every TOC entry. Server-side
MarkdownView uses react-markdown with remark-gfm, rehype-slug, and
rehype-autolink-headings; mermaid code blocks are routed to a
client-only MermaidBlock that dynamic-imports mermaid on mount.

ManualSidebar (client) reads the typed TOC and highlights the active
chapter via usePathname.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(PBI-58): add Manual link to main nav bar

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-07 18:00:10 +02:00
Janpeter Visser
d750676f5e
PBI-56 + ST-1275: PLAN_READY → GRILLING re-grill + SKIPPED status rendering (#147)
* fix(ST-1272): allow PLAN_READY → GRILLING re-grill transition

actions/ideas.ts already lists PLAN_READY in GRILL_TRIGGERABLE_FROM,
but lib/idea-status.ts ALLOWED_TRANSITIONS was missing the
PLAN_READY → GRILLING edge. As a result, clicking Grill on a PLAN_READY
idea returned 422 "Status-transitie ongeldig" while the UI button was
enabled. Mirrors the existing PLANNED → GRILLING re-grill behaviour.

- lib/idea-status.ts: PLAN_READY allows GRILLING in addition to
  PLANNING/PLANNED
- __tests__/lib/idea-status.test.ts: explicit assert for
  PLAN_READY → GRILLING and PLAN_READY added to the regrill loop
  covering every GRILL_TRIGGERABLE_FROM status

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(ST-1275): render SKIPPED job status in chart-colors and insights

Closing the gap left when ClaudeJobStatus.SKIPPED was added to the schema:
the badge map and case-mapper already covered it, but the chart palette,
the per-day insights aggregator and the stacked-bar chart did not. SKIPPED
jobs (e.g. cmovkur8 manually flipped during the no-op-exit hotfix) now
render with a muted style consistent with cancelled.

- lib/chart-colors.ts: JOB_STATUS_COLORS gains a 'skipped' entry
  (var(--muted-foreground), same intensity as cancelled — neither rood/orange)
- lib/insights/agent-throughput.ts: DayCount + STATUSES + perDay zero-fill
  now include 'skipped'; the SQL terminal_7d filter already counted SKIPPED
- app/(app)/insights/components/agent-throughput.tsx: STACKED_STATUSES and
  the empty-state guard include 'skipped'
- __tests__: chart-colors keys list, job-status round-trip ('all 7 statuses')
  and the insights non-zero filter all account for SKIPPED

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-07 17:36:44 +02:00
Janpeter Visser
e8562d4018
Sprint: inzicht jobs (#146)
* feat(admin/jobs): select token-velden en bereken kostprijs server-side

Voegt model_id, input_tokens, output_tokens, cache_read_tokens en
cache_write_tokens toe aan de ClaudeJob-query en berekent cost_usd per
job via een ModelPrice-lookup. Jobs zonder prijs-entry of zonder
input_tokens krijgen cost_usd: null.

* feat(admin/jobs-table): toggle-buttons en view-state voor status/kosten-weergave

Voegt useState toe, breidt Job-type uit met model_id en cost_usd, extraheert
huidige tabellogica naar StatusTable en voegt CostsTable-stub + toggle-knoppen
toe aan JobsTable.

* feat(admin/jobs-table): CostRow en CostsTable voor kosten-view

Voegt CostRow toe met kolommen ID/Gebruiker/Product/Type/Model/Kosten(USD)/
Aangemaakt/Acties en vervangt de CostsTable-stub door een volledige tabel.
Kostprijs geformatteerd als "$0.0042"; ontbrekende prijs toont "—".
2026-05-07 16:09:17 +02:00
Janpeter Visser
94f4f6ffd8
feat(PBI-33): chat-kanaal UI + lint cleanup (#145)
* feat(PBI-33): chat-kanaal UI — IdeaTimeline merge + UserChatInput

Voltooit de UI-laag van PLAN_CHAT (gebruikersvragen over plan, Claude
antwoordt async). Backend (UserQuestion model, createUserQuestionAction,
SSE-handling, server-side prop-passing) was al aanwezig — alleen de
UI-koppeling ontbrak waardoor userQuestions ongebruikt bleven.

- IdeaDetailLayout geeft userQuestions/planMd/ideaId/isDemo door aan
  IdeaTimeline en telt user-questions mee in de tab-count
- IdeaTimeline mergt user-questions chronologisch met logs+questions,
  rendert ze met MessageCircle-icoon en pending/answered status, en
  toont onderaan UserChatInput wanneer plan_md aanwezig is
- UserChatInput nieuw component met textarea + verzend-knop dat
  createUserQuestionAction aanroept en op success router.refresh()
  triggert zodat SSE de pending-state oppikt
- useNotificationsRealtime: router toegevoegd aan useEffect-deps zodat
  router.refresh() op user_question/idea-job events werkt zonder
  stale-closure waarschuwing

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(lint): unused vars/imports + react-hook-form watch incompatibility

Resolves de overige lint-warnings van de gefaalde sprint-build die los
staan van PBI-33. Eslint-config staat unused vars/args toe als ze met
'_' prefixen, dus required interface-params krijgen een prefix terwijl
losse dode constantes/imports verwijderd worden.

- sprint-header: productId is required prop maar nog niet gebruikt
  → prefix _productId i.p.v. verwijderen (caller passeert het door)
- agent-throughput: STATUSES-constante was dood — verwijderd, queries
  gebruiken hardcoded status-velden in de perDay-loop
- claude-jobs: productAccessFilter en enforceUserRateLimit waren
  dode imports — verwijderd
- story-log.test: ongebruikte 'data' binding vervangen door bare
  await res.json() zodat de stream nog wel geconsumeerd wordt
- product-dialog: form.watch('auto_pr') vervangen door useWatch met
  control-prop — useWatch is veilig voor React Compiler memoization

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-07 16:04:53 +02:00
Janpeter Visser
5cb3abbd3d
Sprint: Idee regril mogelijkheid (#144)
* feat(ST-cmovhveef): add PLANNED to GRILL_TRIGGERABLE_FROM and PLANNED→GRILLING transition

- GRILL_TRIGGERABLE_FROM now includes 'PLANNED' in actions/ideas.ts
- ALLOWED_TRANSITIONS PLANNED entry extended with 'GRILLING' in lib/idea-status.ts
- Updated canTransition test to reflect the new re-grill-from-PLANNED behavior

* test(ST-cmovhvef3): add exhaustive re-grill canTransition test covering PLANNED

Adds a loop test that asserts canTransition(status, 'GRILLING') for all
statuses in GRILL_TRIGGERABLE_FROM that support the transition, explicitly
documenting PLANNED as a valid re-grill entry point.

* feat(ST-cmovhvegf): add existingPbi pre-check in materializeIdeaPlanAction

- Adds options.allowAlongside parameter to control behaviour when a PBI
  with executed tasks already exists.
- Returns 409 PBI_HAS_ACTIVE_TASKS:<code> when tasks are DONE/IN_PROGRESS
  and allowAlongside is not set.
- Auto-deletes the old PBI inside the transaction when no tasks have been
  executed (atomic replace).
- Alongside mode (allowAlongside=true) skips deletion and creates a new PBI.

* test(ST-cmovhveh3): add pre-check integration tests for materializeIdeaPlanAction

Three new scenarios in ideas-crud.test.ts:
- auto-vervang: old PBI deleted in transaction when no executed tasks
- conflict-409: returns PBI_HAS_ACTIVE_TASKS:<code> with active tasks
- alongside: skips delete and creates new PBI when allowAlongside=true
Also adds task.count, pbi.findUnique, pbi.delete to prisma mock.

* feat(ST-cmovhveih): remove PLANNED-blokkering in idea-row-actions, add inline Bekijk-PBI button

- Removed grillBlockedReason guard for status==='planned', enabling re-grill from PLANNED
- Removed the early return for PLANNED that hid all standard buttons
- Added conditional 'Bekijk <code>' button at the start of the standard button set,
  visible only when status==='planned' and PBI + product_id are present

* feat(ST-cmovhvej7): add PBI_HAS_ACTIVE_TASKS alongside-dialoog in materialize handler

When materializeIdeaPlanAction returns code 409 with PBI_HAS_ACTIVE_TASKS:<code>,
a confirm dialog offers the user a choice: create new PBI alongside the existing one
or cancel. Alongside=true retries the action; cancel leaves the idea in PLAN_READY.
2026-05-07 15:27:43 +02:00
Janpeter Visser
2d27c41d38
fix(textarea): border-border + bg-input-background voor off-focus zichtbaarheid (#143)
Vervangt border-input door border-border en bg-transparent door
bg-input-background in de gedeelde Textarea-component en de lokale
textareaClass in task-dialog.tsx. Dark mode ongewijzigd via dark:bg-input/30.

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-07 14:27:11 +02:00
Janpeter Visser
c6afde0ff6
docs: fix broken cross-repo links in sprint-execution-modes (PBI-51) (#141)
De drie relatieve `../../scrum4me-{mcp,docker}/...` paden in
docs/architecture/sprint-execution-modes.md verwezen naar zustere repos
buiten deze repo, waardoor `npm run docs:check-links` faalde. Vervangen
door absolute GitHub-URL's (de checker skipt `https://`-links), conform
de conventie in docs/runbooks/mcp-integration.md en docs/backlog/index.md.

- maybeCreateAutoPr → github.com/madhura68/scrum4me-mcp (main)
- scrum4me-mcp README → github.com/madhura68/scrum4me-mcp#readme
- scrum4me-docker CLAUDE.md → github.com/madhura68/scrum4me-docker (master)

Verificatie: `npm run docs:check-links` ✓ (97 files checked, 0 broken).

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-07 13:44:44 +02:00
Janpeter Visser
fffa5a47d2
docs: archiveer sprint-pr-worktree state-machines advies (#140)
Het advies-document dat als input diende voor PBI-50 is nu in docs/plans/
opgeborgen voor traceability. INDEX.md regenerated om hem op te nemen.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-07 13:32:30 +02:00
Janpeter Visser
07749ad9fb
PBI-50: SPRINT_IMPLEMENTATION single-session sprint runner (Scrum4Me-side) (#139)
* PBI-50 F1: SPRINT_BATCH execution-strategy + cross-repo blocker + branch-resume

Schema-migratie + Scrum4Me-side wiring voor de nieuwe SPRINT_IMPLEMENTATION-flow:

- prisma: PrStrategy ADD VALUE 'SPRINT_BATCH'; ClaudeJobKind ADD VALUE
  'SPRINT_IMPLEMENTATION'; nieuwe enum SprintTaskExecutionStatus; ClaudeJob.lease_until
  + status_lease_until index; SprintRun.previous_run_id (self-relation
  SprintRunChain) voor branch-hergebruik bij resume; nieuwe sprint_task_executions
  tabel met frozen plan_snapshot + verify_required_snapshot per task in scope.
- actions/sprint-runs.ts startSprintRunCore: nieuwe blocker-type 'task_cross_repo'
  voor SPRINT_BATCH (pre-flight rejecteert sprints met cross-repo task_url).
  Bij SPRINT_BATCH: één SPRINT_IMPLEMENTATION ClaudeJob (geen per-task loop).
- actions/sprint-runs.ts resumePausedSprintRunAction: SPRINT_BATCH-pad met
  remaining-execution-check; bij onafgemaakt werk → nieuwe SprintRun met
  previous_run_id + run.branch hergebruikt + nieuwe SPRINT_IMPLEMENTATION-job.
  Oude SprintRun → CANCELLED. Bestaande PBI-49 P0 scope-DONE pad ongewijzigd.
- actions/products.ts updatePrStrategyAction: accepteert SPRINT_BATCH.
- components/products/pr-strategy-select.tsx: drie opties met helptekst,
  gebruikt @prisma/client PrStrategy ipv lokaal type.
- components/sprint/sprint-run-controls.tsx: BLOCKER_LABELS + blockerHref
  voor task_cross_repo.

Migratie applied op Neon. Type-check + 532 tests groen.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* PBI-50 F5: cross-repo blocker test voor SPRINT_BATCH

- task_cross_repo blocker fires bij task.repo_url ≠ product.repo_url
- happy path: tasks zonder repo_url-override of met match → één
  SPRINT_IMPLEMENTATION-job (niet per-task).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* PBI-50 F5: docs/architecture/sprint-execution-modes.md

Vergelijking PER_TASK vs SPRINT_BATCH met trade-offs, datamodel-
toevoegingen (SprintTaskExecution, lease_until, SprintRunChain) en
MCP-tools-matrix per modus. Toegevoegd aan breadcrumb in
docs/architecture.md.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-07 13:05:02 +02:00
Janpeter Visser
e6dcc91383
PBI-49 P0: resumePausedSprintRunAction — DONE bij scope-completed (#138)
A STORY-mode MERGE_CONFLICT triggers AFTER all tasks are already DONE
(storyBecameDone is what produces the conflict event). The previous resume
logic put the SprintRun back to QUEUED, but there was no QUEUED job left for
a worker to claim — the run would hang forever.

Now: when both QUEUED and CLAIMED/RUNNING counts are zero, transition straight
to DONE (with finished_at set). The dev resolved the conflict manually and
the PR is theirs to merge. Existing behaviour preserved when active claims
or queued work remain.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-07 11:11:45 +02:00
Janpeter Visser
d3e79021c1
PBI-47: schema, pause_context Zod, resumePausedSprintRunAction, PAUSED-banner UI (#137)
Scrum4Me-side counterpart of scrum4me-mcp@f7f5a48 (PBI-9 + PBI-47):

- prisma migration: ClaudeJob.{base_sha,head_sha} + SprintRun.pause_context
- lib/pause-context.ts: Zod schema + parsePauseContext + pauseReasonLabel
  helper; single source of truth for the JSON pause_context shape produced
  by the mcp sprint-run flow (MERGE_CONFLICT pause)
- actions/sprint-runs.ts: resumePausedSprintRunAction — separate from the
  existing FAILED-resume flow, requires SprintRun.status === PAUSED, closes
  the linked ClaudeQuestion, clears pause_context, sets RUNNING/QUEUED based
  on whether a claim is still active
- components/sprint/sprint-run-controls.tsx: PAUSED banner with reason label,
  PR link, conflict-files list (max 5 + "+N more"), Resume button with
  confirm() guard
- app/(app)/products/[id]/sprint/page.tsx: load pause_context from active
  SprintRun and pass through to SprintRunControls

All MD3 tokens (warning-container, on-warning-container, primary). No raw
Tailwind utility colours.

Tests: 532 passing across 72 files (Scrum4Me side).

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-06 22:17:11 +02:00
Janpeter Visser
77617e89ac
PBI-46: Sprint-niveau jobflow met cascade-FAIL (F1/F2/F4 Scrum4Me) (#136)
* ST-1243: F1 schema + propagateStatusUpwards-helper voor sprint-flow

Schema-uitbreidingen voor de sprint-niveau jobflow (PBI-46):
- TaskStatus, StoryStatus, PbiStatus, SprintStatus krijgen FAILED
- Nieuwe enums: SprintRunStatus, PrStrategy
- Nieuw SprintRun-model dat per-task ClaudeJobs groepeert
- ClaudeJob.sprint_run_id koppeling + index
- Product.pr_strategy (default SPRINT)
- Bijhorende Prisma-migratie

propagateStatusUpwards vervangt updateTaskStatusWithStoryPromotion en
herevalueert de keten Task → Story → PBI → Sprint → SprintRun bij elke
task-statuswijziging. Bij FAILED cancelt het sibling-jobs in dezelfde
SprintRun. PBI-status BLOCKED blijft handmatig en wordt niet overschreven.

Status-mappers + theme krijgen failed-token + label-uitbreidingen.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* ST-1244: F2 sprint-runs actions + deprecate per-task enqueues

actions/sprint-runs.ts (nieuw):
- startSprintRunAction met pre-flight (impl_plan / open ClaudeQuestion / PBI BLOCKED|FAILED)
- Maakt SprintRun + ClaudeJobs in PBI→Story→Task volgorde
- resumeSprintAction zet FAILED tasks/stories/PBIs terug en start nieuwe SprintRun
- cancelSprintRunAction breekt lopende SprintRun af zonder cascade

actions/claude-jobs.ts:
- enqueueClaudeJobAction, enqueueAllTodoJobsAction, previewEnqueueAllAction,
  enqueueClaudeJobsBatchAction nu deprecation-stubs (UI-cleanup volgt in F4)
- cancelClaudeJobAction blijft beschikbaar voor losse jobs

Tests bijgewerkt: 11 nieuwe sprint-runs tests, claude-jobs(-batch) tests
herzien naar deprecation-asserties.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* ST-1246: F4 UI Start/Resume/Cancel sprint + pr_strategy dropdown

- components/sprint/sprint-run-controls.tsx: knoppen Start Sprint
  (sprintStatus=ACTIVE), Hervat sprint (sprintStatus=FAILED) en
  Annuleer sprint-run (lopende run). Pre-flight blocker-modal toont
  blockers met directe links naar de relevante pagina's.
- components/products/pr-strategy-select.tsx: dropdown SPRINT|STORY in
  product-settings, met optimistic update + sonner-toast op fail.
- actions/products.ts: updatePrStrategyAction (eigenaar-only, demo-block).
- Sprint-page: query op actieve SprintRun + tonen van controls-balk.

Live cascade-visualisatie (T-634) staat als follow-up genoteerd —
huidige sprint-board statusbadges volstaan voor MVP. De Solo-board
"Voer uit"-knoppen zijn niet expliciet verwijderd; ze tonen nu de
deprecation-error van de gestubde actions tot de Solo-flow opnieuw
ontworpen wordt.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-06 16:43:57 +02:00
Janpeter Visser
ab8c3dca3f
ST-1239: Atomische database-migratie — todos naar ideas + droppen todos-tabel (#132)
* feat(cleanup): verwijder Todo's navlink en todo-referenties uit marketing page [cmotto5ia000nx3178lq6xk8d]

- nav-bar.tsx: Todo's navLink verwijderd; Ideas-link blijft staan
- app/page.tsx: /todos quick-access link, feature-entry en /api/todos API-doc verwijderd

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(cleanup): verwijder app/(app)/todos/ en components/todos/ [cmottjvzo000cx3172472cu4g]

* test(cleanup): verwijder POST /api/todos import en describe-block uit security.test.ts [cmotto5jn000px317kjqlba89]

- Import 'POST as postTodo' uit verwijderde todos-route verwijderd
- describe('POST /api/todos') sectie (3 tests) verwijderd
- 73 testfiles / 561 tests groen

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* test(cleanup): verwijder __tests__/api/todos.test.ts en __tests__/actions/todos-promote-idea.test.ts [cmottjw1u000fx317igq27mh5]

* feat(cleanup): verwijder actions/todos.ts en app/api/todos/route.ts; verplaats updateRolesAction naar actions/settings.ts [cmottjvy9000ax3173sgfjcqs]

* feat(db): migratie todos→ideas, counters bijwerken, todos dropt [cmotto5fh000jx317r7c5srvb]

Nieuwe Prisma-migratie die in één transactie actieve todos omzet naar
DRAFT-ideas met unieke IDEA-NNN codes, idea_code_counter per user
bijwerkt, en de todos-tabel dropt.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(schema): verwijder Todo model en relaties uit prisma/schema.prisma [cmottjvwu0008x317fwwodg3i]

* feat(cleanup): vervang open_todos door open_ideas in /api/products/:id/claude-context

Laatste prisma.todo-referentie verwijderd. Endpoint geeft nu open_ideas terug
(ideeën van de gebruiker voor dit product die niet gearchiveerd zijn en nog
niet status PLANNED hebben). Docs bijgewerkt in docs/api.md en
docs/api/rest-contract.md.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-06 12:25:37 +02:00
Janpeter Visser
c18d17108c
ST-1240: Verwijder backend todo-code (server actions + API route) (#135)
* feat(cleanup): verwijder Todo's navlink en todo-referenties uit marketing page [cmotto5ia000nx3178lq6xk8d]

- nav-bar.tsx: Todo's navLink verwijderd; Ideas-link blijft staan
- app/page.tsx: /todos quick-access link, feature-entry en /api/todos API-doc verwijderd

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(cleanup): verwijder app/(app)/todos/ en components/todos/ [cmottjvzo000cx3172472cu4g]

* test(cleanup): verwijder POST /api/todos import en describe-block uit security.test.ts [cmotto5jn000px317kjqlba89]

- Import 'POST as postTodo' uit verwijderde todos-route verwijderd
- describe('POST /api/todos') sectie (3 tests) verwijderd
- 73 testfiles / 561 tests groen

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* test(cleanup): verwijder __tests__/api/todos.test.ts en __tests__/actions/todos-promote-idea.test.ts [cmottjw1u000fx317igq27mh5]

* feat(cleanup): verwijder actions/todos.ts en app/api/todos/route.ts; verplaats updateRolesAction naar actions/settings.ts [cmottjvy9000ax3173sgfjcqs]

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-06 12:24:48 +02:00
Janpeter Visser
52c610b11c
ST-1242: Verwijder todo-tests, herstel security-test en verifieer volledige build (#134)
* feat(cleanup): verwijder Todo's navlink en todo-referenties uit marketing page [cmotto5ia000nx3178lq6xk8d]

- nav-bar.tsx: Todo's navLink verwijderd; Ideas-link blijft staan
- app/page.tsx: /todos quick-access link, feature-entry en /api/todos API-doc verwijderd

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(cleanup): verwijder app/(app)/todos/ en components/todos/ [cmottjvzo000cx3172472cu4g]

* test(cleanup): verwijder POST /api/todos import en describe-block uit security.test.ts [cmotto5jn000px317kjqlba89]

- Import 'POST as postTodo' uit verwijderde todos-route verwijderd
- describe('POST /api/todos') sectie (3 tests) verwijderd
- 73 testfiles / 561 tests groen

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* test(cleanup): verwijder __tests__/api/todos.test.ts en __tests__/actions/todos-promote-idea.test.ts [cmottjw1u000fx317igq27mh5]

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-06 12:24:29 +02:00
Janpeter Visser
628fbd7e7b
ST-1241: Verwijder frontend todo-UI (page, component, navbar en marketing page) (#133)
* feat(cleanup): verwijder Todo's navlink en todo-referenties uit marketing page [cmotto5ia000nx3178lq6xk8d]

- nav-bar.tsx: Todo's navLink verwijderd; Ideas-link blijft staan
- app/page.tsx: /todos quick-access link, feature-entry en /api/todos API-doc verwijderd

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(cleanup): verwijder app/(app)/todos/ en components/todos/ [cmottjvzo000cx3172472cu4g]

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-06 12:24:00 +02:00
Janpeter Visser
11937d8a8d
fix(db): restore todos table after out-of-band drop (#131)
De DB-tabel `public.todos` was buiten de migratie-historie om gedropt,
terwijl `prisma/schema.prisma` `model Todo` en migration_lock.toml geen
removal-migratie kenden. Gevolg: drift tussen schema (Todo aanwezig) en
DB (tabel weg) — runtime-fout op alle `prisma.todo.*`-calls in
`actions/todos.ts`, `app/api/todos/route.ts`, `app/(app)/todos/page.tsx`,
`app/api/products/[id]/claude-context/route.ts` en MCP-tool create_todo.

Deze migratie zet de tabel exact terug zoals het schema 'm beschrijft —
gegenereerd via:

  npx prisma migrate diff --from-config-datasource \
    --to-schema prisma/schema.prisma --script

CREATE TABLE todos + 2 indexes + 2 foreign keys naar users (CASCADE) en
products (SET NULL).

Eerdere data is niet hersteld (geen backup-stap); de tabel is leeg. Dat
is acceptabel: Todo's waren lichtgewicht notities zonder kritische data
en de removal-Idea staat nog gepland (zie #128 → re-plan met de
Make-Plan-prompt-update uit #130). Tot dat moment werken de Todo-flows
weer.

Verified locally: prisma migrate status (up to date), lint, typecheck,
tests 564/564, next build.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-06 10:18:20 +02:00
Janpeter Visser
688bd01a75
ST-iiybtinq: voeg Snel idee-knop en inline form toe aan IdeaList (#129)
- Voeg showQuick/quickTitle/quickDescription state toe
- Voeg handleQuickCreate toe die createIdeaAction met product_id=null aanroept
- Voeg Snel idee-knop (variant=outline) toe naast Nieuw idee in de top-bar
- Voeg inline snel-form toe zonder product-dropdown, met Enter-to-submit

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-06 09:31:10 +02:00
Janpeter Visser
dc8557308b
chore: typecheck-script + dependency-cascade-grep in Make-Plan-prompt (#130)
Twee preventieve aanpassingen na de mislukte ST-2wj8mw8q-run, waarbij een
schema-edit (Todo-model verwijderd) groen door lint en vitest kwam maar
op `next build` brak vanwege 16 ongelinkte `prisma.todo`-references in 4
bestanden.

package.json:
- "typecheck": "tsc --noEmit" — losse script voor snelle full-project
  type-check, los van eslint en next build.
- "verify": "npm run lint && npm run typecheck && npm test" — umbrella
  voor agents/CI om voor de eind-build te valideren.

lib/idea-prompts/make-plan.md:
- Werkwijze-stap 3 toegevoegd: "Bij removal/refactor: doe een
  dependency-cascade-grep". Voor de strikte format-sectie staat nu een
  verplicht protocol:
  - Removal van Prisma-model: grep `prisma.x` in actions/app/components/lib
  - Removal van component/utility/type: grep paden + exports
  - Hernoemen: per geraakt bestand een edit-taak
  - Veld-wijziging in create/update: grep op die call-sites
  - Eind-taak: `npm run typecheck` als sanity-check los van
    lint/test/build.
- Toelichting waarom: eslint en vitest+esbuild slaan diepe type-check
  over; next build is de eerste step die alles type-checkt en zit aan
  het eind van de pijp.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-06 09:31:02 +02:00
Janpeter Visser
3a61a8ddc1
Landing v3: van idee tot pull request + 6 nieuwe screenshots (#127)
* feat(landing): tour uitbreiden naar 6 screenshots incl. Ideas/Insights

Vervangt de oude 3 .jpg-screenshots door 6 nieuwe .png's met de huidige
visuele staat van de app. Volgorde toont de hele flow: ideeën binnen →
producten → backlog → sprint → solo → insights.

- Tour-array van 3 naar 6 figures, grid blijft lg:grid-cols-3 (2x2-rijen)
- Intro-tekst aangepast: "Zes weergaven van Scrum4Me — van inkomende
  ideeën tot persoonlijk Kanban-bord en voortgangs-inzichten"
- Bestandsnamen gehernoemd naar lowercase-dash-conventie:
  Sprint.png → sprint.png, Solo.png → solo.png, "Product Backlog.png" →
  product-backlog.png, Producten.png → producten.png, Insights.png →
  insights.png, Ideas-table.png → ideas-table.png,
  Ideas-detail.png → ideas-detail.png (alleen voorbereiding, nog niet in
  tour gebruikt)
- Oude .jpg-bestanden verwijderd

Niet onderdeel: hero/architectuur/handleiding-rewrite voor v3 — die staan
gepland onder ST-1224 en blijven open.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(landing): v3 — van idee tot pull request, met procesflow + Idea-laag

Verbreedt de landing-propositie van "executie lokaal" (v2) naar de
volledige cyclus idee → grill → plan → execute → PR. Eert M12 Ideas dat
sinds 2026-05-04 het kernconcept van het product is, plus auto-PR en
Sync-tab.

Hero:
- H1 "Van idee tot pull request — op je eigen hardware."
- Subhead benoemt grill→plan→materialise→agent→PR-cyclus en houdt het
  lokaal-anker uit v2 vast.

Nieuw §3 "Van idee tot pull request":
- 4 procesflow-kaarten (Idee/Grill/Plan/Execute) met status-chips
  (DRAFT/GRILLING/PLAN_READY/DONE→PR) en pijlen tussen kaarten op md+.
- Samenvattende paragraaf over state-machine, materializeIdeaPlanAction
  en auto-PR.

Architectuur:
- docs/diagrams/architecture.mmd Worker-label uitgebreid met
  "jobs: GRILL · PLAN · IMPL"; beide SVG's geregenereerd.
- Callout "Lokale worker" benoemt nu de drie jobsoorten expliciet.

Feature-grid (set D, 6 kaarten):
- Vervang "Hiërarchisch plannen" door "Ideas — Grill & Plan" op positie 1.
- Lokale Claude-agents: + auto-PR/SQUASH-merge zin.
- Realtime updates: + Sync-tab zin.
- Async vraagkanaal: + Grill-vragen zin.

Quickstart:
- Extra regel over UI-route (/ideas → Nieuw idee → Grill me) onder de
  bestaande MCP-installatie code-block.

Scrum-samenvatting:
- Hiërarchie wordt twee-rij-systeem: Idea (DRAFT → GRILLED → PLAN_READY)
  als bovenste rij, daaronder Product → PBI → Story → Taak met
  "materialiseert ↓"-pijl.
- Terminologie krijgt 2 nieuwe tegels (Idea, Grill/Plan).

Handleiding (10 → 12 stappen):
- Nieuwe stappen 3-5 voor Idea-route (vastleggen, grillen, plan + materialiseren),
  visueel gemarkeerd met tertiary-border en chip "Idea-route".
- Oude 7+8 (token + MCP-koppeling) samengevoegd tot stap 10.
- Stap 11 uitgebreid met Sync-tab-volgen.
- Stap 6 hernoemd "opbouwen" → "finetunen".

Plan-doc + grilling-context vastgelegd in docs/plans/landing-v3-idea-flow.md.

Tracked: ST-1224 onder PBI Marketing & Landingspagina.

Verified: lint 0 errors / 7 warnings (alle pre-existing), 564/564 tests,
productie-build slaagt.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-06 09:05:22 +02:00
Janpeter Visser
a28f0249e5
ST-1230: Sorteerstate en -logica toevoegen aan IdeaList (#126)
* feat(ideas): STATUS_SORT_ORDER + sorteerstate (ST-cmotjj9uf000104l5i70so19b)

- Voeg STATUS_SORT_ORDER toe: workflow-volgorde map (draft→plan_failed)
- Zet standaard sortDir op 'desc' conform AC (code aflopend bij laden)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(ideas): sorted useMemo + tabel-render koppelen (ST-cmotjj9uf000104l5i70so19b)

- Voeg sorted useMemo toe na filtered: locale-aware sort met STATUS_SORT_ORDER
- Ideeën zonder product sorteren achteraan bij oplopende productsortering
- Vervang filtered.length/filtered.map door sorted in tabel-render

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-06 07:24:20 +02:00
Janpeter Visser
6015357905
feat(ST-4uzuhxy0): sorteersectie in popover vervangen door ↑↓ knoppen + pills (#125)
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-06 06:47:41 +02:00
Janpeter Visser
bc90ef2040
feat(ST-05mofrm7): sortDir state + localStorage-persistentie aan PbiList toevoegen (#124)
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-06 06:40:50 +02:00
Janpeter Visser
1dd4e7761b
feat(ST-v3leym34): sorteerbare kolomkoppen met SortHeader in ideeëntabel (#123)
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-06 06:37:47 +02:00
Janpeter Visser
0f3aa403ea
feat(ST-05gegle6): datuminputs pre-vullen met vandaag in start-sprint-button (#122)
Voegt todayLocalDate()-helper toe (toLocaleDateString('en-CA') voor YYYY-MM-DD
zonder UTC-drift) en gebruikt hem als defaultValue op start_date en end_date.
Dialog unmount bij sluiten zorgt automatisch voor reset naar vandaag bij heropenen.

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-06 06:37:05 +02:00
Janpeter Visser
fd02cda207
ST-1229: UI: "Alles op done" knop met AlertDialog in sprint-header.tsx (#121)
* feat(ST-n1csfo4j): AlertDialog imports, state en transition voor Alles-op-done knop

Voegt AlertDialog-imports, setAllSprintTasksDoneAction-import, productId-prop
(hernoemd van _productId) en showAllDoneConfirm/isSettingAllDone state toe aan
sprint-header.tsx als voorbereiding op de Alles-op-done AlertDialog-knop.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(ST-n1csfo4j): handleAllDone + AlertDialog + Alles-op-done knop in sprint-afronden-dialog

Voegt handleAllDone toe (roept setAllSprintTasksDoneAction aan en zet alle
per-story decisions op DONE in de UI), een bevestigende AlertDialog en een
'Alles op done'-knop bovenaan de story-lijst in de sprint-afronden-dialog.
Voegt setAllSprintTasksDoneAction ook toe aan actions/sprints.ts omdat die
branch nog niet op main staat.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-06 06:36:13 +02:00
Janpeter Visser
f09f5a2a06
feat(ST-9pobw4w6): setAllSprintTasksDoneAction — alle sprint-taken atomair op DONE (#120)
Voegt setAllSprintTasksDoneAction toe aan actions/sprints.ts. De actie haalt
alle taken op voor een sprint (via sprint_id + product_id), zet ze via een
interactieve Prisma-transactie op DONE met updateTaskStatusWithStoryPromotion,
en promoot parent-stories automatisch als alle taken DONE zijn.

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-06 06:35:56 +02:00
Janpeter Visser
31dc429b61
feat(M13 PBI-31 T-519b/T-520b): NavBar stand-by badge + quota-check runbook (#119)
* feat(M13 T-519b): SSE worker_heartbeat + NavBar stand-by badge

Aanvulling op scrum4me-mcp PR #25 (worker_heartbeat MCP-tool).

- app/api/realtime/solo/route.ts: WorkerHeartbeatPayload type +
  isWorkerHeartbeatPayload guard + shouldEmit-routing op user_id.
- stores/solo-store.ts: workerQuotaPct + workerQuotaCheckAt state +
  setWorkerQuota action. Reset bij decrementWorkers naar 0.
- lib/realtime/use-solo-realtime.ts: handle worker_heartbeat-event,
  roep setWorkerQuota.
- components/solo/nav-status-indicators.tsx: stand-by badge wanneer
  workerQuotaPct < minQuotaPct + tooltip met drempel.
- components/shared/nav-bar.tsx + app/(app)/layout.tsx: minQuotaPct
  prop plumbing van User.min_quota_pct naar NavStatusIndicators.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* docs(M13 T-520b): pre-flight quota-check sectie in mcp-integration

Documenteert de batch-loop-uitbreiding:
1. get_worker_settings → min_quota_pct
2. bin/worker-quota-probe.sh → pct + reset
3. worker_heartbeat naar server (NavBar stand-by-badge)
4. Sleep tot reset bij low quota; anders wait_for_job

Verwijst naar bin/worker-quota-probe.sh in scrum4me-docker (zie
PR daar).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-06 04:34:48 +02:00
Janpeter Visser
555ed8fe89
feat(ST-qfpqpxzy): DB schema + settings-UI voor min_quota_pct worker-drempel (#118)
- User.min_quota_pct Int @default(20) + ClaudeWorker.last_quota_pct/last_quota_check_at
- Migratie add_worker_quota_gate
- lib/schemas/user.ts: minQuotaPctSchema (int, 1-100)
- actions/settings.ts: updateMinQuotaPctAction met auth/demo/zod-guard
- MinQuotaEditor component met numeric input en DemoTooltip
- Settings-pagina: Worker-instellingen sectie

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-06 03:45:59 +02:00
Janpeter Visser
78543ee796
feat(ST-dgognlsz): SoloTaskCard 4-regels layout met Tooltips (#117)
4-regels layout: taaknaam+task_code badge (tooltip: naam+beschrijving),
beschrijving+pbi_code badge (tooltip: pbi_title+pbi_description), story+job-badge.
SoloTaskCardOverlay identieke 4-regels structuur zonder tooltips.
PBI-velden toegevoegd aan SoloTask-interface + Prisma-queries + test-fixtures.

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-06 03:35:32 +02:00
Janpeter Visser
be8cd4d02c
feat(ST-vi5iff4s): SoloTask-interface + Prisma-queries uitbreiden met PBI-velden (#116)
pbi_code, pbi_title, pbi_description (nullable) toegevoegd aan SoloTask-interface.
Desktop en mobile solo-page: story.pbi select + mapping via ?. en ?? null.
Test-fixtures bijgewerkt (3 bestanden). 72 testfiles groen, tsc + build slagen.

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-06 03:30:11 +02:00
Janpeter Visser
d819d29b04
feat(ST-d9sl8egw): lib/insights/token-history.ts — sprint-historiek, dag-data & PBI-aggregaat (#115)
Drie functies via prisma.$queryRaw: getSprintTokenHistory (per-sprint
aggregaat), getDayTokenData (dag-totalen met guard op lege sprintId),
getPbiTokenAggregates (per-PBI met guard). Tests voor alle drie.

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-06 03:19:45 +02:00
Janpeter Visser
a2c8bd41af
ST-1216: Insights sprint-widget — token KPI-kaartjes & per-job tabel (#114)
* feat(ST-vmc7vpps): lib/insights/token-stats.ts — sprint KPI + per-job query

SQL-queries voor totale tokens/kosten (KPI) en per-job tabel met
ModelPrice JOIN. Guard op lege sprintId. Tests voor empty guard,
KPI-mapping en null token-data.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(ST-vmc7vpps): TokenUsageCard — KPI-kaartjes + sorteerbare per-job tabel

Client-component met drie KPI-strips (totaal tokens, kosten USD, gem. per job)
en sorteerbare tabel op kosten of duur. Nulls als '—', MD3-tokens, geen
hardcoded kleuren.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(ST-vmc7vpps): insights page — TokenUsageCard integreren

Voeg getTokenStats + TokenUsageCard imports toe aan insights/page.tsx.
tokenStats apart awaiten na activeSprints (kan niet in dezelfde Promise.all).
TokenUsageCard-sectie toegevoegd na AgentThroughputCard.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-06 03:19:30 +02:00
Janpeter Visser
b147f813d4
docs(ST-5xfaavbo): mcp-integration.md — update_job_status optionele token-velden gedocumenteerd (#113)
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-06 03:19:15 +02:00
Janpeter Visser
50d0fcab37
feat(PBI-34 ST-1213): UI — multi-select badges + lijst-filter (#111)
* feat(ideas): multi-select secundaire producten + badges in IdeaDetailLayout

Voegt checkbox-lijst toe voor extra producten (exclusief primaire) in
de Idee-tab, geïntegreerd in bestaande save/reset flow via
updateSecondaryProductsAction. Toont secundaire product-badges in de
detail-header. Bevat ook schema/dto/action-dependencies (IdeaProduct
junction, secondary_products in IdeaDto).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(ideas): lijst-filter matcht op primair én secundaire producten

Breidt productFilter-logica in IdeaList uit: naast product_id
wordt ook idea.secondary_products gecheckt, zodat ideeën zichtbaar
blijven bij filteren op een secundair gekoppeld product.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-06 03:18:50 +02:00
Janpeter Visser
9a733d77bb
feat(ST-mgsu85hr): Prisma schema — token-velden op ClaudeJob + ModelPrice model (#112)
- Voeg model_id, input_tokens, output_tokens, cache_read_tokens, cache_write_tokens (nullable) toe aan ClaudeJob
- Voeg nieuw ModelPrice model toe met per-1M prijsvelden en currency default USD
- Migratie 20260506010013_add_token_usage_fields aangemaakt en toegepast
- Seed uitgebreid met standaardprijzen voor claude-opus-4-7, claude-sonnet-4-6, claude-haiku-4-5-20251001

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-06 03:02:00 +02:00
Janpeter Visser
f360c8fe81
Merge pull request #110 from madhura68/feat/story-i9ylvvhk
feat(PBI-34 ST-1212): backend — secondary_products in DTO + updateSecondaryProductsAction
2026-05-06 02:44:46 +02:00
Janpeter Visser
51a7a69be3
Merge pull request #109 from madhura68/feat/story-qtkvz6ly
feat(PBI-34 ST-1211): IdeaProduct junction model + relaties
2026-05-06 02:41:56 +02:00
Scrum4Me Agent
a5afb8c5fd feat(ideas): updateSecondaryProductsAction — atomisch vervangen secundaire producten
Voegt server action toe die secondary_products voor een idee atomisch
vervangt: primair product gefilterd, toegankelijkheid gevalideerd via
productAccessFilter, deleteMany + createMany in één transactie.
Demo-geblokkeerd, Zod-gevalideerd.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-06 02:23:00 +02:00
Scrum4Me Agent
4a929b1962 feat(ideas): secondary_products meeladen in IdeaDto en alle queries
Voegt IdeaProduct schema toe (dependency van story-qtkvz6ly), breidt
IdeaWithProduct type en IdeaDto interface uit met secondary_products array,
en laadt de relatie mee in findMany/findFirst in page.tsx en REST GET.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-06 02:20:34 +02:00
Scrum4Me Agent
9d6239b0eb feat(schema): IdeaProduct junction model + relaties op Idea en Product
Voegt IdeaProduct model toe met idea_id/product_id/created_at,
unique constraint op (idea_id, product_id), cascade-deletes.
Breidt Product.idea_products en Idea.secondary_products relaties uit.
Migratie 20260506010000_add_idea_product_secondary aangemaakt en toegepast.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-06 02:16:26 +02:00
Janpeter Visser
d5333eb7d8
Merge pull request #108 from madhura68/feat/auto-pr-ui-and-docs
docs(PBI-36 ST-1220): auto-pr-flow runbook
2026-05-06 00:43:43 +02:00
Janpeter Visser
6cda5b4930
Merge pull request #107 from madhura68/feat/pbi-36-sync-tab
feat(PBI-36 ST-1219): Sync-tab op Idea-detail
2026-05-06 00:43:30 +02:00
c15719164a docs(auto-pr): runbook voor end-to-end auto-PR flow
Beschrijft hoe agent-jobs met Product.auto_pr=true automatisch
commit → push → PR → auto-merge → deploy doorlopen. Documenteert
welke laag wat doet (worker, scrum4me-mcp, GitHub Actions, Vercel),
setup-vereisten per product, foutpaden en wanneer auto_pr UIT
laten.

Onderdeel van PBI-36 ST-1220. De auto-PR-implementatie zelf zit
in scrum4me-mcp; deze runbook documenteert de bestaande flow plus
de nieuwe auto-merge-stap (scrum4me-mcp PR #23).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-06 00:37:18 +02:00
678069a3d8 feat(T-563): integreer Sync-tab in IdeaDetailLayout + page-loader
- TabKey union uitgebreid met 'sync'.
- Sync-tab alleen zichtbaar als syncData !== null && idea.status === 'planned'
  (M12 keuze 6: na Materialiseer-actie).
- page.tsx roept loadIdeaSyncData alleen aan bij PLANNED + pbi_id, anders
  null doorgeven aan layout.
- showSync-flag bepaalt of de tab in TAB_KEYS array zit en in de UI
  gerenderd wordt.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-06 00:21:59 +02:00
dbf30a2fcb feat(T-562): IdeaSyncTab component met StoryLog-hergebruik
Toont per Story onder de gekoppelde PBI: status-badge, taak-rij met
job-status (incl. SKIPPED), branch, pushed_at, pr_url, en bestaande
<StoryLog>-component voor activity-log. PBI-header met PR-link en
gemerged-badge.

Realtime: subscribed op /api/realtime/notifications. Bij story_log-
event waar story_id matcht, of claude_job_status voor dit idea →
router.refresh() (server-render levert nieuwe data).

MD3-tokens overal: bg-status-todo/in-progress/done, bg-surface-
container, bg-muted/60. Geen bg-blue-500.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-06 00:20:12 +02:00
f4f02bd0d2 feat(T-561): loadIdeaSyncData server-loader voor Sync-tab
Joint Idea → PBI → Stories → Tasks → ClaudeJobs + StoryLog in één
prisma.findFirst-call. user_id-scope conform M12-keuze 2 (strikt
user_id-only). Filtert ClaudeJob op kind=TASK_IMPLEMENTATION en
neemt laatste 20 story-logs per story.

Returns null als idea geen pbi_id heeft — caller render geen tab.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-06 00:18:21 +02:00
e1da9aae43 feat(T-560): SSE-route accepteert story_log-payloads
StoryLogPayload type toegevoegd aan NotifyPayload union. In de
notification-handler: idea_id-pad checkt accessibleIdeaIds (M12
user-private), fallback op product_id check accessibleProductIds.
Consistent met question-payload-pattern.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-06 00:17:38 +02:00
a5f62a0323 feat(T-559): pg_notify-trigger op story_logs voor sync-tab realtime
AFTER INSERT op story_logs emit op scrum4me_changes channel met
entity:'story_log'. Trigger resolved product_id en idea_id via
story → pbi → product/idea zodat SSE-route kan filteren zonder
extra DB-call per event.

Migratie toegepast op Neon productie-DB.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-06 00:16:52 +02:00
Janpeter Visser
f570f07d4a
Merge pull request #106 from madhura68/feat/pbi-36-deploy-controle
feat(PBI-36 ST-1218): selectieve deploy-controle via labels + path-filter
2026-05-06 00:15:48 +02:00
a57eadbbd3 fix(ci): permissions block voor dorny/paths-filter API-toegang
dorny/paths-filter@v3 leest PR-changed-files via de GitHub API.
Default GITHUB_TOKEN heeft op deze repo geen pull-requests:read
permission, waardoor de action faalde met "Resource not accessible
by integration".

Workflow-level permissions toegevoegd: contents:read +
pull-requests:read. Geen andere wijzigingen aan jobs nodig.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-06 00:14:18 +02:00
ee793e9af4 docs(T-557): deploy-control runbook + CLAUDE.md verwijzing
docs/runbooks/deploy-control.md beschrijft triggers (push/PR/dispatch),
path-filter, labels (skip-deploy/force-deploy), beslismatrix per
scenario, voorbeelden en troubleshooting. CLAUDE.md hardstop-regel
"Deployment" verwijst naar runbook.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 23:36:48 +02:00
fe56d4e0c1 feat(T-554/T-555/T-556): selectieve deploy-controle in workflow
Drie samenhangende wijzigingen in ci.yml:

T-554: Nieuwe `changes` job met dorny/paths-filter@v3 die per push/PR
detecteert of er deploy-relevante paden zijn gewijzigd. Output `code`
boolean wordt door de deploy-jobs gelezen.

T-555: deploy-preview if-conditie checkt nu `needs.changes.outputs.code`
plus PR-labels: deployt als (code-changed AND niet skip-deploy) OR
force-deploy. deploy-production deployt alleen bij code-changed pushes
naar main (path-filter op productie).

T-556: workflow_dispatch trigger toegevoegd met `target: preview |
production` input + nieuwe deploy-manual job. Geeft handmatige
re-deploy via Actions-tab. CI-job slaat workflow_dispatch over (geen
nieuwe code, alleen redeploy).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 23:35:22 +02:00
6e5c91b6fa feat(T-553): vercel.json git.deploymentEnabled=false + GitHub-labels
Vercel's eigen Git-integratie uitzetten zodat de GitHub Actions
workflow de enige bron van deploy-truth wordt. Plus labels
skip-deploy en force-deploy aangemaakt voor selectieve controle
in volgende taken.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 23:31:34 +02:00
Janpeter Visser
30955462e4
Merge pull request #105 from madhura68/feat/pbi-37-skipped-job-status
feat(PBI-37): SKIPPED-status voor ClaudeJob + worker-idempotency runbook
2026-05-05 23:20:50 +02:00
084ca81090 docs(T-575): worker-idempotency runbook + CLAUDE.md verwijzing
Beschrijft beslissingsboom verify_result × diff-staat × branch-staat
→ JobStatus, met SKIPPED gereserveerd voor al-gemergd werk en FAILED
voor échte fouten. Plus StoryLog-verplichting (log_implementation,
log_commit, log_test_result) en idempotency-protocol vóór schrijven.

PBI-33 batch (5-5 22:22) gedocumenteerd als case-study: drie
protocol-overtredingen die deze runbook + de nieuwe SKIPPED-status
aanpakken.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 23:13:49 +02:00
ca1a89ca04 test(T-574): cron-cleanup test verwacht SKIPPED in deleteMany filter
Bijgewerkt na uitbreiding van cleanup-criteria met SKIPPED-jobs in
T-572.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 23:12:11 +02:00
273735384a feat(T-573): SKIPPED-badge styling in admin jobs-table
Italic, neutrale grijstint die SKIPPED visueel onderscheidt van
CANCELLED (zelfde grijstint, maar non-italic) en van FAILED (rood).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 23:10:48 +02:00
deb70a9e20 feat(T-572): map SKIPPED in lib/job-status + alle terminal-checks
- lib/job-status.ts: SKIPPED ↔ 'skipped' mapping in beide richtingen
- components/shared/job-status.ts: label "Overgeslagen" + neutrale italic styling
- actions/admin/jobs.ts: cancel-guard erkent SKIPPED als eindstatus
- app/api/cron/cleanup-agent-artifacts: SKIPPED ook opruimen na 7d
- lib/insights/agent-throughput: SKIPPED telt mee als terminal

ACTIVE_JOB_STATUSES bewust ongewijzigd — SKIPPED is afgerond.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 23:10:14 +02:00
fc2f819645 feat(T-571): voeg SKIPPED toe aan ClaudeJobStatus enum
Reactie op PBI-33 batch waar worker correct detecteerde dat werk al
gemerged was, maar geen passende status had om dat uit te drukken.
SKIPPED is bedoeld voor jobs met verify=EMPTY/DIVERGENT waar de
diff t.o.v. origin/main leeg is — geen FAILED (geen fout), geen DONE
(geen netto-output).

Migratie: ALTER TYPE ClaudeJobStatus ADD VALUE 'SKIPPED'.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 23:05:38 +02:00
649c87b658 feat: Ideas UI verbeteringen — hernoeming, tab-states, timeline refresh
- Nav-label 'Ideeën' hernoemd naar 'Ideas'; breadcrumb idem
- Grill/Plan tabs disabled (grijs, cursor-not-allowed) zolang er geen
  content is; groene stip zodra grill_md resp. plan_md beschikbaar is
- SSE hook roept router.refresh() aan bij job done/failed zodat de
  Timeline automatisch de nieuwe GRILL_RESULT/PLAN_RESULT logs toont

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-05 21:13:56 +02:00
474a8da053 feat: admin jobs en products pagina's
- /admin/jobs: overzicht van de laatste 100 Claude jobs met cancel/delete
- /admin/products: overzicht van alle producten met archive/delete
- JobsTable component met statusbadges en acties per job
- ProductsTable component met eigenaar, leden/PBI-telling en acties

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-05 20:46:27 +02:00
fbf58d4e44 fix: admin-navigatie zichtbaar voor ADMIN-rol gebruikers
- requireAdmin() checkt nu de database i.p.v. session.isAdmin (was altijd undefined)
- loginAction stelt session.isAdmin in op basis van UserRole in de DB
- registerAction stelt session.isAdmin = false expliciet in
- NavBar toont 'Admin'-link conditioneel als roles.includes('ADMIN')
- UserMenu ROLE_LABELS uitgebreid met ADMIN → 'Admin'
- Tests aangepast: prismaUserRole.findFirst mock toegevoegd

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-05 20:46:27 +02:00
Janpeter Visser
c3f10cccce
Merge pull request #104 from madhura68/feat/story-0vtnydpi
ST-1210: S3 — Frontend: Chat & Timeline tab UI
2026-05-05 17:41:53 +02:00
Scrum4Me Agent
99ae2d7e8f feat(ST-zyb6qlnn): UserQuestions server-side ophalen en als prop doorzenden
- app/(app)/ideas/[id]/page.tsx: userQuestion.findMany + DTO-mapping
- components/ideas/idea-detail-layout.tsx: IdeaUserQuestionDto type +
  userQuestions prop toegevoegd aan Props interface en component-signature

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-05 17:40:31 +02:00
Janpeter Visser
a6c57eba15
Merge pull request #103 from madhura68/feat/story-7pl4dsb6
ST-1209: S2 — Backend: vraag indienen, beantwoorden en SSE-events
2026-05-05 17:31:31 +02:00
Janpeter Visser
dd77dfb1b5
Merge pull request #102 from madhura68/feat/story-hyikiufi
ST-1208: S1 — Datamodel: UserQuestion model en PLAN_CHAT jobkind
2026-05-05 17:31:07 +02:00
Scrum4Me Agent
1067167611 feat(ST-p6d1odh0): createUserQuestionAction — UserQuestion + PLAN_CHAT job queuing
- Nieuwe server action in actions/user-questions.ts
- Aanmaken UserQuestion + ClaudeJob PLAN_CHAT in transactie
- Blokkeert als idea.plan_md null is of product ontbreekt
- Idempotency-check: geen dubbele PLAN_CHAT per idee
- pg_notify claude_job_enqueued event voor SSE-realtime
- Rate-limit config uitgebreid met create-user-question

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-05 17:30:00 +02:00
Scrum4Me Agent
8bccb56b21 feat(ST-bsjoqjnr): UserQuestion model + PLAN_CHAT enum-waarde
- Voeg PLAN_CHAT toe aan ClaudeJobKind enum
- Voeg UserQuestionStatus enum toe (pending, answered)
- Voeg UserQuestion model toe met idea_id, user_id, question, answer, status
- Koppel user_questions relatie aan Idea model
- Migratie: 20260505120000_add_user_question_plan_chat

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-05 17:26:22 +02:00
Janpeter Visser
881ee007e5
Merge pull request #101 from madhura68/feat/story-abeu63oz
ST-1207: Admin: productenbeheer & ledenbeheer (/admin/products)
2026-05-05 14:55:19 +02:00
Scrum4Me Agent
b9e6e725b6 feat(ST-abeu63oz): admin products-actions (create, update, archive, delete, addMember, removeMember)
- Zod-schema adminProductSchema (name, description, repo_url, definition_of_done, auto_pr, owner_user_id)
- adminCreateProductAction: owner-validatie, prisma.product.create
- adminUpdateProductAction: zelfde schema zonder owner_user_id
- adminArchiveProductAction: toggle archived-vlag
- adminDeleteProductAction: hard delete (cascade)
- adminAddMemberAction: upsert ProductMember
- adminRemoveMemberAction: deleteMany ProductMember
2026-05-05 14:54:08 +02:00
Janpeter Visser
9861495dbd
Merge pull request #100 from madhura68/feat/story-xmwvqru1
ST-1206: Admin: ClaudeJobs beheer (/admin/jobs)
2026-05-05 14:48:30 +02:00
Scrum4Me Agent
788920b790 feat(ST-xmwvqru1): admin jobs-actions (cancelJob, deleteJob)
- lib/session.ts: isAdmin: boolean toegevoegd
- lib/auth-guard.ts: requireAdmin() toegevoegd
- actions/admin/jobs.ts: cancelJobAction (CUID-validatie, eindstatus-check → CANCELLED),
  deleteJobAction (hard delete) — beide 'use server', revalidatePath('/admin/jobs')
2026-05-05 14:47:11 +02:00
Janpeter Visser
384a7ecd4a
Merge pull request #99 from madhura68/feat/story-111ci8t4
ST-1205: Admin: gebruikersbeheer (/admin/users)
2026-05-05 14:44:55 +02:00
Janpeter Visser
64b8c7f5d7
Merge pull request #98 from madhura68/feat/story-l9kkxh2m
ST-1204: Password-reset-flow & CLI-bootstrap
2026-05-05 14:44:27 +02:00
Scrum4Me Agent
31edfa8194 feat(ST-111ci8t4): /admin/users pagina met tabel, role-editor en delete-dialog
- app/(app)/admin/layout.tsx: admin-sidebar met links (Gebruikers/Claude Jobs/Producten)
- app/(app)/admin/page.tsx: redirect naar /admin/users
- app/(app)/admin/users/page.tsx: server component, query users+roles, geeft userId door
- components/admin/users-table.tsx: client component met UsersTable, RoleBadge,
  RolesDialog (checkboxes, eigen ADMIN-rol geblokkeerd), DeleteDialog (confirm),
  ResetToggle — alles via useTransition + server actions
2026-05-05 14:44:04 +02:00
Scrum4Me Agent
5fd56e3f67 feat(ST-111ci8t4): admin user-actions (delete, updateRoles, setMustResetPassword)
- lib/session.ts: isAdmin: boolean toegevoegd aan SessionData
- lib/auth-guard.ts: requireAdmin() toegevoegd (redirect /dashboard bij !isAdmin)
- actions/admin/users.ts: deleteUserAction (zelfbescherming), updateUserRolesAction
  (Zod z.nativeEnum, eigen ADMIN-rol-beveiliging, transactie), setMustResetPasswordAction
  — alle drie 'use server', revalidatePath('/admin/users')
2026-05-05 14:38:42 +02:00
Scrum4Me Agent
b760ec625e feat(ST-l9kkxh2m): CLI-script scripts/create-admin.ts voor admin-bootstrap
- Maakt user aan als die niet bestaat, anders upgrade bestaande user
- Upsert ADMIN in user_roles (idempotent)
- Helder foutbericht als argumenten ontbreken (process.exit(1))
- package.json scripts: "create-admin": "tsx scripts/create-admin.ts"
2026-05-05 14:34:10 +02:00
Scrum4Me Agent
a19ae89e37 feat(ST-l9kkxh2m): /reset-password pagina + resetPasswordAction + hashPassword
- lib/auth.ts: hashPassword(password) geëxporteerd (bcrypt, rounds=12)
- actions/auth.ts: resetPasswordAction met Zod-validatie (min 8, superRefine gelijkheid),
  prisma.user.update (password_hash + must_reset_password=false), redirect /dashboard
- app/(auth)/reset-password/page.tsx: server guard (userId check + must_reset_password check)
- app/(auth)/reset-password/reset-form.tsx: client form (nieuw wachtwoord + bevestiging)
- __tests__/actions/auth.test.ts: 3 tests voor resetPasswordAction
2026-05-05 14:30:59 +02:00
Janpeter Visser
71281038ff
Merge pull request #97 from madhura68/feat/story-nma6ylbl
ST-1203: Database-schema, sessie-uitbreiding & admin-routing
2026-05-05 14:19:21 +02:00
Scrum4Me Agent
19c458287a feat(ST-nma6ylbl): Prisma-migratie ADMIN enum + must_reset_password + CANCELLED-status
- Role enum: ADMIN toegevoegd (na DEVELOPER)
- User model: must_reset_password Boolean @default(false) toegevoegd (na bio_detail)
- ClaudeJobStatus: CANCELLED was al aanwezig, geen wijziging nodig
- Migratie SQL: ALTER TYPE buiten transactie geplaatst (IF NOT EXISTS)
- prisma migrate deploy toegepast, prisma generate gedraaid
- lint 0 errors, 546 tests groen, build succesvol
2026-05-05 14:18:10 +02:00
Janpeter Visser
d2601b6e9b
Merge pull request #96 from madhura68/fix/idea-pbi-link-route
fix(m12): broken /backlog route on PBI-link after materialize
2026-05-05 14:12:17 +02:00
b25c3c5482 fix(m12): drop bogus /backlog#pbi-{code} route on PBI-link
Three places linked to \`/products/[id]/backlog#pbi-{pbi_code}\` after
materializing or in the planned-state link-card. That route doesn't
exist (product backlog lives at \`/products/[id]\` directly), and the
hash was double-prefixed (\`#pbi-PBI-32\`) since pbi_code already starts
with PBI-. Result: 404 for the user.

Fix: route to \`/products/[id]\` without anchor. The new PBI is the most
recent so visible near the top. Per-PBI anchor scrolling is a follow-up
once we add \`id="pbi-{id}"\` attributes to pbi-list rows.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 14:06:24 +02:00
Janpeter Visser
96bda7da00
Merge pull request #95 from madhura68/fix/idea-timeline-auto-refresh
fix(m12): IdeaTimeline auto-refresh on new idea-questions
2026-05-05 13:45:18 +02:00
Janpeter Visser
c6db766ff7
Merge pull request #94 from madhura68/fix/idea-timeline-hydration-locale
fix(m12): hydration mismatch on IdeaTimeline timestamps
2026-05-05 13:45:02 +02:00
Janpeter Visser
fe880d1d05
Merge pull request #93 from madhura68/fix/m12-bell-loses-idea-questions-on-reconnect
fix(m12): bell loses idea-questions on SSE reconnect
2026-05-05 13:44:47 +02:00
5793afc709 fix(m12): IdeaTimeline auto-refresh on new idea-questions
The /ideas/[id]?tab=timeline page is server-rendered: questions are a
prop snapshot. Without a router.refresh, new questions only show after a
manual page reload — and during a grill-session that's every ~20s.

Fix: in use-notifications-realtime, after dispatching idea-question
events to idea-store + re-syncing the bell, call \`router.refresh()\`.
This re-runs the server-component for whichever page the user is on; on
/ideas/[id] it pulls the new question. On other pages it's a no-op (no
visible state change).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 13:44:15 +02:00
4a86910e66 fix(m12): hydration mismatch on IdeaTimeline timestamps
\`new Date(...).toLocaleString()\` zonder expliciete locale gebruikt de
default-locale van runtime: server (Node) levert nl-NL formaat
(\`05/05/2026, 13:21:51\`), browser CSR levert en-US (\`5/5/2026, 1:21:51 PM\`).
React detecteert dat als hydration-mismatch en regenereert de tree.

Fix: pass \`'nl-NL'\` met expliciete date/time-style. Server en client
produceren nu identieke output.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 13:29:43 +02:00
bec4c05e80 fix(m12): bell loses idea-questions on SSE reconnect
The notifications-realtime hook (PR #92) does close+connect on every
idea-question 'open' event, but the SSE state-event-handler in
/api/realtime/notifications only re-fetched story-questions. Result:
each reconnect wiped idea-questions from the bell within ~500ms, even
though the bridge had loaded them on initial page-render.

Symptom: clicking an idea-question in the bell sometimes hit a
\"question gone\" race because the close+connect after the live event
emptied them out.

Fix: SSE initial-state now does a Promise.all on
- story-questions (productAccessFilter, existing path)
- idea-questions (idea.user_id === session.userId, M12 strict-private)
and sends merged + sorted state with discriminated \`kind\` field.

This mirrors the bridge's own initial fetch (PR #92), so a bridge-mount
and an SSE-reconnect now produce identical state.

Tests: 546/546 still green.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 13:14:48 +02:00
Janpeter Visser
4daa564811
Merge pull request #92 from madhura68/fix/m12-idea-question-answering
fix(m12): answer idea-questions — inline + bell support
2026-05-05 13:06:57 +02:00
9e8f33b96e fix(m12): user can answer idea-questions — inline + bell support
Two gaps discovered during the first live grill-session of IDEA-002:
the agent posted a question, but the user had no UI to answer it.
1. Idea-questions only appeared on the Timeline-tab as read-only entries
2. Notifications-bell fetched + handled story-questions only

This fix:

**Inline answer-form in IdeaTimeline** (components/ideas/idea-timeline.tsx)
- Open questions now render an AnswerForm directly under the question text
- Multi-choice options become clickable buttons (one-click submit); free-text
  fallback via collapsed details/textarea
- Plain free-text questions render textarea + Verzend
- Calls existing answerQuestion server-action; toast + router.refresh on success

**Notifications-bell extended for idea-questions**
- stores/notifications-store.ts: NotificationQuestion → discriminated union
  (kind: 'story' | 'idea'); forYouCount treats idea-questions as always-for-you
  (idea is strictly user_id-only — only the owner sees them)
- components/notifications/notifications-bridge.tsx: parallel fetch of
  story-questions (productAccessFilter) + idea-questions (idea.user_id ===
  session.userId); merged + sorted by created_at
- components/notifications/notifications-sheet.tsx: renders idea_code/title
  for kind='idea'
- components/notifications/answer-modal.tsx: header + open-link branch on
  kind (idea → /ideas/[id]?tab=timeline; story → existing /sprint link)
- lib/realtime/use-notifications-realtime.ts: idea-question events also
  trigger close+reconnect on 'open' (loads fresh detail) and remove(id) on
  non-open — same pattern story-questions already use
- components/shared/notifications-bell.tsx: badge counts idea-questions as
  for-you regardless of assignee

**Security gap closed (actions/questions.ts answerQuestion)**
Before: accepted any answer if user has product-access.
After: idea-questions require idea.user_id === session.userId; story-
questions keep the existing productAccessFilter path. (Prisma 7 rejects
\`{ not: null }\` in WHERE; routing happens app-level after a single fetch.)

Tests: 546/546 still green.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 13:05:39 +02:00
Janpeter Visser
2893573004
Merge pull request #91 from madhura68/feat/m12-ideas
M12 — Idea entity + Grill/Plan jobs
2026-05-05 11:58:25 +02:00
02a7f59897 docs: regenerate erd.svg with M12 Idea + IdeaLog models
Auto-generated by prisma generate after schema sync.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 11:55:51 +02:00
Janpeter Visser
452a38726b
Merge pull request #90 from madhura68/docs/pr-merge-conflict-faq
docs(runbook): merge-conflict FAQ voor PR-per-batch flow
2026-05-04 22:14:48 +02:00
492b71beb9 fix: drop \__test__\ export from actions/ideas.ts (use-server-only-fns)
Next.js 'use server' files only allow exports of async functions. The
\`export const __test__ = { canTransition }\` line at the bottom of
actions/ideas.ts threw a runtime error on every page load that imported
the file.

Tests already import canTransition directly from lib/idea-status; the
__test__ helper was vestigial. Removed.

Tests: 546/546 still green.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 21:54:10 +02:00
7269e9732d docs: M12 backlog entry + mcp-integration runbook for idea-jobs (M12 T-517)
docs/backlog/index.md:
- New M12 row in milestone-overview
- Full M12 section with 10 stories (8 done, ST-1197 extern + ST-1201 in
  progress); each story lists its task IDs

docs/runbooks/mcp-integration.md:
- wait_for_job payload contract documented per kind discriminator
  (TASK_IMPLEMENTATION vs IDEA_GRILL vs IDEA_MAKE_PLAN)
- Per-kind agent behavior table
- 5 new MCP-tools documented: get_idea_context, update_idea_grill_md,
  update_idea_plan_md, log_idea_decision; plus extended ask_user_question
  contract (story_id|idea_id xor)
- Batch-loop step 2 expanded to switch on kind

docs/INDEX.md auto-regenerated (83 docs).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 21:45:54 +02:00
6721003572 ui: nav entry "Ideeën" between Insights and Todo's (M12 T-515)
components/shared/nav-bar.tsx:
- New nav-link to /ideas with active-state on pathname.startsWith('/ideas')
- Placement: between Insights and Todo's — matches the M12 plan
  ("direct boven Todo's")
- No icon (existing nav uses text-only links; deviation from plan's
  Lightbulb spec for visual consistency with the rest of the nav)

Tests: 546/546 still green.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 21:43:51 +02:00
7595474fcc ui: "→ Idee" promote button in TodoCard + PromoteIdeaDialog (M12 T-514)
components/todos/todo-list.tsx:
- TodoCard: new "→ Idee" button next to "→ PBI" + "→ Story" (only shown
  for non-demo)
- PromoteIdeaDialog: confirmation modal — no extra inputs needed since
  promoteTodoToIdeaAction takes only todoId; title/description carry
  over from the todo, status starts as DRAFT
- onPromoteIdea callback wired through TodoCard props
- On success: navigates to /ideas/{new-id} so user lands on the fresh
  idea-detail page

Tests: 546/546 still green.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 21:42:59 +02:00
2f41f8917a docs: idea-dialog profile (M12 T-513)
docs/specs/dialogs/idea.md:
- Velden-table with bron-zod links
- URL/state-pattern: dedicated route /ideas/[id] (afwijking van generieke
  modal-spec — rationale documented)
- 4-tab layout spec
- Full state-machine table with transition triggers + server actions
- Server-action catalog with preconditions + foutcodes
- 3-layer demo-policy (proxy + isDemo-guard + DemoTooltip), incl. wat
  demo WEL mag (download-md is read-only)
- Special behaviors: Cmd/Ctrl+S, localStorage draft (lazy seed),
  useMemo-derived validation, status-badge tokens, connectedWorkers
  via solo-store
- Realtime routing notes
- Test-fixture inventory (90+ cases across 7 test files)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 21:41:00 +02:00
1ba9feac1a ui: idea-timeline + pbi-link-card + download-md-button (M12 T-512)
components/ideas/idea-timeline.tsx:
- Chronological merge of IdeaLog + ClaudeQuestion (sorted desc by created_at)
- Per-entry icon by log-type (DECISION/NOTE/GRILL_RESULT/PLAN_RESULT/
  STATUS_CHANGE/JOB_EVENT) + question-status label
- MD3-tokens, vertical timeline rail (border-left + dots)
- Question entries show options + answer (border-left highlight)
- Metadata expansion via <details> for log entries

components/ideas/idea-pbi-link-card.tsx:
- PLANNED + pbi present: green status-done card with PBI link
- PLANNED + pbi removed (FK SetNull): blocked-color banner with
  "Plan opnieuw beschikbaar maken" → relinkIdeaPlanAction
- Demo blocked on relink

components/ideas/download-md-button.tsx:
- Calls downloadIdeaMdAction → builds Blob + anchor + click()
- Filename: {idea.code}-{kind}.md
- Demo MAY use it (read-only)

components/ideas/idea-detail-layout.tsx:
- Replaces inline placeholders with extracted components
- Md tabs gain Download (.md) button + Edit button row

Tests: 546/546 still green.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 21:39:33 +02:00
9d3a993f2a ui: idea-md-editor with yaml-validate + wire into detail tabs (M12 T-511)
components/ideas/idea-md-editor.tsx:
- Textarea-based editor with monospace styling for grill_md / plan_md
- kind='plan': live yaml-frontmatter validation as derived state via
  useMemo (no setState-in-effect); inline errors with line numbers
- kind='grill': free markdown, no validation
- localStorage draft per (ideaId, kind) — lazy initial-value seeded on
  mount; toast notice if drift from server
- Cmd/Ctrl+S keyboard shortcut to save
- Server-action 422 details surface as separate submitErrors state

components/ideas/idea-detail-layout.tsx:
- Grill/Plan tabs flip into edit-mode via "Bewerk" button when:
  - grill: status in [GRILLED, PLAN_READY] (M12 grill-keuze 12)
  - plan: status === PLAN_READY
- Empty-state offers "Schrijf zelf" when md is null + editable
- Demo always read-only

Tests: 546/546 still green.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 21:37:49 +02:00
1362996a2b ui: /ideas/[id] detail page with 4-tab layout (M12 T-510)
app/(app)/ideas/[id]/page.tsx (server-component):
- user_id-only fetch with notFound() on miss (anti-enumeration)
- Parallel fetch: idea+product+pbi, products list, recent logs (100),
  questions (50)

components/ideas/idea-detail-layout.tsx (client-component):
- Header: code + title + status-badge + product-link + IdeaRowActions
- PBI-link card when PLANNED (or Re-link banner when pbi removed —
  T-512 wires the action)
- URL-based tab switcher (?tab=idee|grill|plan|timeline) — bookmarkable
- Idee-tab: inline edit form with isIdeaEditable guard, dirty-tracking +
  Reset/Save buttons
- Grill/Plan-tabs: read-only md preview (T-511 will add the editor)
- Timeline-tab: chronological merge of IdeaLog + ClaudeQuestion entries
  (T-512 will polish the styling and component-split)

Tests: 546/546 still green.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 21:35:48 +02:00
a1d3a83af5 ui: full IdeaRowActions with disabled-rules + tooltips (M12 T-508)
components/ideas/idea-row-actions.tsx — replaces T-507 placeholder:
- Grill Me: disabled in GRILLING/PLANNING/PLANNED, requires
  product-with-repo + connectedWorkers > 0; tooltip shows specific reason
  ("Grill loopt al", "Idee heeft een product met repo nodig", "Geen
  Claude-worker actief")
- Make Plan: enabled only in GRILLED/PLAN_FAILED/PLAN_READY; same
  prerequisites as Grill
- Materialiseer: enabled only in PLAN_READY (no worker needed — synchrone
  server-side parser); confirm-dialog before action; navigates to product
  backlog PBI anchor on success
- *_FAILED: dedicated "Probeer opnieuw" rotate-icon button
- PLANNED: replaces all three with "Bekijk {PBI-code}" link + open-detail
- Demo: every mutating button wrapped in DemoTooltip with disabled state
- connectedWorkers read directly via useSoloStore (per M12 grill-keuze 16)

Tests: 546/546 still green.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 21:32:06 +02:00
2eb0f33068 ui: /ideas list page + IdeaList table + row-actions skeleton (M12 T-507)
app/(app)/ideas/page.tsx (server-component):
- user_id-only fetch (no productAccessFilter — Idee is privé)
- products fetched with productAccessFilter for filter-dropdown + create-form

components/ideas/idea-list.tsx (client-component):
- Search by title, product-dropdown filter, status multi-chip filter
- Inline create form with title/description/product (optional)
- Native shadcn Table + status badge via getIdeaStatusBadge (T-509)
- Row click navigates to /ideas/[id]
- Sonner toasts for success/error; router.refresh() after mutations
- DemoTooltip + disabled on Nieuw + Archive
- Empty-state + filtered-empty messaging

components/ideas/idea-row-actions.tsx (placeholder for T-508):
- "Open" navigation + "Archive" button only — Grill / Make Plan /
  Materialiseer come in T-508 with full disabled-rules

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 21:30:56 +02:00
006d803a16 ui: idea-status badge helper (M12 T-509)
lib/idea-status-colors.ts: getIdeaStatusBadge(status) → { label, classes,
pulse? }. Reuses existing --status-*-tokens (in-progress / blocked / review
/ done) — no new tokens needed in theme.css.

Mapping (per docs/plans/M12-ideas.md state machine):
- DRAFT          → surface-variant (neutral)
- GRILLING       → in-progress + pulse
- GRILL_FAILED   → blocked
- GRILLED        → review (waiting for next step)
- PLANNING       → in-progress + pulse
- PLAN_FAILED    → blocked
- PLAN_READY     → review
- PLANNED        → done

CLAUDE.md hardstop respected — only MD3-tokens, no arbitrary Tailwind colors.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 21:29:02 +02:00
8cc4e0aeb7 realtime: idea-store + extend notifications hook for idea events (M12 T-503)
stores/idea-store.ts (Zustand):
- jobByIdea, ideaStatuses, openQuestionsByIdea
- handleIdeaJobEvent: derives optimistic ideaStatus (queued/claimed/running →
  grilling/planning; failed → grill_failed/plan_failed; done = no-op since
  the server-side update_idea_*_md is source-of-truth)
- handleIdeaQuestionEvent: list-based, removes on non-open
- setIdeaStatus / setJobStatus / clearForIdea optimistic helpers
- connectedWorkers NOT duplicated — UI reads useSoloStore(s.connectedWorkers)

lib/realtime/use-notifications-realtime.ts:
- Single SSE serves both bell-questions and idea-state. Adds dispatcher
  branches: idea-job payloads → idea-store; idea-question payloads (idea_id
  set) → idea-store; story-questions → existing notifications-store path.

Tests: 7/7 idea-store cases (queued→grilling, failed→*_failed, done no-op,
question-list management, clearForIdea isolation).
Full suite: 546/546 green.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 20:02:22 +02:00
0e2808ac88 realtime: route idea-jobs + idea-questions to /notifications channel (M12 T-502)
Idea-jobs and idea-questions are user-private (M12 grill-keuze 8) — they
flow through /api/realtime/notifications, not /api/realtime/solo.

app/api/realtime/notifications/route.ts:
- Pre-fetch user's idea-ids → accessibleIdeaIds Set (avoids per-event DB lookup)
- New IdeaJobPayload type (claude_job_enqueued/_status with kind=IDEA_*)
- New QuestionPayload narrows: story_id and idea_id mutually exclusive (DB
  check-constraint enforces it)
- Routing: idea-jobs filtered on user_id; idea-questions on accessibleIdeaIds;
  story-questions on accessibleProductIds (existing path)

app/api/realtime/solo/route.ts:
- JobPayload extended with optional kind + idea_id
- shouldEmit filters out kind=IDEA_GRILL/IDEA_MAKE_PLAN — they don't belong
  on the product/sprint Solo Paneel

Tests: 539/539 green; notifications-stream test mock updated for idea.findMany.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 20:00:05 +02:00
a1d1f99216 proxy: add /ideas to protectedRoutes; verify demo-guard for /api/ideas (M12 T-501)
- proxy.ts: /ideas added to protectedRoutes — unauthenticated users get
  redirected to /login when navigating to /ideas or /ideas/[id]
- existing demo-guard catch-all (\`/api/* + non-GET\`) already blocks
  POST/PATCH/DELETE /api/ideas* with 403 — confirmed via 3 new tests
- server-action endpoints (start-grill / start-make-plan / materialize /
  promote-to-idea) carry their own \`session.isDemo\` checks inside
  actions/ideas.ts and actions/todos.ts (defense in depth)

Tests: 9/9 in proxy demo-guard suite (added 3 idea cases).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 19:56:41 +02:00
4b234dc300 api: REST endpoints for ideas (M12 T-500)
- app/api/ideas/route.ts: GET (list with archived/product_id/status filters,
  user_id-scope), POST (creates DRAFT with auto IDEA-NNN code, 201)
- app/api/ideas/[id]/route.ts: GET (idea + recent logs), PATCH
  (ideaUpdateSchema, isIdeaEditable guard)
- lib/idea-dto.ts: API projection — converts Prisma row → DTO with
  lowercase status + has_grill_md/has_plan_md flags (md content excluded
  from list payloads, fetch via dedicated download action)

Auth: session OR API-token via authenticateApiRequest. Strict user_id
scope (no productAccessFilter — Idee is privé per Q8). 404 (not 403) for
foreign-user reads to prevent enumeration.

Tests: 13 cases (auth-401, demo-403, validation-422, malformed-400,
not-found-404, status-mismatch-422, filter param round-trip, DTO shape).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 19:55:49 +02:00
6904de9f2b actions: promoteTodoToIdeaAction (M12 T-499)
actions/todos.ts:
- promoteTodoToIdeaAction(todoId): auth + demo + scope + already-archived
  guards. Atomic \$transaction creates DRAFT Idea (with auto IDEA-NNN code)
  and archives source Todo + IdeaLog{NOTE}.
- Anders dan Todo→PBI/Story (die de todo deleten): we ARCHIVEREN. De idea
  wordt het nieuwe planningsartifact; de archived todo bewaart het
  vertrekpunt (zie M12 grill-keuze 12).

Tests: 5 cases — happy, auth-401, demo-403, scope-404, already-archived-422.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 19:52:37 +02:00
6fee0394c5 actions: materializeIdeaPlanAction + relinkIdeaPlanAction (M12 T-498)
actions/ideas.ts:
- materializeIdeaPlanAction(id):
  - guard: status===PLAN_READY, plan_md present, product linked, demo-403
  - parsePlanMd → 422 with line-info on fail
  - Prisma.\$transaction:
    - SELECT max(code) for PBI/Story/Task within product
    - INSERT PBI with sort_order = lastPbi+1 within priority
    - per story: INSERT (sequential ST-NNN), per task: INSERT (T-N)
    - UPDATE idea SET pbi_id, status=PLANNED
    - INSERT IdeaLog{PLAN_RESULT, metadata}
  - returns 409 on P2002 (concurrent-materialize race)
- relinkIdeaPlanAction(id):
  - guard: status===PLANNED && pbi_id===null (PBI manually deleted via SetNull FK)
  - reverts to PLAN_READY + IdeaLog{NOTE}

Tests: 39 cases total (8 new for materialize + relink): happy creates entities,
status-mismatch-422, parse-fail-422 with details, demo-403, P2002→409,
relink happy + invalid-precondition guards.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 19:51:18 +02:00
33cbb6c2f4 actions: idea-job triggers + cancel (M12 T-497)
actions/ideas.ts:
- startGrillJobAction(id) — DRAFT/GRILLED/GRILL_FAILED/PLAN_READY → GRILLING;
  validates product+repo_url, idempotency check (active job 409),
  worker-count check (15s freshness), atomic $transaction creates ClaudeJob
  + flips idea.status + IdeaLog{JOB_EVENT}, manual pg_notify
- startMakePlanJobAction(id) — GRILLED/PLAN_FAILED/PLAN_READY → PLANNING;
  same shape via shared startIdeaJob helper
- cancelIdeaJobAction(id) — finds active QUEUED|CLAIMED|RUNNING job for idea,
  reverts status: grill→DRAFT/GRILLED based on grill_md presence;
  plan→GRILLED/PLAN_READY based on plan_md presence

Tests: 31 cases incl. happy path, demo-403, no-product/no-repo-422,
no-worker-422, idempotency-409, status-mismatch-422, cancel revert paths,
404 no-active-job.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 19:49:27 +02:00
5f410d3b10 actions: ideas CRUD + grill_md/plan_md edit + download (M12 T-496)
actions/ideas.ts (strikt user_id-only, geen productAccessFilter):
- createIdeaAction(input) — atomic nextIdeaCode + idea.create in $transaction
- updateIdeaAction(id, input) — guards on isIdeaEditable
- archiveIdeaAction / unarchiveIdeaAction
- deleteIdeaAction — refuses when pbi_id linked
- updateGrillMdAction — only in GRILLED|PLAN_READY; logs IdeaLog{NOTE}
- updatePlanMdAction — only in PLAN_READY; runs parsePlanMd; 422 with details on fail
- downloadIdeaMdAction — read-only, demo allowed

Added rate-limit configs: create-idea, edit-idea-md, start-idea-job,
materialize-idea.

Tests: 19 cases covering auth (401), demo (403), zod (422), status guards
(422), 404 cross-user-scope, plan-md parse-fail with details.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 19:47:30 +02:00
4d2e4b0b4b fix: drop \{ not: null }\ filters — Prisma 7 rejects them at runtime
PrismaClientValidationError ('Argument \`not\` must not be null') hit at
runtime when notifications-bridge mounted post-M12 schema change.
Although StringNullableFilter typings allow \`not: null\`, the v7 query
engine rejects it.

Removed the WHERE-side filter in 3 places — null-narrowing already
happens client-side via flatMap / Boolean filter:
- components/notifications/notifications-bridge.tsx
- app/api/realtime/notifications/route.ts
- lib/insights/verify-stats.ts (task_id filter)

Idea-questions / idea-jobs will be routed via separate channels in
T-502 + T-507; for now, story-question + task-job paths simply ignore
NULL rows in their post-fetch mapping.

Tests: 479/479 green; tsc clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 19:44:48 +02:00
dd935c22d3 prompts: embedded grill + make-plan prompts for IDEA_* jobs (M12 T-495)
- lib/idea-prompts/grill.md: interview-loop prompt; uses ask_user_question MCP
  one-question-at-a-time; stop-condition (title + scope + 3+ AC + 1+ risk);
  ends with update_idea_grill_md
- lib/idea-prompts/make-plan.md: single-pass planning prompt; reads grill_md +
  repo; produces strict yaml-frontmatter format consumable by parsePlanMd;
  forbids ask_user_question (twijfels → re-grill via UI)

Both in Dutch, consistent with rest of scrum4me content. No external
anthropic-skills dependency: scrum4me owns these prompts.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 19:41:56 +02:00
dfee518996 lib: idea-code generator + plan_md yaml-frontmatter parser (M12 T-494)
- lib/idea-code.ts: pure formatIdeaCode helper (client-safe, no prisma)
- lib/idea-code-server.ts: atomic nextIdeaCode via Prisma row-lock,
  accepts optional TransactionClient for combining with idea.create
- lib/idea-plan-parser.ts: parsePlanMd extracts ---yaml---/body, runs
  yaml.parse + ideaPlanMdFrontmatterSchema, returns line-info on failure;
  CRLF-tolerant
- adds yaml@^2.8.4 dependency
- 8 unit tests (parser happy/missing/yaml-error/zod-error/empty-stories/CRLF;
  formatIdeaCode pad-3 + overflow)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 19:40:39 +02:00
bba3f11269 lib: idea schemas + status mappers + transition guards (M12 T-493)
- lib/schemas/idea.ts: ideaCreateSchema, ideaUpdateSchema, ideaPlanMdFrontmatterSchema
  (yaml-frontmatter contract for materialize-step parser)
- lib/idea-status.ts: bidirectional DB↔API mapping, canTransition state-machine
  guard, isIdeaEditable + isGrillMdEditable + isPlanMdEditable helpers
- includes auto-regen docs/erd.svg from prisma generate

Tests: 26 cases (status round-trip, transitions valid/invalid, schema validation
edge-cases, priority bounds, verify-enum).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 19:38:52 +02:00
86fb97456e db: M12 migration — ideas + idea_logs + check-constraints + pg_notify update (T-492)
- new tables ideas + idea_logs with FKs (User/Product/Pbi cascade rules per plan)
- claude_jobs.task_id nullable; new idea_id FK + kind enum + index
  + check-constraint: exactly_one(task_id, idea_id)
- claude_questions.story_id nullable; new idea_id FK + index
  + check-constraint: exactly_one(story_id, idea_id)
- notify_question_change trigger: handles null story_id; idea_id added to payload

Verified against dev DB: tables created, both check-constraints active
(neither-set insert correctly rejected with errcode 23514),
trigger replaced.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 19:36:28 +02:00
f6aa70a9b6 docs(runbook): clarify merge-conflict behavior for PR-per-batch flow
Add FAQ subsection explaining that stories within the same batch don't
conflict (linear commits on shared branch), while parallel batches may
require rebase or serial PRs.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 19:35:42 +02:00
bfad2452ce db: M12 migration — ideas + idea_logs + check-constraints + pg_notify update (T-492)
- new tables ideas + idea_logs with FKs (User/Product/Pbi cascade rules per plan)
- claude_jobs.task_id nullable; new idea_id FK + kind enum + index
  + check-constraint: exactly_one(task_id, idea_id)
- claude_questions.story_id nullable; new idea_id FK + index
  + check-constraint: exactly_one(story_id, idea_id)
- notify_question_change trigger: handles null story_id; idea_id added to payload

Verified against dev DB: tables created, both check-constraints active
(neither-set insert correctly rejected with errcode 23514),
trigger replaced.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 19:35:28 +02:00
300e426a4e schema: add Idea + IdeaLog models, extend ClaudeJob/Question for ideas (M12 T-491)
- new enums IdeaStatus, ClaudeJobKind, IdeaLogType
- new models Idea (with @@unique([user_id, code]) + pbi_id @unique) and IdeaLog
- User.idea_code_counter Int @default(0) for IDEA-{nnn} code generation
- ClaudeJob.task_id nullable; new idea_id + kind fields + index
- ClaudeQuestion.story_id nullable; new idea_id field + index
- existing call sites narrowed to story-questions / task-jobs (idea-paths come in T-502+)
- includes the M12 plan doc copied from /Users/janpetervisser/.claude/plans

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 19:25:07 +02:00
90343573f3 chore: bump version to 1.0.0
Eerste stabiele release. v1-readiness checklist (Now + Before-launch) is
afgerond, smoke-test groen, lint/tests/build/doc-links allemaal groen.

CHANGELOG.md [Unreleased] gepromoveerd naar [1.0.0] — 2026-05-04 met
volledige Added/Changed/Fixed/Security-secties uit PR #85 t/m #89.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 14:25:15 +02:00
Janpeter Visser
d02434a1e9
Merge pull request #89 from madhura68/chore/before-launch-changelog
docs+fix: Before-launch checklist (CHANGELOG, demo-policy, privacy, smoke-test)
2026-05-04 14:21:26 +02:00
b225c83ace docs: v1.0 smoke-test checklist + readiness-doc bijgewerkt
docs/runbooks/v1-smoke-test.md (NIEUW): 11-secties handmatige checklist
voor de v1.0-pre-launch verificatie — auth, mobile UA-redirect, happy-path
flow, mobile shell, edit-flows, demo-policy, rate-limiting steekproef,
realtime, debug-routes 404 in productie, Lighthouse a11y per pagina,
rollback-trigger.

v1-readiness.md: 4 Before-launch items afgevinkt (demo-policy, privacy,
README, CHANGELOG); smoke-test verwijst nu naar de checklist; PWA-test
en v1.0.0-bump zijn de twee resterende handmatige items.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 14:18:25 +02:00
0f40bc1c70 fix(privacy): NODE_ENV-guard 4 debug-routes (before-launch privacy review)
Privacy/PII review-pass van Server Actions, API-routes, debug-paths en
Sentry config:

 Sentry sendDefaultPii: false in alle drie configs (server/edge/client)
 Geen wachtwoord/email/token in console-logs
 Pair-id-logs zijn metadata-only (5-min TTL, geen secret)

⚠️ Vier debug-routes hadden geen auth-guard:
- /api/debug/realtime-stream — rauwe pg_notify-stream zonder filtering
- /api/debug/emit-test-notify — anonieme test-emit op het kanaal
- /debug-env — lekt env-var-metadata (hostnames, lengtes, pooled-flag)
- /debug-realtime — UI op dezelfde rauwe pg_notify-stream

Allemaal gemarkeerd als TIJDELIJK met VERWIJDEREN-comments uit M8.
Voor v1 launch: NODE_ENV-guard die in productie 404 retourneert. Lokaal
dev blijft alles werken voor debugging.

Toekomstige cleanup: kunnen worden verwijderd zodra M8-realtime stabiel
draait in productie en niemand ze meer nodig heeft.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 14:16:49 +02:00
95eff4087c fix(demo): close 3 demo-policy gaps in mutation actions (before-launch)
Audit van alle Server Actions revealed drie mutation-paden zonder
isDemo-check, terwijl de demo-policy zegt "demo-user is read-only":

- toggleTodoAction: demo kon eigen todos done/undone toggelen
- archiveCompletedTodosAction: demo kon todos archiveren (bulk)
- leaveProductAction: demo kon productMembership verlaten

Fix: standaard `if (session.isDemo) return { error: 'Niet beschikbaar in
demo-modus' }` toegevoegd, conform de andere mutation-actions.

Andere claim/unclaim/reassign/updateTaskPlan-actions zijn al gedekt via
requireProductWriter() → requireWriter() → demo-throw — nu code-side
geverifieerd voor de hele actions/-tree.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 14:14:01 +02:00
7529fd54bc docs: CHANGELOG.md (Keep a Changelog) + README quick-start fixes
CHANGELOG.md: Keep-a-Changelog formaat met [Unreleased], [0.9.0]-release,
en compact-historie. Klaar voor v1.0.0 release-notes.

README:
- Test-count 69 → 445 (was outdated)
- Quick-start claim over auto-erd-watch in `npm run dev` corrigeren
  (npm run db:erd:watch is optioneel, niet automatisch)
- Env-vars-tabel uitgebreid: CRON_SECRET (productie), Sentry DSN +
  source-map vars (optioneel)
- CHANGELOG-link in Documentation-sectie

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 14:11:53 +02:00
Janpeter Visser
54a2511476
Merge pull request #88 from madhura68/feat/a11y-tap-targets-aria
fix(a11y): tap targets ≥28px + aria-pressed on PBI-card (Lighthouse #4 follow-up)
2026-05-04 14:09:13 +02:00
Janpeter Visser
04181e54cb
Merge pull request #87 from madhura68/feat/a11y-audit-fixes
fix(a11y): static accessibility fixes (v1-readiness #4 — code-side)
2026-05-04 14:08:58 +02:00
fa10f87136 fix(a11y): tap targets ≥28px + aria-pressed on pbi-card (Lighthouse 86 → ≥95)
Lighthouse-audit op /products/[id] flagde drie issues; fix in deze PR:

1. **[aria-*] attributes do not match their roles** — pbi-list.tsx had
   aria-selected={isSelected} op role="button". aria-selected is alleen
   geldig op tab/option/treeitem etc. Voor toggle-buttons is aria-pressed
   de juiste attribute.

2. **Touch targets do not have sufficient size** — drie offenders op het
   product-backlog scherm (PBI ✎/× iconen, Story ✎ icoon) hadden
   ~16-18×18px tap-targets via px-1.5/p-0.5. Lighthouse minimum is 24×24
   en WCAG AA streeft 44×44. Fix: inline-flex + min-h-7 min-w-7 (28×28px)
   met behoud van het kleine icoon — wel grotere clickable area.

3. Dashboard product-card pencil-icoon kreeg dezelfde fix preventief.

Sprint-backlog heeft hetzelfde patroon op meer plekken; bewust nu niet
aangeraakt om PR scope te beperken tot de ge-auditeerde route. Vervolg-PR
indien sprint-page-audit ook flagt.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 14:03:37 +02:00
31ff70b71a fix(a11y): static accessibility findings (v1-readiness #4 — code-side)
Statische audit op happy-path-code; 4 categorieën gefixt vóór de Lighthouse-
verificatie die de gebruiker handmatig draait:

1. <main>-landmark op /login en /register (waren <div>); auth-pages krijgen
   nu een correcte landmark zodat screen-readers ze kunnen overslaan/nav

2. solo-task-card.tsx: agent-status-pill had role="button" + aria-label maar
   GEEN tabIndex en GEEN onKeyDown — keyboard-onbereikbaar. Nu compleet:
   tabIndex={0} + Enter/Space-handler

3. Form-label-associaties via htmlFor + id-pairs:
   - story-dialog (5): code, title, description, acceptance + priority via labelledby
   - task-dialog (3): title, description, implementation_plan
   - todo-list PromotePbi/PromoteStory dialogs (6): title, product, pbi, priority

   Lighthouse a11y "form-field-multiple-labels" en "label" rules worden
   hierdoor groen.

Niet aangeraakt:
- pbi-dialog: htmlFor was al goed gewired
- auth-form: htmlFor was al goed gewired
- Color-contrast: gebruikt MD3-tokens; theoretisch correct (verifieer in
  Lighthouse run)
- Heading-hierarchy: nog niet gescand — kan in vervolgronde

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 13:58:34 +02:00
Janpeter Visser
ca4ba6deb5
Merge pull request #86 from madhura68/feat/rate-limit-mutations
feat(rate-limit): per-user mutation-rate-limiting (v1-readiness #3)
2026-05-04 13:53:54 +02:00
a0a10001d5 feat(rate-limit): per-user mutation-rate-limiting (v1-readiness #3)
lib/rate-limit.ts: 11 nieuwe scope-configs + enforceUserRateLimit(scope, userId)
helper. Returnt { error, code: 429 } shape voor consistent foutbeleid.

Toegepast op de high-value mutation-paths:
- actions/pbis.ts createPbiAction
- actions/stories.ts createStoryAction
- actions/tasks.ts saveTask (alleen create-path) + createTaskAction
- actions/todos.ts createTodoAction
- actions/sprints.ts createSprintAction
- actions/products.ts createProductAction + createProductFormAction
- actions/api-tokens.ts createApiTokenAction
- actions/questions.ts answerQuestion
- actions/claude-jobs.ts enqueueClaudeJobAction + enqueueClaudeJobsBatchAction
- app/api/profile/avatar/route.ts POST
- app/api/stories/[id]/log/route.ts POST

Limits zijn ruim genoeg voor normaal gebruik, eng genoeg voor abuse-loops:
create-task 100/min, create-todo 60/min, create-pbi 30/min, create-product
5/min, create-token 10/uur, etc. Per-user scope (geen globale block).

Niet aangeraakt: reorder/status-toggle (intra-session frequent, lage abuse),
update/delete (laag-volume), cron-routes (CRON_SECRET-gated).

Consumer-tweaks: 'success' in result narrowing waar TS de bredere union niet
meer accepteerde. Tests: 9 nieuwe op rate-limit-helper.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 13:48:59 +02:00
Janpeter Visser
43778e3bcb
Merge pull request #85 from madhura68/feat/sentry-error-monitoring
feat(ops): Sentry error-monitoring (v1-readiness #2)
2026-05-04 13:35:17 +02:00
Janpeter Visser
c38ec4a158
Merge pull request #84 from madhura68/feat/story-q5wkvcsw
ST-1139: Docs sync + end-to-end verificatie
2026-05-04 13:25:43 +02:00
ac11483c68 feat(ops): Sentry error-monitoring (v1-readiness item 2)
Vier config-files volgens Next.js 15+ conventie:
- instrumentation.ts (root) → koppelt server/edge config aan runtime-hook
- instrumentation-client.ts → client-init + onRouterTransitionStart
- sentry.server.config.ts → node-runtime
- sentry.edge.config.ts → edge-runtime (proxy.ts)

next.config.ts gewrapped met withSentryConfig:
- Source-map-upload ALLEEN als SENTRY_AUTH_TOKEN gezet is
- Tunnel /monitoring omzeilt ad-blockers (*.sentry.io)
- Silent buiten CI

SDK is no-op zonder NEXT_PUBLIC_SENTRY_DSN — geen network/overhead in
dev of bij ontbrekende creds. Sample-rates conservatief: errors 100%,
performance 10% in productie / 100% in dev. Geen Replay (privacy-review
nodig + overkill voor MVP). sendDefaultPii uit.

.env.example gedocumenteerd; architectuur-doc bijgewerkt met nieuwe
sleutelbeslissing en file-tree-aanvulling. v1-readiness #1 verschoven
naar 'done', #2 hiermee in flight.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 13:24:19 +02:00
Scrum4Me Agent
b79510f5c6 docs: voeg flow-per-scherm toe aan Mobile shell sectie (ST-cmolqa8ma001xq517ree6u5v5)
Acceptatiecriteria vroeg om 'flow per scherm' beschrijving in de
Mobile shell sectie. Toegevoegd: stap-voor-stap flow voor Settings,
Backlog en Solo schermen.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-04 11:28:11 +02:00
Janpeter Visser
70c5be6750
Merge pull request #83 from madhura68/feat/product-edit-icon-on-dashboard
feat(dashboard): pencil-icoon edit-trigger op product-card
2026-05-04 11:23:08 +02:00
63f5231770 feat(dashboard): pencil-icoon edit-trigger op product-card (todo cmoq3ox51)
De dashboard product-card had al een 'Bewerken'-tekstknop, maar het patroon
in de rest van de app (PBI/story/task in cards) is een hover-zichtbaar
pencil-icoon. Vervangen voor consistentie. Product-detail page-header blijft
tekst — daar staat 'Bewerken' tussen andere text-acties zoals "Sprint actief"
en "Instellingen".

Hergebruikt bestaande ProductDialog en setEditingProduct-state — geen wijziging
aan de dialog of action zelf. Demo-block behouden.

Tests: 4 nieuwe (rendert icoon, opent dialog, demo-disabled, geen icoon op
archived).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 11:21:14 +02:00
Janpeter Visser
9ffd0f06f2
Merge pull request #82 from madhura68/docs/v1-readiness
docs: v1.0 readiness checklist
2026-05-04 11:17:07 +02:00
222928b1b4 docs: v1.0 readiness checklist
Living document onder docs/plans/v1-readiness.md. Vier secties (Now/Next/
Before launch/Later) met concrete actions voor de stap van v0.9.0 → v1.0.0.

Now-kandidaten:
- Edit-icoon op Product (todo cmoq3ox51 — UI-gat)
- Sentry/error-monitoring
- Rate-limiting op alle mutation-endpoints
- Accessibility-audit (Lighthouse a11y >=95)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 11:15:09 +02:00
9bfa732a6a chore: bump version to 0.9.0
Release omvat ondermeer PBI-11 (mobile-shell met landscape-lock):
mobile-shell onder /m/* met UA-redirect, route group (mobile)/, gedeelde
auth-guard, gedeelde mobile-fullscreen-dialog-classes, gescheiden
SplitPane cookie-key voor mobile.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 11:09:11 +02:00
Janpeter Visser
db8be67d9b
Merge pull request #81 from madhura68/feat/ST-1134-mobile-shell-foundation
feat(PBI-11): mobile-shell met landscape-lock — settings + backlog + solo
2026-05-04 11:06:41 +02:00
19724eac5a docs(ST-1139): mobile-shell sync in functional spec + architectuur (T-334/T-335/T-336)
- docs/specs/functional.md: nieuwe sectie "Mobile shell" met routestructuur,
  acceptance-criteria, bekende iOS-limiet; desktop-first-clausule herzien naar
  "desktop-first hoofdpad + mobile-shell voor /m/*"
- docs/architecture/project-structure.md: route-tree onder app/(mobile)/,
  components/mobile/ in tree, vier nieuwe sleutelbeslissingen (route group,
  UA-redirect, gedeelde dialog-classes, gescheiden cookie-key)
- docs/INDEX.md regenerated, doc-links 86/86 valid
- T-336 E2E: lint/test/build groen; manuele DevTools/PWA-checks gelogd

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 10:56:15 +02:00
b327fbdf09 feat(ST-1138): mobile Solo-pagina + verify TaskDetailDialog (T-331/T-332/T-333)
- app/(mobile)/m/products/[id]/solo/page.tsx — hergebruikt SoloBoard 1:1 met
  desktop. 3-koloms-kanban blijft, NoActiveSprint-fallback ongewijzigd
- T-332 verify-only: TaskDetailDialog regel 383 gebruikt
  entityDialogContentClasses → mobile-fullscreen erft automatisch uit ST-1133
- Tests: regressie-vangnet op SoloBoard-hergebruik, requireSession,
  NoActiveSprint, en op TaskDetailDialog-className-wiring (geen override)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 10:52:41 +02:00
5b42740461 feat(ST-1137): mobile Product Backlog-pagina (T-328/T-329/T-330)
- app/(mobile)/m/products/[id]/page.tsx — hergebruikt BacklogHydrationWrapper +
  BacklogSplitPane + PbiList/StoryPanel/TaskPanel (1:1 zelfde data-fetch als
  desktop-page; demo blijft read-only via PbiList/StoryPanel)
- Cookie-key gescheiden: `backlog-${id}-mobile` (beslissing C in
  docs/plans/PBI-11-mobile-shell.md) — tab-mode-gebruikers vervuilen de
  desktop-split-percentages niet
- closePath en redirect-targets blijven onder /m/products/
- Tab-mode rendert automatisch op <1024px via SplitPane (uit ST-1116)
- Tests: regressie-vangnet op cookie-key, /m/-paden, hergebruik

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 10:14:20 +02:00
0a3dc401b7 feat(ST-1136): mobile Settings-pagina + LogoutButton (T-325/T-326/T-327)
- app/(mobile)/m/settings/page.tsx — read-only account-info, product-selector
  (hergebruikt ActivateProductButton + setActiveProductAction met redirectTo
  /m/products/[id]/solo), QR-pairing-instructie, logout
- components/mobile/logout-button.tsx — AlertDialog "Uitloggen?" met bevestig
  + annuleer; demo-user mag uitloggen (geen demo-block)
- Tests: LogoutButton render + open + bevestig (logoutAction) + annuleer

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 10:12:19 +02:00
13ab53ab8d feat(ST-1135): UA-redirect bij login — phone naar /m/* (T-322/T-323/T-324)
- lib/user-agent.ts (nieuw): isPhoneUA() — Mobi-substring heuristiek
  (telefoons hebben Mobi, tablets/desktop niet)
- actions/auth.ts loginAction: leest user-agent header na session.save();
  phone-UA + actief product → /m/products/[id]/solo, zonder → /m/settings;
  tablet/desktop/null-UA → /dashboard (ongewijzigd)
- Tests: 7 helper-cases + 6 loginAction-paden incl. demo-user

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 10:09:09 +02:00
479a502dfd feat(ST-1133): entityDialogContentClasses → full-screen op <640px (T-316/T-317/T-318)
Eén edit op de gedeelde constant dekt PbiDialog, StoryDialog, TaskDialog,
TaskDetailDialog (allen renderen DialogContent met dezelfde className).

Toegevoegd: max-sm:w-screen max-sm:h-screen max-sm:max-h-screen
max-sm:max-w-none max-sm:rounded-none. Desktop-classes (sm:max-w-[90vw],
lg:max-w-[50vw]) blijven onveranderd.

Tests: smoke op constant + regressie-vangnet dat de 4 entity-dialogen
entityDialogContentClasses blijven gebruiken.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 10:06:21 +02:00
7b32fc60e6 feat(ST-1134): (mobile) route group + auth-guard helper + manifest (T-321)
- lib/auth-guard.ts (nieuw): requireSession() — gedeelde auth+paired-expiry
  guard, hergebruikt door (app)/layout.tsx
- (app)/layout.tsx: refactor naar requireSession() (gedraagt zich identiek)
- (mobile)/layout.tsx (nieuw): minimal layout met LandscapeGuard +
  MobileTabBar; geen NavBar/StatusBar/MinWidthBanner/bridges
- /m/pair filesystem-move van (app)/ naar (mobile)/ — URL onveranderd
- public/manifest.json: orientation landscape
- Tests: requireSession-helper (3 paden)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 09:55:18 +02:00
47d57a0963 feat(ST-1134): MobileTabBar component (T-320)
Bottom-fixed nav-bar met 3 lucide-iconen (ListTree/Activity/Settings).
Verbergt Backlog/Solo-tabs als activeProductId null is.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 09:52:33 +02:00
e68552bcfd feat(ST-1134): LandscapeGuard component (T-319)
Toont rotate-overlay in portrait, niets in landscape. Kinderen blijven altijd
in DOM — geen unmount zodat SSE-streams overleven bij rotatie.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 09:51:48 +02:00
Janpeter Visser
bdd8c1e53a
Merge pull request #80 from madhura68/docs/pbi-11-plan-update
docs(PBI-11): canoniek plan + drie architectuur-beslissingen
2026-05-04 09:46:13 +02:00
3887e07af2 docs(PBI-11): canoniek plan voor mobile-shell met drie architectuur-beslissingen
Vorige planlocatie (~/.claude/plans/twinkly-plotting-wombat.md) was overschreven
met ST-1209-plan; deze doc neemt het over.

Drie aanbevelingen verwerkt na evaluatie tegen huidige codebase:
- A. Gedeelde entityDialogContentClasses muteren (dekt ST-1133 + ST-1138 in één edit)
- B. Eigen route group app/(mobile)/ — nested layout kan parent-NavBar niet onderdrukken
- C. Gescheiden SplitPane cookie-key voor mobile (backlog-3-mobile)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 09:40:03 +02:00
Janpeter Visser
4a2e94e208
Merge pull request #79 from madhura68/feat/sprint-backlog-filter-popover
feat(sprint): filter popover + edit-iconen op PBI/story/taak
2026-05-04 09:37:59 +02:00
541eb18b35 feat(sprint): edit-icoon op taak in Taken-kolom
Hover-zichtbaar ✎-icoon rechts uitgelijnd op iedere taak-rij; opent dezelfde
edit-dialog als een rij-klik (visuele cue, consistent met PBI/story-rijen).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 09:21:35 +02:00
6a76bc0f8c feat(sprint): edit-icoon op PBI (Product Backlog) en story (Sprint Backlog)
- PBI-rij in Product Backlog-kolom: ✎-icoon rechts uitgelijnd, opent PbiDialog
  (rij is nu div role=button i.p.v. nested-button)
- Story-rij in Sprint Backlog-kolom: ✎-icoon vóór de Trash, opent StoryDialog
- SprintStory + PbiWithStories verrijkt met velden die de dialogen lezen
  (description / acceptance_criteria / pbi_id / created_at op story; priority /
  status / description op PBI)
- pbi.status via pbiStatusToApi → PbiStatusApi (DB UPPER_SNAKE → API lowercase)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 09:19:49 +02:00
cc6baeebc1 feat(sprint): filter popover op Product-Backlog-kolom
Spiegelt het filter-patroon van de Product Backlog-pagina (PbiList) naar de
Sprint-Product-Backlog-kolom: prioriteit + status pills, actieve-filter chips,
localStorage-persistentie. Bestaande collapse-/expand-/alleen-niet-klaar-knoppen
blijven naast de popover staan.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 09:10:05 +02:00
Janpeter Visser
f7a425a5db
Merge pull request #78 from madhura68/chore/untrack-claude-settings
chore: untrack .claude/settings.local.json
2026-05-04 08:55:44 +02:00
fdd9a90cc3 chore: untrack .claude/settings.local.json
Bestand stond al in .gitignore (regel 52) maar was eerder gecommit,
waardoor de ignore-regel niet greep. git rm --cached haalt het uit
git's index zonder het lokaal te verwijderen, zodat per-machine
permissies en local-only Claude-settings niet langer per ongeluk in
commits belanden.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 08:54:46 +02:00
Janpeter Visser
1b680296f4
Merge pull request #77 from madhura68/fix/task-detail-dialog-scroll
fix(solo): TaskDetailDialog body scrollt + inspector-mode in pattern-spec
2026-05-04 08:49:20 +02:00
d09ec7e77e docs(dialog): inspector-mode formaliseren in patroon-spec
§ 4a beschrijft hybrid detail+inline-edit dialogen met dynamische
footer en blur-save: bv. TaskDetailDialog. Maakt expliciet wanneer je
deze variant kiest, welke § 4-eisen blijven gelden en welke vervallen
(geen dirty-guard, geen Cmd+Enter, geen full-record schema).

Profiel docs/specs/dialogs/task-detail.md verwijst nu naar § 4a en
documenteert de layout-keuzes (sticky header, scrollable body,
flex-wrap footer met job-status, plan-textarea max-h-[40vh]).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 08:47:45 +02:00
61b3db195c fix(solo): TaskDetailDialog body scrollt + sticky header/footer
Story 6 zette entityDialogContentClasses op de buitenkant
(flex flex-col p-0 gap-0 max-h-[85vh]) maar de binnenkant van
TaskDetailContent gebruikte nog losse divs zonder shrink-0/flex-1
overflow-y-auto. Resultaat bij lange implementatieplannen: dialog
groeide tot voorbij de viewport, header zat niet vast en footer-margin
(-mx-4 -mb-4) brak omdat parent nu p-0 heeft.

Fix: header in shrink-0 div met px-6 pt-5 pb-4 + border-b; body in
entityDialogBodyClasses (flex-1 overflow-y-auto px-6 py-6 space-y-6);
footer in entityDialogFooterClasses + flex-wrap voor de variabele
job-status-knoppen. Plan-textarea krijgt max-h-[40vh] zodat een lang
plan niet meteen heel het body-gebied opvult.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 08:44:48 +02:00
Janpeter Visser
e1f1f29db7
Merge pull request #76 from madhura68/feat/entity-codes-required
feat(codes): codes verplicht en hiërarchisch zichtbaar voor PBI/Story/Task
2026-05-04 08:40:39 +02:00
658e42a70a docs(api): documenteer entity codes als verplicht response-veld
Aparte 'Entity codes' sectie legt uit dat PBI/Story/Task elk een
verplichte code hebben (max 30 chars, regex), per-product uniek,
stabiel bij re-parenting, met auto-generatie als POST-body de
code weglaat. Voorbeeld response in /next-story en /sprint/tasks
gebruikt nu T-42 i.p.v. ST-356.1 voor task-code.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 08:37:02 +02:00
081a0a51c3 feat(codes): UI toont en accepteert code voor taken
- TaskDialog: code-input boven titel (font-mono, optional,
  placeholder "auto"), CodeBadge in dialog header bij edit
- EditTaskLoader: select code uit DB voor de dialog
- Solo page: vervang inline deriveTaskCode-logica door directe
  task.code uit DB
- Sprint page + TaskList + SprintBoardClient: Task-type krijgt
  verplicht code-veld; TaskList laat ongebruikte storyCode prop
  vallen omdat code-derivatie niet meer nodig is

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 08:36:52 +02:00
7c82a736f5 feat(codes): server actions + seed/scripts gebruiken code overal
- actions/tasks.ts: saveTask + createTaskAction (legacy form) gebruiken
  createWithCodeRetry + generateNextTaskCode; persisten product_id
  denormalisatie. P2002 op user-supplied code wordt 422 met fieldError
- actions/pbis.ts + stories.ts: insert-helpers nemen verplichte string;
  update laat code-veld weg uit data wanneer null (kan niet meer leeg
  worden gemaakt nu DB NOT NULL is)
- actions/todos.ts: promoteTodoToPbi/Story genereren expliciet een code
  voor het transactiestart (kan niet binnen $transaction array retryen)
- prisma/seed.ts: per-product task counter geeft elke task een T-N code
- scripts/insert-milestone.ts: createMany berekent maxN voor product
  en assigneert T-{maxN+i+1} per nieuwe task

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 08:36:41 +02:00
829122d437 feat(codes): generateNextTaskCode + CODE_REGEX export + Zod regex op alle 3 schemas
- lib/code.ts: rename VALID_CODE_RE naar geexporteerde CODE_REGEX,
  verwijder ongebruikte deriveTaskCode
- lib/code-server.ts: generateNextTaskCode(productId) — flat per-product
  T-N teller, hergebruikt nextSequential helper. Export
  isCodeUniqueConflict zodat callers P2002 op code-veld kunnen detecteren
- Zod schemas (pbi/story/task): codeField met trim + max-length + regex,
  optional input (server vult bij ontbreken). Task krijgt voor het
  eerst een codeField

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 08:36:28 +02:00
611b621d75 feat(codes): code NOT NULL voor PBI/Story + Task.code + product_id denorm
- Pbi.code en Story.code worden NOT NULL (tot dusver optional)
- Task krijgt code String + product_id String denorm + @@unique([product_id, code])
- Product krijgt back-relation tasks Task[]
- Migratie backfillt bestaande NULL-rijen via PL/pgSQL:
  PBI-N (per product), ST-N (3-digit padded met GREATEST om
  truncatie van LPAD bij 4-digit nummers te voorkomen),
  T-N voor alle tasks
- Codes zijn stabiele identifiers (Jira-stijl flat-per-product),
  zodat re-parenting de code niet muteert

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 08:36:19 +02:00
Janpeter Visser
74599669cf
Merge pull request #75 from madhura68/feat/dialogs-pattern-compliance
feat(dialogs): alle dialogen conform docs/patterns/dialog.md
2026-05-04 07:48:42 +02:00
Janpeter Visser
50e2e0ffa6
Merge pull request #74 from madhura68/fix/dashboard-product-dialog-click-bubble
fix(dashboard): klik in productdialog redirect niet naar productpagina
2026-05-04 07:48:19 +02:00
Janpeter Visser
13c49eecaa
Merge pull request #73 from madhura68/fix/navbar-product-switch-onclick
fix(nav): product-switch dropdown reageert weer op klik
2026-05-04 07:48:02 +02:00
4b0ab8e4b2 feat(answer-modal): conform aan dialog-pattern + entity-profile
Story 7 van PBI "Alle dialogen conform docs/patterns/dialog.md".

- lib/schemas/question-answer.ts — gedeeld zod-schema +
  ANSWER_MAX_CHARS constant
- actions/questions.ts gebruikt het gedeelde schema
- AnswerModal: entityDialog* layout-classes, useDirtyCloseGuard,
  useDialogSubmitShortcut, DemoTooltip rond submit + multiple-choice
  knoppen
- docs/specs/dialogs/answer-modal.md — entity-profile

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 07:34:56 +02:00
0a58557e9d feat(solo-dialogs): layout-conformance + entity-profielen
Story 6 van PBI "Alle dialogen conform docs/patterns/dialog.md".

- batch-enqueue-blocker-dialog: entityDialog* layout-classes
- task-detail-dialog: entityDialog* layout-classes (rest van interne
  layout blijft custom — hybride detail+blur-save view)
- docs/specs/dialogs/task-detail.md — profiel dat het blur-save +
  PATCH-route patroon documenteert (afwijking van klassieke
  Server-Action+form flow)
- docs/specs/dialogs/batch-enqueue-blocker.md — profiel voor
  informational confirm-dialog

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 07:32:57 +02:00
784791d8f9 feat(sprint-dialogs): conform aan dialog-pattern + entity-profile
Story 5 van PBI "Alle dialogen conform docs/patterns/dialog.md".

- lib/schemas/sprint.ts — gedeelde zod-schemas (create/dates/goal)
- actions/sprints.ts — code+fieldErrors voor 422; code: 403 voor
  auth/demo errors
- StartSprintButton dialog: useDirtyCloseGuard, useDialogSubmitShortcut,
  entityDialog* layout-classes; DemoTooltip op trigger; veld-niveau
  errors via fieldErrors
- SprintHeader's date- en complete-dialogen: zelfde behandeling; date-
  dialog krijgt dirty-guard, complete-dialog krijgt DemoTooltip op
  bevestigen
- docs/specs/dialogs/sprint.md — entity-profile dat alle drie de modes
  documenteert; consolidatie naar één SprintDialog component bewust
  uitgesteld
- Sprint-dates tests aangepast aan nieuwe action-shape

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 07:30:46 +02:00
01e77fc560 feat(story-dialog): conform aan dialog-pattern + AlertDialog delete
Story 4 van PBI "Alle dialogen conform docs/patterns/dialog.md".

- lib/schemas/story.ts — gedeeld zod-schema
- actions/stories.ts — code+fieldErrors voor 422; code: 403 voor auth/demo
- StoryDialog adopt useDirtyCloseGuard, useDialogSubmitShortcut,
  entityDialog* layout-classes
- Inline delete-confirm vervangen door AlertDialog (§10.4)
- docs/specs/dialogs/story.md — gaps weggewerkt; alleen bewuste
  afwijkingen blijven (header met badges, geen char-counter)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 07:26:56 +02:00
97dc4ee553 feat(pbi-dialog): conform aan dialog-pattern + DemoTooltip + dirty-guard
Story 3 van PBI "Alle dialogen conform docs/patterns/dialog.md".

- lib/schemas/pbi.ts — gedeeld zod-schema (createPbiSchema/updatePbiSchema)
- actions/pbis.ts — returnen nu code+fieldErrors (422) en code: 403 voor
  auth/demo errors
- PbiDialog adopt useDirtyCloseGuard, useDialogSubmitShortcut,
  entityDialog* layout-classes; submit-knop + Annuleren in DemoTooltip
- isDemo-prop toegevoegd, pbi-list geeft 'm door
- docs/specs/dialogs/pbi.md — "Bekende gaps" weggewerkt; alleen bewuste
  uitsluitingen blijven

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 07:23:14 +02:00
03a248b0fb feat(product-dialog): conform aan dialog-pattern + entity-profile
Story 2 van PBI "Alle dialogen conform docs/patterns/dialog.md".

- lib/schemas/product.ts — gedeeld zod-schema (Dialog API)
- actions/products.ts — createProductAction/updateProductAction returnen
  nu code+fieldErrors voor 422-validatie en code: 403 voor demo/auth
- ProductDialog adopt useDirtyCloseGuard, useDialogSubmitShortcut,
  entityDialog* layout-classes; 422-fieldErrors mappen naar form.setError
- docs/specs/dialogs/product.md — entity-profile

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 07:18:39 +02:00
b05c4d241b feat(dialogs): gedeelde primitives — useDirtyCloseGuard, useDialogSubmitShortcut, layout-classes
Story 1 van PBI "Alle dialogen conform docs/patterns/dialog.md".

- components/shared/use-dirty-close-guard.tsx — hook + paired AlertDialog
- components/shared/use-dialog-submit-shortcut.ts — Cmd/Ctrl+Enter handler
- components/shared/entity-dialog-layout.ts — MD3-conforme classes voor §4
- TaskDialog refactored om beide hooks + classes te gebruiken (geen
  gedragsverandering)
- 8 nieuwe unit-tests

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 07:14:07 +02:00
4abe2fa0b3 fix(dashboard): klik in productdialog redirect niet meer naar productpagina
ProductDialog werd per kaart gerenderd binnen de klikbare card-div.
Hoewel Base UI de dialog portaalt naar document.body, bubblen React
events via de component-tree, niet de DOM-tree — clicks in de dialog
liepen door naar router.push op de kaart.

Fix: dialog-state opheffen naar ProductList; eén ProductDialog buiten
de map() en EditProductButton vervangen door een inline knop met
e.stopPropagation. EditProductButton blijft beschikbaar voor de
product-detailpagina.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 07:03:03 +02:00
2aa3bc463f fix(nav): product-switch dropdown reageert weer op klik
Base UI's Menu.Item vuurt geen React-onSelect af bij activatie; alleen
onClick werkt. handleSwitchProduct werd daardoor nooit aangeroepen.
user-menu.tsx en sprint-backlog.tsx gebruiken al onClick — NavBar
miste deze workaround.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 06:53:12 +02:00
Janpeter Visser
b47f62966e
Merge pull request #72 from madhura68/restore/landing-and-edit
restore: re-apply PR #70 + #71 lost via force-push to main
2026-05-04 06:43:53 +02:00
7716b379e5 feat(dashboard,nav): edit-knop op productlijst + zichtbare product-switch
- nav-bar: vervang `router.push(/products/{id})` door `router.refresh()` na
  setActiveProductAction; voeg success-toast toe. Maakt de actieve-product
  switch zichtbaar zonder context-switch naar de detail-page; client-cache
  wordt nu correct geinvalideerd.
- product-list (dashboard): integreer EditProductButton naast Activeer/Actief.
  Owner én members kunnen editten (per productAccessFilter); demo-modus
  rendert disabled+tooltip.
- edit-product-button: optionele isDemo + size + variant props; wraps
  DemoTooltip; e.stopPropagation om card-click te voorkomen.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 06:41:46 +02:00
e390e7cdef feat(landing): rewrite around local-first proposition + architecture diagram
Reframe the landing page around what makes Scrum4Me unique: code execution
stays on the developer's own hardware (laptop, NAS or VM). The Vercel UI and
Neon DB are a metadata coordination layer; source code never leaves the local
worker. Adds a mermaid-rendered architecture diagram (two-zone: Scrum4Me-stack
vs Jouw kant) with light/dark variants generated via mmdc.

Page changes (app/page.tsx):
- Hero: H1 "Plannen in de cloud. Uitvoeren op je eigen machine." + new
  subhead; CTA "Hoe het werkt" replaces "Demo bekijken" (anchors to
  #architectuur).
- New section §3 "Architectuur" with light/dark SVG and 4 callout-cards
  (Vercel · Neon · Lokale worker · GitHub) honestly describing what each
  component stores or runs.
- Feature grid: 6 cards (set C) — combines Sprint Board + Solo Paneel,
  adds Lokale Claude-agents, Realtime updates, Async vraagkanaal, Todo's.
  LIVE callout removed (folded into Realtime card).
- "Twee manieren"-section replaced by a Quickstart with concrete git-clone
  snippet for the MCP-server.
- Handleiding: 9 → 10 steps; MCP recommended in step 8; new step 9
  "Story laten uitvoeren" describing the Voer-uit / job-queue flow;
  step 1 mentions QR-pairing as alternative login.
- Footer: adds link to madhura68/scrum4me-mcp alongside the app repo.

Tooling:
- New docs/diagrams/architecture.mmd (mermaid source).
- New npm script "diagrams" generates light + dark SVG via mmdc; output
  committed to public/diagrams/. No prebuild hook (manual regenerate, like
  prisma generate / docs:index).
- Plan + grilling outcomes captured in docs/plans/landing-local-first.md.

Tracked under Scrum4Me story cmoq2qoik0001qa175iynfnaa
(PBI Marketing & Landingspagina, cmoq2q50s0000qa174rmrjove).

Verified: npm run lint (0 new errors), npm test (379/379), npm run build OK.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 06:41:46 +02:00
Janpeter Visser
bf753af1cd
Merge pull request #71 from madhura68/feat/dashboard-edit-and-switch-fix
feat: navbar product-switch zichtbaar + edit-knop op dashboard
2026-05-04 06:33:36 +02:00
a839ac76c6 feat(dashboard,nav): edit-knop op productlijst + zichtbare product-switch
- nav-bar: vervang `router.push(/products/{id})` door `router.refresh()` na
  setActiveProductAction; voeg success-toast toe. Maakt de actieve-product
  switch zichtbaar zonder context-switch naar de detail-page; client-cache
  wordt nu correct geinvalideerd.
- product-list (dashboard): integreer EditProductButton naast Activeer/Actief.
  Owner én members kunnen editten (per productAccessFilter); demo-modus
  rendert disabled+tooltip.
- edit-product-button: optionele isDemo + size + variant props; wraps
  DemoTooltip; e.stopPropagation om card-click te voorkomen.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 06:30:00 +02:00
Janpeter Visser
95c5bd1086
Merge pull request #70 from madhura68/feat/landing-local-first
Landing v2: lokaal-first propositie + architectuurdiagram
2026-05-04 06:29:41 +02:00
Janpeter Visser
d8e6a68d69
Merge pull request #69 from madhura68/docs/runbook-agent-flow-pitfalls
docs(runbook): agent-flow open issues & decision log
2026-05-03 20:38:20 +02:00
4ff50cb87e feat(landing): rewrite around local-first proposition + architecture diagram
Reframe the landing page around what makes Scrum4Me unique: code execution
stays on the developer's own hardware (laptop, NAS or VM). The Vercel UI and
Neon DB are a metadata coordination layer; source code never leaves the local
worker. Adds a mermaid-rendered architecture diagram (two-zone: Scrum4Me-stack
vs Jouw kant) with light/dark variants generated via mmdc.

Page changes (app/page.tsx):
- Hero: H1 "Plannen in de cloud. Uitvoeren op je eigen machine." + new
  subhead; CTA "Hoe het werkt" replaces "Demo bekijken" (anchors to
  #architectuur).
- New section §3 "Architectuur" with light/dark SVG and 4 callout-cards
  (Vercel · Neon · Lokale worker · GitHub) honestly describing what each
  component stores or runs.
- Feature grid: 6 cards (set C) — combines Sprint Board + Solo Paneel,
  adds Lokale Claude-agents, Realtime updates, Async vraagkanaal, Todo's.
  LIVE callout removed (folded into Realtime card).
- "Twee manieren"-section replaced by a Quickstart with concrete git-clone
  snippet for the MCP-server.
- Handleiding: 9 → 10 steps; MCP recommended in step 8; new step 9
  "Story laten uitvoeren" describing the Voer-uit / job-queue flow;
  step 1 mentions QR-pairing as alternative login.
- Footer: adds link to madhura68/scrum4me-mcp alongside the app repo.

Tooling:
- New docs/diagrams/architecture.mmd (mermaid source).
- New npm script "diagrams" generates light + dark SVG via mmdc; output
  committed to public/diagrams/. No prebuild hook (manual regenerate, like
  prisma generate / docs:index).
- Plan + grilling outcomes captured in docs/plans/landing-local-first.md.

Tracked under Scrum4Me story cmoq2qoik0001qa175iynfnaa
(PBI Marketing & Landingspagina, cmoq2q50s0000qa174rmrjove).

Verified: npm run lint (0 new errors), npm test (379/379), npm run build OK.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-03 20:24:10 +02:00
Janpeter Visser
0ee03c6b72
ProductDialog: create + edit met alle velden (#68)
* feat(ST-?): createProductAction + updateProductAction (data-object API)

Voegt data-object-gebaseerde createProductAction(data) en
updateProductAction(id, data) toe aan actions/products.ts voor gebruik
door ProductDialog. Bevat Zod-validatie (incl. github-regex op repo_url),
productAccessFilter voor update, pg_notify bij update, en productMember-
aanleg bij create. FormData-varianten hernoemd naar ...FormAction; callers
bijgewerkt. 9 nieuwe tests groen.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(ST-?): ProductDialog component (create + edit modes)

Voegt components/dialogs/product-dialog.tsx toe op basis van het
entity-dialog-patroon. Gebruikt react-hook-form + zodResolver voor
client-side validatie. Roept createProductAction/updateProductAction
aan en werkt stores/products-store.ts optimistisch bij. Demo-modus
disabled alle velden + submit-knop via DemoTooltip. 7 tests groen.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(ST-?): UI triggers voor ProductDialog op dashboard en product-detail

Voegt NewProductButton toe op het dashboard (vervangt de /products/new
link) en EditProductButton op de product-detail pagina. Bewerken-knop
is alleen zichtbaar voor de product-eigenaar en verborgen in demo-modus.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(test): cast toast via unknown to satisfy strict TS

`toast as { success, error }` direct-cast faalt omdat sonner's toast een
callable + properties is. TS2352. Cast via unknown lost het op zonder
gedrag te wijzigen.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-03 17:56:33 +02:00
2c3c5c0ab2 fix(test): cast toast via unknown to satisfy strict TS
`toast as { success, error }` direct-cast faalt omdat sonner's toast een
callable + properties is. TS2352. Cast via unknown lost het op zonder
gedrag te wijzigen.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-03 17:53:01 +02:00
Scrum4Me Agent
1b94f32954 feat(ST-?): UI triggers voor ProductDialog op dashboard en product-detail
Voegt NewProductButton toe op het dashboard (vervangt de /products/new
link) en EditProductButton op de product-detail pagina. Bewerken-knop
is alleen zichtbaar voor de product-eigenaar en verborgen in demo-modus.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-03 17:39:05 +02:00
Scrum4Me Agent
4103e36900 feat(ST-?): ProductDialog component (create + edit modes)
Voegt components/dialogs/product-dialog.tsx toe op basis van het
entity-dialog-patroon. Gebruikt react-hook-form + zodResolver voor
client-side validatie. Roept createProductAction/updateProductAction
aan en werkt stores/products-store.ts optimistisch bij. Demo-modus
disabled alle velden + submit-knop via DemoTooltip. 7 tests groen.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-03 17:35:18 +02:00
Scrum4Me Agent
ae66c21109 feat(ST-?): createProductAction + updateProductAction (data-object API)
Voegt data-object-gebaseerde createProductAction(data) en
updateProductAction(id, data) toe aan actions/products.ts voor gebruik
door ProductDialog. Bevat Zod-validatie (incl. github-regex op repo_url),
productAccessFilter voor update, pg_notify bij update, en productMember-
aanleg bij create. FormData-varianten hernoemd naar ...FormAction; callers
bijgewerkt. 9 nieuwe tests groen.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-03 17:28:47 +02:00
8d6bdef57e docs(runbook): agent-flow open issues & decision log
Bundelt vier valkuilen in de huidige agent-flow: PBI-ordering,
schema-conflicten bij parallelle migraties, branch-naam-collisies via
8-char suffix, cross-product orchestratie. Eerste is al gedekt door de
merge-policy PBI; de andere drie zijn entries onder anchor-PBI
"Agent-flow: openstaande beslissingen" (prio 4).

Lokaal commit; PR pas wanneer er meer aanverwante docs-changes zijn.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-03 17:09:39 +02:00
Janpeter Visser
60e2b62bbe
ST-migvir40: Schema: Pbi.pr_url + pr_merged_at + Prisma-migratie (#67)
Voeg twee optionele velden toe aan model Pbi voor het opslaan van de
PR-link en merge-status. Migratie 20260503145506_add_pbi_pr_link past
de database aan; Prisma-client is hergenereerd.

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-03 17:02:47 +02:00
Janpeter Visser
c357c662e7
Agent batch-flow: lokaal committen, push + PR aan het eind (#66)
* docs(ST-1115): agent-batch flow — branch-only-at-start, commit lokaal per taak

- CLAUDE.md Track A: voeg stap 1 (branch aanmaken) toe, splits stap 6
  (commit, geen push) af, voeg stap 7-8 (herhaal / push+PR bij lege queue)
- Hardstop Push-regel: verduidelijkt dat commits lokaal accumuleren per
  taak; push pas bij lege queue of expliciete gebruikersbevestiging
- docs/runbooks/branch-and-commit.md: nieuwe subsectie "Agent-batch flow"
  met tabel (run-start / na taak / queue leeg) en single-task edge case

* docs(ST-1115): AGENTS.md branch-and-PR quick-reference tabel

* docs(ST-1115): end-to-end verificatie checklist 1 batch = 1 Vercel-deploy

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-03 15:51:24 +02:00
4ca2635dd4 docs(adr): ADR-0010 — één product = één repo, cross-product planning later via Initiative-laag
Bevestigt het huidige datamodel (Product.repo_url is single) en kiest "duplicate-PBI per product" voor cross-repo werk; markeert een Initiative-laag (boven PBI) als toekomstige uitbreiding zodra de duplicatie-pijn te groot wordt.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-03 14:44:14 +02:00
Janpeter Visser
0ce6076a5c
Solo batch-enqueue: per-PBI volgorde + blocker-dialog (#65)
* feat(solo): orderBy taken per PBI-hiërarchie

Voeg pbi.priority en pbi.sort_order toe aan de task.findMany orderBy in de solo-page query zodat taken per PBI gegroepeerd worden vóór story- en task-volgorde.

* feat(solo): previewEnqueueAllAction met blocker-detectie

Voeg previewEnqueueAllAction toe aan actions/claude-jobs.ts: haalt taken op in PBI-volgorde, filtert actieve jobs, detecteert eerste blocker (REVIEW taak of BLOCKED PBI). Retourneert tasks[], blockerIndex en blockerReason. Tests: 7 nieuwe cases voor alle blocker-scenario's en demo-blokkering.

* feat(solo): enqueueClaudeJobsBatchAction met IDOR-check

Voeg enqueueClaudeJobsBatchAction toe: accepteert expliciete taskIds[], verifieert dat alle IDs bij de ingelogde gebruiker horen (IDOR-preventie), slaat taken met actieve jobs over (idempotent), en maakt jobs aan in transactie in opgegeven volgorde. 6 nieuwe tests.

* feat(solo): BatchEnqueueBlockerDialog component

Nieuw dialoogvenster dat gebruiker waarschuwt bij gedetecteerde blocker: toont blockerReason in NL, prefixCount taken vóór blokkade, confirm-knop (disabled met tooltip bij count=0) en annuleer-knop. 7 tests voor rendering, click-handlers en disabled-state.

* feat(solo): preview-then-confirm flow in SoloBoard Voer-alle-uit

Vervang directe enqueueAllTodoJobsAction door previewEnqueueAllAction + BatchEnqueueBlockerDialog. Geen blocker → enqueueClaudeJobsBatchAction direct. Wel blocker → dialog met prefix-enqueue of annuleer. Loading-state op knop tijdens preview en confirm. 5 integratie-tests.

* test(solo): uitgebreide batch-preflight tests met 2 PBI's en 4 taken

Nieuw claude-jobs-batch.test.ts: 10 gevallen voor previewEnqueueAllAction (PBI-volgorde, REVIEW/BLOCKED-detectie, active-job-skip met blockerIndex-shift) en enqueueClaudeJobsBatchAction (happy path, IDOR, active-job-skip, demo).
2026-05-03 13:55:13 +02:00
Janpeter Visser
add275fa6d
Helper: inventariseer veldnaam-gebruik in solo-store + backlog-store (#64)
Grep-resultaat (stores/ + lib/realtime/):
- solo-store.ts leest task_status, task_sort_order, task_title,
  story_status, story_sort_order, story_title, story_code via RealtimeEvent
- backlog-store.ts spreadt payload direct als Partial<BacklogStory/Task> →
  verwacht title/status/sort_order/pbi_id/priority/created_at (base namen)
- notifications-store.ts leest story_title/story_code uit eigen SSE-stroom
  (notifications/route.ts), niet uit pg_notify → blijft onveranderd
- debug-store.ts leest task_status, task_title (debug-only)

Beslissing: harde rename in trigger + store-update in zelfde migratie-set.
Geen dual-emit alias — zie docs/patterns/realtime-notify-payload.md.

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-03 13:15:41 +02:00
Janpeter Visser
1b3f5b0bee
docs(links): fix broken cross-references after restructure (#63) 2026-05-03 12:52:59 +02:00
Janpeter Visser
66ad0095ea
Phase 1 — Junk cleanup + front-matter on every doc (#62)
* docs(front-matter): add YAML front-matter to docs/ root

* docs(front-matter): add YAML front-matter to patterns/

* docs(index): regenerate INDEX.md after front-matter pass
2026-05-03 12:50:35 +02:00
Janpeter Visser
7e45bbdbc0
docs: AI-optimized docs restructure (Phases 1–8) (#61)
* docs(dialog-pattern): add generic entity-dialog spec

Introduceert docs/patterns/dialog.md als bron-of-truth voor elke
create/edit/detail-dialog in Scrum4Me, ongeacht het achterliggende
dataobject. Bevat 14 secties: uitgangspunten, stack, component-
architectuur, layout, validatie, drielaagse demo-policy, submission,
dialog-gedrag, theming, footer, triggers/URL-state, per-entiteit
profile-template, out-of-scope, en een verificatie-checklist.

Registreert het patroon in CLAUDE.md "Implementatiepatronen"-tabel
zodat Claude (en mensen) de spec verplicht raadplegen voor elke
nieuwe dialog.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* docs(dialog-pattern): convert task spec + add pbi/story entity-profiles

Reduceert docs/scrum4me-task-dialog.md van 507 naar ~140 regels: alle
gedeelde regels verhuisd naar docs/patterns/dialog.md, dit document
bevat nu alleen Task-specifieke velden, URL-pattern, status-veld,
server actions, triggers en bewuste out-of-scope-keuzes.

Voegt twee nieuwe entity-profielen toe voor bestaande dialogen:
- docs/scrum4me-pbi-dialog.md (PbiDialog: state-based, code+title-rij,
  PbiStatusSelect, geen delete in v1)
- docs/scrum4me-story-dialog.md (StoryDialog: state-based, header met
  status/priority badges, inline activity-log, demo-readonly-fallback,
  inline-delete-confirm i.p.v. AlertDialog)

Beide profielen documenteren expliciet de "Bekende gaps t.o.v.
generieke spec" zodat opvolgende PR's de afwijkingen kunnen
rechtzetten of bewust kunnen accorderen.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* Added pdevelopment docs

* docs(plans): add docs-restructure plan for AI-optimized lookup

Audit of existing 39 doc files (~10.700 lines) and a phased restructure
proposal aimed at minimising the tokens an AI agent has to read to find
the right reference. Captures resolved decisions on language (English),
ADR template (Nygard default with MADR escape-hatch), index generator
(node script), and folder taxonomy. Proposal status — fase 1 to follow.

* docs(adr): add ADR scaffolding (templates, README, meta-ADR)

Set up docs/adr/ as the canonical home for architecture decisions:

- templates/nygard.md — default four-section format (Status, Context,
  Decision, Consequences) for one-way-door decisions.
- templates/madr.md — MADR v4 with YAML front-matter and explicit
  Considered Options for decisions where rejected alternatives matter.
- README.md — naming convention (NNNN-kebab-case), template-selection
  guidance (Nygard default; MADR for auth, queue mechanics, agent
  integration), status lifecycle, and ADR roster.
- 0000-record-architecture-decisions.md — meta-ADR establishing the
  practice itself, in Nygard format.

Backfilling existing implicit decisions (base-ui-over-radix, float
sort_order, demo-user three-layer policy, etc.) is fase 6 of the
docs-restructure plan.

* feat(docs): add docs index generator + initial INDEX.md

scripts/generate-docs-index.mjs walks docs/**/*.md, parses YAML
front-matter (or first H1 fallback) and a Nygard-style ## Status
section, then writes docs/INDEX.md with grouped tables for ADRs,
Specs, Plans (with archive subsection), Patterns, and Other.

Pure Node 20 (no external deps); idempotent — running it twice
produces byte-identical output. Excludes adr/templates/, the ADR
README, INDEX.md itself, and any *_*.md sidecar file.

Wire-up:
- package.json: docs:index → node scripts/generate-docs-index.mjs

Initial run indexed 35 docs across the existing structure; the
generated INDEX.md is committed so the table is reviewable in the
PR before hooking generation into a pre-commit step.

* chore: ignore Obsidian vault and personal sidecar files

Add .obsidian/ (Obsidian vault config) and _*.md (personal sidecar
notes) to .gitignore so the docs/ tree can serve as canonical source
of truth while still being usable as an Obsidian vault for personal
authoring. The docs index generator already excludes the same _*.md
pattern from INDEX.md.

* docs(plans): add PBI bulk-create spec for docs-restructure

Machine-parseable spec for an executor that calls the scrum4me MCP
(create_pbi → create_story → create_task) to seed the docs-restructure
work into the DB.

- Section 1 (Context) is the PBI description; serves as task-context
  via mcp__scrum4me__get_claude_context.
- Section 2 lists the 6 resolved decisions (English, MD3+styling
  merged, solo-paneel merged, .Plans archived, Nygard ADR default,
  node index script).
- Section 3 records what already shipped on this branch so the
  executor doesn't duplicate the ADR scaffolding or index generator.
- Section 4 carries the structured YAML graph: 1 PBI, 8 stories
  (one per phase), 39 tasks. product_id is REPLACE_ME — fill before
  running.
- YAML validated with PyYAML; field schema sanity-checked.

* docs(junk-cleanup): remove stub patterns/test.md

* docs(junk-cleanup): archive .Plans/ to docs/plans/archive/

* docs(front-matter): add YAML front-matter to docs/ root

* docs(front-matter): add YAML front-matter to patterns/

* docs(front-matter): add YAML front-matter to plans + agent files

* docs(index): regenerate INDEX.md after front-matter pass

* docs(naming): drop scrum4me- prefix from doc filenames

* docs(naming): lowercase API.md and MD3 filenames

* docs(naming): rename plan file to kebab-case ASCII

* docs(naming): rename middleware.md to proxy.md (next 16)

* docs(naming): polish CLAUDE.md doc-index after renames

* docs(taxonomy): scaffold topical folders under docs/

* docs(taxonomy): move spec files into docs/specs/

* docs(taxonomy): move design/api/qa/backlog/assets into folders

* docs(taxonomy): move agent-instruction-audit into decisions/

* docs(split): break architecture.md into 6 topical files

* docs(split): merge solo-paneel-spec into specs/functional.md

* docs(split): merge md3-color-scheme into design/styling

* docs(trim): extract branch/commit rules into runbook

* docs(trim): extract MCP integration into runbook

* docs(adr): add 0001-base-ui-over-radix

* docs(adr): add 0002-float-sort-order

* docs(adr): add 0003-one-branch-per-milestone

* docs(adr): add 0004-status-enum-mapping

* docs(adr): add 0005-iron-session-over-nextauth

* docs(adr): add 0006-demo-user-three-layer-policy

* docs(adr): add 0007-claude-question-channel-design

* docs(adr): add 0008-agent-instructions-in-claude-md + update README index

* docs(index): regenerate after ADR 0001-0008

* docs(glossary): add docs/glossary.md

* chore(docs): regenerate INDEX.md in pre-commit hook

* docs(readme): link INDEX + glossary + agent instructions

* feat(docs): add doc-link checker script

* chore(docs): wire docs:check-links and docs npm scripts

* ci(docs): block merge on broken doc links

* docs(links): fix broken cross-references after restructure

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-03 03:21:59 +02:00
Janpeter Visser
289bcf9bf0
Phase 3 — Move docs into topical folders (#60)
* docs(taxonomy): scaffold topical folders under docs/

Create empty folder structure: architecture/, specs/, specs/dialogs/,
design/, api/, runbooks/, decisions/, backlog/, qa/, assets/ — each
with a .gitkeep so git tracks the directories.

* docs(taxonomy): add placeholder comment to .gitkeep files
2026-05-03 03:01:06 +02:00
Janpeter Visser
e10f8f81bc
Phase 2 — Normalize file naming (#59)
* docs(naming): drop scrum4me- prefix from doc filenames

Rename 10 docs/scrum4me-*.md files to unprefixed kebab-case names.
Update every internal link in docs/, CLAUDE.md, AGENTS.md, README.md.

* docs(naming): lowercase API.md and MD3 filenames

Rename docs/API.md → docs/api.md and
docs/MD3_Color_Scheme_Documentation.md → docs/md3-color-scheme.md.
Update all internal links across 7 files.

* docs(naming): rename plan file to kebab-case ASCII

Rename "docs/plans/Tweede Claude Agent — Planning Agent.md"
→ docs/plans/tweede-claude-agent-planning.md. No external links needed updating.

* docs(naming): rename middleware.md to proxy.md (next 16)

docs/patterns/middleware.md → docs/patterns/proxy.md following
the Next.js 16 proxy.ts rename. Update link in CLAUDE.md.

* docs(naming): polish CLAUDE.md doc-index after renames

Fix doubled scrum4me-scrum4me-mcp repo references (cascade from
prior sed) in CLAUDE.md, docs/architecture.md, backlog.md,
agent-instruction-audit.md, and plans/ST-1109. Update
'Middleware' label to 'Proxy middleware' in patterns table.
2026-05-03 03:00:47 +02:00
dc3832ad54
feat(schema): add notify_pbi_change trigger so PBI INSERT/UPDATE/DELETE emits NOTIFY on scrum4me_changes (#58)
Co-authored-by: Scrum4Me Agent <30029041+madhura68@users.noreply.github.com>
2026-05-02 21:10:03 +02:00
6375ed6949
End-to-end smoke-test: PBI/Story/Task verschijnen zonder refresh (#57)
* fix(backlog-store): make INSERT handlers idempotent to prevent duplicate entries on duplicate SSE-events

* docs(realtime-smoke): add manual smoke-checklist for PBI/Story/Task realtime end-to-end verification

---------

Co-authored-by: Scrum4Me Agent <30029041+madhura68@users.noreply.github.com>
2026-05-02 21:09:37 +02:00
311f413e24
Twee markdown-bestanden in docs/docker-smoke/ aanmaken (#55)
* docs: add docs/docker-smoke/2-mei-task-1.md smoke test file

* docs: add docs/docker-smoke/2-mei-task-2.md smoke test file
2026-05-02 20:24:46 +02:00
a11b4709a7
fix(insights): narrow Sprint.completed_at to Date in velocity.ts (#56)
Vercel build was failing with TS18047 — `sprint.completed_at` is
possibly `null`. The earlier `.filter(s => s.completed_at != null)`
runtime-filtered the nulls out but did NOT narrow the element type;
TypeScript still saw `Date | null` on the result.

Add a user-defined type guard `(s): s is SprintWithCompletedAt =>` so
the narrowed array carries `completed_at: Date`. No runtime change.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-02 20:21:30 +02:00
b2427fd07b fix(insights): skip sprints with null completed_at in velocity
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-02 18:12:35 +02:00
a754acf13b
feat(schema): Task.repo_url — cross-repo override for agent worktree (#54)
When a task targets a different repo than its parent product (e.g. an
MCP-server task tracked under the main product's PBI), product.repo_url
points to the wrong place. Result observed in story 'Verify-gate'
batch (2 May): agent's gate-task work failed to push because product
was Scrum4Me but the code lives in scrum4me-mcp.

Add optional `Task.repo_url` (TEXT, nullable). scrum4me-mcp's
`resolveRepoRoot` will read this in a follow-up PR — null falls back
to product.repo_url, preserving current behaviour for the 99% case.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-02 18:02:01 +02:00
e02c6ff9d9
docs(CLAUDE.md): add Integration-task smoke-test section (#52)
Documents the bash curl-check recipe agents must run before marking an
Integration-task done: start dev server, curl the route, grep for expected
sections, fail if any are missing.

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-02 17:45:51 +02:00
bae0d478ea
docs: add story-with-ui-component pattern + CLAUDE.md reference (#51)
Documents the mandatory 3-task pattern (Helper / Component / Integration)
for stories introducing UI components. Cites the 2026-05-02 Velocity story
as the anti-pattern and the Foundation Sprint Health story as the blueprint.

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-02 17:45:37 +02:00
ced0a8a4c0
Verify-gate uitbreiden: DIVERGENT/PARTIAL vereist agent-acknowledgement (#53)
* feat(schema): add Task.verify_required enum (ALIGNED / ALIGNED_OR_PARTIAL / ANY)

Adds VerifyRequired enum and verify_required field (default ALIGNED_OR_PARTIAL)
to the Task model. Also declares the claude_jobs_status_finished_at_idx index
in the schema to match the live DB. Applied via db execute + migrate resolve.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(ui): add verify_required select to TaskDetailDialog

SoloTask interface, solo page mapping, solo store, PATCH route handler
and TaskDetailDialog all updated to expose the three-level verify gate
(ALIGNED / ALIGNED_OR_PARTIAL / ANY) as a native select. Disabled with
DemoTooltip in demo mode.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-02 17:45:19 +02:00
d93c91c386
fix(insights): integrate all 5 sections in /insights + add missing components (#50)
The /insights page was rendering only Sprint Health (2 charts).
PRs #47/#48/#49 delivered helpers + tests for Velocity, Backlog health
and Agent throughput, but Velocity and Backlog never produced their
UI components, and none of the four new sections were wired into
page.tsx. Result: user sees 2 charts where 5 sections were promised.

This PR fills the gaps:

- New `app/(app)/insights/components/velocity-chart.tsx` — Recharts
  grouped BarChart with optional ReferenceLine for the average. Empty
  state when <2 completed sprints.
- New `app/(app)/insights/components/backlog-health.tsx` — counters
  (stories sans AC / tasks sans plan / stuck>7d) + stuck-tasks table
  with severity-coded days-stuck cell.
- `app/(app)/insights/page.tsx` rewritten as 5 sections:
  Sprint Health, Plan-quality (donut + alignment-trend), Agent
  throughput, Velocity, Backlog health. Helpers run in one
  Promise.all so the page renders in a single tick.

Tests: 314/314 green, tsc clean, lint 0 errors.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-02 17:23:03 +02:00
739037a60b
Agent throughput: jobs per dag stacked bar + KPI-strip (#49)
* feat(insights): add getJobsPerDay helper — agent throughput per day + KPIs

Raw SQL aggregation of claude_jobs by day and status over 14 days with
zero-fill for missing days. KPIs: todayCount, successRate7d, avgDurationSeconds7d.
Optional productId filter.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(insights): add AgentThroughputCard — stacked BarChart + KPI-strip + product filter

KPI strip (jobs today, 7d success rate, 7d avg duration), 14-day stacked
BarChart with JOB_STATUS_COLORS, and URL-bookmarkable product dropdown via
useTransition + router.replace. Empty-state when no activity.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-02 16:30:06 +02:00
647 changed files with 72015 additions and 9226 deletions

View file

@ -1,81 +0,0 @@
{
"permissions": {
"allow": [
"Bash(npx tsc *)",
"Bash(git add *)",
"Bash(git commit *)",
"Bash(git push *)",
"Bash(npx eslint *)",
"Bash(npm run *)",
"Bash(npx tsx *)",
"mcp__scrum4me__list_products",
"mcp__scrum4me__get_claude_context",
"Bash(gh pr *)",
"Bash(git -C /Users/janpetervisser/Development/Scrum4Me branch --show-current)",
"Bash(git -C /Users/janpetervisser/Development/Scrum4Me log --oneline main..HEAD)",
"Bash(git -C /Users/janpetervisser/Development/Scrum4Me checkout main)",
"Bash(git -C /Users/janpetervisser/Development/Scrum4Me pull --ff-only)",
"Bash(git -C /Users/janpetervisser/Development/Scrum4Me branch -d feat/ST-1001-qr-login-milestone-plan)",
"Bash(git -C /Users/janpetervisser/Development/Scrum4Me checkout -b feat/M10-qr-login)",
"Bash(git -C /Users/janpetervisser/Development/Scrum4Me log --oneline -3)",
"mcp__scrum4me__log_implementation",
"mcp__scrum4me__update_task_status",
"mcp__scrum4me__log_test_result",
"mcp__scrum4me__log_commit",
"Bash(npx vitest *)",
"Bash(echo \"=== exit: $? ===\")",
"Bash(npm test *)",
"Bash(echo \"exit: $?\")",
"Bash(npx prisma *)",
"Bash(npm install *)",
"Bash(git checkout *)",
"Bash(git pull *)",
"Bash(git branch *)",
"Read(//Users/janpetervisser/Development/**)",
"Bash(git -C /Users/janpetervisser/Development/scrum4me-mcp status -sb)",
"Bash(git -C /Users/janpetervisser/Development/scrum4me-mcp submodule status)",
"Bash(git -C /Users/janpetervisser/Development/scrum4me-mcp log --oneline -5)",
"Bash(git -C /Users/janpetervisser/Development/scrum4me-mcp/vendor/scrum4me log --oneline -3)",
"Bash(git -C /Users/janpetervisser/Development/scrum4me-mcp/vendor/scrum4me branch -a)",
"Bash(git fetch *)",
"Bash(git reset *)",
"mcp__scrum4me__update_task_plan",
"mcp__scrum4me__create_task",
"mcp__scrum4me__ask_user_question",
"Bash(git *)",
"mcp__scrum4me__create_pbi",
"mcp__scrum4me__create_story",
"mcp__scrum4me__health",
"Bash(python3 -c \"import json,sys; d=json.load\\(sys.stdin\\); print\\(json.dumps\\(d.get\\('mcpServers', {}\\), indent=2\\)\\)\")",
"Read(//Users/janpetervisser/.claude/**)",
"Bash(python3 -c \"import json,sys; d=json.load\\(sys.stdin\\); print\\(json.dumps\\(d, indent=2\\)\\)\")",
"Bash(python3 -c \"import json,sys; d=json.load\\(sys.stdin\\); print\\(json.dumps\\(d.get\\('mcpServers',{}\\), indent=2\\)\\)\")",
"Bash(python3 -m json.tool)",
"mcp__scrum4me__wait_for_job",
"Bash(npx ctx7@latest docs /websites/github_en_rest \"How to fetch Copilot bot pull request reviews and identify them by author\")",
"Bash(npm i *)",
"Bash(curl *)",
"Bash(grep -E \"\\\\.\\(tsx|ts\\)$\")",
"mcp__scrum4me__update_job_status",
"Bash(node --env-file=.env.local node_modules/tsx/dist/cli.mjs ./scripts/check-jobs-tmp.ts)",
"Bash(node --env-file=.env.local node_modules/tsx/dist/cli.mjs ./scripts/check-workers-tmp.ts)",
"Bash(node --env-file=.env.local node_modules/prisma/build/index.js migrate deploy)",
"Bash(xargs grep *)",
"Bash(node --env-file=.env.local node_modules/prisma/build/index.js migrate status)",
"Bash(gh run *)",
"Bash(dir \"C:\\\\Users\\\\Madhu\\\\Projects\")",
"Bash(Get-ChildItem -Path \"C:\\\\Users\\\\Madhu\\\\Projects\\\\scrum4me-mcp\" -Recurse -Include \"*wait*\" -ErrorAction SilentlyContinue)",
"Bash(Select-Object FullName)",
"Bash(Get-ChildItem -Path \"C:\\\\Users\\\\Madhu\\\\Projects\\\\scrum4me-mcp\" -Force)",
"Bash(Format-Table -Property Name, PSIsContainer)",
"Bash(Sort-Object)",
"PowerShell(Push-Location \"C:\\\\Users\\\\Madhu\\\\Projects\\\\scrum4me-mcp\"; npx tsc --noEmit; $result = $?; Pop-Location; Write-Output \"typecheck ok: $result\")",
"PowerShell(git *)",
"mcp__scrum4me__verify_task_against_plan"
]
},
"enableAllProjectMcpServers": true,
"enabledMcpjsonServers": [
"scrum4me"
]
}

View file

@ -14,3 +14,30 @@ NODE_ENV="development"
# local dev (the route returns 401 if the Authorization header doesn't match).
# Generate with: openssl rand -base64 32
CRON_SECRET=""
# PBI-55 — Web Push (VAPID). All optional; app starts without these.
# Generate keys with: npx web-push generate-vapid-keys
NEXT_PUBLIC_VAPID_PUBLIC_KEY=""
VAPID_PRIVATE_KEY=""
# Must start with mailto: e.g. mailto:admin@example.com
VAPID_SUBJECT="mailto:admin@example.com"
# Shared secret for POST /api/internal/push/send — min 32 chars
# Generate with: openssl rand -base64 32
INTERNAL_PUSH_SECRET=""
# PBI-66 — Anthropic API key voor `npm run db:sync-model-prices`.
# Optional. Alleen nodig om wekelijks de model_prices tabel te synchroniseren.
# Genereer op https://console.anthropic.com/ → API Keys.
# /v1/models is een gratis metadata-call (geen tokens, geen credit nodig).
ANTHROPIC_API_KEY=""
# v1-readiness item 2 — Sentry error monitoring.
# Optional. Without DSN, the SDK is a no-op (no network, no overhead).
# Get a DSN at https://sentry.io → Project → Settings → Client Keys (DSN).
NEXT_PUBLIC_SENTRY_DSN=""
# Required ONLY if you want source-map upload during build (production deploy).
# In Vercel: project settings → Environment Variables → add as encrypted.
SENTRY_ORG=""
SENTRY_PROJECT=""
SENTRY_AUTH_TOKEN=""

View file

@ -5,11 +5,23 @@ on:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
inputs:
target:
type: choice
description: Deploy target
options: [preview, production]
default: preview
permissions:
contents: read
pull-requests: read
jobs:
ci:
name: Lint, Typecheck, Test & Build
runs-on: ubuntu-latest
if: github.event_name != 'workflow_dispatch'
steps:
- name: Checkout
@ -39,6 +51,9 @@ jobs:
- name: Test
run: npm test
- name: Check doc links
run: npm run docs:check-links
- name: Build
run: npm run build
env:
@ -46,11 +61,52 @@ jobs:
DIRECT_URL: ${{ secrets.DIRECT_URL }}
SESSION_SECRET: ${{ secrets.SESSION_SECRET }}
changes:
name: Detect deploy-relevant changes
runs-on: ubuntu-latest
needs: ci
# Alleen relevant voor auto-deploy jobs; skip wanneer auto-deploy uit staat.
if: vars.AUTO_DEPLOY_ENABLED == 'true' && github.event_name != 'workflow_dispatch'
outputs:
code: ${{ steps.filter.outputs.code }}
steps:
- uses: actions/checkout@v5
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
code:
- 'app/**'
- 'components/**'
- 'lib/**'
- 'actions/**'
- 'stores/**'
- 'prisma/**'
- 'public/**'
- 'package.json'
- 'package-lock.json'
- 'next.config.ts'
- 'tsconfig.json'
- 'vercel.json'
- 'proxy.ts'
- 'middleware.ts'
- '.github/workflows/**'
deploy-preview:
name: Deploy Preview (PR)
runs-on: ubuntu-latest
needs: ci
if: github.event_name == 'pull_request'
needs: [ci, changes]
# Auto-deploy is uit. Gebruik "Run workflow" (workflow_dispatch) op de
# Actions-pagina voor handmatige deploys. Zet repo-variable
# AUTO_DEPLOY_ENABLED=true in Settings → Secrets and variables → Actions
# om PR-preview-deploys weer in te schakelen.
if: |
vars.AUTO_DEPLOY_ENABLED == 'true'
&& github.event_name == 'pull_request' && (
(needs.changes.outputs.code == 'true'
&& !contains(github.event.pull_request.labels.*.name, 'skip-deploy'))
|| contains(github.event.pull_request.labels.*.name, 'force-deploy')
)
steps:
- name: Checkout
@ -77,8 +133,15 @@ jobs:
deploy-production:
name: Deploy Production (main)
runs-on: ubuntu-latest
needs: ci
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
needs: [ci, changes]
# Auto-deploy is uit. Gebruik "Run workflow" (workflow_dispatch) →
# target=production voor handmatige productie-deploys. Zet repo-variable
# AUTO_DEPLOY_ENABLED=true om push-naar-main weer auto te deployen.
if: |
vars.AUTO_DEPLOY_ENABLED == 'true'
&& github.ref == 'refs/heads/main'
&& github.event_name == 'push'
&& needs.changes.outputs.code == 'true'
steps:
- name: Checkout
@ -107,3 +170,42 @@ jobs:
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
deploy-manual:
name: Deploy Manual (workflow_dispatch)
runs-on: ubuntu-latest
if: github.event_name == 'workflow_dispatch'
steps:
- name: Checkout
uses: actions/checkout@v5
- name: Setup Node.js
uses: actions/setup-node@v5
with:
node-version: '24'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Install Vercel CLI
run: npm install -g vercel@latest
- name: Run database migrations (production only)
if: inputs.target == 'production'
run: npx prisma migrate deploy
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
DIRECT_URL: ${{ secrets.DIRECT_URL }}
- name: Deploy
run: |
if [ "${{ inputs.target }}" = "production" ]; then
vercel deploy --prod --token=${{ secrets.VERCEL_TOKEN }}
else
vercel deploy --token=${{ secrets.VERCEL_TOKEN }}
fi
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}

8
.gitignore vendored
View file

@ -50,9 +50,9 @@ next-env.d.ts
# Claude Code local settings
.claude/settings.local.json
.claude/worktrees/
# Local plan/scratch files (per-developer, not shared)
.Plans/
# Editor
.vscode/
@ -72,4 +72,8 @@ jp.sh
# Lokale scratch-bestanden
Brainstro
/graphify-out
/graphify-out
# Personal Obsidian authoring layer (vault config + sidecar files prefixed `_`)
.obsidian/
_*.md

View file

@ -1 +1,6 @@
npx lint-staged
if git diff --cached --name-only | grep -q '^docs/.*\.md$'; then
npm run docs:index
git add docs/INDEX.md
fi

View file

@ -1,38 +1,23 @@
<!-- BEGIN:nextjs-agent-rules -->
# This is NOT the Next.js you know
---
title: "AGENTS.md — Scrum4Me agent rules"
status: active
audience: [ai-agent]
language: en
last_updated: 2026-05-03
---
This version has breaking changes — APIs, conventions, and file structure may all differ from your training data. Read the relevant guide in `node_modules/next/dist/docs/` before writing any code. Heed deprecation notices.
<!-- END:nextjs-agent-rules -->
# Agent Instructions — Scrum4Me
# Scrum4Me Codex Rules
This file is a redirect stub. All agent instructions live in **[CLAUDE.md](./CLAUDE.md)**.
Read `CLAUDE.md` and the relevant files in `docs/` before changing behavior. The same product and security rules apply to Codex work.
For Claude Code specifically, CLAUDE.md is loaded automatically. Start there.
## Access Control
## Branch & PR-flow (quick reference)
- Product-scoped access is owner-or-member: use `productAccessFilter(userId)` from `lib/product-access.ts`.
- Use owner-only `user_id` checks only for actions that truly require ownership, such as product archiving and team management.
- Never trust client-provided IDs by themselves. For reorder, promotion, completion, or bulk updates, fetch the records with both `id in (...)` and the parent scope (`product_id`, `pbi_id`, `sprint_id`, or `story_id`) before writing.
- Reject duplicate IDs in ordered lists or decision payloads.
- Derive denormalized fields from database parents, for example `pbi.product_id`, not from form data or JSON bodies.
- Demo users and demo API tokens must receive 403 on write operations.
| Moment | Actie | Verbod |
|---|---|---|
| Start run | `git checkout -b feat/<batch-slug>` | `gh pr create` |
| Na elke taak | `git add -A && git commit -m "<type>(ST-XXX): <title>"` | `git push` |
| Queue leeg | `git push -u origin <branch>` + `gh pr create` | — |
## Documentation Sync
When changing behavior, API responses, dependencies, environment variables, deployment behavior, or analytics, update the matching docs in the same change:
- `README.md` for setup, dependencies, deployment, and API overview.
- `docs/scrum4me-functional-spec.md` for user-facing/API requirements.
- `docs/scrum4me-architecture.md` for stack, access model, data model, env vars, and deployment.
- `docs/patterns/` when a reusable implementation rule changes.
- `CLAUDE.md` and this file when an agent instruction would have prevented the issue.
## Verification
Before handing work back, run:
```bash
npm run lint
npm test
npm run build
```
Full details: [docs/runbooks/branch-and-commit.md § Agent-batch flow](./docs/runbooks/branch-and-commit.md)

106
CHANGELOG.md Normal file
View file

@ -0,0 +1,106 @@
# Changelog
All notable changes to **Scrum4Me** are documented in this file.
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
---
## [Unreleased]
---
## [1.0.0] — 2026-05-04
**Eerste stabiele release** — MVP volgens functional spec is af, getest en in
productie. Geen breaking changes ten opzichte van 0.9.0; deze tag markeert de
launch-ready state na de v1-readiness-checklist (Now + Before-launch items).
### Added
- Rate-limiting: `enforceUserRateLimit(scope, userId)` helper toegepast op alle
high-value mutation paths — PBI/Story/Task/Todo/Sprint/Product/Token create,
Claude job enqueue, answerQuestion, story-log POST, avatar upload.
([#86](https://github.com/madhura68/Scrum4Me/pull/86))
- Sentry error-monitoring scaffolding (`@sentry/nextjs`) met no-op fallback
zonder DSN. Activeer via `NEXT_PUBLIC_SENTRY_DSN` in Vercel env-vars.
([#85](https://github.com/madhura68/Scrum4Me/pull/85))
- `CHANGELOG.md` (Keep a Changelog formaat) + `docs/runbooks/v1-smoke-test.md`
— 11-secties pre-launch verificatie. ([#89](https://github.com/madhura68/Scrum4Me/pull/89))
### Changed
- A11y Lighthouse score op `/products/[id]` van 86 → ≥95: `aria-selected`
`aria-pressed` op PBI-cards (correct ARIA role-attribute pairing); tap-targets
≥28×28 px op hover-icon-buttons. ([#88](https://github.com/madhura68/Scrum4Me/pull/88))
- A11y form-label associaties (`htmlFor` + `id`) op happy-path dialogen
(Story/Task + Promote-PBI/Story); auth-pages krijgen `<main>` landmark.
([#87](https://github.com/madhura68/Scrum4Me/pull/87))
- README: test-count 69 → 445, env-vars-tabel uitgebreid met `CRON_SECRET` en
Sentry-vars. ([#89](https://github.com/madhura68/Scrum4Me/pull/89))
### Fixed
- Demo-policy: drie mutation-paden zonder `isDemo`-check gedicht
(`toggleTodoAction`, `archiveCompletedTodosAction`, `leaveProductAction`).
([#89](https://github.com/madhura68/Scrum4Me/pull/89))
### Security
- Vier debug-routes (`/debug-env`, `/debug-realtime`, `/api/debug/*`) krijgen
een NODE_ENV-guard → 404 in productie. ([#89](https://github.com/madhura68/Scrum4Me/pull/89))
---
## [0.9.0] — 2026-05-04
[GitHub Release](https://github.com/madhura68/Scrum4Me/releases/tag/v0.9.0)
### Added
- **PBI-11: Mobile-shell met landscape-lock** ([#81](https://github.com/madhura68/Scrum4Me/pull/81)):
- Aparte route group `app/(mobile)/m/{settings,pair,products}/...` met eigen
layout (zonder NavBar/StatusBar/MinWidthBanner)
- `LandscapeGuard` (rotate-overlay in portrait), `MobileTabBar` (3 lucide-iconen)
- PWA-manifest met `"orientation": "landscape"`
- UA-redirect bij login: telefoons (`Mobi`-substring) → `/m/products/[active]/solo`,
tablets en desktop → `/dashboard`
- Gedeelde `lib/auth-guard.ts` `requireSession()` helper, hergebruikt door beide layouts
- Mobile-fullscreen voor entity-dialogen via gedeelde `entityDialogContentClasses`
- Sprint Product-Backlog kolom: filter-popover (prioriteit + status) en
edit-iconen op PBI/story/task-rijen. ([#79](https://github.com/madhura68/Scrum4Me/pull/79))
- Edit-icoon op product-card in dashboard (consistent met PBI/story/task-pattern).
([#83](https://github.com/madhura68/Scrum4Me/pull/83))
- v1.0 readiness checklist in `docs/old/plans/v1-readiness.md`.
([#82](https://github.com/madhura68/Scrum4Me/pull/82))
### Changed
- Refactor `app/(app)/layout.tsx` om gedeelde `requireSession()` te gebruiken
(gedrag onveranderd). ([#81](https://github.com/madhura68/Scrum4Me/pull/81))
- `/m/pair` filesystem-verhuisd uit `(app)/` naar `(mobile)/` — URL onveranderd.
([#81](https://github.com/madhura68/Scrum4Me/pull/81))
---
## [0.4.0] — eerder
### Added
- M9 — Actief Product Backlog: persistente actieve PB-keuze, gesplitste
navigatie, disabled-states bij geen actief product
---
## [0.3.1] — eerder
Initiële stabilisatie-release.
---
## Pre-0.3.x
Foundation-werk (M0 t/m M8) is niet retroactief in dit changelog opgenomen.
Voor de volledige milestone-historie zie [docs/old/backlog/index.md](./docs/old/backlog/index.md).
---
[Unreleased]: https://github.com/madhura68/Scrum4Me/compare/v1.0.0...HEAD
[1.0.0]: https://github.com/madhura68/Scrum4Me/releases/tag/v1.0.0
[0.9.0]: https://github.com/madhura68/Scrum4Me/releases/tag/v0.9.0
[0.4.0]: https://github.com/madhura68/Scrum4Me/commit/615f0c8
[0.3.1]: https://github.com/madhura68/Scrum4Me/commit/ecc05dd

404
CLAUDE.md
View file

@ -1,340 +1,154 @@
---
title: "CLAUDE.md — Scrum4Me"
status: active
audience: [ai-agent]
language: nl
last_updated: 2026-05-11
---
# CLAUDE.md — Scrum4Me
Dit is het centrale instructiedocument voor Claude Code. Lees dit volledig voordat je iets bouwt.
Desktop-first Scrum-app voor solo developers en kleine teams. Hiërarchie: product → PBI → story → taak. Zie [README.md](./README.md) voor setup.
---
## Wat is Scrum4Me?
## Orientatie
Een desktop-first fullstack webapplicatie voor solo developers en kleine Scrum Teams die meerdere softwareprojecten parallel beheren. De app organiseert werk hiërarchisch (product → PBI → story → taak), biedt gesplitste planningsschermen met drag-and-drop, en integreert met Claude Code via een REST API.
---
## Specificatiedocumenten
Lees het relevante document voordat je aan een feature begint. Nooit gokken over requirements.
| Document | Gebruik voor |
| Bestand | Waarvoor |
|---|---|
| `docs/scrum4me-functional-spec.md` | Acceptatiecriteria, randgevallen, user flows |
| `docs/scrum4me-architecture.md` | Stack, datamodel, Prisma schema, Zustand stores |
| `docs/scrum4me-backlog.md` | Welke task bouwen, volgorde, "done when"-criteria |
| `docs/scrum4me-personas.md` | Lars (primair), Dina, Remi — gebruik bij UI-beslissingen |
| `docs/scrum4me-product-backlog.md` | Historische domein-backlog (referentie); seed wordt sinds ST-004 gegenereerd uit `scrum4me-backlog.md` via `prisma/seed-data/parse-backlog.ts` |
| `docs/API.md` | REST-API contract voor Claude Code — endpoints, status-enums, foutcodes, voorbeeld-curls |
| `docs/scrum4me-styling.md` | **Lees dit voor elk component** — MD3-kleuren, shadcn patronen |
| `docs/agent-instruction-audit.md` | Waarom de agent-instructies zijn aangescherpt; checklist voor toekomstige wijzigingen |
| `docs/plans/<milestone-key>-*.md` | Implementatieplan per milestone — Bestanden, Stappen, Aandachtspunten, Verificatie. Lees vóór je aan een ST begint. Milestone-key matcht backlog-header (`M9`, `M3.5`, `PBI-9`, …). |
| [`madhura68/scrum4me-mcp`](https://github.com/madhura68/scrum4me-mcp) | MCP-server repo: native tools voor Claude Code, schema-sync via git submodule |
| `docs/INDEX.md` | Gegenereerde index van alle docs — begin hier |
| `docs/specs/functional.md` | Acceptatiecriteria, user flows |
| `docs/architecture.md` | Breadcrumb → 6 topische arch-bestanden |
| `docs/api/rest-contract.md` | REST API contract voor Claude Code |
| `docs/design/styling.md` | **Lees vóór elk component** — MD3-tokens, shadcn |
| `docs/adr/` | Architecture Decision Records — tech-keuzes (base-ui vs Radix, sort-order, demo-policy, …) |
| `docs/architecture/` | 6 topische architecture-bestanden (data-model, auth, sprint-execution, …) — uitwerking van `docs/architecture.md` |
| `docs/runbooks/plan-to-pbi-flow.md` | **Na goedgekeurd plan** — PBI/Story/Task aanmaken via MCP, zónder direct uitvoeren |
---
## Waar te beginnen
## Hoe werk vinden
Volg de backlog strikt op volgorde. Start bij **ST-001**. Sla geen milestone over.
1. Branch aanmaken: `git checkout -b feat/<batch-slug>` — nog **geen** `gh pr create`
2. `mcp__scrum4me__get_claude_context` → pak de next story
3. Voer taken uit in `sort_order`; update status per taak
4. Lees het relevante patroon en styling vóór je begint
5. Verifieer: `npm run verify && npm run build``verify` = lint + typecheck + test
6. Commit per laag: `git add -A && git commit`**geen** `git push` — zie [docs/runbooks/branch-and-commit.md](./docs/runbooks/branch-and-commit.md)
7. Herhaal stap 26 per story; branch blijft dezelfde
8. Queue leeg → `git push -u origin <branch>` + `gh pr create`
```
M0 (ST-001008) → M1 (ST-101110) → M2 (ST-201210)
→ M3 (ST-301312) → M4 (ST-401410) → M5 (ST-501506)
→ M6 (ST-601612)
```
Werken aan een task kan via twee tracks. Track A heeft de voorkeur als je in Claude Code zit; Track B is voor Codex of omgevingen zonder MCP.
### Track A — via Claude Code MCP (aanbevolen)
1. Roep `mcp__scrum4me__implement_next_story` aan met `product_id` (gebruik `mcp__scrum4me__list_products` als je het id niet weet)
2. De prompt orkestreert: `get_claude_context``log_implementation` → per task `update_task_status(in_progress)` → bouw → `update_task_status(done)``log_test_result``log_commit`
3. Bouw de tasks in volgorde van `sort_order`; lees per task de relevante pattern-doc en styling
4. Verifieer: `npm run lint && npm test && npm run build`
5. Commit per laag (zie Commit Strategy)
### Track B — manueel (Codex of zonder MCP)
1. Lees de task in `scrum4me-backlog.md`
2. Zoek de bijbehorende feature-spec in `scrum4me-functional-spec.md`
3. Lees het relevante patroon in `docs/patterns/` en styling in `docs/scrum4me-styling.md` als dat van toepassing is
4. Bouw — test — verifieer de "Done when"-criteria
5. Vraag of de code correct is
6. Commit (zie Commit Strategy hieronder)
7. Vraag of de volgende taak gedaan moet worden
Volledige MCP-tool documentatie: [docs/runbooks/mcp-integration.md](./docs/runbooks/mcp-integration.md)
---
## Tech stack
## Hardstop regels
```
Next.js 16 (App Router) + React 19
TypeScript strict
Tailwind CSS + shadcn/ui
MD3 kleurensysteem via app/styles/theme.css
Zustand (client state)
dnd-kit (drag-and-drop)
Prisma v7 + PostgreSQL (Neon)
iron-session (auth cookies)
bcryptjs + Zod + Sonner
Sharp (avatarverwerking)
Vercel Analytics (@vercel/analytics/next)
```
> ⚠️ **Stylingregel:** Gebruik **nooit** `bg-blue-500` of willekeurige Tailwind-kleuren.
> Gebruik altijd semantische MD3-tokens: `bg-primary`, `bg-status-done`, `bg-priority-critical`.
> Zie `scrum4me-styling.md` voor alle patronen.
> ⚠️ **Next.js-versie:** Lees `node_modules/next/dist/docs/` bij twijfel — API's kunnen afwijken van trainingsdata.
- **Styling:** nooit `bg-blue-500`; altijd MD3-tokens (`bg-primary`, `bg-status-done`, …)
- **UI:** gebruik `@base-ui/react` met `render`-prop, niet Radix `asChild`
- **Push:** commits accumuleren lokaal per taak (`git add -A && git commit`); push + PR pas bij lege queue of na expliciete gebruikersbevestiging — zie [branch-and-commit.md](./docs/runbooks/branch-and-commit.md)
- **Demo:** drie lagen — proxy.ts + server action + UI disabled knop
- **Proxy:** `proxy.ts` in repo-root (géén `middleware.ts`) onverzegelt de iron-session, redirect niet-geauthenticeerde users op `/dashboard|/products|/ideas`, en blokkeert niet-GET API-writes voor demo-users behalve `/api/cron/*`
- **Enum:** DB UPPER_SNAKE ↔ API lowercase — uitsluitend via `lib/task-status.ts`
- **Foutcodes:** 400 = parse-fout, 422 = Zod-validatie, 403 = demo-token
- **Server/client grens:** `*-server.ts` bevat DB/node-only; nooit importeren in client component
- **Worker/jobs:** `ClaudeJob` queue (`QUEUED → CLAIMED → RUNNING → DONE|FAILED|SKIPPED`); MCP-worker claimt via `wait_for_job` en sluit met `update_job_status` — zie [worker-idempotency.md](./docs/runbooks/worker-idempotency.md)
- **Model/mode per ClaudeJob:** kind-default → product → job-snapshot → `task.requires_opus`. Resolver in `scrum4me-mcp/src/lib/job-config.ts` (en gespiegeld in `lib/job-config.ts`) — zie [job-model-selection.md](./docs/runbooks/job-model-selection.md)
- **Deployment:** `npm run verify && npm run build` vóór elke PR. Selectieve deploy-controle (labels + path-filter): zie [docs/runbooks/deploy-control.md](./docs/runbooks/deploy-control.md)
---
## UI Library Conventions
## Stack
- Dit project gebruikt **`@base-ui/react`**, *niet* Radix UI — ondanks dat shadcn-componenten visueel-identiek zijn
- Composition gebeurt via de **`render`-prop**, niet via Radix's `asChild`:
- ✅ `<TooltipTrigger render={<button />}>...</TooltipTrigger>`
- ❌ `<TooltipTrigger asChild><button>...</button></TooltipTrigger>` — geeft TS-errors
- Vóór je een nieuwe shadcn-/UI-primitive gebruikt: grep eerst de codebase voor bestaand gebruik en volg dat patroon (`grep -rn "PrimitiveTrigger" components/`)
- shadcn-componenten in `components/ui/` zijn dunne wrappers rond `@base-ui/react`-primitives; lees die voor de exacte prop-API
| Laag | Technologie |
|---|---|
| Framework | Next.js 16.2 (App Router) + React 19.2 — PPR/Cache Components beschikbaar |
| Taal | TypeScript strict |
| Styling | Tailwind CSS v4 + shadcn/ui + MD3 via `app/styles/theme.css` |
| State | Zustand + dnd-kit |
| DB | Prisma v7.8 + PostgreSQL (Neon) |
| Auth | iron-session + bcryptjs |
| Test | Vitest (`__tests__/`, config in `vitest.config.ts`) |
| Utilities | Zod, Sonner, Sharp, Vercel Analytics |
---
## Implementatiepatronen
Lees het relevante patroon vóór je begint. Nooit uit het hoofd schrijven.
## Patterns quickref
| Patroon | Bestand |
|---|---|
| iron-session (auth cookies) | `docs/patterns/iron-session.md` |
| Prisma Client singleton | `docs/patterns/prisma-client.md` |
| Server Action (met auth + Zod) | `docs/patterns/server-action.md` |
| Route Handler (REST API) | `docs/patterns/route-handler.md` |
| Zustand optimistische update + rollback | `docs/patterns/zustand-optimistic.md` |
| Float sort_order drag-and-drop | `docs/patterns/sort-order.md` |
| Middleware (route protection) | `docs/patterns/middleware.md` |
| QR-pairing (unauth-SSE + pre-auth cookie) | `docs/patterns/qr-login.md` |
| Bidirectionele async-comms MCP-agent ↔ user | `docs/patterns/claude-question-channel.md` |
| **Entity Dialog (verplicht voor élke create/edit/detail-dialog)** | `docs/patterns/dialog.md` — bron-of-truth; per entiteit één profile-doc (bv. `docs/scrum4me-task-dialog.md`) |
| Status-enum mapping (DB ↔ API) | `lib/task-status.ts` |
| Client/server module-boundary | `*-server.ts` bevat DB-calls of node-only deps; `*.ts` is pure (client-safe). Nooit `import { ... } from '@/lib/foo-server'` in een client-component, anders krijg je `Module not found: 'dns'`/`'pg'`-style runtime fouten |
| iron-session | `docs/patterns/iron-session.md` |
| Prisma singleton | `docs/patterns/prisma-client.md` |
| Server Action (auth + Zod) | `docs/patterns/server-action.md` |
| Route Handler (REST) | `docs/patterns/route-handler.md` |
| Workspace-store + realtime (PBI-74) | `docs/patterns/workspace-store.md` |
| Zustand optimistic update | `docs/patterns/zustand-optimistic.md` |
| Float sort_order / drag-and-drop | `docs/patterns/sort-order.md` |
| Proxy / route protection | `docs/patterns/proxy.md` |
| QR-pairing | `docs/patterns/qr-login.md` |
| Claude ↔ user vraagkanaal | `docs/patterns/claude-question-channel.md` |
| Entity Dialog (verplicht) | `docs/patterns/dialog.md` |
| Realtime NOTIFY-payload | `docs/patterns/realtime-notify-payload.md` |
| Story met UI-component | `docs/patterns/story-with-ui-component.md` |
| Web Push | `docs/patterns/web-push.md` |
| Job-config resolver (PBI-67) | `lib/job-config.ts``scrum4me-mcp/src/lib/job-config.ts` |
| Debug-id op component-root | `docs/patterns/debug-id.md` |
| Debug-labels (BEM) | `docs/patterns/debug-labels.md` |
| Demo client-state (PBI-80) | `docs/patterns/demo-client-state.md` |
---
## Env vars
```bash
DATABASE_URL="" # postgresql://... (verplicht)
DIRECT_URL="" # postgresql://... — pooler-bypass voor LISTEN/NOTIFY (Neon/cloud)
SESSION_SECRET="" # min 32 chars; openssl rand -base64 32
CRON_SECRET="" # M11 — Bearer-secret voor /api/cron/*; verplicht in productie, optioneel lokaal (genereer met openssl rand -base64 32)
DATABASE_URL="" # postgresql://...
DIRECT_URL="" # pooler-bypass voor LISTEN/NOTIFY
SESSION_SECRET="" # min 32 chars
CRON_SECRET="" # Bearer-secret /api/cron/*
```
Volledige Zod-schema in `lib/env.ts`. `.env.example` is de canonieke lijst voor nieuwe checkouts.
Volledig schema: `lib/env.ts`. Canonieke lijst: `.env.example` — bevat ook web-push (`VAPID_*`, `INTERNAL_PUSH_SECRET`), Sentry (`SENTRY_*`) en optioneel `ANTHROPIC_API_KEY`.
---
## Conventies
## MCP & cron
- **Branches:** `feat/ST-001-scaffolding`
- **Server Actions:** altijd in `actions/[domein].ts`, nooit inline in page.tsx
- **Validatie:** altijd Zod, nooit handmatige checks
- **Toegangsmodel:** product-scoped resources gebruiken `productAccessFilter(userId)` tenzij het expliciet een eigenaarsactie is
- **Bulk-ID's:** reorder- en beslissingsacties valideren dat alle meegegeven IDs binnen dezelfde parent-scope vallen voordat er geschreven wordt
- **Foreign keys:** denormalized keys zoals `story.product_id` worden afgeleid uit de database-parent (`pbi.product_id`), nooit uit client-input
- **Demo-check (drie lagen — ST-1110):** write-acties zijn drielaags afgedekt: (1) middleware-guard in `proxy.ts` blokkeert non-GET op `/api/*` voor demo; (2) elke Server Action / Route Handler controleert `session.isDemo` vóór schrijven; (3) write-knoppen in UI zijn `disabled` met `<DemoTooltip show={isDemo}>`. Zie `docs/scrum4me-architecture.md#demo-user-policy` en `docs/plans/ST-1110-demo-readonly.md`
- **Foutberichten:** Nederlands voor eindgebruikers — comments in code: Engels
- **Dependencies:** elke geïmporteerde runtime package staat direct in `dependencies`, niet alleen transitief in `package-lock.json`
- **Docs-sync:** elke gedrags-, dependency-, API- of deploymentwijziging werkt README, relevante docs en patterns bij in dezelfde change
- **Entity codes:** gebruik product/PBI/story-codes in commit-titles wanneer aanwezig (`feat(ST-356.2): ...`); branchnaam blijft `feat/ST-XXX-slug`
- **Status-enums op API:** lowercase (`todo|in_progress|review|done`, `open|in_sprint|done`); DB houdt UPPER_SNAKE; conversie uitsluitend via `lib/task-status.ts`-mappers — nooit ad-hoc `.toLowerCase()` elders
- **Foutcodes API:** `400` alleen voor malformed JSON-body (parse-fout via `request.json()`); `422` voor zod-validatie en well-formed-maar-niet-acceptabel; `403` voor demo-tokens. Documenteer per endpoint in `docs/API.md`
- **Tests volgen contract:** bij een API-contract-wijziging (status, foutcode, response-shape) MOET in dezelfde commit ook `__tests__/api/` mee — een test die rood gaat omdat de oude waarde wordt verwacht is een onvolledige wijziging, niet een "kapotte test"
- **Dev port:** `npm run dev` draait altijd op **3000**. Een `predev`-hook killt vooraf elk proces op 3000 (stale Next.js dev-server, vorige sessie) zodat sessies, cookies en MCP-config consistent op één poort werken. Wijk hier niet van af — geen `-p 3001` o.i.d. tenzij je expliciet twee dev-servers naast elkaar wil draaien
- **MCP-server (extern):** standalone Node-proces in `~/Development/scrum4me-mcp/` — Prisma-schema gesynced via `sync-schema.sh`. 30+ tools (`get_claude_context`, `wait_for_job`, `update_task_status`, …)
- **Bewuste duplicaten:** `lib/job-config.ts` (deze repo) en `scrum4me-mcp/src/lib/job-config.ts` (externe MCP) bevatten dezelfde resolver-logica; dit voorkomt dat de MCP-server Next-deps importeert. **Wijzig beide** bij elke job-config aanpassing
- **Cron (vercel.json):**
- `/api/cron/expire-questions` — dagelijks 04:00 UTC
- `/api/cron/cleanup-agent-artifacts` — dagelijks 03:00 UTC
- **Realtime:** SSE op `/api/realtime/*`, gevoed door PostgreSQL `LISTEN`/`NOTIFY` op kanaal `scrum4me_changes` (vereist `DIRECT_URL` voor pooler-bypass)
---
## Branch & PR Strategy (STRICT — kostenbeheersing)
> **Core rule: één branch per milestone, PR alleen na gebruikerstest**
Elke `git push` naar een feature-branch triggert een Vercel preview-deployment. Op het huidige Hobby-account zijn die schaars en kosten geld; we minimaliseren preview-builds tot er werkelijk iets te reviewen valt.
### Wel doen
- Eén branch voor de hele milestone — `feat/M{N}-{slug}` (bv. `feat/M10-qr-login`); voor losse stories zonder milestone blijft `feat/ST-XXX-{slug}` geldig
- Commits accumuleren lokaal volgens de Commit Strategy hieronder — één commit per stap, ST-code in de titel
- Pushen + PR openen **pas nadat de gebruiker de milestone handmatig heeft getest en goedgekeurd** — vraag expliciet om bevestiging vóór `git push`
- Tussentijdse "klaar voor jouw test"-momenten markeren met een lokale tag of een berichtje in chat, niet met een push
### Niet doen
- Pushen na elke story of commit
- Een PR per story openen tijdens de implementatie
- "Just-in-case" pushen om backup te hebben — gebruik `git stash`, een lokale tag, of meerdere lokale branches
- `--force-push` om eerdere preview-builds "weg te toveren" (kost dezelfde build opnieuw bij hercreatie)
- **Direct pushen naar `main`** — die branch heeft protection rules; gebruik altijd een PR
### Wanneer wel commit-zonder-vragen, wanneer niet
- **Tijdens een directed sprint-flow** (Track A: `mcp__scrum4me__implement_next_story` of een expliciete *"implementeer M{N}"*-opdracht): commit-per-laag conform de Commit Strategy hieronder is impliciet geautoriseerd — niet per commit vragen
- **Bij ad-hoc / out-of-band werk** (bug-fix tussendoor, refactor, kleine wijziging op verzoek): toon de diff + voorgestelde commit-message en wacht op `"commit it"` voordat je `git commit` draait
- **`git push` is altijd expliciet** — de scope van de policy gaat over preview-builds, dus push gebeurt alleen na gebruiker-test, ongeacht commit-context
### Uitzonderingen op de push-regel
- Een **planning-PR** zonder code-wijzigingen (alleen docs in `docs/plans/` of `docs/`) mag direct gepusht worden — die triggert geen functional regressie en is goedkoop te bouwen
- Een **bugfix-hotfix** op `main` met aantoonbare productie-impact mag direct gepusht worden (via een PR — zie boven)
### Wanneer aanpassen
Zodra het Vercel-account naar Pro (of andere omgeving zonder per-build-kosten) gaat: vervang deze regel door "branch + PR per story" zoals oorspronkelijk in dit document stond. Werk deze sectie bij én documenteer de wijziging in `docs/agent-instruction-audit.md`.
---
## Plan Mode
- Voor simpele, goed-afgebakende file-edits: **niet** in plan mode gaan — gewoon de wijziging maken
- Reserveer plan mode voor multi-step refactors, ambigue verzoeken, of milestone-planning waarbij design-keuzes vooraf bevestigd moeten worden
- Plannen die uit plan mode komen: opslaan als `docs/plans/M{N}-{slug}.md` (zie memory `feedback_plan_location`), niet als ephemeral systeem-bestand
---
## Commit Strategy (STRICT)
> **Core rule: één commit = één verantwoordelijkheid**
### Nooit doen
- Database + API + UI in één commit mengen
- Feature + documentatie combineren
- Grote "alles gewijzigd" commits
- Vage berichten zoals "update stuff"
### Verplichte structuur
Splits werk op in logische lagen:
1. Database / Prisma
2. API / server actions
3. UI / components
4. Config / infra
5. Documentatie
### Commit-formaat
```
feat(ST-XXX): korte beschrijving
fix(ST-XXX): korte beschrijving
chore(ST-XXX): korte beschrijving
docs(ST-XXX): korte beschrijving
```
### Voorbeeld (verplicht patroon)
In plaats van:
```bash
feat: add profile system
```
Splits altijd op in:
```bash
feat(ST-XXX): add user profile fields to Prisma schema
feat(ST-XXX): add avatar upload endpoint
feat(ST-XXX): add profile editor component
chore(ST-XXX): configure sharp for avatar processing
docs(ST-XXX): document profile feature
```
---
## Scrum-terminologie
| Correct | Niet gebruiken |
PBI (niet: Feature/Epic) · Story (niet: Ticket) · Sprint Goal (niet: Objective)
---
## Verificatie
```bash
npm run verify && npm run build # verify = lint + typecheck + test
```
Worker job-status protocol (wanneer `DONE` / `SKIPPED` / `FAILED`): zie [docs/runbooks/worker-idempotency.md](./docs/runbooks/worker-idempotency.md).
### Scripts
| Commando | Doel |
|---|---|
| Product Backlog Item (PBI) | Feature, Epic, Issue |
| Story | User Story, Ticket |
| Sprint Goal | Sprint Objective |
| Scrum Team | Team |
| `npm run dev` | Next dev op poort 3000 (`predev` kill-port draait automatisch) |
| `npm test` | Vitest eenmalig (`vitest run`) |
| `npm run test:watch` | Vitest watch-mode |
| `npm test -- <pad>` | Eén bestand draaien — bv. `npm test -- lib/env` |
| `npm run seed` | Prisma seed via `prisma/seed.ts` |
| `npm run create-admin` | Admin-user toevoegen (`scripts/create-admin.ts`) |
| `npm run db:insert-milestone` | Milestone-script (`scripts/insert-milestone.ts`) |
| `npm run db:sync-model-prices` | Sync Anthropic-model-prijzen — vereist `ANTHROPIC_API_KEY` |
| `npm run docs` | Regenereer `docs/INDEX.md` + check links |
| `npm run diagrams` | Mermaid → SVG (`public/diagrams/architecture-{light,dark}.svg`) |
---
## MCP-integratie
Scrum4Me heeft een eigen MCP-server in repo [`madhura68/scrum4me-mcp`](https://github.com/madhura68/scrum4me-mcp) die de REST-API als native tools voor Claude Code aanbiedt. Schema's worden gedeeld via een git submodule (`vendor/scrum4me`), niet gedupliceerd.
### Tools beschikbaar in Claude Code (18)
**Read / context:**
- `mcp__scrum4me__health` — service + DB ping
- `mcp__scrum4me__list_products` — producten waar de tokengebruiker toegang tot heeft
- `mcp__scrum4me__get_claude_context` — bundled product / actieve sprint / next story (met tasks) / open todos
**Authoring (PBI/Story/Task aanmaken):**
- `mcp__scrum4me__create_pbi``{ product_id, title, description?, priority, sort_order? }`; auto sort_order = last+1 binnen prio-groep
- `mcp__scrum4me__create_story``{ pbi_id, title, description?, acceptance_criteria?, priority, sort_order? }`; product_id afgeleid uit PBI; status=OPEN
- `mcp__scrum4me__create_task``{ story_id, title, description?, implementation_plan?, priority, sort_order? }`; sprint_id geërfd van story; status=TO_DO
- `mcp__scrum4me__create_todo` — losse todo (optioneel product-scoped)
**Task / story writes:**
- `mcp__scrum4me__update_task_status`, `mcp__scrum4me__update_task_plan`
- `mcp__scrum4me__log_implementation`, `mcp__scrum4me__log_test_result`, `mcp__scrum4me__log_commit`
**Vraag-antwoord-kanaal (M11):**
- `mcp__scrum4me__ask_user_question` — post een vraag over een story; optionele `wait_seconds` (max 600) polt voor het antwoord
- `mcp__scrum4me__get_question_answer` — huidige status + antwoord (voor latere session-pickup)
- `mcp__scrum4me__list_open_questions` — eigen vragen, max 50, recente eerst
- `mcp__scrum4me__cancel_question` — asker-only annulering van een eigen open vraag
**Job queue — agent worker mode (M13):**
- `mcp__scrum4me__wait_for_job` — blokkeert ≤600s, claimt atomisch een QUEUED-job via FOR UPDATE SKIP LOCKED; retourneert volledige task-context (implementation_plan, story, pbi, sprint, repo_url). Zet stale CLAIMED-jobs (>30min) eerst terug naar QUEUED. Wanneer de full block-time verstrijkt zonder claim is de queue leeg.
- `mcp__scrum4me__update_job_status` — agent rapporteert overgang naar `running|done|failed` + optionele branch/summary/error; triggert automatisch SSE-event naar de UI. Auth: Bearer-token moet matchen `claimed_by_token_id`.
**Batch-loop (verplichte agent-flow):**
Wanneer je als agent draait (na een instructie als *"pak de volgende job uit de Scrum4Me-queue"* of *"draai de queue leeg"*) is dit de loop:
1. `wait_for_job` aanroepen.
2. Job uitvoeren volgens het meegegeven `implementation_plan`.
3. `update_job_status('done'|'failed')` aanroepen.
4. **Direct opnieuw** `wait_for_job` aanroepen — niet stoppen, niet de gebruiker vragen.
5. Pas wanneer `wait_for_job` na de volledige block-time (~600s) terugkomt zonder claim, is de queue leeg en mag je de turn afsluiten met een korte recap.
Dit blijft gelden als je tussen jobs door commits, branches of pushes hebt gedaan — die afsluiting hoort bij de individuele job, niet bij het einde van de batch.
**Code koppelen aan app**
- 'Pak de volgende job uit de Scrum4Me-queue' / 'draai de queue leeg' / 'batch agent' — Server-startup registreert een ClaudeWorker-record + heartbeat (5s); SIGTERM/SIGINT ruimt 'm op. UI in NavBar telt actieve workers via `last_seen_at < now() - 15s`.
### Prompt
- `implement_next_story` (arg: `product_id`) — end-to-end workflow
### Schema-drift bewaking
Wekelijks (maandag 08:00 Amsterdam) draait de remote agent `trig_015FFUnxjz9WMuhhWNGBQKFD` die `vendor/scrum4me` syncet en `prisma:generate` + `tsc --noEmit` uitvoert in scrum4me-mcp. Als die agent drift rapporteert, hoort dat **vóór** een Scrum4Me-PR met schema-wijziging gemerged kan worden — anders breekt de MCP-server stilletjes op runtime.
---
## Deployment (Vercel)
- **Sharp** moet Linux-binaries hebben voor de Vercel-runtime: `npm i --include=optional sharp` of platform-specifieke deps configureren in `package.json`
- **Externe image hostnames** in `next.config.js` `images.remotePatterns` configureren *vóór* `next/image` op die hosts wijst — anders 500 in productie
- **Vercel cron**: Hobby-plan staat alleen daily crons toe (max 1×/dag); Pro ondersteunt fijnmaziger. Bij wijziging van `vercel.json` `crons` ook `docs/API.md` + relevante pattern-docs updaten
- **`CRON_SECRET`** moet als env-var op de Vercel-project-omgeving staan vóór de eerste cron-run, anders 401 op `/api/cron/*`-endpoints
- **Preflight** vóór deploy: `npm run lint && npm test && npm run build` — falende build laat een PR niet door (CI blokkeert merge per ST-610)
---
## Definition of Done (MVP)
M7 (MCP-server) is post-MVP en heeft eigen acceptatie in `docs/scrum4me-backlog.md`.
- [ ] Alle 62 tasks (ST-001 t/m ST-612) afgerond
- [ ] Volledige Lars-flow zonder fouten (ST-612)
- [ ] Alle gedocumenteerde API-endpoints werken via curl (zie `docs/API.md`)
- [ ] Demo-gebruiker heeft geen schrijfrechten
- [ ] App opzetbaar via README zonder extra hulp
- [ ] CI/CD actief — falende build blokkeert merge
- [ ] Beveiligingsreview API geslaagd (cross-user toegang onmogelijk)
- [ ] Documentatie is bijgewerkt voor gewijzigde API's, dependencies, deployment en agent-instructies
> Vitest sluit `.claude/**` uit (relevant voor worktrees). `server-only` wordt via alias gemockt naar `tests/stubs/server-only.ts`, zodat `*-server.ts` modules laadbaar zijn in jsdom-tests.

View file

@ -47,6 +47,13 @@ Scrum4Me biedt een lichtgewicht, web-based oplossing voor het beheren van sprint
- Vercel hosting
- GitHub Actions / CI-CD
## Documentation
- [CHANGELOG.md](CHANGELOG.md) — release-historie (Keep a Changelog)
- [docs/INDEX.md](docs/INDEX.md) — generated index of all docs (front-matter driven)
- [docs/glossary.md](docs/glossary.md) — domain terms (PBI, Story, MCP-job, etc.)
- [CLAUDE.md](CLAUDE.md) / [AGENTS.md](AGENTS.md) — agent instructions
## Architectuur (kort)
- Frontend en backend via Next.js App Router
@ -116,16 +123,12 @@ Vul daarna `DATABASE_URL` en `SESSION_SECRET` in. `DIRECT_URL` is optioneel loka
npx prisma db push
```
4. Genereer Prisma Client en de ERD:
4. Genereer Prisma Client:
```bash
npm run db:erd
npx prisma generate
```
Deze command voert lokaal `prisma generate` uit. Daardoor worden zowel de Prisma Client als `docs/erd.svg` opnieuw opgebouwd.
In CI en deployment wordt bewust alleen de Prisma Client gegenereerd met `prisma generate --generator client`. Het ERD-diagram gebruikt Mermaid/Puppeteer en wordt daarom niet in GitHub Actions of Vercel gegenereerd.
5. Seed testdata indien nodig:
```bash
@ -146,7 +149,7 @@ npm run dev
npm test
```
Verwacht: alle 69 tests slagen, 0 failures.
Verwacht: alle 445 tests slagen, 0 failures.
**API curl-tests (vereist lopende dev server + API token):**
@ -155,23 +158,13 @@ Verwacht: alle 69 tests slagen, 0 failures.
bash scripts/test-api.sh
```
De curl-tests dekken alle 7 API-endpoints: auth (401), demo-blokkering (403), inputvalidatie (400) en happy paths. Zie `docs/scrum4me-test-plan.md` voor het volledige testplan.
De curl-tests dekken alle 7 API-endpoints: auth (401), demo-blokkering (403), inputvalidatie (400) en happy paths. Zie `docs/qa/api-test-plan.md` voor het volledige testplan.
## Database
![ERD](./docs/erd.svg)
Het schema staat in `prisma/schema.prisma`; uitgebreide documentatie in [`docs/architecture/data-model.md`](./docs/architecture/data-model.md).
De databasevisualisatie wordt lokaal gegenereerd uit `prisma/schema.prisma` via `prisma-erd-generator`.
Handmatige generatie:
```bash
npm run db:erd
```
Tijdens lokale development draait `npm run dev` naast Next.js ook `npm run db:erd:watch`. Bij wijzigingen in `prisma/schema.prisma` wordt `docs/erd.svg` automatisch opnieuw gegenereerd.
Gebruik `npx prisma db push` alleen om het schema naar de database te synchroniseren. Gebruik `npm run db:erd` om lokaal Prisma Client en de ERD te genereren. Gebruik in CI uitsluitend `npx prisma generate --generator client`.
Gebruik `npx prisma db push` om schema-wijzigingen naar de database te synchroniseren. `npx prisma generate` (of `prisma generate --generator client` in CI) genereert de Prisma Client.
De app draait standaard op `http://localhost:3000`.
@ -182,7 +175,6 @@ npm run dev # lokale development server
npm run lint # ESLint
npm test # Vitest test suite
npm run build # productiebuild zoals Vercel die verwacht
npm run db:erd # Prisma Client + docs/erd.svg genereren
```
### Environment variables
@ -192,8 +184,15 @@ Zie [.env.example](.env.example).
| Variabele | Verplicht | Doel |
|---|---:|---|
| `DATABASE_URL` | Ja | PostgreSQL connection string voor Prisma |
| `DIRECT_URL` | Nee | Directe Neon connection string voor migraties |
| `DIRECT_URL` | Nee | Directe Neon connection string voor migraties (Prisma `directUrl`) |
| `SESSION_SECRET` | Ja | Minimaal 32 tekens; gebruikt door iron-session |
| `CRON_SECRET` | Productie | Bearer-secret voor `/api/cron/*` routes — required als crons aan staan |
| `NEXT_PUBLIC_VAPID_PUBLIC_KEY` | Nee | VAPID public key voor Web Push — genereer met `npx web-push generate-vapid-keys` |
| `VAPID_PRIVATE_KEY` | Nee | VAPID private key voor Web Push |
| `VAPID_SUBJECT` | Nee | Contact URI voor Web Push (bijv. `mailto:admin@example.com`) |
| `INTERNAL_PUSH_SECRET` | Nee | Bearer-secret voor `/api/internal/push/*` routes (min 32 tekens) |
| `NEXT_PUBLIC_SENTRY_DSN` | Nee | Sentry DSN — zonder is de SDK een no-op |
| `SENTRY_ORG` / `SENTRY_PROJECT` / `SENTRY_AUTH_TOKEN` | Nee | Source-map upload tijdens build |
| `NODE_ENV` | Nee | Wordt door Node/Vercel gezet |
Vercel Analytics gebruikt geen project-specifieke environment variabele in deze app; de component staat in `app/layout.tsx`.
@ -248,13 +247,20 @@ Authorization: Bearer <token>
| Methode | Endpoint | Doel |
|---|---|---|
| `GET` | `/api/health` | Liveness; `?db=1` doet ook een DB-ping (geen auth) |
| `GET` | `/api/products` | Actieve producten waarvoor de tokengebruiker eigenaar of teamlid is |
| `GET` | `/api/products/:id/next-story` | Volgende story uit de actieve sprint |
| `GET` | `/api/products/:id/next-story` | Hoogst geprioriteerde open story uit de actieve sprint |
| `GET` | `/api/products/:id/claude-context` | Bundled product / actieve sprint / next-story (met tasks) / open ideas voor MCP |
| `GET` | `/api/sprints/:id/tasks?limit=10` | Eerste taken van een sprint |
| `PATCH` | `/api/stories/:id/tasks/reorder` | Taakvolgorde aanpassen; alle IDs moeten bij de story horen |
| `POST` | `/api/stories/:id/log` | Implementatieplan, testresultaat of commit vastleggen |
| `PATCH` | `/api/tasks/:id` | Taakstatus of implementatieplan bijwerken |
| `POST` | `/api/todos` | Todo aanmaken binnen een productcontext |
| `PATCH` | `/api/tasks/:id` | Taakstatus of `implementation_plan` bijwerken |
| `GET / POST` | `/api/ideas` · `GET / PATCH /api/ideas/:id` | Idea CRUD (M12 — vervangt voormalige `/api/todos`) |
| `GET` | `/api/jobs/:id/sub-tasks` | `sprint_task_executions` van een SPRINT_IMPLEMENTATION-job |
| `GET` | `/api/users/:id/avatar` | Avatar van een specifieke gebruiker |
| `POST / GET` | `/api/profile/avatar` | Eigen avatar uploaden of opvragen |
Daarnaast leveren `/api/realtime/{backlog,solo,jobs,notifications}` SSE-streams en zijn er auth-helpers `/api/auth/pair/*` (QR-pairing, M10), interne push-routes onder `/api/internal/push/*`, en cron-handlers (`/api/cron/cleanup-agent-artifacts`, `/api/cron/expire-questions`).
### Security-regels
@ -279,7 +285,6 @@ De productieomgeving is gericht op Vercel + Neon.
### Documentatie
- [Functionele specificatie](docs/scrum4me-functional-spec.md)
- [Technische architectuur](docs/scrum4me-architecture.md)
- [Backlog](docs/scrum4me-backlog.md)
- [Agent-instructie audit](docs/agent-instruction-audit.md)
- [Functionele specificatie](docs/specs/functional.md)
- [Technische architectuur](docs/architecture.md)
- [Agent-instructie audit](docs/decisions/agent-instructions-history.md)

View file

@ -0,0 +1,103 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
vi.mock('next/cache', () => ({ revalidatePath: vi.fn() }))
vi.mock('next/headers', () => ({
cookies: vi.fn().mockResolvedValue({
set: vi.fn(),
get: vi.fn(),
delete: vi.fn(),
}),
}))
vi.mock('iron-session', () => ({
getIronSession: vi.fn().mockResolvedValue({ userId: 'user-1', isDemo: false }),
}))
vi.mock('@/lib/session', () => ({
sessionOptions: { cookieName: 'test', password: 'test' },
}))
vi.mock('@/lib/product-access', () => ({
productAccessFilter: vi.fn().mockReturnValue({}),
}))
vi.mock('@/lib/prisma', () => ({
prisma: {
sprint: { findFirst: vi.fn() },
product: { findFirst: vi.fn() },
user: {
findUnique: vi.fn(),
update: vi.fn().mockResolvedValue({}),
},
$executeRaw: vi.fn().mockResolvedValue(1),
},
}))
import { prisma } from '@/lib/prisma'
import { clearActiveSprintAction } from '@/actions/active-sprint'
const mockPrisma = prisma as unknown as {
product: { findFirst: ReturnType<typeof vi.fn> }
user: {
findUnique: ReturnType<typeof vi.fn>
update: ReturnType<typeof vi.fn>
}
}
describe('clearActiveSprintAction', () => {
beforeEach(() => {
vi.clearAllMocks()
})
it('writes null instead of deleting the key', async () => {
mockPrisma.product.findFirst.mockResolvedValueOnce({ id: 'p1' })
mockPrisma.user.findUnique.mockResolvedValueOnce({
settings: { layout: { activeSprints: { p1: 'sprint-1', p2: 'sprint-2' } } },
})
const result = await clearActiveSprintAction('p1')
expect(result).toEqual({ success: true })
const updateArg = mockPrisma.user.update.mock.calls[0][0] as {
data: { settings: { layout?: { activeSprints?: Record<string, string | null> } } }
}
expect(updateArg.data.settings.layout?.activeSprints).toEqual({
p1: null,
p2: 'sprint-2',
})
})
it('preserves other product keys when clearing one', async () => {
mockPrisma.product.findFirst.mockResolvedValueOnce({ id: 'p1' })
mockPrisma.user.findUnique.mockResolvedValueOnce({
settings: {
layout: {
activeSprints: { p1: 'sprint-1', p2: 'sprint-2', p3: null },
},
},
})
await clearActiveSprintAction('p1')
const updateArg = mockPrisma.user.update.mock.calls[0][0] as {
data: { settings: { layout?: { activeSprints?: Record<string, string | null> } } }
}
expect(updateArg.data.settings.layout?.activeSprints).toEqual({
p1: null,
p2: 'sprint-2',
p3: null,
})
})
it('rejects when product is not accessible', async () => {
mockPrisma.product.findFirst.mockResolvedValueOnce(null)
const result = await clearActiveSprintAction('p1')
expect(result).toEqual({ error: 'Product niet gevonden of niet toegankelijk' })
expect(mockPrisma.user.update).not.toHaveBeenCalled()
})
it('rejects invalid productId', async () => {
const result = await clearActiveSprintAction('')
expect(result).toEqual({ error: 'Ongeldig product-id' })
expect(mockPrisma.user.update).not.toHaveBeenCalled()
})
})

View file

@ -0,0 +1,141 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
const {
redirectMock,
verifyUserMock,
headerGetMock,
sessionSaveMock,
requireSessionMock,
prismaUserUpdateMock,
prismaUserRoleFindFirstMock,
} = vi.hoisted(() => ({
redirectMock: vi.fn((path: string) => { throw new Error(`REDIRECT:${path}`) }),
verifyUserMock: vi.fn(),
headerGetMock: vi.fn(),
sessionSaveMock: vi.fn(),
requireSessionMock: vi.fn(),
prismaUserUpdateMock: vi.fn(),
prismaUserRoleFindFirstMock: vi.fn().mockResolvedValue(null),
}))
vi.mock('next/navigation', () => ({ redirect: redirectMock }))
vi.mock('next/headers', () => ({
cookies: vi.fn().mockResolvedValue({}),
headers: vi.fn().mockResolvedValue({ get: headerGetMock }),
}))
vi.mock('iron-session', () => ({
getIronSession: vi.fn().mockResolvedValue({
userId: '',
isDemo: false,
save: sessionSaveMock,
}),
}))
vi.mock('@/lib/session', () => ({ sessionOptions: { cookieName: 't', password: 't' } }))
vi.mock('@/lib/auth', () => ({
verifyUser: verifyUserMock,
registerUser: vi.fn(),
hashPassword: vi.fn().mockResolvedValue('hashed'),
}))
vi.mock('@/lib/auth-guard', () => ({ requireSession: requireSessionMock }))
vi.mock('@/lib/prisma', () => ({
prisma: {
user: { update: prismaUserUpdateMock },
userRole: { findFirst: prismaUserRoleFindFirstMock },
},
}))
vi.mock('@/lib/rate-limit', () => ({ checkRateLimit: vi.fn().mockReturnValue(true) }))
import { loginAction, resetPasswordAction } from '@/actions/auth'
const IPHONE_UA = 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_4 like Mac OS X) Mobile/15E148 Safari/604.1'
const IPAD_UA = 'Mozilla/5.0 (iPad; CPU OS 17_4 like Mac OS X) Safari/604.1'
const DESKTOP_UA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 14_4) Chrome/124.0.0.0 Safari/537.36'
function fd(username: string, password: string) {
const f = new FormData()
f.set('username', username)
f.set('password', password)
return f
}
beforeEach(() => {
redirectMock.mockClear()
verifyUserMock.mockReset()
headerGetMock.mockReset()
sessionSaveMock.mockReset()
requireSessionMock.mockReset()
prismaUserUpdateMock.mockReset()
prismaUserRoleFindFirstMock.mockResolvedValue(null)
})
describe('loginAction UA-redirect', () => {
it('phone-UA + actief product → /m/products/[id]/solo', async () => {
verifyUserMock.mockResolvedValue({ id: 'u1', is_demo: false, active_product_id: 'p1' })
headerGetMock.mockReturnValue(IPHONE_UA)
await expect(loginAction(undefined, fd('alice', 'secret123'))).rejects.toThrow('REDIRECT:/m/products/p1/solo')
})
it('phone-UA zonder actief product → /m/settings', async () => {
verifyUserMock.mockResolvedValue({ id: 'u1', is_demo: false, active_product_id: null })
headerGetMock.mockReturnValue(IPHONE_UA)
await expect(loginAction(undefined, fd('alice', 'secret123'))).rejects.toThrow('REDIRECT:/m/settings')
})
it('tablet-UA (iPad) → /dashboard', async () => {
verifyUserMock.mockResolvedValue({ id: 'u1', is_demo: false, active_product_id: 'p1' })
headerGetMock.mockReturnValue(IPAD_UA)
await expect(loginAction(undefined, fd('alice', 'secret123'))).rejects.toThrow('REDIRECT:/dashboard')
})
it('desktop-UA → /dashboard', async () => {
verifyUserMock.mockResolvedValue({ id: 'u1', is_demo: false, active_product_id: 'p1' })
headerGetMock.mockReturnValue(DESKTOP_UA)
await expect(loginAction(undefined, fd('alice', 'secret123'))).rejects.toThrow('REDIRECT:/dashboard')
})
it('geen UA-header → /dashboard', async () => {
verifyUserMock.mockResolvedValue({ id: 'u1', is_demo: false, active_product_id: 'p1' })
headerGetMock.mockReturnValue(null)
await expect(loginAction(undefined, fd('alice', 'secret123'))).rejects.toThrow('REDIRECT:/dashboard')
})
it('demo-user op phone volgt dezelfde routing', async () => {
verifyUserMock.mockResolvedValue({ id: 'demo', is_demo: true, active_product_id: 'p1' })
headerGetMock.mockReturnValue(IPHONE_UA)
await expect(loginAction(undefined, fd('demo', 'demo123pw'))).rejects.toThrow('REDIRECT:/m/products/p1/solo')
})
})
describe('resetPasswordAction', () => {
function fdReset(password: string, confirm: string) {
const f = new FormData()
f.set('password', password)
f.set('confirm', confirm)
return f
}
it('redirect /dashboard na succesvolle reset', async () => {
requireSessionMock.mockResolvedValue({ userId: 'u1' })
prismaUserUpdateMock.mockResolvedValue({})
await expect(resetPasswordAction(undefined, fdReset('nieuwpass1', 'nieuwpass1'))).rejects.toThrow('REDIRECT:/dashboard')
expect(prismaUserUpdateMock).toHaveBeenCalledWith(
expect.objectContaining({
where: { id: 'u1' },
data: expect.objectContaining({ password_hash: 'hashed', must_reset_password: false }),
})
)
})
it('fout als wachtwoorden niet overeenkomen', async () => {
requireSessionMock.mockResolvedValue({ userId: 'u1' })
const result = await resetPasswordAction(undefined, fdReset('nieuwpass1', 'anderpass1'))
expect(result).toMatchObject({ error: expect.objectContaining({ confirm: expect.any(Array) }) })
expect(prismaUserUpdateMock).not.toHaveBeenCalled()
})
it('fout als wachtwoord te kort is', async () => {
requireSessionMock.mockResolvedValue({ userId: 'u1' })
const result = await resetPasswordAction(undefined, fdReset('kort', 'kort'))
expect(result).toMatchObject({ error: expect.objectContaining({ password: expect.any(Array) }) })
})
})

View file

@ -0,0 +1,29 @@
/**
* Per-task batch enqueue is gedeprecateerd ten gunste van startSprintRunAction
* (zie actions/sprint-runs.ts). De functies blijven exporteerbaar als stub voor
* backwards-compat met UI-componenten die in F4 worden vervangen.
*/
import { describe, it, expect, vi } from 'vitest'
vi.mock('next/cache', () => ({ revalidatePath: vi.fn() }))
vi.mock('@/lib/auth', () => ({ getSession: vi.fn() }))
vi.mock('@/lib/prisma', () => ({ prisma: {} }))
import {
previewEnqueueAllAction,
enqueueClaudeJobsBatchAction,
} from '@/actions/claude-jobs'
describe('previewEnqueueAllAction (deprecated)', () => {
it('retourneert een deprecation-error', async () => {
const result = await previewEnqueueAllAction('prod-1')
expect(result).toMatchObject({ error: expect.stringContaining('vervangen') })
})
})
describe('enqueueClaudeJobsBatchAction (deprecated)', () => {
it('retourneert een deprecation-error', async () => {
const result = await enqueueClaudeJobsBatchAction('prod-1', ['t1', 't2'])
expect(result).toMatchObject({ error: expect.stringContaining('Start Sprint') })
})
})

View file

@ -1,47 +1,46 @@
/**
* Per-task enqueue-acties zijn gedeprecateerd. cancelClaudeJobAction blijft
* actief gebruikt voor het annuleren van losse jobs (bv. idea-jobs).
*/
import { describe, it, expect, vi, beforeEach } from 'vitest'
const {
mockGetSession,
mockFindFirstTask,
mockFindManyTask,
mockFindFirstProduct,
mockFindFirstSprint,
mockFindFirstJob,
mockCreateJob,
mockUpdateJob,
mockExecuteRaw,
mockUpdateManyJob,
mockUpdateManySprintTaskExecution,
mockTransaction,
} = vi.hoisted(() => ({
mockGetSession: vi.fn(),
mockFindFirstTask: vi.fn(),
mockFindManyTask: vi.fn(),
mockFindFirstProduct: vi.fn(),
mockFindFirstSprint: vi.fn(),
mockFindFirstJob: vi.fn(),
mockCreateJob: vi.fn(),
mockUpdateJob: vi.fn(),
mockExecuteRaw: vi.fn().mockResolvedValue(undefined),
mockTransaction: vi.fn(),
}))
mockExecuteRaw,
} = vi.hoisted(() => {
const mockUpdateManyJob = vi.fn()
const mockUpdateManySprintTaskExecution = vi.fn()
const mockTransaction = vi.fn()
return {
mockGetSession: vi.fn(),
mockFindFirstJob: vi.fn(),
mockUpdateJob: vi.fn(),
mockUpdateManyJob,
mockUpdateManySprintTaskExecution,
mockTransaction,
mockExecuteRaw: vi.fn().mockResolvedValue(undefined),
}
})
vi.mock('next/cache', () => ({ revalidatePath: vi.fn() }))
vi.mock('@/lib/auth', () => ({
getSession: mockGetSession,
}))
vi.mock('@/lib/auth', () => ({ getSession: mockGetSession }))
vi.mock('@/lib/prisma', () => ({
prisma: {
task: { findFirst: mockFindFirstTask, findMany: mockFindManyTask },
product: { findFirst: mockFindFirstProduct },
sprint: { findFirst: mockFindFirstSprint },
claudeJob: {
findFirst: mockFindFirstJob,
create: mockCreateJob,
update: mockUpdateJob,
updateMany: mockUpdateManyJob,
},
sprintTaskExecution: {
updateMany: mockUpdateManySprintTaskExecution,
},
$executeRaw: mockExecuteRaw,
$transaction: mockTransaction,
$executeRaw: mockExecuteRaw,
},
}))
@ -49,202 +48,194 @@ import {
enqueueClaudeJobAction,
enqueueAllTodoJobsAction,
cancelClaudeJobAction,
restartClaudeJobAction,
} from '@/actions/claude-jobs'
const SESSION_USER = { userId: 'user-1', isDemo: false }
const SESSION_DEMO = { userId: 'demo-1', isDemo: true }
const TASK_ID = 'task-cuid-1'
const JOB_ID = 'job-cuid-1'
const PRODUCT_ID = 'product-cuid-1'
const MOCK_TASK = { id: TASK_ID, story: { product_id: PRODUCT_ID } }
const MOCK_JOB_QUEUED = { id: JOB_ID, status: 'QUEUED' as const, task_id: TASK_ID, product_id: PRODUCT_ID }
beforeEach(() => {
vi.clearAllMocks()
mockExecuteRaw.mockResolvedValue(undefined)
mockTransaction.mockImplementation(async (fn: (tx: unknown) => Promise<unknown>) =>
fn({
claudeJob: { updateMany: mockUpdateManyJob },
sprintTaskExecution: { updateMany: mockUpdateManySprintTaskExecution },
})
)
})
describe('enqueueClaudeJobAction', () => {
it('happy path: creates job with QUEUED status', async () => {
mockGetSession.mockResolvedValue(SESSION_USER)
mockFindFirstTask.mockResolvedValue(MOCK_TASK)
mockFindFirstJob.mockResolvedValue(null)
mockCreateJob.mockResolvedValue({ id: JOB_ID })
const result = await enqueueClaudeJobAction(TASK_ID)
expect(result).toEqual({ success: true, jobId: JOB_ID })
expect(mockCreateJob).toHaveBeenCalledWith(
expect.objectContaining({ data: expect.objectContaining({ status: 'QUEUED', task_id: TASK_ID }) })
)
})
it('blocks demo user', async () => {
mockGetSession.mockResolvedValue(SESSION_DEMO)
const result = await enqueueClaudeJobAction(TASK_ID)
expect(result).toMatchObject({ error: 'Niet beschikbaar in demo-modus' })
expect(mockCreateJob).not.toHaveBeenCalled()
})
it('returns error when task not found', async () => {
mockGetSession.mockResolvedValue(SESSION_USER)
mockFindFirstTask.mockResolvedValue(null)
const result = await enqueueClaudeJobAction(TASK_ID)
expect(result).toMatchObject({ error: 'Task niet gevonden' })
expect(mockCreateJob).not.toHaveBeenCalled()
})
it('idempotency: returns existing jobId when QUEUED job exists', async () => {
mockGetSession.mockResolvedValue(SESSION_USER)
mockFindFirstTask.mockResolvedValue(MOCK_TASK)
mockFindFirstJob.mockResolvedValue({ id: JOB_ID })
const result = await enqueueClaudeJobAction(TASK_ID)
expect(result).toMatchObject({ error: 'Er loopt al een agent voor deze task', jobId: JOB_ID })
expect(mockCreateJob).not.toHaveBeenCalled()
})
it('allows new enqueue after terminal (DONE) job', async () => {
mockGetSession.mockResolvedValue(SESSION_USER)
mockFindFirstTask.mockResolvedValue(MOCK_TASK)
mockFindFirstJob.mockResolvedValue(null) // no active job
mockCreateJob.mockResolvedValue({ id: 'new-job-id' })
const result = await enqueueClaudeJobAction(TASK_ID)
expect(result).toEqual({ success: true, jobId: 'new-job-id' })
describe('enqueueClaudeJobAction (deprecated)', () => {
it('retourneert een deprecation-error', async () => {
const result = await enqueueClaudeJobAction('task-1')
expect(result).toMatchObject({ error: expect.stringContaining('Start Sprint') })
})
})
describe('enqueueAllTodoJobsAction', () => {
it('happy path: scopes to active sprint + assignee, queues all queueable tasks', async () => {
mockGetSession.mockResolvedValue(SESSION_USER)
mockFindFirstProduct.mockResolvedValue({ id: PRODUCT_ID })
mockFindFirstSprint.mockResolvedValue({ id: 'sprint-1' })
mockFindManyTask.mockResolvedValue([{ id: 'task-a' }, { id: 'task-b' }])
mockTransaction.mockResolvedValue([
{ id: 'job-a', task_id: 'task-a' },
{ id: 'job-b', task_id: 'task-b' },
])
const result = await enqueueAllTodoJobsAction(PRODUCT_ID)
expect(result).toEqual({ success: true, count: 2 })
expect(mockFindManyTask).toHaveBeenCalledWith(
expect.objectContaining({
where: expect.objectContaining({
status: 'TO_DO',
story: { sprint_id: 'sprint-1', assignee_id: SESSION_USER.userId },
}),
})
)
expect(mockExecuteRaw).toHaveBeenCalledTimes(2)
})
it('returns count=0 when product has no active sprint', async () => {
mockGetSession.mockResolvedValue(SESSION_USER)
mockFindFirstProduct.mockResolvedValue({ id: PRODUCT_ID })
mockFindFirstSprint.mockResolvedValue(null)
const result = await enqueueAllTodoJobsAction(PRODUCT_ID)
expect(result).toEqual({ success: true, count: 0 })
expect(mockFindManyTask).not.toHaveBeenCalled()
expect(mockTransaction).not.toHaveBeenCalled()
})
it('returns count=0 when no queueable tasks in sprint+assignee scope', async () => {
mockGetSession.mockResolvedValue(SESSION_USER)
mockFindFirstProduct.mockResolvedValue({ id: PRODUCT_ID })
mockFindFirstSprint.mockResolvedValue({ id: 'sprint-1' })
mockFindManyTask.mockResolvedValue([])
const result = await enqueueAllTodoJobsAction(PRODUCT_ID)
expect(result).toEqual({ success: true, count: 0 })
expect(mockTransaction).not.toHaveBeenCalled()
expect(mockExecuteRaw).not.toHaveBeenCalled()
})
it('blocks demo user', async () => {
mockGetSession.mockResolvedValue(SESSION_DEMO)
const result = await enqueueAllTodoJobsAction(PRODUCT_ID)
expect(result).toMatchObject({ error: 'Niet beschikbaar in demo-modus' })
expect(mockTransaction).not.toHaveBeenCalled()
})
it('returns error when product not accessible', async () => {
mockGetSession.mockResolvedValue(SESSION_USER)
mockFindFirstProduct.mockResolvedValue(null)
const result = await enqueueAllTodoJobsAction(PRODUCT_ID)
expect(result).toMatchObject({ error: 'Geen toegang tot dit product' })
expect(mockTransaction).not.toHaveBeenCalled()
describe('enqueueAllTodoJobsAction (deprecated)', () => {
it('retourneert een deprecation-error', async () => {
const result = await enqueueAllTodoJobsAction('prod-1')
expect(result).toMatchObject({ error: expect.stringContaining('Start Sprint') })
})
})
describe('cancelClaudeJobAction', () => {
it('happy path: cancels QUEUED job', async () => {
it('cancelt een actieve job', async () => {
mockGetSession.mockResolvedValue(SESSION_USER)
mockFindFirstJob.mockResolvedValue(MOCK_JOB_QUEUED)
mockUpdateJob.mockResolvedValue({})
mockFindFirstJob.mockResolvedValue({
id: 'job-1',
status: 'QUEUED',
task_id: 'task-1',
product_id: 'prod-1',
})
mockUpdateJob.mockResolvedValue(undefined)
const result = await cancelClaudeJobAction(JOB_ID)
const result = await cancelClaudeJobAction('job-1')
expect(result).toEqual({ success: true })
expect(mockUpdateJob).toHaveBeenCalledWith(
expect(mockUpdateJob).toHaveBeenCalledWith({
where: { id: 'job-1' },
data: expect.objectContaining({ status: 'CANCELLED' }),
})
})
it('weigert demo-sessie', async () => {
mockGetSession.mockResolvedValue({ userId: 'demo', isDemo: true })
const result = await cancelClaudeJobAction('job-1')
expect(result).toMatchObject({ error: expect.stringContaining('demo') })
expect(mockUpdateJob).not.toHaveBeenCalled()
})
it('retourneert error als job niet gevonden', async () => {
mockGetSession.mockResolvedValue(SESSION_USER)
mockFindFirstJob.mockResolvedValue(null)
const result = await cancelClaudeJobAction('nonexistent')
expect(result).toMatchObject({ error: expect.stringContaining('niet gevonden') })
})
it('weigert wanneer job niet meer actief is', async () => {
mockGetSession.mockResolvedValue(SESSION_USER)
mockFindFirstJob.mockResolvedValue({
id: 'job-1',
status: 'DONE',
task_id: 'task-1',
product_id: 'prod-1',
})
const result = await cancelClaudeJobAction('job-1')
expect(result).toMatchObject({ error: expect.stringContaining('actieve') })
})
})
describe('restartClaudeJobAction', () => {
const FAILED_JOB = {
id: 'job-1',
status: 'FAILED',
kind: 'TASK_IMPLEMENTATION',
task_id: 'task-1',
idea_id: null,
sprint_run_id: null,
product_id: 'prod-1',
}
it('reset een FAILED job naar QUEUED (happy path)', async () => {
mockGetSession.mockResolvedValue(SESSION_USER)
mockFindFirstJob.mockResolvedValue(FAILED_JOB)
mockUpdateManyJob.mockResolvedValue({ count: 1 })
const result = await restartClaudeJobAction('job-1')
expect(result).toEqual({ success: true })
expect(mockUpdateManyJob).toHaveBeenCalledWith(
expect.objectContaining({
where: { id: JOB_ID },
data: expect.objectContaining({ status: 'CANCELLED' }),
where: expect.objectContaining({ id: 'job-1', status: { in: ['FAILED', 'CANCELLED', 'SKIPPED'] } }),
data: expect.objectContaining({ status: 'QUEUED' }),
})
)
expect(mockExecuteRaw).toHaveBeenCalled()
})
it('reset een CANCELLED job naar QUEUED', async () => {
mockGetSession.mockResolvedValue(SESSION_USER)
mockFindFirstJob.mockResolvedValue({ ...FAILED_JOB, status: 'CANCELLED' })
mockUpdateManyJob.mockResolvedValue({ count: 1 })
const result = await restartClaudeJobAction('job-1')
expect(result).toEqual({ success: true })
})
it('reset een SKIPPED job naar QUEUED', async () => {
mockGetSession.mockResolvedValue(SESSION_USER)
mockFindFirstJob.mockResolvedValue({ ...FAILED_JOB, status: 'SKIPPED' })
mockUpdateManyJob.mockResolvedValue({ count: 1 })
const result = await restartClaudeJobAction('job-1')
expect(result).toEqual({ success: true })
})
it('weigert demo-sessie', async () => {
mockGetSession.mockResolvedValue({ userId: 'demo', isDemo: true })
const result = await restartClaudeJobAction('job-1')
expect(result).toMatchObject({ error: expect.stringContaining('demo') })
expect(mockUpdateManyJob).not.toHaveBeenCalled()
})
it('retourneert error als job niet gevonden', async () => {
mockGetSession.mockResolvedValue(SESSION_USER)
mockFindFirstJob.mockResolvedValue(null)
const result = await restartClaudeJobAction('job-1')
expect(result).toMatchObject({ error: expect.stringContaining('niet gevonden') })
})
it('weigert wanneer job een niet-restartbare status heeft', async () => {
mockGetSession.mockResolvedValue(SESSION_USER)
mockFindFirstJob.mockResolvedValue({ ...FAILED_JOB, status: 'DONE' })
const result = await restartClaudeJobAction('job-1')
expect(result).toMatchObject({ error: expect.stringContaining('mislukte') })
expect(mockUpdateManyJob).not.toHaveBeenCalled()
})
it('retourneert error bij race-conditie (updateMany count === 0)', async () => {
mockGetSession.mockResolvedValue(SESSION_USER)
mockFindFirstJob.mockResolvedValue(FAILED_JOB)
mockUpdateManyJob.mockResolvedValue({ count: 0 })
const result = await restartClaudeJobAction('job-1')
expect(result).toMatchObject({ error: expect.stringContaining('gewijzigd') })
})
it('reset ook SprintTaskExecution-rows bij SPRINT_IMPLEMENTATION', async () => {
mockGetSession.mockResolvedValue(SESSION_USER)
mockFindFirstJob.mockResolvedValue({
...FAILED_JOB,
kind: 'SPRINT_IMPLEMENTATION',
sprint_run_id: 'run-1',
})
mockUpdateManyJob.mockResolvedValue({ count: 1 })
mockUpdateManySprintTaskExecution.mockResolvedValue({ count: 3 })
const result = await restartClaudeJobAction('job-1')
expect(result).toEqual({ success: true })
expect(mockUpdateManySprintTaskExecution).toHaveBeenCalledWith(
expect.objectContaining({
where: { sprint_job_id: 'job-1' },
data: expect.objectContaining({ status: 'PENDING' }),
})
)
})
it('demo user is blocked', async () => {
mockGetSession.mockResolvedValue(SESSION_DEMO)
const result = await cancelClaudeJobAction(JOB_ID)
expect(result).toMatchObject({ error: 'Niet beschikbaar in demo-modus' })
expect(mockUpdateJob).not.toHaveBeenCalled()
})
it('returns error when job not found (ownership check)', async () => {
it('reset geen SprintTaskExecution-rows bij TASK_IMPLEMENTATION', async () => {
mockGetSession.mockResolvedValue(SESSION_USER)
mockFindFirstJob.mockResolvedValue(null)
mockFindFirstJob.mockResolvedValue(FAILED_JOB)
mockUpdateManyJob.mockResolvedValue({ count: 1 })
const result = await cancelClaudeJobAction(JOB_ID)
await restartClaudeJobAction('job-1')
expect(result).toMatchObject({ error: 'Job niet gevonden' })
expect(mockUpdateJob).not.toHaveBeenCalled()
})
it('returns error when cancelling terminal (DONE) job', async () => {
mockGetSession.mockResolvedValue(SESSION_USER)
mockFindFirstJob.mockResolvedValue({ ...MOCK_JOB_QUEUED, status: 'DONE' as const })
const result = await cancelClaudeJobAction(JOB_ID)
expect(result).toMatchObject({ error: 'Alleen actieve jobs kunnen geannuleerd worden' })
expect(mockUpdateJob).not.toHaveBeenCalled()
})
it('returns error when cancelling FAILED job', async () => {
mockGetSession.mockResolvedValue(SESSION_USER)
mockFindFirstJob.mockResolvedValue({ ...MOCK_JOB_QUEUED, status: 'FAILED' as const })
const result = await cancelClaudeJobAction(JOB_ID)
expect(result).toMatchObject({ error: 'Alleen actieve jobs kunnen geannuleerd worden' })
expect(mockUpdateManySprintTaskExecution).not.toHaveBeenCalled()
})
})

View file

@ -0,0 +1,290 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
vi.mock('next/cache', () => ({ revalidatePath: vi.fn() }))
vi.mock('next/headers', () => ({
cookies: vi.fn().mockResolvedValue({
set: vi.fn(),
get: vi.fn(),
delete: vi.fn(),
}),
}))
vi.mock('iron-session', () => ({
getIronSession: vi.fn().mockResolvedValue({ userId: 'user-1', isDemo: false }),
}))
vi.mock('@/lib/session', () => ({
sessionOptions: { cookieName: 'test', password: 'test' },
}))
vi.mock('@/lib/product-access', () => ({
productAccessFilter: vi.fn().mockReturnValue({}),
getAccessibleProduct: vi.fn().mockResolvedValue({ id: 'product-1' }),
}))
vi.mock('@/lib/rate-limit', () => ({
enforceUserRateLimit: vi.fn().mockReturnValue(null),
}))
vi.mock('@/lib/code-server', () => ({
createWithCodeRetry: vi.fn(),
generateNextSprintCode: vi.fn(),
}))
vi.mock('@/lib/active-sprint', () => ({
setActiveSprintInSettings: vi.fn().mockResolvedValue(undefined),
}))
vi.mock('@/lib/prisma', () => {
const txClient = {
sprint: { create: vi.fn() },
story: { updateMany: vi.fn() },
task: { updateMany: vi.fn() },
}
return {
prisma: {
sprint: { findFirst: vi.fn() },
story: {
findMany: vi.fn(),
updateMany: vi.fn(),
},
task: {
findMany: vi.fn(),
updateMany: vi.fn(),
},
$transaction: vi.fn(async (fn: (tx: typeof txClient) => unknown) => fn(txClient)),
__txClient: txClient,
},
}
})
import { prisma } from '@/lib/prisma'
import { commitSprintMembershipAction } from '@/actions/sprints'
type Mocked = {
sprint: { findFirst: ReturnType<typeof vi.fn> }
story: {
findMany: ReturnType<typeof vi.fn>
updateMany: ReturnType<typeof vi.fn>
}
task: {
findMany: ReturnType<typeof vi.fn>
updateMany: ReturnType<typeof vi.fn>
}
$transaction: ReturnType<typeof vi.fn>
__txClient: {
sprint: { create: ReturnType<typeof vi.fn> }
story: { updateMany: ReturnType<typeof vi.fn> }
task: { updateMany: ReturnType<typeof vi.fn> }
}
}
const mockPrisma = prisma as unknown as Mocked
beforeEach(() => {
vi.clearAllMocks()
mockPrisma.sprint.findFirst.mockReset().mockResolvedValue({
id: 'sprint-active',
product_id: 'product-1',
})
mockPrisma.story.findMany.mockReset()
mockPrisma.story.updateMany.mockReset()
mockPrisma.task.findMany.mockReset()
mockPrisma.task.updateMany.mockReset()
mockPrisma.$transaction.mockImplementation(
async (fn: (tx: typeof mockPrisma.__txClient) => unknown) =>
fn(mockPrisma.__txClient),
)
mockPrisma.__txClient.story.updateMany.mockReset().mockResolvedValue({ count: 0 })
mockPrisma.__txClient.task.updateMany.mockReset().mockResolvedValue({ count: 0 })
})
describe('commitSprintMembershipAction', () => {
it('happy path: eligible adds + valid removes → transactie commits', async () => {
// adds-partition: alle eligible (sprint_id=null + niet DONE)
mockPrisma.story.findMany
// partition lookup
.mockResolvedValueOnce([
{ id: 's-add-1', sprint_id: null, status: 'OPEN', sprint: null },
])
// removes-filter (sprint_id == activeSprintId)
.mockResolvedValueOnce([{ id: 's-rem-1' }])
// affectedStories
.mockResolvedValueOnce([
{ pbi_id: 'pbiA' },
{ pbi_id: 'pbiB' },
])
mockPrisma.task.findMany.mockResolvedValueOnce([{ id: 't1' }])
const result = await commitSprintMembershipAction({
activeSprintId: 'sprint-active',
adds: ['s-add-1'],
removes: ['s-rem-1'],
})
expect('success' in result).toBe(true)
if ('success' in result) {
expect(result.affectedStoryIds.sort()).toEqual(['s-add-1', 's-rem-1'])
expect(result.affectedPbiIds.sort()).toEqual(['pbiA', 'pbiB'])
expect(result.affectedTaskIds).toEqual(['t1'])
expect(result.conflicts.notEligible).toEqual([])
expect(result.conflicts.alreadyRemoved).toEqual([])
}
expect(mockPrisma.$transaction).toHaveBeenCalledTimes(1)
expect(mockPrisma.__txClient.story.updateMany).toHaveBeenCalledTimes(2)
expect(mockPrisma.__txClient.task.updateMany).toHaveBeenCalledTimes(2)
})
it('add met status=DONE → conflicts.notEligible, story niet ge-update', async () => {
mockPrisma.story.findMany
.mockResolvedValueOnce([
{ id: 's-done', sprint_id: null, status: 'DONE', sprint: null },
])
// removes-filter (geen removes)
.mockResolvedValueOnce([])
const result = await commitSprintMembershipAction({
activeSprintId: 'sprint-active',
adds: ['s-done'],
removes: [],
})
expect('success' in result).toBe(true)
if ('success' in result) {
expect(result.affectedStoryIds).toEqual([])
expect(result.conflicts.notEligible).toEqual([
{ storyId: 's-done', reason: 'DONE' },
])
}
// Geen transaction omdat er niets te commiten valt.
expect(mockPrisma.$transaction).not.toHaveBeenCalled()
})
it('add met sprint_id in andere OPEN sprint → conflicts.notEligible IN_OTHER_SPRINT', async () => {
mockPrisma.story.findMany
.mockResolvedValueOnce([
{
id: 's-elsewhere',
sprint_id: 'sprint-other',
status: 'IN_SPRINT',
sprint: { id: 'sprint-other', code: 'SP-O', status: 'OPEN' },
},
])
.mockResolvedValueOnce([])
const result = await commitSprintMembershipAction({
activeSprintId: 'sprint-active',
adds: ['s-elsewhere'],
removes: [],
})
if ('success' in result) {
expect(result.conflicts.notEligible).toEqual([
{ storyId: 's-elsewhere', reason: 'IN_OTHER_SPRINT' },
])
}
})
it('remove voor story die niet in actieve sprint zit → conflicts.alreadyRemoved', async () => {
mockPrisma.story.findMany
// adds-partition (geen adds)
.mockResolvedValueOnce([])
// removes-filter — race scenario: story zit niet meer in active sprint
.mockResolvedValueOnce([])
const result = await commitSprintMembershipAction({
activeSprintId: 'sprint-active',
adds: [],
removes: ['s-was-removed'],
})
if ('success' in result) {
expect(result.affectedStoryIds).toEqual([])
expect(result.conflicts.alreadyRemoved).toEqual(['s-was-removed'])
}
})
it('transactie: story.status=IN_SPRINT bij add, =OPEN bij remove', async () => {
mockPrisma.story.findMany
.mockResolvedValueOnce([
{ id: 's-add', sprint_id: null, status: 'OPEN', sprint: null },
])
.mockResolvedValueOnce([{ id: 's-rem' }])
.mockResolvedValueOnce([{ pbi_id: 'pbiA' }])
mockPrisma.task.findMany.mockResolvedValueOnce([])
await commitSprintMembershipAction({
activeSprintId: 'sprint-active',
adds: ['s-add'],
removes: ['s-rem'],
})
const calls = mockPrisma.__txClient.story.updateMany.mock.calls
// Add: status=IN_SPRINT + sprint_id=sprint-active
expect(calls[0][0].data).toEqual({
sprint_id: 'sprint-active',
status: 'IN_SPRINT',
})
// Remove: status=OPEN + sprint_id=null
expect(calls[1][0].data).toEqual({ sprint_id: null, status: 'OPEN' })
})
it('task.sprint_id wordt in dezelfde transactie ge-update', async () => {
mockPrisma.story.findMany
.mockResolvedValueOnce([
{ id: 's-add', sprint_id: null, status: 'OPEN', sprint: null },
])
.mockResolvedValueOnce([])
.mockResolvedValueOnce([{ pbi_id: 'pbiA' }])
mockPrisma.task.findMany.mockResolvedValueOnce([])
await commitSprintMembershipAction({
activeSprintId: 'sprint-active',
adds: ['s-add'],
removes: [],
})
expect(mockPrisma.__txClient.task.updateMany).toHaveBeenCalledWith(
expect.objectContaining({
where: { story_id: { in: ['s-add'] } },
data: { sprint_id: 'sprint-active' },
}),
)
})
it('return: affectedStoryIds + affectedPbiIds + affectedTaskIds + conflicts', async () => {
mockPrisma.story.findMany
.mockResolvedValueOnce([
{ id: 's-add', sprint_id: null, status: 'OPEN', sprint: null },
])
.mockResolvedValueOnce([{ id: 's-rem' }])
.mockResolvedValueOnce([
{ pbi_id: 'pbiA' },
{ pbi_id: 'pbiB' },
])
mockPrisma.task.findMany.mockResolvedValueOnce([
{ id: 't1' },
{ id: 't2' },
])
const result = await commitSprintMembershipAction({
activeSprintId: 'sprint-active',
adds: ['s-add'],
removes: ['s-rem'],
})
expect(result).toMatchObject({
success: true,
affectedStoryIds: expect.arrayContaining(['s-add', 's-rem']),
affectedPbiIds: expect.arrayContaining(['pbiA', 'pbiB']),
affectedTaskIds: expect.arrayContaining(['t1', 't2']),
})
})
it('rejects when sprint is not accessible', async () => {
mockPrisma.sprint.findFirst.mockResolvedValue(null)
const result = await commitSprintMembershipAction({
activeSprintId: 'sprint-active',
adds: [],
removes: [],
})
expect('error' in result).toBe(true)
if ('error' in result) {
expect(result.code).toBe(403)
}
})
})

View file

@ -0,0 +1,300 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
vi.mock('next/cache', () => ({ revalidatePath: vi.fn() }))
vi.mock('next/headers', () => ({
cookies: vi.fn().mockResolvedValue({
set: vi.fn(),
get: vi.fn(),
delete: vi.fn(),
}),
}))
vi.mock('iron-session', () => ({
getIronSession: vi.fn().mockResolvedValue({ userId: 'user-1', isDemo: false }),
}))
vi.mock('@/lib/session', () => ({
sessionOptions: { cookieName: 'test', password: 'test' },
}))
vi.mock('@/lib/product-access', () => ({
productAccessFilter: vi.fn().mockReturnValue({}),
getAccessibleProduct: vi.fn().mockResolvedValue({
id: 'product-1',
user_id: 'user-1',
}),
}))
vi.mock('@/lib/rate-limit', () => ({
enforceUserRateLimit: vi.fn().mockReturnValue(null),
}))
vi.mock('@/lib/code-server', () => ({
createWithCodeRetry: vi.fn(async (_gen, fn) => fn('SP-1')),
generateNextSprintCode: vi.fn().mockResolvedValue('SP-1'),
}))
vi.mock('@/lib/active-sprint', () => ({
setActiveSprintInSettings: vi.fn().mockResolvedValue(undefined),
}))
vi.mock('@/lib/prisma', () => {
const txClient = {
sprint: { create: vi.fn() },
story: { updateMany: vi.fn() },
task: { updateMany: vi.fn() },
}
return {
prisma: {
sprint: {
create: vi.fn(),
findFirst: vi.fn(),
update: vi.fn(),
},
story: {
findMany: vi.fn(),
updateMany: vi.fn(),
},
task: {
findMany: vi.fn(),
updateMany: vi.fn(),
},
pbi: { findMany: vi.fn() },
user: {
findUnique: vi.fn(),
update: vi.fn(),
},
$transaction: vi.fn(async (fn: (tx: typeof txClient) => unknown) => fn(txClient)),
__txClient: txClient,
},
}
})
import { prisma } from '@/lib/prisma'
import {
createSprintWithSelectionAction,
type CreateSprintWithSelectionInput,
} from '@/actions/sprints'
type Mocked = {
sprint: {
create: ReturnType<typeof vi.fn>
findFirst: ReturnType<typeof vi.fn>
update: ReturnType<typeof vi.fn>
}
story: {
findMany: ReturnType<typeof vi.fn>
updateMany: ReturnType<typeof vi.fn>
}
task: {
findMany: ReturnType<typeof vi.fn>
updateMany: ReturnType<typeof vi.fn>
}
$transaction: ReturnType<typeof vi.fn>
__txClient: {
sprint: { create: ReturnType<typeof vi.fn> }
story: { updateMany: ReturnType<typeof vi.fn> }
task: { updateMany: ReturnType<typeof vi.fn> }
}
}
const mockPrisma = prisma as unknown as Mocked
function baseInput(
overrides: Partial<CreateSprintWithSelectionInput> = {},
): CreateSprintWithSelectionInput {
return {
productId: 'product-1',
metadata: { goal: 'Sprint 1' },
pbiIntent: {},
storyOverrides: {},
...overrides,
}
}
beforeEach(() => {
vi.clearAllMocks()
mockPrisma.sprint.create.mockReset()
mockPrisma.story.findMany.mockReset()
mockPrisma.story.updateMany.mockReset()
mockPrisma.task.findMany.mockReset()
mockPrisma.task.updateMany.mockReset()
mockPrisma.$transaction.mockImplementation(
async (fn: (tx: typeof mockPrisma.__txClient) => unknown) =>
fn(mockPrisma.__txClient),
)
mockPrisma.__txClient.sprint.create
.mockReset()
.mockResolvedValue({ id: 'sprint-1', code: 'SP-1' })
mockPrisma.__txClient.story.updateMany
.mockReset()
.mockResolvedValue({ count: 0 })
mockPrisma.__txClient.task.updateMany
.mockReset()
.mockResolvedValue({ count: 0 })
})
describe('createSprintWithSelectionAction', () => {
it('resolves intent=all naar alle child-stories en weert overrides.remove', async () => {
// Stap 1: stories voor PBI-A (intent=all). Plus eligibility-fetch.
mockPrisma.story.findMany
// resolve step (only for pbis with intent='all')
.mockResolvedValueOnce([
{ id: 's1', pbi_id: 'pbiA' },
{ id: 's2', pbi_id: 'pbiA' },
{ id: 's3', pbi_id: 'pbiA' },
])
// partitionByEligibility — alle eligible
.mockResolvedValueOnce([
{ id: 's1', sprint_id: null, status: 'OPEN', sprint: null },
{ id: 's3', sprint_id: null, status: 'OPEN', sprint: null },
])
// affectedStories
.mockResolvedValueOnce([
{ pbi_id: 'pbiA' },
{ pbi_id: 'pbiA' },
])
mockPrisma.task.findMany.mockResolvedValueOnce([{ id: 't1' }])
const result = await createSprintWithSelectionAction(
baseInput({
pbiIntent: { pbiA: 'all' },
storyOverrides: { pbiA: { add: [], remove: ['s2'] } },
}),
)
expect('success' in result).toBe(true)
if ('success' in result) {
expect(result.affectedStoryIds).toEqual(['s1', 's3'])
expect(result.conflicts.notEligible).toEqual([])
}
})
it('voegt storyOverrides.add toe over PBI heen (zelfs intent=none)', async () => {
// Geen PBI met intent=all → stap 1 wordt niet uitgevoerd.
mockPrisma.story.findMany
// partition
.mockResolvedValueOnce([
{ id: 's10', sprint_id: null, status: 'OPEN', sprint: null },
])
// affectedStories
.mockResolvedValueOnce([{ pbi_id: 'pbiB' }])
mockPrisma.task.findMany.mockResolvedValueOnce([])
const result = await createSprintWithSelectionAction(
baseInput({
pbiIntent: { pbiB: 'none' },
storyOverrides: { pbiB: { add: ['s10'], remove: [] } },
}),
)
expect('success' in result).toBe(true)
if ('success' in result) {
expect(result.affectedStoryIds).toEqual(['s10'])
}
})
it('eligibility-filter classificeert DONE en cross-sprint stories', async () => {
mockPrisma.story.findMany
// resolve
.mockResolvedValueOnce([
{ id: 's1', pbi_id: 'pbiA' },
{ id: 's2', pbi_id: 'pbiA' },
{ id: 's3', pbi_id: 'pbiA' },
])
// partition: s1=DONE, s2=eligible, s3=in andere OPEN sprint
.mockResolvedValueOnce([
{ id: 's1', sprint_id: null, status: 'DONE', sprint: null },
{ id: 's2', sprint_id: null, status: 'OPEN', sprint: null },
{
id: 's3',
sprint_id: 'sprint-other',
status: 'IN_SPRINT',
sprint: { id: 'sprint-other', code: 'SP-O', status: 'OPEN' },
},
])
// affectedStories
.mockResolvedValueOnce([{ pbi_id: 'pbiA' }])
mockPrisma.task.findMany.mockResolvedValueOnce([])
const result = await createSprintWithSelectionAction(
baseInput({ pbiIntent: { pbiA: 'all' } }),
)
expect('success' in result).toBe(true)
if ('success' in result) {
expect(result.affectedStoryIds).toEqual(['s2'])
expect(result.conflicts.notEligible.map((n) => n.storyId).sort()).toEqual(
['s1', 's3'],
)
expect(result.conflicts.crossSprint.map((c) => c.storyId)).toEqual(['s3'])
}
})
it('zet story.status=IN_SPRINT en task.sprint_id mee in dezelfde transactie', async () => {
mockPrisma.story.findMany
.mockResolvedValueOnce([{ id: 's1', pbi_id: 'pbiA' }])
.mockResolvedValueOnce([
{ id: 's1', sprint_id: null, status: 'OPEN', sprint: null },
])
.mockResolvedValueOnce([{ pbi_id: 'pbiA' }])
mockPrisma.task.findMany.mockResolvedValueOnce([{ id: 't1' }])
await createSprintWithSelectionAction(
baseInput({ pbiIntent: { pbiA: 'all' } }),
)
expect(mockPrisma.$transaction).toHaveBeenCalledTimes(1)
expect(mockPrisma.__txClient.story.updateMany).toHaveBeenCalledWith(
expect.objectContaining({
data: expect.objectContaining({
sprint_id: 'sprint-1',
status: 'IN_SPRINT',
}),
}),
)
expect(mockPrisma.__txClient.task.updateMany).toHaveBeenCalledWith(
expect.objectContaining({
data: { sprint_id: 'sprint-1' },
}),
)
})
it('returnt affectedStoryIds + affectedPbiIds + affectedTaskIds', async () => {
mockPrisma.story.findMany
.mockResolvedValueOnce([
{ id: 's1', pbi_id: 'pbiA' },
{ id: 's2', pbi_id: 'pbiB' },
])
.mockResolvedValueOnce([
{ id: 's1', sprint_id: null, status: 'OPEN', sprint: null },
{ id: 's2', sprint_id: null, status: 'OPEN', sprint: null },
])
.mockResolvedValueOnce([{ pbi_id: 'pbiA' }, { pbi_id: 'pbiB' }])
mockPrisma.task.findMany.mockResolvedValueOnce([
{ id: 't1' },
{ id: 't2' },
])
const result = await createSprintWithSelectionAction(
baseInput({ pbiIntent: { pbiA: 'all', pbiB: 'all' } }),
)
expect('success' in result).toBe(true)
if ('success' in result) {
expect(result.affectedStoryIds.sort()).toEqual(['s1', 's2'])
expect(result.affectedPbiIds.sort()).toEqual(['pbiA', 'pbiB'])
expect(result.affectedTaskIds.sort()).toEqual(['t1', 't2'])
}
})
it('returnt error wanneer geen eligible stories overblijven', async () => {
mockPrisma.story.findMany
.mockResolvedValueOnce([{ id: 's1', pbi_id: 'pbiA' }])
// s1 is DONE → notEligible
.mockResolvedValueOnce([
{ id: 's1', sprint_id: null, status: 'DONE', sprint: null },
])
const result = await createSprintWithSelectionAction(
baseInput({ pbiIntent: { pbiA: 'all' } }),
)
expect('error' in result).toBe(true)
if ('error' in result) {
expect(result.code).toBe(422)
}
})
})

View file

@ -0,0 +1,717 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
const { mockSession } = vi.hoisted(() => ({
mockSession: { userId: 'user-1', isDemo: false },
}))
vi.mock('next/cache', () => ({ revalidatePath: vi.fn() }))
vi.mock('next/headers', () => ({ cookies: vi.fn().mockResolvedValue({}) }))
vi.mock('iron-session', () => ({
getIronSession: vi.fn().mockImplementation(async () => mockSession),
}))
vi.mock('@/lib/session', () => ({
sessionOptions: { cookieName: 'test', password: 'test-password-32-chars-minimum-len' },
}))
vi.mock('@/lib/idea-code-server', () => ({
nextIdeaCode: vi.fn().mockResolvedValue('IDEA-001'),
}))
vi.mock('@/lib/prisma', () => ({
prisma: {
idea: {
create: vi.fn(),
findFirst: vi.fn(),
update: vi.fn(),
delete: vi.fn(),
},
ideaLog: { create: vi.fn() },
claudeJob: {
findFirst: vi.fn(),
create: vi.fn(),
update: vi.fn(),
},
claudeWorker: {
count: vi.fn(),
},
pbi: {
findFirst: vi.fn(),
findMany: vi.fn(),
findUnique: vi.fn(),
create: vi.fn(),
delete: vi.fn(),
},
story: {
findMany: vi.fn(),
create: vi.fn(),
},
task: {
findMany: vi.fn(),
create: vi.fn(),
count: vi.fn(),
findUnique: vi.fn().mockResolvedValue(null),
},
product: {
findUnique: vi.fn().mockResolvedValue(null),
},
$transaction: vi.fn(),
$executeRaw: vi.fn().mockResolvedValue(0),
},
}))
import { prisma } from '@/lib/prisma'
import {
createIdeaAction,
updateIdeaAction,
archiveIdeaAction,
deleteIdeaAction,
updateGrillMdAction,
updatePlanMdAction,
uploadPlanMdAction,
downloadIdeaMdAction,
startGrillJobAction,
startMakePlanJobAction,
cancelIdeaJobAction,
materializeIdeaPlanAction,
relinkIdeaPlanAction,
} from '@/actions/ideas'
type MockIdea = {
idea: { create: ReturnType<typeof vi.fn>; findFirst: ReturnType<typeof vi.fn>; update: ReturnType<typeof vi.fn>; delete: ReturnType<typeof vi.fn> }
ideaLog: { create: ReturnType<typeof vi.fn> }
claudeJob: { findFirst: ReturnType<typeof vi.fn>; create: ReturnType<typeof vi.fn>; update: ReturnType<typeof vi.fn> }
claudeWorker: { count: ReturnType<typeof vi.fn> }
pbi: { findFirst: ReturnType<typeof vi.fn>; findMany: ReturnType<typeof vi.fn>; findUnique: ReturnType<typeof vi.fn>; create: ReturnType<typeof vi.fn>; delete: ReturnType<typeof vi.fn> }
story: { findMany: ReturnType<typeof vi.fn>; create: ReturnType<typeof vi.fn> }
task: { findMany: ReturnType<typeof vi.fn>; create: ReturnType<typeof vi.fn>; count: ReturnType<typeof vi.fn> }
$transaction: ReturnType<typeof vi.fn>
$executeRaw: ReturnType<typeof vi.fn>
}
const m = prisma as unknown as MockIdea
beforeEach(() => {
vi.clearAllMocks()
mockSession.userId = 'user-1'
mockSession.isDemo = false
// Default: $transaction passes its callback through with our mocked prisma
m.$transaction.mockImplementation(async (arg: unknown) => {
if (typeof arg === 'function') {
return (arg as (tx: unknown) => unknown)(m)
}
return arg
})
})
describe('createIdeaAction', () => {
it('happy path: creates DRAFT idea with auto-generated code', async () => {
m.idea.create.mockResolvedValueOnce({ id: 'idea-1', code: 'IDEA-001' })
const r = await createIdeaAction({ title: 'Plant-watering reminder' })
expect(r).toEqual({ success: true, data: { id: 'idea-1', code: 'IDEA-001' } })
expect(m.idea.create).toHaveBeenCalledWith(
expect.objectContaining({
data: expect.objectContaining({
user_id: 'user-1',
code: 'IDEA-001',
title: 'Plant-watering reminder',
status: 'DRAFT',
}),
}),
)
})
it('rejects unauthenticated', async () => {
mockSession.userId = ''
const r = await createIdeaAction({ title: 'x' })
expect(r).toMatchObject({ error: expect.stringMatching(/ingelogd/), code: 401 })
expect(m.idea.create).not.toHaveBeenCalled()
})
it('rejects demo-user', async () => {
mockSession.isDemo = true
const r = await createIdeaAction({ title: 'x' })
expect(r).toMatchObject({ error: expect.stringMatching(/demo/), code: 403 })
expect(m.idea.create).not.toHaveBeenCalled()
})
it('rejects invalid title (zod 422)', async () => {
const r = await createIdeaAction({ title: ' ' })
expect(r).toMatchObject({ code: 422 })
expect(m.idea.create).not.toHaveBeenCalled()
})
})
describe('updateIdeaAction', () => {
it('happy: updates editable idea (DRAFT)', async () => {
m.idea.findFirst.mockResolvedValueOnce({ id: 'idea-1', status: 'DRAFT' })
m.idea.update.mockResolvedValueOnce({})
const r = await updateIdeaAction('idea-1', { title: 'Updated' })
expect(r).toEqual({ success: true })
expect(m.idea.update).toHaveBeenCalledWith({
where: { id: 'idea-1' },
data: { title: 'Updated' },
})
})
it('blocks update on PLANNED (status-mismatch 422)', async () => {
m.idea.findFirst.mockResolvedValueOnce({ id: 'idea-1', status: 'PLANNED' })
const r = await updateIdeaAction('idea-1', { title: 'x' })
expect(r).toMatchObject({ code: 422 })
expect(m.idea.update).not.toHaveBeenCalled()
})
it('blocks update during GRILLING', async () => {
m.idea.findFirst.mockResolvedValueOnce({ id: 'idea-1', status: 'GRILLING' })
const r = await updateIdeaAction('idea-1', { title: 'x' })
expect(r).toMatchObject({ code: 422 })
})
it('returns 404 when idea belongs to another user', async () => {
m.idea.findFirst.mockResolvedValueOnce(null)
const r = await updateIdeaAction('idea-1', { title: 'x' })
expect(r).toMatchObject({ code: 404 })
})
})
describe('deleteIdeaAction', () => {
it('happy: deletes idea without pbi', async () => {
m.idea.findFirst.mockResolvedValueOnce({ id: 'idea-1', pbi_id: null })
const r = await deleteIdeaAction('idea-1')
expect(r).toEqual({ success: true })
expect(m.idea.delete).toHaveBeenCalledWith({ where: { id: 'idea-1' } })
})
it('blocks deletion when PBI is linked', async () => {
m.idea.findFirst.mockResolvedValueOnce({ id: 'idea-1', pbi_id: 'pbi-1' })
const r = await deleteIdeaAction('idea-1')
expect(r).toMatchObject({ code: 422 })
expect(m.idea.delete).not.toHaveBeenCalled()
})
})
describe('archiveIdeaAction', () => {
it('archives owned idea', async () => {
m.idea.findFirst.mockResolvedValueOnce({ id: 'idea-1' })
const r = await archiveIdeaAction('idea-1')
expect(r).toEqual({ success: true })
expect(m.idea.update).toHaveBeenCalledWith({
where: { id: 'idea-1' },
data: { archived: true },
})
})
})
describe('updateGrillMdAction', () => {
it('happy: updates grill_md in GRILLED', async () => {
m.idea.findFirst.mockResolvedValueOnce({ status: 'GRILLED' })
const r = await updateGrillMdAction('idea-1', '# Updated grill')
expect(r).toEqual({ success: true })
expect(m.$transaction).toHaveBeenCalled()
})
it('blocks in DRAFT', async () => {
m.idea.findFirst.mockResolvedValueOnce({ status: 'DRAFT' })
const r = await updateGrillMdAction('idea-1', 'x')
expect(r).toMatchObject({ code: 422 })
expect(m.$transaction).not.toHaveBeenCalled()
})
})
describe('updatePlanMdAction', () => {
const VALID_PLAN = `---
pbi:
title: Test
priority: 2
stories:
- title: S1
priority: 2
tasks:
- title: T1
priority: 2
---
body
`
it('happy: updates plan_md in PLAN_READY with valid yaml', async () => {
m.idea.findFirst.mockResolvedValueOnce({ status: 'PLAN_READY' })
const r = await updatePlanMdAction('idea-1', VALID_PLAN)
expect(r).toEqual({ success: true })
})
it('rejects invalid yaml (parse-fail 422 with details)', async () => {
m.idea.findFirst.mockResolvedValueOnce({ status: 'PLAN_READY' })
const r = await updatePlanMdAction('idea-1', '# no frontmatter')
expect(r).toMatchObject({ code: 422 })
expect((r as { details?: unknown }).details).toBeDefined()
})
it('blocks in PLANNED', async () => {
m.idea.findFirst.mockResolvedValueOnce({ status: 'PLANNED' })
const r = await updatePlanMdAction('idea-1', VALID_PLAN)
expect(r).toMatchObject({ code: 422 })
})
})
describe('uploadPlanMdAction', () => {
const VALID_PLAN = `---
pbi:
title: Uploaded
priority: 2
stories:
- title: S1
priority: 2
tasks:
- title: T1
priority: 2
---
body
`
it('happy: uploads from DRAFT — skips grill, sets PLAN_READY', async () => {
m.idea.findFirst.mockResolvedValueOnce({ status: 'DRAFT' })
const r = await uploadPlanMdAction('idea-1', VALID_PLAN)
expect(r).toEqual({ success: true })
expect(m.$transaction).toHaveBeenCalled()
const txnArg = m.$transaction.mock.calls.at(-1)?.[0] as unknown[] | undefined
expect(txnArg).toBeDefined()
// The first call in the transaction is the update — confirm status=PLAN_READY.
expect(m.idea.update).toHaveBeenCalledWith(
expect.objectContaining({
data: expect.objectContaining({ plan_md: VALID_PLAN, status: 'PLAN_READY' }),
}),
)
})
it('happy: uploads from GRILLED', async () => {
m.idea.findFirst.mockResolvedValueOnce({ status: 'GRILLED' })
const r = await uploadPlanMdAction('idea-1', VALID_PLAN)
expect(r).toEqual({ success: true })
})
it('happy: overwrites existing plan from PLAN_READY', async () => {
m.idea.findFirst.mockResolvedValueOnce({ status: 'PLAN_READY' })
const r = await uploadPlanMdAction('idea-1', VALID_PLAN)
expect(r).toEqual({ success: true })
})
it('happy: uploads from PLAN_FAILED (retry)', async () => {
m.idea.findFirst.mockResolvedValueOnce({ status: 'PLAN_FAILED' })
const r = await uploadPlanMdAction('idea-1', VALID_PLAN)
expect(r).toEqual({ success: true })
})
it('rejects from PLANNED (already materialized)', async () => {
m.idea.findFirst.mockResolvedValueOnce({ status: 'PLANNED' })
const r = await uploadPlanMdAction('idea-1', VALID_PLAN)
expect(r).toMatchObject({ code: 422 })
expect(m.$transaction).not.toHaveBeenCalled()
})
it('rejects from GRILLING (job running)', async () => {
m.idea.findFirst.mockResolvedValueOnce({ status: 'GRILLING' })
const r = await uploadPlanMdAction('idea-1', VALID_PLAN)
expect(r).toMatchObject({ code: 422 })
})
it('rejects empty markdown', async () => {
const r = await uploadPlanMdAction('idea-1', ' \n ')
expect(r).toMatchObject({ code: 422 })
// Should fail before touching DB
expect(m.idea.findFirst).not.toHaveBeenCalled()
})
it('rejects oversized markdown', async () => {
const huge = 'a'.repeat(100_001)
const r = await uploadPlanMdAction('idea-1', huge)
expect(r).toMatchObject({ code: 422 })
expect(m.idea.findFirst).not.toHaveBeenCalled()
})
it('rejects invalid yaml (parse-fail 422 with details)', async () => {
m.idea.findFirst.mockResolvedValueOnce({ status: 'DRAFT' })
const r = await uploadPlanMdAction('idea-1', '# no frontmatter')
expect(r).toMatchObject({ code: 422 })
expect((r as { details?: unknown }).details).toBeDefined()
expect(m.$transaction).not.toHaveBeenCalled()
})
it('returns 404 when idea not found', async () => {
m.idea.findFirst.mockResolvedValueOnce(null)
const r = await uploadPlanMdAction('nope', VALID_PLAN)
expect(r).toMatchObject({ code: 404 })
})
})
describe('startGrillJobAction', () => {
const idea = {
id: 'idea-1',
status: 'DRAFT',
product_id: 'prod-1',
product: { id: 'prod-1', repo_url: 'https://github.com/x/y' },
}
beforeEach(() => {
m.idea.findFirst.mockResolvedValue(idea)
m.claudeJob.findFirst.mockResolvedValue(null)
m.claudeWorker.count.mockResolvedValue(1)
m.claudeJob.create.mockResolvedValue({ id: 'job-1' })
})
it('happy path: creates IDEA_GRILL job, flips status to GRILLING', async () => {
const r = await startGrillJobAction('idea-1')
expect(r).toMatchObject({ success: true, data: { job_id: 'job-1' } })
expect(m.$executeRaw).toHaveBeenCalled()
})
it('blocks demo-user', async () => {
mockSession.isDemo = true
const r = await startGrillJobAction('idea-1')
expect(r).toMatchObject({ code: 403 })
expect(m.claudeJob.create).not.toHaveBeenCalled()
})
it('blocks when product has no repo_url', async () => {
m.idea.findFirst.mockResolvedValueOnce({
...idea,
product: { id: 'prod-1', repo_url: null },
})
const r = await startGrillJobAction('idea-1')
expect(r).toMatchObject({ code: 422, error: expect.stringMatching(/repo_url/i) })
})
it('blocks when no idea is unlinked', async () => {
m.idea.findFirst.mockResolvedValueOnce({ ...idea, product_id: null, product: null })
const r = await startGrillJobAction('idea-1')
expect(r).toMatchObject({ code: 422 })
})
it('blocks when no worker is active', async () => {
m.claudeWorker.count.mockResolvedValueOnce(0)
const r = await startGrillJobAction('idea-1')
expect(r).toMatchObject({ code: 422, error: expect.stringMatching(/worker/i) })
expect(m.claudeJob.create).not.toHaveBeenCalled()
})
it('blocks when an active job already exists (409)', async () => {
m.claudeJob.findFirst.mockResolvedValueOnce({ id: 'existing-job' })
const r = await startGrillJobAction('idea-1')
expect(r).toMatchObject({ code: 409 })
})
it('blocks invalid status (PLANNING)', async () => {
m.idea.findFirst.mockResolvedValueOnce({ ...idea, status: 'PLANNING' })
const r = await startGrillJobAction('idea-1')
expect(r).toMatchObject({ code: 422 })
})
})
describe('startMakePlanJobAction', () => {
const idea = {
id: 'idea-1',
status: 'GRILLED',
product_id: 'prod-1',
product: { id: 'prod-1', repo_url: 'https://github.com/x/y' },
}
beforeEach(() => {
m.idea.findFirst.mockResolvedValue(idea)
m.claudeJob.findFirst.mockResolvedValue(null)
m.claudeWorker.count.mockResolvedValue(1)
m.claudeJob.create.mockResolvedValue({ id: 'job-2' })
})
it('happy: GRILLED → PLANNING', async () => {
const r = await startMakePlanJobAction('idea-1')
expect(r).toMatchObject({ success: true })
})
it('blocks from DRAFT (must grill first)', async () => {
m.idea.findFirst.mockResolvedValueOnce({ ...idea, status: 'DRAFT' })
const r = await startMakePlanJobAction('idea-1')
expect(r).toMatchObject({ code: 422 })
})
})
describe('cancelIdeaJobAction', () => {
it('grill cancel without prior grill_md → DRAFT', async () => {
m.idea.findFirst.mockResolvedValueOnce({
id: 'idea-1',
status: 'GRILLING',
grill_md: null,
plan_md: null,
})
m.claudeJob.findFirst.mockResolvedValueOnce({ id: 'job-1', kind: 'IDEA_GRILL' })
const r = await cancelIdeaJobAction('idea-1')
expect(r).toEqual({ success: true })
// Verify $transaction was called with 3 ops (job-update, idea-update, log)
expect(m.$transaction).toHaveBeenCalled()
})
it('grill re-grill cancel with prior grill_md → GRILLED', async () => {
m.idea.findFirst.mockResolvedValueOnce({
id: 'idea-1',
status: 'GRILLING',
grill_md: '# old grill',
plan_md: null,
})
m.claudeJob.findFirst.mockResolvedValueOnce({ id: 'job-1', kind: 'IDEA_GRILL' })
const r = await cancelIdeaJobAction('idea-1')
expect(r).toEqual({ success: true })
})
it('returns 404 when no active job', async () => {
m.idea.findFirst.mockResolvedValueOnce({
id: 'idea-1',
status: 'GRILLED',
grill_md: null,
plan_md: null,
})
m.claudeJob.findFirst.mockResolvedValueOnce(null)
const r = await cancelIdeaJobAction('idea-1')
expect(r).toMatchObject({ code: 404 })
})
})
describe('materializeIdeaPlanAction', () => {
const VALID_PLAN = `---
pbi:
title: New PBI
priority: 2
stories:
- title: Story A
priority: 2
tasks:
- title: Task A1
priority: 2
implementation_plan: "1. Doe X"
- title: Task A2
priority: 2
- title: Story B
priority: 3
tasks:
- title: Task B1
priority: 3
---
body
`
beforeEach(() => {
m.idea.findFirst.mockResolvedValue({
id: 'idea-1',
status: 'PLAN_READY',
product_id: 'prod-1',
plan_md: VALID_PLAN,
})
m.pbi.findMany.mockResolvedValue([])
m.story.findMany.mockResolvedValue([])
m.task.findMany.mockResolvedValue([])
m.pbi.findFirst.mockResolvedValue(null)
m.pbi.create.mockResolvedValue({ id: 'pbi-1', code: 'PBI-1' })
m.story.create
.mockResolvedValueOnce({ id: 's-A' })
.mockResolvedValueOnce({ id: 's-B' })
m.task.create
.mockResolvedValueOnce({ id: 't-A1' })
.mockResolvedValueOnce({ id: 't-A2' })
.mockResolvedValueOnce({ id: 't-B1' })
})
it('happy: creates PBI + 2 stories + 3 tasks, links idea, returns ids; sort_order = parseCodeNumber(code)', async () => {
const r = await materializeIdeaPlanAction('idea-1')
expect(r).toMatchObject({
success: true,
data: {
pbi_id: 'pbi-1',
pbi_code: 'PBI-1',
story_ids: ['s-A', 's-B'],
task_ids: ['t-A1', 't-A2', 't-B1'],
},
})
expect(m.pbi.create).toHaveBeenCalledTimes(1)
expect(m.story.create).toHaveBeenCalledTimes(2)
expect(m.task.create).toHaveBeenCalledTimes(3)
// story sort_order = parseCodeNumber(auto-code): ST-001→1, ST-002→2
expect(m.story.create.mock.calls[0][0].data.sort_order).toBe(1)
expect(m.story.create.mock.calls[1][0].data.sort_order).toBe(2)
// task sort_order = parseCodeNumber(auto-code): T-1→1, T-2→2, T-3→3
expect(m.task.create.mock.calls[0][0].data.sort_order).toBe(1)
expect(m.task.create.mock.calls[1][0].data.sort_order).toBe(2)
expect(m.task.create.mock.calls[2][0].data.sort_order).toBe(3)
})
it('blocks when not PLAN_READY (e.g. GRILLED)', async () => {
m.idea.findFirst.mockResolvedValueOnce({
id: 'idea-1',
status: 'GRILLED',
product_id: 'prod-1',
plan_md: VALID_PLAN,
})
const r = await materializeIdeaPlanAction('idea-1')
expect(r).toMatchObject({ code: 422 })
expect(m.pbi.create).not.toHaveBeenCalled()
})
it('returns 422 with details on parse-fail', async () => {
m.idea.findFirst.mockResolvedValueOnce({
id: 'idea-1',
status: 'PLAN_READY',
product_id: 'prod-1',
plan_md: '# no frontmatter',
})
const r = await materializeIdeaPlanAction('idea-1')
expect(r).toMatchObject({ code: 422 })
expect((r as { details?: unknown }).details).toBeDefined()
})
it('blocks demo-user', async () => {
mockSession.isDemo = true
const r = await materializeIdeaPlanAction('idea-1')
expect(r).toMatchObject({ code: 403 })
})
it('returns 409 on P2002 race', async () => {
m.$transaction.mockImplementationOnce(async () => {
throw new Error('Unique constraint failed (P2002)')
})
const r = await materializeIdeaPlanAction('idea-1')
expect(r).toMatchObject({ code: 409 })
})
})
describe('materializeIdeaPlanAction — existing PBI pre-check', () => {
const VALID_PLAN = `---
pbi:
title: New PBI
priority: 2
stories:
- title: Story A
priority: 2
tasks:
- title: Task A1
priority: 2
---
body
`
beforeEach(() => {
// Use a distinct userId to avoid sharing the rate-limit bucket with the
// materializeIdeaPlanAction describe block above.
mockSession.userId = 'user-precheck'
m.idea.findFirst.mockResolvedValue({
id: 'idea-1',
status: 'PLAN_READY',
product_id: 'prod-1',
plan_md: VALID_PLAN,
pbi_id: 'old-pbi',
})
m.pbi.findMany.mockResolvedValue([])
m.story.findMany.mockResolvedValue([])
m.task.findMany.mockResolvedValue([])
m.pbi.findFirst.mockResolvedValue(null)
m.pbi.findUnique.mockResolvedValue({ code: 'PBI-X' })
m.pbi.create.mockResolvedValue({ id: 'pbi-new', code: 'PBI-2' })
m.pbi.delete.mockResolvedValue({})
m.story.create.mockResolvedValue({ id: 's-1' })
m.task.create.mockResolvedValue({ id: 't-1' })
})
it('auto-vervang: deletes old PBI in transaction when no tasks executed', async () => {
m.task.count.mockResolvedValueOnce(0)
const r = await materializeIdeaPlanAction('idea-1')
expect(r).toMatchObject({ success: true, data: { pbi_id: 'pbi-new' } })
expect(m.pbi.delete).toHaveBeenCalledWith({ where: { id: 'old-pbi' } })
expect(m.pbi.create).toHaveBeenCalledTimes(1)
})
it('conflict-409: returns PBI_HAS_ACTIVE_TASKS when executed tasks exist', async () => {
m.task.count.mockResolvedValueOnce(1)
const r = await materializeIdeaPlanAction('idea-1')
expect(r).toMatchObject({ code: 409, error: 'PBI_HAS_ACTIVE_TASKS:PBI-X' })
expect(m.pbi.create).not.toHaveBeenCalled()
expect(m.pbi.delete).not.toHaveBeenCalled()
})
it('alongside: skips old PBI delete and creates new PBI when allowAlongside=true', async () => {
m.task.count.mockResolvedValueOnce(1)
const r = await materializeIdeaPlanAction('idea-1', { allowAlongside: true })
expect(r).toMatchObject({ success: true, data: { pbi_id: 'pbi-new' } })
expect(m.pbi.delete).not.toHaveBeenCalled()
expect(m.pbi.create).toHaveBeenCalledTimes(1)
})
})
describe('relinkIdeaPlanAction', () => {
it('happy: PLANNED with pbi_id=null → PLAN_READY', async () => {
m.idea.findFirst.mockResolvedValueOnce({
id: 'idea-1',
status: 'PLANNED',
pbi_id: null,
})
const r = await relinkIdeaPlanAction('idea-1')
expect(r).toEqual({ success: true })
expect(m.$transaction).toHaveBeenCalled()
})
it('blocks when pbi still linked', async () => {
m.idea.findFirst.mockResolvedValueOnce({
id: 'idea-1',
status: 'PLANNED',
pbi_id: 'pbi-1',
})
const r = await relinkIdeaPlanAction('idea-1')
expect(r).toMatchObject({ code: 422 })
})
it('blocks when not PLANNED', async () => {
m.idea.findFirst.mockResolvedValueOnce({
id: 'idea-1',
status: 'PLAN_READY',
pbi_id: null,
})
const r = await relinkIdeaPlanAction('idea-1')
expect(r).toMatchObject({ code: 422 })
})
})
describe('downloadIdeaMdAction', () => {
it('returns grill_md when present', async () => {
m.idea.findFirst.mockResolvedValueOnce({
code: 'IDEA-001',
grill_md: '# Idee\nscope',
plan_md: null,
})
const r = await downloadIdeaMdAction('idea-1', 'grill')
expect(r).toMatchObject({
success: true,
data: { filename: 'IDEA-001-grill.md', markdown: '# Idee\nscope' },
})
})
it('404 when md not yet generated', async () => {
m.idea.findFirst.mockResolvedValueOnce({
code: 'IDEA-001',
grill_md: null,
plan_md: null,
})
const r = await downloadIdeaMdAction('idea-1', 'plan')
expect(r).toMatchObject({ code: 404 })
})
it('demo MAY download (read-only operation)', async () => {
mockSession.isDemo = true
m.idea.findFirst.mockResolvedValueOnce({
code: 'IDEA-001',
grill_md: 'x',
plan_md: null,
})
const r = await downloadIdeaMdAction('idea-1', 'grill')
expect(r).toMatchObject({ success: true })
})
})

View file

@ -0,0 +1,163 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
const {
mockGetSession,
mockFindFirstProduct,
mockCreateProduct,
mockUpdateProduct,
mockCreateMember,
mockExecuteRaw,
mockTransaction,
} = vi.hoisted(() => ({
mockGetSession: vi.fn(),
mockFindFirstProduct: vi.fn(),
mockCreateProduct: vi.fn(),
mockUpdateProduct: vi.fn(),
mockCreateMember: vi.fn(),
mockExecuteRaw: vi.fn().mockResolvedValue(undefined),
mockTransaction: vi.fn(),
}))
vi.mock('next/cache', () => ({ revalidatePath: vi.fn() }))
vi.mock('next/navigation', () => ({ redirect: vi.fn() }))
vi.mock('next/headers', () => ({ cookies: vi.fn().mockResolvedValue({}) }))
vi.mock('iron-session', () => ({
getIronSession: vi.fn().mockResolvedValue({ userId: 'user-1', isDemo: false }),
}))
vi.mock('@/lib/session', () => ({
sessionOptions: { cookieName: 'test', password: 'test' },
}))
vi.mock('@/lib/auth', () => ({ getSession: mockGetSession }))
vi.mock('@/lib/product-access', () => ({
productAccessFilter: vi.fn().mockReturnValue({ OR: [{ user_id: 'user-1' }] }),
}))
vi.mock('@/lib/prisma', () => ({
prisma: {
product: { findFirst: mockFindFirstProduct, create: mockCreateProduct, update: mockUpdateProduct },
productMember: { create: mockCreateMember },
$executeRaw: mockExecuteRaw,
$transaction: mockTransaction,
},
}))
import { createProductAction, updateProductAction } from '@/actions/products'
import { getIronSession } from 'iron-session'
const mockSession = getIronSession as ReturnType<typeof vi.fn>
const SESSION_USER = { userId: 'user-1', isDemo: false }
const SESSION_DEMO = { userId: 'demo-1', isDemo: true }
const PRODUCT_ID = 'product-1'
const VALID_DATA = {
name: 'Test Product',
code: 'TP',
description: 'Een product',
repo_url: 'https://github.com/org/repo',
definition_of_done: 'Alles groen',
auto_pr: false,
}
beforeEach(() => {
vi.clearAllMocks()
mockExecuteRaw.mockResolvedValue(undefined)
mockSession.mockResolvedValue(SESSION_USER)
})
// =============================================================
// createProductAction
// =============================================================
describe('createProductAction', () => {
it('happy path: maakt product + member aan en retourneert productId', async () => {
mockFindFirstProduct.mockResolvedValue(null) // geen dubbele code
mockTransaction.mockImplementation(async (fn: (tx: unknown) => Promise<unknown>) => {
return fn({
product: {
create: vi.fn().mockResolvedValue({ id: PRODUCT_ID }),
},
productMember: {
create: vi.fn().mockResolvedValue({}),
},
})
})
const result = await createProductAction(VALID_DATA)
expect(result).toEqual({ success: true, productId: PRODUCT_ID })
})
it('demo-user → error', async () => {
mockSession.mockResolvedValue(SESSION_DEMO)
const result = await createProductAction(VALID_DATA)
expect(result).toMatchObject({ error: expect.stringContaining('demo') })
expect(mockTransaction).not.toHaveBeenCalled()
})
it('ongeldige repo_url (niet github) → validatiefout', async () => {
const result = await createProductAction({ ...VALID_DATA, repo_url: 'https://gitlab.com/org/repo' })
expect(result).toMatchObject({ error: expect.any(String) })
expect(mockTransaction).not.toHaveBeenCalled()
})
it('dubbele code → error', async () => {
mockFindFirstProduct.mockResolvedValue({ id: 'other-product' })
const result = await createProductAction(VALID_DATA)
expect(result).toMatchObject({
code: 422,
fieldErrors: { code: expect.arrayContaining([expect.stringContaining('gebruik')]) },
})
expect(mockTransaction).not.toHaveBeenCalled()
})
it('naam ontbreekt → validatiefout', async () => {
const result = await createProductAction({ ...VALID_DATA, name: '' })
expect(result).toMatchObject({ error: expect.any(String) })
})
})
// =============================================================
// updateProductAction
// =============================================================
describe('updateProductAction', () => {
it('happy path: werkt product bij en stuurt pg_notify', async () => {
mockFindFirstProduct.mockResolvedValue({ id: PRODUCT_ID })
mockUpdateProduct.mockResolvedValue({ id: PRODUCT_ID })
const result = await updateProductAction(PRODUCT_ID, VALID_DATA)
expect(result).toEqual({ success: true })
expect(mockUpdateProduct).toHaveBeenCalled()
expect(mockExecuteRaw).toHaveBeenCalledTimes(1)
})
it('demo-user → error', async () => {
mockSession.mockResolvedValue(SESSION_DEMO)
const result = await updateProductAction(PRODUCT_ID, VALID_DATA)
expect(result).toMatchObject({ error: expect.stringContaining('demo') })
expect(mockUpdateProduct).not.toHaveBeenCalled()
})
it('geen toegang tot product → error', async () => {
mockFindFirstProduct.mockResolvedValue(null)
const result = await updateProductAction(PRODUCT_ID, VALID_DATA)
expect(result).toMatchObject({ error: expect.stringContaining('toegang') })
expect(mockUpdateProduct).not.toHaveBeenCalled()
})
it('ongeldige repo_url → validatiefout', async () => {
const result = await updateProductAction(PRODUCT_ID, { ...VALID_DATA, repo_url: 'https://bitbucket.org/x' })
expect(result).toMatchObject({ error: expect.any(String) })
expect(mockUpdateProduct).not.toHaveBeenCalled()
})
})

View file

@ -0,0 +1,102 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
const { mockGetSession } = vi.hoisted(() => ({
mockGetSession: vi.fn(),
}))
vi.mock('@/lib/auth', () => ({
getSession: mockGetSession,
}))
const { mockUpsert, mockDeleteMany } = vi.hoisted(() => ({
mockUpsert: vi.fn(),
mockDeleteMany: vi.fn(),
}))
vi.mock('@/lib/prisma', () => ({
prisma: {
pushSubscription: {
upsert: mockUpsert,
deleteMany: mockDeleteMany,
},
},
}))
import { subscribeToPushAction, unsubscribeFromPushAction } from '@/actions/push'
const VALID_INPUT = {
endpoint: 'https://push.example.com/subscription/abc123',
keys: { p256dh: 'aBcDeFgH', auth: 'xYzAbC' },
}
const SESSION_USER = { userId: 'user-1', isDemo: false }
const SESSION_DEMO = { userId: 'demo-1', isDemo: true }
beforeEach(() => {
vi.clearAllMocks()
mockUpsert.mockResolvedValue({})
mockDeleteMany.mockResolvedValue({ count: 1 })
})
describe('subscribeToPushAction', () => {
it('upserts subscription for authenticated user', async () => {
mockGetSession.mockResolvedValue(SESSION_USER)
await subscribeToPushAction(VALID_INPUT)
expect(mockUpsert).toHaveBeenCalledWith(
expect.objectContaining({
where: { endpoint: VALID_INPUT.endpoint },
create: expect.objectContaining({ user_id: 'user-1', endpoint: VALID_INPUT.endpoint }),
})
)
})
it('is idempotent — calling twice upserts twice without error', async () => {
mockGetSession.mockResolvedValue(SESSION_USER)
await subscribeToPushAction(VALID_INPUT)
await subscribeToPushAction(VALID_INPUT)
expect(mockUpsert).toHaveBeenCalledTimes(2)
})
it('returns without writing for demo user', async () => {
mockGetSession.mockResolvedValue(SESSION_DEMO)
await subscribeToPushAction(VALID_INPUT)
expect(mockUpsert).not.toHaveBeenCalled()
})
it('returns without writing when not authenticated', async () => {
mockGetSession.mockResolvedValue({})
await subscribeToPushAction(VALID_INPUT)
expect(mockUpsert).not.toHaveBeenCalled()
})
it('returns without writing for invalid input', async () => {
mockGetSession.mockResolvedValue(SESSION_USER)
// @ts-expect-error intentionally invalid
await subscribeToPushAction({ endpoint: 'not-a-url', keys: {} })
expect(mockUpsert).not.toHaveBeenCalled()
})
})
describe('unsubscribeFromPushAction', () => {
it('deletes subscription scoped to user_id', async () => {
mockGetSession.mockResolvedValue(SESSION_USER)
await unsubscribeFromPushAction({ endpoint: VALID_INPUT.endpoint })
expect(mockDeleteMany).toHaveBeenCalledWith({
where: { endpoint: VALID_INPUT.endpoint, user_id: 'user-1' },
})
})
it('does not touch subscriptions of other users', async () => {
mockGetSession.mockResolvedValue({ userId: 'other-user', isDemo: false })
await unsubscribeFromPushAction({ endpoint: VALID_INPUT.endpoint })
expect(mockDeleteMany).toHaveBeenCalledWith(
expect.objectContaining({ where: expect.objectContaining({ user_id: 'other-user' }) })
)
})
it('returns without writing when not authenticated', async () => {
mockGetSession.mockResolvedValue({})
await unsubscribeFromPushAction({ endpoint: VALID_INPUT.endpoint })
expect(mockDeleteMany).not.toHaveBeenCalled()
})
})

View file

@ -16,6 +16,9 @@ vi.mock('@/lib/prisma', () => ({
findFirst: vi.fn(),
updateMany: vi.fn(),
},
product: {
findFirst: vi.fn().mockResolvedValue({ id: 'product-1' }),
},
},
}))
@ -44,7 +47,13 @@ beforeEach(() => {
describe('actions/questions — answerQuestion', () => {
it('happy: status pending→answered, revalidatePath geroepen', async () => {
mockGetSession.mockResolvedValue(SESSION_USER)
mockPrisma.claudeQuestion.findFirst.mockResolvedValueOnce({ id: VALID_ID }) // access-check
mockPrisma.claudeQuestion.findFirst.mockResolvedValueOnce({
id: VALID_ID,
story_id: 'story-1',
idea_id: null,
product_id: 'product-1',
idea: null,
})
mockPrisma.claudeQuestion.updateMany.mockResolvedValueOnce({ count: 1 })
const res = await answerQuestion(VALID_ID, VALID_ANSWER)
@ -85,7 +94,13 @@ describe('actions/questions — answerQuestion', () => {
it('al-answered: race-error met begrijpelijke melding', async () => {
mockGetSession.mockResolvedValue(SESSION_USER)
mockPrisma.claudeQuestion.findFirst.mockResolvedValueOnce({ id: VALID_ID }) // access-check
mockPrisma.claudeQuestion.findFirst.mockResolvedValueOnce({
id: VALID_ID,
story_id: 'story-1',
idea_id: null,
product_id: 'product-1',
idea: null,
})
mockPrisma.claudeQuestion.updateMany.mockResolvedValueOnce({ count: 0 })
mockPrisma.claudeQuestion.findFirst.mockResolvedValueOnce({
status: 'answered',
@ -99,7 +114,13 @@ describe('actions/questions — answerQuestion', () => {
it('verlopen: updateMany count=0, nog open status maar voorbij expiry', async () => {
mockGetSession.mockResolvedValue(SESSION_USER)
mockPrisma.claudeQuestion.findFirst.mockResolvedValueOnce({ id: VALID_ID })
mockPrisma.claudeQuestion.findFirst.mockResolvedValueOnce({
id: VALID_ID,
story_id: 'story-1',
idea_id: null,
product_id: 'product-1',
idea: null,
})
mockPrisma.claudeQuestion.updateMany.mockResolvedValueOnce({ count: 0 })
mockPrisma.claudeQuestion.findFirst.mockResolvedValueOnce({
status: 'open',

View file

@ -0,0 +1,72 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
const { mockUserUpdate, mockGetIronSession } = vi.hoisted(() => ({
mockUserUpdate: vi.fn(),
mockGetIronSession: vi.fn(),
}))
vi.mock('next/cache', () => ({ revalidatePath: vi.fn() }))
vi.mock('next/headers', () => ({ cookies: vi.fn().mockResolvedValue({}) }))
vi.mock('iron-session', () => ({ getIronSession: mockGetIronSession }))
vi.mock('@/lib/session', () => ({ sessionOptions: { cookieName: 'test', password: 'test' } }))
vi.mock('@/lib/prisma', () => ({
prisma: { user: { update: mockUserUpdate } },
}))
import { updateMinQuotaPctAction } from '@/actions/settings'
const SESSION_USER = { userId: 'user-1', isDemo: false }
const SESSION_DEMO = { userId: 'demo-1', isDemo: true }
const SESSION_UNAUTH = { userId: undefined, isDemo: false }
describe('updateMinQuotaPctAction', () => {
beforeEach(() => {
vi.clearAllMocks()
mockUserUpdate.mockResolvedValue({})
})
it('returns error when not authenticated', async () => {
mockGetIronSession.mockResolvedValue(SESSION_UNAUTH)
const result = await updateMinQuotaPctAction(20)
expect(result).toMatchObject({ error: expect.any(String) })
expect(mockUserUpdate).not.toHaveBeenCalled()
})
it('returns 403 error for demo session', async () => {
mockGetIronSession.mockResolvedValue(SESSION_DEMO)
const result = await updateMinQuotaPctAction(20)
expect(result).toMatchObject({ status: 403 })
expect(mockUserUpdate).not.toHaveBeenCalled()
})
it('returns 422 error when value is 0 (below min)', async () => {
mockGetIronSession.mockResolvedValue(SESSION_USER)
const result = await updateMinQuotaPctAction(0)
expect(result).toMatchObject({ status: 422 })
expect(mockUserUpdate).not.toHaveBeenCalled()
})
it('returns 422 error when value is 101 (above max)', async () => {
mockGetIronSession.mockResolvedValue(SESSION_USER)
const result = await updateMinQuotaPctAction(101)
expect(result).toMatchObject({ status: 422 })
expect(mockUserUpdate).not.toHaveBeenCalled()
})
it('saves valid value and returns success', async () => {
mockGetIronSession.mockResolvedValue(SESSION_USER)
const result = await updateMinQuotaPctAction(35)
expect(result).toEqual({ success: true })
expect(mockUserUpdate).toHaveBeenCalledWith({
where: { id: 'user-1' },
data: { min_quota_pct: 35 },
})
})
it('accepts boundary values 1 and 100', async () => {
mockGetIronSession.mockResolvedValue(SESSION_USER)
await updateMinQuotaPctAction(1)
await updateMinQuotaPctAction(100)
expect(mockUserUpdate).toHaveBeenCalledTimes(2)
})
})

View file

@ -1,7 +1,7 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
vi.mock('next/cache', () => ({ revalidatePath: vi.fn() }))
vi.mock('next/headers', () => ({ cookies: vi.fn().mockResolvedValue({}) }))
vi.mock('next/headers', () => ({ cookies: vi.fn().mockResolvedValue({ set: vi.fn(), get: vi.fn(), delete: vi.fn() }) }))
vi.mock('iron-session', () => ({
getIronSession: vi.fn().mockResolvedValue({ userId: 'user-1', isDemo: false }),
}))
@ -16,16 +16,22 @@ vi.mock('@/lib/prisma', () => ({
prisma: {
sprint: {
findFirst: vi.fn(),
findMany: vi.fn(),
create: vi.fn(),
update: vi.fn(),
},
user: {
findUnique: vi.fn().mockResolvedValue({ settings: {} }),
update: vi.fn().mockResolvedValue({}),
},
$executeRaw: vi.fn().mockResolvedValue(1),
},
}))
import { prisma } from '@/lib/prisma'
import { createSprintAction, updateSprintDatesAction } from '@/actions/sprints'
const mockSprint = prisma as unknown as { sprint: { findFirst: ReturnType<typeof vi.fn>; create: ReturnType<typeof vi.fn>; update: ReturnType<typeof vi.fn> } }
const mockSprint = prisma as unknown as { sprint: { findFirst: ReturnType<typeof vi.fn>; findMany: ReturnType<typeof vi.fn>; create: ReturnType<typeof vi.fn>; update: ReturnType<typeof vi.fn> } }
function makeFormData(data: Record<string, string | null>) {
const fd = new FormData()
@ -39,6 +45,7 @@ describe('createSprintAction — date validation', () => {
beforeEach(() => {
vi.clearAllMocks()
mockSprint.sprint.findFirst.mockResolvedValue(null)
mockSprint.sprint.findMany.mockResolvedValue([])
mockSprint.sprint.create.mockResolvedValue({ id: 'sprint-1' })
})
@ -53,10 +60,9 @@ describe('createSprintAction — date validation', () => {
it('rejects end_date before start_date', async () => {
const fd = makeFormData({ productId: 'product-1', sprint_goal: 'Doel', start_date: '2026-05-14', end_date: '2026-05-01' })
const result = await createSprintAction(undefined, fd)
expect(result.error).toBeTruthy()
const errors = result.error as Record<string, string[]>
expect(errors.end_date?.[0]).toContain('Einddatum')
const result = await createSprintAction(undefined, fd) as { code?: number; fieldErrors?: Record<string, string[]> }
expect(result.code).toBe(422)
expect(result.fieldErrors?.end_date?.[0]).toContain('Einddatum')
})
it('accepts no dates (both optional)', async () => {
@ -81,10 +87,9 @@ describe('updateSprintDatesAction — date validation', () => {
it('rejects end_date before start_date', async () => {
const fd = makeFormData({ id: 'sprint-1', start_date: '2026-05-10', end_date: '2026-05-05' })
const result = await updateSprintDatesAction(undefined, fd)
expect(result.error).toBeTruthy()
const errors = result.error as Record<string, string[]>
expect(errors.end_date?.[0]).toContain('Einddatum')
const result = await updateSprintDatesAction(undefined, fd) as { code?: number; fieldErrors?: Record<string, string[]> }
expect(result.code).toBe(422)
expect(result.fieldErrors?.end_date?.[0]).toContain('Einddatum')
})
it('blocks demo users', async () => {

View file

@ -0,0 +1,167 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
vi.mock('next/cache', () => ({ revalidatePath: vi.fn() }))
vi.mock('next/headers', () => ({
cookies: vi.fn().mockResolvedValue({
set: vi.fn(),
get: vi.fn(),
delete: vi.fn(),
}),
}))
vi.mock('iron-session', () => ({
getIronSession: vi.fn().mockResolvedValue({ userId: 'user-1', isDemo: false }),
}))
vi.mock('@/lib/session', () => ({
sessionOptions: { cookieName: 'test', password: 'test' },
}))
vi.mock('@/lib/product-access', () => ({
productAccessFilter: vi.fn().mockReturnValue({}),
}))
vi.mock('@/lib/prisma', () => ({
prisma: {
product: { findFirst: vi.fn() },
user: {
findUnique: vi.fn(),
update: vi.fn().mockResolvedValue({}),
},
$executeRaw: vi.fn().mockResolvedValue(1),
},
}))
import { prisma } from '@/lib/prisma'
import {
clearPendingSprintDraftAction,
setPendingSprintDraftAction,
} from '@/actions/sprint-draft'
import type { PendingSprintDraft, UserSettings } from '@/lib/user-settings'
const mockPrisma = prisma as unknown as {
product: { findFirst: ReturnType<typeof vi.fn> }
user: {
findUnique: ReturnType<typeof vi.fn>
update: ReturnType<typeof vi.fn>
}
}
const validDraft: PendingSprintDraft = {
goal: 'Sprint 1',
pbiIntent: { pbiA: 'all' },
storyOverrides: { pbiA: { add: [], remove: ['story-1'] } },
}
describe('setPendingSprintDraftAction', () => {
beforeEach(() => {
vi.clearAllMocks()
mockPrisma.product.findFirst.mockReset()
mockPrisma.user.findUnique.mockReset()
mockPrisma.user.update.mockReset().mockResolvedValue({})
})
it('persists draft for accessible product', async () => {
mockPrisma.product.findFirst.mockResolvedValueOnce({ id: 'p1' })
mockPrisma.user.findUnique.mockResolvedValueOnce({ settings: {} })
const result = await setPendingSprintDraftAction('p1', validDraft)
expect(result).toEqual({ success: true })
const updateArg = mockPrisma.user.update.mock.calls[0][0] as {
data: { settings: UserSettings }
}
expect(updateArg.data.settings.workflow?.pendingSprintDraft?.p1).toMatchObject({
goal: 'Sprint 1',
pbiIntent: { pbiA: 'all' },
})
})
it('preserves drafts for other products', async () => {
mockPrisma.product.findFirst.mockResolvedValueOnce({ id: 'p1' })
mockPrisma.user.findUnique.mockResolvedValueOnce({
settings: {
workflow: {
pendingSprintDraft: {
p2: { goal: 'P2 draft', pbiIntent: {}, storyOverrides: {} },
},
},
},
})
await setPendingSprintDraftAction('p1', validDraft)
const updateArg = mockPrisma.user.update.mock.calls[0][0] as {
data: { settings: UserSettings }
}
const drafts = updateArg.data.settings.workflow?.pendingSprintDraft
expect(Object.keys(drafts ?? {})).toEqual(expect.arrayContaining(['p1', 'p2']))
})
it('rejects invalid draft (empty goal)', async () => {
mockPrisma.product.findFirst.mockResolvedValueOnce({ id: 'p1' })
const result = await setPendingSprintDraftAction('p1', {
...validDraft,
goal: '',
} as PendingSprintDraft)
expect(result).toHaveProperty('error')
expect(mockPrisma.user.update).not.toHaveBeenCalled()
})
it('rejects when product not accessible', async () => {
mockPrisma.product.findFirst.mockResolvedValueOnce(null)
const result = await setPendingSprintDraftAction('p1', validDraft)
expect(result).toEqual({ error: 'Product niet gevonden of niet toegankelijk' })
expect(mockPrisma.user.update).not.toHaveBeenCalled()
})
})
describe('clearPendingSprintDraftAction', () => {
beforeEach(() => {
vi.clearAllMocks()
mockPrisma.product.findFirst.mockReset()
mockPrisma.user.findUnique.mockReset()
mockPrisma.user.update.mockReset().mockResolvedValue({})
})
it('removes draft key for product', async () => {
mockPrisma.product.findFirst.mockResolvedValueOnce({ id: 'p1' })
mockPrisma.user.findUnique.mockResolvedValueOnce({
settings: {
workflow: {
pendingSprintDraft: {
p1: { goal: 'gone', pbiIntent: {}, storyOverrides: {} },
p2: { goal: 'keep', pbiIntent: {}, storyOverrides: {} },
},
},
},
})
await clearPendingSprintDraftAction('p1')
const updateArg = mockPrisma.user.update.mock.calls[0][0] as {
data: { settings: UserSettings }
}
expect(updateArg.data.settings.workflow?.pendingSprintDraft).toEqual({
p2: { goal: 'keep', pbiIntent: {}, storyOverrides: {} },
})
})
it('is a no-op when there is no draft for the product', async () => {
mockPrisma.product.findFirst.mockResolvedValueOnce({ id: 'p1' })
mockPrisma.user.findUnique.mockResolvedValueOnce({ settings: {} })
const result = await clearPendingSprintDraftAction('p1')
expect(result).toEqual({ success: true })
expect(mockPrisma.user.update).not.toHaveBeenCalled()
})
it('rejects when product not accessible', async () => {
mockPrisma.product.findFirst.mockResolvedValueOnce(null)
const result = await clearPendingSprintDraftAction('p1')
expect(result).toEqual({ error: 'Product niet gevonden of niet toegankelijk' })
})
})

View file

@ -0,0 +1,407 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
vi.mock('next/cache', () => ({ revalidatePath: vi.fn() }))
vi.mock('next/headers', () => ({ cookies: vi.fn().mockResolvedValue({}) }))
vi.mock('iron-session', () => ({
getIronSession: vi.fn(),
}))
vi.mock('@/lib/session', () => ({
sessionOptions: { cookieName: 'test', password: 'test' },
}))
vi.mock('@/lib/prisma', () => ({
prisma: {
sprint: {
findUnique: vi.fn(),
update: vi.fn(),
},
sprintRun: {
findFirst: vi.fn(),
findUnique: vi.fn(),
create: vi.fn(),
update: vi.fn(),
},
story: {
findMany: vi.fn(),
updateMany: vi.fn(),
},
pbi: {
updateMany: vi.fn(),
},
task: {
updateMany: vi.fn(),
findUnique: vi.fn().mockResolvedValue(null),
},
claudeQuestion: {
findMany: vi.fn(),
},
claudeJob: {
create: vi.fn(),
updateMany: vi.fn(),
},
product: {
findUnique: vi.fn().mockResolvedValue(null),
},
$transaction: vi.fn(),
},
}))
import { prisma } from '@/lib/prisma'
import { getIronSession } from 'iron-session'
import {
startSprintRunAction,
resumeSprintAction,
cancelSprintRunAction,
} from '@/actions/sprint-runs'
const mockSession = getIronSession as ReturnType<typeof vi.fn>
type Mocked = {
sprint: { findUnique: ReturnType<typeof vi.fn>; update: ReturnType<typeof vi.fn> }
sprintRun: {
findFirst: ReturnType<typeof vi.fn>
findUnique: ReturnType<typeof vi.fn>
create: ReturnType<typeof vi.fn>
update: ReturnType<typeof vi.fn>
}
story: {
findMany: ReturnType<typeof vi.fn>
updateMany: ReturnType<typeof vi.fn>
}
pbi: { updateMany: ReturnType<typeof vi.fn> }
task: { updateMany: ReturnType<typeof vi.fn> }
claudeQuestion: { findMany: ReturnType<typeof vi.fn> }
claudeJob: {
create: ReturnType<typeof vi.fn>
updateMany: ReturnType<typeof vi.fn>
}
$transaction: ReturnType<typeof vi.fn>
}
const mockPrisma = prisma as unknown as Mocked
const SPRINT_OK = {
id: 'sprint-1',
status: 'OPEN',
product_id: 'prod-1',
product: { id: 'prod-1', pr_strategy: 'SPRINT' },
}
const STORY_OK = {
id: 'story-1',
pbi_id: 'pbi-1',
priority: 1,
sort_order: 1,
pbi: {
id: 'pbi-1',
code: 'PBI-1',
title: 'PBI',
status: 'READY',
priority: 1,
sort_order: 1,
},
tasks: [
{ id: 'task-1', code: 'T-1', title: 'T1', priority: 1, sort_order: 1, implementation_plan: 'plan' },
{ id: 'task-2', code: 'T-2', title: 'T2', priority: 1, sort_order: 2, implementation_plan: 'plan' },
],
}
beforeEach(() => {
vi.clearAllMocks()
mockSession.mockResolvedValue({ userId: 'user-1', isDemo: false })
mockPrisma.$transaction.mockImplementation(
async (run: (tx: typeof prisma) => Promise<unknown>) => run(prisma),
)
})
describe('startSprintRunAction — happy path', () => {
it('maakt SprintRun + 2 ClaudeJobs voor 2 TO_DO tasks', async () => {
mockPrisma.sprint.findUnique.mockResolvedValue(SPRINT_OK)
mockPrisma.sprintRun.findFirst.mockResolvedValue(null)
mockPrisma.story.findMany.mockResolvedValue([STORY_OK])
mockPrisma.claudeQuestion.findMany.mockResolvedValue([])
mockPrisma.sprintRun.create.mockResolvedValue({ id: 'run-1' })
mockPrisma.claudeJob.create.mockResolvedValue({ id: 'job-x' })
const result = await startSprintRunAction({ sprint_id: 'sprint-1' })
expect(result).toEqual({ ok: true, sprint_run_id: 'run-1', jobs_count: 2 })
expect(mockPrisma.sprintRun.create).toHaveBeenCalledWith({
data: expect.objectContaining({
sprint_id: 'sprint-1',
started_by_id: 'user-1',
status: 'QUEUED',
pr_strategy: 'SPRINT',
}),
})
expect(mockPrisma.claudeJob.create).toHaveBeenCalledTimes(2)
})
})
describe('startSprintRunAction — pre-flight blockers', () => {
it('blokkeert wanneer task geen implementation_plan heeft', async () => {
mockPrisma.sprint.findUnique.mockResolvedValue(SPRINT_OK)
mockPrisma.sprintRun.findFirst.mockResolvedValue(null)
mockPrisma.story.findMany.mockResolvedValue([
{
...STORY_OK,
tasks: [
{ id: 'task-1', code: 'T-1', title: 'T1', priority: 1, sort_order: 1, implementation_plan: null },
],
},
])
mockPrisma.claudeQuestion.findMany.mockResolvedValue([])
const result = await startSprintRunAction({ sprint_id: 'sprint-1' })
expect(result).toMatchObject({ ok: false, error: 'PRE_FLIGHT_BLOCKED' })
if (result.ok === false && 'blockers' in result) {
expect(result.blockers).toContainEqual({
type: 'task_no_plan',
id: 'task-1',
label: 'T-1: T1',
})
}
expect(mockPrisma.sprintRun.create).not.toHaveBeenCalled()
})
it('blokkeert wanneer er een open ClaudeQuestion in scope is', async () => {
mockPrisma.sprint.findUnique.mockResolvedValue(SPRINT_OK)
mockPrisma.sprintRun.findFirst.mockResolvedValue(null)
mockPrisma.story.findMany.mockResolvedValue([STORY_OK])
mockPrisma.claudeQuestion.findMany.mockResolvedValue([
{ id: 'q-1', question: 'Welke route?' },
])
const result = await startSprintRunAction({ sprint_id: 'sprint-1' })
expect(result).toMatchObject({ ok: false, error: 'PRE_FLIGHT_BLOCKED' })
if (result.ok === false && 'blockers' in result) {
expect(result.blockers).toContainEqual({
type: 'open_question',
id: 'q-1',
label: 'Welke route?',
})
}
})
it('blokkeert wanneer een PBI BLOCKED of FAILED is', async () => {
mockPrisma.sprint.findUnique.mockResolvedValue(SPRINT_OK)
mockPrisma.sprintRun.findFirst.mockResolvedValue(null)
mockPrisma.story.findMany.mockResolvedValue([
{ ...STORY_OK, pbi: { ...STORY_OK.pbi, status: 'BLOCKED' } },
])
mockPrisma.claudeQuestion.findMany.mockResolvedValue([])
const result = await startSprintRunAction({ sprint_id: 'sprint-1' })
expect(result).toMatchObject({ ok: false, error: 'PRE_FLIGHT_BLOCKED' })
if (result.ok === false && 'blockers' in result) {
expect(result.blockers).toContainEqual({
type: 'pbi_blocked',
id: 'pbi-1',
label: 'PBI-1: PBI',
})
}
})
})
describe('startSprintRunAction — SPRINT_BATCH', () => {
const SPRINT_BATCH = {
...SPRINT_OK,
product: {
id: 'prod-1',
pr_strategy: 'SPRINT_BATCH',
repo_url: 'https://github.com/example/main',
},
}
it('blokkeert task met afwijkende repo_url', async () => {
mockPrisma.sprint.findUnique.mockResolvedValue(SPRINT_BATCH)
mockPrisma.sprintRun.findFirst.mockResolvedValue(null)
mockPrisma.story.findMany.mockResolvedValue([
{
...STORY_OK,
tasks: [
{
id: 'task-1',
code: 'T-1',
title: 'In main repo',
priority: 1,
sort_order: 1,
implementation_plan: 'plan',
repo_url: null,
},
{
id: 'task-2',
code: 'T-2',
title: 'Cross-repo',
priority: 1,
sort_order: 2,
implementation_plan: 'plan',
repo_url: 'https://github.com/example/other',
},
],
},
])
mockPrisma.claudeQuestion.findMany.mockResolvedValue([])
const result = await startSprintRunAction({ sprint_id: 'sprint-1' })
expect(result).toMatchObject({ ok: false, error: 'PRE_FLIGHT_BLOCKED' })
if (result.ok === false && 'blockers' in result) {
expect(result.blockers).toContainEqual({
type: 'task_cross_repo',
id: 'task-2',
label: 'T-2: Cross-repo',
})
}
expect(mockPrisma.sprintRun.create).not.toHaveBeenCalled()
})
it('staat tasks toe wanneer repo_url leeg is of gelijk aan product.repo_url', async () => {
mockPrisma.sprint.findUnique.mockResolvedValue(SPRINT_BATCH)
mockPrisma.sprintRun.findFirst.mockResolvedValue(null)
mockPrisma.story.findMany.mockResolvedValue([
{
...STORY_OK,
tasks: [
{
id: 'task-1',
code: 'T-1',
title: 'No override',
priority: 1,
sort_order: 1,
implementation_plan: 'plan',
repo_url: null,
},
{
id: 'task-2',
code: 'T-2',
title: 'Same repo',
priority: 1,
sort_order: 2,
implementation_plan: 'plan',
repo_url: 'https://github.com/example/main',
},
],
},
])
mockPrisma.claudeQuestion.findMany.mockResolvedValue([])
mockPrisma.sprintRun.create.mockResolvedValue({ id: 'run-batch' })
mockPrisma.claudeJob.create.mockResolvedValue({ id: 'job-sprint' })
const result = await startSprintRunAction({ sprint_id: 'sprint-1' })
expect(result).toMatchObject({ ok: true, sprint_run_id: 'run-batch' })
// Eén SPRINT_IMPLEMENTATION-job, niet per-task
expect(mockPrisma.claudeJob.create).toHaveBeenCalledTimes(1)
expect(mockPrisma.claudeJob.create).toHaveBeenCalledWith({
data: expect.objectContaining({
kind: 'SPRINT_IMPLEMENTATION',
sprint_run_id: 'run-batch',
product_id: 'prod-1',
}),
})
})
})
describe('startSprintRunAction — guards', () => {
it('weigert wanneer Sprint niet ACTIVE is', async () => {
mockPrisma.sprint.findUnique.mockResolvedValue({ ...SPRINT_OK, status: 'CLOSED' })
const result = await startSprintRunAction({ sprint_id: 'sprint-1' })
expect(result).toMatchObject({ ok: false, error: 'SPRINT_NOT_ACTIVE' })
})
it('weigert wanneer er al een actieve SprintRun is', async () => {
mockPrisma.sprint.findUnique.mockResolvedValue(SPRINT_OK)
mockPrisma.sprintRun.findFirst.mockResolvedValue({ id: 'run-existing', status: 'RUNNING' })
const result = await startSprintRunAction({ sprint_id: 'sprint-1' })
expect(result).toMatchObject({ ok: false, error: 'SPRINT_RUN_ALREADY_ACTIVE' })
})
it('weigert demo-sessie', async () => {
mockSession.mockResolvedValue({ userId: 'demo', isDemo: true })
const result = await startSprintRunAction({ sprint_id: 'sprint-1' })
expect(result).toMatchObject({ ok: false, code: 403 })
})
})
describe('resumeSprintAction', () => {
it('zet sprint en cascade-statuses terug en maakt nieuwe SprintRun', async () => {
// Eerste findUnique (resume) ziet de sprint nog op FAILED;
// de tweede call (binnen startSprintRunCore na de update) ziet ACTIVE.
mockPrisma.sprint.findUnique
.mockResolvedValueOnce({ ...SPRINT_OK, status: 'FAILED' })
.mockResolvedValue(SPRINT_OK)
mockPrisma.sprintRun.findFirst.mockResolvedValue(null)
mockPrisma.story.findMany.mockImplementation(async (args: { select?: { pbi_id?: boolean } }) => {
if (args.select?.pbi_id) return [{ pbi_id: 'pbi-1' }]
return [STORY_OK]
})
mockPrisma.claudeQuestion.findMany.mockResolvedValue([])
mockPrisma.sprintRun.create.mockResolvedValue({ id: 'run-2' })
mockPrisma.claudeJob.create.mockResolvedValue({ id: 'job-x' })
const result = await resumeSprintAction({ sprint_id: 'sprint-1' })
expect(result).toMatchObject({ ok: true, sprint_run_id: 'run-2' })
expect(mockPrisma.sprint.update).toHaveBeenCalledWith({
where: { id: 'sprint-1' },
data: { status: 'OPEN', completed_at: null },
})
expect(mockPrisma.story.updateMany).toHaveBeenCalledWith({
where: { sprint_id: 'sprint-1', status: 'FAILED' },
data: { status: 'IN_SPRINT' },
})
expect(mockPrisma.task.updateMany).toHaveBeenCalledWith({
where: { story: { sprint_id: 'sprint-1' }, status: 'FAILED' },
data: { status: 'TO_DO' },
})
})
it('weigert als sprint niet FAILED is', async () => {
mockPrisma.sprint.findUnique.mockResolvedValue({ ...SPRINT_OK, status: 'OPEN' })
const result = await resumeSprintAction({ sprint_id: 'sprint-1' })
expect(result).toMatchObject({ ok: false, error: 'SPRINT_NOT_FAILED' })
})
})
describe('cancelSprintRunAction', () => {
it('zet SprintRun op CANCELLED en cancelt openstaande jobs', async () => {
mockPrisma.sprintRun.findUnique.mockResolvedValue({
id: 'run-1',
status: 'RUNNING',
sprint_id: 'sprint-1',
})
const result = await cancelSprintRunAction({ sprint_run_id: 'run-1' })
expect(result).toEqual({ ok: true })
expect(mockPrisma.sprintRun.update).toHaveBeenCalledWith({
where: { id: 'run-1' },
data: expect.objectContaining({ status: 'CANCELLED' }),
})
expect(mockPrisma.claudeJob.updateMany).toHaveBeenCalledWith(expect.objectContaining({
where: expect.objectContaining({
sprint_run_id: 'run-1',
status: { in: ['QUEUED', 'CLAIMED', 'RUNNING'] },
}),
data: expect.objectContaining({ status: 'CANCELLED' }),
}))
})
it('weigert wanneer SprintRun al DONE is', async () => {
mockPrisma.sprintRun.findUnique.mockResolvedValue({
id: 'run-1',
status: 'DONE',
sprint_id: 'sprint-1',
})
const result = await cancelSprintRunAction({ sprint_run_id: 'run-1' })
expect(result).toMatchObject({ ok: false, error: 'SPRINT_RUN_NOT_CANCELLABLE' })
})
})

View file

@ -49,7 +49,7 @@ const mockPrisma = prisma as unknown as {
$transaction: ReturnType<typeof vi.fn>
}
const SPRINT = { id: 'sprint-1', product_id: 'product-1', status: 'ACTIVE' }
const SPRINT = { id: 'sprint-1', product_id: 'product-1', status: 'OPEN' }
beforeEach(() => {
vi.clearAllMocks()

View file

@ -50,7 +50,7 @@ const mockRequireProductWriter = requireProductWriter as ReturnType<typeof vi.fn
const mockGetIronSession = getIronSession as ReturnType<typeof vi.fn>
const STORY = { id: 'story-1', product_id: 'product-1', assignee_id: null }
const SPRINT = { id: 'sprint-1', product_id: 'product-1', status: 'ACTIVE' }
const SPRINT = { id: 'sprint-1', product_id: 'product-1', status: 'OPEN' }
beforeEach(() => {
vi.clearAllMocks()

View file

@ -23,6 +23,24 @@ vi.mock('@/lib/prisma', () => ({
story: {
findFirst: vi.fn(),
findUniqueOrThrow: vi.fn(),
findMany: vi.fn(),
update: vi.fn(),
},
pbi: {
findUniqueOrThrow: vi.fn(),
findMany: vi.fn(),
update: vi.fn(),
},
sprint: {
findUniqueOrThrow: vi.fn(),
update: vi.fn(),
},
claudeJob: {
findFirst: vi.fn(),
updateMany: vi.fn(),
},
sprintRun: {
findUnique: vi.fn(),
update: vi.fn(),
},
$transaction: vi.fn(),
@ -44,6 +62,24 @@ const mockPrisma = prisma as unknown as {
story: {
findFirst: ReturnType<typeof vi.fn>
findUniqueOrThrow: ReturnType<typeof vi.fn>
findMany: ReturnType<typeof vi.fn>
update: ReturnType<typeof vi.fn>
}
pbi: {
findUniqueOrThrow: ReturnType<typeof vi.fn>
findMany: ReturnType<typeof vi.fn>
update: ReturnType<typeof vi.fn>
}
sprint: {
findUniqueOrThrow: ReturnType<typeof vi.fn>
update: ReturnType<typeof vi.fn>
}
claudeJob: {
findFirst: ReturnType<typeof vi.fn>
updateMany: ReturnType<typeof vi.fn>
}
sprintRun: {
findUnique: ReturnType<typeof vi.fn>
update: ReturnType<typeof vi.fn>
}
$transaction: ReturnType<typeof vi.fn>
@ -154,7 +190,14 @@ describe('saveTask — edit met status-promotie', () => {
implementation_plan: null,
})
mockPrisma.task.findMany.mockResolvedValue([{ status: 'DONE' }, { status: 'DONE' }])
mockPrisma.story.findUniqueOrThrow.mockResolvedValue({ status: 'IN_SPRINT' })
mockPrisma.story.findUniqueOrThrow.mockResolvedValue({
id: 'story-1',
status: 'IN_SPRINT',
pbi_id: 'pbi-1',
sprint_id: null,
})
mockPrisma.story.findMany.mockResolvedValue([{ status: 'DONE' }])
mockPrisma.pbi.findUniqueOrThrow.mockResolvedValue({ id: 'pbi-1', status: 'READY' })
const result = await saveTask(
{ ...VALID_INPUT, status: 'DONE' },

View file

@ -0,0 +1,148 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
vi.mock('next/cache', () => ({ revalidatePath: vi.fn() }))
vi.mock('next/headers', () => ({
cookies: vi.fn().mockResolvedValue({
set: vi.fn(),
get: vi.fn(),
delete: vi.fn(),
}),
}))
vi.mock('iron-session', () => ({
getIronSession: vi.fn().mockResolvedValue({ userId: 'user-1', isDemo: false }),
}))
vi.mock('@/lib/session', () => ({
sessionOptions: { cookieName: 'test', password: 'test' },
}))
vi.mock('@/lib/product-access', () => ({
productAccessFilter: vi.fn().mockReturnValue({}),
getAccessibleProduct: vi.fn().mockResolvedValue({ id: 'product-1' }),
}))
vi.mock('@/lib/rate-limit', () => ({
enforceUserRateLimit: vi.fn().mockReturnValue(null),
}))
vi.mock('@/lib/code-server', () => ({
createWithCodeRetry: vi.fn(),
generateNextSprintCode: vi.fn(),
}))
vi.mock('@/lib/active-sprint', () => ({
setActiveSprintInSettings: vi.fn().mockResolvedValue(undefined),
}))
vi.mock('@/lib/prisma', () => ({
prisma: {
sprint: {
findFirst: vi.fn(),
update: vi.fn(),
},
story: {
findMany: vi.fn(),
updateMany: vi.fn(),
},
task: {
findMany: vi.fn(),
updateMany: vi.fn(),
},
$transaction: vi.fn(),
},
}))
import { prisma } from '@/lib/prisma'
import { updateSprintAction } from '@/actions/sprints'
type Mocked = {
sprint: {
findFirst: ReturnType<typeof vi.fn>
update: ReturnType<typeof vi.fn>
}
}
const mockPrisma = prisma as unknown as Mocked
beforeEach(() => {
vi.clearAllMocks()
mockPrisma.sprint.findFirst.mockReset().mockResolvedValue({
id: 'sprint-1',
product_id: 'product-1',
})
mockPrisma.sprint.update.mockReset().mockResolvedValue({})
})
describe('updateSprintAction', () => {
it('updates sprint_goal alone', async () => {
const result = await updateSprintAction({
sprintId: 'sprint-1',
fields: { goal: 'Nieuw doel' },
})
expect('success' in result).toBe(true)
expect(mockPrisma.sprint.update).toHaveBeenCalledWith({
where: { id: 'sprint-1' },
data: { sprint_goal: 'Nieuw doel' },
})
})
it('updates dates only', async () => {
await updateSprintAction({
sprintId: 'sprint-1',
fields: { startAt: '2026-06-01', endAt: '2026-06-14' },
})
expect(mockPrisma.sprint.update).toHaveBeenCalledWith({
where: { id: 'sprint-1' },
data: {
start_date: new Date('2026-06-01'),
end_date: new Date('2026-06-14'),
},
})
})
it('accepts null to clear a date', async () => {
await updateSprintAction({
sprintId: 'sprint-1',
fields: { startAt: null },
})
expect(mockPrisma.sprint.update).toHaveBeenCalledWith({
where: { id: 'sprint-1' },
data: { start_date: null },
})
})
it('rejects when sprint not accessible', async () => {
mockPrisma.sprint.findFirst.mockResolvedValue(null)
const result = await updateSprintAction({
sprintId: 'sprint-1',
fields: { goal: 'x' },
})
expect('error' in result).toBe(true)
if ('error' in result) {
expect(result.code).toBe(403)
}
expect(mockPrisma.sprint.update).not.toHaveBeenCalled()
})
it('rejects empty goal', async () => {
const result = await updateSprintAction({
sprintId: 'sprint-1',
fields: { goal: '' },
})
expect('error' in result).toBe(true)
expect(mockPrisma.sprint.update).not.toHaveBeenCalled()
})
it('rejects when no fields are supplied', async () => {
const result = await updateSprintAction({
sprintId: 'sprint-1',
fields: {},
})
// Schema-refine should reject; OR action treats empty data as no-op success.
// Current implementation: refine forces minstens één veld → 422 error.
expect('error' in result).toBe(true)
if ('error' in result) {
expect(result.code).toBe(422)
}
})
})

View file

@ -0,0 +1,82 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
vi.mock('next/headers', () => ({ cookies: vi.fn().mockResolvedValue({}) }))
vi.mock('iron-session', () => ({
getIronSession: vi.fn().mockResolvedValue({ userId: 'user-1', isDemo: false }),
}))
vi.mock('@/lib/session', () => ({
sessionOptions: { cookieName: 'test', password: 'test' },
}))
vi.mock('@/lib/prisma', () => ({
prisma: {
user: { findUnique: vi.fn() },
$transaction: vi.fn(async (fn: (tx: unknown) => Promise<unknown>) => {
return fn({
user: {
findUnique: vi.fn().mockResolvedValue({ settings: {} }),
update: vi.fn().mockResolvedValue({}),
},
})
}),
$executeRaw: vi.fn().mockResolvedValue(1),
},
}))
import { prisma } from '@/lib/prisma'
import { getIronSession } from 'iron-session'
import { updateUserSettingsAction } from '@/actions/user-settings'
const mockPrisma = prisma as unknown as {
user: { findUnique: ReturnType<typeof vi.fn> }
$transaction: ReturnType<typeof vi.fn>
$executeRaw: ReturnType<typeof vi.fn>
}
const mockGetIronSession = getIronSession as ReturnType<typeof vi.fn>
beforeEach(() => {
vi.clearAllMocks()
mockGetIronSession.mockResolvedValue({ userId: 'user-1', isDemo: false })
mockPrisma.$executeRaw.mockResolvedValue(1)
})
describe('updateUserSettingsAction', () => {
it('returns 401 when not logged in', async () => {
mockGetIronSession.mockResolvedValue({ userId: undefined, isDemo: false })
const result = await updateUserSettingsAction({})
expect(result).toEqual({ error: 'Niet ingelogd', code: 401 })
})
it('returns 403 for demo accounts', async () => {
mockGetIronSession.mockResolvedValue({ userId: 'user-1', isDemo: true })
const result = await updateUserSettingsAction({})
expect('error' in result && result.code).toBe(403)
})
it('returns 422 when patch is invalid', async () => {
const result = await updateUserSettingsAction({
views: { sprintBacklog: { filterStatus: 'NONSENSE' } },
} as never)
expect('error' in result && result.code).toBe(422)
})
it('merges with current settings and emits notify on success', async () => {
const existingFindUnique = vi.fn().mockResolvedValue({
settings: { views: { sprintBacklog: { sort: 'code' } } },
})
const update = vi.fn().mockResolvedValue({})
mockPrisma.$transaction.mockImplementationOnce(async (fn: (tx: unknown) => Promise<unknown>) => {
return fn({ user: { findUnique: existingFindUnique, update } })
})
const result = await updateUserSettingsAction({
views: { sprintBacklog: { sortDir: 'desc' } },
})
expect('success' in result && result.success).toBe(true)
expect(update).toHaveBeenCalledWith({
where: { id: 'user-1' },
data: { settings: { views: { sprintBacklog: { sort: 'code', sortDir: 'desc' } } } },
})
expect(mockPrisma.$executeRaw).toHaveBeenCalled()
})
})

View file

@ -1,131 +0,0 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
const { mockGetSession } = vi.hoisted(() => ({ mockGetSession: vi.fn() }))
vi.mock('@/lib/auth', () => ({ getSession: mockGetSession }))
vi.mock('@/lib/product-access', () => ({
getAccessibleProduct: vi.fn(),
}))
import { getAccessibleProduct } from '@/lib/product-access'
import type { NextRequest } from 'next/server'
import { GET } from '@/app/api/realtime/backlog/route'
import { useBacklogStore } from '@/stores/backlog-store'
const mockGetAccessibleProduct = getAccessibleProduct as ReturnType<typeof vi.fn>
function makeReq(productId?: string): NextRequest {
const url = productId
? `http://localhost/api/realtime/backlog?product_id=${productId}`
: 'http://localhost/api/realtime/backlog'
return {
signal: new AbortController().signal,
nextUrl: new URL(url),
} as unknown as NextRequest
}
beforeEach(() => {
vi.clearAllMocks()
})
describe('GET /api/realtime/backlog', () => {
it('401 when not authenticated', async () => {
mockGetSession.mockResolvedValue({ userId: undefined, isDemo: false })
const res = await GET(makeReq('prod-1'))
expect(res.status).toBe(401)
expect(mockGetAccessibleProduct).not.toHaveBeenCalled()
})
it('400 when product_id is missing', async () => {
mockGetSession.mockResolvedValue({ userId: 'user-1', isDemo: false })
const res = await GET(makeReq())
expect(res.status).toBe(400)
})
it('403 when user has no access to the product', async () => {
mockGetSession.mockResolvedValue({ userId: 'user-1', isDemo: false })
mockGetAccessibleProduct.mockResolvedValue(null)
const res = await GET(makeReq('prod-1'))
expect(res.status).toBe(403)
expect(mockGetAccessibleProduct).toHaveBeenCalledWith('prod-1', 'user-1')
})
it('500 when DIRECT_URL and DATABASE_URL are absent', async () => {
mockGetSession.mockResolvedValue({ userId: 'user-1', isDemo: false })
mockGetAccessibleProduct.mockResolvedValue({ id: 'prod-1' })
const before = { DIRECT_URL: process.env.DIRECT_URL, DATABASE_URL: process.env.DATABASE_URL }
delete process.env.DIRECT_URL
delete process.env.DATABASE_URL
try {
const res = await GET(makeReq('prod-1'))
expect(res.status).toBe(500)
} finally {
if (before.DIRECT_URL !== undefined) process.env.DIRECT_URL = before.DIRECT_URL
if (before.DATABASE_URL !== undefined) process.env.DATABASE_URL = before.DATABASE_URL
}
})
it('demo user is allowed (no 403) when product is accessible', async () => {
mockGetSession.mockResolvedValue({ userId: 'demo-user', isDemo: true })
mockGetAccessibleProduct.mockResolvedValue({ id: 'prod-1' })
const before = { DIRECT_URL: process.env.DIRECT_URL, DATABASE_URL: process.env.DATABASE_URL }
delete process.env.DIRECT_URL
delete process.env.DATABASE_URL
try {
const res = await GET(makeReq('prod-1'))
// Fails at 500 (no DB URL) — not 403, confirming demo user is not blocked
expect(res.status).toBe(500)
} finally {
if (before.DIRECT_URL !== undefined) process.env.DIRECT_URL = before.DIRECT_URL
if (before.DATABASE_URL !== undefined) process.env.DATABASE_URL = before.DATABASE_URL
}
})
})
// shouldEmit scope filter — white-box unit tests
describe('shouldEmit scope filter (via backlog-store reducer)', () => {
it('applyChange: pbi INSERT adds to pbis array', () => {
useBacklogStore.setState({ pbis: [], storiesByPbi: {}, tasksByStory: {} })
const pbi = { id: 'pbi-1', code: 'PBI-1', title: 'Test', priority: 2, created_at: new Date(), status: 'ready' as const }
useBacklogStore.getState().applyChange('pbi', 'I', pbi)
expect(useBacklogStore.getState().pbis).toHaveLength(1)
expect(useBacklogStore.getState().pbis[0].id).toBe('pbi-1')
})
it('applyChange: pbi UPDATE patches existing pbi', () => {
const pbi = { id: 'pbi-1', code: 'PBI-1', title: 'Old', priority: 2, created_at: new Date(), status: 'ready' as const }
useBacklogStore.setState({ pbis: [pbi], storiesByPbi: {}, tasksByStory: {} })
useBacklogStore.getState().applyChange('pbi', 'U', { id: 'pbi-1', title: 'New' })
expect(useBacklogStore.getState().pbis[0].title).toBe('New')
})
it('applyChange: pbi DELETE removes pbi', () => {
const pbi = { id: 'pbi-1', code: 'PBI-1', title: 'Test', priority: 2, created_at: new Date(), status: 'ready' as const }
useBacklogStore.setState({ pbis: [pbi], storiesByPbi: {}, tasksByStory: {} })
useBacklogStore.getState().applyChange('pbi', 'D', { id: 'pbi-1' })
expect(useBacklogStore.getState().pbis).toHaveLength(0)
})
it('applyChange: story INSERT adds to storiesByPbi', () => {
useBacklogStore.setState({ pbis: [], storiesByPbi: { 'pbi-1': [] }, tasksByStory: {} })
const story = { id: 'story-1', code: 'ST-1', title: 'S', description: null, acceptance_criteria: null, priority: 2, status: 'OPEN', pbi_id: 'pbi-1', created_at: new Date() }
useBacklogStore.getState().applyChange('story', 'I', story)
expect(useBacklogStore.getState().storiesByPbi['pbi-1']).toHaveLength(1)
})
it('applyChange: story DELETE removes from correct pbi bucket', () => {
const story = { id: 'story-1', code: 'ST-1', title: 'S', description: null, acceptance_criteria: null, priority: 2, status: 'OPEN', pbi_id: 'pbi-1', created_at: new Date() }
useBacklogStore.setState({ pbis: [], storiesByPbi: { 'pbi-1': [story] }, tasksByStory: {} })
useBacklogStore.getState().applyChange('story', 'D', { id: 'story-1' })
expect(useBacklogStore.getState().storiesByPbi['pbi-1']).toHaveLength(0)
})
it('applyChange: task UPDATE patches task across story buckets', () => {
const task = { id: 'task-1', title: 'Old', description: null, priority: 2, status: 'TO_DO', sort_order: 1, story_id: 'story-1', created_at: new Date() }
useBacklogStore.setState({ pbis: [], storiesByPbi: {}, tasksByStory: { 'story-1': [task] } })
useBacklogStore.getState().applyChange('task', 'U', { id: 'task-1', status: 'IN_PROGRESS' })
expect(useBacklogStore.getState().tasksByStory['story-1'][0].status).toBe('IN_PROGRESS')
})
})

View file

@ -41,7 +41,7 @@ describe('POST /api/cron/cleanup-agent-artifacts', () => {
expect(mockPrisma.claudeJob.deleteMany).not.toHaveBeenCalled()
})
it('200 met juiste secret + deleteMany aangeroepen voor FAILED/CANCELLED ouder dan 7 dagen', async () => {
it('200 met juiste secret + deleteMany aangeroepen voor FAILED/CANCELLED/SKIPPED ouder dan 7 dagen', async () => {
mockPrisma.claudeJob.deleteMany.mockResolvedValue({ count: 5 })
const res = await POST(makeReq({ authorization: 'Bearer ' + SECRET }))
@ -51,7 +51,7 @@ describe('POST /api/cron/cleanup-agent-artifacts', () => {
expect(body.ran_at).toMatch(/^\d{4}-\d{2}-\d{2}T/)
const arg = mockPrisma.claudeJob.deleteMany.mock.calls[0][0]
expect(arg.where.status).toEqual({ in: ['FAILED', 'CANCELLED'] })
expect(arg.where.status).toEqual({ in: ['FAILED', 'CANCELLED', 'SKIPPED'] })
expect(arg.where.finished_at.lt).toBeInstanceOf(Date)
// cutoff should be approximately 7 days ago

View file

@ -0,0 +1,120 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
vi.mock('@/lib/prisma', () => ({
prisma: {
product: { findFirst: vi.fn() },
story: { findMany: vi.fn() },
},
}))
vi.mock('@/lib/api-auth', () => ({
authenticateApiRequest: vi.fn(),
}))
vi.mock('@/lib/product-access', () => ({
productAccessFilter: vi.fn().mockReturnValue({}),
}))
import { prisma } from '@/lib/prisma'
import { authenticateApiRequest } from '@/lib/api-auth'
import { GET } from '@/app/api/products/[id]/cross-sprint-blocks/route'
const mockPrisma = prisma as unknown as {
product: { findFirst: ReturnType<typeof vi.fn> }
story: { findMany: ReturnType<typeof vi.fn> }
}
const mockAuth = authenticateApiRequest as unknown as ReturnType<typeof vi.fn>
function makeRequest(url: string) {
return new Request(url)
}
describe('GET /api/products/[id]/cross-sprint-blocks', () => {
beforeEach(() => {
vi.clearAllMocks()
mockPrisma.product.findFirst.mockReset()
mockPrisma.story.findMany.mockReset()
mockAuth.mockReset().mockResolvedValue({ userId: 'user-1' })
})
it('returns blocking sprint info per story for happy path', async () => {
mockPrisma.product.findFirst.mockResolvedValue({ id: 'p1' })
mockPrisma.story.findMany.mockResolvedValue([
{
id: 'story-1',
sprint: { id: 'sprint-x', code: 'SP-X' },
},
{
id: 'story-2',
sprint: { id: 'sprint-y', code: 'SP-Y' },
},
])
const req = makeRequest(
'http://localhost/api/products/p1/cross-sprint-blocks?excludeSprintId=sp-1&pbiIds=pbiA',
)
const res = await GET(req, { params: Promise.resolve({ id: 'p1' }) })
expect(res.status).toBe(200)
const body = await res.json()
expect(body).toEqual({
'story-1': { sprintId: 'sprint-x', sprintName: 'SP-X' },
'story-2': { sprintId: 'sprint-y', sprintName: 'SP-Y' },
})
})
it('rejects when pbiIds is missing', async () => {
const req = makeRequest(
'http://localhost/api/products/p1/cross-sprint-blocks?excludeSprintId=sp-1',
)
const res = await GET(req, { params: Promise.resolve({ id: 'p1' }) })
expect(res.status).toBe(400)
})
it('rejects when pbiIds is empty', async () => {
const req = makeRequest(
'http://localhost/api/products/p1/cross-sprint-blocks?pbiIds=',
)
const res = await GET(req, { params: Promise.resolve({ id: 'p1' }) })
expect(res.status).toBe(400)
})
it('returns 404 when product is not accessible', async () => {
mockPrisma.product.findFirst.mockResolvedValue(null)
const req = makeRequest(
'http://localhost/api/products/p1/cross-sprint-blocks?pbiIds=pbiA',
)
const res = await GET(req, { params: Promise.resolve({ id: 'p1' }) })
expect(res.status).toBe(404)
})
it('returns auth error when authenticate fails', async () => {
mockAuth.mockResolvedValue({ error: 'Niet ingelogd', status: 401 })
const req = makeRequest(
'http://localhost/api/products/p1/cross-sprint-blocks?pbiIds=pbiA',
)
const res = await GET(req, { params: Promise.resolve({ id: 'p1' }) })
expect(res.status).toBe(401)
})
it('passes NOT excludeSprintId to prisma when provided', async () => {
mockPrisma.product.findFirst.mockResolvedValue({ id: 'p1' })
mockPrisma.story.findMany.mockResolvedValue([])
const req = makeRequest(
'http://localhost/api/products/p1/cross-sprint-blocks?excludeSprintId=sp-active&pbiIds=pbiA',
)
await GET(req, { params: Promise.resolve({ id: 'p1' }) })
const callArg = mockPrisma.story.findMany.mock.calls[0][0] as {
where: Record<string, unknown>
}
expect(callArg.where).toMatchObject({
pbi_id: { in: ['pbiA'] },
product_id: 'p1',
sprint_id: { not: null },
NOT: { sprint_id: 'sp-active' },
sprint: { status: 'OPEN' },
})
})
})

194
__tests__/api/ideas.test.ts Normal file
View file

@ -0,0 +1,194 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
vi.mock('@/lib/prisma', () => ({
prisma: {
product: { findFirst: vi.fn() },
idea: {
findFirst: vi.fn(),
findMany: vi.fn(),
create: vi.fn(),
update: vi.fn(),
},
ideaLog: { findMany: vi.fn() },
$transaction: vi.fn(),
},
}))
vi.mock('@/lib/api-auth', () => ({
authenticateApiRequest: vi.fn(),
}))
vi.mock('@/lib/idea-code-server', () => ({
nextIdeaCode: vi.fn().mockResolvedValue('IDEA-001'),
}))
import { prisma } from '@/lib/prisma'
import { authenticateApiRequest } from '@/lib/api-auth'
import { GET as getIdeas, POST as postIdea } from '@/app/api/ideas/route'
import { GET as getIdea, PATCH as patchIdea } from '@/app/api/ideas/[id]/route'
type M = {
product: { findFirst: ReturnType<typeof vi.fn> }
idea: { findFirst: ReturnType<typeof vi.fn>; findMany: ReturnType<typeof vi.fn>; create: ReturnType<typeof vi.fn>; update: ReturnType<typeof vi.fn> }
ideaLog: { findMany: ReturnType<typeof vi.fn> }
$transaction: ReturnType<typeof vi.fn>
}
const m = prisma as unknown as M
const mockAuth = authenticateApiRequest as ReturnType<typeof vi.fn>
const NOW = new Date('2026-05-04T19:00:00Z')
const IDEA_ROW = {
id: 'idea-1',
user_id: 'user-1',
code: 'IDEA-001',
title: 'Plant-watering reminder',
description: null,
status: 'DRAFT' as const,
product_id: null,
product: null,
pbi: null,
pbi_id: null,
archived: false,
grill_md: null,
plan_md: null,
created_at: NOW,
updated_at: NOW,
}
function makeRequest(method: 'GET' | 'POST' | 'PATCH', url: string, body?: unknown): Request {
return new Request(`http://localhost${url}`, {
method,
headers: {
Authorization: 'Bearer test-token',
'Content-Type': 'application/json',
},
body: body !== undefined ? JSON.stringify(body) : undefined,
})
}
beforeEach(() => {
vi.clearAllMocks()
mockAuth.mockResolvedValue({ userId: 'user-1', isDemo: false })
m.$transaction.mockImplementation(async (arg: unknown) => {
if (typeof arg === 'function') return (arg as (tx: unknown) => unknown)(m)
return arg
})
})
describe('GET /api/ideas', () => {
it('returns user ideas (DTO shape)', async () => {
m.idea.findMany.mockResolvedValueOnce([IDEA_ROW])
const res = await getIdeas(makeRequest('GET', '/api/ideas'))
expect(res.status).toBe(200)
const body = await res.json()
expect(body.ideas).toHaveLength(1)
expect(body.ideas[0]).toMatchObject({
id: 'idea-1',
code: 'IDEA-001',
status: 'draft',
has_grill_md: false,
})
})
it('rejects unauthenticated', async () => {
mockAuth.mockResolvedValueOnce({ error: 'Unauthorized', status: 401 })
const res = await getIdeas(makeRequest('GET', '/api/ideas'))
expect(res.status).toBe(401)
})
it('filters by archived=false param', async () => {
m.idea.findMany.mockResolvedValueOnce([])
await getIdeas(makeRequest('GET', '/api/ideas?archived=false'))
expect(m.idea.findMany).toHaveBeenCalledWith(
expect.objectContaining({
where: expect.objectContaining({ archived: false, user_id: 'user-1' }),
}),
)
})
})
describe('POST /api/ideas', () => {
it('creates idea and returns 201', async () => {
m.idea.create.mockResolvedValueOnce(IDEA_ROW)
const res = await postIdea(makeRequest('POST', '/api/ideas', { title: 'Plant-watering reminder' }))
expect(res.status).toBe(201)
const body = await res.json()
expect(body.idea).toMatchObject({ id: 'idea-1', code: 'IDEA-001', status: 'draft' })
})
it('rejects demo with 403', async () => {
mockAuth.mockResolvedValueOnce({ userId: 'demo-1', isDemo: true })
const res = await postIdea(makeRequest('POST', '/api/ideas', { title: 'x' }))
expect(res.status).toBe(403)
})
it('rejects empty title with 422', async () => {
const res = await postIdea(makeRequest('POST', '/api/ideas', { title: '' }))
expect(res.status).toBe(422)
})
it('rejects malformed JSON with 400', async () => {
const req = new Request('http://localhost/api/ideas', {
method: 'POST',
headers: { Authorization: 'Bearer test', 'Content-Type': 'application/json' },
body: 'not-json',
})
const res = await postIdea(req)
expect(res.status).toBe(400)
})
it('returns 404 when product_id refers to a foreign product', async () => {
m.product.findFirst.mockResolvedValueOnce(null)
const res = await postIdea(
makeRequest('POST', '/api/ideas', {
title: 'x',
product_id: 'cmohrysyj0000rd17clnjy4tc',
}),
)
expect(res.status).toBe(404)
})
})
describe('GET /api/ideas/[id]', () => {
it('returns idea + logs', async () => {
m.idea.findFirst.mockResolvedValueOnce(IDEA_ROW)
m.ideaLog.findMany.mockResolvedValueOnce([
{ id: 'l-1', type: 'NOTE', content: 'x', metadata: null, created_at: NOW },
])
const ctx = { params: Promise.resolve({ id: 'idea-1' }) }
const res = await getIdea(makeRequest('GET', '/api/ideas/idea-1'), ctx)
expect(res.status).toBe(200)
const body = await res.json()
expect(body.idea).toMatchObject({ id: 'idea-1' })
expect(body.logs).toHaveLength(1)
})
it('returns 404 (not 403) for foreign user — anti-enumeration', async () => {
m.idea.findFirst.mockResolvedValueOnce(null)
const ctx = { params: Promise.resolve({ id: 'idea-1' }) }
const res = await getIdea(makeRequest('GET', '/api/ideas/idea-1'), ctx)
expect(res.status).toBe(404)
})
})
describe('PATCH /api/ideas/[id]', () => {
const ctx = { params: Promise.resolve({ id: 'idea-1' }) }
it('updates editable idea', async () => {
m.idea.findFirst.mockResolvedValueOnce({ id: 'idea-1', status: 'DRAFT' })
m.idea.update.mockResolvedValueOnce({ ...IDEA_ROW, title: 'Updated' })
const res = await patchIdea(makeRequest('PATCH', '/api/ideas/idea-1', { title: 'Updated' }), ctx)
expect(res.status).toBe(200)
})
it('blocks demo with 403', async () => {
mockAuth.mockResolvedValueOnce({ userId: 'demo-1', isDemo: true })
const res = await patchIdea(makeRequest('PATCH', '/api/ideas/idea-1', { title: 'x' }), ctx)
expect(res.status).toBe(403)
})
it('blocks update on PLANNED with 422', async () => {
m.idea.findFirst.mockResolvedValueOnce({ id: 'idea-1', status: 'PLANNED' })
const res = await patchIdea(makeRequest('PATCH', '/api/ideas/idea-1', { title: 'x' }), ctx)
expect(res.status).toBe(422)
})
})

View file

@ -25,7 +25,7 @@ const mockPrisma = prisma as unknown as {
}
const mockAuth = authenticateApiRequest as ReturnType<typeof vi.fn>
const SPRINT = { id: 'sprint-1', product_id: 'prod-1', status: 'ACTIVE' }
const SPRINT = { id: 'sprint-1', product_id: 'prod-1', status: 'OPEN' }
const STORY = {
id: 'story-1',
title: 'Account aanmaken',
@ -95,7 +95,7 @@ describe('GET /api/products/:id/next-story', () => {
expect(data.tasks[0]).toMatchObject({ id: 'task-1', status: 'todo' })
})
it('queries story ordered by priority then sort_order', async () => {
it('queries story ordered by sort_order only', async () => {
mockPrisma.sprint.findFirst.mockResolvedValue(SPRINT)
mockPrisma.story.findFirst.mockResolvedValue(STORY)
@ -103,7 +103,7 @@ describe('GET /api/products/:id/next-story', () => {
expect(mockPrisma.story.findFirst).toHaveBeenCalledWith(
expect.objectContaining({
orderBy: [{ priority: 'asc' }, { sort_order: 'asc' }],
orderBy: [{ sort_order: 'asc' }],
})
)
})

View file

@ -10,6 +10,7 @@ vi.mock('@/lib/prisma', () => ({
prisma: {
product: { findMany: vi.fn() },
claudeQuestion: { findMany: vi.fn() },
idea: { findMany: vi.fn().mockResolvedValue([]) },
},
}))

View file

@ -0,0 +1,75 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
vi.mock('server-only', () => ({}))
const { mockSendPushToUser } = vi.hoisted(() => ({
mockSendPushToUser: vi.fn(),
}))
vi.mock('@/lib/push-server', () => ({
sendPushToUser: mockSendPushToUser,
enabled: true,
}))
vi.hoisted(() => {
process.env.INTERNAL_PUSH_SECRET = 'a-valid-secret-that-is-at-least-32-chars'
})
import { POST } from '@/app/api/internal/push/send/route'
const VALID_BODY = {
userId: 'user-1',
payload: { title: 'Hello', body: 'World', url: '/dashboard' },
}
const SECRET = 'a-valid-secret-that-is-at-least-32-chars'
function makeRequest(body: unknown, bearer?: string) {
return new Request('http://localhost/api/internal/push/send', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
...(bearer !== undefined ? { Authorization: bearer } : {}),
},
body: JSON.stringify(body),
})
}
beforeEach(() => {
vi.clearAllMocks()
mockSendPushToUser.mockResolvedValue(undefined)
})
describe('POST /api/internal/push/send', () => {
it('returns 401 without authorization header', async () => {
const res = await POST(makeRequest(VALID_BODY))
expect(res.status).toBe(401)
expect(mockSendPushToUser).not.toHaveBeenCalled()
})
it('returns 401 with wrong bearer secret', async () => {
const res = await POST(makeRequest(VALID_BODY, 'Bearer wrong-secret'))
expect(res.status).toBe(401)
})
it('returns 422 with invalid body', async () => {
const res = await POST(makeRequest({ userId: '', payload: {} }, `Bearer ${SECRET}`))
expect(res.status).toBe(422)
expect(mockSendPushToUser).not.toHaveBeenCalled()
})
it('returns 204 and calls sendPushToUser on success', async () => {
const res = await POST(makeRequest(VALID_BODY, `Bearer ${SECRET}`))
expect(res.status).toBe(204)
expect(mockSendPushToUser).toHaveBeenCalledWith('user-1', VALID_BODY.payload)
})
it('returns 400 for invalid JSON', async () => {
const req = new Request('http://localhost/api/internal/push/send', {
method: 'POST',
headers: { Authorization: `Bearer ${SECRET}`, 'Content-Type': 'application/json' },
body: 'not-json',
})
const res = await POST(req)
expect(res.status).toBe(400)
})
})

View file

@ -1,111 +0,0 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
vi.mock('@/lib/prisma', () => ({
prisma: {
story: {
findFirst: vi.fn(),
},
task: {
update: vi.fn(),
},
$transaction: vi.fn(),
},
}))
vi.mock('@/lib/api-auth', () => ({
authenticateApiRequest: vi.fn(),
}))
import { prisma } from '@/lib/prisma'
import { authenticateApiRequest } from '@/lib/api-auth'
import { PATCH as patchReorder } from '@/app/api/stories/[id]/tasks/reorder/route'
const mockPrisma = prisma as unknown as {
story: { findFirst: ReturnType<typeof vi.fn> }
task: { update: ReturnType<typeof vi.fn> }
$transaction: ReturnType<typeof vi.fn>
}
const mockAuth = authenticateApiRequest as ReturnType<typeof vi.fn>
function makeStory(taskIds: string[]) {
return {
id: 'story-1',
product_id: 'prod-1',
tasks: taskIds.map(id => ({ id })),
}
}
function makeRequest(body: unknown, storyId = 'story-1'): [Request, { params: Promise<{ id: string }> }] {
return [
new Request(`http://localhost/api/stories/${storyId}/tasks/reorder`, {
method: 'PATCH',
headers: { Authorization: 'Bearer test-token', 'Content-Type': 'application/json' },
body: JSON.stringify(body),
}),
{ params: Promise.resolve({ id: storyId }) },
]
}
describe('PATCH /api/stories/:id/tasks/reorder', () => {
beforeEach(() => {
vi.clearAllMocks()
mockAuth.mockResolvedValue({ userId: 'user-1', isDemo: false })
mockPrisma.$transaction.mockResolvedValue([])
mockPrisma.task.update.mockResolvedValue({ id: 'task-1', sort_order: 1 })
})
// TC-RO-06 — body validation fires before story lookup
it('returns 422 when task_ids is an empty array', async () => {
const res = await patchReorder(...makeRequest({ task_ids: [] }))
expect(res.status).toBe(422)
expect(mockPrisma.story.findFirst).not.toHaveBeenCalled()
})
// TC-RO-07
it('returns 422 when task_ids is not an array', async () => {
const res = await patchReorder(...makeRequest({ task_ids: 'task-1' }))
expect(res.status).toBe(422)
expect(mockPrisma.story.findFirst).not.toHaveBeenCalled()
})
it('returns 422 when task_ids is missing entirely', async () => {
const res = await patchReorder(...makeRequest({}))
expect(res.status).toBe(422)
})
// TC-RO-08
it('returns 422 when task_ids contains an ID not belonging to the story', async () => {
mockPrisma.story.findFirst.mockResolvedValue(makeStory(['task-1', 'task-2']))
const res = await patchReorder(...makeRequest({ task_ids: ['task-1', 'task-from-other-story'] }))
const data = await res.json()
expect(res.status).toBe(422)
expect(data.error).toContain('task-from-other-story')
})
// TC-RO-09
it('reorders tasks and returns 200 with success: true', async () => {
mockPrisma.story.findFirst.mockResolvedValue(makeStory(['task-1', 'task-2', 'task-3']))
const res = await patchReorder(...makeRequest({ task_ids: ['task-3', 'task-1', 'task-2'] }))
const data = await res.json()
expect(res.status).toBe(200)
expect(data).toEqual({ success: true })
expect(mockPrisma.$transaction).toHaveBeenCalled()
})
it('updates each task with its new sort_order index', async () => {
mockPrisma.story.findFirst.mockResolvedValue(makeStory(['task-1', 'task-2']))
await patchReorder(...makeRequest({ task_ids: ['task-2', 'task-1'] }))
expect(mockPrisma.task.update).toHaveBeenCalledWith(
expect.objectContaining({ where: { id: 'task-2' }, data: { sort_order: 1 } })
)
expect(mockPrisma.task.update).toHaveBeenCalledWith(
expect.objectContaining({ where: { id: 'task-1' }, data: { sort_order: 2 } })
)
})
})

View file

@ -8,10 +8,13 @@ vi.mock('@/lib/prisma', () => ({
},
sprint: {
findFirst: vi.fn(),
findUniqueOrThrow: vi.fn(),
update: vi.fn(),
},
story: {
findFirst: vi.fn(),
findUniqueOrThrow: vi.fn(),
findMany: vi.fn(),
update: vi.fn(),
},
task: {
@ -19,6 +22,19 @@ vi.mock('@/lib/prisma', () => ({
update: vi.fn(),
findMany: vi.fn(),
},
pbi: {
findUniqueOrThrow: vi.fn(),
findMany: vi.fn(),
update: vi.fn(),
},
claudeJob: {
findFirst: vi.fn(),
updateMany: vi.fn(),
},
sprintRun: {
findUnique: vi.fn(),
update: vi.fn(),
},
storyLog: {
create: vi.fn(),
},
@ -38,17 +54,20 @@ import { authenticateApiRequest } from '@/lib/api-auth'
import { GET as getProducts } from '@/app/api/products/route'
import { GET as getNextStory } from '@/app/api/products/[id]/next-story/route'
import { GET as getSprintTasks } from '@/app/api/sprints/[id]/tasks/route'
import { PATCH as patchReorder } from '@/app/api/stories/[id]/tasks/reorder/route'
import { POST as postStoryLog } from '@/app/api/stories/[id]/log/route'
import { PATCH as patchTask } from '@/app/api/tasks/[id]/route'
import { POST as postTodo } from '@/app/api/todos/route'
const mockPrisma = prisma as unknown as {
product: { findMany: ReturnType<typeof vi.fn>; findFirst: ReturnType<typeof vi.fn> }
sprint: { findFirst: ReturnType<typeof vi.fn> }
sprint: {
findFirst: ReturnType<typeof vi.fn>
findUniqueOrThrow: ReturnType<typeof vi.fn>
update: ReturnType<typeof vi.fn>
}
story: {
findFirst: ReturnType<typeof vi.fn>
findUniqueOrThrow: ReturnType<typeof vi.fn>
findMany: ReturnType<typeof vi.fn>
update: ReturnType<typeof vi.fn>
}
task: {
@ -56,6 +75,19 @@ const mockPrisma = prisma as unknown as {
update: ReturnType<typeof vi.fn>
findMany: ReturnType<typeof vi.fn>
}
pbi: {
findUniqueOrThrow: ReturnType<typeof vi.fn>
findMany: ReturnType<typeof vi.fn>
update: ReturnType<typeof vi.fn>
}
claudeJob: {
findFirst: ReturnType<typeof vi.fn>
updateMany: ReturnType<typeof vi.fn>
}
sprintRun: {
findUnique: ReturnType<typeof vi.fn>
update: ReturnType<typeof vi.fn>
}
storyLog: { create: ReturnType<typeof vi.fn> }
todo: { create: ReturnType<typeof vi.fn> }
$transaction: ReturnType<typeof vi.fn>
@ -164,7 +196,7 @@ describe('GET /api/products/:id/next-story', () => {
expect.objectContaining({
where: expect.objectContaining({
product_id: 'prod-other',
status: 'ACTIVE',
status: 'OPEN',
product: expect.objectContaining({
OR: expect.arrayContaining([{ user_id: 'user-1' }]),
}),
@ -243,56 +275,6 @@ describe('GET /api/sprints/:id/tasks', () => {
})
})
// ─── PATCH /api/stories/:id/tasks/reorder ────────────────────────────────────
describe('PATCH /api/stories/:id/tasks/reorder', () => {
const VALID_BODY = { task_ids: ['task-x'] }
// TC-RO-01
it('returns 401 when no valid token provided', async () => {
mockAuth.mockResolvedValue(UNAUTHORIZED)
const res = await patchReorder(
makePatch('http://localhost/api/stories/story-1/tasks/reorder', VALID_BODY),
routeCtx('story-1')
)
expect(res.status).toBe(401)
})
// TC-RO-03
it('returns 403 for demo users', async () => {
mockAuth.mockResolvedValue(DEMO_AUTH)
const res = await patchReorder(
makePatch('http://localhost/api/stories/story-1/tasks/reorder', VALID_BODY),
routeCtx('story-1')
)
expect(res.status).toBe(403)
const data = await res.json()
expect(data.error).toBe('Niet beschikbaar in demo-modus')
})
// TC-RO-04 / TC-RO-05
it('returns 404 when story is not accessible to the authenticated user', async () => {
mockAuth.mockResolvedValue(USER_2_AUTH)
mockPrisma.story.findFirst.mockResolvedValue(null)
const res = await patchReorder(
makePatch('http://localhost/api/stories/story-1/tasks/reorder', VALID_BODY),
routeCtx('story-1')
)
expect(res.status).toBe(404)
expect(mockPrisma.story.findFirst).toHaveBeenCalledWith(
expect.objectContaining({
where: expect.objectContaining({
id: 'story-1',
product: expect.objectContaining({
OR: expect.arrayContaining([{ user_id: 'user-2' }]),
}),
}),
})
)
})
})
// ─── POST /api/stories/:id/log ────────────────────────────────────────────────
describe('POST /api/stories/:id/log', () => {
@ -410,7 +392,14 @@ describe('PATCH /api/tasks/:id', () => {
implementation_plan: null,
})
mockPrisma.task.findMany.mockResolvedValue([{ status: 'DONE' }])
mockPrisma.story.findUniqueOrThrow.mockResolvedValue({ status: 'DONE' })
mockPrisma.story.findUniqueOrThrow.mockResolvedValue({
id: 'story-1',
status: 'DONE',
pbi_id: 'pbi-1',
sprint_id: null,
})
mockPrisma.story.findMany.mockResolvedValue([{ status: 'DONE' }])
mockPrisma.pbi.findUniqueOrThrow.mockResolvedValue({ id: 'pbi-1', status: 'DONE' })
const res = await patchTask(
makePatch('http://localhost/api/tasks/task-1', { status: 'done' }),
@ -419,46 +408,3 @@ describe('PATCH /api/tasks/:id', () => {
expect(res.status).toBe(200)
})
})
// ─── POST /api/todos ──────────────────────────────────────────────────────────
describe('POST /api/todos', () => {
// product_id is required by the Zod schema (z.string().min(1))
const VALID_BODY = { title: 'Test todo', product_id: 'prod-1' }
// TC-TD-01
it('returns 401 when no valid token provided', async () => {
mockAuth.mockResolvedValue(UNAUTHORIZED)
const res = await postTodo(makePost('http://localhost/api/todos', VALID_BODY))
expect(res.status).toBe(401)
})
// TC-TD-03
it('returns 403 for demo users', async () => {
mockAuth.mockResolvedValue(DEMO_AUTH)
const res = await postTodo(makePost('http://localhost/api/todos', VALID_BODY))
expect(res.status).toBe(403)
const data = await res.json()
expect(data.error).toBe('Niet beschikbaar in demo-modus')
})
// TC-TD-08
it('returns 404 when product_id belongs to another user', async () => {
mockAuth.mockResolvedValue(USER_2_AUTH)
mockPrisma.product.findFirst.mockResolvedValue(null)
const res = await postTodo(
makePost('http://localhost/api/todos', { title: 'Todo', product_id: 'prod-owned-by-user-1' })
)
expect(res.status).toBe(404)
// Verify it queries by user_id, not productAccessFilter
expect(mockPrisma.product.findFirst).toHaveBeenCalledWith(
expect.objectContaining({
where: expect.objectContaining({
id: 'prod-owned-by-user-1',
user_id: 'user-2',
}),
})
)
})
})

View file

@ -0,0 +1,121 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
vi.mock('@/lib/prisma', () => ({
prisma: {
product: { findFirst: vi.fn() },
story: { groupBy: vi.fn() },
},
}))
vi.mock('@/lib/api-auth', () => ({
authenticateApiRequest: vi.fn(),
}))
vi.mock('@/lib/product-access', () => ({
productAccessFilter: vi.fn().mockReturnValue({}),
}))
import { prisma } from '@/lib/prisma'
import { authenticateApiRequest } from '@/lib/api-auth'
import { GET } from '@/app/api/products/[id]/sprint-membership-summary/route'
const mockPrisma = prisma as unknown as {
product: { findFirst: ReturnType<typeof vi.fn> }
story: { groupBy: ReturnType<typeof vi.fn> }
}
const mockAuth = authenticateApiRequest as unknown as ReturnType<typeof vi.fn>
function makeRequest(url: string) {
return new Request(url)
}
describe('GET /api/products/[id]/sprint-membership-summary', () => {
beforeEach(() => {
vi.clearAllMocks()
mockPrisma.product.findFirst.mockReset()
mockPrisma.story.groupBy.mockReset()
mockAuth.mockReset().mockResolvedValue({ userId: 'user-1' })
})
it('returns counts per PBI for happy path', async () => {
mockPrisma.product.findFirst.mockResolvedValue({ id: 'p1' })
mockPrisma.story.groupBy
.mockResolvedValueOnce([
{ pbi_id: 'pbiA', _count: { _all: 5 } },
{ pbi_id: 'pbiB', _count: { _all: 3 } },
])
.mockResolvedValueOnce([{ pbi_id: 'pbiA', _count: { _all: 2 } }])
const req = makeRequest(
'http://localhost/api/products/p1/sprint-membership-summary?sprintId=sp-1&pbiIds=pbiA,pbiB',
)
const res = await GET(req, { params: Promise.resolve({ id: 'p1' }) })
expect(res.status).toBe(200)
const body = await res.json()
expect(body).toEqual({
pbiA: { total: 5, inSprint: 2 },
pbiB: { total: 3, inSprint: 0 },
})
})
it('rejects when pbiIds is missing', async () => {
const req = makeRequest(
'http://localhost/api/products/p1/sprint-membership-summary?sprintId=sp-1',
)
const res = await GET(req, { params: Promise.resolve({ id: 'p1' }) })
expect(res.status).toBe(400)
})
it('rejects when pbiIds is empty', async () => {
const req = makeRequest(
'http://localhost/api/products/p1/sprint-membership-summary?sprintId=sp-1&pbiIds=',
)
const res = await GET(req, { params: Promise.resolve({ id: 'p1' }) })
expect(res.status).toBe(400)
})
it('rejects when sprintId is missing', async () => {
const req = makeRequest(
'http://localhost/api/products/p1/sprint-membership-summary?pbiIds=pbiA',
)
const res = await GET(req, { params: Promise.resolve({ id: 'p1' }) })
expect(res.status).toBe(400)
})
it('returns 404 when product is not accessible', async () => {
mockPrisma.product.findFirst.mockResolvedValue(null)
const req = makeRequest(
'http://localhost/api/products/p1/sprint-membership-summary?sprintId=sp-1&pbiIds=pbiA',
)
const res = await GET(req, { params: Promise.resolve({ id: 'p1' }) })
expect(res.status).toBe(404)
})
it('returns auth error when authenticate fails', async () => {
mockAuth.mockResolvedValue({ error: 'Niet ingelogd', status: 401 })
const req = makeRequest(
'http://localhost/api/products/p1/sprint-membership-summary?sprintId=sp-1&pbiIds=pbiA',
)
const res = await GET(req, { params: Promise.resolve({ id: 'p1' }) })
expect(res.status).toBe(401)
})
it('returns zero counts for PBIs without stories', async () => {
mockPrisma.product.findFirst.mockResolvedValue({ id: 'p1' })
mockPrisma.story.groupBy
.mockResolvedValueOnce([])
.mockResolvedValueOnce([])
const req = makeRequest(
'http://localhost/api/products/p1/sprint-membership-summary?sprintId=sp-1&pbiIds=pbiA,pbiB',
)
const res = await GET(req, { params: Promise.resolve({ id: 'p1' }) })
const body = await res.json()
expect(body).toEqual({
pbiA: { total: 0, inSprint: 0 },
pbiB: { total: 0, inSprint: 0 },
})
})
})

View file

@ -25,7 +25,7 @@ const mockPrisma = prisma as unknown as {
}
const mockAuth = authenticateApiRequest as ReturnType<typeof vi.fn>
const SPRINT = { id: 'sprint-1', product_id: 'prod-1', status: 'ACTIVE' }
const SPRINT = { id: 'sprint-1', product_id: 'prod-1', status: 'OPEN' }
function makeTask(n: number) {
return {

View file

@ -129,7 +129,7 @@ describe('POST /api/stories/:id/log', () => {
const res = await postStoryLog(
...makeRequest({ type: 'TEST_RESULT', content: 'Test gefaald.', status: 'FAILED' })
)
const data = await res.json()
await res.json()
expect(res.status).toBe(201)
expect(mockPrisma.storyLog.create).toHaveBeenCalledWith(

View file

@ -9,6 +9,24 @@ vi.mock('@/lib/prisma', () => ({
},
story: {
findUniqueOrThrow: vi.fn(),
findMany: vi.fn(),
update: vi.fn(),
},
pbi: {
findUniqueOrThrow: vi.fn(),
findMany: vi.fn(),
update: vi.fn(),
},
sprint: {
findUniqueOrThrow: vi.fn(),
update: vi.fn(),
},
claudeJob: {
findFirst: vi.fn(),
updateMany: vi.fn(),
},
sprintRun: {
findUnique: vi.fn(),
update: vi.fn(),
},
$transaction: vi.fn(),
@ -31,6 +49,24 @@ const mockPrisma = prisma as unknown as {
}
story: {
findUniqueOrThrow: ReturnType<typeof vi.fn>
findMany: ReturnType<typeof vi.fn>
update: ReturnType<typeof vi.fn>
}
pbi: {
findUniqueOrThrow: ReturnType<typeof vi.fn>
findMany: ReturnType<typeof vi.fn>
update: ReturnType<typeof vi.fn>
}
sprint: {
findUniqueOrThrow: ReturnType<typeof vi.fn>
update: ReturnType<typeof vi.fn>
}
claudeJob: {
findFirst: ReturnType<typeof vi.fn>
updateMany: ReturnType<typeof vi.fn>
}
sprintRun: {
findUnique: ReturnType<typeof vi.fn>
update: ReturnType<typeof vi.fn>
}
$transaction: ReturnType<typeof vi.fn>
@ -75,7 +111,14 @@ describe('PATCH /api/tasks/:id', () => {
})
// Default sibling state: only this task, already DONE → no story-promotion
mockPrisma.task.findMany.mockResolvedValue([{ status: 'DONE' }])
mockPrisma.story.findUniqueOrThrow.mockResolvedValue({ status: 'DONE' })
mockPrisma.story.findUniqueOrThrow.mockResolvedValue({
id: 'story-1',
status: 'DONE',
pbi_id: 'pbi-1',
sprint_id: null,
})
mockPrisma.story.findMany.mockResolvedValue([{ status: 'DONE' }])
mockPrisma.pbi.findUniqueOrThrow.mockResolvedValue({ id: 'pbi-1', status: 'DONE' })
// Pass-through for $transaction so tests behave as if Prisma ran the run-fn directly.
mockPrisma.$transaction.mockImplementation(async (run: (tx: typeof prisma) => Promise<unknown>) => {
return run(prisma)
@ -190,7 +233,14 @@ describe('PATCH /api/tasks/:id', () => {
story_id: 'story-1',
})
mockPrisma.task.findMany.mockResolvedValue([{ status: 'DONE' }, { status: 'DONE' }])
mockPrisma.story.findUniqueOrThrow.mockResolvedValue({ status: 'IN_SPRINT' })
mockPrisma.story.findUniqueOrThrow.mockResolvedValue({
id: 'story-1',
status: 'IN_SPRINT',
pbi_id: 'pbi-1',
sprint_id: null,
})
mockPrisma.story.findMany.mockResolvedValue([{ status: 'DONE' }])
mockPrisma.pbi.findUniqueOrThrow.mockResolvedValue({ id: 'pbi-1', status: 'READY' })
const res = await patchTask(...makeRequest({ status: 'done' }))
expect(res.status).toBe(200)

View file

@ -1,109 +0,0 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
vi.mock('@/lib/prisma', () => ({
prisma: {
product: {
findFirst: vi.fn(),
},
todo: {
create: vi.fn(),
},
},
}))
vi.mock('@/lib/api-auth', () => ({
authenticateApiRequest: vi.fn(),
}))
import { prisma } from '@/lib/prisma'
import { authenticateApiRequest } from '@/lib/api-auth'
import { POST as postTodo } from '@/app/api/todos/route'
const mockPrisma = prisma as unknown as {
product: { findFirst: ReturnType<typeof vi.fn> }
todo: { create: ReturnType<typeof vi.fn> }
}
const mockAuth = authenticateApiRequest as ReturnType<typeof vi.fn>
const PRODUCT = { id: 'prod-1', name: 'DevPlanner', archived: false, user_id: 'user-1' }
const TODO_RESULT = { id: 'todo-1', title: 'Test todo', created_at: new Date('2026-04-30T10:00:00Z') }
function makeRequest(body: unknown): Request {
return new Request('http://localhost/api/todos', {
method: 'POST',
headers: { Authorization: 'Bearer test-token', 'Content-Type': 'application/json' },
body: JSON.stringify(body),
})
}
describe('POST /api/todos', () => {
beforeEach(() => {
vi.clearAllMocks()
mockAuth.mockResolvedValue({ userId: 'user-1', isDemo: false })
mockPrisma.product.findFirst.mockResolvedValue(PRODUCT)
mockPrisma.todo.create.mockResolvedValue(TODO_RESULT)
})
// TC-TD-04
it('returns 422 when title is missing', async () => {
const res = await postTodo(makeRequest({ product_id: 'prod-1' }))
expect(res.status).toBe(422)
})
// TC-TD-05
it('returns 422 when title is empty string', async () => {
const res = await postTodo(makeRequest({ title: '', product_id: 'prod-1' }))
expect(res.status).toBe(422)
})
it('returns 422 when product_id is missing', async () => {
// product_id is required by the Zod schema (z.string().min(1))
const res = await postTodo(makeRequest({ title: 'My todo' }))
expect(res.status).toBe(422)
})
it('returns 422 when product_id is empty string', async () => {
const res = await postTodo(makeRequest({ title: 'My todo', product_id: '' }))
expect(res.status).toBe(422)
})
// TC-TD-07
it('creates todo with valid product_id and returns 201', async () => {
const res = await postTodo(makeRequest({ title: 'Test todo', product_id: 'prod-1' }))
const data = await res.json()
expect(res.status).toBe(201)
expect(data).toMatchObject({ id: 'todo-1', title: 'Test todo' })
expect(data).toHaveProperty('created_at')
expect(mockPrisma.todo.create).toHaveBeenCalledWith(
expect.objectContaining({
data: expect.objectContaining({
user_id: 'user-1',
product_id: 'prod-1',
title: 'Test todo',
}),
})
)
})
it('queries product by user_id (not productAccessFilter) to enforce ownership', async () => {
await postTodo(makeRequest({ title: 'Test todo', product_id: 'prod-1' }))
expect(mockPrisma.product.findFirst).toHaveBeenCalledWith(
expect.objectContaining({
where: expect.objectContaining({
id: 'prod-1',
user_id: 'user-1',
archived: false,
}),
})
)
})
it('returns 404 when product does not exist or is archived', async () => {
mockPrisma.product.findFirst.mockResolvedValue(null)
const res = await postTodo(makeRequest({ title: 'My todo', product_id: 'nonexistent' }))
expect(res.status).toBe(404)
})
})

View file

@ -0,0 +1,106 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
const { mockGetSession, mockFindFirstJob, mockFindManyPrice } = vi.hoisted(() => ({
mockGetSession: vi.fn(),
mockFindFirstJob: vi.fn(),
mockFindManyPrice: vi.fn(),
}))
vi.mock('@/lib/auth', () => ({ getSession: mockGetSession }))
vi.mock('@/lib/prisma', () => ({
prisma: {
claudeJob: { findFirst: mockFindFirstJob },
modelPrice: { findMany: mockFindManyPrice },
},
}))
import { GET } from '@/app/api/jobs/[id]/route'
function makeParams(id = 'job-1'): { params: Promise<{ id: string }> } {
return { params: Promise.resolve({ id }) }
}
function makeRequest(id = 'job-1'): Request {
return new Request(`http://localhost/api/jobs/${id}`)
}
const RAW_JOB = {
id: 'job-1',
kind: 'TASK_IMPLEMENTATION' as const,
status: 'DONE' as const,
model_id: 'claude-sonnet-4-6',
input_tokens: 100,
output_tokens: 50,
cache_read_tokens: 0,
cache_write_tokens: 0,
branch: 'feat/test',
pr_url: null,
error: null,
summary: 'Done',
verify_result: 'ALIGNED' as const,
started_at: new Date('2026-01-01T10:00:00Z'),
finished_at: new Date('2026-01-01T10:05:00Z'),
created_at: new Date('2026-01-01T09:59:00Z'),
sprint_run_id: null,
task: {
code: 'T-42',
title: 'Some task',
description: null,
implementation_plan: 'Do the thing',
story: { code: 'S-10', pbi: { code: 'PBI-5' } },
},
idea: null,
product: { name: 'Scrum4Me', code: 'SCR' },
sprint_run: null,
}
describe('GET /api/jobs/:id', () => {
beforeEach(() => {
vi.clearAllMocks()
mockGetSession.mockResolvedValue({ userId: 'user-1' })
mockFindFirstJob.mockResolvedValue(RAW_JOB)
mockFindManyPrice.mockResolvedValue([])
})
it('returns 401 when not logged in', async () => {
mockGetSession.mockResolvedValue({ userId: undefined })
const res = await GET(makeRequest() as never, makeParams())
expect(res.status).toBe(401)
const body = await res.json()
expect(body.error).toBeTruthy()
})
it('returns 404 when job not found', async () => {
mockFindFirstJob.mockResolvedValue(null)
const res = await GET(makeRequest() as never, makeParams())
expect(res.status).toBe(404)
const body = await res.json()
expect(body.error).toBeTruthy()
})
it('queries with user_id filter to prevent cross-user access', async () => {
await GET(makeRequest() as never, makeParams())
expect(mockFindFirstJob).toHaveBeenCalledWith(
expect.objectContaining({
where: { id: 'job-1', user_id: 'user-1' },
})
)
})
it('returns 200 with mapped job shape including breadcrumb codes', async () => {
const res = await GET(makeRequest() as never, makeParams())
expect(res.status).toBe(200)
const body = await res.json()
expect(body).toMatchObject({
id: 'job-1',
kind: 'TASK_IMPLEMENTATION',
status: 'DONE',
taskCode: 'T-42',
taskTitle: 'Some task',
productCode: 'SCR',
storyCode: 'S-10',
pbiCode: 'PBI-5',
branch: 'feat/test',
})
})
})

View file

@ -0,0 +1,38 @@
// Lichte regressie-tests voor de mobile backlog-page. Server-component render
// vereist te veel mocking; we asserten op statische source-eigenschappen die
// kritisch zijn voor de mobile-shell (cookie-key gescheiden, /m/-paden).
import { describe, it, expect } from 'vitest'
import { readFileSync } from 'node:fs'
import { resolve } from 'node:path'
const PAGE = resolve(process.cwd(), 'app/(mobile)/m/products/[id]/page.tsx')
const src = readFileSync(PAGE, 'utf-8')
describe('mobile backlog page (ST-1137)', () => {
it('gebruikt gescheiden cookie-key (backlog-{id}-mobile)', () => {
// Beslissing C: tab-mode-gebruikers vervuilen desktop-split niet.
expect(src).toMatch(/cookieKey=\{`backlog-\$\{id\}-mobile`\}/)
})
it('closePath en TaskDialog redirect blijven onder /m/products/', () => {
expect(src).toContain('const closePath = `/m/products/${id}`')
})
it('hergebruikt BacklogHydrationWrapper + BacklogSplitPane (geen content-componenten dupliceren)', () => {
expect(src).toContain('BacklogHydrationWrapper')
expect(src).toContain('BacklogSplitPane')
expect(src).toContain('PbiList')
expect(src).toContain('StoryPanel')
expect(src).toContain('TaskPanel')
})
it('auth via requireSession() (gedeelde guard)', () => {
expect(src).toContain("from '@/lib/auth-guard'")
expect(src).toContain('requireSession()')
})
it('rendert TaskDialog op ?newTask en EditTaskLoader op ?editTask', () => {
expect(src).toContain('{newTask &&')
expect(src).toContain('{editTask && !newTask &&')
})
})

View file

@ -0,0 +1,35 @@
// ST-1138: regressie-vangnet voor mobile solo-page (server component).
import { describe, it, expect } from 'vitest'
import { readFileSync } from 'node:fs'
import { resolve } from 'node:path'
const PAGE = resolve(process.cwd(), 'app/(mobile)/m/products/[id]/solo/page.tsx')
const TASK_DETAIL = resolve(process.cwd(), 'components/solo/task-detail-dialog.tsx')
describe('mobile solo page (ST-1138)', () => {
const src = readFileSync(PAGE, 'utf-8')
it('hergebruikt SoloBoard zonder content-aanpassingen', () => {
expect(src).toContain('SoloBoard')
expect(src).toContain("from '@/components/solo/solo-board'")
})
it('auth via gedeelde requireSession()', () => {
expect(src).toContain("from '@/lib/auth-guard'")
expect(src).toContain('requireSession()')
})
it('geeft NoActiveSprint terug als geen actieve sprint (zelfde gedrag als desktop)', () => {
expect(src).toContain('NoActiveSprint')
})
})
describe('TaskDetailDialog erft mobile-fullscreen (ST-1138 T-332 verify-only)', () => {
// Beslissing A: TaskDetailDialog gebruikt entityDialogContentClasses; mobile-classes
// komen automatisch door uit T-317. Dit test bewijst de wiring blijft staan.
const src = readFileSync(TASK_DETAIL, 'utf-8')
it('rendert DialogContent met entityDialogContentClasses (geen eigen className-override)', () => {
expect(src).toContain('className={entityDialogContentClasses}')
})
})

View file

@ -1,9 +1,21 @@
// @vitest-environment jsdom
import { describe, it, expect, beforeEach } from 'vitest'
import { describe, it, expect, beforeEach, vi } from 'vitest'
import { render, screen } from '@testing-library/react'
import { useSelectionStore } from '@/stores/selection-store'
vi.mock('@/actions/user-settings', () => ({
updateUserSettingsAction: vi.fn().mockResolvedValue({ success: true, settings: {} }),
}))
import { useProductWorkspaceStore } from '@/stores/product-workspace/store'
import { BacklogSplitPane } from '@/components/backlog/backlog-split-pane'
function setSelection(pbiId: string | null, storyId: string | null) {
useProductWorkspaceStore.setState((s) => {
s.context.activePbiId = pbiId
s.context.activeStoryId = storyId
})
}
const PANES = [
<div key="a">PBI pane</div>,
<div key="b">Stories pane</div>,
@ -22,7 +34,7 @@ function renderPane() {
}
beforeEach(() => {
useSelectionStore.setState({ selectedPbiId: null, selectedStoryId: null })
setSelection(null, null)
// Force mobile viewport
Object.defineProperty(window, 'innerWidth', { writable: true, configurable: true, value: 600 })
window.dispatchEvent(new Event('resize'))
@ -37,7 +49,7 @@ describe('BacklogSplitPane auto-switch', () => {
it('auto-switches to tab 1 when PBI is selected', () => {
const { rerender } = renderPane()
useSelectionStore.setState({ selectedPbiId: 'pbi-1', selectedStoryId: null })
setSelection('pbi-1', null)
rerender(
<BacklogSplitPane
panes={PANES}
@ -52,7 +64,7 @@ describe('BacklogSplitPane auto-switch', () => {
it('auto-switches to tab 2 when story is selected', () => {
const { rerender } = renderPane()
useSelectionStore.setState({ selectedPbiId: 'pbi-1', selectedStoryId: 'story-1' })
setSelection('pbi-1', 'story-1')
rerender(
<BacklogSplitPane
panes={PANES}
@ -67,11 +79,11 @@ describe('BacklogSplitPane auto-switch', () => {
it('switches to tab 1 on cascade-reset (story cleared when new PBI selected)', () => {
// Start with story selected (tab 2)
useSelectionStore.setState({ selectedPbiId: 'pbi-1', selectedStoryId: 'story-1' })
setSelection('pbi-1', 'story-1')
const { rerender } = renderPane()
// Cascade-reset: new PBI → story clears
useSelectionStore.setState({ selectedPbiId: 'pbi-2', selectedStoryId: null })
setSelection('pbi-2', null)
rerender(
<BacklogSplitPane
panes={PANES}

View file

@ -1,8 +1,11 @@
// @vitest-environment jsdom
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { render, screen, fireEvent } from '@testing-library/react'
import { useSelectionStore } from '@/stores/selection-store'
import { useBacklogStore } from '@/stores/backlog-store'
import { useProductWorkspaceStore } from '@/stores/product-workspace/store'
import type {
BacklogStory,
BacklogTask,
} from '@/stores/product-workspace/types'
// Mock next/navigation
const mockPush = vi.fn()
@ -22,15 +25,16 @@ Object.defineProperty(globalThis, 'localStorage', { value: localStorageMock, wri
// Mock server actions
vi.mock('@/actions/stories', () => ({
reorderStoriesAction: vi.fn().mockResolvedValue({ success: true }),
reorderPbisAction: vi.fn().mockResolvedValue({ success: true }),
updatePbiPriorityAction: vi.fn().mockResolvedValue({ success: true }),
}))
vi.mock('@/actions/pbis', () => ({ deletePbiAction: vi.fn().mockResolvedValue({ success: true }) }))
vi.mock('@/actions/tasks', () => ({ reorderTasksAction: vi.fn().mockResolvedValue({ success: true }) }))
vi.mock('@/actions/user-settings', () => ({
updateUserSettingsAction: vi.fn().mockResolvedValue({ success: true, settings: {} }),
}))
vi.mock('sonner', () => ({ toast: { error: vi.fn(), success: vi.fn() } }))
// Mock dnd-kit
// Mock dnd-kit (still needed for PBI panel which supports drag-and-drop)
vi.mock('@dnd-kit/core', () => ({
DndContext: ({ children }: { children: React.ReactNode }) => <>{children}</>,
PointerSensor: class {},
@ -61,19 +65,40 @@ const PBI_ID = 'pbi-1'
const ALT_PBI_ID = 'pbi-2'
const STORY_ID = 'story-1'
const STORIES = [
{ id: STORY_ID, code: 'ST-1', title: 'Eerste story', description: null, acceptance_criteria: null, priority: 2, status: 'OPEN', pbi_id: PBI_ID, created_at: new Date() },
const STORIES: BacklogStory[] = [
{ id: STORY_ID, code: 'ST-1', title: 'Eerste story', description: null, acceptance_criteria: null, priority: 2, sort_order: 1, status: 'OPEN', pbi_id: PBI_ID, sprint_id: null, created_at: new Date() },
]
const TASKS = [
{ id: 'task-1', title: 'Eerste taak', description: null, priority: 2, status: 'TO_DO', sort_order: 1, story_id: STORY_ID, created_at: new Date() },
const TASKS: BacklogTask[] = [
{ id: 'task-1', code: null, title: 'Eerste taak', description: null, priority: 2, status: 'TO_DO', sort_order: 1, story_id: STORY_ID, created_at: new Date() },
]
function resetStores() {
useSelectionStore.setState({ selectedPbiId: null, selectedStoryId: null })
useBacklogStore.setState({
pbis: [],
storiesByPbi: { [PBI_ID]: STORIES },
tasksByStory: { [STORY_ID]: TASKS },
useProductWorkspaceStore.setState((s) => {
s.context.activeProduct = null
s.context.activePbiId = null
s.context.activeStoryId = null
s.context.activeTaskId = null
s.entities.pbisById = {}
s.entities.storiesById = Object.fromEntries(STORIES.map((st) => [st.id, st]))
s.entities.tasksById = Object.fromEntries(TASKS.map((t) => [t.id, t]))
s.relations.pbiIds = []
s.relations.storyIdsByPbi = { [PBI_ID]: STORIES.map((st) => st.id) }
s.relations.taskIdsByStory = { [STORY_ID]: TASKS.map((t) => t.id) }
})
}
function selectPbi(pbiId: string | null) {
useProductWorkspaceStore.setState((s) => {
s.context.activePbiId = pbiId
s.context.activeStoryId = null
s.context.activeTaskId = null
})
}
function selectStory(pbiId: string | null, storyId: string | null) {
useProductWorkspaceStore.setState((s) => {
s.context.activePbiId = pbiId
s.context.activeStoryId = storyId
})
}
@ -89,42 +114,40 @@ describe('Backlog 3-pane integration', () => {
})
it('StoryPanel shows stories when PBI is selected', () => {
useSelectionStore.setState({ selectedPbiId: PBI_ID, selectedStoryId: null })
selectPbi(PBI_ID)
render(<StoryPanel productId={PRODUCT_ID} isDemo={false} />)
expect(screen.getByText('Eerste story')).toBeTruthy()
})
it('clicking a story dispatches selectStory to the store', () => {
useSelectionStore.setState({ selectedPbiId: PBI_ID, selectedStoryId: null })
it('clicking a story dispatches setActiveStory to the workspace-store', () => {
selectPbi(PBI_ID)
render(<StoryPanel productId={PRODUCT_ID} isDemo={false} />)
fireEvent.click(screen.getByText('Eerste story'))
expect(useSelectionStore.getState().selectedStoryId).toBe(STORY_ID)
expect(useProductWorkspaceStore.getState().context.activeStoryId).toBe(STORY_ID)
})
it('cascade-reset: selecting different PBI clears selectedStoryId', () => {
useSelectionStore.setState({ selectedPbiId: PBI_ID, selectedStoryId: STORY_ID })
useSelectionStore.getState().selectPbi(ALT_PBI_ID)
expect(useSelectionStore.getState().selectedStoryId).toBeNull()
it('cascade-reset: selecting different PBI clears activeStoryId', () => {
selectStory(PBI_ID, STORY_ID)
useProductWorkspaceStore.getState().setActivePbi(ALT_PBI_ID)
expect(useProductWorkspaceStore.getState().context.activeStoryId).toBeNull()
})
it('TaskPanel shows tasks after story is selected', () => {
useSelectionStore.setState({ selectedPbiId: PBI_ID, selectedStoryId: STORY_ID })
selectStory(PBI_ID, STORY_ID)
render(<TaskPanel productId={PRODUCT_ID} isDemo={false} closePath={`/products/${PRODUCT_ID}`} />)
expect(screen.getByText('Eerste taak')).toBeTruthy()
})
it('TaskPanel shows empty state after cascade-reset', () => {
useSelectionStore.setState({ selectedPbiId: PBI_ID, selectedStoryId: STORY_ID })
selectStory(PBI_ID, STORY_ID)
render(<TaskPanel productId={PRODUCT_ID} isDemo={false} closePath={`/products/${PRODUCT_ID}`} />)
// Reset via selectPbi
useSelectionStore.getState().selectPbi(ALT_PBI_ID)
// Re-render reflects new store state
useProductWorkspaceStore.getState().setActivePbi(ALT_PBI_ID)
render(<TaskPanel productId={PRODUCT_ID} isDemo={false} closePath={`/products/${PRODUCT_ID}`} />)
expect(screen.getAllByText('Selecteer een story om de taken te bekijken.').length).toBeGreaterThan(0)
})
it('selected story card has isSelected highlight class applied', () => {
useSelectionStore.setState({ selectedPbiId: PBI_ID, selectedStoryId: STORY_ID })
selectStory(PBI_ID, STORY_ID)
const { container } = render(<StoryPanel productId={PRODUCT_ID} isDemo={false} />)
// bg-primary-container is applied when isSelected
const selected = container.querySelector('.bg-primary-container')

View file

@ -0,0 +1,57 @@
// @vitest-environment jsdom
import { describe, it, expect, beforeEach, vi } from 'vitest'
import { render, screen } from '@testing-library/react'
import '@testing-library/jest-dom'
import type { ReactNode } from 'react'
const workflowMock: {
value: { pendingSprintDraft?: Record<string, unknown> } | undefined
} = { value: undefined }
vi.mock('@/stores/user-settings/store', () => ({
useUserSettingsStore: (
selector: (s: {
entities: {
settings: {
workflow: { pendingSprintDraft?: Record<string, unknown> } | undefined
}
}
}) => unknown,
) => selector({ entities: { settings: { workflow: workflowMock.value } } }),
}))
vi.mock('./new-sprint-metadata-dialog', () => ({
NewSprintMetadataDialog: () => null,
}))
vi.mock('@/components/shared/demo-tooltip', () => ({
DemoTooltip: ({ children }: { children: ReactNode }) => children,
}))
import { NewSprintTrigger } from '@/components/backlog/new-sprint-trigger'
beforeEach(() => {
workflowMock.value = undefined
})
describe('NewSprintTrigger', () => {
it('renders the button on an active product without a draft', () => {
render(<NewSprintTrigger productId="p1" isDemo={false} isActiveProduct={true} />)
expect(screen.getByText('Nieuwe sprint')).toBeInTheDocument()
})
it('renders nothing on a non-active product (G6)', () => {
const { container } = render(
<NewSprintTrigger productId="p1" isDemo={false} isActiveProduct={false} />,
)
expect(container).toBeEmptyDOMElement()
})
it('renders nothing when a sprint draft is pending', () => {
workflowMock.value = { pendingSprintDraft: { p1: { goal: 'X' } } }
const { container } = render(
<NewSprintTrigger productId="p1" isDemo={false} isActiveProduct={true} />,
)
expect(container).toBeEmptyDOMElement()
})
})

View file

@ -1,44 +1,40 @@
// @vitest-environment jsdom
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { render, screen, fireEvent } from '@testing-library/react'
import { useSelectionStore } from '@/stores/selection-store'
import { useBacklogStore } from '@/stores/backlog-store'
import { useProductWorkspaceStore } from '@/stores/product-workspace/store'
import type { BacklogTask } from '@/stores/product-workspace/types'
function resetWorkspace() {
useProductWorkspaceStore.setState((s) => {
s.context.activeProduct = null
s.context.activePbiId = null
s.context.activeStoryId = null
s.context.activeTaskId = null
s.entities.pbisById = {}
s.entities.storiesById = {}
s.entities.tasksById = {}
s.relations.pbiIds = []
s.relations.storyIdsByPbi = {}
s.relations.taskIdsByStory = {}
})
}
function setActiveStoryAndTasks(storyId: string | null, tasks: BacklogTask[] = []) {
useProductWorkspaceStore.setState((s) => {
s.context.activeStoryId = storyId
if (storyId) {
s.relations.taskIdsByStory[storyId] = tasks.map((t) => t.id)
for (const task of tasks) s.entities.tasksById[task.id] = task
}
})
}
// Mock next/navigation
const mockPush = vi.fn()
vi.mock('next/navigation', () => ({ useRouter: () => ({ push: mockPush }) }))
// Mock reorderTasksAction
vi.mock('@/actions/tasks', () => ({ reorderTasksAction: vi.fn().mockResolvedValue({ success: true }) }))
vi.mock('sonner', () => ({ toast: { error: vi.fn(), success: vi.fn() } }))
// Mock dnd-kit to avoid jsdom drag complexity
vi.mock('@dnd-kit/core', () => ({
DndContext: ({ children }: { children: React.ReactNode }) => <>{children}</>,
PointerSensor: class {},
KeyboardSensor: class {},
useSensor: vi.fn(),
useSensors: vi.fn(() => []),
closestCenter: vi.fn(),
DragOverlay: () => null,
}))
vi.mock('@dnd-kit/sortable', () => ({
SortableContext: ({ children }: { children: React.ReactNode }) => <>{children}</>,
useSortable: () => ({
attributes: {}, listeners: {}, setNodeRef: vi.fn(),
transform: null, transition: undefined, isDragging: false,
}),
rectSortingStrategy: {},
sortableKeyboardCoordinates: {},
arrayMove: (arr: unknown[], from: number, to: number) => {
const next = [...arr]
next.splice(from, 1)
next.splice(to, 0, arr[from])
return next
},
}))
vi.mock('@dnd-kit/utilities', () => ({ CSS: { Transform: { toString: () => '' } } }))
import { TaskPanel } from '@/components/backlog/task-panel'
const PRODUCT_ID = 'prod-1'
@ -46,8 +42,8 @@ const STORY_ID = 'story-1'
const CLOSE_PATH = `/products/${PRODUCT_ID}`
const TASKS = [
{ id: 'task-1', title: 'Eerste taak', description: null, priority: 2, status: 'TO_DO', sort_order: 1, story_id: STORY_ID, created_at: new Date() },
{ id: 'task-2', title: 'Tweede taak', description: null, priority: 3, status: 'IN_PROGRESS', sort_order: 2, story_id: STORY_ID, created_at: new Date() },
{ id: 'task-1', code: null, title: 'Eerste taak', description: null, priority: 2, status: 'TO_DO', sort_order: 1, story_id: STORY_ID, created_at: new Date() },
{ id: 'task-2', code: null, title: 'Tweede taak', description: null, priority: 3, status: 'IN_PROGRESS', sort_order: 2, story_id: STORY_ID, created_at: new Date() },
]
function renderPanel(isDemo = false) {
@ -57,8 +53,7 @@ function renderPanel(isDemo = false) {
describe('TaskPanel', () => {
beforeEach(() => {
mockPush.mockClear()
useSelectionStore.setState({ selectedStoryId: null, selectedPbiId: null })
useBacklogStore.setState({ pbis: [], storiesByPbi: {}, tasksByStory: {} })
resetWorkspace()
})
it('shows empty state when no story is selected', () => {
@ -67,40 +62,35 @@ describe('TaskPanel', () => {
})
it('shows empty state with action when story selected but no tasks', () => {
useSelectionStore.setState({ selectedStoryId: STORY_ID, selectedPbiId: null })
useBacklogStore.setState({ tasksByStory: { [STORY_ID]: [] } })
setActiveStoryAndTasks(STORY_ID, [])
renderPanel()
expect(screen.getByText('Nog geen taken voor deze story.')).toBeTruthy()
expect(screen.getAllByText('+ Nieuwe taak').length).toBeGreaterThanOrEqual(1)
})
it('renders task cards when tasks are present', () => {
useSelectionStore.setState({ selectedStoryId: STORY_ID, selectedPbiId: null })
useBacklogStore.setState({ tasksByStory: { [STORY_ID]: TASKS } })
setActiveStoryAndTasks(STORY_ID, TASKS)
renderPanel()
expect(screen.getByText('Eerste taak')).toBeTruthy()
expect(screen.getByText('Tweede taak')).toBeTruthy()
})
it('renders status badges on task cards', () => {
useSelectionStore.setState({ selectedStoryId: STORY_ID, selectedPbiId: null })
useBacklogStore.setState({ tasksByStory: { [STORY_ID]: TASKS } })
setActiveStoryAndTasks(STORY_ID, TASKS)
renderPanel()
expect(screen.getByText('To Do')).toBeTruthy()
expect(screen.getByText('Bezig')).toBeTruthy()
})
it('task cards are rendered inside a grid container', () => {
useSelectionStore.setState({ selectedStoryId: STORY_ID, selectedPbiId: null })
useBacklogStore.setState({ tasksByStory: { [STORY_ID]: TASKS } })
setActiveStoryAndTasks(STORY_ID, TASKS)
const { container } = renderPanel()
const grid = container.querySelector('.grid')
expect(grid).toBeTruthy()
})
it('clicking + button calls router.push with newTask params', () => {
useSelectionStore.setState({ selectedStoryId: STORY_ID, selectedPbiId: null })
useBacklogStore.setState({ tasksByStory: { [STORY_ID]: [] } })
setActiveStoryAndTasks(STORY_ID, [])
renderPanel()
const buttons = screen.getAllByText('+ Nieuwe taak')
fireEvent.click(buttons[0])
@ -108,29 +98,18 @@ describe('TaskPanel', () => {
})
it('clicking task card calls router.push with editTask param', () => {
useSelectionStore.setState({ selectedStoryId: STORY_ID, selectedPbiId: null })
useBacklogStore.setState({ tasksByStory: { [STORY_ID]: TASKS } })
setActiveStoryAndTasks(STORY_ID, TASKS)
renderPanel()
fireEvent.click(screen.getByText('Eerste taak'))
expect(mockPush).toHaveBeenCalledWith(`${CLOSE_PATH}?editTask=task-1`)
})
it('+ button is disabled in demo mode', () => {
useSelectionStore.setState({ selectedStoryId: STORY_ID, selectedPbiId: null })
useBacklogStore.setState({ tasksByStory: { [STORY_ID]: [] } })
setActiveStoryAndTasks(STORY_ID, [])
renderPanel(true)
const btn = screen.getAllByText('+ Nieuwe taak')[0].closest('button')
expect(btn).toBeTruthy()
expect((btn as HTMLButtonElement).disabled).toBe(true)
})
it('cards have no drag listeners in demo mode (whole-card drag disabled)', () => {
useSelectionStore.setState({ selectedStoryId: STORY_ID, selectedPbiId: null })
useBacklogStore.setState({ tasksByStory: { [STORY_ID]: TASKS } })
// In demo mode, listeners ({} from useSortable mock) are not spread onto the card.
// The mock always returns empty listeners, so we just verify the cards render without error.
renderPanel(true)
expect(screen.getByText('Eerste taak')).toBeTruthy()
expect(screen.getByText('Tweede taak')).toBeTruthy()
})
})

View file

@ -0,0 +1,56 @@
// @vitest-environment jsdom
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { render, screen, fireEvent } from '@testing-library/react'
const { pushMock } = vi.hoisted(() => ({ pushMock: vi.fn() }))
vi.mock('next/navigation', () => ({ useRouter: () => ({ push: pushMock, refresh: vi.fn() }) }))
vi.mock('@/actions/products', () => ({ restoreProductAction: vi.fn() }))
vi.mock('@/actions/active-product', () => ({ setActiveProductAction: vi.fn() }))
vi.mock('sonner', () => ({ toast: { success: vi.fn(), error: vi.fn() } }))
vi.mock('@/components/dialogs/product-dialog', () => ({
ProductDialog: ({ open }: { open: boolean }) => (open ? <div role="dialog">ProductDialog</div> : null),
}))
import { ProductList } from '@/components/dashboard/product-list'
const PRODUCT = {
id: 'p1',
name: 'Mijn Product',
code: 'MP',
description: 'Een product',
repo_url: 'https://github.com/foo/bar',
definition_of_done: 'klaar als het werkt',
auto_pr: false,
}
beforeEach(() => {
pushMock.mockClear()
})
describe('ProductList — edit-icoon (todo cmoq3ox51)', () => {
it('rendert pencil-icoon (Bewerk product) op active card, geen tekstknop "Bewerken"', () => {
render(<ProductList products={[PRODUCT]} isDemo={false} activeProductId="p1" />)
expect(screen.getByLabelText('Bewerk product')).toBeTruthy()
// Oude tekstknop is weg
expect(screen.queryByText('Bewerken')).toBeNull()
})
it('opent ProductDialog op klik (en stopt propagation zodat card-click niet navigeert)', () => {
render(<ProductList products={[PRODUCT]} isDemo={false} activeProductId="p1" />)
expect(screen.queryByRole('dialog')).toBeNull()
fireEvent.click(screen.getByLabelText('Bewerk product'))
expect(screen.getByRole('dialog')).toBeTruthy()
expect(pushMock).not.toHaveBeenCalled() // card-navigation niet getriggerd
})
it('demo-user: knop is disabled', () => {
render(<ProductList products={[PRODUCT]} isDemo={true} activeProductId="p1" />)
const btn = screen.getByLabelText('Bewerk product') as HTMLButtonElement
expect(btn.disabled).toBe(true)
})
it('toont geen edit-icoon bij gearchiveerde producten', () => {
render(<ProductList products={[PRODUCT]} isDemo={false} showArchived={true} activeProductId={null} />)
expect(screen.queryByLabelText('Bewerk product')).toBeNull()
})
})

View file

@ -0,0 +1,104 @@
// @vitest-environment jsdom
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { render, screen, fireEvent, waitFor } from '@testing-library/react'
import React from 'react'
vi.mock('@/actions/questions', () => ({
answerQuestion: vi.fn(),
}))
vi.mock('sonner', () => ({ toast: { success: vi.fn(), error: vi.fn() } }))
vi.mock('@/stores/notifications-store', () => ({
useNotificationsStore: {
getState: () => ({ remove: vi.fn() }),
},
}))
vi.mock('next/link', () => ({
default: ({ href, children }: { href: string; children: React.ReactNode }) => (
<a href={href}>{children}</a>
),
}))
import { AnswerModal } from '@/components/notifications/answer-modal'
import { answerQuestion } from '@/actions/questions'
import { toast } from 'sonner'
import type { NotificationQuestion } from '@/stores/notifications-store'
const mockAnswerQuestion = answerQuestion as ReturnType<typeof vi.fn>
const mockToast = toast as unknown as {
success: ReturnType<typeof vi.fn>
error: ReturnType<typeof vi.fn>
}
const QUESTION: NotificationQuestion = {
kind: 'idea',
id: 'q-1',
product_id: 'prod-1',
idea_id: 'idea-1',
idea_code: 'IDEA-42',
idea_title: 'Mijn Idee',
question: 'Wat denk jij?',
options: ['Optie A', 'Optie B'],
created_at: '2026-01-01T00:00:00Z',
expires_at: '2026-12-31T00:00:00Z',
}
beforeEach(() => {
vi.clearAllMocks()
})
describe('AnswerModal — met opties', () => {
it('toont optieknoppen, textarea en Verstuur-knop', () => {
render(<AnswerModal question={QUESTION} isDemo={false} onClose={vi.fn()} />)
expect(screen.getByRole('button', { name: 'Optie A' })).toBeTruthy()
expect(screen.getByRole('button', { name: 'Optie B' })).toBeTruthy()
expect(screen.getByLabelText(/Antwoord op Claude/)).toBeTruthy()
expect(screen.getByRole('button', { name: 'Verstuur' })).toBeTruthy()
})
it('roept answerQuestion aan met optiewaarde bij klik op optieknop', async () => {
mockAnswerQuestion.mockResolvedValue({ ok: true })
render(<AnswerModal question={QUESTION} isDemo={false} onClose={vi.fn()} />)
fireEvent.click(screen.getByRole('button', { name: 'Optie A' }))
await waitFor(() => {
expect(mockAnswerQuestion).toHaveBeenCalledWith('q-1', 'Optie A')
})
})
it('roept answerQuestion aan met getypte tekst bij klik op Verstuur', async () => {
mockAnswerQuestion.mockResolvedValue({ ok: true })
render(<AnswerModal question={QUESTION} isDemo={false} onClose={vi.fn()} />)
fireEvent.change(screen.getByLabelText(/Antwoord op Claude/), {
target: { value: 'Mijn eigen antwoord' },
})
fireEvent.click(screen.getByRole('button', { name: 'Verstuur' }))
await waitFor(() => {
expect(mockAnswerQuestion).toHaveBeenCalledWith('q-1', 'Mijn eigen antwoord')
})
})
it('Verstuur-knop is disabled zolang het tekstveld leeg is', () => {
render(<AnswerModal question={QUESTION} isDemo={false} onClose={vi.fn()} />)
expect(screen.getByRole('button', { name: 'Verstuur' })).toHaveProperty('disabled', true)
})
})
describe('AnswerModal — demo-modus', () => {
it('textarea is disabled en Verstuur is disabled bij isDemo=true', () => {
render(<AnswerModal question={QUESTION} isDemo={true} onClose={vi.fn()} />)
expect(screen.getByLabelText(/Antwoord op Claude/)).toHaveProperty('disabled', true)
expect(screen.getByRole('button', { name: 'Verstuur' })).toHaveProperty('disabled', true)
})
})
describe('AnswerModal — geen vraag', () => {
it('rendert niets wanneer question null is', () => {
const { container } = render(
<AnswerModal question={null} isDemo={false} onClose={vi.fn()} />,
)
expect(container.firstChild).toBeNull()
})
})

View file

@ -0,0 +1,134 @@
// @vitest-environment jsdom
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { render, screen, fireEvent, waitFor } from '@testing-library/react'
vi.mock('@/actions/products', () => ({
createProductAction: vi.fn(),
updateProductAction: vi.fn(),
}))
vi.mock('sonner', () => ({ toast: { success: vi.fn(), error: vi.fn() } }))
vi.mock('@/stores/products-store', () => ({
useProductsStore: vi.fn((selector: (s: { addProduct: () => void; updateProduct: () => void }) => unknown) =>
selector({ addProduct: vi.fn(), updateProduct: vi.fn() })
),
}))
import { ProductDialog } from '@/components/dialogs/product-dialog'
import { createProductAction, updateProductAction } from '@/actions/products'
import { toast } from 'sonner'
const mockCreate = createProductAction as ReturnType<typeof vi.fn>
const mockUpdate = updateProductAction as ReturnType<typeof vi.fn>
const mockToast = toast as unknown as {
success: ReturnType<typeof vi.fn>
error: ReturnType<typeof vi.fn>
}
const PRODUCT = {
id: 'prod-1',
name: 'Mijn Product',
code: 'MP',
description: 'Een product',
repo_url: 'https://github.com/org/repo',
definition_of_done: 'Alles groen',
auto_pr: false,
}
beforeEach(() => {
vi.clearAllMocks()
})
describe('ProductDialog — create mode', () => {
it('rendert met lege velden en "Nieuw product" titel', () => {
render(
<ProductDialog mode="create" open={true} onOpenChange={vi.fn()} />
)
expect(screen.getByText('Nieuw product')).toBeTruthy()
expect(screen.getByLabelText(/Naam/)).toBeTruthy()
expect((screen.getByLabelText(/Naam/) as HTMLInputElement).value).toBe('')
})
it('toont validatiefout als naam leeg is bij submit', async () => {
render(
<ProductDialog mode="create" open={true} onOpenChange={vi.fn()} />
)
fireEvent.click(screen.getByRole('button', { name: 'Aanmaken' }))
await waitFor(() => {
expect(screen.getByText('Naam is verplicht')).toBeTruthy()
})
expect(mockCreate).not.toHaveBeenCalled()
})
it('roept createProductAction aan bij geldig formulier', async () => {
mockCreate.mockResolvedValue({ success: true, productId: 'new-prod' })
render(
<ProductDialog mode="create" open={true} onOpenChange={vi.fn()} />
)
fireEvent.change(screen.getByLabelText(/Naam/), { target: { value: 'Nieuw Product' } })
fireEvent.submit(document.getElementById('product-form')!)
await waitFor(() => {
expect(mockCreate).toHaveBeenCalledWith(
expect.objectContaining({ name: 'Nieuw Product' })
)
})
expect(mockToast.success).toHaveBeenCalledWith('Product aangemaakt')
})
it('toont error-toast als createProductAction een error retourneert', async () => {
mockCreate.mockResolvedValue({ error: 'Code is al in gebruik' })
render(
<ProductDialog mode="create" open={true} onOpenChange={vi.fn()} />
)
fireEvent.change(screen.getByLabelText(/Naam/), { target: { value: 'Test' } })
fireEvent.submit(document.getElementById('product-form')!)
await waitFor(() => {
expect(mockToast.error).toHaveBeenCalledWith('Code is al in gebruik')
})
})
})
describe('ProductDialog — edit mode', () => {
it('rendert met bestaande waarden vooringevuld', () => {
render(
<ProductDialog mode="edit" open={true} onOpenChange={vi.fn()} product={PRODUCT} />
)
expect(screen.getByText('Product bewerken')).toBeTruthy()
expect((screen.getByLabelText(/Naam/) as HTMLInputElement).value).toBe('Mijn Product')
})
it('roept updateProductAction aan bij opslaan', async () => {
mockUpdate.mockResolvedValue({ success: true })
render(
<ProductDialog mode="edit" open={true} onOpenChange={vi.fn()} product={PRODUCT} />
)
fireEvent.change(screen.getByLabelText(/Naam/), { target: { value: 'Gewijzigd Product' } })
fireEvent.submit(document.getElementById('product-form')!)
await waitFor(() => {
expect(mockUpdate).toHaveBeenCalledWith(
PRODUCT.id,
expect.objectContaining({ name: 'Gewijzigd Product' })
)
})
expect(mockToast.success).toHaveBeenCalledWith('Product opgeslagen')
})
})
describe('ProductDialog — demo mode', () => {
it('submit-knop is disabled in demo-modus', () => {
render(
<ProductDialog mode="create" open={true} onOpenChange={vi.fn()} isDemo={true} />
)
const submitBtn = screen.getByRole('button', { name: 'Aanmaken' })
expect(submitBtn).toHaveProperty('disabled', true)
})
})

View file

@ -0,0 +1,277 @@
// @vitest-environment jsdom
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { render, screen, fireEvent, waitFor } from '@testing-library/react'
import '@testing-library/jest-dom'
import React from 'react'
// --- Navigation mock ---
vi.mock('next/navigation', () => ({
useRouter: () => ({ push: vi.fn(), refresh: vi.fn() }),
}))
// --- Actions mocks ---
vi.mock('@/actions/ideas', () => ({
createIdeaAction: vi.fn(),
archiveIdeaAction: vi.fn(),
}))
vi.mock('@/actions/user-settings', () => ({
updateUserSettingsAction: vi.fn().mockResolvedValue({ success: true, settings: {} }),
}))
// --- Sonner mock ---
vi.mock('sonner', () => ({
toast: { error: vi.fn(), success: vi.fn() },
}))
// --- IdeaRowActions mock (complex component with many deps) ---
vi.mock('@/components/ideas/idea-row-actions', () => ({
IdeaRowActions: () => <div data-testid="idea-row-actions" />,
}))
// --- DemoTooltip mock ---
vi.mock('@/components/shared/demo-tooltip', () => ({
DemoTooltip: ({ children }: { children: React.ReactNode }) => <>{children}</>,
}))
// --- Popover mock — controlled via open prop ---
vi.mock('@/components/ui/popover', () => {
const PopoverCtx = React.createContext<{
open: boolean
onOpenChange: (v: boolean) => void
}>({ open: false, onOpenChange: () => {} })
return {
Popover: ({
children,
open,
onOpenChange,
}: {
children: React.ReactNode
open?: boolean
onOpenChange?: (v: boolean) => void
}) => (
<PopoverCtx.Provider value={{ open: open ?? false, onOpenChange: onOpenChange ?? (() => {}) }}>
{children}
</PopoverCtx.Provider>
),
PopoverTrigger: ({ render: renderEl }: { render: React.ReactElement<{ onClick?: (e: React.MouseEvent) => void }> }) => {
const { open, onOpenChange } = React.useContext(PopoverCtx)
return React.cloneElement(renderEl, {
onClick: (e: React.MouseEvent) => {
onOpenChange(!open)
renderEl.props.onClick?.(e)
},
})
},
PopoverContent: ({ children }: { children: React.ReactNode }) => {
const { open } = React.useContext(PopoverCtx)
return open ? <div data-testid="popover-content">{children}</div> : null
},
}
})
// Import after mocks
import { useUserSettingsStore } from '@/stores/user-settings/store'
import { IdeaList } from '@/components/ideas/idea-list'
import { createIdeaAction } from '@/actions/ideas'
import type { IdeaDto } from '@/lib/idea-dto'
const PRODUCTS = [
{ id: 'prod-1', name: 'Product A', repo_url: null },
// repo_url ingesteld zodat de optietekst gewoon "Product B" is (zonder "(geen repo)" suffix)
{ id: 'prod-2', name: 'Product B', repo_url: 'https://github.com/org/prod-b' },
]
// Minimal IdeaDto factory
function makeIdea(overrides: Partial<IdeaDto> = {}): IdeaDto {
return {
id: 'idea-1',
code: 'ID-1',
title: 'Test Idee',
description: null,
status: 'draft',
product_id: null,
product: null,
pbi_id: null,
pbi: null,
secondary_products: [],
archived: false,
has_grill_md: false,
has_plan_md: false,
created_at: '2024-01-01T00:00:00.000Z',
updated_at: '2024-01-01T00:00:00.000Z',
...overrides,
}
}
const IDEAS: IdeaDto[] = [
makeIdea({ id: 'idea-1', code: 'ID-1', title: 'Idee Concept', status: 'draft' }),
makeIdea({ id: 'idea-2', code: 'ID-2', title: 'Idee Gegrilld', status: 'grilled' }),
makeIdea({ id: 'idea-3', code: 'ID-3', title: 'Idee Gepland', status: 'planned' }),
]
beforeEach(() => {
vi.clearAllMocks()
useUserSettingsStore.getState().hydrate({}, false)
})
describe('IdeaList — filterpopover', () => {
it('toont de "Filters"-knop in de toolbar (geen inline chip-rij)', () => {
render(<IdeaList ideas={IDEAS} products={[]} isDemo={false} activeProductId={null} />)
// Filters-knop aanwezig
expect(screen.getByText('Filters')).toBeInTheDocument()
// Status-labels zoals "Concept" mogen NIET los zichtbaar zijn zonder popover te openen
// (anders was de oude inline chip-rij er nog)
expect(screen.queryByRole('button', { name: 'Concept' })).not.toBeInTheDocument()
})
it('klik op "Filters" opent de popover en toont 11 statusopties', () => {
render(<IdeaList ideas={IDEAS} products={[]} isDemo={false} activeProductId={null} />)
// Popover nog niet open: content niet zichtbaar
expect(screen.queryByTestId('popover-content')).not.toBeInTheDocument()
fireEvent.click(screen.getByText('Filters'))
// Content verschijnt
expect(screen.getByTestId('popover-content')).toBeInTheDocument()
// 11 statusopties + "Alle" = 12 buttons in de popover
// Controleer specifiek de 11 status-labels
const statusLabels = [
'Concept', 'Grillen', 'Gegrilld', 'Plannen', 'Plan klaar',
'Plan beoordelen', 'Gepland', 'Grill mislukt', 'Plan mislukt',
'Beoordeling mislukt', 'Plan beoordeeld',
]
for (const label of statusLabels) {
expect(screen.getByRole('button', { name: label })).toBeInTheDocument()
}
})
it('klik op een statuschip schrijft de status naar de store', () => {
render(<IdeaList ideas={IDEAS} products={[]} isDemo={false} activeProductId={null} />)
fireEvent.click(screen.getByText('Filters'))
fireEvent.click(screen.getByRole('button', { name: 'Concept' }))
const stored =
useUserSettingsStore.getState().entities.settings.views?.ideasList?.filterStatuses
expect(stored).toContain('draft')
})
it('gehydrateerde filter toont "Filters (1)" en filtert de tabel', () => {
useUserSettingsStore
.getState()
.hydrate({ views: { ideasList: { filterStatuses: ['draft'] } } }, false)
render(<IdeaList ideas={IDEAS} products={[]} isDemo={false} activeProductId={null} />)
// Trigger toont het actieve filteraantal
expect(screen.getByText('Filters (1)')).toBeInTheDocument()
// Alleen het concept-idee is zichtbaar; de andere twee worden weggefilterd
expect(screen.getByText('Idee Concept')).toBeInTheDocument()
expect(screen.queryByText('Idee Gegrilld')).not.toBeInTheDocument()
expect(screen.queryByText('Idee Gepland')).not.toBeInTheDocument()
})
it('"Wis filters" is disabled wanneer geen filter actief is', () => {
render(<IdeaList ideas={IDEAS} products={[]} isDemo={false} activeProductId={null} />)
fireEvent.click(screen.getByText('Filters'))
const wisButton = screen.getByRole('button', { name: 'Wis filters' })
expect(wisButton).toBeDisabled()
})
it('"Wis filters" is enabled en wist de filter wanneer een filter actief is', () => {
useUserSettingsStore
.getState()
.hydrate({ views: { ideasList: { filterStatuses: ['draft'] } } }, false)
render(<IdeaList ideas={IDEAS} products={[]} isDemo={false} activeProductId={null} />)
fireEvent.click(screen.getByText('Filters (1)'))
const wisButton = screen.getByRole('button', { name: 'Wis filters' })
expect(wisButton).not.toBeDisabled()
fireEvent.click(wisButton)
const stored =
useUserSettingsStore.getState().entities.settings.views?.ideasList?.filterStatuses
expect(stored).toEqual([])
})
})
describe('IdeaList — activeProductId voorvullen', () => {
// Hulpfunctie: vind een knop op basis van gedeeltelijke tekstinhoud.
// getByText() werkt hier betrouwbaarder dan getByRole({name}) voor knoppen
// met SVG-icoon omdat de accessible-name-berekening van Base UI knoppen in
// jsdom soms afwijkt van wat we verwachten.
function clickButton(label: string) {
const btn = Array.from(document.querySelectorAll('button')).find(
(b) => b.textContent?.trim().includes(label)
)
if (!btn) throw new Error(`Knop met tekst "${label}" niet gevonden`)
fireEvent.click(btn)
}
it('AC1: "Nieuw idee"-select is voorgevuld met het actieve product', async () => {
render(
<IdeaList ideas={[]} products={PRODUCTS} isDemo={false} activeProductId="prod-2" />
)
clickButton('Nieuw idee')
// Wacht tot het formulier verschijnt; create-form-select toont "Product B" (waarde 'prod-2').
// De toolbar-select toont "Alle producten" (waarde 'all'), zodat displayValue uniek is.
const createFormSelect = await waitFor(() => screen.getByDisplayValue('Product B'))
expect(createFormSelect).toHaveValue('prod-2')
})
it('AC2: "Nieuw idee"-select staat op leeg wanneer activeProductId null is', async () => {
render(
<IdeaList ideas={[]} products={PRODUCTS} isDemo={false} activeProductId={null} />
)
clickButton('Nieuw idee')
// Toolbar-select toont "Alle producten"; create-form-select toont de placeholder (waarde '').
const createFormSelect = await waitFor(() =>
screen.getByDisplayValue('Geen product (kan later worden gekoppeld)')
)
expect(createFormSelect).toHaveValue('')
})
it('AC3: "Snel idee" stuurt product_id gelijk aan activeProductId mee', async () => {
vi.mocked(createIdeaAction).mockResolvedValue({ data: { code: 'ID-99', id: 'idea-99' } } as never)
render(
<IdeaList ideas={[]} products={PRODUCTS} isDemo={false} activeProductId="prod-2" />
)
// Open "Snel idee"-formulier en wacht tot het verschijnt
clickButton('Snel idee')
await waitFor(() => screen.getByPlaceholderText('Titel *'))
// Vul de verplichte titel in
fireEvent.change(screen.getByPlaceholderText('Titel *'), {
target: { value: 'Mijn snel idee' },
})
// Klik Opslaan — startTransition roept createIdeaAction synchroon aan
clickButton('Opslaan')
await waitFor(() => {
expect(createIdeaAction).toHaveBeenCalledWith({
title: 'Mijn snel idee',
description: null,
product_id: 'prod-2',
})
})
})
})

View file

@ -0,0 +1,85 @@
// @vitest-environment jsdom
import { describe, it, expect } from 'vitest'
import { render, screen } from '@testing-library/react'
import '@testing-library/jest-dom'
import JobCard from '@/components/jobs/job-card'
const BASE_PROPS = {
id: 'job-1',
kind: 'TASK_IMPLEMENTATION' as const,
status: 'RUNNING' as const,
productName: 'Scrum4Me',
productCode: 'S4M',
pbiCode: 'PBI-1',
storyCode: 'ST-1',
createdAt: new Date('2026-01-01T10:00:00Z'),
}
describe('JobCard breadcrumb', () => {
it('TASK-job toont productCode, pbiCode en storyCode in de breadcrumb', () => {
render(<JobCard {...BASE_PROPS} />)
const breadcrumb = screen.getByText('S4M PBI-1 ST-1')
expect(breadcrumb).toBeInTheDocument()
})
it('TASK-job zonder productCode valt terug op productName in de breadcrumb', () => {
render(<JobCard {...BASE_PROPS} productCode={null} />)
expect(screen.getByText('Scrum4Me PBI-1 ST-1')).toBeInTheDocument()
})
it('TASK-job laat ontbrekende codes weg uit de breadcrumb', () => {
render(<JobCard {...BASE_PROPS} pbiCode={null} storyCode={null} />)
expect(screen.getByText('S4M')).toBeInTheDocument()
})
it('GRILL-job toont productCode en ideaCode', () => {
render(
<JobCard
{...BASE_PROPS}
kind="IDEA_GRILL"
productCode="S4M"
ideaCode="IDEA-5"
pbiCode={null}
storyCode={null}
/>,
)
expect(screen.getByText('S4M IDEA-5')).toBeInTheDocument()
})
it('SPRINT-job toont productCode en sprintCode', () => {
render(
<JobCard
{...BASE_PROPS}
kind="SPRINT_IMPLEMENTATION"
productCode="S4M"
sprintCode="SP-3"
pbiCode={null}
storyCode={null}
/>,
)
expect(screen.getByText('S4M SP-3')).toBeInTheDocument()
})
})
describe('JobCard datumweergave', () => {
it('toont finishedAt als die beschikbaar is', () => {
const finishedAt = new Date('2026-03-15T14:30:00Z')
render(<JobCard {...BASE_PROPS} startedAt={new Date('2026-03-10T09:00:00Z')} finishedAt={finishedAt} />)
const formatted = finishedAt.toLocaleString('nl-NL', { dateStyle: 'short', timeStyle: 'short' })
expect(screen.getByText(formatted)).toBeInTheDocument()
})
it('toont startedAt als finishedAt ontbreekt', () => {
const startedAt = new Date('2026-03-10T09:00:00Z')
render(<JobCard {...BASE_PROPS} startedAt={startedAt} finishedAt={null} />)
const formatted = startedAt.toLocaleString('nl-NL', { dateStyle: 'short', timeStyle: 'short' })
expect(screen.getByText(formatted)).toBeInTheDocument()
})
it('toont createdAt als zowel finishedAt als startedAt ontbreken', () => {
const createdAt = new Date('2026-01-01T10:00:00Z')
render(<JobCard {...BASE_PROPS} createdAt={createdAt} startedAt={null} finishedAt={null} />)
const formatted = createdAt.toLocaleString('nl-NL', { dateStyle: 'short', timeStyle: 'short' })
expect(screen.getByText(formatted)).toBeInTheDocument()
})
})

View file

@ -0,0 +1,78 @@
// @vitest-environment jsdom
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { render, screen, fireEvent } from '@testing-library/react'
import '@testing-library/jest-dom'
import type { JobWithRelations } from '@/actions/jobs-page'
vi.mock('@/actions/claude-jobs', () => ({
restartClaudeJobAction: vi.fn(),
}))
vi.mock('sonner', () => ({ toast: { error: vi.fn() } }))
import { restartClaudeJobAction } from '@/actions/claude-jobs'
import JobDetailPane from '@/components/jobs/job-detail-pane'
const mockAction = restartClaudeJobAction as ReturnType<typeof vi.fn>
function makeJob(status: JobWithRelations['status']): JobWithRelations {
return {
id: 'job-1',
kind: 'TASK_IMPLEMENTATION',
status,
taskCode: 'T-1',
taskTitle: 'Test taak',
ideaCode: null,
ideaTitle: null,
sprintGoal: null,
sprintCode: null,
productName: 'Scrum4Me',
productCode: null,
storyCode: null,
pbiCode: null,
modelId: null,
inputTokens: null,
outputTokens: null,
cacheReadTokens: null,
cacheWriteTokens: null,
costUsd: null,
branch: null,
prUrl: null,
error: null,
summary: null,
description: null,
verifyResult: null,
startedAt: null,
finishedAt: null,
createdAt: new Date('2026-01-01'),
sprintRunId: null,
}
}
beforeEach(() => {
vi.clearAllMocks()
mockAction.mockResolvedValue({ success: true })
})
describe('JobDetailPane restart button', () => {
it('toont de knop voor FAILED-jobs', () => {
render(<JobDetailPane job={makeJob('FAILED')} isDemo={false} />)
expect(screen.getByRole('button', { name: /opnieuw starten/i })).toBeInTheDocument()
})
it('toont de knop niet voor DONE-jobs', () => {
render(<JobDetailPane job={makeJob('DONE')} isDemo={false} />)
expect(screen.queryByRole('button', { name: /opnieuw starten/i })).not.toBeInTheDocument()
})
it('roept restartClaudeJobAction aan met het juiste id bij klik', () => {
render(<JobDetailPane job={makeJob('FAILED')} isDemo={false} />)
fireEvent.click(screen.getByRole('button', { name: /opnieuw starten/i }))
expect(mockAction).toHaveBeenCalledWith('job-1')
})
it('knop is disabled in demo-modus', () => {
render(<JobDetailPane job={makeJob('FAILED')} isDemo={true} />)
expect(screen.getByRole('button', { name: /opnieuw starten/i })).toBeDisabled()
})
})

View file

@ -0,0 +1,73 @@
// @vitest-environment jsdom
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
import { render, screen, act } from '@testing-library/react'
import { LandscapeGuard } from '@/components/mobile/landscape-guard'
type Listener = (e: MediaQueryListEvent) => void
function mockMatchMedia(initialPortrait: boolean) {
let matches = initialPortrait
let listener: Listener | null = null
const mql = {
get matches() { return matches },
media: '(orientation: portrait)',
onchange: null,
addEventListener: (_: string, l: Listener) => { listener = l },
removeEventListener: () => { listener = null },
addListener: () => {},
removeListener: () => {},
dispatchEvent: () => false,
}
Object.defineProperty(window, 'matchMedia', {
writable: true,
configurable: true,
value: () => mql,
})
return {
setPortrait(p: boolean) {
matches = p
if (listener) listener({ matches: p } as MediaQueryListEvent)
},
}
}
describe('LandscapeGuard', () => {
beforeEach(() => {})
afterEach(() => {
vi.restoreAllMocks()
})
it('renders children always', () => {
mockMatchMedia(false)
render(<LandscapeGuard><div>kids</div></LandscapeGuard>)
expect(screen.getByText('kids')).toBeTruthy()
})
it('shows overlay in portrait', () => {
mockMatchMedia(true)
render(<LandscapeGuard><div>kids</div></LandscapeGuard>)
expect(screen.getByRole('alert').textContent).toContain('Draai je telefoon naar landscape')
// children blijven in DOM (geen unmount → SSE-streams blijven leven)
expect(screen.getByText('kids')).toBeTruthy()
})
it('hides overlay in landscape', () => {
mockMatchMedia(false)
render(<LandscapeGuard><div>kids</div></LandscapeGuard>)
expect(screen.queryByRole('alert')).toBeNull()
})
it('toggles overlay on orientation change', () => {
const ctl = mockMatchMedia(false)
render(<LandscapeGuard><div>kids</div></LandscapeGuard>)
expect(screen.queryByRole('alert')).toBeNull()
act(() => ctl.setPortrait(true))
expect(screen.getByRole('alert')).toBeTruthy()
act(() => ctl.setPortrait(false))
expect(screen.queryByRole('alert')).toBeNull()
})
})

View file

@ -0,0 +1,46 @@
// @vitest-environment jsdom
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { render, screen, fireEvent, waitFor } from '@testing-library/react'
const { logoutMock } = vi.hoisted(() => ({
logoutMock: vi.fn().mockResolvedValue(undefined),
}))
vi.mock('@/actions/auth', () => ({ logoutAction: logoutMock }))
import { LogoutButton } from '@/components/mobile/logout-button'
beforeEach(() => {
logoutMock.mockClear()
})
describe('LogoutButton', () => {
it('toont initieel alleen de Uitloggen-knop, geen dialog', () => {
render(<LogoutButton />)
expect(screen.getByRole('button', { name: /Uitloggen/ })).toBeTruthy()
expect(screen.queryByText(/Weet je zeker/)).toBeNull()
})
it('opent AlertDialog bij klikken op de knop', () => {
render(<LogoutButton />)
fireEvent.click(screen.getByRole('button', { name: /Uitloggen/ }))
expect(screen.getByText('Uitloggen?')).toBeTruthy()
expect(screen.getByText(/Weet je zeker/)).toBeTruthy()
})
it('roept logoutAction aan op bevestigen', async () => {
const { container } = render(<LogoutButton />)
fireEvent.click(screen.getByRole('button', { name: /Uitloggen/ }))
// Het body-portal wordt buiten container gerenderd; query op document.body.
const allButtons = Array.from(document.body.querySelectorAll('button'))
const confirmBtn = allButtons.find(b => b.textContent?.trim() === 'Uitloggen' && !container.contains(b)) ?? allButtons[allButtons.length - 1]
fireEvent.click(confirmBtn)
await waitFor(() => expect(logoutMock).toHaveBeenCalledTimes(1))
})
it('roept logoutAction NIET aan bij annuleren', () => {
render(<LogoutButton />)
fireEvent.click(screen.getByRole('button', { name: /Uitloggen/ }))
fireEvent.click(screen.getByText('Annuleren'))
expect(logoutMock).not.toHaveBeenCalled()
})
})

View file

@ -0,0 +1,57 @@
// @vitest-environment jsdom
import { describe, it, expect, vi } from 'vitest'
import { render, screen } from '@testing-library/react'
import { MobileTabBar } from '@/components/mobile/mobile-tab-bar'
let pathname = '/m/products/p1'
vi.mock('next/navigation', () => ({
usePathname: () => pathname,
}))
function setPathname(p: string) { pathname = p }
describe('MobileTabBar', () => {
it('toont 3 tabs als activeProductId aanwezig is', () => {
setPathname('/m/products/p1')
render(<MobileTabBar activeProductId="p1" />)
expect(screen.getByLabelText('Backlog')).toBeTruthy()
expect(screen.getByLabelText('Solo')).toBeTruthy()
expect(screen.getByLabelText('Settings')).toBeTruthy()
})
it('toont alleen Settings als activeProductId null is', () => {
setPathname('/m/settings')
render(<MobileTabBar activeProductId={null} />)
expect(screen.queryByLabelText('Backlog')).toBeNull()
expect(screen.queryByLabelText('Solo')).toBeNull()
expect(screen.getByLabelText('Settings')).toBeTruthy()
})
it('Backlog-tab is aria-current op /m/products/[id]', () => {
setPathname('/m/products/p1')
render(<MobileTabBar activeProductId="p1" />)
expect(screen.getByLabelText('Backlog').getAttribute('aria-current')).toBe('page')
expect(screen.getByLabelText('Solo').getAttribute('aria-current')).toBeNull()
})
it('Solo-tab is aria-current op /m/products/[id]/solo', () => {
setPathname('/m/products/p1/solo')
render(<MobileTabBar activeProductId="p1" />)
expect(screen.getByLabelText('Solo').getAttribute('aria-current')).toBe('page')
expect(screen.getByLabelText('Backlog').getAttribute('aria-current')).toBeNull()
})
it('Settings-tab is aria-current op /m/settings', () => {
setPathname('/m/settings')
render(<MobileTabBar activeProductId="p1" />)
expect(screen.getByLabelText('Settings').getAttribute('aria-current')).toBe('page')
})
it('tap-targets >=44x44 (h-14 = 56px breedtevulling per tab)', () => {
setPathname('/m/products/p1')
render(<MobileTabBar activeProductId="p1" />)
const tab = screen.getByLabelText('Backlog')
expect(tab.className).toContain('h-14')
expect(tab.className).toContain('flex-1')
})
})

View file

@ -0,0 +1,38 @@
import { describe, it, expect } from 'vitest'
import { readFileSync } from 'node:fs'
import { resolve } from 'node:path'
import { entityDialogContentClasses } from '@/components/shared/entity-dialog-layout'
describe('entityDialogContentClasses', () => {
it('bevat mobile-fullscreen classes (<640px)', () => {
const cls = entityDialogContentClasses
expect(cls).toContain('max-sm:w-screen')
expect(cls).toContain('max-sm:h-screen')
expect(cls).toContain('max-sm:max-w-none')
expect(cls).toContain('max-sm:rounded-none')
})
it('behoudt desktop-classes (>=640px)', () => {
const cls = entityDialogContentClasses
expect(cls).toContain('sm:max-w-[90vw]')
expect(cls).toContain('sm:max-h-[85vh]')
expect(cls).toContain('lg:max-w-[50vw]')
})
})
describe('alle entity-dialogen gebruiken entityDialogContentClasses', () => {
// Regressie-vangnet: voorkomt dat een dialog zijn eigen className meegeeft en
// daarmee de gedeelde mobile-fullscreen-classes ontwijkt.
const files = [
'app/_components/tasks/task-dialog.tsx',
'components/solo/task-detail-dialog.tsx',
'components/backlog/pbi-dialog.tsx',
'components/backlog/story-dialog.tsx',
]
for (const f of files) {
it(`${f} importeert + gebruikt entityDialogContentClasses`, () => {
const src = readFileSync(resolve(process.cwd(), f), 'utf-8')
expect(src).toContain('entityDialogContentClasses')
})
}
})

View file

@ -0,0 +1,179 @@
// @vitest-environment jsdom
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { render, screen, fireEvent } from '@testing-library/react'
import '@testing-library/jest-dom'
import React from 'react'
const pushMock = vi.fn()
const refreshMock = vi.fn()
const pathnameMock = vi.fn(() => '/dashboard')
vi.mock('next/navigation', () => ({
useRouter: () => ({ push: pushMock, refresh: refreshMock }),
usePathname: () => pathnameMock(),
}))
vi.mock('@/actions/active-product', () => ({
setActiveProductAction: vi.fn(),
}))
vi.mock('sonner', () => ({
toast: { error: vi.fn(), success: vi.fn() },
}))
vi.mock('@/components/ui/dropdown-menu', () => {
type Props = React.HTMLAttributes<HTMLDivElement> & {
children?: React.ReactNode
onClick?: () => void
}
const PassThrough = ({ children }: Props) => <>{children}</>
const Forwarding = ({ children, ...rest }: Props) => <div {...rest}>{children}</div>
return {
DropdownMenu: PassThrough,
DropdownMenuTrigger: Forwarding,
DropdownMenuContent: PassThrough,
DropdownMenuItem: ({ children, onClick, className }: Props) => (
<button type="button" onClick={onClick} className={className} data-testid="dd-item">
{children}
</button>
),
DropdownMenuSeparator: () => null,
}
})
vi.mock('@/components/ui/tooltip', () => {
type Props = { children?: React.ReactNode }
const PassThrough = ({ children }: Props) => <>{children}</>
return {
Tooltip: PassThrough,
TooltipContent: PassThrough,
TooltipProvider: PassThrough,
TooltipTrigger: PassThrough,
}
})
vi.mock('@/components/shared/app-icon', () => ({ AppIcon: () => null }))
vi.mock('@/components/shared/user-menu', () => ({ UserMenu: () => null }))
vi.mock('@/components/shared/notifications-bell', () => ({ NotificationsBell: () => null }))
vi.mock('@/components/solo/nav-status-indicators', () => ({
SoloNavStatusIndicators: () => null,
}))
import { setActiveProductAction } from '@/actions/active-product'
import { toast } from 'sonner'
import { NavBar } from '@/components/shared/nav-bar'
const actionMock = setActiveProductAction as unknown as ReturnType<typeof vi.fn>
const toastSuccess = toast.success as unknown as ReturnType<typeof vi.fn>
const products = [
{ id: 'A', name: 'Alpha' },
{ id: 'B', name: 'Beta' },
]
function renderNavBar(overrides: { isDemo?: boolean; activeProductId?: string } = {}) {
const isDemo = overrides.isDemo ?? false
const activeId = overrides.activeProductId ?? 'A'
const activeProduct = products.find(p => p.id === activeId) ?? null
return render(
<NavBar
isDemo={isDemo}
roles={[]}
userId="u1"
username="user"
email={null}
activeProduct={activeProduct}
products={products}
hasActiveSprint={false}
minQuotaPct={100}
/>,
)
}
beforeEach(() => {
vi.clearAllMocks()
actionMock.mockResolvedValue({ success: true })
pathnameMock.mockReturnValue('/dashboard')
})
describe('NavBar — product switch', () => {
it('demo: clicking another product navigates via router.push without calling the action', () => {
renderNavBar({ isDemo: true, activeProductId: 'A' })
fireEvent.click(screen.getByText('Beta'))
expect(pushMock).toHaveBeenCalledWith('/products/B')
expect(actionMock).not.toHaveBeenCalled()
expect(toastSuccess).not.toHaveBeenCalled()
})
it('non-demo: clicking another product calls setActiveProductAction', async () => {
renderNavBar({ isDemo: false, activeProductId: 'A' })
fireEvent.click(screen.getByText('Beta'))
await Promise.resolve()
expect(actionMock).toHaveBeenCalledWith('B')
})
it('non-demo: on /products/A navigates to /products/B', async () => {
pathnameMock.mockReturnValue('/products/A')
renderNavBar({ isDemo: false, activeProductId: 'A' })
fireEvent.click(screen.getByText('Beta'))
await Promise.resolve()
await Promise.resolve()
expect(pushMock).toHaveBeenCalledWith('/products/B')
expect(toastSuccess).toHaveBeenCalled()
})
it('non-demo: on /products/A/sprint/SPR1 navigates to /products/B/sprint', async () => {
pathnameMock.mockReturnValue('/products/A/sprint/SPR1')
renderNavBar({ isDemo: false, activeProductId: 'A' })
fireEvent.click(screen.getByText('Beta'))
await Promise.resolve()
await Promise.resolve()
expect(pushMock).toHaveBeenCalledWith('/products/B/sprint')
expect(toastSuccess).toHaveBeenCalled()
})
it('non-demo: on /products/A/solo navigates to /products/B/solo', async () => {
pathnameMock.mockReturnValue('/products/A/solo')
renderNavBar({ isDemo: false, activeProductId: 'A' })
fireEvent.click(screen.getByText('Beta'))
await Promise.resolve()
await Promise.resolve()
expect(pushMock).toHaveBeenCalledWith('/products/B/solo')
expect(toastSuccess).toHaveBeenCalled()
})
it('non-demo: on /dashboard calls router.refresh and not router.push', async () => {
pathnameMock.mockReturnValue('/dashboard')
renderNavBar({ isDemo: false, activeProductId: 'A' })
fireEvent.click(screen.getByText('Beta'))
await Promise.resolve()
await Promise.resolve()
expect(refreshMock).toHaveBeenCalled()
expect(pushMock).not.toHaveBeenCalled()
expect(toastSuccess).toHaveBeenCalled()
})
})
describe('NavBar — URL-derived active product (demo only)', () => {
it('demo: label and dropdown highlight follow pathname, not the activeProduct prop', () => {
pathnameMock.mockReturnValue('/products/B/sprint')
const { container } = renderNavBar({ isDemo: true, activeProductId: 'A' })
const trigger = container.querySelector('[data-debug-id="nav-bar__product-switcher"]')
expect(trigger?.textContent).toContain('Beta')
expect(trigger?.textContent).not.toContain('Alpha')
const items = screen.getAllByTestId('dd-item')
const itemB = items.find(el => el.textContent?.includes('Beta'))
expect(itemB?.className).toContain('bg-primary-container')
const itemA = items.find(el => el.textContent?.includes('Alpha'))
expect(itemA?.className ?? '').not.toContain('bg-primary-container')
})
it('non-demo: pathname does NOT override the activeProduct prop', () => {
pathnameMock.mockReturnValue('/products/B/sprint')
renderNavBar({ isDemo: false, activeProductId: 'A' })
// Label still reflects server-rendered activeProduct (Alpha)
const items = screen.getAllByTestId('dd-item')
const itemA = items.find(el => el.textContent?.includes('Alpha'))
expect(itemA?.className).toContain('bg-primary-container')
})
})

View file

@ -0,0 +1,174 @@
// @vitest-environment jsdom
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { render, screen, fireEvent } from '@testing-library/react'
import '@testing-library/jest-dom'
import React from 'react'
const pushMock = vi.fn()
const refreshMock = vi.fn()
const pathnameMock = vi.fn(() => '/products/p1/sprint')
vi.mock('next/navigation', () => ({
useRouter: () => ({ push: pushMock, refresh: refreshMock }),
usePathname: () => pathnameMock(),
}))
vi.mock('@/actions/active-sprint', () => ({
setActiveSprintAction: vi.fn(),
switchActiveSprintAction: vi.fn(),
clearActiveSprintAction: vi.fn(),
}))
vi.mock('sonner', () => ({
toast: { error: vi.fn(), success: vi.fn() },
}))
const isDemoMock = { value: false }
const workflowMock: {
value:
| { pendingSprintDraft?: Record<string, { goal: string } | undefined> }
| undefined
} = { value: undefined }
// Mock-state shape moet alle paden dekken die SprintSwitcher selecteert:
// - s.context.isDemo (oude code)
// - s.entities.settings.workflow?.pendingSprintDraft?.[productId]?.goal (PBI-79)
type MockStoreState = {
context: { isDemo: boolean }
entities: {
settings: {
workflow?: {
pendingSprintDraft?: Record<string, { goal: string } | undefined>
}
}
}
}
vi.mock('@/stores/user-settings/store', () => ({
useUserSettingsStore: (selector: (s: MockStoreState) => unknown) =>
selector({
context: { isDemo: isDemoMock.value },
entities: { settings: { workflow: workflowMock.value } },
}),
}))
vi.mock('@/components/ui/dropdown-menu', () => {
type Props = { children?: React.ReactNode; onClick?: () => void; className?: string }
const PassThrough = ({ children }: Props) => <>{children}</>
return {
DropdownMenu: PassThrough,
DropdownMenuTrigger: PassThrough,
DropdownMenuContent: PassThrough,
DropdownMenuItem: ({ children, onClick, className }: Props) => (
<button type="button" onClick={onClick} className={className}>
{children}
</button>
),
DropdownMenuSeparator: () => null,
}
})
vi.mock('@/components/ui/tooltip', () => {
type Props = { children?: React.ReactNode }
const PassThrough = ({ children }: Props) => <>{children}</>
return {
Tooltip: PassThrough,
TooltipContent: PassThrough,
TooltipProvider: PassThrough,
TooltipTrigger: PassThrough,
}
})
import { switchActiveSprintAction } from '@/actions/active-sprint'
import { toast } from 'sonner'
import { SprintSwitcher } from '@/components/shared/sprint-switcher'
const actionMock = switchActiveSprintAction as unknown as ReturnType<typeof vi.fn>
const toastError = toast.error as unknown as ReturnType<typeof vi.fn>
const toastSuccess = toast.success as unknown as ReturnType<typeof vi.fn>
const sprints = [
{ id: 's1', code: 'SP-1', sprint_goal: 'Goal 1', status: 'open' as const },
{ id: 's2', code: 'SP-2', sprint_goal: 'Goal 2', status: 'open' as const },
]
beforeEach(() => {
vi.clearAllMocks()
isDemoMock.value = false
workflowMock.value = undefined
actionMock.mockResolvedValue({ success: true })
pathnameMock.mockReturnValue('/products/p1/sprint')
})
describe('SprintSwitcher', () => {
it('demo: clicking another sprint navigates via router.push without calling the action', () => {
isDemoMock.value = true
render(
<SprintSwitcher
productId="p1"
sprints={sprints}
activeSprint={sprints[0]}
buildingSprintIds={[]}
/>,
)
fireEvent.click(screen.getByText('Goal 2'))
expect(pushMock).toHaveBeenCalledWith('/products/p1/sprint/s2')
expect(actionMock).not.toHaveBeenCalled()
expect(toastError).not.toHaveBeenCalled()
expect(toastSuccess).not.toHaveBeenCalled()
})
it('non-demo: clicking another sprint calls setActiveSprintAction', async () => {
isDemoMock.value = false
render(
<SprintSwitcher
productId="p1"
sprints={sprints}
activeSprint={sprints[0]}
buildingSprintIds={[]}
/>,
)
fireEvent.click(screen.getByText('Goal 2'))
// Wait microtask for the transition to flush.
await Promise.resolve()
expect(actionMock).toHaveBeenCalledWith('p1', 's2')
})
it('clicking the already-active sprint does nothing', () => {
isDemoMock.value = true
render(
<SprintSwitcher
productId="p1"
sprints={sprints}
activeSprint={sprints[0]}
buildingSprintIds={[]}
/>,
)
fireEvent.click(screen.getByText('Goal 1'))
expect(pushMock).not.toHaveBeenCalled()
expect(actionMock).not.toHaveBeenCalled()
})
it('shows the concept-sprint on the trigger when a draft is pending (G5)', () => {
workflowMock.value = { pendingSprintDraft: { p1: { goal: 'Test goal' } } }
render(
<SprintSwitcher
productId="p1"
sprints={sprints}
activeSprint={null}
buildingSprintIds={[]}
/>,
)
expect(screen.getByText('⚙ Concept — Test goal')).toBeInTheDocument()
})
it('shows no concept label on the trigger when no draft is pending', () => {
render(
<SprintSwitcher
productId="p1"
sprints={sprints}
activeSprint={sprints[0]}
buildingSprintIds={[]}
/>,
)
expect(screen.queryByText(/⚙ Concept/)).not.toBeInTheDocument()
})
})

View file

@ -0,0 +1,114 @@
// @vitest-environment jsdom
import '@testing-library/jest-dom'
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { render, screen, fireEvent } from '@testing-library/react'
vi.mock('@/components/ui/dialog', () => ({
Dialog: ({ open, children }: { open: boolean; onOpenChange?: (v: boolean) => void; children: React.ReactNode }) =>
open ? <div data-testid="dialog">{children}</div> : null,
DialogContent: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
DialogHeader: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
DialogTitle: ({ children }: { children: React.ReactNode }) => <h2>{children}</h2>,
}))
vi.mock('@/components/ui/button', () => ({
Button: ({
children,
onClick,
disabled,
variant,
}: {
children?: React.ReactNode
onClick?: () => void
disabled?: boolean
variant?: string
}) => (
<button onClick={onClick} disabled={disabled} data-variant={variant}>
{children}
</button>
),
}))
vi.mock('@/components/ui/tooltip', () => ({
TooltipProvider: ({ children }: { children: React.ReactNode }) => <>{children}</>,
Tooltip: ({ children }: { children: React.ReactNode }) => <>{children}</>,
TooltipTrigger: ({ render: r, children }: { render?: React.ReactElement; children?: React.ReactNode }) =>
r ? <>{r}</> : <>{children}</>,
TooltipContent: ({ children }: { children: React.ReactNode }) => (
<span data-testid="tooltip-content">{children}</span>
),
}))
import { BatchEnqueueBlockerDialog } from '@/components/solo/batch-enqueue-blocker-dialog'
const DEFAULT_PROPS = {
open: true,
onOpenChange: vi.fn(),
prefixCount: 3,
blockerReason: 'task-review' as const,
blockerLabel: 'Story X — Task Y (in review)',
onConfirm: vi.fn(),
onCancel: vi.fn(),
}
beforeEach(() => {
vi.clearAllMocks()
})
describe('BatchEnqueueBlockerDialog', () => {
it('renders title and blocker info for task-review', () => {
render(<BatchEnqueueBlockerDialog {...DEFAULT_PROPS} />)
expect(screen.getByRole('heading')).toHaveTextContent('Blokkade gedetecteerd')
expect(screen.getByText(/Een taak staat op 'review'/)).toBeInTheDocument()
expect(screen.getByText(/Story X — Task Y/)).toBeInTheDocument()
})
it('renders correct blocker label for pbi-blocked', () => {
render(
<BatchEnqueueBlockerDialog
{...DEFAULT_PROPS}
blockerReason="pbi-blocked"
blockerLabel="PBI Z — geblokkeerd"
/>
)
expect(screen.getByText(/De PBI is geblokkeerd/)).toBeInTheDocument()
expect(screen.getByText(/PBI Z/)).toBeInTheDocument()
})
it('calls onConfirm when primary button is clicked', () => {
render(<BatchEnqueueBlockerDialog {...DEFAULT_PROPS} />)
fireEvent.click(screen.getByText(/Stuur 3 taken tot aan blokkade/))
expect(DEFAULT_PROPS.onConfirm).toHaveBeenCalledTimes(1)
})
it('calls onCancel when cancel button is clicked', () => {
render(<BatchEnqueueBlockerDialog {...DEFAULT_PROPS} />)
fireEvent.click(screen.getByText('Annuleer'))
expect(DEFAULT_PROPS.onCancel).toHaveBeenCalledTimes(1)
})
it('disables confirm button and shows tooltip when prefixCount is 0', () => {
render(<BatchEnqueueBlockerDialog {...DEFAULT_PROPS} prefixCount={0} />)
const confirmBtn = screen.getByText(/Stuur 0/).closest('button')
expect(confirmBtn).toBeDisabled()
expect(screen.getByTestId('tooltip-content')).toHaveTextContent('Geen taken vóór blokkade')
})
it('does not render when open is false', () => {
render(<BatchEnqueueBlockerDialog {...DEFAULT_PROPS} open={false} />)
expect(screen.queryByTestId('dialog')).not.toBeInTheDocument()
})
it('uses singular taak when prefixCount is 1', () => {
render(<BatchEnqueueBlockerDialog {...DEFAULT_PROPS} prefixCount={1} />)
expect(screen.getByText(/Stuur 1 taak tot aan blokkade/)).toBeInTheDocument()
expect(screen.getByText(/1 taak vóór de blokkade/)).toBeInTheDocument()
})
})

View file

@ -0,0 +1,207 @@
// @vitest-environment jsdom
import '@testing-library/jest-dom'
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { render, screen, fireEvent, waitFor } from '@testing-library/react'
const { mockPreviewEnqueueAllAction, mockEnqueueClaudeJobsBatchAction } = vi.hoisted(() => ({
mockPreviewEnqueueAllAction: vi.fn(),
mockEnqueueClaudeJobsBatchAction: vi.fn(),
}))
vi.mock('@/actions/claude-jobs', () => ({
previewEnqueueAllAction: mockPreviewEnqueueAllAction,
enqueueClaudeJobsBatchAction: mockEnqueueClaudeJobsBatchAction,
cancelClaudeJobAction: vi.fn(),
enqueueClaudeJobAction: vi.fn(),
}))
vi.mock('next/cache', () => ({ revalidatePath: vi.fn() }))
vi.mock('sonner', () => ({ toast: { error: vi.fn(), success: vi.fn(), info: vi.fn() } }))
vi.mock('@dnd-kit/core', () => ({
DndContext: ({ children }: { children: React.ReactNode }) => <>{children}</>,
DragOverlay: () => null,
PointerSensor: class {},
useSensor: vi.fn(() => ({})),
useSensors: vi.fn(() => []),
closestCorners: vi.fn(),
}))
vi.mock('@/components/ui/button', () => ({
Button: ({
children,
onClick,
disabled,
}: {
children?: React.ReactNode
onClick?: () => void
disabled?: boolean
}) => (
<button onClick={onClick} disabled={disabled}>
{children}
</button>
),
}))
vi.mock('@/components/ui/dialog', () => ({
Dialog: ({ open, children }: { open: boolean; children: React.ReactNode }) =>
open ? <div data-testid="dialog">{children}</div> : null,
DialogContent: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
DialogHeader: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
DialogTitle: ({ children }: { children: React.ReactNode }) => <h2>{children}</h2>,
}))
vi.mock('@/components/ui/tooltip', () => ({
TooltipProvider: ({ children }: { children: React.ReactNode }) => <>{children}</>,
Tooltip: ({ children }: { children: React.ReactNode }) => <>{children}</>,
TooltipTrigger: ({ render: r, children }: { render?: React.ReactElement; children?: React.ReactNode }) =>
r ? <>{r}</> : <>{children}</>,
TooltipContent: () => null,
}))
vi.mock('@/components/shared/demo-tooltip', () => ({
DemoTooltip: ({ children }: { children: React.ReactNode }) => <>{children}</>,
}))
vi.mock('@/components/split-pane/split-pane', () => ({
SplitPane: ({ panes }: { panes: React.ReactNode[] }) => <>{panes}</>,
}))
vi.mock('@/components/solo/solo-column', () => ({
SoloColumn: () => <div data-testid="solo-column" />,
}))
vi.mock('@/components/solo/solo-task-card', () => ({
SoloTaskCardOverlay: () => null,
}))
vi.mock('@/components/solo/task-detail-dialog', () => ({
TaskDetailDialog: () => null,
}))
vi.mock('@/components/solo/unassigned-stories-sheet', () => ({
UnassignedStoriesSheet: () => null,
}))
vi.mock('@/lib/task-status', () => ({
taskStatusToApi: (s: string) => s.toLowerCase(),
}))
import { useSoloStore } from '@/stores/solo-store'
import { SoloBoard } from '@/components/solo/solo-board'
import { toast } from 'sonner'
const PRODUCT_ID = 'prod-1'
const TODO_TASK = {
id: 't1',
title: 'Task 1',
description: null,
implementation_plan: null,
priority: 1,
sort_order: 1,
status: 'TO_DO' as const,
verify_only: false,
verify_required: 'ALIGNED_OR_PARTIAL' as const,
story_id: 'story-1',
story_code: 'ST-1',
story_title: 'Story 1',
task_code: 'ST-1.1',
pbi_code: null,
pbi_title: null,
pbi_description: null,
}
const DEFAULT_PROPS = {
productId: PRODUCT_ID,
sprintGoal: 'Sprint goal',
tasks: [TODO_TASK],
unassignedStories: [],
isDemo: false,
currentUserId: 'user-1',
}
const PREVIEW_NO_BLOCKER = {
tasks: [{ id: 't1', title: 'Task 1', status: 'TO_DO', story_title: 'Story 1', pbi_id: 'pbi-1', pbi_status: 'READY' }],
blockerIndex: null,
blockerReason: null,
}
const PREVIEW_WITH_BLOCKER = {
tasks: [
{ id: 't1', title: 'Task 1', status: 'TO_DO', story_title: 'Story 1', pbi_id: 'pbi-1', pbi_status: 'READY' },
{ id: 't2', title: 'Task 2', status: 'TO_DO', story_title: 'Story 1', pbi_id: 'pbi-1', pbi_status: 'READY' },
{ id: 't3', title: 'Task Review', status: 'REVIEW', story_title: 'Story 1', pbi_id: 'pbi-1', pbi_status: 'READY' },
],
blockerIndex: 2,
blockerReason: 'task-review' as const,
}
beforeEach(() => {
vi.clearAllMocks()
useSoloStore.setState({ tasks: {}, claudeJobsByTaskId: {}, connectedWorkers: 1 })
})
describe('SoloBoard — batch-enqueue flow', () => {
it('no blocker: calls enqueueClaudeJobsBatchAction with TO_DO task IDs directly', async () => {
mockPreviewEnqueueAllAction.mockResolvedValue(PREVIEW_NO_BLOCKER)
mockEnqueueClaudeJobsBatchAction.mockResolvedValue({ success: true, count: 1 })
render(<SoloBoard {...DEFAULT_PROPS} />)
fireEvent.click(screen.getByText(/Start agents/))
await waitFor(() => {
expect(mockPreviewEnqueueAllAction).toHaveBeenCalledWith(PRODUCT_ID)
expect(mockEnqueueClaudeJobsBatchAction).toHaveBeenCalledWith(PRODUCT_ID, ['t1'])
expect(toast.success).toHaveBeenCalledWith(expect.stringContaining('1 agent'))
})
})
it('blocker: shows dialog when preview returns blockerIndex', async () => {
mockPreviewEnqueueAllAction.mockResolvedValue(PREVIEW_WITH_BLOCKER)
render(<SoloBoard {...DEFAULT_PROPS} />)
fireEvent.click(screen.getByText(/Start agents/))
await waitFor(() => {
expect(screen.getByTestId('dialog')).toBeInTheDocument()
expect(screen.getByText(/Blokkade gedetecteerd/)).toBeInTheDocument()
})
expect(mockEnqueueClaudeJobsBatchAction).not.toHaveBeenCalled()
})
it('blocker dialog confirm: enqueues prefix tasks and closes', async () => {
mockPreviewEnqueueAllAction.mockResolvedValue(PREVIEW_WITH_BLOCKER)
mockEnqueueClaudeJobsBatchAction.mockResolvedValue({ success: true, count: 2 })
render(<SoloBoard {...DEFAULT_PROPS} />)
fireEvent.click(screen.getByText(/Start agents/))
await waitFor(() => screen.getByTestId('dialog'))
fireEvent.click(screen.getByText(/Stuur 2 taken tot aan blokkade/))
await waitFor(() => {
expect(mockEnqueueClaudeJobsBatchAction).toHaveBeenCalledWith(PRODUCT_ID, ['t1', 't2'])
expect(toast.success).toHaveBeenCalledWith(expect.stringContaining('2 agents'))
expect(screen.queryByTestId('dialog')).not.toBeInTheDocument()
})
})
it('blocker dialog cancel: closes dialog without enqueuing', async () => {
mockPreviewEnqueueAllAction.mockResolvedValue(PREVIEW_WITH_BLOCKER)
render(<SoloBoard {...DEFAULT_PROPS} />)
fireEvent.click(screen.getByText(/Start agents/))
await waitFor(() => screen.getByTestId('dialog'))
fireEvent.click(screen.getByText('Annuleer'))
await waitFor(() => {
expect(screen.queryByTestId('dialog')).not.toBeInTheDocument()
})
expect(mockEnqueueClaudeJobsBatchAction).not.toHaveBeenCalled()
})
it('preview error: shows toast without opening dialog', async () => {
mockPreviewEnqueueAllAction.mockResolvedValue({ error: 'Geen toegang' })
render(<SoloBoard {...DEFAULT_PROPS} />)
fireEvent.click(screen.getByText(/Start agents/))
await waitFor(() => {
expect(toast.error).toHaveBeenCalledWith('Geen toegang')
})
expect(screen.queryByTestId('dialog')).not.toBeInTheDocument()
})
})

View file

@ -0,0 +1,84 @@
// @vitest-environment jsdom
import '@testing-library/jest-dom'
import { describe, it, expect, vi } from 'vitest'
import { render, screen } from '@testing-library/react'
import type { SoloTask } from '@/components/solo/solo-board'
vi.mock('@/components/ui/tooltip', () => ({
TooltipProvider: ({ children }: { children: React.ReactNode }) => <>{children}</>,
Tooltip: ({ children }: { children: React.ReactNode }) => <>{children}</>,
TooltipTrigger: ({ children }: { children?: React.ReactNode }) => <>{children}</>,
TooltipContent: ({ children }: { children: React.ReactNode }) => <span data-testid="tooltip-content">{children}</span>,
}))
vi.mock('@dnd-kit/core', () => ({
useDraggable: () => ({ attributes: {}, listeners: {}, setNodeRef: vi.fn(), transform: null, isDragging: false }),
}))
vi.mock('@/stores/solo-store', () => ({
useSoloStore: () => null,
}))
vi.mock('@/components/shared/code-badge', () => ({
CodeBadge: ({ code }: { code: string }) => <span data-testid="code-badge">{code}</span>,
}))
import { SoloTaskCard, SoloTaskCardOverlay } from '@/components/solo/solo-task-card'
function makeSoloTask(overrides: Partial<SoloTask> = {}): SoloTask {
return {
id: 'task-1',
title: 'Taak titel',
description: 'Omschrijving van de taak die langer is dan tachtig tekens voor test',
implementation_plan: null,
priority: 2,
sort_order: 0,
status: 'TO_DO',
verify_only: false,
verify_required: 'ALIGNED',
story_id: 'story-1',
story_code: 'ST-1',
story_title: 'Story titel',
task_code: 'T-1',
pbi_code: 'PBI-1',
pbi_title: 'PBI titel',
pbi_description: 'PBI omschrijving',
...overrides,
}
}
describe('SoloTaskCard', () => {
it('toont taaknaam, task_code, pbi_code, story_code, story_title', () => {
render(<SoloTaskCard task={makeSoloTask()} isDemo={false} onClick={vi.fn()} />)
expect(screen.getAllByText('Taak titel').length).toBeGreaterThan(0)
expect(screen.getAllByText('T-1').length).toBeGreaterThan(0)
expect(screen.getAllByText('PBI-1').length).toBeGreaterThan(0)
expect(screen.getByText('ST-1')).toBeInTheDocument()
expect(screen.getByText('Story titel')).toBeInTheDocument()
})
it('verbergt pbi_code badge als pbi_code null is', () => {
render(<SoloTaskCard task={makeSoloTask({ pbi_code: null })} isDemo={false} onClick={vi.fn()} />)
const badges = screen.queryAllByTestId('code-badge')
const codes = badges.map(b => b.textContent)
expect(codes).not.toContain('PBI-1')
})
it('verbergt description als description null is', () => {
const task = makeSoloTask({ description: null })
render(<SoloTaskCard task={task} isDemo={false} onClick={vi.fn()} />)
expect(screen.queryByText(/Omschrijving/)).toBeNull()
})
it('toont description als tekst', () => {
render(<SoloTaskCard task={makeSoloTask()} isDemo={false} onClick={vi.fn()} />)
expect(screen.getAllByText('Omschrijving van de taak die langer is dan tachtig tekens voor test').length).toBeGreaterThan(0)
})
})
describe('SoloTaskCardOverlay', () => {
it('toont taaknaam en codes zonder tooltip-wrappers', () => {
render(<SoloTaskCardOverlay task={makeSoloTask()} />)
expect(screen.getByText('Taak titel')).toBeInTheDocument()
expect(screen.getByText('T-1')).toBeInTheDocument()
expect(screen.getByText('PBI-1')).toBeInTheDocument()
expect(screen.queryAllByTestId('tooltip-content')).toHaveLength(0)
})
})

View file

@ -60,10 +60,14 @@ const baseTask: SoloTask = {
sort_order: 1,
status: 'TO_DO',
verify_only: false,
verify_required: 'ALIGNED_OR_PARTIAL',
story_id: 'story-1',
story_code: 'ST-100',
story_title: 'Test Story',
task_code: 'ST-100.1',
pbi_code: null,
pbi_title: null,
pbi_description: null,
}
const DEFAULT_PROPS = {

View file

@ -1,28 +1,35 @@
// @vitest-environment jsdom
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
import { render, screen, fireEvent } from '@testing-library/react'
import { SplitPane } from '@/components/split-pane/split-pane'
// Helper to set a cookie
function setCookie(key: string, value: string) {
Object.defineProperty(document, 'cookie', {
writable: true,
configurable: true,
value: `sp:${key}=${encodeURIComponent(value)}`,
vi.mock('@/actions/user-settings', () => ({
updateUserSettingsAction: vi.fn().mockResolvedValue({ success: true, settings: {} }),
}))
import { SplitPane } from '@/components/split-pane/split-pane'
import { useUserSettingsStore } from '@/stores/user-settings/store'
function seedPositions(key: string, positions: number[]) {
useUserSettingsStore.setState((s) => {
s.entities.settings = {
layout: {
splitPanePositions: { [key]: positions },
},
}
})
}
function clearCookies() {
Object.defineProperty(document, 'cookie', {
writable: true,
configurable: true,
value: '',
function resetStore() {
useUserSettingsStore.setState((s) => {
s.entities.settings = {}
s.context.hydrated = false
s.context.isDemo = false
})
}
describe('SplitPane', () => {
beforeEach(() => {
clearCookies()
resetStore()
// Default: desktop viewport
Object.defineProperty(window, 'innerWidth', { writable: true, configurable: true, value: 1440 })
window.dispatchEvent(new Event('resize'))
@ -64,9 +71,8 @@ describe('SplitPane', () => {
expect(dividers).toHaveLength(2)
})
it('restores splits from cookie on mount', () => {
const stored = JSON.stringify([40, 60])
setCookie('test-restore', stored)
it('restores splits from user-settings store on mount', () => {
seedPositions('test-restore', [40, 60])
const { container } = render(
<SplitPane
@ -81,8 +87,9 @@ describe('SplitPane', () => {
expect(paneDiv).toBeTruthy()
})
it('falls back to defaultSplit when cookie is invalid', () => {
setCookie('test-invalid', 'not-valid-json')
it('falls back to defaultSplit when persisted positions are invalid', () => {
// Wrong number of values for a 2-pane layout
seedPositions('test-invalid', [10, 30, 60])
const { container } = render(
<SplitPane

View file

@ -0,0 +1,119 @@
// @vitest-environment jsdom
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { render, screen, fireEvent, waitFor } from '@testing-library/react'
vi.mock('next/navigation', () => ({ useRouter: () => ({ push: vi.fn() }) }))
vi.mock('@/actions/tasks', () => ({
saveTask: vi.fn(),
deleteTask: vi.fn(),
}))
vi.mock('sonner', () => ({ toast: { success: vi.fn(), error: vi.fn() } }))
import { SprintTaskDialogMount } from '@/components/sprint/sprint-task-dialog-mount'
import { useSprintWorkspaceStore } from '@/stores/sprint-workspace/store'
import type { SprintWorkspaceTaskDetail } from '@/stores/sprint-workspace/types'
const TASK_DETAIL: SprintWorkspaceTaskDetail = {
id: 't1',
code: 'T-1',
title: 'Mijn taak',
description: 'Beschrijving',
priority: 2,
sort_order: 1,
status: 'in_progress',
story_id: 'story-1',
sprint_id: 'sprint-1',
created_at: new Date('2026-01-15'),
_detail: true,
implementation_plan: 'Stap 1\nStap 2',
}
function resetStore() {
useSprintWorkspaceStore.setState((s) => {
s.context.activeProduct = null
s.context.activeSprintId = null
s.context.activeStoryId = null
s.context.activeTaskId = null
s.entities.sprintsById = {}
s.entities.storiesById = {}
s.entities.tasksById = {}
s.relations.sprintIdsByProduct = {}
s.relations.storyIdsBySprint = {}
s.relations.taskIdsByStory = {}
s.loading.loadedProductSprintsIds = {}
s.loading.loadingProductId = null
s.loading.loadedSprintIds = {}
s.loading.loadingSprintId = null
s.loading.loadedStoryIds = {}
s.loading.loadedTaskIds = {}
s.loading.activeRequestId = null
s.pendingMutations = {}
})
}
beforeEach(() => {
resetStore()
})
afterEach(() => {
vi.restoreAllMocks()
})
describe('SprintTaskDialogMount', () => {
it('rendert niets wanneer er geen active task is', () => {
const { container } = render(
<SprintTaskDialogMount productId="p1" isDemo={false} />,
)
expect(container.textContent).toBe('')
})
it('rendert niets wanneer active task geen _detail heeft', () => {
useSprintWorkspaceStore.setState((s) => {
s.entities.tasksById['t1'] = {
id: 't1',
code: 'T-1',
title: 'Mijn taak',
description: null,
priority: 2,
sort_order: 1,
status: 'todo',
story_id: 'story-1',
sprint_id: 'sprint-1',
created_at: new Date(),
}
s.context.activeTaskId = 't1'
})
const { container } = render(
<SprintTaskDialogMount productId="p1" isDemo={false} />,
)
expect(container.textContent).toBe('')
})
it('rendert TaskDialog met titel "Taak bewerken" wanneer detail aanwezig is', () => {
useSprintWorkspaceStore.setState((s) => {
s.entities.tasksById['t1'] = TASK_DETAIL
s.context.activeTaskId = 't1'
})
render(<SprintTaskDialogMount productId="p1" isDemo={false} />)
expect(screen.getByText('Taak bewerken')).toBeTruthy()
expect((screen.getByLabelText(/Titel/) as HTMLInputElement).value).toBe('Mijn taak')
})
it('clear activeTaskId wanneer Annuleren wordt geklikt', async () => {
useSprintWorkspaceStore.setState((s) => {
s.entities.tasksById['t1'] = TASK_DETAIL
s.context.activeTaskId = 't1'
})
render(<SprintTaskDialogMount productId="p1" isDemo={false} />)
fireEvent.click(screen.getByRole('button', { name: 'Annuleren' }))
await waitFor(() => {
expect(useSprintWorkspaceStore.getState().context.activeTaskId).toBeNull()
})
})
})

View file

@ -0,0 +1,57 @@
// @vitest-environment jsdom
import { describe, it, expect, vi } from 'vitest'
import { useDialogSubmitShortcut } from '@/components/shared/use-dialog-submit-shortcut'
function makeEvent(opts: Partial<KeyboardEvent>) {
return {
metaKey: false,
ctrlKey: false,
key: '',
preventDefault: vi.fn(),
...opts,
} as unknown as React.KeyboardEvent
}
describe('useDialogSubmitShortcut', () => {
it('triggert submit op Cmd+Enter', () => {
const submit = vi.fn()
const handler = useDialogSubmitShortcut(submit)
const e = makeEvent({ metaKey: true, key: 'Enter' })
handler(e)
expect(submit).toHaveBeenCalledTimes(1)
expect(e.preventDefault).toHaveBeenCalled()
})
it('triggert submit op Ctrl+Enter', () => {
const submit = vi.fn()
const handler = useDialogSubmitShortcut(submit)
const e = makeEvent({ ctrlKey: true, key: 'Enter' })
handler(e)
expect(submit).toHaveBeenCalledTimes(1)
})
it('triggert NIET op Enter zonder modifier', () => {
const submit = vi.fn()
const handler = useDialogSubmitShortcut(submit)
const e = makeEvent({ key: 'Enter' })
handler(e)
expect(submit).not.toHaveBeenCalled()
expect(e.preventDefault).not.toHaveBeenCalled()
})
it('triggert NIET op Cmd+andere toets', () => {
const submit = vi.fn()
const handler = useDialogSubmitShortcut(submit)
const e = makeEvent({ metaKey: true, key: 'a' })
handler(e)
expect(submit).not.toHaveBeenCalled()
})
})

View file

@ -0,0 +1,50 @@
// @vitest-environment jsdom
import { describe, it, expect, vi } from 'vitest'
import { renderHook, act } from '@testing-library/react'
import { useDirtyCloseGuard } from '@/components/shared/use-dirty-close-guard'
describe('useDirtyCloseGuard', () => {
it('sluit direct als form niet dirty is', () => {
const onClose = vi.fn()
const { result } = renderHook(() => useDirtyCloseGuard(false, onClose))
act(() => result.current.attemptClose())
expect(onClose).toHaveBeenCalledTimes(1)
expect(result.current.confirmOpen).toBe(false)
})
it('opent confirm als form dirty is', () => {
const onClose = vi.fn()
const { result } = renderHook(() => useDirtyCloseGuard(true, onClose))
act(() => result.current.attemptClose())
expect(onClose).not.toHaveBeenCalled()
expect(result.current.confirmOpen).toBe(true)
})
it('confirmDiscard sluit confirm en roept onClose', () => {
const onClose = vi.fn()
const { result } = renderHook(() => useDirtyCloseGuard(true, onClose))
act(() => result.current.attemptClose())
expect(result.current.confirmOpen).toBe(true)
act(() => result.current.confirmDiscard())
expect(onClose).toHaveBeenCalledTimes(1)
expect(result.current.confirmOpen).toBe(false)
})
it('setConfirmOpen(false) annuleert zonder onClose te roepen', () => {
const onClose = vi.fn()
const { result } = renderHook(() => useDirtyCloseGuard(true, onClose))
act(() => result.current.attemptClose())
act(() => result.current.setConfirmOpen(false))
expect(onClose).not.toHaveBeenCalled()
expect(result.current.confirmOpen).toBe(false)
})
})

View file

@ -0,0 +1,147 @@
// @vitest-environment jsdom
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { renderHook, act } from '@testing-library/react'
import { useJobsStore } from '@/stores/jobs-store'
import useJobsRealtime from '@/hooks/use-jobs-realtime'
type Listener = (event: { data: string }) => void
class MockEventSource {
static instance: MockEventSource | null = null
private listeners: Record<string, Listener[]> = {}
onerror: (() => void) | null = null
constructor(_url: string) {
MockEventSource.instance = this
}
addEventListener(type: string, listener: Listener) {
if (!this.listeners[type]) this.listeners[type] = []
this.listeners[type].push(listener)
}
dispatch(type: string, data: unknown) {
for (const l of this.listeners[type] ?? []) {
l({ data: JSON.stringify(data) })
}
}
close() {}
}
const fullJob = {
id: 'job-unknown-1',
kind: 'TASK_IMPLEMENTATION',
status: 'RUNNING',
taskCode: 'T-1',
taskTitle: 'Test',
ideaCode: null,
ideaTitle: null,
sprintGoal: null,
sprintCode: null,
productName: 'Scrum4Me',
productCode: null,
storyCode: null,
pbiCode: null,
modelId: null,
inputTokens: null,
outputTokens: null,
cacheReadTokens: null,
cacheWriteTokens: null,
costUsd: null,
branch: null,
prUrl: null,
error: null,
summary: null,
description: null,
verifyResult: null,
startedAt: null,
finishedAt: null,
createdAt: new Date('2026-01-01'),
sprintRunId: null,
}
beforeEach(() => {
vi.stubGlobal('EventSource', MockEventSource)
MockEventSource.instance = null
// Lege store
useJobsStore.setState({ activeJobs: [], doneJobs: [], selectedJobId: null })
// fetch resolveert naar de volledige job
vi.stubGlobal(
'fetch',
vi.fn().mockImplementation(async () => ({
ok: true,
json: async () => fullJob,
}))
)
})
afterEach(() => {
vi.unstubAllGlobals()
vi.restoreAllMocks()
})
describe('useJobsRealtime: fetch-on-unknown', () => {
it('haalt onbekende job op via REST bij message-event', async () => {
renderHook(() => useJobsRealtime())
const es = MockEventSource.instance!
// Dispatch twee events met hetzelfde onbekende job_id gelijktijdig
act(() => {
es.dispatch('message', { job_id: 'job-unknown-1', status: 'RUNNING' })
es.dispatch('message', { job_id: 'job-unknown-1', status: 'RUNNING' })
})
// Wacht op alle microtasks / fetch-promises
await act(async () => {
await Promise.resolve()
})
expect(fetch).toHaveBeenCalledTimes(1)
expect(fetch).toHaveBeenCalledWith('/api/jobs/job-unknown-1')
const { activeJobs } = useJobsStore.getState()
expect(activeJobs.some(j => j.id === 'job-unknown-1')).toBe(true)
expect(activeJobs.find(j => j.id === 'job-unknown-1')?.taskTitle).toBe('Test')
})
it('gebruikt partial-upsert voor bekende jobs bij message-event', async () => {
// Zet een bekende job in de store
useJobsStore.setState({
activeJobs: [{ ...fullJob, id: 'job-known-1', status: 'QUEUED' } as never],
doneJobs: [],
selectedJobId: null,
})
renderHook(() => useJobsRealtime())
const es = MockEventSource.instance!
act(() => {
es.dispatch('message', { job_id: 'job-known-1', status: 'RUNNING', branch: 'feat/x' })
})
await act(async () => { await Promise.resolve() })
expect(fetch).not.toHaveBeenCalled()
const { activeJobs } = useJobsStore.getState()
expect(activeJobs.find(j => j.id === 'job-known-1')?.status).toBe('RUNNING')
})
it('haalt onbekende job op via REST bij jobs_initial-event', async () => {
renderHook(() => useJobsRealtime())
const es = MockEventSource.instance!
act(() => {
es.dispatch('jobs_initial', [{ job_id: 'job-unknown-1', status: 'RUNNING' }])
})
await act(async () => { await Promise.resolve() })
expect(fetch).toHaveBeenCalledTimes(1)
expect(fetch).toHaveBeenCalledWith('/api/jobs/job-unknown-1')
const { activeJobs } = useJobsStore.getState()
expect(activeJobs.some(j => j.id === 'job-unknown-1')).toBe(true)
})
})

View file

@ -0,0 +1,190 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
vi.mock('@/lib/prisma', () => ({
prisma: {
sprint: { findFirst: vi.fn() },
user: {
findUnique: vi.fn(),
update: vi.fn().mockResolvedValue({}),
},
$executeRaw: vi.fn().mockResolvedValue(1),
},
}))
import { prisma } from '@/lib/prisma'
import type { UserSettings } from '@/lib/user-settings'
import {
clearActiveSprintInSettings,
readStoredActiveSprintState,
resolveActiveSprint,
} from '@/lib/active-sprint'
const mockPrisma = prisma as unknown as {
sprint: { findFirst: ReturnType<typeof vi.fn> }
user: {
findUnique: ReturnType<typeof vi.fn>
update: ReturnType<typeof vi.fn>
}
$executeRaw: ReturnType<typeof vi.fn>
}
function withSettings(settings: UserSettings) {
mockPrisma.user.findUnique.mockResolvedValueOnce({ settings })
}
describe('readStoredActiveSprintState', () => {
it('returns unset when activeSprints map is absent', () => {
expect(readStoredActiveSprintState({}, 'p1')).toEqual({ kind: 'unset' })
})
it('returns unset when productId key is absent', () => {
const settings: UserSettings = {
layout: { activeSprints: { p2: 'sprint-2' } },
}
expect(readStoredActiveSprintState(settings, 'p1')).toEqual({
kind: 'unset',
})
})
it('returns cleared when key is present with null value', () => {
const settings: UserSettings = {
layout: { activeSprints: { p1: null } },
}
expect(readStoredActiveSprintState(settings, 'p1')).toEqual({
kind: 'cleared',
})
})
it('returns set when key is present with string value', () => {
const settings: UserSettings = {
layout: { activeSprints: { p1: 'sprint-1' } },
}
expect(readStoredActiveSprintState(settings, 'p1')).toEqual({
kind: 'set',
sprintId: 'sprint-1',
})
})
})
describe('resolveActiveSprint', () => {
beforeEach(() => {
vi.clearAllMocks()
})
it('returns null without fallback when key is explicitly null (cleared)', async () => {
withSettings({ layout: { activeSprints: { p1: null } } })
const result = await resolveActiveSprint('p1', 'user-1')
expect(result).toBeNull()
expect(mockPrisma.sprint.findFirst).not.toHaveBeenCalled()
})
it('returns the stored sprint when key is set and sprint exists', async () => {
withSettings({ layout: { activeSprints: { p1: 'sprint-1' } } })
mockPrisma.sprint.findFirst.mockResolvedValueOnce({
id: 'sprint-1',
code: 'SP-1',
status: 'OPEN',
})
const result = await resolveActiveSprint('p1', 'user-1')
expect(result).toEqual({ id: 'sprint-1', code: 'SP-1', status: 'OPEN' })
expect(mockPrisma.sprint.findFirst).toHaveBeenCalledTimes(1)
})
it('falls back when stored sprint is not found in DB', async () => {
withSettings({ layout: { activeSprints: { p1: 'stale-id' } } })
mockPrisma.sprint.findFirst
.mockResolvedValueOnce(null) // stored lookup misses
.mockResolvedValueOnce({ id: 'sprint-open', code: 'SP-O', status: 'OPEN' })
const result = await resolveActiveSprint('p1', 'user-1')
expect(result).toEqual({
id: 'sprint-open',
code: 'SP-O',
status: 'OPEN',
})
})
it('falls back to first OPEN sprint when key is absent', async () => {
withSettings({})
mockPrisma.sprint.findFirst.mockResolvedValueOnce({
id: 'sprint-open',
code: 'SP-O',
status: 'OPEN',
})
const result = await resolveActiveSprint('p1', 'user-1')
expect(result).toEqual({
id: 'sprint-open',
code: 'SP-O',
status: 'OPEN',
})
})
it('falls back to recent CLOSED sprint when no OPEN exists', async () => {
withSettings({})
mockPrisma.sprint.findFirst
.mockResolvedValueOnce(null) // no OPEN
.mockResolvedValueOnce({
id: 'sprint-closed',
code: 'SP-C',
status: 'CLOSED',
})
const result = await resolveActiveSprint('p1', 'user-1')
expect(result).toEqual({
id: 'sprint-closed',
code: 'SP-C',
status: 'CLOSED',
})
})
it('returns null when key absent and no sprints exist', async () => {
withSettings({})
mockPrisma.sprint.findFirst.mockResolvedValue(null)
const result = await resolveActiveSprint('p1', 'user-1')
expect(result).toBeNull()
})
})
describe('clearActiveSprintInSettings', () => {
beforeEach(() => {
vi.clearAllMocks()
})
it('writes null instead of deleting the key', async () => {
withSettings({
layout: { activeSprints: { p1: 'sprint-1', p2: 'sprint-2' } },
})
await clearActiveSprintInSettings('user-1', 'p1')
expect(mockPrisma.user.update).toHaveBeenCalledTimes(1)
const updateArg = mockPrisma.user.update.mock.calls[0][0] as {
data: { settings: UserSettings }
}
expect(updateArg.data.settings.layout?.activeSprints).toEqual({
p1: null,
p2: 'sprint-2',
})
})
it('adds the key with null when previously unset', async () => {
withSettings({})
await clearActiveSprintInSettings('user-1', 'p1')
const updateArg = mockPrisma.user.update.mock.calls[0][0] as {
data: { settings: UserSettings }
}
expect(updateArg.data.settings.layout?.activeSprints).toEqual({ p1: null })
})
})

View file

@ -0,0 +1,53 @@
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
const getSessionMock = vi.fn()
const isPairedSessionExpiredMock = vi.fn()
const redirectMock = vi.fn(() => { throw new Error('REDIRECT_CALLED') })
const prismaUserRoleFindFirstMock = vi.fn()
vi.mock('@/lib/auth', () => ({ getSession: getSessionMock }))
vi.mock('@/lib/auth/pairing', () => ({ isPairedSessionExpired: isPairedSessionExpiredMock }))
vi.mock('next/navigation', () => ({ redirect: redirectMock }))
vi.mock('@/lib/prisma', () => ({
prisma: { userRole: { findFirst: prismaUserRoleFindFirstMock } },
}))
describe('requireSession', () => {
beforeEach(() => {
getSessionMock.mockReset()
isPairedSessionExpiredMock.mockReset()
redirectMock.mockClear()
})
afterEach(() => {
vi.resetModules()
})
it('redirect /login als userId ontbreekt', async () => {
getSessionMock.mockResolvedValue({ userId: undefined, destroy: vi.fn() })
isPairedSessionExpiredMock.mockReturnValue(false)
const { requireSession } = await import('@/lib/auth-guard')
await expect(requireSession()).rejects.toThrow('REDIRECT_CALLED')
expect(redirectMock).toHaveBeenCalledWith('/login')
})
it('vernietigt + redirect /login als paired-sessie verlopen is', async () => {
const destroy = vi.fn().mockResolvedValue(undefined)
getSessionMock.mockResolvedValue({ userId: 'u1', destroy })
isPairedSessionExpiredMock.mockReturnValue(true)
const { requireSession } = await import('@/lib/auth-guard')
await expect(requireSession()).rejects.toThrow('REDIRECT_CALLED')
expect(destroy).toHaveBeenCalled()
expect(redirectMock).toHaveBeenCalledWith('/login')
})
it('geeft sessie terug als alles ok', async () => {
const sess = { userId: 'u1', destroy: vi.fn() }
getSessionMock.mockResolvedValue(sess)
isPairedSessionExpiredMock.mockReturnValue(false)
const { requireSession } = await import('@/lib/auth-guard')
const result = await requireSession()
expect(result).toBe(sess)
expect(redirectMock).not.toHaveBeenCalled()
})
})

View file

@ -34,7 +34,7 @@ describe('chart-colors', () => {
it('JOB_STATUS_COLORS has all ClaudeJobStatus keys and non-empty values', () => {
const keys: (keyof typeof JOB_STATUS_COLORS)[] = [
'queued', 'claimed', 'running', 'done', 'failed', 'cancelled',
'queued', 'claimed', 'running', 'done', 'failed', 'cancelled', 'skipped',
]
for (const key of keys) {
expect(JOB_STATUS_COLORS[key]).toBeTruthy()

View file

@ -0,0 +1,25 @@
import { describe, it, expect } from 'vitest'
import { parseCodeNumber } from '@/lib/code'
describe('parseCodeNumber', () => {
it('parses a standard story code', () => {
expect(parseCodeNumber('ST-001')).toBe(1)
})
it('parses a task code', () => {
expect(parseCodeNumber('T-42')).toBe(42)
})
it('parses a large number', () => {
expect(parseCodeNumber('ST-1000')).toBe(1000)
})
it('returns MAX_SAFE_INTEGER for a code with no trailing digits', () => {
expect(parseCodeNumber('FOO')).toBe(Number.MAX_SAFE_INTEGER)
})
it('returns MAX_SAFE_INTEGER for an empty string', () => {
expect(parseCodeNumber('')).toBe(Number.MAX_SAFE_INTEGER)
})
})

View file

@ -0,0 +1,23 @@
import { describe, it, expect, vi } from 'vitest'
import { debugProps } from '@/lib/debug'
describe('debugProps', () => {
it('returns data-debug-id attr in dev mode', () => {
const result = debugProps('sprint-board', 'SprintBoard', 'components/sprint/sprint-board.tsx')
expect(result).toEqual({
'data-debug-id': 'sprint-board',
})
})
it('returns empty object in production mode', () => {
const original = process.env.NODE_ENV
try {
vi.stubEnv('NODE_ENV', 'production')
const result = debugProps('sprint-board', 'SprintBoard', 'components/sprint/sprint-board.tsx')
expect(result).toEqual({})
} finally {
vi.stubEnv('NODE_ENV', original ?? 'test')
}
})
})

View file

@ -0,0 +1,21 @@
import { describe, it, expect } from 'vitest'
import { formatIdeaCode } from '@/lib/idea-code'
describe('formatIdeaCode', () => {
it('pads to 3 digits', () => {
expect(formatIdeaCode(1)).toBe('IDEA-001')
expect(formatIdeaCode(42)).toBe('IDEA-042')
expect(formatIdeaCode(999)).toBe('IDEA-999')
})
it('does not truncate beyond pad-width', () => {
expect(formatIdeaCode(1000)).toBe('IDEA-1000')
expect(formatIdeaCode(99999)).toBe('IDEA-99999')
})
})
// Integration-style concurrency-test op nextIdeaCode is in
// __tests__/integration/ tests die de echte DB raken (zie M12 verificatie-stap).
// Hier alleen de pure formatter; de increment-logica leunt op Prisma's
// row-lock in $transaction die we per-database vertrouwen.

View file

@ -0,0 +1,138 @@
import { describe, it, expect } from 'vitest'
import { parsePlanMd } from '@/lib/idea-plan-parser'
const VALID = `---
pbi:
title: Test PBI
priority: 2
stories:
- title: Eerste flow
priority: 2
tasks:
- title: Setup
priority: 2
implementation_plan: |
1. Doe X
2. Doe Y
---
# Overwegingen
Dit is de body, niet geparsed.
`
describe('parsePlanMd', () => {
it('parses a valid plan', () => {
const r = parsePlanMd(VALID)
expect(r.ok).toBe(true)
if (r.ok) {
expect(r.plan.pbi.title).toBe('Test PBI')
expect(r.plan.stories).toHaveLength(1)
expect(r.plan.stories[0].tasks).toHaveLength(1)
expect(r.plan.stories[0].tasks[0].implementation_plan).toContain('Doe X')
expect(r.body).toContain('# Overwegingen')
}
})
it('rejects when frontmatter is missing', () => {
const r = parsePlanMd('# Just markdown\n\nNo frontmatter here.')
expect(r.ok).toBe(false)
if (!r.ok) {
expect(r.errors[0].line).toBe(1)
expect(r.errors[0].message).toMatch(/frontmatter/i)
}
})
it('reports yaml syntax error with line info', () => {
const broken = `---
pbi:
title: Test
priority: [unclosed
stories:
- foo
---
body
`
const r = parsePlanMd(broken)
expect(r.ok).toBe(false)
if (!r.ok) {
expect(r.errors[0].message.length).toBeGreaterThan(0)
}
})
it('hints when markdown sneaks into frontmatter', () => {
// "1. **...**: [unclosed" triggers a YAMLParseError at the markdown line
// (plain-list-with-bold parses as valid YAML without an unclosed flow)
const broken = `---
pbi:
title: Test
priority: 2
stories:
1. **Toggle zichtbaar in productie**: [unclosed
---
body
`
const r = parsePlanMd(broken)
expect(r.ok).toBe(false)
if (!r.ok) {
expect(r.errors[0].hint).toMatch(/markdown/i)
expect(r.errors[0].line).toBeGreaterThan(1)
}
})
it('omits hint for non-markdown yaml errors', () => {
const broken = `---
pbi:
title: Test
priority: [unclosed
stories:
- foo
---
`
const r = parsePlanMd(broken)
expect(r.ok).toBe(false)
if (!r.ok) expect(r.errors[0].hint).toBeUndefined()
})
it('reports schema-validation error when pbi-section missing', () => {
const noPbi = `---
stories:
- title: x
priority: 2
tasks:
- title: y
priority: 2
---
body
`
const r = parsePlanMd(noPbi)
expect(r.ok).toBe(false)
if (!r.ok) {
expect(r.errors.some((e) => e.message.includes('pbi'))).toBe(true)
}
})
it('rejects empty stories array', () => {
const noStories = `---
pbi:
title: x
priority: 2
stories: []
---
body
`
const r = parsePlanMd(noStories)
expect(r.ok).toBe(false)
})
it('handles CRLF line endings', () => {
const crlf = VALID.replace(/\n/g, '\r\n')
const r = parsePlanMd(crlf)
expect(r.ok).toBe(true)
})
})

View file

@ -0,0 +1,148 @@
import { describe, it, expect } from 'vitest'
import {
ideaCreateSchema,
ideaUpdateSchema,
ideaPlanMdFrontmatterSchema,
} from '@/lib/schemas/idea'
describe('ideaCreateSchema', () => {
it('accepts minimal valid input', () => {
const r = ideaCreateSchema.safeParse({ title: 'Plant-watering reminder' })
expect(r.success).toBe(true)
})
it('trims and enforces non-empty title', () => {
const r = ideaCreateSchema.safeParse({ title: ' ' })
expect(r.success).toBe(false)
})
it('rejects oversized title and description', () => {
expect(ideaCreateSchema.safeParse({ title: 'x'.repeat(201) }).success).toBe(false)
expect(
ideaCreateSchema.safeParse({ title: 'ok', description: 'x'.repeat(4001) }).success,
).toBe(false)
})
it('accepts cuid-like product_id', () => {
const r = ideaCreateSchema.safeParse({
title: 'Idee',
product_id: 'cmohrysyj0000rd17clnjy4tc',
})
expect(r.success).toBe(true)
})
it('rejects non-cuid product_id', () => {
const r = ideaCreateSchema.safeParse({ title: 'Idee', product_id: 'not-a-cuid' })
expect(r.success).toBe(false)
})
})
describe('ideaUpdateSchema', () => {
it('allows empty object (no-op update)', () => {
expect(ideaUpdateSchema.safeParse({}).success).toBe(true)
})
it('allows partial title update', () => {
expect(ideaUpdateSchema.safeParse({ title: 'Updated' }).success).toBe(true)
})
})
describe('ideaPlanMdFrontmatterSchema', () => {
const validPlan = {
pbi: { title: 'Test PBI', priority: 2 },
stories: [
{
title: 'Eerste flow',
priority: 2,
tasks: [
{ title: 'Setup', priority: 2, implementation_plan: '1. Doe X' },
],
},
],
}
it('accepts a minimal valid plan', () => {
expect(ideaPlanMdFrontmatterSchema.safeParse(validPlan).success).toBe(true)
})
it('requires at least one story', () => {
const r = ideaPlanMdFrontmatterSchema.safeParse({ ...validPlan, stories: [] })
expect(r.success).toBe(false)
})
it('requires at least one task per story', () => {
const r = ideaPlanMdFrontmatterSchema.safeParse({
...validPlan,
stories: [{ ...validPlan.stories[0], tasks: [] }],
})
expect(r.success).toBe(false)
})
it('validates priority bounds 1-4', () => {
expect(
ideaPlanMdFrontmatterSchema.safeParse({
...validPlan,
pbi: { ...validPlan.pbi, priority: 5 },
}).success,
).toBe(false)
expect(
ideaPlanMdFrontmatterSchema.safeParse({
...validPlan,
pbi: { ...validPlan.pbi, priority: 0 },
}).success,
).toBe(false)
})
it('accepts optional verify_required + verify_only', () => {
const r = ideaPlanMdFrontmatterSchema.safeParse({
...validPlan,
stories: [
{
...validPlan.stories[0],
tasks: [
{
title: 'Verify-only task',
priority: 2,
verify_required: 'ALIGNED_OR_PARTIAL',
verify_only: true,
},
],
},
],
})
expect(r.success).toBe(true)
})
it('rejects invalid verify_required enum', () => {
const r = ideaPlanMdFrontmatterSchema.safeParse({
...validPlan,
stories: [
{
...validPlan.stories[0],
tasks: [
{ title: 't', priority: 2, verify_required: 'INVALID' },
],
},
],
})
expect(r.success).toBe(false)
})
it('accepts plan with task.priority omitted (inherits story-priority via materialize)', () => {
const r = ideaPlanMdFrontmatterSchema.safeParse({
...validPlan,
stories: [
{
title: 'Story zonder task-priorities',
priority: 2,
tasks: [
{ title: 'Taak 1' }, // geen priority — moet geaccepteerd
{ title: 'Taak 2', verify_required: 'ALIGNED' },
],
},
],
})
expect(r.success).toBe(true)
})
})

View file

@ -0,0 +1,108 @@
import { describe, it, expect } from 'vitest'
import {
ideaStatusToApi,
ideaStatusFromApi,
canTransition,
isIdeaEditable,
isGrillMdEditable,
isPlanMdEditable,
IDEA_STATUS_API_VALUES,
} from '@/lib/idea-status'
describe('idea-status mappers', () => {
it('round-trips every API value', () => {
for (const api of IDEA_STATUS_API_VALUES) {
const db = ideaStatusFromApi(api)
expect(db).not.toBeNull()
expect(ideaStatusToApi(db!)).toBe(api)
}
})
it('returns null for invalid input', () => {
expect(ideaStatusFromApi('NOT_A_STATUS')).toBeNull()
})
it('is case-insensitive on the API side', () => {
expect(ideaStatusFromApi('PLAN_READY')).toBe('PLAN_READY')
expect(ideaStatusFromApi('Plan_Ready')).toBe('PLAN_READY')
})
})
describe('canTransition', () => {
it('allows valid forward transitions', () => {
expect(canTransition('DRAFT', 'GRILLING')).toBe(true)
expect(canTransition('GRILLING', 'GRILLED')).toBe(true)
expect(canTransition('GRILLED', 'PLANNING')).toBe(true)
expect(canTransition('PLANNING', 'PLAN_READY')).toBe(true)
expect(canTransition('PLAN_READY', 'PLANNED')).toBe(true)
})
it('allows re-grill from GRILLED and PLAN_READY-ish states', () => {
expect(canTransition('GRILLED', 'GRILLING')).toBe(true)
expect(canTransition('PLAN_FAILED', 'PLANNING')).toBe(true)
expect(canTransition('PLAN_READY', 'GRILLING')).toBe(true)
})
it('allows fail-side transitions', () => {
expect(canTransition('GRILLING', 'GRILL_FAILED')).toBe(true)
expect(canTransition('PLANNING', 'PLAN_FAILED')).toBe(true)
})
it('allows recovery from failed states', () => {
expect(canTransition('GRILL_FAILED', 'GRILLING')).toBe(true)
expect(canTransition('PLAN_FAILED', 'GRILLED')).toBe(true)
})
it('allows PLANNED → PLAN_READY (relink) and PLANNED → GRILLING (re-grill)', () => {
expect(canTransition('PLANNED', 'PLAN_READY')).toBe(true)
expect(canTransition('PLANNED', 'GRILLING')).toBe(true)
expect(canTransition('PLANNED', 'DRAFT')).toBe(false)
})
it('canTransition to GRILLING from all statuses that allow re-grill', () => {
// GRILL_TRIGGERABLE_FROM in actions/ideas.ts — alle statussen die re-grill ondersteunen.
const regrill = ['DRAFT', 'GRILLED', 'GRILL_FAILED', 'PLAN_READY', 'PLANNED'] as const
for (const status of regrill) {
expect(canTransition(status, 'GRILLING')).toBe(true)
}
})
it('rejects invalid jumps', () => {
expect(canTransition('DRAFT', 'PLANNED')).toBe(false)
expect(canTransition('DRAFT', 'PLAN_READY')).toBe(false)
expect(canTransition('GRILLING', 'PLANNED')).toBe(false)
})
})
describe('isIdeaEditable', () => {
it('allows edit in non-running, non-PLANNED states', () => {
expect(isIdeaEditable('DRAFT')).toBe(true)
expect(isIdeaEditable('GRILLED')).toBe(true)
expect(isIdeaEditable('GRILL_FAILED')).toBe(true)
expect(isIdeaEditable('PLAN_FAILED')).toBe(true)
expect(isIdeaEditable('PLAN_READY')).toBe(true)
})
it('blocks edit while a job is running or after PLANNED', () => {
expect(isIdeaEditable('GRILLING')).toBe(false)
expect(isIdeaEditable('PLANNING')).toBe(false)
expect(isIdeaEditable('PLANNED')).toBe(false)
})
})
describe('isGrillMdEditable / isPlanMdEditable', () => {
it('grill_md only editable in GRILLED or PLAN_READY', () => {
expect(isGrillMdEditable('GRILLED')).toBe(true)
expect(isGrillMdEditable('PLAN_READY')).toBe(true)
expect(isGrillMdEditable('DRAFT')).toBe(false)
expect(isGrillMdEditable('PLANNED')).toBe(false)
})
it('plan_md only editable in PLAN_READY', () => {
expect(isPlanMdEditable('PLAN_READY')).toBe(true)
expect(isPlanMdEditable('GRILLED')).toBe(false)
expect(isPlanMdEditable('PLAN_FAILED')).toBe(false)
expect(isPlanMdEditable('PLANNED')).toBe(false)
})
})

View file

@ -0,0 +1,82 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
const { mockQueryRaw } = vi.hoisted(() => ({ mockQueryRaw: vi.fn() }))
vi.mock('@/lib/prisma', () => ({
prisma: { $queryRaw: mockQueryRaw },
}))
import { getJobsPerDay } from '@/lib/insights/agent-throughput'
// Build a date string for N days ago (UTC)
function daysAgo(n: number): Date {
const d = new Date()
d.setUTCDate(d.getUTCDate() - n)
return d
}
function toUTCDate(d: Date): Date {
return new Date(Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate()))
}
beforeEach(() => {
vi.clearAllMocks()
})
describe('getJobsPerDay', () => {
it('returns a 14-day array zero-filled for missing days', async () => {
// Only 3 days have data; the rest should be 0
const day0 = toUTCDate(daysAgo(0))
const day3 = toUTCDate(daysAgo(3))
const day7 = toUTCDate(daysAgo(7))
const dayRows = [
{ day: day0, status: 'done', count: BigInt(2) },
{ day: day3, status: 'failed', count: BigInt(1) },
{ day: day7, status: 'done', count: BigInt(5) },
]
const kpiRows = [
{ today_count: BigInt(2), done_7d: BigInt(7), terminal_7d: BigInt(10), avg_seconds: 120 },
]
mockQueryRaw.mockResolvedValueOnce(dayRows).mockResolvedValueOnce(kpiRows)
const result = await getJobsPerDay('user-1')
expect(result.perDay).toHaveLength(14)
// All days should have zero counts except the three we seeded
const nonZero = result.perDay.filter(
d => d.done + d.failed + d.queued + d.claimed + d.running + d.cancelled + d.skipped > 0,
)
expect(nonZero).toHaveLength(3)
// Today's done count should be 2
const today = result.perDay[result.perDay.length - 1]
expect(today.done).toBe(2)
})
it('calculates KPIs correctly', async () => {
mockQueryRaw.mockResolvedValueOnce([]).mockResolvedValueOnce([
{ today_count: BigInt(3), done_7d: BigInt(7), terminal_7d: BigInt(10), avg_seconds: 90 },
])
const result = await getJobsPerDay('user-1')
expect(result.kpi.todayCount).toBe(3)
expect(result.kpi.successRate7d).toBe(0.7)
expect(result.kpi.avgDurationSeconds7d).toBe(90)
})
it('returns zero successRate and null avgDuration when no terminal jobs', async () => {
mockQueryRaw.mockResolvedValueOnce([]).mockResolvedValueOnce([
{ today_count: BigInt(0), done_7d: BigInt(0), terminal_7d: BigInt(0), avg_seconds: null },
])
const result = await getJobsPerDay('user-1')
expect(result.kpi.successRate7d).toBe(0)
expect(result.kpi.avgDurationSeconds7d).toBeNull()
})
})

View file

@ -0,0 +1,74 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
const { mockQueryRaw } = vi.hoisted(() => ({ mockQueryRaw: vi.fn() }))
vi.mock('@/lib/prisma', () => ({
prisma: { $queryRaw: mockQueryRaw },
}))
import {
getSprintTokenHistory,
getDayTokenData,
getPbiTokenAggregates,
} from '@/lib/insights/token-history'
beforeEach(() => {
vi.clearAllMocks()
})
describe('getSprintTokenHistory', () => {
it('returns mapped sprint rows', async () => {
mockQueryRaw.mockResolvedValueOnce([
{ sprint_id: 'sp-1', sprint_goal: 'Goal A', total_tokens: BigInt(5000), total_cost: 0.1, job_count: BigInt(2) },
])
const rows = await getSprintTokenHistory('user-1')
expect(rows).toHaveLength(1)
expect(rows[0].sprintId).toBe('sp-1')
expect(rows[0].totalTokens).toBe(5000)
expect(rows[0].totalCostUsd).toBe(0.1)
expect(rows[0].jobCount).toBe(2)
})
it('returns zero cost when total_cost is null', async () => {
mockQueryRaw.mockResolvedValueOnce([
{ sprint_id: 'sp-2', sprint_goal: 'Goal B', total_tokens: BigInt(0), total_cost: null, job_count: BigInt(0) },
])
const rows = await getSprintTokenHistory('user-1')
expect(rows[0].totalCostUsd).toBe(0)
})
})
describe('getDayTokenData', () => {
it('returns empty array for empty sprintId', async () => {
const rows = await getDayTokenData('user-1', '')
expect(rows).toHaveLength(0)
expect(mockQueryRaw).not.toHaveBeenCalled()
})
it('maps day rows with ISO date string', async () => {
mockQueryRaw.mockResolvedValueOnce([
{ day: new Date('2026-05-01T00:00:00Z'), total_tokens: BigInt(2000), total_cost: 0.05 },
])
const rows = await getDayTokenData('user-1', 'sprint-1')
expect(rows).toHaveLength(1)
expect(rows[0].day).toBe('2026-05-01')
expect(rows[0].totalTokens).toBe(2000)
})
})
describe('getPbiTokenAggregates', () => {
it('returns empty array for empty sprintId', async () => {
const rows = await getPbiTokenAggregates('user-1', '')
expect(rows).toHaveLength(0)
expect(mockQueryRaw).not.toHaveBeenCalled()
})
it('maps pbi rows', async () => {
mockQueryRaw.mockResolvedValueOnce([
{ pbi_id: 'pbi-1', pbi_code: 'M1', pbi_title: 'First PBI', total_tokens: BigInt(3000), total_cost: 0.08 },
])
const rows = await getPbiTokenAggregates('user-1', 'sprint-1')
expect(rows[0].pbiCode).toBe('M1')
expect(rows[0].totalTokens).toBe(3000)
})
})

View file

@ -0,0 +1,67 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
const { mockQueryRaw } = vi.hoisted(() => ({ mockQueryRaw: vi.fn() }))
vi.mock('@/lib/prisma', () => ({
prisma: { $queryRaw: mockQueryRaw },
}))
import { getTokenStats } from '@/lib/insights/token-stats'
beforeEach(() => {
vi.clearAllMocks()
})
describe('getTokenStats', () => {
it('returns empty result for empty sprintId', async () => {
const result = await getTokenStats('user-1', '')
expect(result.kpi.totalTokens).toBe(0)
expect(result.kpi.totalCostUsd).toBe(0)
expect(result.kpi.avgCostPerJob).toBe(0)
expect(result.kpi.jobCount).toBe(0)
expect(result.jobs).toHaveLength(0)
expect(mockQueryRaw).not.toHaveBeenCalled()
})
it('maps kpi rows correctly', async () => {
const kpiRows = [{ total_tokens: BigInt(10000), total_cost: 0.15, avg_cost: 0.05, job_count: BigInt(3) }]
const jobRows: unknown[] = []
mockQueryRaw.mockResolvedValueOnce(kpiRows).mockResolvedValueOnce(jobRows)
const result = await getTokenStats('user-1', 'sprint-1')
expect(result.kpi.totalTokens).toBe(10000)
expect(result.kpi.totalCostUsd).toBe(0.15)
expect(result.kpi.avgCostPerJob).toBe(0.05)
expect(result.kpi.jobCount).toBe(3)
})
it('maps job rows and handles null token data', async () => {
const kpiRows = [{ total_tokens: BigInt(0), total_cost: null, avg_cost: null, job_count: BigInt(0) }]
const jobRows = [
{
job_id: 'job-1',
task_title: 'My Task',
idea_code: null,
model_id: 'claude-sonnet-4-6',
input_tokens: null,
output_tokens: null,
cache_read_tokens: null,
cache_write_tokens: null,
cost_usd: null,
duration_seconds: 42,
},
]
mockQueryRaw.mockResolvedValueOnce(kpiRows).mockResolvedValueOnce(jobRows)
const result = await getTokenStats('user-1', 'sprint-1')
expect(result.jobs).toHaveLength(1)
const job = result.jobs[0]
expect(job.jobId).toBe('job-1')
expect(job.taskTitle).toBe('My Task')
expect(job.costUsd).toBeNull()
expect(job.durationSeconds).toBe(42)
})
})

View file

@ -0,0 +1,101 @@
import { describe, it, expect } from 'vitest'
import {
getKindDefault,
resolveJobConfig,
mapBudgetToEffort,
} from '@/lib/job-config'
describe('mapBudgetToEffort', () => {
it.each([
[0, null],
[-1, null],
[1, 'medium'],
[3000, 'medium'],
[6000, 'medium'],
[6001, 'high'],
[9000, 'high'],
[12000, 'high'],
[12001, 'xhigh'],
[18000, 'xhigh'],
[24000, 'xhigh'],
[24001, 'max'],
[50000, 'max'],
[100000, 'max'],
])('budget %i → %s', (budget, expected) => {
expect(mapBudgetToEffort(budget)).toBe(expected)
})
})
describe('KIND_DEFAULTS.allowed_tools — sync met scrum4me-mcp', () => {
it('TASK_IMPLEMENTATION bevat geen claim-tools', () => {
const cfg = getKindDefault('TASK_IMPLEMENTATION')
expect(cfg.allowed_tools).not.toContain('mcp__scrum4me__wait_for_job')
expect(cfg.allowed_tools).not.toContain('mcp__scrum4me__check_queue_empty')
expect(cfg.allowed_tools).not.toContain('mcp__scrum4me__get_idea_context')
})
it('TASK_IMPLEMENTATION bevat de essentiële task-tools', () => {
const cfg = getKindDefault('TASK_IMPLEMENTATION')
expect(cfg.allowed_tools).toContain('mcp__scrum4me__update_task_status')
expect(cfg.allowed_tools).toContain('mcp__scrum4me__update_job_status')
expect(cfg.allowed_tools).toContain('mcp__scrum4me__verify_task_against_plan')
expect(cfg.allowed_tools).toContain('Bash')
expect(cfg.allowed_tools).toContain('Edit')
expect(cfg.allowed_tools).toContain('Write')
})
it('SPRINT_IMPLEMENTATION bevat sprint-specifieke tools maar GEEN job_heartbeat (runner doet die)', () => {
const cfg = getKindDefault('SPRINT_IMPLEMENTATION')
expect(cfg.allowed_tools).toContain('mcp__scrum4me__update_task_execution')
expect(cfg.allowed_tools).toContain('mcp__scrum4me__verify_sprint_task')
expect(cfg.allowed_tools).not.toContain('mcp__scrum4me__job_heartbeat')
})
it('IDEA_GRILL bevat update_idea_grill_md en geen wait_for_job', () => {
const cfg = getKindDefault('IDEA_GRILL')
expect(cfg.allowed_tools).toContain('mcp__scrum4me__update_idea_grill_md')
expect(cfg.allowed_tools).toContain('mcp__scrum4me__log_idea_decision')
expect(cfg.allowed_tools).toContain('mcp__scrum4me__update_job_status')
expect(cfg.allowed_tools).not.toContain('mcp__scrum4me__wait_for_job')
})
it('IDEA_MAKE_PLAN bevat update_idea_plan_md en geen wait_for_job', () => {
const cfg = getKindDefault('IDEA_MAKE_PLAN')
expect(cfg.allowed_tools).toContain('mcp__scrum4me__update_idea_plan_md')
expect(cfg.allowed_tools).toContain('mcp__scrum4me__log_idea_decision')
expect(cfg.allowed_tools).not.toContain('mcp__scrum4me__wait_for_job')
})
it('alle kinds hebben non-null allowed_tools', () => {
for (const kind of [
'IDEA_GRILL',
'IDEA_MAKE_PLAN',
'PLAN_CHAT',
'TASK_IMPLEMENTATION',
'SPRINT_IMPLEMENTATION',
]) {
const cfg = getKindDefault(kind)
expect(cfg.allowed_tools).not.toBeNull()
expect(Array.isArray(cfg.allowed_tools)).toBe(true)
}
})
})
describe('resolveJobConfig — cascade (regression)', () => {
it('task.requires_opus overrult product.preferred_model', () => {
const cfg = resolveJobConfig(
{ kind: 'TASK_IMPLEMENTATION' },
{ preferred_model: 'claude-sonnet-4-6' },
{ requires_opus: true },
)
expect(cfg.model).toBe('claude-opus-4-7')
})
it('product.preferred_permission_mode overrult bypassPermissions', () => {
const cfg = resolveJobConfig(
{ kind: 'TASK_IMPLEMENTATION' },
{ preferred_permission_mode: 'acceptEdits' },
)
expect(cfg.permission_mode).toBe('acceptEdits')
})
})

View file

@ -27,13 +27,14 @@ describe('job-status mappers', () => {
expect(jobStatusFromApi('QUEUED')).toBe('QUEUED')
})
it('maps all 6 DB statuses to API', () => {
it('maps all 7 DB statuses to API', () => {
expect(jobStatusToApi('QUEUED')).toBe('queued')
expect(jobStatusToApi('CLAIMED')).toBe('claimed')
expect(jobStatusToApi('RUNNING')).toBe('running')
expect(jobStatusToApi('DONE')).toBe('done')
expect(jobStatusToApi('FAILED')).toBe('failed')
expect(jobStatusToApi('CANCELLED')).toBe('cancelled')
expect(jobStatusToApi('SKIPPED')).toBe('skipped')
})
it('ACTIVE_JOB_STATUSES contains exactly QUEUED, CLAIMED, RUNNING', () => {

View file

@ -0,0 +1,57 @@
import { describe, expect, it } from 'vitest'
import { isWithinTimeWindow } from '@/lib/jobs-time-filter'
const HOUR_MS = 60 * 60 * 1000
describe('isWithinTimeWindow', () => {
it("returns true for filter='all' regardless of age", () => {
const old = new Date(0)
expect(isWithinTimeWindow(old, 'all')).toBe(true)
})
describe("filter='1h'", () => {
const now = Date.now()
it('returns true for a job created 30 minutes ago', () => {
const createdAt = new Date(now - 30 * 60 * 1000)
expect(isWithinTimeWindow(createdAt, '1h', now)).toBe(true)
})
it('returns false for a job created 90 minutes ago', () => {
const createdAt = new Date(now - 90 * 60 * 1000)
expect(isWithinTimeWindow(createdAt, '1h', now)).toBe(false)
})
})
describe("filter='24h'", () => {
const now = Date.now()
it('returns true for a job created 23 hours ago', () => {
const createdAt = new Date(now - 23 * HOUR_MS)
expect(isWithinTimeWindow(createdAt, '24h', now)).toBe(true)
})
it('returns false for a job created 25 hours ago', () => {
const createdAt = new Date(now - 25 * HOUR_MS)
expect(isWithinTimeWindow(createdAt, '24h', now)).toBe(false)
})
})
describe('accepts both Date and ISO string for createdAt', () => {
const now = Date.now()
const recent = new Date(now - 30 * 60 * 1000)
it('accepts a Date object', () => {
expect(isWithinTimeWindow(recent, '1h', now)).toBe(true)
})
it('accepts an ISO string', () => {
expect(isWithinTimeWindow(recent.toISOString(), '1h', now)).toBe(true)
})
})
it('returns true for an invalid date string (fail-open)', () => {
expect(isWithinTimeWindow('not-a-date', '1h')).toBe(true)
})
})

View file

@ -0,0 +1,56 @@
import { describe, it, expect } from 'vitest'
import { resolveProductSwitchTarget } from '@/lib/product-switch-path'
describe('resolveProductSwitchTarget', () => {
it('returns null for non-product pages', () => {
expect(resolveProductSwitchTarget('/dashboard', 'new-id')).toBeNull()
expect(resolveProductSwitchTarget('/insights', 'new-id')).toBeNull()
expect(resolveProductSwitchTarget('/ideas', 'new-id')).toBeNull()
expect(resolveProductSwitchTarget('/jobs', 'new-id')).toBeNull()
expect(resolveProductSwitchTarget('/', 'new-id')).toBeNull()
})
it('maps /products/<old> to /products/<new>', () => {
expect(resolveProductSwitchTarget('/products/old-id', 'new-id')).toBe('/products/new-id')
})
it('maps /products/<old>/ to /products/<new>', () => {
expect(resolveProductSwitchTarget('/products/old-id/', 'new-id')).toBe('/products/new-id')
})
it('maps /products/<old>/sprint to /products/<new>/sprint', () => {
expect(resolveProductSwitchTarget('/products/old-id/sprint', 'new-id')).toBe(
'/products/new-id/sprint',
)
})
it('maps /products/<old>/sprint/<sprintId> to /products/<new>/sprint', () => {
expect(resolveProductSwitchTarget('/products/old-id/sprint/abc123', 'new-id')).toBe(
'/products/new-id/sprint',
)
})
it('maps /products/<old>/sprint/.../planning to /products/<new>/sprint', () => {
expect(resolveProductSwitchTarget('/products/old-id/sprint/abc123/planning', 'new-id')).toBe(
'/products/new-id/sprint',
)
})
it('maps /products/<old>/solo to /products/<new>/solo', () => {
expect(resolveProductSwitchTarget('/products/old-id/solo', 'new-id')).toBe(
'/products/new-id/solo',
)
})
it('falls back to /products/<new> for /products/<old>/settings', () => {
expect(resolveProductSwitchTarget('/products/old-id/settings', 'new-id')).toBe(
'/products/new-id',
)
})
it('falls back to /products/<new> for unknown sub-segments', () => {
expect(resolveProductSwitchTarget('/products/old-id/unknown/deep', 'new-id')).toBe(
'/products/new-id',
)
})
})

View file

@ -0,0 +1,35 @@
import { describe, it, expect, vi } from 'vitest'
vi.mock('@/actions/push', () => ({
subscribeToPushAction: vi.fn(),
unsubscribeFromPushAction: vi.fn(),
}))
import { urlBase64ToUint8Array } from '@/lib/push-client'
describe('urlBase64ToUint8Array', () => {
it('converts a base64url-encoded VAPID public key to Uint8Array', () => {
// 65-byte uncompressed EC public key encoded as base64url (no padding)
const base64url = 'BNMxB-LJm6XvGGiJSsYLdumcYiM7q9s_1aM9i5lI8lVzZ7GYJw1QkQFmrknwFsI4dI-e1iyvUhYHjNpHJKJD3oc'
const result = urlBase64ToUint8Array(base64url)
expect(result).toBeInstanceOf(Uint8Array)
expect(result.length).toBe(65)
expect(result[0]).toBe(0x04) // uncompressed EC point prefix
})
it('handles base64url with padding', () => {
// simple known vector: "hello" = aGVsbG8= in base64
const result = urlBase64ToUint8Array('aGVsbG8')
expect(result).toBeInstanceOf(Uint8Array)
expect(Array.from(result)).toEqual([104, 101, 108, 108, 111]) // "hello"
})
it('converts - and _ characters correctly', () => {
// base64url uses - and _ instead of + and /
const base64standard = 'AB+/AA=='
const base64url = 'AB-_AA'
const fromStd = urlBase64ToUint8Array(base64standard)
const fromUrl = urlBase64ToUint8Array(base64url)
expect(Array.from(fromStd)).toEqual(Array.from(fromUrl))
})
})

View file

@ -0,0 +1,77 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
vi.mock('server-only', () => ({}))
const { mockSendNotification } = vi.hoisted(() => ({
mockSendNotification: vi.fn(),
}))
vi.mock('web-push', () => ({
default: {
setVapidDetails: vi.fn(),
sendNotification: mockSendNotification,
},
}))
vi.hoisted(() => {
process.env.NEXT_PUBLIC_VAPID_PUBLIC_KEY = 'pk'
process.env.VAPID_PRIVATE_KEY = 'sk'
process.env.VAPID_SUBJECT = 'mailto:test@example.com'
})
const { mockPushSubscription } = vi.hoisted(() => ({
mockPushSubscription: {
findMany: vi.fn(),
update: vi.fn(),
delete: vi.fn(),
},
}))
vi.mock('@/lib/prisma', () => ({
prisma: { pushSubscription: mockPushSubscription },
}))
import { sendPushToUser } from '@/lib/push-server'
const SUB = { id: 'sub-1', endpoint: 'https://push.example.com/1', p256dh: 'p256dh', auth: 'auth' }
const PAYLOAD = { title: 'Test', body: 'Body', url: '/test' }
beforeEach(() => {
vi.clearAllMocks()
mockPushSubscription.findMany.mockResolvedValue([SUB])
mockPushSubscription.update.mockResolvedValue(SUB)
mockPushSubscription.delete.mockResolvedValue(SUB)
})
describe('sendPushToUser', () => {
it('sends notification and updates last_used_at on success', async () => {
mockSendNotification.mockResolvedValue({ statusCode: 201 })
await sendPushToUser('user-1', PAYLOAD)
expect(mockSendNotification).toHaveBeenCalledOnce()
expect(mockPushSubscription.update).toHaveBeenCalledWith({
where: { id: SUB.id },
data: { last_used_at: expect.any(Date) },
})
})
it('deletes subscription on 410 (expired)', async () => {
mockSendNotification.mockRejectedValue({ statusCode: 410 })
await sendPushToUser('user-1', PAYLOAD)
expect(mockPushSubscription.delete).toHaveBeenCalledWith({ where: { id: SUB.id } })
expect(mockPushSubscription.update).not.toHaveBeenCalled()
})
it('deletes subscription on 404 (not found)', async () => {
mockSendNotification.mockRejectedValue({ statusCode: 404 })
await sendPushToUser('user-1', PAYLOAD)
expect(mockPushSubscription.delete).toHaveBeenCalledWith({ where: { id: SUB.id } })
})
it('logs error but does not delete on other error status', async () => {
const consoleSpy = vi.spyOn(console, 'error').mockImplementation(() => {})
mockSendNotification.mockRejectedValue({ statusCode: 500 })
await sendPushToUser('user-1', PAYLOAD)
expect(mockPushSubscription.delete).not.toHaveBeenCalled()
expect(consoleSpy).toHaveBeenCalled()
consoleSpy.mockRestore()
})
})

View file

@ -0,0 +1,64 @@
import { describe, it, expect, beforeEach } from 'vitest'
import { checkRateLimit, enforceUserRateLimit, _resetRateLimit } from '@/lib/rate-limit'
beforeEach(() => {
_resetRateLimit()
})
describe('checkRateLimit (legacy auth-keys)', () => {
it('staat de eerste request toe', () => {
expect(checkRateLimit('login:1.2.3.4')).toBe(true)
})
it('blokkeert na exceeding max (login: 10/min)', () => {
for (let i = 0; i < 10; i++) checkRateLimit('login:1.2.3.4')
expect(checkRateLimit('login:1.2.3.4')).toBe(false)
})
it('register heeft eigen lagere limiet (5/uur)', () => {
for (let i = 0; i < 5; i++) checkRateLimit('register:9.9.9.9')
expect(checkRateLimit('register:9.9.9.9')).toBe(false)
})
it('verschillende keys hebben hun eigen counter', () => {
for (let i = 0; i < 10; i++) checkRateLimit('login:1.1.1.1')
expect(checkRateLimit('login:1.1.1.1')).toBe(false)
expect(checkRateLimit('login:2.2.2.2')).toBe(true)
})
})
describe('enforceUserRateLimit (v1-readiness #3 mutation-scopes)', () => {
it('returnt null bij eerste call', () => {
expect(enforceUserRateLimit('create-pbi', 'user-1')).toBeNull()
})
it('returnt 429-shape na exceeding limiet', () => {
// create-product limiet = 5/min
for (let i = 0; i < 5; i++) enforceUserRateLimit('create-product', 'user-1')
const result = enforceUserRateLimit('create-product', 'user-1')
expect(result).not.toBeNull()
expect(result?.code).toBe(429)
expect(result?.error).toContain('Te veel acties')
})
it('scope is per (action, user) — andere user heeft eigen quota', () => {
for (let i = 0; i < 5; i++) enforceUserRateLimit('create-product', 'user-A')
expect(enforceUserRateLimit('create-product', 'user-A')).not.toBeNull()
expect(enforceUserRateLimit('create-product', 'user-B')).toBeNull()
})
it('verschillende scopes voor dezelfde user vullen apart', () => {
for (let i = 0; i < 5; i++) enforceUserRateLimit('create-product', 'user-1')
expect(enforceUserRateLimit('create-product', 'user-1')).not.toBeNull()
// create-task heeft eigen counter
expect(enforceUserRateLimit('create-task', 'user-1')).toBeNull()
})
it('create-task limiet (100) is hoger dan create-pbi (30)', () => {
for (let i = 0; i < 30; i++) enforceUserRateLimit('create-pbi', 'u')
expect(enforceUserRateLimit('create-pbi', 'u')).not.toBeNull()
// create-task is nog niet hit
for (let i = 0; i < 30; i++) enforceUserRateLimit('create-task', 'u')
expect(enforceUserRateLimit('create-task', 'u')).toBeNull()
})
})

View file

@ -0,0 +1,275 @@
import { describe, it, expect, vi } from 'vitest'
import type { StoryStatus } from '@prisma/client'
import {
getBlockingSprintMap,
isEligibleForSprint,
partitionByEligibility,
} from '@/lib/sprint-conflicts'
function mockPrisma(stories: Array<Record<string, unknown>>) {
return {
story: {
findMany: vi.fn().mockResolvedValue(stories),
},
} as unknown as Parameters<typeof partitionByEligibility>[0]
}
describe('isEligibleForSprint', () => {
it('returns true for OPEN story without sprint', () => {
expect(
isEligibleForSprint({ sprint_id: null, status: 'OPEN' as StoryStatus }),
).toBe(true)
})
it('returns true for IN_SPRINT story without sprint_id (edge: restoration)', () => {
expect(
isEligibleForSprint({
sprint_id: null,
status: 'IN_SPRINT' as StoryStatus,
}),
).toBe(true)
})
it('returns false for DONE story without sprint', () => {
expect(
isEligibleForSprint({ sprint_id: null, status: 'DONE' as StoryStatus }),
).toBe(false)
})
it('returns false when story is in an OPEN sprint', () => {
expect(
isEligibleForSprint({
sprint_id: 'abc',
status: 'IN_SPRINT' as StoryStatus,
sprint: { status: 'OPEN' },
}),
).toBe(false)
})
it('returns false when story is DONE (sprint_id irrelevant)', () => {
expect(
isEligibleForSprint({
sprint_id: 'abc',
status: 'DONE' as StoryStatus,
sprint: { status: 'CLOSED' },
}),
).toBe(false)
})
it('returns true when story is in a CLOSED sprint (released back to planning)', () => {
expect(
isEligibleForSprint({
sprint_id: 'abc',
status: 'IN_SPRINT' as StoryStatus,
sprint: { status: 'CLOSED' },
}),
).toBe(true)
})
it('returns true when story is in an ARCHIVED sprint', () => {
expect(
isEligibleForSprint({
sprint_id: 'abc',
status: 'IN_SPRINT' as StoryStatus,
sprint: { status: 'ARCHIVED' },
}),
).toBe(true)
})
it('returns true when story is in a FAILED sprint', () => {
expect(
isEligibleForSprint({
sprint_id: 'abc',
status: 'IN_SPRINT' as StoryStatus,
sprint: { status: 'FAILED' },
}),
).toBe(true)
})
it('returns false when sprint_id is set but sprint relation is missing (defensive)', () => {
// Zonder sprint-data weten we niet of die OPEN is, dus blijven we
// conservatief — niet eligible.
expect(
isEligibleForSprint({
sprint_id: 'abc',
status: 'IN_SPRINT' as StoryStatus,
}),
).toBe(false)
})
})
describe('partitionByEligibility', () => {
it('returns empty partition for empty input', async () => {
const prisma = mockPrisma([])
const result = await partitionByEligibility(prisma, [])
expect(result).toEqual({ eligible: [], notEligible: [], crossSprint: [] })
})
it('classifies all eligible when stories are free + OPEN', async () => {
const prisma = mockPrisma([
{ id: 's1', sprint_id: null, status: 'OPEN', sprint: null },
{ id: 's2', sprint_id: null, status: 'IN_SPRINT', sprint: null },
])
const result = await partitionByEligibility(prisma, ['s1', 's2'])
expect(result.eligible).toEqual(['s1', 's2'])
expect(result.notEligible).toEqual([])
expect(result.crossSprint).toEqual([])
})
it('marks DONE stories as notEligible with reason=DONE', async () => {
const prisma = mockPrisma([
{ id: 's1', sprint_id: null, status: 'DONE', sprint: null },
])
const result = await partitionByEligibility(prisma, ['s1'])
expect(result.eligible).toEqual([])
expect(result.notEligible).toEqual([{ storyId: 's1', reason: 'DONE' }])
})
it('marks stories in other OPEN sprint as crossSprint + notEligible', async () => {
const prisma = mockPrisma([
{
id: 's1',
sprint_id: 'sprint-other',
status: 'IN_SPRINT',
sprint: { id: 'sprint-other', code: 'SP-2', status: 'OPEN' },
},
])
const result = await partitionByEligibility(prisma, ['s1'])
expect(result.crossSprint).toEqual([
{ storyId: 's1', sprintId: 'sprint-other', sprintName: 'SP-2' },
])
expect(result.notEligible).toEqual([
{ storyId: 's1', reason: 'IN_OTHER_SPRINT' },
])
expect(result.eligible).toEqual([])
})
it('classifies story in CLOSED sprint with status=OPEN as eligible (status reset already happened)', async () => {
const prisma = mockPrisma([
{
id: 's1',
sprint_id: null,
status: 'OPEN',
sprint: null,
},
])
const result = await partitionByEligibility(prisma, ['s1'])
expect(result.eligible).toEqual(['s1'])
})
it('frees stories from a CLOSED sprint — they become eligible again', async () => {
const prisma = mockPrisma([
{
id: 's1',
sprint_id: 'sprint-closed',
status: 'IN_SPRINT',
sprint: { id: 'sprint-closed', code: 'SP-C', status: 'CLOSED' },
},
])
const result = await partitionByEligibility(prisma, ['s1'])
expect(result.eligible).toEqual(['s1'])
expect(result.crossSprint).toEqual([])
expect(result.notEligible).toEqual([])
})
it('frees stories from ARCHIVED and FAILED sprints', async () => {
const prisma = mockPrisma([
{
id: 's1',
sprint_id: 'sprint-arch',
status: 'IN_SPRINT',
sprint: { id: 'sprint-arch', code: 'SP-A', status: 'ARCHIVED' },
},
{
id: 's2',
sprint_id: 'sprint-fail',
status: 'IN_SPRINT',
sprint: { id: 'sprint-fail', code: 'SP-F', status: 'FAILED' },
},
])
const result = await partitionByEligibility(prisma, ['s1', 's2'])
expect(result.eligible).toEqual(['s1', 's2'])
expect(result.notEligible).toEqual([])
})
it('a DONE story in a CLOSED sprint is notEligible because DONE (sprint inactive)', async () => {
// Volgorde: niet-actieve sprint blokkeert niet meer, dus de DONE-check
// bepaalt de reason. Vroeger werd dit 'IN_OTHER_SPRINT' — dat was misleidend
// omdat de sprint helemaal niet meer actief was.
const prisma = mockPrisma([
{
id: 's1',
sprint_id: 'sprint-closed',
status: 'DONE',
sprint: { id: 'sprint-closed', code: 'SP-C', status: 'CLOSED' },
},
])
const result = await partitionByEligibility(prisma, ['s1'])
expect(result.crossSprint).toEqual([])
expect(result.notEligible).toEqual([{ storyId: 's1', reason: 'DONE' }])
expect(result.eligible).toEqual([])
})
it('respects excludeSprintId — story in same sprint is eligible', async () => {
const prisma = mockPrisma([
{
id: 's1',
sprint_id: 'sprint-active',
status: 'IN_SPRINT',
sprint: { id: 'sprint-active', code: 'SP-A', status: 'OPEN' },
},
])
const result = await partitionByEligibility(prisma, ['s1'], 'sprint-active')
expect(result.eligible).toEqual(['s1'])
expect(result.crossSprint).toEqual([])
})
})
describe('getBlockingSprintMap', () => {
it('returns empty map for empty input', async () => {
const prisma = mockPrisma([])
const result = await getBlockingSprintMap(prisma, 'p1', [])
expect(result.size).toBe(0)
})
it('returns blocking sprint info for stories in OPEN sprints', async () => {
const prisma = mockPrisma([
{
id: 's1',
sprint_id: 'sprint-x',
sprint: { id: 'sprint-x', code: 'SP-X', status: 'OPEN' },
},
])
const result = await getBlockingSprintMap(prisma, 'p1', ['s1'])
expect(result.get('s1')).toEqual({
sprintId: 'sprint-x',
sprintName: 'SP-X',
})
})
it('excludes the active sprint from blocking', async () => {
const prisma = mockPrisma([
{
id: 's1',
sprint_id: 'sprint-active',
sprint: { id: 'sprint-active', code: 'SP-A', status: 'OPEN' },
},
])
const result = await getBlockingSprintMap(
prisma,
'p1',
['s1'],
'sprint-active',
)
expect(result.size).toBe(0)
})
it('does not include CLOSED sprints (filtered at DB query level)', async () => {
// The prisma mock receives WHERE sprint.status='OPEN' so CLOSED stories
// are already filtered out before reaching this function's mapping logic.
const prisma = mockPrisma([])
const result = await getBlockingSprintMap(prisma, 'p1', ['s1'])
expect(result.size).toBe(0)
})
})

View file

@ -78,8 +78,8 @@ describe('task-status mappers', () => {
expect(pbiStatusFromApi('todo')).toBeNull()
})
it('exposes exactly three API values', () => {
expect(PBI_STATUS_API_VALUES).toEqual(['ready', 'blocked', 'done'])
it('exposes alle vier API values', () => {
expect(PBI_STATUS_API_VALUES).toEqual(['ready', 'blocked', 'failed', 'done'])
})
})
})

View file

@ -8,6 +8,23 @@ vi.mock('@/lib/prisma', () => ({
},
story: {
findUniqueOrThrow: vi.fn(),
findMany: vi.fn(),
update: vi.fn(),
},
pbi: {
findUniqueOrThrow: vi.fn(),
update: vi.fn(),
},
sprint: {
findUniqueOrThrow: vi.fn(),
update: vi.fn(),
},
claudeJob: {
findFirst: vi.fn(),
updateMany: vi.fn(),
},
sprintRun: {
findUnique: vi.fn(),
update: vi.fn(),
},
$transaction: vi.fn(),
@ -15,27 +32,35 @@ vi.mock('@/lib/prisma', () => ({
}))
import { prisma } from '@/lib/prisma'
import { updateTaskStatusWithStoryPromotion } from '@/lib/tasks-status-update'
import { propagateStatusUpwards } from '@/lib/tasks-status-update'
const mockPrisma = prisma as unknown as {
task: {
update: ReturnType<typeof vi.fn>
findMany: ReturnType<typeof vi.fn>
}
type MockedPrisma = {
task: { update: ReturnType<typeof vi.fn>; findMany: ReturnType<typeof vi.fn> }
story: {
findUniqueOrThrow: ReturnType<typeof vi.fn>
findMany: ReturnType<typeof vi.fn>
update: ReturnType<typeof vi.fn>
}
pbi: {
findUniqueOrThrow: ReturnType<typeof vi.fn>
update: ReturnType<typeof vi.fn>
}
sprint: {
findUniqueOrThrow: ReturnType<typeof vi.fn>
update: ReturnType<typeof vi.fn>
}
claudeJob: {
findFirst: ReturnType<typeof vi.fn>
updateMany: ReturnType<typeof vi.fn>
}
sprintRun: {
findUnique: ReturnType<typeof vi.fn>
update: ReturnType<typeof vi.fn>
}
$transaction: ReturnType<typeof vi.fn>
}
beforeEach(() => {
vi.clearAllMocks()
// Pass-through: $transaction(run) just calls run with the mocked prisma client.
mockPrisma.$transaction.mockImplementation(async (run: (tx: typeof prisma) => Promise<unknown>) => {
return run(prisma)
})
})
const mockPrisma = prisma as unknown as MockedPrisma
const TASK_BASE = {
id: 'task-1',
@ -44,110 +69,267 @@ const TASK_BASE = {
implementation_plan: null,
}
describe('updateTaskStatusWithStoryPromotion', () => {
it('promotes story to DONE when last sibling task transitions to DONE', async () => {
beforeEach(() => {
vi.clearAllMocks()
mockPrisma.$transaction.mockImplementation(
async (run: (tx: typeof prisma) => Promise<unknown>) => run(prisma),
)
})
describe('propagateStatusUpwards — story-niveau', () => {
it('zet story op DONE wanneer alle siblings DONE zijn', async () => {
mockPrisma.task.update.mockResolvedValue({ ...TASK_BASE, status: 'DONE' })
mockPrisma.task.findMany.mockResolvedValue([
{ status: 'DONE' },
{ status: 'DONE' },
])
mockPrisma.story.findUniqueOrThrow.mockResolvedValue({ status: 'IN_SPRINT' })
mockPrisma.story.findUniqueOrThrow.mockResolvedValue({
id: 'story-1',
status: 'IN_SPRINT',
pbi_id: 'pbi-1',
sprint_id: null,
})
mockPrisma.pbi.findUniqueOrThrow.mockResolvedValue({ id: 'pbi-1', status: 'READY' })
mockPrisma.story.findMany.mockResolvedValue([{ status: 'DONE' }])
const result = await updateTaskStatusWithStoryPromotion('task-1', 'DONE')
const result = await propagateStatusUpwards('task-1', 'DONE')
expect(result.storyStatusChange).toBe('promoted')
expect(result.storyId).toBe('story-1')
expect(result.storyChanged).toBe(true)
expect(mockPrisma.story.update).toHaveBeenCalledWith({
where: { id: 'story-1' },
data: { status: 'DONE' },
})
})
it('does not promote when story is already DONE (idempotent)', async () => {
mockPrisma.task.update.mockResolvedValue({ ...TASK_BASE, status: 'DONE' })
mockPrisma.task.findMany.mockResolvedValue([{ status: 'DONE' }])
mockPrisma.story.findUniqueOrThrow.mockResolvedValue({ status: 'DONE' })
it('zet story op FAILED wanneer een task FAILED is, ongeacht andere tasks', async () => {
mockPrisma.task.update.mockResolvedValue({ ...TASK_BASE, status: 'FAILED' })
mockPrisma.task.findMany.mockResolvedValue([
{ status: 'FAILED' },
{ status: 'DONE' },
{ status: 'TO_DO' },
])
mockPrisma.story.findUniqueOrThrow.mockResolvedValue({
id: 'story-1',
status: 'IN_SPRINT',
pbi_id: 'pbi-1',
sprint_id: null,
})
mockPrisma.pbi.findUniqueOrThrow.mockResolvedValue({ id: 'pbi-1', status: 'READY' })
mockPrisma.story.findMany.mockResolvedValue([{ status: 'FAILED' }])
const result = await updateTaskStatusWithStoryPromotion('task-1', 'DONE')
const result = await propagateStatusUpwards('task-1', 'FAILED')
expect(result.storyStatusChange).toBe(null)
expect(mockPrisma.story.update).not.toHaveBeenCalled()
expect(result.storyChanged).toBe(true)
expect(mockPrisma.story.update).toHaveBeenCalledWith({
where: { id: 'story-1' },
data: { status: 'FAILED' },
})
})
it('does not promote when not all siblings are DONE', async () => {
it('houdt story op IN_SPRINT als nog niet alle tasks DONE en geen FAILED', async () => {
mockPrisma.task.update.mockResolvedValue({ ...TASK_BASE, status: 'DONE' })
mockPrisma.task.findMany.mockResolvedValue([
{ status: 'DONE' },
{ status: 'IN_PROGRESS' },
{ status: 'TO_DO' },
])
mockPrisma.story.findUniqueOrThrow.mockResolvedValue({ status: 'IN_SPRINT' })
mockPrisma.story.findUniqueOrThrow.mockResolvedValue({
id: 'story-1',
status: 'IN_SPRINT',
pbi_id: 'pbi-1',
sprint_id: 'sprint-1',
})
mockPrisma.pbi.findUniqueOrThrow.mockResolvedValue({ id: 'pbi-1', status: 'READY' })
mockPrisma.story.findMany.mockImplementation(async (args: { where?: { pbi_id?: string; sprint_id?: string } }) => {
if (args.where?.pbi_id) return [{ status: 'IN_SPRINT' }]
if (args.where?.sprint_id) return [{ pbi_id: 'pbi-1' }]
return []
})
mockPrisma.sprint.findUniqueOrThrow.mockResolvedValue({ id: 'sprint-1', status: 'OPEN' })
;(mockPrisma.pbi as unknown as { findMany: ReturnType<typeof vi.fn> }).findMany = vi.fn().mockResolvedValue([{ status: 'READY' }])
const result = await updateTaskStatusWithStoryPromotion('task-1', 'DONE')
const result = await propagateStatusUpwards('task-1', 'DONE')
expect(result.storyStatusChange).toBe(null)
expect(result.storyChanged).toBe(false)
expect(mockPrisma.story.update).not.toHaveBeenCalled()
})
it('demotes story to IN_SPRINT when a task moves out of DONE on a DONE story', async () => {
mockPrisma.task.update.mockResolvedValue({ ...TASK_BASE, status: 'IN_PROGRESS' })
it('demoot story uit DONE als een task terug naar TO_DO gaat', async () => {
mockPrisma.task.update.mockResolvedValue({ ...TASK_BASE, status: 'TO_DO' })
mockPrisma.task.findMany.mockResolvedValue([
{ status: 'IN_PROGRESS' },
{ status: 'TO_DO' },
{ status: 'DONE' },
])
mockPrisma.story.findUniqueOrThrow.mockResolvedValue({ status: 'DONE' })
mockPrisma.story.findUniqueOrThrow.mockResolvedValue({
id: 'story-1',
status: 'DONE',
pbi_id: 'pbi-1',
sprint_id: 'sprint-1',
})
mockPrisma.pbi.findUniqueOrThrow.mockResolvedValue({ id: 'pbi-1', status: 'DONE' })
mockPrisma.story.findMany.mockImplementation(async (args: { where?: { pbi_id?: string; sprint_id?: string } }) => {
if (args.where?.pbi_id) return [{ status: 'IN_SPRINT' }, { status: 'DONE' }]
if (args.where?.sprint_id) return [{ pbi_id: 'pbi-1' }]
return []
})
mockPrisma.sprint.findUniqueOrThrow.mockResolvedValue({ id: 'sprint-1', status: 'CLOSED' })
;(mockPrisma.pbi as unknown as { findMany: ReturnType<typeof vi.fn> }).findMany = vi.fn().mockResolvedValue([{ status: 'READY' }])
const result = await updateTaskStatusWithStoryPromotion('task-1', 'IN_PROGRESS')
const result = await propagateStatusUpwards('task-1', 'TO_DO')
expect(result.storyStatusChange).toBe('demoted')
expect(result.storyChanged).toBe(true)
expect(mockPrisma.story.update).toHaveBeenCalledWith({
where: { id: 'story-1' },
data: { status: 'IN_SPRINT' },
})
})
it('does not demote when story is not DONE', async () => {
it('zet story op OPEN als sprint_id null is en niet DONE/FAILED', async () => {
mockPrisma.task.update.mockResolvedValue({ ...TASK_BASE, status: 'IN_PROGRESS' })
mockPrisma.task.findMany.mockResolvedValue([{ status: 'IN_PROGRESS' }])
mockPrisma.story.findUniqueOrThrow.mockResolvedValue({ status: 'IN_SPRINT' })
const result = await updateTaskStatusWithStoryPromotion('task-1', 'IN_PROGRESS')
expect(result.storyStatusChange).toBe(null)
expect(mockPrisma.story.update).not.toHaveBeenCalled()
})
it('updates the task regardless of story-status change', async () => {
mockPrisma.task.update.mockResolvedValue({ ...TASK_BASE, status: 'IN_PROGRESS' })
mockPrisma.task.findMany.mockResolvedValue([{ status: 'IN_PROGRESS' }])
mockPrisma.story.findUniqueOrThrow.mockResolvedValue({ status: 'IN_SPRINT' })
await updateTaskStatusWithStoryPromotion('task-1', 'IN_PROGRESS')
expect(mockPrisma.task.update).toHaveBeenCalledWith({
where: { id: 'task-1' },
data: { status: 'IN_PROGRESS' },
select: expect.any(Object),
mockPrisma.story.findUniqueOrThrow.mockResolvedValue({
id: 'story-1',
status: 'IN_SPRINT',
pbi_id: 'pbi-1',
sprint_id: null,
})
})
mockPrisma.pbi.findUniqueOrThrow.mockResolvedValue({ id: 'pbi-1', status: 'READY' })
mockPrisma.story.findMany.mockResolvedValue([{ status: 'OPEN' }])
it('uses the provided transaction client when passed', async () => {
const tx = {
task: { update: vi.fn(), findMany: vi.fn() },
story: { findUniqueOrThrow: vi.fn(), update: vi.fn() },
}
tx.task.update.mockResolvedValue({ ...TASK_BASE, status: 'DONE' })
tx.task.findMany.mockResolvedValue([{ status: 'DONE' }])
tx.story.findUniqueOrThrow.mockResolvedValue({ status: 'IN_SPRINT' })
const result = await propagateStatusUpwards('task-1', 'IN_PROGRESS')
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const result = await updateTaskStatusWithStoryPromotion('task-1', 'DONE', tx as any)
expect(result.storyStatusChange).toBe('promoted')
// $transaction should NOT be called when caller already provides a tx.
expect(mockPrisma.$transaction).not.toHaveBeenCalled()
expect(tx.story.update).toHaveBeenCalledWith({
expect(result.storyChanged).toBe(true)
expect(mockPrisma.story.update).toHaveBeenCalledWith({
where: { id: 'story-1' },
data: { status: 'DONE' },
data: { status: 'OPEN' },
})
})
})
describe('propagateStatusUpwards — PBI BLOCKED met rust laten', () => {
it('overschrijft een handmatig BLOCKED PBI niet', async () => {
mockPrisma.task.update.mockResolvedValue({ ...TASK_BASE, status: 'DONE' })
mockPrisma.task.findMany.mockResolvedValue([{ status: 'DONE' }])
mockPrisma.story.findUniqueOrThrow.mockResolvedValue({
id: 'story-1',
status: 'IN_SPRINT',
pbi_id: 'pbi-1',
sprint_id: null,
})
mockPrisma.pbi.findUniqueOrThrow.mockResolvedValue({ id: 'pbi-1', status: 'BLOCKED' })
const result = await propagateStatusUpwards('task-1', 'DONE')
expect(result.pbiChanged).toBe(false)
expect(mockPrisma.pbi.update).not.toHaveBeenCalled()
})
})
describe('propagateStatusUpwards — sprint cascade tot SprintRun', () => {
it('zet bij FAILED de hele keten op FAILED en cancelt sibling-jobs', async () => {
mockPrisma.task.update.mockResolvedValue({ ...TASK_BASE, status: 'FAILED' })
mockPrisma.task.findMany.mockResolvedValue([
{ status: 'FAILED' },
{ status: 'DONE' },
])
mockPrisma.story.findUniqueOrThrow.mockResolvedValue({
id: 'story-1',
status: 'IN_SPRINT',
pbi_id: 'pbi-1',
sprint_id: 'sprint-1',
})
mockPrisma.pbi.findUniqueOrThrow.mockResolvedValue({ id: 'pbi-1', status: 'READY' })
mockPrisma.story.findMany.mockImplementation(async (args: { where?: { pbi_id?: string; sprint_id?: string } }) => {
if (args.where?.pbi_id) return [{ status: 'FAILED' }]
if (args.where?.sprint_id) return [{ pbi_id: 'pbi-1' }]
return []
})
mockPrisma.sprint.findUniqueOrThrow.mockResolvedValue({ id: 'sprint-1', status: 'OPEN' })
// findMany on pbi:
;(mockPrisma.pbi as unknown as { findMany: ReturnType<typeof vi.fn> }).findMany = vi.fn().mockResolvedValue([{ status: 'FAILED' }])
mockPrisma.claudeJob.findFirst.mockResolvedValue({ id: 'job-1', sprint_run_id: 'run-1' })
mockPrisma.sprintRun.findUnique.mockResolvedValue({ id: 'run-1', status: 'RUNNING' })
const result = await propagateStatusUpwards('task-1', 'FAILED')
expect(result.storyChanged).toBe(true)
expect(result.pbiChanged).toBe(true)
expect(result.sprintChanged).toBe(true)
expect(result.sprintRunChanged).toBe(true)
expect(mockPrisma.sprintRun.update).toHaveBeenCalledWith(expect.objectContaining({
where: { id: 'run-1' },
data: expect.objectContaining({ status: 'FAILED', failed_task_id: 'task-1' }),
}))
expect(mockPrisma.claudeJob.updateMany).toHaveBeenCalledWith(expect.objectContaining({
where: expect.objectContaining({
sprint_run_id: 'run-1',
status: { in: ['QUEUED', 'CLAIMED', 'RUNNING'] },
id: { not: 'job-1' },
}),
data: expect.objectContaining({ status: 'CANCELLED' }),
}))
})
it('zet bij alle DONE de SprintRun op DONE en Sprint op COMPLETED', async () => {
mockPrisma.task.update.mockResolvedValue({ ...TASK_BASE, status: 'DONE' })
mockPrisma.task.findMany.mockResolvedValue([{ status: 'DONE' }])
mockPrisma.story.findUniqueOrThrow.mockResolvedValue({
id: 'story-1',
status: 'IN_SPRINT',
pbi_id: 'pbi-1',
sprint_id: 'sprint-1',
})
mockPrisma.pbi.findUniqueOrThrow.mockResolvedValue({ id: 'pbi-1', status: 'READY' })
mockPrisma.story.findMany.mockImplementation(async (args: { where?: { pbi_id?: string; sprint_id?: string } }) => {
if (args.where?.pbi_id) return [{ status: 'DONE' }]
if (args.where?.sprint_id) return [{ pbi_id: 'pbi-1' }]
return []
})
mockPrisma.sprint.findUniqueOrThrow.mockResolvedValue({ id: 'sprint-1', status: 'OPEN' })
;(mockPrisma.pbi as unknown as { findMany: ReturnType<typeof vi.fn> }).findMany = vi.fn().mockResolvedValue([{ status: 'DONE' }])
mockPrisma.claudeJob.findFirst.mockResolvedValue({ id: 'job-1', sprint_run_id: 'run-1' })
mockPrisma.sprintRun.findUnique.mockResolvedValue({ id: 'run-1', status: 'RUNNING' })
const result = await propagateStatusUpwards('task-1', 'DONE')
expect(result.sprintRunChanged).toBe(true)
expect(mockPrisma.sprint.update).toHaveBeenCalledWith(expect.objectContaining({
where: { id: 'sprint-1' },
data: expect.objectContaining({ status: 'CLOSED' }),
}))
expect(mockPrisma.sprintRun.update).toHaveBeenCalledWith(expect.objectContaining({
where: { id: 'run-1' },
data: expect.objectContaining({ status: 'DONE' }),
}))
})
})
describe('propagateStatusUpwards — transactionele aanroep', () => {
it('gebruikt de meegegeven transaction client', async () => {
const tx = {
task: { update: vi.fn(), findMany: vi.fn() },
story: { findUniqueOrThrow: vi.fn(), findMany: vi.fn(), update: vi.fn() },
pbi: { findUniqueOrThrow: vi.fn(), findMany: vi.fn(), update: vi.fn() },
sprint: { findUniqueOrThrow: vi.fn(), update: vi.fn() },
claudeJob: { findFirst: vi.fn(), updateMany: vi.fn() },
sprintRun: { findUnique: vi.fn(), update: vi.fn() },
}
tx.task.update.mockResolvedValue({ ...TASK_BASE, status: 'IN_PROGRESS' })
tx.task.findMany.mockResolvedValue([{ status: 'IN_PROGRESS' }])
tx.story.findUniqueOrThrow.mockResolvedValue({
id: 'story-1',
status: 'OPEN',
pbi_id: 'pbi-1',
sprint_id: null,
})
tx.pbi.findUniqueOrThrow.mockResolvedValue({ id: 'pbi-1', status: 'READY' })
tx.story.findMany.mockResolvedValue([{ status: 'OPEN' }])
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const result = await propagateStatusUpwards('task-1', 'IN_PROGRESS', tx as any)
expect(result.storyChanged).toBe(false)
// $transaction wordt niet aangeroepen wanneer caller al een tx meegeeft.
expect(mockPrisma.$transaction).not.toHaveBeenCalled()
})
})

View file

@ -0,0 +1,37 @@
import { describe, it, expect } from 'vitest'
import { isPhoneUA } from '@/lib/user-agent'
describe('isPhoneUA', () => {
it('iPhone Safari Mobile → true', () => {
const ua = 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.4 Mobile/15E148 Safari/604.1'
expect(isPhoneUA(ua)).toBe(true)
})
it('Android Chrome (phone) → true', () => {
const ua = 'Mozilla/5.0 (Linux; Android 14; Pixel 7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Mobile Safari/537.36'
expect(isPhoneUA(ua)).toBe(true)
})
it('iPad → false (geen Mobi)', () => {
const ua = 'Mozilla/5.0 (iPad; CPU OS 17_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.4 Safari/604.1'
expect(isPhoneUA(ua)).toBe(false)
})
it('Android tablet (Galaxy Tab) → false', () => {
const ua = 'Mozilla/5.0 (Linux; Android 14; SM-X910) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36'
expect(isPhoneUA(ua)).toBe(false)
})
it('Desktop Chrome → false', () => {
const ua = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36'
expect(isPhoneUA(ua)).toBe(false)
})
it('null → false', () => {
expect(isPhoneUA(null)).toBe(false)
})
it('lege string → false', () => {
expect(isPhoneUA('')).toBe(false)
})
})

View file

@ -0,0 +1,147 @@
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
import {
buildMigrationPatch,
clearLegacyStorage,
} from '@/lib/user-settings-migration'
function clearAllCookies() {
for (const part of document.cookie.split(';')) {
const eq = part.indexOf('=')
const name = (eq < 0 ? part : part.slice(0, eq)).trim()
if (name) document.cookie = `${name}=; max-age=0; path=/`
}
}
beforeEach(() => {
localStorage.clear()
clearAllCookies()
})
afterEach(() => {
localStorage.clear()
clearAllCookies()
})
describe('buildMigrationPatch', () => {
it('returns no data when nothing is stored', () => {
const result = buildMigrationPatch()
expect(result.hasData).toBe(false)
expect(result.patch).toEqual({})
expect(result.legacyKeys).toEqual([])
})
it('skips after marker is set to current version', () => {
localStorage.setItem('scrum4me:sprint_pb_filter_status', 'all')
localStorage.setItem('scrum4me:settings_migrated', 'v2')
const result = buildMigrationPatch()
expect(result.hasData).toBe(false)
})
it('still runs when only the v1 marker is set (re-migration)', () => {
localStorage.setItem('scrum4me:sprint_pb_filter_status', 'all')
localStorage.setItem('scrum4me:settings_migrated', 'v1')
const result = buildMigrationPatch()
expect(result.hasData).toBe(true)
})
it('extracts split-pane cookies into layout', () => {
document.cookie = `sp:backlog-p1=${encodeURIComponent(JSON.stringify([25, 35, 40]))}; path=/`
const result = buildMigrationPatch()
expect(result.patch.layout?.splitPanePositions).toEqual({ 'backlog-p1': [25, 35, 40] })
expect(result.legacyCookies).toContain('sp:backlog-p1')
})
it('ignores split-pane cookies that do not sum to 100', () => {
document.cookie = `sp:bad=${encodeURIComponent(JSON.stringify([10, 20]))}; path=/`
const result = buildMigrationPatch()
expect(result.patch.layout).toBeUndefined()
})
it('extracts active-sprint cookies into layout.activeSprints', () => {
document.cookie = `active_sprint_prod-1=sprint-abc; path=/`
document.cookie = `active_sprint_prod-2=sprint-xyz; path=/`
const result = buildMigrationPatch()
expect(result.patch.layout?.activeSprints).toEqual({
'prod-1': 'sprint-abc',
'prod-2': 'sprint-xyz',
})
expect(result.legacyCookies).toContain('active_sprint_prod-1')
})
it('extracts sprint backlog prefs into nested patch', () => {
localStorage.setItem('scrum4me:sprint_pb_filter_status', 'all')
localStorage.setItem('scrum4me:sprint_pb_sort', 'priority')
localStorage.setItem('scrum4me:sprint_pb_sort_dir', 'desc')
localStorage.setItem('scrum4me:sprint_pb_collapsed', JSON.stringify(['pbi-1', 'pbi-2']))
localStorage.setItem('scrum4me:sprint_pb_filter_popover_open', 'true')
const result = buildMigrationPatch()
expect(result.hasData).toBe(true)
expect(result.patch.views?.sprintBacklog).toEqual({
filterStatus: 'all',
sort: 'priority',
sortDir: 'desc',
collapsedPbis: ['pbi-1', 'pbi-2'],
filterPopoverOpen: true,
})
expect(result.legacyKeys).toContain('scrum4me:sprint_pb_filter_status')
expect(result.legacyKeys).toContain('scrum4me:sprint_pb_collapsed')
})
it('extracts pbi-list prefs', () => {
localStorage.setItem('scrum4me:pbi_sort', 'date')
localStorage.setItem('scrum4me:pbi_filter_priority', '2')
const result = buildMigrationPatch()
expect(result.patch.views?.pbiList).toEqual({ sort: 'date', filterPriority: 2 })
})
it('extracts story_sort', () => {
localStorage.setItem('scrum4me:story_sort', 'code')
const result = buildMigrationPatch()
expect(result.patch.views?.storyPanel).toEqual({ sort: 'code' })
})
it('extracts debug-mode', () => {
localStorage.setItem('scrum4me:debug-mode', 'true')
const result = buildMigrationPatch()
expect(result.patch.devTools).toEqual({ debugMode: true })
})
it('extracts jobs-column dynamic prefixes from CSV values', () => {
localStorage.setItem('queue_filter_kind', 'TASK_IMPLEMENTATION,SPRINT_IMPLEMENTATION')
localStorage.setItem('queue_filter_status', 'queued,running')
const result = buildMigrationPatch()
expect(result.patch.views?.jobsColumns?.['queue']).toEqual({
kinds: ['TASK_IMPLEMENTATION', 'SPRINT_IMPLEMENTATION'],
statuses: ['queued', 'running'],
})
})
it('ignores invalid enum values', () => {
localStorage.setItem('scrum4me:sprint_pb_filter_status', 'BOGUS')
const result = buildMigrationPatch()
expect(result.hasData).toBe(false)
})
})
describe('clearLegacyStorage', () => {
it('removes given keys and cookies and sets the v2 marker', () => {
localStorage.setItem('scrum4me:sprint_pb_sort', 'code')
document.cookie = 'sp:x=foo; path=/'
clearLegacyStorage(['scrum4me:sprint_pb_sort'], ['sp:x'])
expect(localStorage.getItem('scrum4me:sprint_pb_sort')).toBeNull()
expect(document.cookie).not.toContain('sp:x=foo')
expect(localStorage.getItem('scrum4me:settings_migrated')).toBe('v2')
})
it('sets marker even with empty lists (no-op migration)', () => {
clearLegacyStorage([], [])
expect(localStorage.getItem('scrum4me:settings_migrated')).toBe('v2')
})
})

View file

@ -0,0 +1,209 @@
import { describe, expect, it } from 'vitest'
import {
DEFAULT_USER_SETTINGS,
UserSettingsSchema,
mergeSettings,
parseUserSettings,
type UserSettings,
} from '@/lib/user-settings'
describe('mergeSettings', () => {
it('returns the patch when previous is empty', () => {
const result = mergeSettings({}, { views: { sprintBacklog: { sort: 'code' } } })
expect(result).toEqual({ views: { sprintBacklog: { sort: 'code' } } })
})
it('preserves existing keys when patch only sets new ones', () => {
const prev: UserSettings = { views: { sprintBacklog: { sort: 'code' } } }
const result = mergeSettings(prev, {
views: { pbiList: { sort: 'date' } },
})
expect(result).toEqual({
views: {
sprintBacklog: { sort: 'code' },
pbiList: { sort: 'date' },
},
})
})
it('merges nested objects without overwriting siblings', () => {
const prev: UserSettings = {
views: { sprintBacklog: { sort: 'code', sortDir: 'asc' } },
}
const result = mergeSettings(prev, {
views: { sprintBacklog: { sort: 'priority' } },
})
expect(result).toEqual({
views: { sprintBacklog: { sort: 'priority', sortDir: 'asc' } },
})
})
it('replaces arrays instead of appending', () => {
const prev: UserSettings = {
views: { sprintBacklog: { collapsedPbis: ['a', 'b'] } },
}
const result = mergeSettings(prev, {
views: { sprintBacklog: { collapsedPbis: ['c'] } },
})
expect(result.views?.sprintBacklog?.collapsedPbis).toEqual(['c'])
})
it('does not mutate the previous object', () => {
const prev: UserSettings = { views: { sprintBacklog: { sort: 'code' } } }
const snapshot = JSON.parse(JSON.stringify(prev))
mergeSettings(prev, { views: { sprintBacklog: { sortDir: 'desc' } } })
expect(prev).toEqual(snapshot)
})
it('skips undefined values in the patch', () => {
const prev: UserSettings = { views: { sprintBacklog: { sort: 'code' } } }
const result = mergeSettings(prev, { views: undefined })
expect(result).toEqual(prev)
})
})
describe('parseUserSettings', () => {
it('returns defaults for null', () => {
expect(parseUserSettings(null)).toEqual(DEFAULT_USER_SETTINGS)
})
it('returns defaults for undefined', () => {
expect(parseUserSettings(undefined)).toEqual(DEFAULT_USER_SETTINGS)
})
it('returns defaults for invalid input', () => {
expect(parseUserSettings({ views: { sprintBacklog: { filterStatus: 'BOGUS' } } }))
.toEqual(DEFAULT_USER_SETTINGS)
})
it('passes valid settings through', () => {
const valid = { views: { sprintBacklog: { sort: 'code' as const } } }
expect(parseUserSettings(valid)).toEqual(valid)
})
})
describe('UserSettingsSchema', () => {
it('rejects unknown top-level keys', () => {
const result = UserSettingsSchema.safeParse({ unknown: 1 })
expect(result.success).toBe(false)
})
it('accepts an empty object', () => {
expect(UserSettingsSchema.safeParse({}).success).toBe(true)
})
it('accepts the full shape', () => {
const result = UserSettingsSchema.safeParse({
views: {
sprintBacklog: {
filterPriority: 1,
filterStatus: 'OPEN',
sort: 'code',
sortDir: 'asc',
collapsedPbis: ['x'],
filterPopoverOpen: true,
},
pbiList: { sort: 'priority', filterPriority: 'all', filterStatus: 'ready', sortDir: 'desc' },
storyPanel: { sort: 'date' },
jobsColumns: { 'queue:active': { kinds: ['TASK_IMPLEMENTATION'], statuses: [] } },
jobs: { timeFilter: '24h' },
ideasList: { filterStatuses: ['draft', 'planned'] },
},
devTools: { debugMode: true },
layout: {
splitPanePositions: { 'backlog-pid': [25, 35, 40] },
activeSprints: { 'product-1': 'sprint-1' },
},
})
expect(result.success).toBe(true)
})
it('accepts views.jobs.timeFilter and returns it via parseUserSettings', () => {
const input = { views: { jobs: { timeFilter: '1h' as const } } }
const result = parseUserSettings(input)
expect(result).toEqual(input)
})
it('rejects an invalid views.jobs.timeFilter value', () => {
const result = UserSettingsSchema.safeParse({ views: { jobs: { timeFilter: 'BOGUS' } } })
expect(result.success).toBe(false)
})
it('accepts layout-only settings', () => {
expect(UserSettingsSchema.safeParse({
layout: { splitPanePositions: { x: [50, 50] }, activeSprints: { p: 's' } },
}).success).toBe(true)
})
it('accepts null values in activeSprints (explicit "no active sprint")', () => {
const result = UserSettingsSchema.safeParse({
layout: { activeSprints: { 'product-1': null, 'product-2': 'sprint-2' } },
})
expect(result.success).toBe(true)
if (result.success) {
expect(result.data.layout?.activeSprints).toEqual({
'product-1': null,
'product-2': 'sprint-2',
})
}
})
it('accepts pendingSprintDraft with per-PBI intent and overrides', () => {
const result = UserSettingsSchema.safeParse({
workflow: {
pendingSprintDraft: {
'product-1': {
goal: 'Sprint goal',
pbiIntent: { pbiA: 'all', pbiB: 'none' },
storyOverrides: {
pbiA: { add: [], remove: ['story-1'] },
pbiB: { add: ['story-2'], remove: [] },
},
},
},
},
})
expect(result.success).toBe(true)
})
it('fills empty defaults for pbiIntent and storyOverrides in draft', () => {
const result = UserSettingsSchema.safeParse({
workflow: { pendingSprintDraft: { 'product-1': { goal: 'g' } } },
})
expect(result.success).toBe(true)
if (result.success) {
const draft = result.data.workflow?.pendingSprintDraft?.['product-1']
expect(draft?.pbiIntent).toEqual({})
expect(draft?.storyOverrides).toEqual({})
}
})
it('rejects pendingSprintDraft with empty goal', () => {
const result = UserSettingsSchema.safeParse({
workflow: { pendingSprintDraft: { 'p': { goal: '' } } },
})
expect(result.success).toBe(false)
})
it('rejects an invalid ideasList.filterStatuses value', () => {
const result = UserSettingsSchema.safeParse({ views: { ideasList: { filterStatuses: ['BOGUS'] } } })
expect(result.success).toBe(false)
})
it('accepts an empty ideasList.filterStatuses array', () => {
const result = UserSettingsSchema.safeParse({ views: { ideasList: { filterStatuses: [] } } })
expect(result.success).toBe(true)
})
it('rejects unknown intent value', () => {
const result = UserSettingsSchema.safeParse({
workflow: {
pendingSprintDraft: {
p: { goal: 'x', pbiIntent: { a: 'partial' } },
},
},
})
expect(result.success).toBe(false)
})
})

View file

@ -30,6 +30,26 @@ beforeEach(() => {
})
describe('proxy demo-guard', () => {
it('demo + POST /api/ideas → 403 (M12)', async () => {
mockUnsealData.mockResolvedValue({ userId: 'demo-user', isDemo: true })
const req = makeRequest('POST', '/api/ideas', true)
const res = await proxy(req)
expect(res?.status).toBe(403)
})
it('demo + PATCH /api/ideas/abc → 403 (M12)', async () => {
mockUnsealData.mockResolvedValue({ userId: 'demo-user', isDemo: true })
const req = makeRequest('PATCH', '/api/ideas/abc', true)
const res = await proxy(req)
expect(res?.status).toBe(403)
})
it('demo + GET /api/ideas → passthrough (M12)', async () => {
const req = makeRequest('GET', '/api/ideas', true)
const res = await proxy(req)
expect(res?.status).not.toBe(403)
})
it('demo + POST /api/todos → 403', async () => {
mockUnsealData.mockResolvedValue({ userId: 'demo-user', isDemo: true })
const req = makeRequest('POST', '/api/todos', true)

View file

@ -0,0 +1,69 @@
// @vitest-environment jsdom
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { renderHook } from '@testing-library/react'
import { useProductWorkspaceStore } from '@/stores/product-workspace/store'
import { useWorkspaceResync } from '@/lib/realtime/use-workspace-resync'
let resyncSpy: ReturnType<typeof vi.fn>
beforeEach(() => {
resyncSpy = vi.fn().mockResolvedValue(undefined)
useProductWorkspaceStore.setState((s) => {
s.resyncActiveScopes = resyncSpy as unknown as typeof s.resyncActiveScopes
})
// visibilitychange handler leest document.visibilityState — default is 'visible'
Object.defineProperty(document, 'visibilityState', {
value: 'visible',
writable: true,
configurable: true,
})
})
afterEach(() => {
vi.restoreAllMocks()
})
describe('useWorkspaceResync', () => {
it('triggert resyncActiveScopes("visible") op visibilitychange hidden→visible', () => {
renderHook(() => useWorkspaceResync())
Object.defineProperty(document, 'visibilityState', {
value: 'visible',
writable: true,
configurable: true,
})
document.dispatchEvent(new Event('visibilitychange'))
expect(resyncSpy).toHaveBeenCalledWith('visible')
})
it('triggert resyncActiveScopes("reconnect") op online-event', () => {
renderHook(() => useWorkspaceResync())
window.dispatchEvent(new Event('online'))
expect(resyncSpy).toHaveBeenCalledWith('reconnect')
})
it('triggert geen resync bij visibilitychange naar hidden', () => {
renderHook(() => useWorkspaceResync())
Object.defineProperty(document, 'visibilityState', {
value: 'hidden',
writable: true,
configurable: true,
})
document.dispatchEvent(new Event('visibilitychange'))
expect(resyncSpy).not.toHaveBeenCalled()
})
it('cleanup verwijdert listeners bij unmount', () => {
const { unmount } = renderHook(() => useWorkspaceResync())
unmount()
window.dispatchEvent(new Event('online'))
document.dispatchEvent(new Event('visibilitychange'))
expect(resyncSpy).not.toHaveBeenCalled()
})
})

View file

@ -0,0 +1,212 @@
import { describe, it, expect } from 'vitest'
/**
* Review-Plan Job Tests
*
* Tests for the IDEA_REVIEW_PLAN job kind and review-log schema validation.
*/
// Sample review-log structure for testing
const sampleReviewLog = {
plan_file: 'I-042',
created_at: new Date().toISOString(),
rounds: [
{
round: 0,
model: 'claude-3-5-haiku',
role: 'Structure Review',
focus: 'YAML parsing, format, syntax',
plan_before: '---\npbi:\n title: "Test PBI"\nstories:\n - title: "Story 1"\n---',
plan_after:
'---\npbi:\n title: "Test PBI"\nstories:\n - title: "Story 1"\n priority: 2\n---',
issues: [
{
category: 'structure',
severity: 'warning',
suggestion: 'Add priority field to story',
},
],
score: 75,
plan_diff_lines: 1,
converged: false,
timestamp: new Date().toISOString(),
},
{
round: 1,
model: 'claude-3-5-sonnet',
role: 'Logic & Patterns',
focus: 'Logic gaps, missing patterns, architecture fit',
plan_before: '---\npbi:\n title: "Test PBI"\nstories:\n - title: "Story 1"\n---',
plan_after: '---\npbi:\n title: "Test PBI"\nstories:\n - title: "Story 1"\n---',
issues: [
{
category: 'logic',
severity: 'info',
suggestion: 'Consider adding acceptance criteria',
},
],
score: 80,
plan_diff_lines: 0,
converged: false,
timestamp: new Date().toISOString(),
},
{
round: 2,
model: 'claude-opus-4-7',
role: 'Risk Assessment',
focus: 'Risk assessment, edge cases, refactoring',
plan_before: '---\npbi:\n title: "Test PBI"\nstories:\n - title: "Story 1"\n---',
plan_after: '---\npbi:\n title: "Test PBI"\nstories:\n - title: "Story 1"\n---',
issues: [],
score: 85,
plan_diff_lines: 0,
converged: true,
timestamp: new Date().toISOString(),
},
],
convergence: {
stable_at_round: 2,
final_diff_pct: 0.5,
convergence_metric: 'plan_stability',
},
approval: {
status: 'approved',
timestamp: new Date().toISOString(),
},
summary: 'Plan reviewed across three rounds. Minor structure improvements suggested. Plan approved.',
}
describe('review-plan-job', () => {
describe('ReviewLog Schema', () => {
it('should have required top-level fields', () => {
expect(sampleReviewLog).toHaveProperty('plan_file')
expect(sampleReviewLog).toHaveProperty('created_at')
expect(sampleReviewLog).toHaveProperty('rounds')
expect(sampleReviewLog).toHaveProperty('convergence')
expect(sampleReviewLog).toHaveProperty('approval')
expect(sampleReviewLog).toHaveProperty('summary')
})
it('should have valid plan_file format', () => {
expect(typeof sampleReviewLog.plan_file).toBe('string')
expect(sampleReviewLog.plan_file.length).toBeGreaterThan(0)
})
it('should have valid ISO timestamps', () => {
const isoRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/
expect(sampleReviewLog.created_at).toMatch(isoRegex)
expect(sampleReviewLog.approval.timestamp).toMatch(isoRegex)
})
it('should have at least one round', () => {
expect(sampleReviewLog.rounds.length).toBeGreaterThan(0)
})
it('should have valid round structure', () => {
for (const round of sampleReviewLog.rounds) {
expect(round).toHaveProperty('round')
expect(round).toHaveProperty('model')
expect(round).toHaveProperty('role')
expect(round).toHaveProperty('focus')
expect(round).toHaveProperty('plan_before')
expect(round).toHaveProperty('plan_after')
expect(round).toHaveProperty('issues')
expect(round).toHaveProperty('score')
expect(round).toHaveProperty('plan_diff_lines')
expect(round).toHaveProperty('converged')
expect(round).toHaveProperty('timestamp')
expect(typeof round.round).toBe('number')
expect(round.round).toBeGreaterThanOrEqual(0)
expect(typeof round.score).toBe('number')
expect(round.score).toBeGreaterThanOrEqual(0)
expect(round.score).toBeLessThanOrEqual(100)
expect(typeof round.plan_diff_lines).toBe('number')
expect(round.plan_diff_lines).toBeGreaterThanOrEqual(0)
}
})
it('should have valid issue structure per round', () => {
for (const round of sampleReviewLog.rounds) {
for (const issue of round.issues) {
expect(issue).toHaveProperty('category')
expect(issue).toHaveProperty('severity')
expect(issue).toHaveProperty('suggestion')
expect(['structure', 'logic', 'risk', 'pattern']).toContain(issue.category)
expect(['error', 'warning', 'info']).toContain(issue.severity)
expect(typeof issue.suggestion).toBe('string')
expect(issue.suggestion.length).toBeGreaterThan(0)
}
}
})
it('should have valid convergence structure when present', () => {
if (sampleReviewLog.convergence) {
expect(sampleReviewLog.convergence).toHaveProperty('stable_at_round')
expect(sampleReviewLog.convergence).toHaveProperty('final_diff_pct')
expect(sampleReviewLog.convergence).toHaveProperty('convergence_metric')
expect(typeof sampleReviewLog.convergence.stable_at_round).toBe('number')
expect(sampleReviewLog.convergence.stable_at_round).toBeGreaterThanOrEqual(0)
expect(typeof sampleReviewLog.convergence.final_diff_pct).toBe('number')
expect(sampleReviewLog.convergence.final_diff_pct).toBeGreaterThanOrEqual(0)
expect(sampleReviewLog.convergence.final_diff_pct).toBeLessThanOrEqual(100)
}
})
it('should have valid approval status', () => {
expect(['pending', 'approved', 'rejected']).toContain(sampleReviewLog.approval.status)
if (sampleReviewLog.approval.status !== 'pending') {
expect(sampleReviewLog.approval.timestamp).toBeDefined()
}
})
it('should have non-empty summary', () => {
expect(typeof sampleReviewLog.summary).toBe('string')
expect(sampleReviewLog.summary.length).toBeGreaterThan(0)
})
})
describe('Convergence Detection', () => {
it('should detect convergence when diff_pct < 5% for two consecutive rounds', () => {
// Simulate convergence: round 0 has 1 diff line, rounds 1-2 have 0 diffs
const totalLines = 50
const diff0 = 1
const diff1 = 0
const diff2 = 0
const pct0 = (diff0 / totalLines) * 100 // 2%
const pct1 = (diff1 / totalLines) * 100 // 0%
const pct2 = (diff2 / totalLines) * 100 // 0%
expect(pct0).toBeLessThan(5) // Should converge
expect(pct1).toBeLessThan(5) // Should converge
expect(pct2).toBeLessThan(5) // Should converge
})
it('should not detect convergence when diff_pct >= 5%', () => {
const totalLines = 50
const diff = 3 // 6% change
const pct = (diff / totalLines) * 100
expect(pct).toBeGreaterThanOrEqual(5)
})
})
describe('Status Transitions', () => {
it('should transition REVIEWING_PLAN → PLAN_REVIEWED when approved', () => {
const log = { ...sampleReviewLog, approval: { status: 'approved', timestamp: new Date().toISOString() } }
expect(log.approval.status).toBe('approved')
// In actual implementation: update_idea_plan_reviewed({ approval_status: 'approved' })
// → idea.status = 'PLAN_REVIEWED'
})
it('should transition REVIEWING_PLAN → PLAN_REVIEW_FAILED when rejected', () => {
const log = { ...sampleReviewLog, approval: { status: 'rejected' } }
expect(log.approval.status).toBe('rejected')
// In actual implementation: update_idea_plan_reviewed({ approval_status: 'rejected' })
// → idea.status = 'PLAN_REVIEW_FAILED'
})
})
})

View file

@ -0,0 +1,145 @@
import { describe, it, expect, beforeEach } from 'vitest'
import { useIdeaStore } from '@/stores/idea-store'
beforeEach(() => {
// Reset store between tests — Zustand persists state across tests otherwise.
useIdeaStore.setState({
jobByIdea: {},
ideaStatuses: {},
openQuestionsByIdea: {},
})
})
describe('useIdeaStore — handleIdeaJobEvent', () => {
it('queued IDEA_GRILL → ideaStatuses[id] = grilling', () => {
useIdeaStore.getState().handleIdeaJobEvent({
type: 'claude_job_enqueued',
job_id: 'job-1',
idea_id: 'idea-1',
user_id: 'u-1',
kind: 'IDEA_GRILL',
status: 'queued',
})
const s = useIdeaStore.getState()
expect(s.jobByIdea['idea-1']?.status).toBe('queued')
expect(s.ideaStatuses['idea-1']).toBe('grilling')
})
it('failed IDEA_GRILL → ideaStatuses[id] = grill_failed', () => {
useIdeaStore.getState().handleIdeaJobEvent({
type: 'claude_job_status',
job_id: 'job-1',
idea_id: 'idea-1',
user_id: 'u-1',
kind: 'IDEA_GRILL',
status: 'failed',
error: 'oops',
})
expect(useIdeaStore.getState().ideaStatuses['idea-1']).toBe('grill_failed')
expect(useIdeaStore.getState().jobByIdea['idea-1']?.error).toBe('oops')
})
it('failed IDEA_MAKE_PLAN → plan_failed', () => {
useIdeaStore.getState().handleIdeaJobEvent({
type: 'claude_job_status',
job_id: 'job-2',
idea_id: 'idea-2',
user_id: 'u-1',
kind: 'IDEA_MAKE_PLAN',
status: 'failed',
})
expect(useIdeaStore.getState().ideaStatuses['idea-2']).toBe('plan_failed')
})
it('done does NOT auto-derive status (server is source-of-truth)', () => {
useIdeaStore.getState().setIdeaStatus('idea-3', 'grilled')
useIdeaStore.getState().handleIdeaJobEvent({
type: 'claude_job_status',
job_id: 'job-3',
idea_id: 'idea-3',
user_id: 'u-1',
kind: 'IDEA_GRILL',
status: 'done',
})
expect(useIdeaStore.getState().ideaStatuses['idea-3']).toBe('grilled')
})
})
describe('useIdeaStore — handleIdeaQuestionEvent', () => {
it('non-open status removes question from list', () => {
useIdeaStore.getState().initQuestions('idea-1', [
{
id: 'q-1',
idea_id: 'idea-1',
question: 'Q',
options: null,
status: 'open',
created_at: '',
expires_at: '',
},
])
useIdeaStore.getState().handleIdeaQuestionEvent({
op: 'U',
entity: 'question',
id: 'q-1',
product_id: 'p-1',
story_id: null,
idea_id: 'idea-1',
status: 'answered',
})
expect(useIdeaStore.getState().openQuestionsByIdea['idea-1']).toEqual([])
})
it('open status keeps existing list (no detail in payload)', () => {
const q = {
id: 'q-1',
idea_id: 'idea-1',
question: 'Q',
options: null,
status: 'open' as const,
created_at: '',
expires_at: '',
}
useIdeaStore.getState().initQuestions('idea-1', [q])
useIdeaStore.getState().handleIdeaQuestionEvent({
op: 'I',
entity: 'question',
id: 'q-2',
product_id: 'p-1',
story_id: null,
idea_id: 'idea-1',
status: 'open',
})
// List length blijft 1 (server-fetch leveert de detail)
expect(useIdeaStore.getState().openQuestionsByIdea['idea-1']).toHaveLength(1)
})
})
describe('useIdeaStore — clearForIdea', () => {
it('removes job + status + questions for one idea, leaves others', () => {
const s = useIdeaStore.getState()
s.setJobStatus({
job_id: 'j-1',
idea_id: 'idea-1',
kind: 'IDEA_GRILL',
status: 'running',
})
s.setJobStatus({
job_id: 'j-2',
idea_id: 'idea-2',
kind: 'IDEA_GRILL',
status: 'running',
})
s.setIdeaStatus('idea-1', 'grilling')
s.setIdeaStatus('idea-2', 'grilling')
s.clearForIdea('idea-1')
const after = useIdeaStore.getState()
expect(after.jobByIdea['idea-1']).toBeUndefined()
expect(after.jobByIdea['idea-2']).toBeDefined()
expect(after.ideaStatuses['idea-1']).toBeUndefined()
expect(after.ideaStatuses['idea-2']).toBe('grilling')
})
})

View file

@ -0,0 +1,117 @@
import { describe, expect, it } from 'vitest'
import {
clearHints,
readHints,
writePbiHint,
writeProductHint,
writeStoryHint,
writeTaskHint,
} from '@/stores/product-workspace/restore'
describe('readHints', () => {
it('retourneert lege defaults wanneer localStorage leeg is', () => {
const hints = readHints()
expect(hints.lastActiveProductId).toBeNull()
expect(hints.perProduct).toEqual({})
})
it('herstelt hints uit localStorage', () => {
localStorage.setItem(
'product-workspace-hints',
JSON.stringify({
lastActiveProductId: 'p1',
perProduct: { p1: { lastActivePbiId: 'pbi-1' } },
}),
)
const hints = readHints()
expect(hints.lastActiveProductId).toBe('p1')
expect(hints.perProduct.p1.lastActivePbiId).toBe('pbi-1')
})
it('valt terug op defaults bij ongeldige JSON', () => {
localStorage.setItem('product-workspace-hints', '{not-json')
const hints = readHints()
expect(hints.lastActiveProductId).toBeNull()
expect(hints.perProduct).toEqual({})
})
it('valt terug op defaults bij verkeerde shape', () => {
localStorage.setItem('product-workspace-hints', '"just a string"')
const hints = readHints()
expect(hints.perProduct).toEqual({})
})
})
describe('writeProductHint', () => {
it('schrijft lastActiveProductId', () => {
writeProductHint('p1')
expect(readHints().lastActiveProductId).toBe('p1')
})
it('overschrijft bestaande waarde', () => {
writeProductHint('p1')
writeProductHint('p2')
expect(readHints().lastActiveProductId).toBe('p2')
})
it('accepteert null om hint te wissen', () => {
writeProductHint('p1')
writeProductHint(null)
expect(readHints().lastActiveProductId).toBeNull()
})
})
describe('writePbiHint', () => {
it('schrijft lastActivePbiId per productId', () => {
writePbiHint('prod-1', 'pbi-a')
writePbiHint('prod-2', 'pbi-b')
const hints = readHints()
expect(hints.perProduct['prod-1'].lastActivePbiId).toBe('pbi-a')
expect(hints.perProduct['prod-2'].lastActivePbiId).toBe('pbi-b')
})
it('null wist child story- en task-hints', () => {
writePbiHint('prod-1', 'pbi-1')
writeStoryHint('prod-1', 's-1')
writeTaskHint('prod-1', 't-1')
writePbiHint('prod-1', null)
const hints = readHints()
expect(hints.perProduct['prod-1'].lastActivePbiId).toBeNull()
expect(hints.perProduct['prod-1'].lastActiveStoryId).toBeNull()
expect(hints.perProduct['prod-1'].lastActiveTaskId).toBeNull()
})
})
describe('writeStoryHint', () => {
it('schrijft lastActiveStoryId per productId', () => {
writeStoryHint('prod-1', 's-1')
expect(readHints().perProduct['prod-1'].lastActiveStoryId).toBe('s-1')
})
it('null wist child task-hint', () => {
writeStoryHint('prod-1', 's-1')
writeTaskHint('prod-1', 't-1')
writeStoryHint('prod-1', null)
expect(readHints().perProduct['prod-1'].lastActiveStoryId).toBeNull()
expect(readHints().perProduct['prod-1'].lastActiveTaskId).toBeNull()
})
})
describe('writeTaskHint', () => {
it('schrijft lastActiveTaskId per productId', () => {
writeTaskHint('prod-1', 't-1')
expect(readHints().perProduct['prod-1'].lastActiveTaskId).toBe('t-1')
})
})
describe('clearHints', () => {
it('verwijdert alle hints', () => {
writeProductHint('p1')
writePbiHint('p1', 'pbi-1')
clearHints()
const hints = readHints()
expect(hints.lastActiveProductId).toBeNull()
expect(hints.perProduct).toEqual({})
})
})

Some files were not shown because too many files have changed in this diff Show more