chore(memory): BDR-075, EVAL-037, V1-1.2 journal, TODO, gate contract

This commit is contained in:
bchanot committed 2026-10-25 21:27:29 +01:00
1 parent a945e79131
commit 5bc6631b6e
6 files changed
+90 -10

No files matched your search

+7 -7
View File
@@ -401,17 +401,17 @@ Order (BDR-071): P0 docs + decisions → V1-1 clients and animals → V1-2 sheet
- Security: no platform-role branch; no `using (true)`; helpers `search_path = ''`, EXECUTE only where evaluated; email confirmation checked in SQL; `log_event` callers unchanged
- Stop if: `auth.users` join behaves differently on PGlite and the real stack; the profiles trigger interferes with `handle_new_auth_user` or sign-up; an existing policy would need editing beyond the `log_event` redefinition
- [ ] V1-1.2 Clients data (owner brief 2026-10-25; isolated stack only; DEV untouched; stop at checkpoint before V1-1.3)
- [ ] M1 closure: types re-checked with the official generator against an isolated DB holding M1 (diff 0); sandbox tool committed (`scripts/db-sandbox.sh`, `pnpm db:sandbox`: rootless, loopback, own ports, no volume, generated secrets outside Git, fresh + upgrade, official `supabase test db` / `gen types` via `--db-url`); owner DEV procedure for M1 (target, history, backup incl. auth, restore check, `db:test` non-destructive check) rehearsed on the sandbox; LRN-080/081
- [ ] M2 `<ts>_clients.sql`: unaccent, `private.fold_text`, `client_kind`, `clients` (+ `create_request_digest` for divergent replays), budget table + `private.consume_write_budget` (UTC fixed hour/day windows, row lock, last lock taken), RPCs create/update/set_archived/search, N9 audit policy, grants, RLS
- [ ] pgTAP 013; harness loads unaccent; `field-limits.ts` + behavioural parity test; types; census
- [ ] sandbox suite (vitest, real GoTrue/PostgREST sessions): M1 regression, clients HTTP, concurrency (creates, replay, divergent replay, stale revision, archive/restore race, budget limits, no deadlock), 20 000-client search timing
- [ ] docs: contract (budget, divergent replay, search_clients without current_animal_count until M3), SUPABASE.md, TEST_STRATEGY, BDR-075, journal
- [ ] fresh verifier + security audit; rust:check, check:all; checkpoint
- [x] M1 closure: types re-checked with the official generator against an isolated DB holding M1 (diff 0); sandbox tool committed (`scripts/db-sandbox.sh`, `pnpm db:sandbox`: rootless, loopback, own ports, no volume, generated secrets outside Git, fresh + upgrade, official `supabase test db` / `gen types` via `--db-url`); owner DEV procedure for M1 (target, history, backup incl. auth, restore check, `db:test` non-destructive check) rehearsed on the sandbox; LRN-080/081
- [x] M2 `<ts>_clients.sql`: unaccent, `private.fold_text`, `client_kind`, `clients` (+ `create_request_digest` for divergent replays), budget table + `private.consume_write_budget` (UTC fixed hour/day windows, row lock, last lock taken), RPCs create/update/set_archived/search, N9 audit policy, grants, RLS
- [x] pgTAP 013; harness loads unaccent; `field-limits.ts` + behavioural parity test; types; census
- [x] sandbox suite (vitest, real GoTrue/PostgREST sessions): M1 regression, clients HTTP, concurrency (creates, replay, divergent replay, stale revision, archive/restore race, budget limits, no deadlock), 20 000-client search timing
- [x] docs: contract (budget, divergent replay, search_clients without current_animal_count until M3), SUPABASE.md, TEST_STRATEGY, BDR-075, journal
- [x] fresh verifier + security audit (PASS; ECARTS closed); sandbox hardened; rust:check, check:all green; checkpoint
- Deviation: access layer `clients.ts` + workspace read move to V1-1.5 (first consumer; brief §6 scope lists no access layer)
- Objective: clients created, edited, archived, restored and searched through RPCs with the D15 guards, isolated per workspace, proven on the real stack
- Depends: V1-1.1; N2, N3, N6, N9 decided
- Files: `supabase/migrations/<ts>_clients.sql`; `supabase/tests/013_clients.sql`; `packages/supabase/tests/db/harness.ts` (load `unaccent`); `packages/supabase/src/field-limits.ts` + `tests/db/field-limits.test.ts` (behavioural parity, code points); `packages/supabase/src/clients.ts` (accessors, closed failure kinds) + unit tests; `packages/supabase/tests/e2e/clients-animals.e2e.ts` (seed and teardown through the existing psql helper), `scripts/clients-animals-e2e.sh`, root script (name to confirm); types regenerated
- Migration M2: `unaccent` in `extensions`; `private.fold_text`; `private.require_write_budget(p_workspace_id)` (N6: per workspace, 1 000/h, 5 000/day, counted under a per-workspace lock; document counter + lock order in contract §9.3); enum `client_kind`; `clients` (`name_key`, `search_key`, `phone_digits`, `create_request_id`); `create_client`, `update_client`, `set_client_archived`, `search_clients`; N9 condition on `audit_logs_select_admin`; grants; RLS
- Migration M2: `unaccent` in `extensions`; `private.fold_text`; `private.consume_write_budget(p_workspace_id)` (N6: per workspace, UTC hour/day windows, budget row lock taken last; contract §9.3, §10); enum `client_kind`; `clients` (`name_key`, `search_key`, `phone_digits`, `create_request_id`); `create_client`, `update_client`, `set_client_archived`, `search_clients`; N9 condition on `audit_logs_select_admin`; grants; RLS
- Tests: contract §12.1 rows for clients (whole-error identity, no lock outside the workspace, archived before conflict, replayed request id, caps, budgets, audit without values, search accents/case/backslash/phone formats/keyset); parity test; e2e cross-account + service key refused + GoTrue admin delete; search time on 20 000 clients recorded
- Acceptance: gates green; e2e green on the local stack; measurement written in the contract
- Security: constraint and parse errors caught inside RPCs; text parameters parsed in the body; search through POST; definer census
@@ -0,0 +1,59 @@
# 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.