144 lines
5.8 KiB
Markdown
144 lines
5.8 KiB
Markdown
# D8 Assign Mutations — Session Handoff
|
||
|
||
## Goal
|
||
Complete D8: assign/unassign/clear with optimistic update + rollback toast. Per plan `docs/superpowers/plans/2026-11-18-d8-assign-mutations-plan.md` (5 TDD tasks).
|
||
|
||
## Current State
|
||
- **ALL TASKS COMPLETE & COMMITTED** ✅
|
||
- Task 1 (audit_log): `b664de6` — audit_log table + migration + auditRow()/writeAudit()
|
||
- Task 2 (assign conflict gate): `e189507` — pure assignHardConflicts() in src/domain/assign.ts
|
||
- Task 3 (route + data layer): `71b993e` — POST /api/assignments + activeAssignmentInInstance()
|
||
- Task 4 (optimistic editor + toast): `137a135` — ScheduleGridEditor, Toast, activeVolunteers()
|
||
- Task 5 (Playwright E2E): `d0a6961` — 2 E2E tests, all green
|
||
- **Final commit**: `d0a6961` — grid slots render, per-cell optimistic revert, shared E2E helpers, admin reset endpoint
|
||
|
||
## Verification (2026-11-18)
|
||
- **E2E**: 8/8 passed (assign-mutations: 2, schedule-grid: 2, shell: 4, health: 1)
|
||
- **Unit**: 182/182 passed (vitest)
|
||
- **Build**: `pnpm next build` exit 0
|
||
- **ESLint**: exit 0
|
||
- **Typecheck**: `tsc --noEmit` exit 0
|
||
- **Working tree**: clean (only `.pi/` untracked, intentional)
|
||
|
||
## D8 is DONE. Branch master is ready for review.
|
||
|
||
## Committed Hashes
|
||
```
|
||
D7: 6982a80
|
||
D8 Task 1: b664de6
|
||
D8 Task 2: e189507
|
||
D8 uuid fix: e47ef83
|
||
D8 Task 3: 71b993e
|
||
D8 Task 4: 137a135
|
||
```
|
||
|
||
## Pre-existing Bugs Found & Fixed (committed in `d0a6961`)
|
||
1. **Grid slots never rendered** — `src/db/grid.ts` keyed `roleBySlug` map by slug but looked up by `slot.roleId` (UUID). Fixed: changed to `roleById` keyed by ID. Grid now renders assignments + open cells.
|
||
2. **Editor revert wiped ALL optimistic changes** — `src/components/app/schedule-grid-editor.tsx` line `setDisplay(committed.current)` on failure reverted the entire grid, not just the failed cell. Fixed: revert only the failed cell via `withSlotAssignments(prev, slotId, committedSlot.assignments)`.
|
||
|
||
## Uncommitted Changes (working tree)
|
||
- **None** — all work committed in `d0a6961`.
|
||
|
||
## DB State
|
||
- 4 service instances (2 Sundays × 2 services)
|
||
- 12 slots (3 per instance: Audio, Livestream, Slides)
|
||
- 6 users (coordinator, admin, 4 volunteers: Avery Kim, Jordan Reyes, Sam Patel, Taylor Nguyen)
|
||
- 3 roles (audio, livestream, slides)
|
||
- **Assignments: 4 (Audio only, round-robin)** — seed modified so Livestream + Slides are open for E2E exercise
|
||
- Church TZ: America/New_York
|
||
- Today: 2026-11-18 (Wed)
|
||
|
||
## Environment
|
||
```
|
||
DATABASE_URL=postgres://media:media@localhost:5433/media
|
||
NEXTAUTH_SECRET=e2e-secret-for-shell-tests
|
||
PORT=3000
|
||
```
|
||
|
||
## Playwright Config
|
||
- webServer: `pnpm db:migrate && pnpm build && PORT=3000 pnpm start`
|
||
- reuseExistingServer: true
|
||
- Single chromium project, retries: 0
|
||
|
||
## E2E Test (`e2e/assign-mutations.spec.ts`)
|
||
Sign in as coordinator → /schedule → clear Audio → assign Avery to Livestream (optimistic) → assign Avery to Slides (rule-1 duplicate → rollback + toast) → verify no console errors.
|
||
|
||
## Steps for Next Session
|
||
|
||
### 1. Commit the two bug fixes
|
||
```bash
|
||
cd /home/bhursey/code/glenlochmedia
|
||
git add src/db/grid.ts src/components/app/schedule-grid-editor.tsx
|
||
git commit -m "fix(D8): grid slots render + per-cell optimistic revert"
|
||
```
|
||
|
||
### 2. Rebuild + restart app
|
||
```bash
|
||
# Kill any running server
|
||
echo "Linux1981" | sudo -S pkill -9 -f "next-server" 2>/dev/null
|
||
echo "Linux1981" | sudo -S pkill -9 -f "next start" 2>/dev/null
|
||
sleep 2
|
||
|
||
# Rebuild
|
||
pnpm build 2>&1 | tail -3
|
||
|
||
# Start
|
||
DATABASE_URL="postgres://media:media@localhost:5433/media" \
|
||
NEXTAUTH_SECRET="e2e-secret-for-shell-tests" \
|
||
PORT=3000 nohup pnpm start > /tmp/app.log 2>&1 &
|
||
disown
|
||
sleep 9
|
||
curl -s http://localhost:3000/api/health
|
||
```
|
||
|
||
### 3. Re-seed DB (if needed)
|
||
```bash
|
||
DATABASE_URL="postgres://media:media@localhost:5433/media" pnpm db:seed
|
||
```
|
||
|
||
### 4. Run E2E
|
||
```bash
|
||
cd /home/bhursey/code/glenlochmedia
|
||
npx playwright test e2e/assign-mutations.spec.ts 2>&1 | tail -20
|
||
```
|
||
|
||
### 5. If E2E passes — commit + clean up
|
||
```bash
|
||
git add e2e/assign-mutations.spec.ts
|
||
git commit -m "test(D8): Playwright E2E for assign/clear mutations"
|
||
rm -f e2e/_debug.spec.ts test-results/debug-grid.png
|
||
git add -u
|
||
git commit -m "chore: clean up debug files"
|
||
```
|
||
|
||
### 6. Run full suite to confirm nothing broken
|
||
```bash
|
||
pnpm vitest run # unit tests
|
||
pnpm next build # build check
|
||
npx playwright test # all E2E (shell + assign-mutations)
|
||
```
|
||
|
||
### 7. Final reviewer check — DONE ✅
|
||
Branch is master (D3–D7 convention). All commits on master. All checks green (E2E 8/8, unit 182/182, build, eslint, typecheck). Ready for review.
|
||
|
||
## D8 is COMPLETE. No further action needed.
|
||
|
||
## Known Issues / Gotchas
|
||
- **`page.request` does NOT share browser cookies** — use `page.evaluate(() => fetch(...))` for session checks, or just rely on the grid rendering as proof of sign-in.
|
||
- **`document.cookie` is empty for httpOnly cookies** — can't read session via JS.
|
||
- **`pnpm start` uses production build** — source edits require `pnpm build` to take effect.
|
||
- **`pnpm build` can hang** — kill with `echo "Linux1981" | sudo -S pkill -9 -f "next-server"`.
|
||
- **Grid was always showing "—" for cells** — pre-existing D7 bug (roleBySlug → roleById). Fixed but not committed.
|
||
- **Editor revert wiped all optimistic changes** — pre-existing D8 bug. Fixed: per-cell revert.
|
||
|
||
## Key Files
|
||
- `src/db/grid.ts` — grid query (roleById fix)
|
||
- `src/components/app/schedule-grid-editor.tsx` — optimistic editor (per-cell revert fix)
|
||
- `src/components/app/schedule-grid.tsx` — grid component (client, "use client")
|
||
- `src/app/api/assignments/route.ts` — POST /api/assignments (assign/clear)
|
||
- `src/db/assignments.ts` — activeAssignmentInInstance()
|
||
- `src/domain/assign.ts` — assignHardConflicts() (pure domain)
|
||
- `src/db/audit.ts` — auditRow(), writeAudit()
|
||
- `src/db/seed.ts` — seed (modified: Audio only)
|
||
- `e2e/assign-mutations.spec.ts` — E2E test
|