Files
faunosteo/.claude/tasks/contracts/2026-10-25-v1-1-2-clients.md

4.8 KiB

CONTRACT: V1-1.2 Clients data (M2) + M1 closure, owner brief 2026-10-25 « Validation V1-1.1 et autorisation V1-1.2 Données clients »

  • branch feature/v1-1-clients-animals, base 6bf6978 (V1-1.1 validated); commits 08abe42 (sandbox tool + M1 suite), 5ed1f01 (DEV procedure docs), 2c0531d (memory), 4adbfcb (M2 code), f8bd1b6 (docs)
  • diff under review: git diff 6bf6978..f8bd1b6 -- scripts supabase packages package.json docs
  • functional contract docs/development/V1-1_OWNERS_ANIMALS.md §5, §5.1, §8.2, §9, §10, §12, §13.2
  • isolated stack: pnpm db:sandbox (scripts/db-sandbox.sh, SUPABASE.md §5.1) is UP (upgrade mode, M1+M2 applied over older data). Allowed: pnpm db:sandbox test-db, pnpm db:sandbox types --check, pnpm db:sandbox test, echo "<read-only SQL>" | pnpm db:sandbox sql. The DEV stack (supabase_*_faunosteo) must not be touched except pnpm supabase migration list --local (read-only).

Clauses

C1. Scope. M2 only: supabase/migrations/20261025110000_clients.sql. No M3 object (animals, relations, species rows, animal enums), no React screen or route, no V1-1.3 tooling (Playwright, Dialog), no change to crates/, no edit of an existing migration, no change to existing tables' grants or policies except the N9 condition on audit_logs_select_admin.

C2. M1 closure. The committed database.types.ts equals the official generator's output (supabase gen types typescript --schema public, through Prettier) against an isolated database holding the migrations; no hand edit; types cover exactly the public schema objects of M1 and M2.

C3. Sandbox tool. scripts/db-sandbox.sh: rootless Docker, ports on 127.0.0.1 only and distinct from DEV, no volume created or removed, cleanup by literal faunosteo_dbsandbox_* names only, secrets generated outside the repository and never printed or committed, image versions pinned and documented, fresh and upgrade modes, every Supabase CLI call with an explicit sandbox --db-url (none can reach DEV).

C4. DEV procedure (doc only). SUPABASE.md §3.3: target check, migration history, only V1-1 migrations pending, accounts count, backup including auth data stored outside Git and checked, application without reset and without db push, migration repair or destructive command, db:test shown non-destructive, post-checks (history, workspaces, duplicates, privileges, types, e2e:avatar), stop conditions, no secret printed. Claude applied nothing to DEV.

C5. Clients model. person | organization; display_name required, no first/last name, no notes; optional contacts; no default country; workspace FK on delete restrict; text rules and bounds as contract §5/§5.1; no sensitive extra field; field-limits.ts constants proven equal to the SQL CHECKs by a behavioural parity test (bounds, code points, control ranges, patterns; TypeScript never accepts what SQL refuses).

C6. RPCs. create_client, update_client, set_client_archived (definer) and search_clients (invoker): identity from auth.uid() only via writable_workspace_ids / RLS (active profile, confirmed email); same whole error for a foreign and an unknown id; parse errors and constraint violations → invalid_input without echo; idempotent create, divergent replay → request_conflict; stale revision → conflict; archived read-only (archived before conflict); restore allowed; no-op writes nothing; EXECUTE only for authenticated; search_path empty; owner postgres; audit rows ids only ({workspace_id}), hidden from platform staff (N9).

C7. Budget and caps. Transactional counter per workspace (owner §9): UTC hour/day windows documented (zone, reset, boundaries); 1 000/h, 5 000/day, 20 000 clients; increment and write in one transaction; refused, replayed and no-op calls not counted; concurrency-safe; stable lock order documented (workspace, animal, client, budget last); lock scope per workspace, measured.

C8. Search. POST RPC, 25 default / 100 max page, ≤ 100-character term, deterministic order (name_key, id) with keyset, LIKE wildcards escaped, phone search, no leak of another workspace through rows, counts or pages; index exists; 20 000-client timing recorded.

C9. Tests. pgTAP 013_clients.sql + 001 census green on PGlite and on the isolated real image (fresh and upgrade); sandbox suite: real authenticated sessions per role (A, B, anon key, service key, deactivated, unconfirmed), concurrent creates, replays, divergent replay race, stale revision race, archive/restore race, budget at the limit under concurrency, no deadlock; M1 regression (workspaces, backfill, auth/profile). pnpm test:run green.

C10. Docs and limits. Contract §8.2 as built + deviations, SUPABASE.md §3.4/§5.1, TEST_STRATEGY, BDR-075, LRN-080/081 (scoped, no duplicate). No merge, main and release/0.2.0 untouched, no deploy, fixtures fictitious.