diff --git a/.claude/rules/sheet-model.md b/.claude/rules/sheet-model.md index 043ba26c..a8598a82 100644 --- a/.claude/rules/sheet-model.md +++ b/.claude/rules/sheet-model.md @@ -12,8 +12,8 @@ paths: ["crates/core/src/domain/sheet/**", "docs/development/ANATOMICAL_SHEET_MO draft (`create_sheet_draft`) then publication; from V1-2, publication only from an approved round on a server verdict of the core. - The Rust core is the only authority on document rules (O22): add a rule to `validate_sheet_document` and to the spec - table only. Never extend `private.sheet_document_issues`: V1-2 (M5) removes its business rules and keeps the - structural and relational guards. + table only. V1-2 (M5) dropped the SQL mirror (`private.sheet_document_issues`); SQL keeps the structural and + relational guards and the one declared status check (contract §12.2). Never add a business rule in SQL. - Document schema change → bump `SHEET_DOCUMENT_SCHEMA_VERSION`, extend the SQL CHECK on `document_schema_version`. No bump during V1-2 (BLK-008). - Historical equine sheet `503dc301…` = generated seed `draft/` (`pnpm import:equine --out` into an empty folder, then diff --git a/crates/core/src/domain/sheet/check.rs b/crates/core/src/domain/sheet/check.rs index ee6f4e29..ad508941 100644 --- a/crates/core/src/domain/sheet/check.rs +++ b/crates/core/src/domain/sheet/check.rs @@ -1,6 +1,6 @@ -//! The publication gate on the client side (`packages/supabase/src/anatomical-sheets.ts`): -//! the full strict shape, then every integrity rule. The database re-checks the referential -//! rules on its own (`private.sheet_document_issues`); this never replaces that guard. +//! The core's document check: the full strict shape, then every integrity rule. Since +//! V1-2.1 the client publication gate and the SQL mirror are gone (contract §12.2): +//! publication rests on the server verdict, never on this check run in a page. use serde::{Deserialize, Serialize}; use serde_json::Value; diff --git a/crates/core/src/domain/sheet/validate.rs b/crates/core/src/domain/sheet/validate.rs index 48de2b48..ad1b9424 100644 --- a/crates/core/src/domain/sheet/validate.rs +++ b/crates/core/src/domain/sheet/validate.rs @@ -3,8 +3,9 @@ //! //! The shape tier (serde, as Zod) accepts dangling references so drafts can be saved //! mid-edit; this tier lists every inconsistency for the editor and gates publication. Each -//! rule is one function, run in the TypeScript order; codes, paths and messages are the -//! contract shared with the SQL re-check (`private.sheet_document_issues`). +//! rule is one function, run in the TypeScript order; codes, paths and messages are a +//! contract (the fixtures under `tests/conformance`). No SQL mirror re-checks them since +//! V1-2.1 (contract §12.2): the core is the only authority. use std::collections::{HashMap, HashSet}; diff --git a/crates/core/tests/curation/LEDGER.tsv b/crates/core/tests/curation/LEDGER.tsv index 5f5050ae..98cf12de 100644 --- a/crates/core/tests/curation/LEDGER.tsv +++ b/crates/core/tests/curation/LEDGER.tsv @@ -360,7 +360,7 @@ packages/domain/tests/r2-conformance.test.ts sheet conformance fixtures > findin packages/domain/tests/r2-conformance.test.ts sheet conformance fixtures > several-errors integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported crates/core/tests/conformance/several-errors.json TS (MAKE unset) asserts the fixture file = TS validateSheetDocument output (+ shape tier verdict); Rust checks its rules and the SQL codes against the same file packages/domain/tests/r2-conformance.test.ts sheet conformance fixtures > shape-references-not-array integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported crates/core/tests/conformance/shape-references-not-array.json TS (MAKE unset) asserts the fixture file = TS validateSheetDocument output (+ shape tier verdict); Rust checks its rules and the SQL codes against the same file packages/domain/tests/r2-conformance.test.ts sheet conformance fixtures > shape-reference-url-scheme integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported crates/core/tests/conformance/shape-reference-url-scheme.json TS (MAKE unset) asserts the fixture file = TS validateSheetDocument output (+ shape tier verdict); Rust checks its rules and the SQL codes against the same file -packages/domain/tests/r2-conformance.test.ts sheet conformance fixtures > has no stale fixture file integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported crates/core/tests/conformance TS lists files absent from its CASES; Rust reads every *.json of the folder (>=25) and the committed supabase/tests/011_sheet_conformance.sql (26 asserts) pins the set +packages/domain/tests/r2-conformance.test.ts sheet conformance fixtures > has no stale fixture file integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported crates/core/tests/conformance TS lists files absent from its CASES; Rust reads every *.json of the folder (>=25); the generated pgTAP file that pinned the set left with the SQL mirror (V1-2.1 M5, contract §12.2) packages/domain/tests/r2-horse-slice.test.ts horse slice JSON fixture > equals the TypeScript lean input horse slice fixture freeze deleted - - TS generator/asserter of crates/core/tests/fixtures/horse-slice.json from horse-slice.ts; once the TS fixture is gone the JSON is the source; no business contract packages/domain/tests/r2-oracles.test.ts Zod output oracles of the R2 switch > sheet.draft.json Zod output oracles (contracts byte for byte) replaced cargo sheet_contract::the_curated_draft_prints_as_zod_outputs_it crates/core/tests/oracles/sheet.draft.json TS asserts source path and Zod(draft/document.json) = oracle output; Rust prints its parse of the same source and compares to the oracle output packages/domain/tests/r2-oracles.test.ts Zod output oracles of the R2 switch > sheet.legacy-import.json Zod output oracles (contracts byte for byte) replaced cargo sheet_contract::the_legacy_import_baseline_prints_as_zod_outputs_it crates/core/tests/oracles/sheet.legacy-import.json same mechanism on legacy-import/document.json diff --git a/docs/development/BACKEND_ARCHITECTURE.md b/docs/development/BACKEND_ARCHITECTURE.md index 5a95f488..32c4f321 100644 --- a/docs/development/BACKEND_ARCHITECTURE.md +++ b/docs/development/BACKEND_ARCHITECTURE.md @@ -58,7 +58,7 @@ Conventions fixed now so every step follows them: - UUID primary keys (`gen_random_uuid()`), `created_at` / `updated_at` with a shared trigger, soft delete `deleted_at` where the architecture names it. - Enums as PostgreSQL `enum` types when the value set is closed by the business (report status, appointment status), `text` + CHECK when the set is expected to grow (document types). -- JSONB documents (`reports.current_document`, `anatomical_sheet_versions.content`) carry their own `schema_version` and are validated by the Rust core's contracts (`crates/core/src/domain`, since R2) at the application boundary and by a CHECK on `schema_version` in SQL. SQL re-checks only what publication needs (`private.sheet_document_issues`, BDR-032), with the same rule codes as the core. +- JSONB documents (`reports.current_document`, `anatomical_sheet_versions.content`) carry their own `schema_version` and are validated by the Rust core's contracts (`crates/core/src/domain`, since R2) at the application boundary and by a CHECK on `schema_version` in SQL. Since V1-2.1 the core is the only authority on the sheet document's rules: SQL keeps the structural guards (shape, schema version, size, species) and the declared status check at approval and publication, and publication rests on a server verdict (`V1-2_ANATOMICAL_SHEETS.md` §12.2, O22). - Every table exposed to the browser: RLS enabled, no `USING (true)` policy for `authenticated`, no anonymous policy on core tables (§17.4). ## 4. RLS strategy diff --git a/docs/development/SUPABASE.md b/docs/development/SUPABASE.md index 28424e29..8adae5f2 100644 --- a/docs/development/SUPABASE.md +++ b/docs/development/SUPABASE.md @@ -798,7 +798,7 @@ Docker. | `pnpm db:sandbox up upgrade []` | the migrations before ``, the seeds, two GoTrue accounts (confirmed, unconfirmed), then `migration up`: the path a DEV database takes; with ``, the migrations before `` first (the workspaces count is printed), then the rest | | `pnpm db:sandbox test-db` | `supabase test db --db-url`: the pgTAP files on the real image (rows unchanged afterwards) | | `pnpm db:sandbox types [--check]` | `supabase gen types --db-url ... --schema public` through Prettier, written or diffed with the committed file | -| `pnpm db:sandbox test` | `packages/supabase/tests/sandbox/*.sandbox.ts`: real GoTrue and PostgREST sessions, concurrent SQL sessions | +| `pnpm db:sandbox test` | `packages/supabase/tests/sandbox/*.sandbox.ts`: real GoTrue, PostgREST and Storage sessions, concurrent SQL sessions (two-session lock order, V1-2.1), timing at the caps, the PGlite shim against the image; re-runnable on one stack | | `pnpm db:sandbox e2e-shell` (= `pnpm e2e:shell`) | the authenticated `/app` shell in Chromium (`apps/app/e2e/shell`, `docs/development/BROWSER_TESTS.md`): a loopback dev server whose Supabase calls are replayed on the sandbox, fictitious accounts per test | | `pnpm db:sandbox sql` / `down` | psql as postgres on stdin / remove the stack |