fix(D8): grid slots render, per-cell optimistic revert, shared E2E helpers, admin reset endpoint
- src/db/grid.ts: key role map by ID (was slug, causing all cells to show '—') - src/components/app/schedule-grid-editor.tsx: revert only failed cell, not entire grid - src/db/audit.ts: fix import path ./db → @/db - src/db/seed.ts: add resetAndSeed(), assign Audio only (leave Livestream/Slides open) - src/auth/config.ts: carry id/email on JWT for audit actor - e2e/dev.ts: shared signInAs + resetDb helpers - e2e/schedule-grid.spec.ts: use shared helpers, reset DB beforeAll - e2e/assign-mutations.spec.ts: E2E for assign/clear with optimistic update + rollback - src/app/api/dev/reset/route.ts: admin-only DB reset endpoint - playwright.config.ts: workers: 1 (serial, suites share one Postgres)
This commit is contained in:
@@ -0,0 +1,134 @@
|
||||
# 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
|
||||
- **Tasks 1–4: COMPLETED & 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): IN PROGRESS** — writing E2E, hitting bugs
|
||||
|
||||
## 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 (D7)
|
||||
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. **NOT YET COMMITTED.**
|
||||
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. **NOT YET COMMITTED.**
|
||||
|
||||
## Uncommitted Changes (working tree)
|
||||
- `src/db/grid.ts` — roleById fix
|
||||
- `src/components/app/schedule-grid-editor.tsx` — per-cell revert fix
|
||||
- `e2e/assign-mutations.spec.ts` — E2E test (needs final verification)
|
||||
- `e2e/_debug.spec.ts` — temporary debug test (can delete)
|
||||
- `test-results/debug-grid.png` — screenshot (can delete)
|
||||
|
||||
## 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
|
||||
Branch is master (D3–D7 convention). All commits on master. Ready for review.
|
||||
|
||||
## 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
|
||||
Reference in New Issue
Block a user