4.6 KiB
4.6 KiB
id, title, status, wave, depends_on, plan, spec
| id | title | status | wave | depends_on | plan | spec | |
|---|---|---|---|---|---|---|---|
| 02-e2e-guard-mirror | E2E coverage for guard-matched buttons | done | 2 |
|
plan.md | ../../specs/auth/requirements/self-actions-guard.md |
Task 02: E2E coverage for guard-matched buttons
Intent
Prove from the browser that the toggle buttons are disabled exactly when the existing backend last-admin guard would reject the action, and that the backend behavior itself is unchanged.
Inputs
- The spec
Scenariossection. - E2E auth patterns:
apps/web/e2e/tests/auth/auth-screenshots.spec.ts(serial describe,backend.restart({ KANDEV_FEATURES_AUTH: "true" })inbeforeAll, baseline restart inafterAll) andapps/web/e2e/helpers/auth.ts(setupAdmin,login). - Row locators:
users-table-rowrows carrydata-user-id; the toggle buttons carryusers-table-toggle-role/users-table-toggle-status.
Change
New file apps/web/e2e/tests/auth/users-self-actions.spec.ts:
- Serial describe;
beforeAllrestarts the backend withKANDEV_FEATURES_AUTH: "true";afterAllrestarts to baseline. - Setup the admin (
setupAdmin), login the admin context, and create a member viaPOST /api/v1/usersoncontext.request(shares the session cookie). Capture the admin and member ids. - Sole-admin UI: open
/settings/system/users; own row[data-user-id="{adminId}"]has both togglestoBeDisabled(); the member row has bothtoBeEnabled(). - Existing-guard proof:
PATCH /api/v1/users/{adminId}with{ "role": "member" }as the sole admin returns 409 (backend unchanged). - Create a second active admin (
POST /api/v1/users,role: "admin"); reload the page; the own row's toggles are nowtoBeEnabled(). - No-new-behavior proof:
PATCH /api/v1/users/{adminId}with{ "role": "member" }now returns 200 (self-demotion still allowed when another active admin exists).
Acceptance
- The spec passes with the production build (the managed runner builds it).
- Test discovery:
pnpm e2e:run --project auth tests/auth/users-self-actions.spec.tsruns exactly the new tests.
TDD sequence
- Write the spec (RED: buttons are enabled for the sole admin today).
- Run it via the auth project; confirm the failures are the expected assertions.
- With Task 01 landed, re-run; confirm green.
Verification
cd "$(git rev-parse --show-toplevel)/apps/web" && pnpm e2e:run --project auth tests/auth/users-self-actions.spec.ts
Dependencies
Task 01 (disabled-button state).
Parallelism
sequential. The spec asserts the Task 01 change and the unchanged backend.
Output contract
Report the spec path, the red and green run results (with the exact command),
blockers, and risks. Update this task and plan.md in the same conversation.
Results
- Spec:
apps/web/e2e/tests/auth/users-self-actions.spec.ts, one serial test in theauthproject (backend.restart({ KANDEV_FEATURES_AUTH: "true" })). - Red (before Task 01): failed at the sole-admin
toBeDisabled()assertion onusers-table-toggle-role— button was enabled. - Green (after Task 01):
cd apps/web && pnpm e2e:run --project auth tests/auth/users-self-actions.spec.ts→ 1 passed (7.6s). - The spec also proves the backend is unchanged: sole-admin self-PATCH
{role:"member"}→ 409; after a second active admin, same PATCH → 200. - Review fixup (luna round 1):
beforeAllnow restarts with a per-fileKANDEV_DATABASE_PATHinside the fixture tmpDir. The worker-scoped fixture andrestart()preserve the SQLite DB and auth setup is single-shot, so two auth specs sharing the worker collided regardless of admin email; the isolated DB keeps the full--project authsuite deterministic in either file order. Coverage widened: a disabled-admin row is created and asserted enabled while the sole active admin stays disabled (catches droppingstatus === "active"from the count or the per-row condition), and both active-admin rows are asserted enabled after the second admin is added. - Full auth project run:
pnpm e2e:run --no-build --project auth tests/auth/→ exit 0, 15 passed (both spec files in one worker). - Review fixup (luna round 2, mobile parity): added
apps/web/e2e/tests/auth/mobile-users-self-actions.spec.ts(runs in themobile-chromePixel 5 project via atestIgnoreon the desktopauthproject) asserting the same disabled/enabled states at the mobile viewport, plus the sharedusers-auth-helpers.tsused by both specs. Mobile run:pnpm e2e:run --no-build --project mobile-chrome tests/auth/mobile-users-self-actions.spec.ts→ 1 passed (8.1s).