Files
faunosteo/.claude/tasks/contracts/2026-10-26-v1-1-6-animals-ui.md
bchanot e7fd7e34e6 test(supabase): the audit privacy check no longer reads a uuid as a date
014 #237 matched « 20[0-9]{2}- » inside a workspace uuid on a long-lived stack.
The pattern now reads the metadata without workspace_id, still over every
audit row. It would have stopped the DEV procedure at db:test. Found by the
V1-1.6 verifier.
2026-10-26 17:53:37 +01:00

103 lines
8.9 KiB
Markdown

# CONTRACT: V1-1.6 Animals and relations UI, owner brief 2026-10-26 « Validation V1-1.5 et autorisation V1-1.6 Interface Animaux et clôture »
- branch `feature/v1-1-clients-animals`, base 3c2b503 (V1-1.5 validated); commits e223576 (access layer), 930499c
(screens), 3c2b503..HEAD also holds 3e968ee (Playwright journeys, sandbox e2e argument passthrough) and e215e9b (docs)
- diff under review: `git diff 3c2b503..HEAD -- packages apps docs scripts CLAUDE.md`
- functional contract `docs/development/V1-1_OWNERS_ANIMALS.md` §5.2, §5.3, §5.4, §7.1, §9.3, §9.4, §11.1 to §11.5,
§11.8 (as built), §13.3, §15 (closure inventory); owner decisions recorded in §11.8 and TODO: D11 drawer only, first
animal from the client page in one `create_animal` call, no role preselected, relation add as an in-page panel, end /
dates / void as confirmations, U3 date fills and locks the year; D12 not in the brief
- isolated stack `pnpm db:sandbox` is UP. Allowed: `pnpm db:sandbox test`, `pnpm db:sandbox test-db`,
`pnpm db:sandbox types --check`, `pnpm db:sandbox e2e-shell [spec] [--project ...] [--grep ...]`,
`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, `db:sandbox up/down`, any
file change, anything on the DEV stack except `pnpm supabase migration list --local`.
## Clauses
C1. **Scope.** Animal screens, relation panels and dialogs, the client page's animal section, their data access, tests
and docs only: no migration, nothing under `supabase/` or `crates/`, no bilan link (V1-3), no sheet shown, no cabinet,
no tab bar, no dashboard tiles, no weight / photo / coat / identification / neutering / death date / notes field, no
redesign of the client screens (the client page's animal section and the shared `Card` / `Button` fixes aside).
C2. **Access layer.** `packages/supabase/src/{animals,relations}.ts` and the `records.ts` additions: writes only
through the M3 RPCs (no direct insert, update or delete on a record table); reads by id with explicit column lists,
never `select=*`; searches through POST RPCs (no term in a URL); the relations read by animal id with `voided_at is
null` and a bound; generated argument names; Zod-checked answers; closed failure kinds including `duplicate_relation`
and `already_ended`; a non-uuid id makes no request; a foreign id reads as unknown; no service key.
C3. **Routes and isolation.** `/app/animals`, `/new`, `/:animalId`, `/:animalId/edit` behind the workspace gate
(remount per workspace, no data of a previous account shown); the same « Animal introuvable » for unknown, foreign and
malformed ids; no private value or business identifier in a URL query (the origin client travels in the navigation
state and is read again and checked active before being pre-associated); the workspace id is a context, never an
authorisation.
C4. **Form (D-R7).** Name, species, sex required; sex with no preselected value; species from the active rows only;
the detail required for « Autre » and never sent for another species; breed optional; birth year or full date (D6b),
a full date fills and locks the year (U3), no year turned into a date, not in the future (device date), not before
1900; bounds and patterns from `field-limits.ts`; errors under their field, first error focused; one
`create_request_id` per creation intent reused on a retry; `conflict` keeps the typed values and shows the stored
ones; leave guard.
C5. **Creation with a first client.** Optional; one atomic `create_animal` call carrying `client_id`,
`relation_role` and `started_on` (never two calls); the role explicit with none preselected; the pre-associated client
removable before saving; a lost answer retried with the same request id gives one animal and one relation.
C6. **Animal page.** Identity, species, sex, breed, birth with its known precision, status; current relations then the
history, roles, client links, phones as `tel:`, dates only when known (`ended_at` never shown as a date); « Propriétaire
non renseigné » without a current owner, never a placeholder client; voided relations shown nowhere; actions only on an
active animal; archive and restore through the shared dialog, archived page read-only, no client archived.
C7. **Relation writes.** Add (both active, explicit role, optional start), end with an optional real date not before
the start, correct dates, void explained as an erroneous entry and final, never a physical deletion; every write sends
the revision it read; `duplicate_relation`, `conflict`, `already_ended`, `archived`, `limit_reached`, `rate_limited`,
`session_expired`, `network` phrased distinctly; a stale relation (`conflict`, `not_found`) reloads the relations;
confirmations refuse to close while pending and return focus after the change is shown, also when the opener left.
C8. **Client page.** Animals from `list_client_animals` once per animal and group with every role and dates, linked to
the animal page; « Ajouter un (premier) animal » with the client pre-associated; « Associer un animal existant » panel;
none on an archived client; the contractual `current_animal_count` of the list unchanged; ended relations shown as
former, voided ones nowhere.
C9. **Navigation, design, accessibility.** « Animaux » after « Clients » in the sidebar and the drawer, drawer only (no
tab bar); existing components and tokens; labels, visible focus, errors announced, heading focused on page open; 375 px
without horizontal overflow; FR/EN key parity; the new pages pass axe without any KNOWN exception applying to their own
elements; the two phone states scanned from the top of the page are justified in BROWSER_TESTS.md §6.
C10. **Tests.** Unit (access mapping and call shapes, schema and display rules, screens: states, request id reuse,
conflict, archive, relations, client page, session gate); the access layer against real PostgREST
(`animals-access.sandbox.ts`); Chromium journeys `e2e/shell/animals.spec.ts` (brief §17 items 1 to 24, FR/EN, desktop
and 375, axe, request URLs free of fixture values); existing suites green; counter-checks recorded in §11.8.
C11. **Reports, docs, git.** No private data in reports, traces or logs beyond fictitious fixtures (shell suite: no
trace, no HTML report); contract §11.8, §13.3, §14, §15, SUPABASE.md §3.3 (restore check, DEV browser acceptance),
BROWSER_TESTS, TEST_STRATEGY, FRONTEND_ARCHITECTURE, design README, CLAUDE.md updated; commits pushed; no merge; `main`,
`develop` and `release/0.2.0` untouched; DEV untouched (M1 to M3 still pending there).
C12. **Technology boundary.** No business rule re-implemented in TypeScript that PostgreSQL already enforces beyond the
D-R7 form checks; no artificial Rust/wasm call; the boundary choice written in §11.8.
## CLARIFICATIONS
- Owner brief §17 (not on disk), items 1 to 24, and where `e2e/shell/animals.spec.ts` covers them: 1 sign-in and
workspace (every test's `signIn` + `openAnimals`); 2 empty list, 3 creation without owner, 5 search, 6 species
filter, 7 consultation, 8 edit, 10 archive and restore (test « empty list, an « Autre » … restore »); 4 creation with
an initial relation, 11 creation from a client page, 12 linking an existing animal (« from a client page … »); 13
several owners, 14 normal end, 15 voiding, 16 duplicate refused (« animal page: co-owners … »); 17 two accounts, 18
change of session (« two accounts and a change of session »); 19 keyboard (« keyboard only »); 9 revision conflict
(« a concurrent edit »); 23 retry after a lost answer (« a lost answer »); 24 network errors (« failures … »); 20
FR/EN (every test in both languages, plus « the animal pages follow a change of language »); 21 desktop and 375
(both projects); 22 axe on the new pages (every state). Pagination: « pages of 25 ».
- Restore of an archived animal is one button with no confirmation, as on the validated client page (V1-1.5); only
archiving is confirmed.
- Verifier round 1 (ECARTS C10): the client journey failed intermittently on a late replay after its restore (the
client page now reloads its animals). Fixed: `dropLateReplays` in `e2e/support/sandbox.ts`, called after each test
by the three shell specs; the client journey ends on the reloaded animal section; `e2e:shell` 82/82 three runs in a
row.
- Verifier round 2 (ECARTS C10): pgTAP 014 #237 « no name, role, breed or date in the audit rows » failed on the
long-lived sandbox: its date pattern `20[0-9]{2}-` matched a workspace uuid (`…2012-…`) in the metadata of a real
row (a false positive, latent since V1-1.4, that would also have stopped the owner's DEV procedure at `db:test`).
Authorised exception to C1 (test file only, no migration): the pattern now reads the metadata without
`workspace_id` (the test before it proves that key is the only one), still over every audit row; counter-checked
(uuid alone: false; a name or a date added: true); pgTAP 919/919 on the sandbox and on PGlite.