From 3c2b503fc9efd8806acd4fe060b69f59daa70206 Mon Sep 17 00:00:00 2001 From: bchanot Date: Mon, 26 Oct 2026 02:31:53 +0100 Subject: [PATCH] chore(memory): BDR-078, LRN-085/086, EVAL-040, V1-1.5 journal, TODO, gate contract --- .claude/memory/decisions.md | 6 ++ .claude/memory/evals.md | 7 ++ .claude/memory/journal.md | 5 ++ .claude/memory/learnings.md | 10 +++ .claude/tasks/TODO.md | 13 +++- .../contracts/2026-10-26-v1-1-5-clients-ui.md | 75 +++++++++++++++++++ 6 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 .claude/tasks/contracts/2026-10-26-v1-1-5-clients-ui.md diff --git a/.claude/memory/decisions.md b/.claude/memory/decisions.md index 23156a96..1c4e6055 100644 --- a/.claude/memory/decisions.md +++ b/.claude/memory/decisions.md @@ -570,3 +570,9 @@ Status: active. Contract §11.6, BROWSER_TESTS.md. Decision (owner brief « Validation V1-1.3 et autorisation V1-1.4 Animaux et relations »): V1-1.3 accepted (native dialog, Playwright + axe, defects fixed); no JS focus trap without shown defect; D11 still open, 3 options before V1-1.6, none default. M3 `20261026100000_animals_relations.sql` as built (contract §8.3): species 8 + other rows (equine unchanged, rows not enum, Rust untouched); animals w/ D6b CHECKs, sex no default; relations w/ composite FKs (not deferrable), partial unique index current = `ended_at` and `voided_at` null; states current / ended (date known or unknown, `ended_at` discriminates, no contract change) / voided (frozen, shown nowhere). Caps: current ≤ 20 excludes ended+voided; totals 200/animal + 100 000/ws count every row (create-void loop bounded). `create_animal` + relation = 2 budget units (2 audit rows), relation reuses animal request id. Relation replay answered before `archived` (idempotence). Lock order M2+M3: workspace → animal → relation → client → budget last; relation RPCs read target ws unlocked among writable first (no lock outside ws). `search_animals` filter = `species_filter` (PG forbids param named like output col). `list_client_animals` cursor `sort_key` = '0'/'1' + name_key. Helpers `utc_tomorrow(timestamptz)` (pure, testable 31 Dec), parsers, `lock_relation_for_write`. No id-immutability trigger: privileged SQL may repoint within ws / move relation-less animal (§4 evolution path); composite FKs forbid cross-ws. Access layer → UI steps. Brief §2 follow-ups: axe KNOWN = rule + selector + opening markup + route; check:all prints PASSED / SKIPPED / NOT RUN, FAILED stage on error. Alt: 1 budget unit per create_animal (undercounts audit rows); totals excluding voided (unbounded create-void loop); replay after archived check (retry of committed create fails); trigger freezing ids (blocks §4 transfer path); keep `^dl$` route-free exceptions (new screens inherit). Status: active. M1-M3 not on DEV; procedure SUPABASE.md §3.3 (owner runs). + +## BDR-078 | 2026-10-26 | V1-1.4 validated; V1-1.5 client screens: owner U1/U2 choices, workspace in authStore, leave guard on links + +Decision (owner brief « Validation V1-1.4 et autorisation V1-1.5 Interface Clients »): V1-1.4 accepted (species_filter + replay order in scope). Owner choices asked before UI: U1 « Afficher plus » keyset (25 + 1 probe row, no count), U2 one « Afficher les archivés » switch, client page animals read-only (list_client_animals, no link/add), « premier animal » section → V1-1.6. Built: access layer `packages/supabase/src/{records,workspaces,clients,species}.ts` (closed RecordFailure = §9.4 kinds + session_expired + network; Zod on RPC answers; read by id explicit columns, non-uuid → null w/o request); personal workspace in authStore (loading/ready/inactive/unconfirmed/missing/error; account change resets profile+roles+avatar+workspace in one set; late answers of previous user dropped; ready kept during same-user re-read); RequireWorkspace remounts routes per workspace; leave guard = beforeunload + AppLayout capture on in-app links (ModalDialog), back/forward not interceptable (documented); heading focus on open (callback ref, waits drawer close); request id per form mount via generateUuid (getRandomValues; LAN http has no randomUUID). Shell suite: no HTML reporter (kept typed passwords). +Alt: numbered pages (needs count), tabs for archived, data-router migration for blocking, global data cache lib, storing search term (PII) to survive back nav. +Status: active. Client screens not checked on DEV (M1-M3 not applied; owner). diff --git a/.claude/memory/evals.md b/.claude/memory/evals.md index b3ca4fc7..ededacbd 100644 --- a/.claude/memory/evals.md +++ b/.claude/memory/evals.md @@ -282,3 +282,10 @@ Method: 14 mutations of M3 (PGlite pgTAP; M9 swapped into the sandbox, restored, Result: verifier CONFORME 11/11; security PASS (MEDIUM: sandbox fixture password literal pre-existing, policy-via-helper false positive; LOW: authz read then lock not re-checked (no membership change in V1-1), no-op/replay unmetered (as M2), reads reachable by GET (app convention), service_role ALL on species pre-existing). Mutations 12/14 caught first pass; M6 (voided-only link counted) + M9 (foreign client locked) survived → tests added (533a1c4), both caught after. Anomalies: pgTAP 014 green at first run (suspicious) → mutations proved it bites; axe route regex assumed /app/dashboard, dashboard is /app → shell suite failed until fixed (counter-mutations confirm scoping); permission layer refused sourcing sandbox secrets in shell → rehearsal via SQL + container env. Action: keep lock-wait probes for cross-tenant RPCs (LRN-084); check real route table before path-scoped test rules. + +## EVAL-040 | 2026-10-26 | V1-1.5 client screens: gates, three verifier rounds, report check + +Method: unit (supabase 92, app 509), access layer vs real PostgREST (sandbox 54), Chromium e2e:shell 42 (36 client journeys), mutations on app (request id per submit, double-click guard, late-answer guard, account reset, re-read loading) all caught; visual pass desktop+375 via temp capture spec; impeccable detect 0; report scan (decoded embedded zip); check:all green twice (02:04:48, 02:15:51); import:equine 0 diff; pgTAP 919; types match. Fresh security auditor + verifier ×3. +Result: security PASS (LOW: test SQL interpolation of sandbox uuids); noted USER_UPDATED reset of workspace unmounting forms → fixed e1c1980. Verifier 1 ECARTS (not-found heading unfocused → fixed 567ad40), verifier 2 ECARTS (docs counts uncommitted; floor assert drop of moved signIn → CLARIFICATIONS), verifier 3 CONFORME 11/11. +Anomalies: Prettier over whole src reformatted 39 files → restored, edits re-applied on originals; duplicate h1 (pre-existing top bar) broke selectors; StrictMode ran listener cleanup; drawer exit kept page inert; shell HTML report held typed passwords (BROWSER_TESTS claim false since V1-1.3) → reporter removed; permission layer refused rm -rf via variable (correct) and secrets sourcing. +Action: format new files only; dispatch verifier after committing docs; scan reports by content. diff --git a/.claude/memory/journal.md b/.claude/memory/journal.md index f27bf008..f2e845de 100644 --- a/.claude/memory/journal.md +++ b/.claude/memory/journal.md @@ -419,3 +419,8 @@ R5.4: `draft/{labels,changelog,review_report,drawing,overlay,app_review,svg_comp - Owner validated V1-1.3, authorised V1-1.4. M3 `20261026100000_animals_relations.sql` (b54c8e5): species 8+other, animals, relations current/ended/voided, 7 write RPCs + 3 reads, search_clients count; pgTAP 014 (258), parity, sandbox suite 18; sandbox `up upgrade ` (2dc04bc). - 14 mutations, 2 gaps closed (533a1c4); 4 migration states green; axe exceptions scoped (ba3a51e), check:all statuses (d7845b7); docs + DEV procedure to M3, not run (bc6a7dd). BDR-077, LRN-083/084, EVAL-039. - Verifier CONFORME 11/11, security PASS, check:all green. STOP at checkpoint: no V1-1.5, no DEV, no merge. + +## 2026-10-26 (V1-1.5 client screens, branch feature/v1-1-clients-animals) +- Owner validated V1-1.4, authorised V1-1.5. Owner choices: U1 « Afficher plus », U2 archived toggle, animals read-only, first-animal section → V1-1.6. Built access layer (a0e0699), workspace in authStore (ff028ec), screens (b38e627), Chromium journeys (d33a8f6), docs (ae0bd3f, d8e86a4). +- Fixes from gates: shell HTML report kept passwords (db81928), re-read unmounted forms (e1c1980), not-found heading focus (567ad40). BDR-078, LRN-085/086, EVAL-040. +- Security PASS, verifier CONFORME 11/11 (3rd round), check:all green. STOP at checkpoint: no V1-1.6, DEV untouched, no merge. diff --git a/.claude/memory/learnings.md b/.claude/memory/learnings.md index f1d19bfb..ff400828 100644 --- a/.claude/memory/learnings.md +++ b/.claude/memory/learnings.md @@ -599,3 +599,13 @@ Apply: any plpgsql RPC parsing text input; any pgTAP string_agg over same-transa Context: M3 mutation M9 removed the workspace filter on the client lookup in `create_animal_client_relation`. pgTAP stayed green: the composite FK refused the row and the RPC mapped it to the same `not_found`. Real effect: B's call took FOR SHARE on A's client → B waited on A's lock (timing side channel, cross-tenant contention). Caught only by sandbox test: A holds the row FOR UPDATE 2 s, B's refusal must answer < 1 s (measured 15 ms; mutated 1 749 ms). Apply: for every RPC that locks rows, a real-session test where the victim holds the locks and the attacker's refusal must be fast; equal error text alone does not prove "no lock outside the workspace". + +## LRN-085 | 2026-10-26 | Focus after drawer navigation: page inert during exit animation, StrictMode cleanup kills listeners + +Context: V1-1.5 page heading focus on open. Drawer (native modal dialog + motion exit 200 ms) keeps page inert → heading.focus() fails; then dialog close restores focus to menu button. Fix: callback ref on heading; if `dialog:modal` present, one-shot `close` listener + setTimeout(0) → focus after ModalDialog's microtask restore. Trap: useEffect cleanup removing the listener ran in React StrictMode's simulated unmount (dev) → listener gone; keep one-shot listener, check `isConnected`, no cleanup. Also: a page that renders its h1 after loading needs a callback ref, not a mount effect. Traced with a temporary focusin/close logger spec. +Apply: any focus-on-navigation or focus handoff next to a modal with exit animation; never rely on effect cleanup for listeners that must survive StrictMode. + +## LRN-086 | 2026-10-26 | Playwright HTML report keeps every typed value in step titles + +Context: V1-1.5 report check. `locator.fill(value)` step titles hold the value; the shell suite's HTML report (embedded base64 zip) held the throwaway accounts' passwords, contrary to BROWSER_TESTS.md ("no trace" was thought enough). Found by decoding the zip in memory and counting fixture patterns. +Apply: suites typing secrets → `reporter: [['list']]` (no html, no trace); audit reports by decoding the embedded zip, not by grepping the html. Also: never run Prettier on a whole src tree here (EVAL-037 repeat) — format new files only. diff --git a/.claude/tasks/TODO.md b/.claude/tasks/TODO.md index c08595e1..b611afd9 100644 --- a/.claude/tasks/TODO.md +++ b/.claude/tasks/TODO.md @@ -457,7 +457,18 @@ Order (BDR-071): P0 docs + decisions → V1-1 clients and animals → V1-2 sheet - Acceptance: gates green; e2e green; local tool and PDF unchanged - Security: same whole error for every foreign id; FK proof independent of the RPC; animal-then-client lock order - Stop if: N1, N4, N5 or N8 undecided; any change needed in report, sheet or editor code; the D9a guard blocks a flow the owner did not foresee - - [ ] V1-1.5 Clients UI + - [ ] V1-1.5 Clients UI (owner brief 2026-10-26 « Validation V1-1.4 et autorisation V1-1.5 Interface Clients »; isolated stack only; no animal screen; stop at checkpoint before V1-1.6) + - [x] V1-1.4 closure: owner validated (CONFORME 11/11, security PASS); species_filter + replay order accepted + - [x] owner choices 2026-10-26: U1 « Afficher plus » (keyset, page of 25 + 1 probe); U2 « Archivés » toggle; client page animals = read-only list (list_client_animals, no link, no add); « premier animal » section deferred to V1-1.6 + - [x] access layer `packages/supabase/src/{workspaces,clients,species,records}.ts`: personal workspace read, client reads/RPCs with explicit columns, keyset cursors, closed RecordFailure kinds (contract §9.4 + network, session_expired), Zod-checked RPC results; unit tests + real-PostgREST sandbox test of the same functions + - [x] authStore: personal workspace state (loading / ready / inactive / unconfirmed / missing / error) loaded with the account; identity change clears profile, roles, avatar, workspace at once and drops late responses of a previous user + - [x] app: routes /app/clients, /new, /:clientId, /:clientId/edit behind a workspace gate (remount per workspace); list (debounced search, toggle, « Afficher plus », states); detail (contact links, archived read-only, animals read-only, archive dialog with preview, restore); form (D-R7 schema on field-limits, phone entry rule, ISO country list via Intl.DisplayNames, request id per intent, conflict shows saved values, archived refusal); leave guard (beforeunload + in-app link clicks in the shell + Cancel; browser back not interceptable, documented); nav entry after Tableau de bord (mockup order); FR/EN + - [x] unit tests (schema, phone rule, countries, access mapping, store identity change, routes states, archive dialog, conflict, guard) + Playwright `e2e/shell/clients.spec.ts` on the sandbox (journeys, two accounts, pagination, keyboard, FR/EN, 375, axe without inherited exceptions, conflict, retry idempotence, error states, URLs free of fixture values) + - [x] gates (typecheck, test:run, lint, build, e2e:ui, e2e:shell, db:sandbox test-db/test/types --check, import:equine --check, rust:check, check:all), impeccable detect, fresh verifier + security audit + - [x] docs: contract §11.7 as built, FRONTEND_ARCHITECTURE, BROWSER_TESTS, SUPABASE §3.3 note, design README, CLAUDE.md map; BDR, EVAL, journal; commits pushed; checkpoint + - [x] gate fixes: shell HTML report removed (kept typed passwords), ready workspace kept during re-read, not-found heading focus; security PASS, verifier CONFORME 11/11 (round 3); check:all green 02:15:51 + - Deviation: leave guard extended from Cancel to every in-app link; search term not kept on back navigation; phones shown E.164 + - Pending owner: M1-M3 on DEV (SUPABASE.md §3.3) before the LAN check; D11 decision before V1-1.6 - Objective: list and search, create, edit, detail, archive and restore clients, FR/EN, phone and computer, keyboard - Depends: V1-1.2, V1-1.3, V1-1.4 (client page lists animals); D11, U1, U2 - Files: `apps/app/src/app/App.tsx` (routes); `apps/app/src/app/routes/app/clients/*`; `apps/app/src/clients/{validation,useClientForm}.ts`; `apps/app/src/components/clients/*`; `SidebarNav.tsx`, `MobileDrawer.tsx`; `apps/app/src/i18n/{fr,en}.ts`; tests; `apps/app/e2e/clients.spec.ts` diff --git a/.claude/tasks/contracts/2026-10-26-v1-1-5-clients-ui.md b/.claude/tasks/contracts/2026-10-26-v1-1-5-clients-ui.md new file mode 100644 index 00000000..ae19db1c --- /dev/null +++ b/.claude/tasks/contracts/2026-10-26-v1-1-5-clients-ui.md @@ -0,0 +1,75 @@ +# CONTRACT: V1-1.5 Clients UI, owner brief 2026-10-26 « Validation V1-1.4 et autorisation V1-1.5 Interface Clients » + +- branch `feature/v1-1-clients-animals`, base 6251051 (V1-1.4 validated); commits a0e0699 (access layer), ff028ec + (workspace state), b38e627 (client screens), d33a8f6 (Playwright journeys), db81928 (shell report fix), ae0bd3f (docs) +- diff under review: `git diff 6251051..HEAD -- packages apps docs CLAUDE.md` (HEAD includes e1c1980 workspace kept during a re-read, 567ad40 not-found heading focus, and the docs count update) +- functional contract `docs/development/V1-1_OWNERS_ANIMALS.md` §5.1, §7.1, §9.3, §9.4, §11 (§11.7 as built), §12.4, §12.5 +- owner choices recorded in TODO (V1-1.5) and contract §11.7: U1 « Afficher plus », U2 archived toggle, animals + read-only on the client page, « premier animal » section deferred to V1-1.6 +- isolated stack `pnpm db:sandbox` is UP. Allowed: `pnpm db:sandbox test`, `pnpm db:sandbox test-db`, + `pnpm db:sandbox types --check`, `pnpm e2e:shell`, `pnpm --filter @faunosteo/supabase test:run`, + `pnpm --filter @faunosteo/app exec vitest run`, typecheck and lint, read-only SQL through `pnpm db:sandbox sql`. + Not allowed: `pnpm check:all` and builds (a run is in progress), `db:sandbox up/down`, anything on the DEV stack + except `pnpm supabase migration list --local`. + +## Clauses + +C1. **Scope.** Client screens and their data access only: no animal screen, route or form, no `animals.ts` or +`relations.ts` access module, no migration, no change under `crates/` or `supabase/`, no mobile tab bar, no +dashboard tiles, no change to the validated mockups. Existing files changed only where the clients need it +(App routes, AppLayout guard, SidebarNav entry, Icon, i18n, authStore, lib/id, e2e support). + +C2. **Access layer.** `packages/supabase/src/{records,workspaces,clients,species}.ts`: only the authorised RPCs and +reads (search/list/preview through POST RPCs, read by id with an explicit column list, no `select=*`, no text +filter in a GET URL); pagination contract (25 default, ≤ 100, keyset, one probe row); generated types used for +argument names; failures folded into closed kinds keeping not_found, archived, conflict, request_conflict, +limit_reached, rate_limited, invalid_input, session_expired, network, unavailable; nothing distinguishes a foreign +id from an unknown one; no service key; the workspace id is a context the server re-checks, never an authorisation. + +C3. **Personal workspace and identity.** Read after sign-in, never created by the browser; states session absent +(RequireAuth), unconfirmed, inactive, loading, ready, missing, error each rendered; a change of account clears the +previous account's profile, roles, avatar and workspace at once, and late answers of the previous account are +dropped; the client routes remount per workspace, so no row of a previous session shows. + +C4. **List.** Search through the backend only (no client-side engine), debounced, ≤ 100 characters; 25 per page +with « Afficher plus »; deterministic order; archived toggle; status badges; access to the page; empty, loading, +network error with retry; reload after changes; no private value in URLs or logs. + +C5. **Form.** Person | organization, display name required, no first/last name, optional contacts, no default +country, no notes; bounds and patterns from `field-limits.ts` (D-R7), code points, control characters, Unicode; +phone entry rule of contract §11.3; FR/EN messages; submitting state; double-click guard; one create_request_id per +creation intent reused on retry, a new form a new id, request_conflict explicit; update with the expected revision, +no silent overwrite, conflict understandable with the saved values; archived refusal. + +C6. **Archive and restore.** Confirmation through the shared Dialog/ModalDialog (closing is not confirming, +refuses to close while pending, focus D13 kept), preview of sole-owned active animals, no deletion, no cascade to +animals, read-only archived page, restore through the RPC. + +C7. **Client page.** Contract fields; `tel:` and `mailto:`; animals read-only from `list_client_animals` (no link, +no add, no invented data); `current_animal_count` from the backend in the list; same « introuvable » for unknown, +foreign and malformed ids. + +C8. **Navigation, design, accessibility.** Clients entry in sidebar and drawer in the mockup's order, existing +navigation kept, no tab bar; existing components and tokens reused; labels, visible focus, errors announced next +to fields, first error focused, page heading focused on open; 375 px without horizontal overflow; FR/EN; the new +pages pass axe without any KNOWN exception applying to their own elements. + +C9. **Unsaved changes.** `beforeunload` while dirty; in-app links ask first (ModalDialog), staying keeps the +values; what the router cannot intercept (browser back/forward) documented, not claimed. + +C10. **Tests.** Unit tests (access layer call shapes and failure mapping; schema; store identity change; screens: +states, retry idempotence, new intent, conflict, archived, archive dialog pending, leave guard, double click); +the access layer against real PostgREST (`clients-access.sandbox.ts`); Chromium journeys on the sandbox +(`e2e/shell/clients.spec.ts`: create, search, edit, archive, filter, restore, pagination, keyboard, two accounts, +conflict, retry, errors, leave guard, language, desktop + 375, axe); request URLs free of fixture values; suites +green when run. + +C11. **Reports and docs.** No private data in test reports beyond fictitious fixtures (the shell HTML report that +kept typed passwords removed); contract §11.7, BROWSER_TESTS, TEST_STRATEGY, SUPABASE.md, FRONTEND_ARCHITECTURE, +design README, CLAUDE.md updated; commits pushed; no merge; main and release/0.2.0 untouched; DEV untouched. + +## CLARIFICATIONS + +- FLOOR ASSERT_DROP `apps/app/e2e/shell/shell.spec.ts` (2 → 0 assertion lines): the `signIn` helper, with its two + `expect` lines, moved verbatim to `apps/app/e2e/support/shell.ts` so both shell specs share it; both specs still + await it, no assertion is lost. Authorised.