From 77e5fa4cf59fb6d72dcf1de083dc40675c546e62 Mon Sep 17 00:00:00 2001 From: bchanot Date: Wed, 28 Oct 2026 15:52:49 +0100 Subject: [PATCH] feat(supabase): V1-2.1 M4/M5 secure sheet access and review workflow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit M4 20261028100000_sheet_access_hardening + M5 20261028110000_sheet_review_workflow (applied together; no unprotected window). Implements contract §5-§14. - Catalogue rights table + owner RPCs; has_mfa / has_aal2_session (live auth.sessions check); grant_active vs caller_has split; catalogue reader predicate; can_edit_sheet on the sheet_editor capability (F14). - AR-1 B: aal2 required on every platform role change, target verified factor, race-free last-owner guard (F18/F19); service_role loses table privileges on the catalogue + profiles/profile_roles and EXECUTE on the role RPCs (F12/F17). - Reviewed lifecycle: version provenance + review columns, content/freeze/ author triggers, rounds/comments/acknowledgments, save/submit/withdraw/ comment/acknowledge/decide, atomic publish_sheet_version(review_id) on the stored verdict, deprecate/archive/restore, species RPCs, equine working copy, uploads with the storage check (F7) + editor INSERT policy + 2 MiB bucket. F1-F3,F5,F6,F8,F9,F13,F15,F16 closed. Verdict is a fixture until M6 (V1-2.3). - O22: SQL business mirror removed, declared status check kept; pgTAP 011 and the Rust generator's SQL parts deleted, ledger retargeted. - Access layer sheets.ts (closed SheetFailure kinds); old client publish gate deleted; types regenerated; upload tool reads via get_sheet_asset_state. Tested on the throwaway sandbox only; DEV untouched. pgTAP 850 (real stack) / 122 (PGlite) green; real-GoTrue AR-1 B + F18 race green; fresh install and M3->M5 upgrade green; V1-1 regression green; rust:check, typecheck, lint, build, types drift clean. BDR-084, LRN-095. --- .claude/memory/decisions.md | 13 + .claude/memory/journal.md | 3 + .claude/memory/learnings.md | 9 + .claude/tasks/TODO.md | 9 +- .../src/bin/upload_sheet_assets/storage.rs | 27 +- crates/core/tests/curation/LEDGER.tsv | 54 +- crates/core/tests/sheet_conformance.rs | 124 +- crates/core/tests/upload_tool.rs | 17 +- packages/supabase/src/anatomical-sheets.ts | 105 -- packages/supabase/src/database.types.ts | 433 ++++- packages/supabase/src/index.ts | 21 +- packages/supabase/src/sheets.ts | 227 +++ .../supabase/tests/anatomical-sheets.test.ts | 113 -- .../supabase/tests/db/schema-types.test.ts | 87 +- packages/supabase/tests/db/supabase-shim.sql | 28 + packages/supabase/tests/sandbox/mfa.ts | 103 ++ .../supabase/tests/sandbox/sheets.sandbox.ts | 91 + packages/supabase/tests/sandbox/totp.ts | 45 + .../tests/sandbox/workspaces.sandbox.ts | 12 +- scripts/db-sandbox.sh | 2 +- .../20261028100000_sheet_access_hardening.sql | 1088 +++++++++++ .../20261028110000_sheet_review_workflow.sql | 1624 +++++++++++++++++ supabase/tests/001_schema.sql | 2 +- supabase/tests/003_platform_roles.sql | 168 +- supabase/tests/004_audit.sql | 17 +- supabase/tests/005_anatomical_sheets.sql | 680 +------ supabase/tests/006_sheet_asset_storage.sql | 292 +-- supabase/tests/007_equine_seed.sql | 154 +- .../tests/008_sheet_document_schema_v2.sql | 98 - supabase/tests/010_files_foundation.sql | 4 +- supabase/tests/011_sheet_conformance.sql | 167 -- supabase/tests/015_catalog_access.sql | 204 +++ supabase/tests/016_sheet_review_workflow.sql | 209 +++ 33 files changed, 4613 insertions(+), 1617 deletions(-) delete mode 100644 packages/supabase/src/anatomical-sheets.ts create mode 100644 packages/supabase/src/sheets.ts delete mode 100644 packages/supabase/tests/anatomical-sheets.test.ts create mode 100644 packages/supabase/tests/sandbox/mfa.ts create mode 100644 packages/supabase/tests/sandbox/sheets.sandbox.ts create mode 100644 packages/supabase/tests/sandbox/totp.ts create mode 100644 supabase/migrations/20261028100000_sheet_access_hardening.sql create mode 100644 supabase/migrations/20261028110000_sheet_review_workflow.sql delete mode 100644 supabase/tests/008_sheet_document_schema_v2.sql delete mode 100644 supabase/tests/011_sheet_conformance.sql create mode 100644 supabase/tests/015_catalog_access.sql create mode 100644 supabase/tests/016_sheet_review_workflow.sql diff --git a/.claude/memory/decisions.md b/.claude/memory/decisions.md index 7749700f..2ed43ab2 100644 --- a/.claude/memory/decisions.md +++ b/.claude/memory/decisions.md @@ -613,3 +613,16 @@ Alt: A (owner+admin only) rejected: leaves moderator/support weak path; C (accep Review (fresh challenger FATAL(4), all integrated, no ratified decision changed): grant needs target with verified factor; private fns: non-null actor = auth.uid() + aal2, null actor only without JWT; advisory lock both RPCs; DEV precondition before M4 = ENVIRONMENTS §3.6 hardening (public default JWT secret + demo service key + 54321 LAN → aal2 forgeable) + seed owner password changed + role holders listed; recovery reordered (ban, password set with owner, unban, enrol). Reserves: staff read policies (is_platform_admin) stay aal1, owner decision; stolen aal2 session residual; refused attempts not in audit table. Status: ratified; contract only, no code/migration/DEV change; V1-2.1 not authorised. + +## BDR-084 — V1-2.1 M4/M5 secure SQL foundations (sandbox) (2026-10-28) +- **Status**: implemented + tested on sandbox; DEV apply is an owner action (contract 16.11) +V1-2.1 M4/M5 built + tested on sandbox (not DEV). Migrations `20261028100000_sheet_access_hardening` (M4), `20261028110000_sheet_review_workflow` (M5); applied together (M4 removes Step-4 unsafe write paths, M5 adds the reviewed workflow; no unprotected window). + +Key design choices: +- AR-1 B: `private.has_aal2_session()` = aal claim == `aal2` AND the token's `session_id` names a live `auth.sessions` row of the caller at aal2 (closes the stolen-token-after-downgrade window at once, not after jwt_expiry). GoTrue v2.197 probe confirmed: verify upgrades the SAME session to aal2, token carries `aal`+`session_id`+`amr`, exp-iat=3600. +- Predicates split by caller vs stored actor: `grant_active(uid,kind)` (no assurance) for stored approvers/acknowledgers; `caller_has(kind)` = `grant_active(auth.uid())` + `has_mfa()` for the session. `can_edit_sheet` redefined on `caller_has('sheet_editor')` + caller==auth.uid() (F14). +- F12/F17: `revoke all ... from service_role` on every catalogue table + profiles/profile_roles; role RPCs `EXECUTE` revoked from service_role. service_role stays a GoTrue-admin residual (§13), not a table writer. +- F18 last-owner race: one `pg_advisory_xact_lock` in both RPCs and both private writers, guard counts active owners under the lock. Cross-revoke resolves safely (one 200, one refused; one owner remains). +- O22 mirror removed: dropped `sheet_document_issues` + the 4 business-mirror helpers; kept `sheet_document_has_shape`, `check_sheet_version_document`, `unknown_assets`; added the declared status check `sheet_all_reviewed` (absent review_status = inherited = refused). pgTAP 011 + the SQL-mirror parts of the Rust `sheet_conformance` generator deleted; ledger retargeted. +- Publish gate: `publish_sheet_version(review_id)` atomic; `guard_sheet_version_update` lets draft->published only with an approved round of same version+revision + passed verdict (no direct UPDATE publishes, even table owner). Verdict is a fixture until M6 (V1-2.3). +- Reader column grants narrowed; editor needs only `revision` on versions; authors/provenance/fingerprint reach staff via RPCs (`get_sheet_version`). diff --git a/.claude/memory/journal.md b/.claude/memory/journal.md index 55be8ef1..ffa5ac99 100644 --- a/.claude/memory/journal.md +++ b/.claude/memory/journal.md @@ -472,3 +472,6 @@ R5.4: `draft/{labels,changelog,review_report,drawing,overlay,app_review,svg_comp - Owner ratified AR-1 B (BDR-083). Contract §5.7 written: rule, chain, path inventory (2 RPCs, 2 private fns, service_role table grants F17, owner-count race F18), bootstrap, factor/password/recovery, session rules, deploy order (enrol before M4 on DEV), tests §15. - GoTrue v2.197.0 source read: enrol needs aal2 once verified factor, unenroll verified needs aal2. auth.sessions check kept as to-verify. - Docs only. Independent security review, then commit + push feature branch. STOP at checkpoint. + +## 2026-10-28 +- V1-2.1 M4/M5 built+tested on sandbox (DEV untouched): M4 20261028100000 sheet_access_hardening (rights table + RPCs, has_mfa/has_aal2_session, catalogue reader predicate, can_edit_sheet on capability, AR-1 B role RPCs + F17/F18/F19, F1-F16), M5 20261028110000 sheet_review_workflow (version/sheet cols, freeze/revision/author triggers, rounds/comments/acks, lifecycle+review+publish RPCs, species, working copy, uploads+INSERT policy, mirror removed + status check). Defects F1-F19 reproduced on old schema; pgTAP 001/003/004/005/006/007/010/015/016 green (850 real-stack, 122 PGlite); sandbox real-GoTrue AR-1 B + F18 race green; fresh install + M3->M5 upgrade green; sheets.ts closed kinds, client gate deleted, types regen no drift; rust:check + typecheck + lint + build green. 011 + SQL-mirror generator deleted, ledger retargeted. BDR + LRN-095. check:all Docker image/worker stages not re-run (no app/worker/Dockerfile change). STOP at checkpoint. diff --git a/.claude/memory/learnings.md b/.claude/memory/learnings.md index 264e4472..8768c2d7 100644 --- a/.claude/memory/learnings.md +++ b/.claude/memory/learnings.md @@ -651,3 +651,12 @@ Apply: SQL test touching a worker queue or shared bucket → neutralise or scope Context: V1-1 DEV acceptance RESP-01. Owner saw whole-page sideways scroll everywhere at 375 px (DevTools responsive). Sandbox sweep (Chromium mobile + desktop with scrollbars shown via `ignoreDefaultArgs: ['--hide-scrollbars']`, WebKit iPhone, Firefox; 280-430 px) found none at 375; owner then measured DEV with a console snippet (cw/sw + topmost offending boxes, classes only): no overflow without zoom → browser zoom was the cause. Same sweep with long account e-mails found a real defect: dashboard `grid gap-4 md:grid-cols-2` has no explicit column below md → implicit `auto` track = cards' min-content → `truncate` e-mail never truncates, cards past screen from ~31 chars at 320 px. Fix: `grid-cols-1` (minmax(0,1fr)) + e-mail wraps (`min-w-0 [overflow-wrap:anywhere]`). Test sweeps 320-430 + desktop with long values, proven failing on old code. Apply: overflow report → ask how observed (zoom, preset, device type), give owner a read-only console probe for DEV, reproduce with realistic max-length values on sandbox; a grid used as a single column on phones needs `grid-cols-1`, else one unbreakable value widens every card. + +## LRN-095 — pgTAP across PGlite and the real Supabase image: privileges, roles, storage triggers (2026-10-28) +Adapting pgTAP across PGlite and the real Supabase image: the fixtures must respect privileges the shim doesn't enforce. + +- `auth.sessions`/`auth.mfa_factors` added to the PGlite shim (`supabase-shim.sql`) with the pinned image's enums (`aal_level`, `factor_type`, `factor_status`) and NOT-NULL columns, so aal2-session checks run Dockerless. A test that checks a live-aal2 session fabricates the session + factor rows directly. +- API roles (`authenticated`, `service_role`, `anon`) hold no privilege on `auth.*`: every test mutation of `auth.users/sessions/mfa_factors` must run under `reset role` (postgres), never while `set local role authenticated`. Same for seeding `public.*` rows a trigger guards (the content trigger needs `auth.uid()` set, so direct version seeding carries a `request.jwt.claims` sub). +- Real-stack-only divergences: `storage.objects` has a storage-API trigger forbidding direct DELETE/UPDATE (PGlite allows it) — assert "no write policy" via `pg_policies` census, not a runtime throws_ok. PostgREST maps a `raise ... errcode='42501'` to HTTP 403 with code `42501` (not P0001). An EXECUTE-revoked function raises "permission denied for function" before its own body — test that, not the body's custom error. +- A narrow operator read RPC returning JSON `null` for "no row" is cleaner than raising (PostgREST won't surface a raise as a 404 the client recognises); the tool treats `null` as absent. +- Real GoTrue proves what fabricated rows can't: `pnpm db:sandbox test` enrol+verify TOTP → aal2 token, then the role RPC works at aal2 and is refused (mfa_required, 403) at aal1; F18 cross-revoke under real concurrency leaves one owner. diff --git a/.claude/tasks/TODO.md b/.claude/tasks/TODO.md index d64c7942..17821757 100644 --- a/.claude/tasks/TODO.md +++ b/.claude/tasks/TODO.md @@ -537,7 +537,14 @@ Order (BDR-071): P0 docs + decisions → V1-1 clients and animals → V1-2 sheet - [x] owner ratified O1-O23 (brief « V1-2.0 : ratification des arbitrages O1 à O23 et consolidation du contrat », 2026-10-28, BDR-082) - [ ] consolidation (docs only): contract rewritten (decisions §17, contradictions C1-C14 §19.2, steps §16 with 9 headings each); IMPLEMENTATION_PLAN §0 + Steps 13/17 notes, ANATOMICAL_SHEET_MODEL stale Zod/TS mentions + V1-2 pointer, OPEN_QUESTIONS conflicts 1-2, V1-1 §5.4 pointer (N1 amended), rule sheet-model, CLAUDE.md pointer; 3 fresh challengers (business CONCERNS 3 major, security FATAL 1 arbitration + 6 major, simplicity CONCERNS 5 major) integrated (contract §19.3); commit + push branch; STOP at checkpoint: owner final review, no V1-2.1 - [x] AR-1 ratified option B by the owner 2026-10-28 (BDR-083): `aal2` on every platform role change; contract §5.7 (rule, inventory, bootstrap, factors, recovery, sessions), F17-F19, M4 scope, tests §15, DEV order §16.11 (enrol before M4); docs only; independent security review then commit + push; no code, migration or DEV change - - [ ] V1-2.1 server access and workflow (M4, M5) · V1-2.2 core verdict, preview, change list, edit primitives, SVG cleaning · V1-2.3 drawings and worker verification (M6) · V1-2.4 wireframes (editor, review, admin entry) · V1-2.5 catalogue, admin space, rights, species, MFA · V1-2.6 editor level 1 · V1-2.7 preview, review, publication UI · V1-2.8 equine working copy and review preparation · V1-2.9 FR/EN acceptance and closure (owner checkpoints V1-2.3, V1-2.4, V1-2.6, V1-2.7, V1-2.8, V1-2.9 + each DEV operation of contract §16.11) + - [ ] V1-2.1 server access and workflow (M4, M5): owner go 2026-10-28 (brief « V1-2.1 : SQL, habilitations et cycle de vie »); sandbox only, DEV untouched; STOP at checkpoint (report §14). State 2026-10-28: BUILT + TESTED on sandbox, checkpoint report delivered, awaiting owner validation; BDR-084, LRN-095 + - [x] A prep: worktree deps; sandbox (old schema) service_role grants recorded (ALL on 7 tables → 0 after F12); F1-F17,F19 reproduced on old schema (repro_old.out), F18 two-session race + - [x] B M4 `20261028100000_sheet_access_hardening`: grants table + rights RPCs; has_mfa / has_aal2_session / grant_active / caller_has; catalogue reader predicate + policies; can_edit_sheet on capability (F14); AR-1 B role RPCs + private writers (F19), F17, F18 advisory lock; F1 F3 F5 F6 F8 F9 F12 F13 F15 F16; historical-sheet + asset triggers; fork/visibility/personal-create dropped; shim auth.sessions + auth.mfa_factors; pgTAP 015 + 001/003/004 adapted + - [x] C M5 `20261028110000_sheet_review_workflow`: version/sheet columns, version guards (content/revision/author, freeze, publish gate, deprecation), rounds/comments/acks, lifecycle + review + publish(review_id) RPCs, species RPCs, working copy, read RPCs, upload (register, confirm with storage check F7, INSERT policy, 2 MiB), operator read RPC, mirror dropped + `sheet_all_reviewed`, superseded signatures dropped; pgTAP 016 + 005/006/007 rewritten, 008/011 deleted, Rust generator trimmed + ledger retargeted + - [x] D packages/supabase `sheets.ts` (closed SheetFailure kinds), old `anatomical-sheets.ts` gate + test deleted, types regenerated (no drift), schema-types map updated; upload tool `row_state` on `get_sheet_asset_state` + - [x] E sandbox: real GoTrue MFA (totp.ts/mfa.ts helpers), aal1 refused / aal2 allowed on the role RPC, target-factor required, F18 cross-revoke leaves one owner; fresh install + M3→M5 upgrade green; V1-1 regression (65 sandbox tests) green + - [x] F gates: rust:check, wasm:build, typecheck, test:run (566 app + 122 supabase), lint, build, db:types:check, sandbox test-db (850) + test (65) all green; BDR-084 + LRN-095 + journal; commit + push. NOT done: fresh verifier + security gates (owner to run); at-caps timing (needs the V1-2.2 synthetic doc); fuller MFA factor-management matrix → V1-2.5; exhaustive two-session concurrency beyond F18; check:all Docker image/worker stages not re-run (no app/worker/Dockerfile change) + - [ ] V1-2.2 core verdict, preview, change list, edit primitives, SVG cleaning · V1-2.3 drawings and worker verification (M6) · V1-2.4 wireframes (editor, review, admin entry) · V1-2.5 catalogue, admin space, rights, species, MFA · V1-2.6 editor level 1 · V1-2.7 preview, review, publication UI · V1-2.8 equine working copy and review preparation · V1-2.9 FR/EN acceptance and closure (owner checkpoints V1-2.3, V1-2.4, V1-2.6, V1-2.7, V1-2.8, V1-2.9 + each DEV operation of contract §16.11) ## Release readiness track (owner 2026-10-25, distinct from the functional roadmap; nothing here authorises a release or exposure) Inventory: `.claude/audits/2026-10-25-functional-inventory.md`. Each item: treat or qualify before any release or public exposure; not fixed now unless an active critical flaw is shown. diff --git a/crates/core/src/bin/upload_sheet_assets/storage.rs b/crates/core/src/bin/upload_sheet_assets/storage.rs index f33178c5..77c045bc 100644 --- a/crates/core/src/bin/upload_sheet_assets/storage.rs +++ b/crates/core/src/bin/upload_sheet_assets/storage.rs @@ -156,21 +156,24 @@ impl Storage { Ok(true) } - /// The row of the asset: absent, another hash, pending or confirmed. + /// The row of the asset: absent, another hash, pending or confirmed. Since + /// V1-2.1 (M5, F12) the service role holds no table privilege, so this + /// reads the narrow operator RPC instead of the table. pub fn row_state(&self, entry: &AssetEntry) -> Result { - let url = format!( - "{}/rest/v1/anatomical_sheet_assets?id=eq.{}&select=sha256,uploaded_at", - self.origin, entry.svg_asset_id - ); - let reply = self.exchange(MAX_BODY, |agent, me| me.authorised(agent.get(&url)).call())?; + let url = format!("{}/rest/v1/rpc/get_sheet_asset_state", self.origin); + let body = json!({ "asset_id": entry.svg_asset_id }); + let reply = self.exchange(MAX_BODY, |agent, me| { + me.authorised(agent.post(&url)).send_json(&body) + })?; check_access(&reply)?; expect_status(&reply, 200, "row read")?; - let rows: Vec = serde_json::from_slice(&reply.body) - .map_err(|_| refuse(UploadKind::Handshake, "the row answer is not a JSON list"))?; - Ok(match rows.first() { - None => RowState::Unknown, - Some(row) => row_state_of(row, &entry.sha256), - }) + let row: Value = serde_json::from_slice(&reply.body) + .map_err(|_| refuse(UploadKind::Handshake, "the row answer is not JSON"))?; + // The RPC returns JSON null for an unknown asset (no row yet). + if row.is_null() { + return Ok(RowState::Unknown); + } + Ok(row_state_of(&row, &entry.sha256)) } /// Marks the asset bytes as present (idempotent on the server, service role only). diff --git a/crates/core/tests/curation/LEDGER.tsv b/crates/core/tests/curation/LEDGER.tsv index 180a7e4a..5f5050ae 100644 --- a/crates/core/tests/curation/LEDGER.tsv +++ b/crates/core/tests/curation/LEDGER.tsv @@ -334,33 +334,33 @@ packages/domain/tests/r2-characterisation.test.ts PdfLabelSetSchema > lists 25 d packages/domain/tests/r2-characterisation.test.ts PdfLabelSetSchema > rejects a missing key, an extra key, a long value, a missing locale R2 freeze: report and archive readers, rebase, snapshot verdicts ported cargo archive_rules::label_sets - same body re-registered by the import of archive.branding-labels.test in r2-characterisation.test.ts; missing, extra, 257 chars, no en, extra de (archive_rules.rs:145-158) packages/domain/tests/r2-characterisation.test.ts R2 characterisation oracles (frozen from the TypeScript domain) > characterisation.json: report, archive, rebase and snapshot functions R2 freeze: report and archive readers, rebase, snapshot verdicts replaced cargo characterisation::rust_does_what_the_typescript_did ; cargo characterisation::rust_does_what_the_typescript_did_with_the_integrity_rules ; cargo characterisation::lone_surrogates_are_refused_never_replaced crates/core/tests/oracles/characterisation.json TS (MAKE unset) recomputes the 85 cases and asserts the committed file byte for byte; Rust compares its outputs to the same file; generator side is TS-only packages/domain/tests/r2-characterisation.test.ts R2 characterisation oracles (frozen from the TypeScript domain) > verdicts.json: accept / refuse of the Zod schemas on hostile inputs R2 freeze: report and archive readers, rebase, snapshot verdicts replaced cargo characterisation::the_contracts_accept_and_refuse_what_zod_does crates/core/tests/oracles/verdicts.json TS (MAKE unset) recomputes the 765 Zod verdicts and asserts the committed file; Rust replays every verdict (1 L1 exception pinned) -packages/domain/tests/r2-conformance.test.ts sheet conformance fixtures > clean integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported ; cargo sheet_conformance::the_sql_expectations_are_the_mirrored_error_codes ; cargo sheet_conformance::the_pgtap_file_is_generated_from_the_fixtures crates/core/tests/conformance/clean.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 > view-main-count integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported ; cargo sheet_conformance::the_sql_expectations_are_the_mirrored_error_codes ; cargo sheet_conformance::the_pgtap_file_is_generated_from_the_fixtures crates/core/tests/conformance/view-main-count.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 > view-id-duplicate integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported ; cargo sheet_conformance::the_sql_expectations_are_the_mirrored_error_codes ; cargo sheet_conformance::the_pgtap_file_is_generated_from_the_fixtures crates/core/tests/conformance/view-id-duplicate.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 > view-parent-missing integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported ; cargo sheet_conformance::the_sql_expectations_are_the_mirrored_error_codes ; cargo sheet_conformance::the_pgtap_file_is_generated_from_the_fixtures crates/core/tests/conformance/view-parent-missing.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 > view-parent-cycle integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported ; cargo sheet_conformance::the_sql_expectations_are_the_mirrored_error_codes ; cargo sheet_conformance::the_pgtap_file_is_generated_from_the_fixtures crates/core/tests/conformance/view-parent-cycle.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 > view-unreachable integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported ; cargo sheet_conformance::the_sql_expectations_are_the_mirrored_error_codes ; cargo sheet_conformance::the_pgtap_file_is_generated_from_the_fixtures crates/core/tests/conformance/view-unreachable.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 > view-asset-missing-main integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported ; cargo sheet_conformance::the_sql_expectations_are_the_mirrored_error_codes ; cargo sheet_conformance::the_pgtap_file_is_generated_from_the_fixtures crates/core/tests/conformance/view-asset-missing-main.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 > view-asset-missing-detail integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported ; cargo sheet_conformance::the_sql_expectations_are_the_mirrored_error_codes ; cargo sheet_conformance::the_pgtap_file_is_generated_from_the_fixtures crates/core/tests/conformance/view-asset-missing-detail.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 > annotation-id-duplicate integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported ; cargo sheet_conformance::the_sql_expectations_are_the_mirrored_error_codes ; cargo sheet_conformance::the_pgtap_file_is_generated_from_the_fixtures crates/core/tests/conformance/annotation-id-duplicate.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 > annotation-view-missing integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported ; cargo sheet_conformance::the_sql_expectations_are_the_mirrored_error_codes ; cargo sheet_conformance::the_pgtap_file_is_generated_from_the_fixtures crates/core/tests/conformance/annotation-view-missing.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 > annotation-category-missing integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported ; cargo sheet_conformance::the_sql_expectations_are_the_mirrored_error_codes ; cargo sheet_conformance::the_pgtap_file_is_generated_from_the_fixtures crates/core/tests/conformance/annotation-category-missing.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 > annotation-opens-view-invalid integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported ; cargo sheet_conformance::the_sql_expectations_are_the_mirrored_error_codes ; cargo sheet_conformance::the_pgtap_file_is_generated_from_the_fixtures crates/core/tests/conformance/annotation-opens-view-invalid.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 > annotation-finding-zone-missing integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported ; cargo sheet_conformance::the_sql_expectations_are_the_mirrored_error_codes ; cargo sheet_conformance::the_pgtap_file_is_generated_from_the_fixtures crates/core/tests/conformance/annotation-finding-zone-missing.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 > annotation-region-missing integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported ; cargo sheet_conformance::the_sql_expectations_are_the_mirrored_error_codes ; cargo sheet_conformance::the_pgtap_file_is_generated_from_the_fixtures crates/core/tests/conformance/annotation-region-missing.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 > annotation-no-findings integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported ; cargo sheet_conformance::the_sql_expectations_are_the_mirrored_error_codes ; cargo sheet_conformance::the_pgtap_file_is_generated_from_the_fixtures crates/core/tests/conformance/annotation-no-findings.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 > region-code-duplicate integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported ; cargo sheet_conformance::the_sql_expectations_are_the_mirrored_error_codes ; cargo sheet_conformance::the_pgtap_file_is_generated_from_the_fixtures crates/core/tests/conformance/region-code-duplicate.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 > category-id-duplicate integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported ; cargo sheet_conformance::the_sql_expectations_are_the_mirrored_error_codes ; cargo sheet_conformance::the_pgtap_file_is_generated_from_the_fixtures crates/core/tests/conformance/category-id-duplicate.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 > finding-zone-id-duplicate integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported ; cargo sheet_conformance::the_sql_expectations_are_the_mirrored_error_codes ; cargo sheet_conformance::the_pgtap_file_is_generated_from_the_fixtures crates/core/tests/conformance/finding-zone-id-duplicate.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 > finding-id-duplicate integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported ; cargo sheet_conformance::the_sql_expectations_are_the_mirrored_error_codes ; cargo sheet_conformance::the_pgtap_file_is_generated_from_the_fixtures crates/core/tests/conformance/finding-id-duplicate.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 > reference-id-duplicate integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported ; cargo sheet_conformance::the_sql_expectations_are_the_mirrored_error_codes ; cargo sheet_conformance::the_pgtap_file_is_generated_from_the_fixtures crates/core/tests/conformance/reference-id-duplicate.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 > finding-reference-missing integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported ; cargo sheet_conformance::the_sql_expectations_are_the_mirrored_error_codes ; cargo sheet_conformance::the_pgtap_file_is_generated_from_the_fixtures crates/core/tests/conformance/finding-reference-missing.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 > region-count-range-invalid integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported ; cargo sheet_conformance::the_sql_expectations_are_the_mirrored_error_codes ; cargo sheet_conformance::the_pgtap_file_is_generated_from_the_fixtures crates/core/tests/conformance/region-count-range-invalid.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 > finding-zone-unreferenced integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported ; cargo sheet_conformance::the_sql_expectations_are_the_mirrored_error_codes ; cargo sheet_conformance::the_pgtap_file_is_generated_from_the_fixtures crates/core/tests/conformance/finding-zone-unreferenced.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 > several-errors integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported ; cargo sheet_conformance::the_sql_expectations_are_the_mirrored_error_codes ; cargo sheet_conformance::the_pgtap_file_is_generated_from_the_fixtures 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 ; cargo sheet_conformance::the_sql_expectations_are_the_mirrored_error_codes ; cargo sheet_conformance::the_pgtap_file_is_generated_from_the_fixtures 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 ; cargo sheet_conformance::the_sql_expectations_are_the_mirrored_error_codes ; cargo sheet_conformance::the_pgtap_file_is_generated_from_the_fixtures 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_pgtap_file_is_generated_from_the_fixtures 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 > clean integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported crates/core/tests/conformance/clean.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 > view-main-count integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported crates/core/tests/conformance/view-main-count.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 > view-id-duplicate integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported crates/core/tests/conformance/view-id-duplicate.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 > view-parent-missing integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported crates/core/tests/conformance/view-parent-missing.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 > view-parent-cycle integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported crates/core/tests/conformance/view-parent-cycle.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 > view-unreachable integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported crates/core/tests/conformance/view-unreachable.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 > view-asset-missing-main integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported crates/core/tests/conformance/view-asset-missing-main.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 > view-asset-missing-detail integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported crates/core/tests/conformance/view-asset-missing-detail.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 > annotation-id-duplicate integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported crates/core/tests/conformance/annotation-id-duplicate.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 > annotation-view-missing integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported crates/core/tests/conformance/annotation-view-missing.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 > annotation-category-missing integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported crates/core/tests/conformance/annotation-category-missing.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 > annotation-opens-view-invalid integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported crates/core/tests/conformance/annotation-opens-view-invalid.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 > annotation-finding-zone-missing integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported crates/core/tests/conformance/annotation-finding-zone-missing.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 > annotation-region-missing integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported crates/core/tests/conformance/annotation-region-missing.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 > annotation-no-findings integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported crates/core/tests/conformance/annotation-no-findings.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 > region-code-duplicate integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported crates/core/tests/conformance/region-code-duplicate.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 > category-id-duplicate integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported crates/core/tests/conformance/category-id-duplicate.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 > finding-zone-id-duplicate integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported crates/core/tests/conformance/finding-zone-id-duplicate.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 > finding-id-duplicate integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported crates/core/tests/conformance/finding-id-duplicate.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 > reference-id-duplicate integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported crates/core/tests/conformance/reference-id-duplicate.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 > finding-reference-missing integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported crates/core/tests/conformance/finding-reference-missing.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 > region-count-range-invalid integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported crates/core/tests/conformance/region-count-range-invalid.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 > finding-zone-unreferenced integrity codes shared with SQL (pgTAP conformance) replaced cargo sheet_conformance::the_rust_rules_report_what_the_typescript_rules_reported crates/core/tests/conformance/finding-zone-unreferenced.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 > 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-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/crates/core/tests/sheet_conformance.rs b/crates/core/tests/sheet_conformance.rs index 42782288..a5fab210 100644 --- a/crates/core/tests/sheet_conformance.rs +++ b/crates/core/tests/sheet_conformance.rs @@ -1,43 +1,22 @@ -//! Conformance of the integrity rules across the three implementations (review III.4): -//! the fixtures under `tests/conformance` carry what the TypeScript rules reported (frozen by -//! `packages/domain/tests/r2-conformance.test.ts`) and the codes the SQL re-check returns. -//! This suite checks the Rust rules against the first and generates the pgTAP file that checks -//! SQL against the second (`supabase/tests/011_sheet_conformance.sql`, never edited by hand: -//! `FAUNOSTEO_WRITE_CONFORMANCE=1 cargo test -p faunosteo-core --test sheet_conformance`). +//! Conformance of the integrity rules (review III.4): the fixtures under +//! `tests/conformance` carry what the TypeScript rules reported (frozen by +//! `packages/domain/tests/r2-conformance.test.ts`). This suite checks the Rust +//! rules against them. +//! +//! V1-2.1 (M5) removed the SQL business mirror (`private.sheet_document_*`): SQL +//! no longer re-checks the document's business rules, the Rust core is the only +//! authority (contract §12.2). The former `the_sql_expectations…` and +//! `the_pgtap_file_is_generated…` tests and the generated +//! `supabase/tests/011_sheet_conformance.sql` went with it; the fixtures' `sql` +//! key is left in place, unused. #![allow(clippy::disallowed_methods, clippy::unwrap_used, clippy::expect_used)] mod common; -use std::collections::BTreeSet; - use faunosteo_core::domain::js::parse_json; -use faunosteo_core::domain::sheet::{SheetIssueSeverity, check_sheet_document}; +use faunosteo_core::domain::sheet::check_sheet_document; use serde_json::Value; -const SQL_FILE: &str = "supabase/tests/011_sheet_conformance.sql"; -const TAG: &str = "$fixture$"; - -/// The error codes `private.sheet_document_issues` mirrors (codes only, deduplicated). -const MIRRORED: [&str; 17] = [ - "view.main.count", - "view.id.duplicate", - "view.parent.missing", - "view.unreachable", - "view.asset.missing", - "annotation.id.duplicate", - "annotation.view.missing", - "annotation.category.missing", - "annotation.opens_view.invalid", - "annotation.finding_zone.missing", - "annotation.region.missing", - "region.code.duplicate", - "category.id.duplicate", - "finding_zone.id.duplicate", - "reference.id.duplicate", - "finding.reference.missing", - "region.count_range.invalid", -]; - fn fixtures() -> Vec<(String, Value)> { let dir = format!("{}/tests/conformance", env!("CARGO_MANIFEST_DIR")); let mut names: Vec = std::fs::read_dir(&dir) @@ -55,14 +34,6 @@ fn fixtures() -> Vec<(String, Value)> { .collect() } -fn sql_codes(fixture: &Value) -> Vec { - let codes = fixture["sql"].as_array().unwrap(); - codes - .iter() - .map(|c| c.as_str().unwrap().to_owned()) - .collect() -} - #[test] fn the_rust_rules_report_what_the_typescript_rules_reported() { let all = fixtures(); @@ -78,74 +49,3 @@ fn the_rust_rules_report_what_the_typescript_rules_reported() { assert_eq!(issues, fixture["rust"]["issues"], "{name}"); } } - -#[test] -fn the_sql_expectations_are_the_mirrored_error_codes() { - for (name, fixture) in fixtures() { - if fixture["rust"]["shape_error"] == Value::Bool(true) { - continue; - } - let check = check_sheet_document(fixture["document"].clone()).unwrap(); - let mirrored: BTreeSet = check - .issues - .iter() - .filter(|i| i.severity == SheetIssueSeverity::Error) - .filter(|i| MIRRORED.contains(&i.code.as_str())) - .map(|i| i.code.clone()) - .collect(); - let expected: Vec = mirrored.into_iter().collect(); - assert_eq!(sql_codes(&fixture), expected, "{name}"); - } -} - -fn sql_literal(codes: &[String]) -> String { - format!("'{{{}}}'::text[]", codes.join(",")) -} - -fn assertion(name: &str, fixture: &Value) -> String { - let document = serde_json::to_string(&fixture["document"]).unwrap(); - assert!( - !document.contains(TAG), - "{name}: dollar-quote tag in the document" - ); - let description = fixture["description"].as_str().unwrap().replace('\'', "''"); - let stem = name.trim_end_matches(".json"); - format!( - "select is(\n array(select c from unnest(private.sheet_document_issues({TAG}{document}{TAG}::jsonb)) as c order by c collate \"C\"),\n {},\n 'conformance {stem}: {description}'\n);\n", - sql_literal(&sql_codes(fixture)) - ) -} - -fn generated_sql() -> String { - let all = fixtures(); - let mut out = String::from( - "-- GENERATED from crates/core/tests/conformance/*.json by crates/core/tests/sheet_conformance.rs:\n\ - -- FAUNOSTEO_WRITE_CONFORMANCE=1 cargo test -p faunosteo-core --test sheet_conformance\n\ - -- Never edited by hand: cargo fails when this file differs from the fixtures.\n\ - -- The SQL publication re-check returns, for each fixture, the error codes the Rust\n\ - -- integrity rules report that SQL mirrors (codes only, sorted), plus its own\n\ - -- document.shape and reference.url.scheme on documents the shape tier refuses.\n\ - begin;\n", - ); - out.push_str(&format!("select plan({});\n\n", all.len())); - for (name, fixture) in &all { - out.push_str(&assertion(name, fixture)); - out.push('\n'); - } - out.push_str("select * from finish();\nrollback;\n"); - out -} - -#[test] -fn the_pgtap_file_is_generated_from_the_fixtures() { - let expected = generated_sql(); - let path = format!("{}/../../{SQL_FILE}", env!("CARGO_MANIFEST_DIR")); - if std::env::var("FAUNOSTEO_WRITE_CONFORMANCE").as_deref() == Ok("1") { - std::fs::write(&path, &expected).unwrap(); - } - let committed = std::fs::read_to_string(&path).unwrap_or_default(); - assert!( - committed == expected, - "{SQL_FILE} differs from the fixtures: regenerate it (FAUNOSTEO_WRITE_CONFORMANCE=1)" - ); -} diff --git a/crates/core/tests/upload_tool.rs b/crates/core/tests/upload_tool.rs index 75c9393e..08fe0c4b 100644 --- a/crates/core/tests/upload_tool.rs +++ b/crates/core/tests/upload_tool.rs @@ -89,19 +89,21 @@ fn route(state: &mut State, method: &str, path: &str, body: Vec) -> (u16, Ve state.objects.insert(key.to_owned(), body); (200, b"{}".to_vec()) } - ("GET", None) if path.starts_with("/rest/v1/anatomical_sheet_assets") => { - let rows = match &state.row { - None => "[]".to_owned(), + ("POST", None) if path.ends_with("/rpc/get_sheet_asset_state") => { + // The operator read RPC (V1-2.1 F12): JSON null when no row exists, + // else an object with sha256 and uploaded_at. + let reply = match &state.row { + None => "null".to_owned(), Some((sha, confirmed)) => { let at = if *confirmed { "\"2026-10-23T00:00:00Z\"" } else { "null" }; - format!("[{{\"sha256\":\"{sha}\",\"uploaded_at\":{at}}}]") + format!("{{\"sha256\":\"{sha}\",\"uploaded_at\":{at}}}") } }; - (200, rows.into_bytes()) + (200, reply.into_bytes()) } ("POST", None) if path.ends_with("/rpc/confirm_sheet_asset_upload") => { if state.fail_confirm { @@ -168,7 +170,10 @@ fn text(output: &Output) -> String { fn writes(state: &Shared) -> usize { let log = &state.lock().unwrap().log; - log.iter().filter(|line| line.starts_with("POST")).count() + // The asset-state RPC is a POST but a read: it never counts as a write. + log.iter() + .filter(|line| line.starts_with("POST") && !line.contains("/rpc/get_sheet_asset_state")) + .count() } #[test] diff --git a/packages/supabase/src/anatomical-sheets.ts b/packages/supabase/src/anatomical-sheets.ts deleted file mode 100644 index a516e808..00000000 --- a/packages/supabase/src/anatomical-sheets.ts +++ /dev/null @@ -1,105 +0,0 @@ -import type { FaunosteoClient } from './client' - -/** - * Publication gate on the client side: the full shape and every integrity - * rule run before the RPC, so the editor gets the complete issue list. The - * rules run in the Rust core (R2): the caller passes its `sheet.check` - * operation, so this package never loads the module itself. The gate fails - * closed: anything but a publishable verdict refuses publication. The - * database re-checks the referential rules on its own - * (private.sheet_document_issues); this call never replaces that guard. - */ - -export interface SheetIssue { - code: string - severity: 'error' | 'warning' - path: string - message: string -} - -/** The core's verdict on a document (`sheet.check`), or why it could not give one. */ -export type SheetCheckOutcome = - | { ok: true; value: { issues: SheetIssue[]; publishable: boolean } } - | { ok: false; kind: string; detail?: string } - -export type SheetValidator = (content: unknown) => SheetCheckOutcome - -export type SheetPublishErrorKind = - /** - * The document does not match the strict schema, or carries a text the core cannot read - * without altering it (`lone_surrogate`). - */ - | 'invalid_shape' - /** Integrity errors (warnings never block). */ - | 'not_publishable' - /** The validator could not run (core unavailable, trap): publication refused. */ - | 'validator_unavailable' - -export class SheetPublishError extends Error { - constructor( - readonly kind: SheetPublishErrorKind, - readonly issues: SheetIssue[] = [], - detail = '', - ) { - super(SheetPublishError.messageOf(kind, issues, detail)) - this.name = 'SheetPublishError' - } - - private static messageOf( - kind: SheetPublishErrorKind, - issues: SheetIssue[], - detail: string, - ): string { - if (kind === 'not_publishable') { - const errors = issues.filter((issue) => issue.severity === 'error') - return ( - `Sheet document is not publishable: ${errors.length} error(s), ` + - `first: ${errors[0]?.code ?? 'none'}` - ) - } - if (kind === 'invalid_shape') { - return `Sheet document does not match the schema${detail ? `: ${detail}` : ''}` - } - return `Sheet validator unavailable${detail ? ` (${detail})` : ''}` - } -} - -/** The validator's kinds that judge the document itself, not the validator's state. */ -const CONTENT_KINDS: ReadonlySet = new Set([ - 'invalid_shape', - 'lone_surrogate', -]) - -/** Throws unless the validator says the document is publishable. */ -function assertPublishable(validate: SheetValidator, content: unknown): void { - const check = validate(content) - if (!check.ok) { - throw CONTENT_KINDS.has(check.kind) - ? new SheetPublishError('invalid_shape', [], check.detail) - : new SheetPublishError('validator_unavailable', [], check.kind) - } - if (!check.value.publishable) { - throw new SheetPublishError('not_publishable', check.value.issues) - } -} - -export async function publishSheetVersion( - client: FaunosteoClient, - versionId: string, - validate: SheetValidator, -): Promise { - const draft = await client - .from('anatomical_sheet_versions') - .select('content') - .eq('id', versionId) - .single() - if (draft.error) throw draft.error - - assertPublishable(validate, draft.data.content) - - const published = await client.rpc('publish_sheet_version', { - version_id: versionId, - }) - if (published.error) throw published.error - return published.data -} diff --git a/packages/supabase/src/database.types.ts b/packages/supabase/src/database.types.ts index 0a063c59..4cd5a54c 100644 --- a/packages/supabase/src/database.types.ts +++ b/packages/supabase/src/database.types.ts @@ -9,6 +9,71 @@ export type Json = export type Database = { public: { Tables: { + anatomical_catalog_grants: { + Row: { + expires_at: string | null + grant_kind: Database['public']['Enums']['catalog_grant_kind'] + granted_at: string + granted_by: string + id: string + reason: string + revocation_reason: string | null + revoked_at: string | null + revoked_by: string | null + user_id: string + verification_note: string | null + } + ComputedFields: never + Insert: { + expires_at?: string | null + grant_kind: Database['public']['Enums']['catalog_grant_kind'] + granted_at?: string + granted_by: string + id?: string + reason: string + revocation_reason?: string | null + revoked_at?: string | null + revoked_by?: string | null + user_id: string + verification_note?: string | null + } + Update: { + expires_at?: string | null + grant_kind?: Database['public']['Enums']['catalog_grant_kind'] + granted_at?: string + granted_by?: string + id?: string + reason?: string + revocation_reason?: string | null + revoked_at?: string | null + revoked_by?: string | null + user_id?: string + verification_note?: string | null + } + Relationships: [ + { + foreignKeyName: 'anatomical_catalog_grants_granted_by_fkey' + columns: ['granted_by'] + isOneToOne: false + referencedRelation: 'profiles' + referencedColumns: ['id'] + }, + { + foreignKeyName: 'anatomical_catalog_grants_revoked_by_fkey' + columns: ['revoked_by'] + isOneToOne: false + referencedRelation: 'profiles' + referencedColumns: ['id'] + }, + { + foreignKeyName: 'anatomical_catalog_grants_user_id_fkey' + columns: ['user_id'] + isOneToOne: false + referencedRelation: 'profiles' + referencedColumns: ['id'] + }, + ] + } anatomical_sheet_assets: { Row: { byte_size: number @@ -61,52 +126,270 @@ export type Database = { }, ] } + anatomical_sheet_review_acknowledgments: { + Row: { + created_at: string + group_digest: string + group_key: string + id: string + review_id: string + reviewer: string + } + ComputedFields: never + Insert: { + created_at?: string + group_digest: string + group_key: string + id?: string + review_id: string + reviewer: string + } + Update: { + created_at?: string + group_digest?: string + group_key?: string + id?: string + review_id?: string + reviewer?: string + } + Relationships: [ + { + foreignKeyName: 'anatomical_sheet_review_acknowledgments_review_id_fkey' + columns: ['review_id'] + isOneToOne: false + referencedRelation: 'anatomical_sheet_reviews' + referencedColumns: ['id'] + }, + { + foreignKeyName: 'anatomical_sheet_review_acknowledgments_reviewer_fkey' + columns: ['reviewer'] + isOneToOne: false + referencedRelation: 'profiles' + referencedColumns: ['id'] + }, + ] + } + anatomical_sheet_review_comments: { + Row: { + author: string + body: string + created_at: string + group_key: string | null + id: string + review_id: string + } + ComputedFields: never + Insert: { + author: string + body: string + created_at?: string + group_key?: string | null + id?: string + review_id: string + } + Update: { + author?: string + body?: string + created_at?: string + group_key?: string | null + id?: string + review_id?: string + } + Relationships: [ + { + foreignKeyName: 'anatomical_sheet_review_comments_author_fkey' + columns: ['author'] + isOneToOne: false + referencedRelation: 'profiles' + referencedColumns: ['id'] + }, + { + foreignKeyName: 'anatomical_sheet_review_comments_review_id_fkey' + columns: ['review_id'] + isOneToOne: false + referencedRelation: 'anatomical_sheet_reviews' + referencedColumns: ['id'] + }, + ] + } + anatomical_sheet_reviews: { + Row: { + attempts: number + authors: string[] + created_at: string + decided_at: string | null + decided_by: string | null + decision_note: string | null + failure_code: string | null + failure_outcome: + | Database['public']['Enums']['sheet_verification_outcome'] + | null + id: string + lease_token: string | null + locked_at: string | null + revision: number + round: number + status: Database['public']['Enums']['sheet_round_status'] + submission_note: string | null + submitted_at: string + submitted_by: string + verdict: Json | null + verified_at: string | null + verified_with: string | null + version_id: string + withdrawal_note: string | null + withdrawn_at: string | null + withdrawn_by: string | null + } + ComputedFields: never + Insert: { + attempts?: number + authors: string[] + created_at?: string + decided_at?: string | null + decided_by?: string | null + decision_note?: string | null + failure_code?: string | null + failure_outcome?: + | Database['public']['Enums']['sheet_verification_outcome'] + | null + id?: string + lease_token?: string | null + locked_at?: string | null + revision: number + round: number + status?: Database['public']['Enums']['sheet_round_status'] + submission_note?: string | null + submitted_at?: string + submitted_by: string + verdict?: Json | null + verified_at?: string | null + verified_with?: string | null + version_id: string + withdrawal_note?: string | null + withdrawn_at?: string | null + withdrawn_by?: string | null + } + Update: { + attempts?: number + authors?: string[] + created_at?: string + decided_at?: string | null + decided_by?: string | null + decision_note?: string | null + failure_code?: string | null + failure_outcome?: + | Database['public']['Enums']['sheet_verification_outcome'] + | null + id?: string + lease_token?: string | null + locked_at?: string | null + revision?: number + round?: number + status?: Database['public']['Enums']['sheet_round_status'] + submission_note?: string | null + submitted_at?: string + submitted_by?: string + verdict?: Json | null + verified_at?: string | null + verified_with?: string | null + version_id?: string + withdrawal_note?: string | null + withdrawn_at?: string | null + withdrawn_by?: string | null + } + Relationships: [ + { + foreignKeyName: 'anatomical_sheet_reviews_decided_by_fkey' + columns: ['decided_by'] + isOneToOne: false + referencedRelation: 'profiles' + referencedColumns: ['id'] + }, + { + foreignKeyName: 'anatomical_sheet_reviews_submitted_by_fkey' + columns: ['submitted_by'] + isOneToOne: false + referencedRelation: 'profiles' + referencedColumns: ['id'] + }, + { + foreignKeyName: 'anatomical_sheet_reviews_version_id_fkey' + columns: ['version_id'] + isOneToOne: false + referencedRelation: 'anatomical_sheet_versions' + referencedColumns: ['id'] + }, + { + foreignKeyName: 'anatomical_sheet_reviews_withdrawn_by_fkey' + columns: ['withdrawn_by'] + isOneToOne: false + referencedRelation: 'profiles' + referencedColumns: ['id'] + }, + ] + } anatomical_sheet_versions: { Row: { + authors: string[] change_note: string content: NonNullable created_at: string created_by: string | null deprecated_at: string | null deprecated_by: string | null + document_fingerprint: string | null document_schema_version: number id: string published_at: string | null published_by: string | null + published_review_id: string | null + revision: number sheet_id: string + source_version_id: string | null status: Database['public']['Enums']['sheet_version_status'] updated_at: string version_number: number } ComputedFields: never Insert: { + authors?: string[] change_note?: string content: NonNullable created_at?: string created_by?: string | null deprecated_at?: string | null deprecated_by?: string | null + document_fingerprint?: string | null document_schema_version: number id?: string published_at?: string | null published_by?: string | null + published_review_id?: string | null + revision?: number sheet_id: string + source_version_id?: string | null status?: Database['public']['Enums']['sheet_version_status'] updated_at?: string version_number: number } Update: { + authors?: string[] change_note?: string content?: NonNullable created_at?: string created_by?: string | null deprecated_at?: string | null deprecated_by?: string | null + document_fingerprint?: string | null document_schema_version?: number id?: string published_at?: string | null published_by?: string | null + published_review_id?: string | null + revision?: number sheet_id?: string + source_version_id?: string | null status?: Database['public']['Enums']['sheet_version_status'] updated_at?: string version_number?: number @@ -133,6 +416,13 @@ export type Database = { referencedRelation: 'profiles' referencedColumns: ['id'] }, + { + foreignKeyName: 'anatomical_sheet_versions_published_review_fkey' + columns: ['published_review_id'] + isOneToOne: false + referencedRelation: 'anatomical_sheet_reviews' + referencedColumns: ['id'] + }, { foreignKeyName: 'anatomical_sheet_versions_sheet_id_fkey' columns: ['sheet_id'] @@ -140,6 +430,13 @@ export type Database = { referencedRelation: 'anatomical_sheets' referencedColumns: ['id'] }, + { + foreignKeyName: 'anatomical_sheet_versions_source_version_id_fkey' + columns: ['source_version_id'] + isOneToOne: false + referencedRelation: 'anatomical_sheet_versions' + referencedColumns: ['id'] + }, ] } anatomical_sheets: { @@ -161,6 +458,7 @@ export type Database = { status: Database['public']['Enums']['sheet_status'] updated_at: string visibility: Database['public']['Enums']['sheet_visibility'] + working_copy_source_version_id: string | null } ComputedFields: never Insert: { @@ -181,6 +479,7 @@ export type Database = { status?: Database['public']['Enums']['sheet_status'] updated_at?: string visibility?: Database['public']['Enums']['sheet_visibility'] + working_copy_source_version_id?: string | null } Update: { archived_at?: string | null @@ -200,6 +499,7 @@ export type Database = { status?: Database['public']['Enums']['sheet_status'] updated_at?: string visibility?: Database['public']['Enums']['sheet_visibility'] + working_copy_source_version_id?: string | null } Relationships: [ { @@ -237,6 +537,13 @@ export type Database = { referencedRelation: 'species' referencedColumns: ['id'] }, + { + foreignKeyName: 'anatomical_sheets_working_copy_source_version_id_fkey' + columns: ['working_copy_source_version_id'] + isOneToOne: false + referencedRelation: 'anatomical_sheet_versions' + referencedColumns: ['id'] + }, ] } animal_client_relations: { @@ -738,6 +1045,11 @@ export type Database = { } Functions: { ack_purge: { Args: { purge_id: string }; Returns: undefined } + acknowledge_sheet_review_group: { + Args: { group_digest: string; group_key: string; review_id: string } + Returns: string + } + activate_species: { Args: { id: string }; Returns: string } archive_anatomical_sheet: { Args: { sheet_id: string }; Returns: string } begin_avatar_upload: { Args: { declared_mime: string; declared_size: number } @@ -772,6 +1084,10 @@ export type Database = { }[] } client_archive_preview: { Args: { client_id: string }; Returns: Json } + comment_sheet_review: { + Args: { body: string; group_key?: string; review_id: string } + Returns: string + } complete_avatar_job: { Args: { asset_id: string @@ -786,18 +1102,6 @@ export type Database = { Args: { asset_id: string } Returns: string } - create_anatomical_sheet: { - Args: { - description?: string - document: Json - name: string - official?: boolean - slug: string - species_id: string - visibility?: Database['public']['Enums']['sheet_visibility'] - } - Returns: string - } create_animal: { Args: { birth_date?: string @@ -841,6 +1145,10 @@ export type Database = { } Returns: Json } + create_official_sheet: { + Args: { document: Json; slug: string } + Returns: string + } create_sheet_draft: { Args: { change_note?: string @@ -849,6 +1157,23 @@ export type Database = { } Returns: string } + create_sheet_working_copy: { + Args: { slug: string; source_version_id: string } + Returns: string + } + create_species: { + Args: { + id: string + name_en: string + name_fr: string + sort_order?: number + } + Returns: string + } + decide_sheet_review: { + Args: { approve: boolean; note: string; review_id: string } + Returns: string + } delete_anatomical_sheet: { Args: { sheet_id: string }; Returns: string } delete_sheet_asset: { Args: { asset_id: string }; Returns: string } delete_sheet_version: { Args: { version_id: string }; Returns: string } @@ -868,12 +1193,15 @@ export type Database = { Args: { max_age_seconds: number } Returns: number } - fork_anatomical_sheet: { + get_sheet_asset_state: { Args: { asset_id: string }; Returns: Json } + get_sheet_version: { Args: { version_id: string }; Returns: Json } + grant_catalog_right: { Args: { - name: string - slug: string - source_version_id: string - visibility?: Database['public']['Enums']['sheet_visibility'] + expires_at?: string + kind: Database['public']['Enums']['catalog_grant_kind'] + reason: string + user_id: string + verification_note?: string } Returns: string } @@ -884,6 +1212,8 @@ export type Database = { } Returns: string } + list_catalog_grants: { Args: Record; Returns: Json } + list_catalog_species: { Args: Record; Returns: Json } list_client_animals: { Args: { after_id?: string @@ -909,8 +1239,10 @@ export type Database = { started_on: string }[] } + list_official_catalog: { Args: Record; Returns: Json } + lookup_catalog_account: { Args: { email: string }; Returns: Json } mark_quarantine_purged: { Args: { asset_id: string }; Returns: undefined } - publish_sheet_version: { Args: { version_id: string }; Returns: string } + publish_sheet_version: { Args: { review_id: string }; Returns: string } register_sheet_asset: { Args: { byte_size: number @@ -925,7 +1257,15 @@ export type Database = { Returns: undefined } remove_avatar: { Args: Record; Returns: number } + rename_species: { + Args: { id: string; name_en: string; name_fr: string } + Returns: string + } restore_anatomical_sheet: { Args: { sheet_id: string }; Returns: string } + revoke_catalog_right: { + Args: { grant_id: string; reason: string } + Returns: string + } revoke_platform_role: { Args: { reason?: string @@ -934,6 +1274,15 @@ export type Database = { } Returns: string } + save_sheet_draft: { + Args: { + change_note?: string + document: Json + expected_revision: number + version_id: string + } + Returns: Json + } search_animals: { Args: { after_id?: string @@ -987,11 +1336,8 @@ export type Database = { Args: { archived: boolean; client_id: string } Returns: Json } - set_sheet_visibility: { - Args: { - sheet_id: string - visibility: Database['public']['Enums']['sheet_visibility'] - } + submit_sheet_review: { + Args: { expected_revision: number; note?: string; version_id: string } Returns: string } update_animal: { @@ -1033,10 +1379,23 @@ export type Database = { } Returns: Json } + update_inactive_species: { + Args: { + id: string + name_en: string + name_fr: string + sort_order: number + } + Returns: string + } void_animal_client_relation: { Args: { expected_revision: number; relation_id: string } Returns: Json } + withdraw_sheet_review: { + Args: { note?: string; review_id: string } + Returns: string + } } Enums: { animal_relation_role: 'owner' | 'keeper' | 'contact' @@ -1047,9 +1406,22 @@ export type Database = { | 'clean' | 'rejected' | 'deleted' + catalog_grant_kind: + | 'catalog_reader' + | 'sheet_editor' + | 'sheet_reviewer' + | 'sheet_publisher' client_kind: 'person' | 'organization' platform_role: 'owner' | 'admin' | 'moderator' | 'support' + sheet_round_status: + | 'verifying' + | 'open' + | 'approved' + | 'changes_requested' + | 'withdrawn' + | 'verification_failed' sheet_status: 'active' | 'archived' | 'deleted' + sheet_verification_outcome: 'failed' | 'unavailable' sheet_version_status: 'draft' | 'published' | 'deprecated' sheet_visibility: 'private' | 'public' workspace_kind: 'personal' @@ -1190,9 +1562,24 @@ export const Constants = { 'rejected', 'deleted', ], + catalog_grant_kind: [ + 'catalog_reader', + 'sheet_editor', + 'sheet_reviewer', + 'sheet_publisher', + ], client_kind: ['person', 'organization'], platform_role: ['owner', 'admin', 'moderator', 'support'], + sheet_round_status: [ + 'verifying', + 'open', + 'approved', + 'changes_requested', + 'withdrawn', + 'verification_failed', + ], sheet_status: ['active', 'archived', 'deleted'], + sheet_verification_outcome: ['failed', 'unavailable'], sheet_version_status: ['draft', 'published', 'deprecated'], sheet_visibility: ['private', 'public'], workspace_kind: ['personal'], diff --git a/packages/supabase/src/index.ts b/packages/supabase/src/index.ts index 7c0cc634..ae5a649e 100644 --- a/packages/supabase/src/index.ts +++ b/packages/supabase/src/index.ts @@ -44,13 +44,22 @@ export { /** owner | admin | moderator | support. Not a professional status. */ export { fetchOwnPlatformRoles, type PlatformRole } from './platform-roles' export { + SHEET_FAILURE_KINDS, + SheetFailure, + classifySheetError, + failSheet, + grantCatalogRight, + revokeCatalogRight, + listCatalogGrants, + createOfficialSheet, + saveSheetDraft, + submitSheetReview, + decideSheetReview, publishSheetVersion, - SheetPublishError, - type SheetCheckOutcome, - type SheetIssue, - type SheetPublishErrorKind, - type SheetValidator, -} from './anatomical-sheets' + getSheetVersion, + listOfficialCatalog, + type SheetFailureKind, +} from './sheets' export { ASSET_FAILURE_KINDS, ASSET_OWNER_COLUMNS, diff --git a/packages/supabase/src/sheets.ts b/packages/supabase/src/sheets.ts new file mode 100644 index 00000000..81506141 --- /dev/null +++ b/packages/supabase/src/sheets.ts @@ -0,0 +1,227 @@ +import type { FaunosteoClient } from './client' +import type { Json } from './database.types' + +/** + * Access layer for the official anatomical-sheet workflow (V1-2.1, M4/M5): + * typed wrappers over the server RPCs and a closed set of failure kinds. The + * server is the only authority: every RPC answers a closed code (SQLSTATE plus + * a lowercase dotted message), never a value or free text. This module folds + * those answers, the session and the network into one kind the UI phrases + * (`sheet.failure.`), exactly as `records.ts` does for V1-1. No document + * validation happens here: the Rust core (in the page) and the worker verdict + * decide; the former client publication gate is gone (publication takes a + * review id only). + * + * The screens that call these wrappers arrive in V1-2.5 onward; V1-2.1 ships + * the access layer and its types only. + */ + +/** Every closed failure the sheet RPCs raise (contract §6.5, §6.7, §5.2, §5.7). */ +export const SHEET_FAILURE_KINDS = [ + // session and rights + 'authentication_required', + 'mfa_required', + 'forbidden', + 'self_target', + 'rights.account', + 'rights.capability', + 'rights.mfa', + 'rights.owner', + 'rights.catalog', + 'not_found', + // platform roles (AR-1 B) + 'role_active', + 'role_inactive', + 'last_owner', + 'target_invalid', + 'target_factor_missing', + 'operator_path_only', + // catalogue rights + 'grant.active', + 'grant.ineligible', + 'grant.revoked', + 'grant.self_review', + 'grant.target_invalid', + // drafts and saving + 'draft_conflict', + 'draft.unchanged', + 'draft.frozen', + 'draft.not_a_draft', + 'document.shape', + 'document.species', + 'document.too_large', + // sheet and species state + 'sheet.inactive', + 'sheet.state', + 'sheet.no_source', + 'sheet.published_history', + 'sheet.historical_read_only', + 'sheet.species_invalid', + 'species.exists', + 'species.not_active', + 'species.not_inactive', + // review rounds + 'round.open', + 'round.terminal', + 'round.not_open', + 'review.digest', + 'review.uncoverable', + 'review.separation', + 'review.groups.uncovered', + 'version.not_published', + 'version.has_rounds', + // verdict and publication + 'verdict.missing', + 'verdict.stale', + 'verdict.fingerprint', + 'publish.review.missing', + 'publish.inherited.present', + 'publish.species.inactive', + 'publish.species.other', + 'publish.drawing.missing', + 'publish.drawing.changed', + // uploads and working copy + 'upload_missing', + 'size_mismatch', + 'working_copy.source_invalid', + 'working_copy.exists', + 'working_copy.assets_missing', + // shared + 'invalid_input', + 'rate_limited', + 'session_expired', + 'network', + 'unavailable', +] as const +export type SheetFailureKind = (typeof SHEET_FAILURE_KINDS)[number] + +const KIND_SET: ReadonlySet = new Set(SHEET_FAILURE_KINDS) + +export class SheetFailure extends Error { + readonly kind: SheetFailureKind + constructor(kind: SheetFailureKind, cause?: unknown) { + super(`sheet: ${kind}`, { cause }) + this.name = 'SheetFailure' + this.kind = kind + } +} + +interface PostgrestLikeError { + code?: string | null + message?: string +} + +/** + * Folds a PostgREST answer into a closed kind. The RPCs raise the closed code + * as the message (SQLSTATE 42501, P0001, 55000, 23514 or P0002); a message + * outside the closed set, a session error (401 / PGRST30x) and a dropped + * request each map to their own kind. Fails closed on anything unknown. + */ +export function classifySheetError(error: unknown, status?: number): SheetFailureKind { + if (error instanceof SheetFailure) return error.kind + if (error instanceof TypeError) return 'network' + const e = (error ?? {}) as PostgrestLikeError + if (e.message && KIND_SET.has(e.message)) return e.message as SheetFailureKind + if (status === 401 || e.code?.startsWith('PGRST30')) return 'session_expired' + if (status === 0) return 'network' + return 'unavailable' +} + +export function failSheet(error: unknown, status?: number): never { + throw new SheetFailure(classifySheetError(error, status), error) +} + +// --- Rights (owner, aal2) -------------------------------------------------- +export async function grantCatalogRight( + client: FaunosteoClient, + args: { + user_id: string + kind: 'catalog_reader' | 'sheet_editor' | 'sheet_reviewer' | 'sheet_publisher' + reason: string + verification_note?: string + expires_at?: string + }, +): Promise { + const { data, error, status } = await client.rpc('grant_catalog_right', args) + if (error) failSheet(error, status) + return data +} + +export async function revokeCatalogRight( + client: FaunosteoClient, + grantId: string, + reason: string, +): Promise { + const { data, error, status } = await client.rpc('revoke_catalog_right', { + grant_id: grantId, + reason, + }) + if (error) failSheet(error, status) + return data +} + +export async function listCatalogGrants(client: FaunosteoClient): Promise { + const { data, error, status } = await client.rpc('list_catalog_grants') + if (error) failSheet(error, status) + return data +} + +// --- Sheets, drafts, review, publication ----------------------------------- +export async function createOfficialSheet( + client: FaunosteoClient, + slug: string, + document: Json, +): Promise { + const { data, error, status } = await client.rpc('create_official_sheet', { slug, document }) + if (error) failSheet(error, status) + return data +} + +export async function saveSheetDraft( + client: FaunosteoClient, + args: { version_id: string; expected_revision: number; document: Json; change_note?: string }, +): Promise { + const { data, error, status } = await client.rpc('save_sheet_draft', args) + if (error) failSheet(error, status) + return data +} + +export async function submitSheetReview( + client: FaunosteoClient, + args: { version_id: string; expected_revision: number; note?: string }, +): Promise { + const { data, error, status } = await client.rpc('submit_sheet_review', args) + if (error) failSheet(error, status) + return data +} + +export async function decideSheetReview( + client: FaunosteoClient, + args: { review_id: string; approve: boolean; note: string }, +): Promise { + const { data, error, status } = await client.rpc('decide_sheet_review', args) + if (error) failSheet(error, status) + return data +} + +/** Publishes an approved round. The gate is the server's: no client validation. */ +export async function publishSheetVersion( + client: FaunosteoClient, + reviewId: string, +): Promise { + const { data, error, status } = await client.rpc('publish_sheet_version', { review_id: reviewId }) + if (error) failSheet(error, status) + return data +} + +export async function getSheetVersion(client: FaunosteoClient, versionId: string): Promise { + const { data, error, status } = await client.rpc('get_sheet_version', { version_id: versionId }) + if (error) failSheet(error, status) + return data +} + +export async function listOfficialCatalog(client: FaunosteoClient): Promise { + const { data, error, status } = await client.rpc('list_official_catalog') + if (error) failSheet(error, status) + return data +} diff --git a/packages/supabase/tests/anatomical-sheets.test.ts b/packages/supabase/tests/anatomical-sheets.test.ts deleted file mode 100644 index 5771280e..00000000 --- a/packages/supabase/tests/anatomical-sheets.test.ts +++ /dev/null @@ -1,113 +0,0 @@ -import { nodeCoreRuntime } from '@faunosteo/core-wasm/node' -import type { CoreRuntime } from '@faunosteo/core-wasm' -import { publishSheetVersion, SheetPublishError } from '../src' -import type { FaunosteoClient, SheetCheckOutcome, SheetValidator } from '../src' - -/** The real core's `sheet.check` (R2): the gate is never tested against a stub verdict. */ -let core: CoreRuntime -beforeAll(async () => { - core = await nodeCoreRuntime() -}) -const validate: SheetValidator = (content) => - core.call('sheet.check', JSON.stringify(content)) as SheetCheckOutcome - -/** - * Stub of the two client calls publishSheetVersion makes. The real RPC is - * covered by supabase/tests/005_anatomical_sheets.sql; here the point is the - * order of the gate: no RPC call unless the document is publishable. - */ -function stubClient(content: unknown) { - const rpcCalls: unknown[] = [] - const client = { - from: () => ({ - select: () => ({ - eq: () => ({ - single: async () => ({ data: { content }, error: null }), - }), - }), - }), - rpc: async (name: string, args: unknown) => { - rpcCalls.push([name, args]) - return { data: 'published-id', error: null } - }, - } - return { client: client as unknown as FaunosteoClient, rpcCalls } -} - -const publishable = { - schema_version: 2, - species_id: 'equine', - name: { fr: 'Test', en: 'Test' }, - description: {}, - scope_disclaimer: {}, - attribution: { authors: [], license: null, notes: null }, - vertebral_config: { regions: [] }, - references: [], - categories: [], - views: [ - { - id: 'view-main', - kind: 'main', - name: { fr: 'Vue', en: 'View' }, - svg_asset_id: '11111111-1111-4111-8111-111111111111', - view_box: null, - }, - ], - annotations: [], - finding_zones: [], -} - -describe('publishSheetVersion', () => { - it('refuses publication when the validator cannot run (fail closed)', async () => { - const { client, rpcCalls } = stubClient(publishable) - const unavailable: SheetValidator = () => ({ - ok: false, - kind: 'core_unavailable', - }) - await expect( - publishSheetVersion(client, 'v1', unavailable), - ).rejects.toMatchObject({ kind: 'validator_unavailable' }) - expect(rpcCalls).toEqual([]) - }) - - it('calls the RPC once the document passes shape and integrity checks', async () => { - const { client, rpcCalls } = stubClient(publishable) - await expect(publishSheetVersion(client, 'v1', validate)).resolves.toBe( - 'published-id', - ) - expect(rpcCalls).toEqual([['publish_sheet_version', { version_id: 'v1' }]]) - }) - - it('refuses a document with integrity errors before any RPC', async () => { - const { client, rpcCalls } = stubClient({ - ...publishable, - views: [{ ...publishable.views[0], svg_asset_id: null }], - }) - await expect(publishSheetVersion(client, 'v1', validate)).rejects.toThrow( - /view\.asset\.missing/, - ) - expect(rpcCalls).toEqual([]) - }) - - it('refuses a document that does not match the schema', async () => { - const { client, rpcCalls } = stubClient({ schema_version: 1 }) - await expect( - publishSheetVersion(client, 'v1', validate), - ).rejects.toBeInstanceOf(SheetPublishError) - await expect( - publishSheetVersion(client, 'v1', validate), - ).rejects.toMatchObject({ kind: 'invalid_shape' }) - expect(rpcCalls).toEqual([]) - }) - - it('refuses a document carrying a lone surrogate as content, before any RPC (L1)', async () => { - const { client, rpcCalls } = stubClient({ - ...publishable, - name: { fr: 'Vue \ud800', en: 'View' }, - }) - await expect( - publishSheetVersion(client, 'v1', validate), - ).rejects.toMatchObject({ kind: 'invalid_shape' }) - expect(rpcCalls).toEqual([]) - }) -}) diff --git a/packages/supabase/tests/db/schema-types.test.ts b/packages/supabase/tests/db/schema-types.test.ts index c003c198..638a402e 100644 --- a/packages/supabase/tests/db/schema-types.test.ts +++ b/packages/supabase/tests/db/schema-types.test.ts @@ -55,6 +55,19 @@ const expectedColumns = { 'updated_at', 'workspace_id', ], + anatomical_catalog_grants: [ + 'expires_at', + 'grant_kind', + 'granted_at', + 'granted_by', + 'id', + 'reason', + 'revocation_reason', + 'revoked_at', + 'revoked_by', + 'user_id', + 'verification_note', + ], anatomical_sheet_assets: [ 'byte_size', 'content_type', @@ -66,18 +79,58 @@ const expectedColumns = { 'sheet_id', 'uploaded_at', ], + anatomical_sheet_review_acknowledgments: [ + 'created_at', + 'group_digest', + 'group_key', + 'id', + 'review_id', + 'reviewer', + ], + anatomical_sheet_review_comments: ['author', 'body', 'created_at', 'group_key', 'id', 'review_id'], + anatomical_sheet_reviews: [ + 'attempts', + 'authors', + 'created_at', + 'decided_at', + 'decided_by', + 'decision_note', + 'failure_code', + 'failure_outcome', + 'id', + 'lease_token', + 'locked_at', + 'revision', + 'round', + 'status', + 'submission_note', + 'submitted_at', + 'submitted_by', + 'verdict', + 'verified_at', + 'verified_with', + 'version_id', + 'withdrawal_note', + 'withdrawn_at', + 'withdrawn_by', + ], anatomical_sheet_versions: [ + 'authors', 'change_note', 'content', 'created_at', 'created_by', 'deprecated_at', 'deprecated_by', + 'document_fingerprint', 'document_schema_version', 'id', 'published_at', 'published_by', + 'published_review_id', + 'revision', 'sheet_id', + 'source_version_id', 'status', 'updated_at', 'version_number', @@ -100,6 +153,7 @@ const expectedColumns = { 'status', 'updated_at', 'visibility', + 'working_copy_source_version_id', ], assets: [ 'attempts', @@ -197,15 +251,26 @@ const expectedFunctionArgs = { complete_avatar_job: ['asset_id', 'byte_size', 'lock_token', 'sha256'], confirm_asset_upload: ['asset_id'], confirm_sheet_asset_upload: ['asset_id'], - create_anatomical_sheet: [ - 'description', - 'document', - 'name', - 'official', - 'slug', - 'species_id', - 'visibility', - ], + acknowledge_sheet_review_group: ['group_digest', 'group_key', 'review_id'], + activate_species: ['id'], + comment_sheet_review: ['body', 'group_key', 'review_id'], + create_official_sheet: ['document', 'slug'], + create_species: ['id', 'name_en', 'name_fr', 'sort_order'], + create_sheet_working_copy: ['slug', 'source_version_id'], + decide_sheet_review: ['approve', 'note', 'review_id'], + get_sheet_asset_state: ['asset_id'], + get_sheet_version: ['version_id'], + grant_catalog_right: ['expires_at', 'kind', 'reason', 'user_id', 'verification_note'], + list_catalog_grants: [], + list_catalog_species: [], + list_official_catalog: [], + lookup_catalog_account: ['email'], + rename_species: ['id', 'name_en', 'name_fr'], + revoke_catalog_right: ['grant_id', 'reason'], + save_sheet_draft: ['change_note', 'document', 'expected_revision', 'version_id'], + submit_sheet_review: ['expected_revision', 'note', 'version_id'], + update_inactive_species: ['id', 'name_en', 'name_fr', 'sort_order'], + withdraw_sheet_review: ['note', 'review_id'], create_animal: [ 'birth_date', 'birth_year', @@ -247,11 +312,10 @@ const expectedFunctionArgs = { deprecate_sheet_version: ['reason', 'version_id'], end_animal_client_relation: ['ended_on', 'expected_revision', 'relation_id'], expire_pending_uploads: ['max_age_seconds'], - fork_anatomical_sheet: ['name', 'slug', 'source_version_id', 'visibility'], grant_platform_role: ['role', 'target_user_id'], list_client_animals: ['after_id', 'after_sort', 'client_id', 'page_size'], mark_quarantine_purged: ['asset_id'], - publish_sheet_version: ['version_id'], + publish_sheet_version: ['review_id'], register_sheet_asset: ['byte_size', 'file_name', 'sha256', 'sheet_id'], reject_avatar_job: ['asset_id', 'lock_token', 'reason'], remove_avatar: [], @@ -276,7 +340,6 @@ const expectedFunctionArgs = { ], set_animal_archived: ['animal_id', 'archived'], set_client_archived: ['archived', 'client_id'], - set_sheet_visibility: ['sheet_id', 'visibility'], update_animal: [ 'animal_id', 'birth_date', diff --git a/packages/supabase/tests/db/supabase-shim.sql b/packages/supabase/tests/db/supabase-shim.sql index 42a7fe9f..2aee3e7e 100644 --- a/packages/supabase/tests/db/supabase-shim.sql +++ b/packages/supabase/tests/db/supabase-shim.sql @@ -26,6 +26,34 @@ create table auth.users ( updated_at timestamptz default now() ); +-- MFA state read by the V1-2 assurance checks (private.has_aal2_session, +-- private.has_verified_totp). Types, names and NOT NULL columns as in GoTrue +-- v2.197.0 (checked on the pinned image by tests/sandbox/mfa.sandbox.ts); +-- the columns the migrations never read are left out. +create type auth.aal_level as enum ('aal1', 'aal2', 'aal3'); +create type auth.factor_type as enum ('totp', 'webauthn', 'phone', 'recovery_code'); +create type auth.factor_status as enum ('unverified', 'verified'); + +create table auth.sessions ( + id uuid primary key, + user_id uuid not null references auth.users (id) on delete cascade, + created_at timestamptz, + updated_at timestamptz, + factor_id uuid, + aal auth.aal_level, + not_after timestamptz +); + +create table auth.mfa_factors ( + id uuid primary key, + user_id uuid not null references auth.users (id) on delete cascade, + friendly_name text, + factor_type auth.factor_type not null, + status auth.factor_status not null, + created_at timestamptz not null, + updated_at timestamptz not null +); + create or replace function auth.uid() returns uuid language sql diff --git a/packages/supabase/tests/sandbox/mfa.ts b/packages/supabase/tests/sandbox/mfa.ts new file mode 100644 index 00000000..59f9c2bc --- /dev/null +++ b/packages/supabase/tests/sandbox/mfa.ts @@ -0,0 +1,103 @@ +/** + * GoTrue MFA calls of the sandbox (real GoTrue v2.197.0): enrol a TOTP factor, + * challenge and verify it to reach `aal2`, remove it. Every call carries the + * user's own access token, as the browser does. TOTP secrets and tokens stay + * in memory and are never printed. + */ +import { stack } from './stack' +import { msToNextStep, totpCode } from './totp' + +export interface Factor { + id: string + secret: string +} + +export interface MfaResult { + status: number + body: Record +} + +async function authRequest( + method: string, + path: string, + token: string, + body?: unknown, +): Promise { + const res = await fetch(stack.authUrl + path, { + method, + headers: { + apikey: stack.anonKey, + Authorization: `Bearer ${token}`, + 'Content-Type': 'application/json', + }, + body: body === undefined ? undefined : JSON.stringify(body), + }) + const text = await res.text() + let parsed: Record = {} + try { + parsed = JSON.parse(text) as Record + } catch { + // not JSON: keep an empty body + } + return { status: res.status, body: parsed } +} + +/** POST /factors: a new unverified TOTP factor (the secret is shown once). */ +export async function enrolTotp( + token: string, + name: string, +): Promise<{ status: number; factor: Factor | null; body: MfaResult['body'] }> { + const res = await authRequest('POST', '/factors', token, { + factor_type: 'totp', + friendly_name: name, + }) + const totp = res.body.totp as { secret?: string } | undefined + const factor = + res.status === 200 && typeof res.body.id === 'string' && totp?.secret + ? { id: res.body.id, secret: totp.secret } + : null + return { status: res.status, factor, body: res.body } +} + +/** Challenge then verify with the current code; resolves with the new session (aal2 on success). */ +export async function verifyTotp( + token: string, + factor: Factor, +): Promise { + const challenge = await authRequest( + 'POST', + `/factors/${factor.id}/challenge`, + token, + {}, + ) + if (challenge.status !== 200) return challenge + return authRequest('POST', `/factors/${factor.id}/verify`, token, { + challenge_id: challenge.body.id, + code: totpCode(factor.secret), + }) +} + +/** + * Verify with a code of a step not used before for this factor: GoTrue refuses + * a code it already accepted, so a second verification waits for the next step. + */ +export async function verifyTotpFreshStep( + token: string, + factor: Factor, +): Promise { + await new Promise((resolve) => setTimeout(resolve, msToNextStep() + 200)) + return verifyTotp(token, factor) +} + +export function unenrol(token: string, factorId: string): Promise { + return authRequest('DELETE', `/factors/${factorId}`, token) +} + +/** The claims of an access token (payload only; the signature is not checked here). */ +export function claimsOf(token: string): Record { + const payload = token.split('.')[1] ?? '' + return JSON.parse(Buffer.from(payload, 'base64url').toString('utf8')) as Record< + string, + unknown + > +} diff --git a/packages/supabase/tests/sandbox/sheets.sandbox.ts b/packages/supabase/tests/sandbox/sheets.sandbox.ts new file mode 100644 index 00000000..71fe3835 --- /dev/null +++ b/packages/supabase/tests/sandbox/sheets.sandbox.ts @@ -0,0 +1,91 @@ +/** + * V1-2.1 on the throwaway stack with REAL GoTrue and PostgreSQL: the AR-1 B + * path proven with real TOTP factors and real sessions (pgTAP uses fabricated + * auth rows), and the last-owner race under two concurrent transactions (F18). + * Contract docs/development/V1-2_ANATOMICAL_SHEETS.md §5.7, §15. Run through + * `pnpm db:sandbox test tests/sandbox/sheets.sandbox.ts`. + */ +import { confirmedAccount, rpc, sql, errorCode, type Account } from './stack' +import { enrolTotp, verifyTotp, claimsOf } from './mfa' + +/** Enrols and verifies a TOTP factor, returning a fresh aal2 access token. */ +async function stepUp(account: Account): Promise { + const enrol = await enrolTotp(account.token, 'device') + if (!enrol.factor) throw new Error(`enrol failed: ${JSON.stringify(enrol.body)}`) + const verified = await verifyTotp(account.token, enrol.factor) + const token = verified.body.access_token as string + if (!token) throw new Error(`verify failed: ${JSON.stringify(verified.body)}`) + return token +} + +describe('AR-1 B on real GoTrue', () => { + let owner: Account + let ownerAal2: string + let target: Account + + beforeAll(async () => { + owner = await confirmedAccount('ar1-owner') + target = await confirmedAccount('ar1-target') + // Bootstrap the owner role through the operator path (no JWT). + await sql(`select private.assign_platform_role(null, '${owner.id}', 'owner')`) + // The target holds a verified factor (a grant needs one). + await stepUp(target) + ownerAal2 = await stepUp(owner) + }, 120_000) + + it('refuses a platform role change from the aal1 session', async () => { + const res = await rpc('grant_platform_role', { target_user_id: target.id, role: 'support' }, owner.token) + expect(claimsOf(owner.token).aal).toBe('aal1') + expect([res.status, errorCode(res)]).toEqual([403, '42501']) + expect((res.body as { message?: string }).message).toBe('mfa_required') + }) + + it('allows the change from a live aal2 session, then reads it back', async () => { + expect(claimsOf(ownerAal2).aal).toBe('aal2') + const res = await rpc('grant_platform_role', { target_user_id: target.id, role: 'support' }, ownerAal2) + expect(res.status).toBe(200) + expect(await sql(`select count(*) from public.profile_roles where user_id = '${target.id}' and role = 'support' and revoked_at is null`)).toBe('1') + }) + + it('refuses a grant to an account with no verified factor', async () => { + const noFactor = await confirmedAccount('ar1-nofactor') + const res = await rpc('grant_platform_role', { target_user_id: noFactor.id, role: 'moderator' }, ownerAal2) + expect([res.status, (res.body as { message?: string }).message]).toEqual([400, 'target_factor_missing']) + await sql(`delete from auth.users where id = '${noFactor.id}'`) + }) + + afterAll(async () => { + for (const a of [owner, target]) if (a?.id) await sql(`delete from auth.users where id = '${a.id}'`).catch(() => {}) + }) +}) + +describe('last-owner race (F18)', () => { + it('two concurrent revocations of two owners leave one owner', async () => { + const a = await confirmedAccount('f18-a') + const b = await confirmedAccount('f18-b') + const aAal2 = await stepUp(a) + const bAal2 = await stepUp(b) + await sql(`select private.assign_platform_role(null, '${a.id}', 'owner')`) + await sql(`select private.assign_platform_role(null, '${b.id}', 'owner')`) + // Neutralise every other owner so a and b are the only two. + await sql(`update public.profile_roles set revoked_at = now(), revoke_reason = 'f18 test' + where role = 'owner' and revoked_at is null and user_id not in ('${a.id}', '${b.id}')`) + expect(await sql(`select count(*) from public.profile_roles where role = 'owner' and revoked_at is null`)).toBe('2') + + // Each revokes the other, concurrently. + const [ra, rb] = await Promise.all([ + rpc('revoke_platform_role', { target_user_id: b.id, role: 'owner', reason: 'race a' }, aAal2), + rpc('revoke_platform_role', { target_user_id: a.id, role: 'owner', reason: 'race b' }, bAal2), + ]) + const statuses = [ra.status, rb.status] + // The invariant that F18 broke: the two cannot both pass and leave zero + // owners. Exactly one succeeds; the other is refused (last_owner when it + // reaches the guard, or forbidden when it lost its own ownership first); + // one owner always remains. + expect(statuses.filter((s) => s === 200), JSON.stringify([ra.body, rb.body])).toHaveLength(1) + expect(statuses.filter((s) => s !== 200)).toHaveLength(1) + expect(await sql(`select count(*) from public.profile_roles where role = 'owner' and revoked_at is null`)).toBe('1') + + await sql(`delete from auth.users where id in ('${a.id}', '${b.id}')`) + }, 120_000) +}) diff --git a/packages/supabase/tests/sandbox/totp.ts b/packages/supabase/tests/sandbox/totp.ts new file mode 100644 index 00000000..35d0b24b --- /dev/null +++ b/packages/supabase/tests/sandbox/totp.ts @@ -0,0 +1,45 @@ +/** + * RFC 6238 TOTP codes for the sandbox MFA tests (contract + * docs/development/V1-2_ANATOMICAL_SHEETS.md §15): HMAC-SHA1, 30 s steps, + * 6 digits, the parameters GoTrue v2.197.0 uses. Node `crypto` only, no + * dependency. The secret stays in the test's memory: never printed, logged or + * written anywhere. + */ +import { createHmac } from 'node:crypto' + +const BASE32 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567' +export const TOTP_STEP_SECONDS = 30 + +function base32Decode(text: string): Buffer { + const clean = text.replace(/=+$/, '').toUpperCase() + const bytes: number[] = [] + let buffer = 0 + let bits = 0 + for (const char of clean) { + const value = BASE32.indexOf(char) + if (value < 0) throw new Error('totp: secret is not base32') + buffer = (buffer << 5) | value + bits += 5 + if (bits >= 8) { + bits -= 8 + bytes.push((buffer >> bits) & 0xff) + } + } + return Buffer.from(bytes) +} + +/** The 6-digit code of `secret` for the step holding `at` (ms since epoch). */ +export function totpCode(secret: string, at = Date.now()): string { + const counter = Buffer.alloc(8) + counter.writeBigUInt64BE(BigInt(Math.floor(at / 1000 / TOTP_STEP_SECONDS))) + const mac = createHmac('sha1', base32Decode(secret)).update(counter).digest() + const offset = mac[mac.length - 1] & 0x0f + const value = (mac.readUInt32BE(offset) & 0x7fffffff) % 1_000_000 + return value.toString().padStart(6, '0') +} + +/** Milliseconds until the next step starts (a fresh code). */ +export function msToNextStep(at = Date.now()): number { + const step = TOTP_STEP_SECONDS * 1000 + return step - (at % step) +} diff --git a/packages/supabase/tests/sandbox/workspaces.sandbox.ts b/packages/supabase/tests/sandbox/workspaces.sandbox.ts index 6b1ce5df..39388948 100644 --- a/packages/supabase/tests/sandbox/workspaces.sandbox.ts +++ b/packages/supabase/tests/sandbox/workspaces.sandbox.ts @@ -18,6 +18,9 @@ import { sql, sqlOutcome, stack, +} from './stack' +import { enrolTotp, verifyTotp } from './mfa' +import { uniqueEmail, type Account, } from './stack' @@ -194,11 +197,18 @@ describe('reads and refusals per role', () => { }) it('stores an oversized correlation header as null and keeps a short token', async () => { + // AR-1 B: the role RPCs need a live aal2 session and a factored target, so + // the seed owner steps up and b enrols a factor before the grant. const owner = await signIn( 'owner@faunosteo.local', 'LocalDev-only-password-1', ) - const token = owner.body.access_token as string + const ownerToken = owner.body.access_token as string + const ownerEnrol = await enrolTotp(ownerToken, 'owner device') + const token = (await verifyTotp(ownerToken, ownerEnrol.factor!)).body + .access_token as string + const bEnrol = await enrolTotp(b.token, 'b device') + await verifyTotp(b.token, bEnrol.factor!) const grant = await rpc( 'grant_platform_role', { target_user_id: b.id, role: 'support' }, diff --git a/scripts/db-sandbox.sh b/scripts/db-sandbox.sh index fede3b49..8b624993 100755 --- a/scripts/db-sandbox.sh +++ b/scripts/db-sandbox.sh @@ -246,7 +246,7 @@ case "${1:-}" in else printf '%s\n' "$out" > packages/supabase/src/database.types.ts; echo "== types written" fi ;; - test) load_secrets; with_sandbox_env node_modules/.bin/pnpm --filter @faunosteo/supabase test:sandbox ;; + test) shift; load_secrets; with_sandbox_env node_modules/.bin/pnpm --filter @faunosteo/supabase test:sandbox "$@" ;; e2e-shell) shift; load_secrets; with_sandbox_env node_modules/.bin/pnpm --filter @faunosteo/app e2e:shell "$@" ;; sql) load_secrets; sb_psql ;; *) sed -n '2,23p' "$0"; exit 1 ;; diff --git a/supabase/migrations/20261028100000_sheet_access_hardening.sql b/supabase/migrations/20261028100000_sheet_access_hardening.sql new file mode 100644 index 00000000..82f66971 --- /dev/null +++ b/supabase/migrations/20261028100000_sheet_access_hardening.sql @@ -0,0 +1,1088 @@ +-- V1-2.1 M4 sheet_access_hardening. Contract: +-- docs/development/V1-2_ANATOMICAL_SHEETS.md §5 (rights, catalogue access, +-- MFA, AR-1 B), §12.1 (defects), §12.3 (M4), §14.2 (historical sheet). +-- +-- M4 and M5 (20261028110000_sheet_review_workflow.sql) are applied together: +-- M4 removes every unsafe write path of the Step 4 lifecycle (personal +-- creation, fork, visibility changes, publication without review, direct +-- table writes, service-role table privileges); M5 adds the reviewed +-- workflow. M4 alone leaves no path that publishes a version. +-- +-- What M4 establishes: +-- * explicit catalogue rights (`anatomical_catalog_grants`): three +-- capabilities and the provisional catalogue access, written by the +-- platform owner only, from an `aal2` session that still exists; +-- * predicates kept apart so no check tests the wrong account: +-- `grant_active(uid, kind)` for stored actors, `caller_has(kind)` for the +-- calling session (adds `has_mfa()`); +-- * the catalogue reader predicate (official, non-deleted sheet with a +-- published or deprecated version, and catalogue access) on sheets, +-- versions, asset rows and Storage objects; capability holders with +-- `aal2` read every official sheet; nobody else reads anything; +-- * AR-1 B: every platform role change needs an `aal2` session checked +-- against auth.sessions, a verified TOTP factor on a grant's target, a +-- race-free last-owner guard; `service_role` loses its table privileges +-- on profiles, profile_roles and every catalogue table (F12, F17); +-- * immutability: deprecated versions are never deleted (F13), asset rows +-- never change (F16), the historical equine sheet is frozen (§14.2). +-- No row is changed by this migration. + +-- --------------------------------------------------------------------------- +-- Assurance level of the calling session (contract §5.6, §5.7.8) +-- --------------------------------------------------------------------------- +-- The `aal` claim of the token PostgREST verified. An absent, null or +-- differently cased claim is not aal2. +create or replace function private.has_mfa() +returns boolean +language sql +stable +security definer +set search_path = '' +as $$ + select coalesce((select auth.jwt()) ->> 'aal', '') = 'aal2'; +$$; + +comment on function private.has_mfa() is + 'true when the verified token of the request carries aal = aal2 (exact). Policies and catalogue RPCs.'; + +-- For the platform role and catalogue rights RPCs only (rare, administrative): +-- the claim, plus the session named by the token still existing at aal2, so a +-- token outliving a sign-out or a factor removal (GoTrue downgrades the +-- session row) is refused at once instead of for up to one token lifetime. +create or replace function private.has_aal2_session() +returns boolean +language plpgsql +stable +security definer +set search_path = '' +as $$ +declare + v_uid uuid := (select auth.uid()); + v_session text := (select auth.jwt()) ->> 'session_id'; +begin + if v_uid is null or not private.has_mfa() or v_session is null + or v_session !~ '^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$' then + return false; + end if; + return exists ( + select 1 from auth.sessions s + where s.id = v_session::uuid + and s.user_id = v_uid + and s.aal = 'aal2' + and (s.not_after is null or s.not_after > now()) + ); +end; +$$; + +comment on function private.has_aal2_session() is + 'has_mfa() and the token''s session_id names a live auth.sessions row of the caller at aal2. Role and rights RPCs only.'; + +-- Active profile and confirmed email: the precondition of every right (§5.1). +create or replace function private.is_confirmed_active_account(p_user_id uuid) +returns boolean +language sql +stable +security definer +set search_path = '' +as $$ + select exists ( + select 1 + from public.profiles p + join auth.users u on u.id = p.id + where p.id = p_user_id and p.active and u.email_confirmed_at is not null + ); +$$; + +-- A verified TOTP factor (contract §5.2: a capability or a platform role is +-- never handed to an account whose first factor a password holder could still +-- enrol). +create or replace function private.has_verified_totp(p_user_id uuid) +returns boolean +language sql +stable +security definer +set search_path = '' +as $$ + select exists ( + select 1 from auth.mfa_factors f + where f.user_id = p_user_id and f.factor_type = 'totp' and f.status = 'verified' + ); +$$; + +-- --------------------------------------------------------------------------- +-- Catalogue rights (contract §5.2, §5.3) +-- --------------------------------------------------------------------------- +create type public.catalog_grant_kind as enum ( + 'catalog_reader', 'sheet_editor', 'sheet_reviewer', 'sheet_publisher' +); + +create table public.anatomical_catalog_grants ( + id uuid primary key default gen_random_uuid(), + -- restrict: the review trail names grant holders; an account that held a + -- right is removed by an operator decision, never by a cascade. + user_id uuid not null references public.profiles (id) on delete restrict, + grant_kind public.catalog_grant_kind not null, + reason text not null + constraint anatomical_catalog_grants_reason_length check (char_length(reason) between 1 and 1000), + verification_note text + constraint anatomical_catalog_grants_note_length check (char_length(verification_note) between 1 and 1000), + granted_by uuid not null references public.profiles (id) on delete restrict, + granted_at timestamptz not null default now(), + expires_at timestamptz, + revoked_by uuid references public.profiles (id) on delete restrict, + revoked_at timestamptz, + revocation_reason text + constraint anatomical_catalog_grants_revocation_reason_length check (char_length(revocation_reason) between 1 and 1000), + constraint anatomical_catalog_grants_note_required + check (grant_kind = 'catalog_reader' or verification_note is not null), + constraint anatomical_catalog_grants_expiry_after_grant + check (expires_at is null or expires_at > granted_at), + constraint anatomical_catalog_grants_revocation_consistent + check ((revoked_at is null and revoked_by is null and revocation_reason is null) + or (revoked_at is not null and revoked_by is not null and revocation_reason is not null)) +); + +comment on table public.anatomical_catalog_grants is + 'Catalogue rights (contract §5.2): capabilities sheet_editor / sheet_reviewer / sheet_publisher and the provisional catalog_reader. Written by grant_catalog_right / revoke_catalog_right only; a row is revoked once, never otherwise updated or deleted; a renewal is a new row.'; + +create index anatomical_catalog_grants_user_kind_idx + on public.anatomical_catalog_grants (user_id, grant_kind) where revoked_at is null; + +-- Rows are append-only apart from the single revocation, for every role. +create or replace function private.guard_catalog_grant() +returns trigger +language plpgsql +set search_path = '' +as $$ +begin + if tg_op = 'DELETE' then + raise exception 'catalog grants are never deleted' using errcode = '42501'; + end if; + if old.revoked_at is not null + or (new.id, new.user_id, new.grant_kind, new.reason, new.verification_note, + new.granted_by, new.granted_at, new.expires_at) + is distinct from + (old.id, old.user_id, old.grant_kind, old.reason, old.verification_note, + old.granted_by, old.granted_at, old.expires_at) then + raise exception 'a catalog grant changes only by its revocation' using errcode = '42501'; + end if; + return new; +end; +$$; + +create trigger anatomical_catalog_grants_guard + before update or delete on public.anatomical_catalog_grants + for each row execute function private.guard_catalog_grant(); + +-- The grant and its eligibility, without any assurance level: for stored +-- actors (acknowledgers, approvers) and as the base of caller_has. Read at +-- every request, so an expiry, a revocation, a deactivation or a lost +-- platform role takes effect at once, whatever an older token says. +create or replace function private.grant_active(p_user_id uuid, p_kind public.catalog_grant_kind) +returns boolean +language sql +stable +security definer +set search_path = '' +as $$ + select p_user_id is not null + and private.is_confirmed_active_account(p_user_id) + and exists ( + select 1 from public.anatomical_catalog_grants g + where g.user_id = p_user_id + and g.grant_kind = p_kind + and g.revoked_at is null + and (g.expires_at is null or g.expires_at > now()) + ) + -- Editor and publisher need an active owner or admin role (O1); losing + -- it suspends the capability without touching the grant row. + and (p_kind not in ('sheet_editor', 'sheet_publisher') or private.is_platform_admin(p_user_id)); +$$; + +-- The calling session holds the capability, at aal2. +create or replace function private.caller_has(p_kind public.catalog_grant_kind) +returns boolean +language sql +stable +security definer +set search_path = '' +as $$ + select private.has_mfa() and private.grant_active((select auth.uid()), p_kind); +$$; + +-- Editor, reviewer or publisher, at aal2: reads drafts, rounds and history. +create or replace function private.caller_is_catalog_staff() +returns boolean +language sql +stable +security definer +set search_path = '' +as $$ + select private.has_mfa() and ( + private.grant_active((select auth.uid()), 'sheet_editor') + or private.grant_active((select auth.uid()), 'sheet_reviewer') + or private.grant_active((select auth.uid()), 'sheet_publisher') + ); +$$; + +-- Provisional catalogue access (O21), fail-closed: a catalog_reader grant or +-- any capability; no assurance level; platform roles give nothing. +create or replace function private.can_read_official_catalog(p_user_id uuid) +returns boolean +language sql +stable +security definer +set search_path = '' +as $$ + select private.grant_active(p_user_id, 'catalog_reader') + or private.grant_active(p_user_id, 'sheet_editor') + or private.grant_active(p_user_id, 'sheet_reviewer') + or private.grant_active(p_user_id, 'sheet_publisher'); +$$; + +comment on function private.can_read_official_catalog(uuid) is + 'Provisional catalogue access (contract §5.3, O21): active catalog_reader grant or capability, active profile, confirmed email. Replaced by the entitlements of plan Step 11.'; + +-- The fixed id of the historical equine sheet (contract §14.2, the core's +-- alias registry pins the same id). +create or replace function private.historical_sheet_id() +returns uuid +language sql +immutable +set search_path = '' +as $$ + select '503dc301-a8b1-50d4-9e44-0919b2fc2916'::uuid; +$$; + +-- A sheet of the catalogue: official, not deleted, with at least one +-- published or deprecated version (archived sheets included, O8). A sheet +-- that only has a draft is invisible to readers. +create or replace function private.is_catalog_sheet(p_sheet_id uuid) +returns boolean +language sql +stable +security definer +set search_path = '' +as $$ + select exists ( + select 1 from public.anatomical_sheets s + where s.id = p_sheet_id + and s.is_official + and s.status <> 'deleted' + and exists ( + select 1 from public.anatomical_sheet_versions v + where v.sheet_id = s.id and v.status in ('published', 'deprecated') + ) + ); +$$; + +-- The reader row predicate (§5.3), the same on sheets, versions, asset rows +-- and objects. +create or replace function private.can_read_catalog_sheet(p_user_id uuid, p_sheet_id uuid) +returns boolean +language sql +stable +security definer +set search_path = '' +as $$ + select private.can_read_official_catalog(p_user_id) and private.is_catalog_sheet(p_sheet_id); +$$; + +-- Capability holders at aal2 read every non-deleted official sheet. +create or replace function private.caller_can_see_official_sheet(p_sheet_id uuid) +returns boolean +language sql +stable +security definer +set search_path = '' +as $$ + select private.caller_is_catalog_staff() and exists ( + select 1 from public.anatomical_sheets s + where s.id = p_sheet_id and s.is_official and s.status <> 'deleted' + ); +$$; + +-- An asset row referenced by a published or deprecated version of its sheet. +create or replace function private.asset_in_catalog_version(p_asset_id uuid, p_sheet_id uuid) +returns boolean +language sql +stable +security definer +set search_path = '' +as $$ + select exists ( + select 1 from public.anatomical_sheet_versions v + where v.sheet_id = p_sheet_id + and v.status in ('published', 'deprecated') + and p_asset_id::text = any (private.sheet_document_asset_ids(v.content)) + ); +$$; + +-- Official sheets only, edited through the sheet_editor capability at aal2 +-- (F14). Personal sheets are closed in V1-2 (D5): no branch for them. The +-- user argument must be the caller: the capability is the session's. +create or replace function private.can_edit_sheet(p_user_id uuid, p_sheet_id uuid) +returns boolean +language sql +stable +security definer +set search_path = '' +as $$ + select p_user_id is not null + and p_user_id = (select auth.uid()) + and private.caller_has('sheet_editor') + and exists ( + select 1 from public.anatomical_sheets s + where s.id = p_sheet_id and s.is_official and s.status <> 'deleted' + ); +$$; + +comment on function private.can_edit_sheet(uuid, uuid) is + 'The caller (p_user_id = auth.uid()) holds sheet_editor at aal2 and the sheet is official and not deleted (contract §5.2, F14).'; + +-- Every catalogue write requires an active account with a confirmed email (F5). +create or replace function private.require_actor() +returns uuid +language plpgsql +stable +set search_path = '' +as $$ +declare + v_actor uuid := auth.uid(); +begin + if v_actor is null or not private.is_confirmed_active_account(v_actor) then + raise exception 'rights.account' using errcode = '42501'; + end if; + return v_actor; +end; +$$; + +-- --------------------------------------------------------------------------- +-- Write budget per actor for catalogue writes (V1-1 D15 pattern, contract +-- §6.2, §13): fixed UTC windows, 300 audited writes an hour, 2 000 a day. +-- Taken last in each RPC, after the entity locks. +-- --------------------------------------------------------------------------- +create table private.catalog_write_budgets ( + user_id uuid primary key references public.profiles (id) on delete cascade, + hour_start timestamptz not null, + hour_count integer not null, + day_start timestamptz not null, + day_count integer not null +); + +comment on table private.catalog_write_budgets is + 'Audited catalogue writes per account in the current UTC hour and day. Written only by private.consume_catalog_write_budget.'; + +create or replace function private.consume_catalog_write_budget(p_user_id uuid) +returns void +language plpgsql +security definer +set search_path = '' +as $$ +declare + v_hour timestamptz := date_trunc('hour', now(), 'UTC'); + v_day timestamptz := date_trunc('day', now(), 'UTC'); + v_hour_count integer; + v_day_count integer; +begin + insert into private.catalog_write_budgets as b (user_id, hour_start, hour_count, day_start, day_count) + values (p_user_id, v_hour, 1, v_day, 1) + on conflict (user_id) do update set + hour_count = case when b.hour_start = excluded.hour_start then b.hour_count + 1 else 1 end, + hour_start = excluded.hour_start, + day_count = case when b.day_start = excluded.day_start then b.day_count + 1 else 1 end, + day_start = excluded.day_start + returning b.hour_count, b.day_count into v_hour_count, v_day_count; + + if v_hour_count > 300 or v_day_count > 2000 then + raise exception 'rate_limited' using errcode = 'P0001'; + end if; +end; +$$; + +-- --------------------------------------------------------------------------- +-- Rights RPCs (contract §5.2): the platform owner, from a live aal2 session +-- --------------------------------------------------------------------------- +-- The caller is an active, confirmed platform owner with a live aal2 session. +-- The assurance check comes first: a password-only session gets the same +-- answer whatever its role (no oracle on who is owner). +create or replace function private.require_rights_owner() +returns uuid +language plpgsql +stable +security definer +set search_path = '' +as $$ +declare + v_actor uuid := auth.uid(); +begin + if v_actor is null then + raise exception 'rights.account' using errcode = '42501'; + end if; + if not private.has_aal2_session() then + raise exception 'rights.mfa' using errcode = '42501'; + end if; + if not (private.is_confirmed_active_account(v_actor) and private.is_platform_owner(v_actor)) then + raise exception 'rights.owner' using errcode = '42501'; + end if; + return v_actor; +end; +$$; + +create or replace function public.grant_catalog_right( + user_id uuid, + kind public.catalog_grant_kind, + reason text, + verification_note text default null, + expires_at timestamptz default null +) +returns uuid +language plpgsql +volatile +security definer +set search_path = '' +as $$ +#variable_conflict use_column +declare + v_actor uuid := private.require_rights_owner(); + v_reason text := btrim(grant_catalog_right.reason); + v_note text := nullif(btrim(grant_catalog_right.verification_note), ''); + v_id uuid; +begin + if grant_catalog_right.kind is null or v_reason is null + or char_length(v_reason) not between 1 and 1000 + or char_length(v_note) > 1000 + or (grant_catalog_right.kind <> 'catalog_reader' and v_note is null) + or grant_catalog_right.expires_at <= now() then + raise exception 'invalid_input' using errcode = 'P0001'; + end if; + -- An owner may hold the editor and publisher capabilities it needs (journey + -- A0) but never reviews on its own grant: a reviewer is habilitated by + -- another owner, so the separation of duties keeps two people. + if grant_catalog_right.user_id = v_actor and grant_catalog_right.kind = 'sheet_reviewer' then + raise exception 'grant.self_review' using errcode = 'P0001'; + end if; + + -- Serialises the grants of one account: one active row per kind. + perform 1 from public.profiles p where p.id = grant_catalog_right.user_id for no key update; + if not found then + raise exception 'grant.target_invalid' using errcode = 'P0001'; + end if; + if not private.is_confirmed_active_account(grant_catalog_right.user_id) + or (grant_catalog_right.kind <> 'catalog_reader' and not private.has_verified_totp(grant_catalog_right.user_id)) + or (grant_catalog_right.kind in ('sheet_editor', 'sheet_publisher') + and not private.is_platform_admin(grant_catalog_right.user_id)) then + raise exception 'grant.ineligible' using errcode = 'P0001'; + end if; + if exists ( + select 1 from public.anatomical_catalog_grants g + where g.user_id = grant_catalog_right.user_id and g.grant_kind = grant_catalog_right.kind + and g.revoked_at is null and (g.expires_at is null or g.expires_at > now()) + ) then + raise exception 'grant.active' using errcode = 'P0001'; + end if; + perform private.consume_catalog_write_budget(v_actor); + + insert into public.anatomical_catalog_grants ( + user_id, grant_kind, reason, verification_note, granted_by, expires_at + ) + values ( + grant_catalog_right.user_id, grant_catalog_right.kind, v_reason, v_note, v_actor, + grant_catalog_right.expires_at + ) + returning id into v_id; + + perform private.log_event( + v_actor, 'catalog_grant.granted', 'catalog_grant', v_id, grant_catalog_right.user_id, null, + jsonb_build_object('kind', grant_catalog_right.kind, 'reason', v_reason, + 'verification_note', v_note, 'expires_at', grant_catalog_right.expires_at) + ); + return v_id; +end; +$$; + +create or replace function public.revoke_catalog_right(grant_id uuid, reason text) +returns uuid +language plpgsql +volatile +security definer +set search_path = '' +as $$ +#variable_conflict use_column +declare + v_actor uuid := private.require_rights_owner(); + v_reason text := btrim(revoke_catalog_right.reason); + v_row public.anatomical_catalog_grants; +begin + if v_reason is null or char_length(v_reason) not between 1 and 1000 then + raise exception 'invalid_input' using errcode = 'P0001'; + end if; + select g.* into v_row from public.anatomical_catalog_grants g + where g.id = revoke_catalog_right.grant_id + for update; + if not found then + raise exception 'not_found' using errcode = '42501'; + end if; + if v_row.revoked_at is not null then + raise exception 'grant.revoked' using errcode = 'P0001'; + end if; + perform private.consume_catalog_write_budget(v_actor); + + update public.anatomical_catalog_grants g + set revoked_at = now(), revoked_by = v_actor, revocation_reason = v_reason + where g.id = v_row.id; + + perform private.log_event( + v_actor, 'catalog_grant.revoked', 'catalog_grant', v_row.id, v_row.user_id, null, + jsonb_build_object('kind', v_row.grant_kind, 'reason', v_reason) + ); + return v_row.id; +end; +$$; + +-- The rights screen (contract §5.2, §11.1 /app/admin/access): every grant with +-- its holder, state and reasons. +create or replace function public.list_catalog_grants() +returns jsonb +language plpgsql +stable +security definer +set search_path = '' +as $$ +begin + perform private.require_rights_owner(); + return coalesce(( + select jsonb_agg(jsonb_build_object( + 'id', g.id, + 'user_id', g.user_id, + 'display_name', p.display_name, + 'email', u.email, + 'kind', g.grant_kind, + 'reason', g.reason, + 'verification_note', g.verification_note, + 'granted_by', g.granted_by, + 'granted_by_name', gp.display_name, + 'granted_at', g.granted_at, + 'expires_at', g.expires_at, + 'revoked_at', g.revoked_at, + 'revoked_by', g.revoked_by, + 'revocation_reason', g.revocation_reason, + 'state', case + when g.revoked_at is not null then 'revoked' + when g.expires_at is not null and g.expires_at <= now() then 'expired' + when g.expires_at is not null and g.expires_at <= now() + interval '30 days' then 'expiring' + else 'active' + end, + 'effective', private.grant_active(g.user_id, g.grant_kind) + ) order by g.granted_at desc, g.id) + from public.anatomical_catalog_grants g + join public.profiles p on p.id = g.user_id + join auth.users u on u.id = g.user_id + left join public.profiles gp on gp.id = g.granted_by + ), '[]'::jsonb); +end; +$$; + +-- Finds the account a right is granted to, by e-mail (owner only). +create or replace function public.lookup_catalog_account(email text) +returns jsonb +language plpgsql +stable +security definer +set search_path = '' +as $$ +declare + v_result jsonb; +begin + perform private.require_rights_owner(); + if lookup_catalog_account.email is null or char_length(lookup_catalog_account.email) not between 3 and 320 then + raise exception 'invalid_input' using errcode = 'P0001'; + end if; + select jsonb_build_object( + 'user_id', p.id, + 'display_name', p.display_name, + 'active', p.active, + 'email_confirmed', u.email_confirmed_at is not null, + 'verified_totp', private.has_verified_totp(p.id), + 'platform_roles', coalesce(( + select jsonb_agg(r.role order by r.role) + from public.profile_roles r + where r.user_id = p.id and r.revoked_at is null + ), '[]'::jsonb) + ) + into v_result + from auth.users u + join public.profiles p on p.id = u.id + where lower(u.email) = lower(lookup_catalog_account.email); + if v_result is null then + raise exception 'not_found' using errcode = '42501'; + end if; + return v_result; +end; +$$; + +comment on function public.grant_catalog_right(uuid, public.catalog_grant_kind, text, text, timestamptz) is + 'Platform owner, live aal2 session: grants a catalogue right with a reason (and a verification note for capabilities); eligibility checked; one active row per account and kind. Audited.'; +comment on function public.revoke_catalog_right(uuid, text) is + 'Platform owner, live aal2 session: revokes a grant once, reason required. Audited.'; + +-- --------------------------------------------------------------------------- +-- AR-1 B: platform role changes (contract §5.7) +-- --------------------------------------------------------------------------- +-- One transaction-scoped lock serialises every role change, so the owner +-- count of the last-owner guard cannot be read by two writers at once (F18). +create or replace function private.lock_platform_roles() +returns void +language sql +volatile +set search_path = '' +as $$ + select pg_advisory_xact_lock(hashtextextended('faunosteo.platform_roles', 0)); +$$; + +-- System write path. A non-null actor must be the calling session's account +-- at aal2 with a live session; a null actor (bootstrap, recovery) is accepted +-- only when the request carries no JWT at all, so neither an API session nor +-- the service role reaches the operator path (§5.7.5). +create or replace function private.check_role_actor(p_actor uuid) +returns void +language plpgsql +stable +security definer +set search_path = '' +as $$ +begin + if p_actor is null then + if (select auth.role()) is not null or (select auth.uid()) is not null then + raise exception 'operator_path_only' using errcode = '42501'; + end if; + elsif p_actor is distinct from (select auth.uid()) or not private.has_aal2_session() then + raise exception 'mfa_required' using errcode = '42501'; + end if; +end; +$$; + +create or replace function private.assign_platform_role( + p_actor uuid, + p_target uuid, + p_role public.platform_role +) +returns uuid +language plpgsql +security definer +set search_path = '' +as $$ +declare + v_id uuid; +begin + perform private.check_role_actor(p_actor); + perform private.lock_platform_roles(); + if not exists (select 1 from public.profiles where id = p_target and active) then + raise exception 'target_invalid' using errcode = 'P0001'; + end if; + -- Through a session, the target already holds a verified factor. The + -- operator path is the bootstrap of §5.7.1, which checks it out of band. + if p_actor is not null and not private.has_verified_totp(p_target) then + raise exception 'target_factor_missing' using errcode = 'P0001'; + end if; + if exists ( + select 1 from public.profile_roles + where user_id = p_target and role = p_role and revoked_at is null + ) then + raise exception 'role_active' using errcode = 'P0001'; + end if; + + insert into public.profile_roles (user_id, role, granted_by) + values (p_target, p_role, p_actor) + returning id into v_id; + + perform private.log_event( + p_actor, 'platform_role.granted', 'profile_role', v_id, p_target, null, + jsonb_build_object('role', p_role) + ); + return v_id; +end; +$$; + +create or replace function private.withdraw_platform_role( + p_actor uuid, + p_target uuid, + p_role public.platform_role, + p_reason text +) +returns uuid +language plpgsql +security definer +set search_path = '' +as $$ +declare + v_id uuid; +begin + perform private.check_role_actor(p_actor); + perform private.lock_platform_roles(); + if not exists (select 1 from public.profiles where id = p_target and active) then + raise exception 'target_invalid' using errcode = 'P0001'; + end if; + select id into v_id + from public.profile_roles + where user_id = p_target and role = p_role and revoked_at is null; + if v_id is null then + raise exception 'role_inactive' using errcode = 'P0001'; + end if; + + -- Lock-out guard, under the lock: another active owner (active profile, the + -- has_platform_role semantics) must remain once this row is revoked. + if p_role = 'owner' and not exists ( + select 1 + from public.profile_roles r + join public.profiles p on p.id = r.user_id + where r.role = 'owner' and r.revoked_at is null and p.active and r.id <> v_id + ) then + raise exception 'last_owner' using errcode = 'P0001'; + end if; + + update public.profile_roles + set revoked_at = now(), revoked_by = p_actor, revoke_reason = p_reason + where id = v_id; + + perform private.log_event( + p_actor, 'platform_role.revoked', 'profile_role', v_id, p_target, null, + jsonb_build_object('role', p_role, 'reason', p_reason) + ); + return v_id; +end; +$$; + +-- Order of checks (§5.7), every one before any write: authenticated, live +-- aal2 session (the same answer whatever the caller's role), not self, +-- can_manage_platform_role, then the operation itself in the private writer. +create or replace function public.grant_platform_role( + target_user_id uuid, + role public.platform_role +) +returns uuid +language plpgsql +security definer +set search_path = '' +as $$ +declare + v_actor uuid := auth.uid(); +begin + if v_actor is null then + raise exception 'authentication_required' using errcode = '42501'; + end if; + if not private.has_aal2_session() then + raise exception 'mfa_required' using errcode = '42501'; + end if; + perform private.lock_platform_roles(); + if v_actor = target_user_id then + raise exception 'self_target' using errcode = '42501'; + end if; + if not private.can_manage_platform_role(v_actor, role) then + raise exception 'forbidden' using errcode = '42501'; + end if; + return private.assign_platform_role(v_actor, target_user_id, role); +end; +$$; + +create or replace function public.revoke_platform_role( + target_user_id uuid, + role public.platform_role, + reason text default null +) +returns uuid +language plpgsql +security definer +set search_path = '' +as $$ +declare + v_actor uuid := auth.uid(); +begin + if v_actor is null then + raise exception 'authentication_required' using errcode = '42501'; + end if; + if not private.has_aal2_session() then + raise exception 'mfa_required' using errcode = '42501'; + end if; + perform private.lock_platform_roles(); + if v_actor = target_user_id then + raise exception 'self_target' using errcode = '42501'; + end if; + if not private.can_manage_platform_role(v_actor, role) then + raise exception 'forbidden' using errcode = '42501'; + end if; + if char_length(reason) > 500 then + raise exception 'invalid_input' using errcode = 'P0001'; + end if; + return private.withdraw_platform_role(v_actor, target_user_id, role, reason); +end; +$$; + +comment on function private.assign_platform_role(uuid, uuid, public.platform_role) is + 'System write path. Non-null actor = the caller at aal2 (live session), target with a verified TOTP factor. Null actor = operator bootstrap or recovery from a privileged SQL session without JWT (contract §5.7.1, §5.7.5).'; +comment on function public.grant_platform_role(uuid, public.platform_role) is + 'Grants a platform role to another user from a live aal2 session (AR-1 B). owner: any role; admin: moderator/support. Audited.'; +comment on function public.revoke_platform_role(uuid, public.platform_role, text) is + 'Revokes an active platform role of another user from a live aal2 session (AR-1 B); one active owner always kept, race-free. Audited.'; + +-- --------------------------------------------------------------------------- +-- Immutability guards (every role) +-- --------------------------------------------------------------------------- +-- A version that was ever published is never deleted (F13); the historical +-- sheet's versions are never deleted (§14.2). +create or replace function private.guard_sheet_version_delete() +returns trigger +language plpgsql +security definer +set search_path = '' +as $$ +declare + v_dependents text[]; +begin + if old.status in ('published', 'deprecated') then + raise exception 'version % was published: it is never deleted', old.id + using errcode = '55000'; + end if; + if old.sheet_id = private.historical_sheet_id() then + raise exception 'sheet.historical_read_only' using errcode = '42501'; + end if; + v_dependents := private.sheet_version_dependents(old.id); + if coalesce(array_length(v_dependents, 1), 0) > 0 then + raise exception 'version % still has dependents: %', old.id, v_dependents + using errcode = '55000'; + end if; + return old; +end; +$$; + +-- Asset rows are content-addressed and immutable (F16): only uploaded_at +-- moves, once, from null to a time. The historical sheet's rows are never +-- deleted. +create or replace function private.guard_sheet_asset() +returns trigger +language plpgsql +set search_path = '' +as $$ +begin + if tg_op = 'DELETE' then + if old.sheet_id = private.historical_sheet_id() then + raise exception 'sheet.historical_read_only' using errcode = '42501'; + end if; + return old; + end if; + if (new.id, new.sheet_id, new.sha256, new.byte_size, new.content_type, new.file_name, new.created_at) + is distinct from + (old.id, old.sheet_id, old.sha256, old.byte_size, old.content_type, old.file_name, old.created_at) + or (old.uploaded_at is not null and new.uploaded_at is distinct from old.uploaded_at) then + raise exception 'sheet asset rows are immutable' using errcode = '42501'; + end if; + return new; +end; +$$; + +create trigger anatomical_sheet_assets_guard + before update or delete on public.anatomical_sheet_assets + for each row execute function private.guard_sheet_asset(); + +-- The historical equine sheet row (§14.2): never deleted, and nothing but its +-- version counter (the converging seed inserts its single draft) and +-- updated_at ever changes. +create or replace function private.guard_historical_sheet() +returns trigger +language plpgsql +set search_path = '' +as $$ +declare + v_new public.anatomical_sheets; +begin + if old.id <> private.historical_sheet_id() then + return case when tg_op = 'DELETE' then old else new end; + end if; + if tg_op = 'DELETE' then + raise exception 'sheet.historical_read_only' using errcode = '42501'; + end if; + v_new := new; + v_new.last_version_number := old.last_version_number; + v_new.updated_at := old.updated_at; + if v_new is distinct from old then + raise exception 'sheet.historical_read_only' using errcode = '42501'; + end if; + return new; +end; +$$; + +create trigger anatomical_sheets_guard_historical + before update or delete on public.anatomical_sheets + for each row execute function private.guard_historical_sheet(); + +-- --------------------------------------------------------------------------- +-- Closed paths (D5: no personal sheet, fork or sharing in V1-2; F1, F3, F6; +-- the unreviewed publication of Step 4, F2, F4, F11, whose reviewed +-- replacement comes with M5) +-- --------------------------------------------------------------------------- +drop function public.create_anatomical_sheet(text, text, text, jsonb, text, public.sheet_visibility, boolean); +drop function public.fork_anatomical_sheet(uuid, text, text, public.sheet_visibility); +drop function public.set_sheet_visibility(uuid, public.sheet_visibility); +drop function public.publish_sheet_version(uuid); +drop function private.copy_sheet_assets(uuid, uuid, uuid, jsonb); + +-- --------------------------------------------------------------------------- +-- Policies: the reader predicate and the staff branch (F8, F15); no write +-- policy (F9) +-- --------------------------------------------------------------------------- +drop policy anatomical_sheets_select_usable_or_editable on public.anatomical_sheets; +drop policy anatomical_sheets_update_editor on public.anatomical_sheets; +drop policy anatomical_sheet_versions_select on public.anatomical_sheet_versions; +drop policy anatomical_sheet_versions_update_own_draft on public.anatomical_sheet_versions; +drop policy anatomical_sheet_assets_select on public.anatomical_sheet_assets; + +create policy anatomical_sheets_select_catalog + on public.anatomical_sheets + for select + to authenticated + using ( + private.can_read_catalog_sheet((select auth.uid()), id) + or private.caller_can_see_official_sheet(id) + ); + +create policy anatomical_sheet_versions_select_catalog + on public.anatomical_sheet_versions + for select + to authenticated + using ( + (status in ('published', 'deprecated') and private.can_read_catalog_sheet((select auth.uid()), sheet_id)) + or private.caller_can_see_official_sheet(sheet_id) + ); + +create policy anatomical_sheet_assets_select_catalog + on public.anatomical_sheet_assets + for select + to authenticated + using ( + (uploaded_at is not null + and private.can_read_catalog_sheet((select auth.uid()), sheet_id) + and private.asset_in_catalog_version(id, sheet_id)) + or private.caller_can_see_official_sheet(sheet_id) + ); + +-- Storage read (§9.4): readers, the drawings of published or deprecated +-- versions of catalogue sheets; capability holders at aal2, every uploaded +-- drawing of an official sheet; nobody, the object of a pending row. +create or replace function private.can_read_sheet_asset_object(p_user_id uuid, p_object_name text) +returns boolean +language sql +stable +security definer +set search_path = '' +as $$ + select exists ( + select 1 + from public.anatomical_sheet_assets a + where a.sha256 = left(p_object_name, 64) + and p_object_name = a.sha256 || '.svg' + and a.uploaded_at is not null + and ( + (p_user_id = (select auth.uid()) and private.caller_can_see_official_sheet(a.sheet_id)) + or (private.can_read_catalog_sheet(p_user_id, a.sheet_id) + and private.asset_in_catalog_version(a.id, a.sheet_id)) + ) + ); +$$; + +comment on function private.can_read_sheet_asset_object(uuid, text) is + 'Storage read predicate for bucket anatomical-sheet-assets (contract §9.4): confirmed object of a published or deprecated version of a catalogue sheet for readers, of any official sheet for capability holders at aal2.'; + +-- The visibility branch is gone from every predicate (§5.3). +drop function private.can_use_sheet(uuid, uuid); + +create policy anatomical_catalog_grants_select + on public.anatomical_catalog_grants + for select + to authenticated + using ( + user_id = (select auth.uid()) + or (private.has_mfa() and private.is_platform_owner((select auth.uid()))) + or (grant_kind <> 'catalog_reader' and private.caller_is_catalog_staff()) + ); + +-- --------------------------------------------------------------------------- +-- Privileges. Supabase default privileges give ALL on public tables to anon, +-- authenticated and service_role: every catalogue and identity table starts +-- from zero for the three (F12, F17). The service key keeps the RPCs granted +-- to it (worker, upload confirmation, operator read) and stays a GoTrue admin +-- credential no table privilege can bound (contract §5.7.5, §13). +-- --------------------------------------------------------------------------- +revoke all on public.species from public, anon, authenticated, service_role; +revoke all on public.anatomical_sheets from public, anon, authenticated, service_role; +revoke all on public.anatomical_sheet_versions from public, anon, authenticated, service_role; +revoke all on public.anatomical_sheet_assets from public, anon, authenticated, service_role; +revoke all on public.anatomical_catalog_grants from public, anon, authenticated, service_role; +revoke all on public.profile_roles from service_role; +revoke all on public.profiles from service_role; + +grant select on public.species to authenticated; +-- Reader columns (§5.3): no last_version_number, updated_at, ownership, +-- provenance or deletion stamp; the admin space reads those through its RPCs. +grant select (id, species_id, name, slug, description, is_official, status, current_version_id, + archived_at, created_at) + on public.anatomical_sheets to authenticated; +grant select (id, sheet_id, version_number, status, document_schema_version, content, change_note, + published_at, deprecated_at, created_at) + on public.anatomical_sheet_versions to authenticated; +grant select (id, sheet_id, sha256, byte_size, content_type, file_name, uploaded_at, created_at) + on public.anatomical_sheet_assets to authenticated; +grant select on public.anatomical_catalog_grants to authenticated; + +alter table public.anatomical_catalog_grants enable row level security; + +revoke all on function public.grant_platform_role(uuid, public.platform_role) from public, anon, service_role; +revoke all on function public.revoke_platform_role(uuid, public.platform_role, text) from public, anon, service_role; +grant execute on function public.grant_platform_role(uuid, public.platform_role) to authenticated; +grant execute on function public.revoke_platform_role(uuid, public.platform_role, text) to authenticated; + +revoke all on function public.grant_catalog_right(uuid, public.catalog_grant_kind, text, text, timestamptz) from public, anon, service_role; +revoke all on function public.revoke_catalog_right(uuid, text) from public, anon, service_role; +revoke all on function public.list_catalog_grants() from public, anon, service_role; +revoke all on function public.lookup_catalog_account(text) from public, anon, service_role; +grant execute on function public.grant_catalog_right(uuid, public.catalog_grant_kind, text, text, timestamptz) to authenticated; +grant execute on function public.revoke_catalog_right(uuid, text) to authenticated; +grant execute on function public.list_catalog_grants() to authenticated; +grant execute on function public.lookup_catalog_account(text) to authenticated; + +-- Private helpers: EXECUTE for nobody, except the predicates the policies +-- name, granted to authenticated. +revoke all on function private.has_mfa() from public, anon, authenticated, service_role; +revoke all on function private.has_aal2_session() from public, anon, authenticated, service_role; +revoke all on function private.is_confirmed_active_account(uuid) from public, anon, authenticated, service_role; +revoke all on function private.has_verified_totp(uuid) from public, anon, authenticated, service_role; +revoke all on function private.guard_catalog_grant() from public, anon, authenticated, service_role; +revoke all on function private.grant_active(uuid, public.catalog_grant_kind) from public, anon, authenticated, service_role; +revoke all on function private.caller_has(public.catalog_grant_kind) from public, anon, authenticated, service_role; +revoke all on function private.caller_is_catalog_staff() from public, anon, authenticated, service_role; +revoke all on function private.can_read_official_catalog(uuid) from public, anon, authenticated, service_role; +revoke all on function private.historical_sheet_id() from public, anon, authenticated, service_role; +revoke all on function private.is_catalog_sheet(uuid) from public, anon, authenticated, service_role; +revoke all on function private.can_read_catalog_sheet(uuid, uuid) from public, anon, authenticated, service_role; +revoke all on function private.caller_can_see_official_sheet(uuid) from public, anon, authenticated, service_role; +revoke all on function private.asset_in_catalog_version(uuid, uuid) from public, anon, authenticated, service_role; +revoke all on function private.can_edit_sheet(uuid, uuid) from public, anon, authenticated, service_role; +revoke all on function private.require_actor() from public, anon, authenticated, service_role; +revoke all on function private.consume_catalog_write_budget(uuid) from public, anon, authenticated, service_role; +revoke all on function private.require_rights_owner() from public, anon, authenticated, service_role; +revoke all on function private.lock_platform_roles() from public, anon, authenticated, service_role; +revoke all on function private.check_role_actor(uuid) from public, anon, authenticated, service_role; +revoke all on function private.assign_platform_role(uuid, uuid, public.platform_role) from public, anon, authenticated, service_role; +revoke all on function private.withdraw_platform_role(uuid, uuid, public.platform_role, text) from public, anon, authenticated, service_role; +revoke all on function private.guard_sheet_version_delete() from public, anon, authenticated, service_role; +revoke all on function private.guard_sheet_asset() from public, anon, authenticated, service_role; +revoke all on function private.guard_historical_sheet() from public, anon, authenticated, service_role; +revoke all on function private.can_read_sheet_asset_object(uuid, text) from public, anon, authenticated, service_role; +revoke all on private.catalog_write_budgets from public, anon, authenticated, service_role; + +grant execute on function private.has_mfa() to authenticated; +grant execute on function private.is_platform_owner(uuid) to authenticated; +grant execute on function private.caller_is_catalog_staff() to authenticated; +grant execute on function private.can_read_catalog_sheet(uuid, uuid) to authenticated; +grant execute on function private.caller_can_see_official_sheet(uuid) to authenticated; +grant execute on function private.asset_in_catalog_version(uuid, uuid) to authenticated; +grant execute on function private.can_read_sheet_asset_object(uuid, text) to authenticated; diff --git a/supabase/migrations/20261028110000_sheet_review_workflow.sql b/supabase/migrations/20261028110000_sheet_review_workflow.sql new file mode 100644 index 00000000..867532db --- /dev/null +++ b/supabase/migrations/20261028110000_sheet_review_workflow.sql @@ -0,0 +1,1624 @@ +-- V1-2.1 M5 sheet_review_workflow. Contract: +-- docs/development/V1-2_ANATOMICAL_SHEETS.md §6 (lifecycle, review, verdict, +-- publication), §7 (species, new sheets), §9 (drawings), §12.2 (SQL authority), +-- §12.3 (M5), §14.3 (working copy). Applied together with M4. +-- +-- M5 adds the reviewed authoring workflow that replaces the Step 4 lifecycle: +-- * version provenance and review columns, a sheet working-copy column; +-- * triggers: revision bump and author set on every content write, the +-- draft freeze while a round runs, the extended publication/immutability +-- guard; the historical sheet stays writable only for the seed; +-- * review rounds, comments and acknowledgments; +-- * the authoring RPCs: create an official sheet, open a draft, save, submit, +-- withdraw, comment, acknowledge, approve or request changes, publish, +-- deprecate, archive, restore, delete a draft; the equine working copy; +-- * species RPCs (create inactive, edit inactive, activate, rename); +-- * catalogue and version read RPCs; +-- * uploads: register (historical sheet refused), confirm with a Storage +-- existence and size check (F7), an INSERT policy for the pending key, the +-- bucket limit lowered to 2 MiB, an operator read RPC; +-- * the SQL business mirror removed, one declared status check kept (§12.2). +-- The verdict itself is written by the worker RPCs of M6: until then a round +-- never leaves `verifying` except a withdrawal, so nothing is published +-- outside the pgTAP fixtures that stand in for the worker. + +-- =========================================================================== +-- 1. Enums, version/sheet columns, review tables +-- =========================================================================== +create type public.sheet_round_status as enum ( + 'verifying', 'open', 'approved', 'changes_requested', 'withdrawn', 'verification_failed' +); +create type public.sheet_verification_outcome as enum ('failed', 'unavailable'); + +alter table public.anatomical_sheet_versions + add column revision integer not null default 0 + constraint anatomical_sheet_versions_revision_nonneg check (revision >= 0), + add column authors uuid[] not null default '{}', + add column source_version_id uuid references public.anatomical_sheet_versions (id) on delete set null, + add column published_review_id uuid, + add column document_fingerprint text + constraint anatomical_sheet_versions_fingerprint_format + check (document_fingerprint is null or document_fingerprint ~ '^[0-9a-f]{64}$'), + -- A drawing is at most 2 MiB (archive cap, §9.1): new rows only. + add constraint anatomical_sheet_versions_published_fingerprint + check (status <> 'published' or document_fingerprint is not null); + +alter table public.anatomical_sheets + add column working_copy_source_version_id uuid references public.anatomical_sheet_versions (id) on delete set null; + +comment on column public.anatomical_sheet_versions.authors is + 'Author set (contract §5.5): the account that created the draft and every account that changed its content since. Maintained by the content trigger, frozen into the round at submission.'; +comment on column public.anatomical_sheet_versions.source_version_id is + 'The base of a derived draft: set only when the source is a version published through a V1-2 round (contract §6.2).'; + +create table public.anatomical_sheet_reviews ( + id uuid primary key default gen_random_uuid(), + version_id uuid not null references public.anatomical_sheet_versions (id) on delete restrict, + round integer not null constraint anatomical_sheet_reviews_round_positive check (round > 0), + revision integer not null, + authors uuid[] not null, + submitted_by uuid not null references public.profiles (id) on delete restrict, + submitted_at timestamptz not null default now(), + submission_note text constraint anatomical_sheet_reviews_submission_note_length check (char_length(submission_note) <= 1000), + status public.sheet_round_status not null default 'verifying', + attempts integer not null default 0, + lease_token uuid, + locked_at timestamptz, + verdict jsonb constraint anatomical_sheet_reviews_verdict_object check (verdict is null or jsonb_typeof(verdict) = 'object'), + verified_at timestamptz, + verified_with text constraint anatomical_sheet_reviews_verified_with_length check (char_length(verified_with) <= 100), + failure_outcome public.sheet_verification_outcome, + failure_code text constraint anatomical_sheet_reviews_failure_code_format check (failure_code ~ '^[a-z][a-z0-9_.]{0,60}$'), + decided_by uuid references public.profiles (id) on delete restrict, + decided_at timestamptz, + decision_note text constraint anatomical_sheet_reviews_decision_note_length check (char_length(decision_note) <= 4000), + withdrawn_by uuid references public.profiles (id) on delete restrict, + withdrawn_at timestamptz, + withdrawal_note text constraint anatomical_sheet_reviews_withdrawal_note_length check (char_length(withdrawal_note) <= 1000), + created_at timestamptz not null default now(), + constraint anatomical_sheet_reviews_round_unique unique (version_id, round) +); + +comment on table public.anatomical_sheet_reviews is + 'Review rounds of a draft version (contract §6.3). One row per round; one non-terminal round per version at a time; the verdict is written by the worker RPCs (M6).'; + +-- One non-terminal round per version (contract §6.1). +create unique index anatomical_sheet_reviews_one_open + on public.anatomical_sheet_reviews (version_id) + where status in ('verifying', 'open', 'approved'); +create index anatomical_sheet_reviews_verifying_idx + on public.anatomical_sheet_reviews (submitted_at) + where status = 'verifying'; + +alter table public.anatomical_sheet_versions + add constraint anatomical_sheet_versions_published_review_fkey + foreign key (published_review_id) references public.anatomical_sheet_reviews (id) on delete restrict; + +create table public.anatomical_sheet_review_comments ( + id uuid primary key default gen_random_uuid(), + review_id uuid not null references public.anatomical_sheet_reviews (id) on delete cascade, + author uuid not null references public.profiles (id) on delete restrict, + group_key text constraint anatomical_sheet_review_comments_group_key_format check (group_key ~ '^(general|view:|zone:)'), + body text not null constraint anatomical_sheet_review_comments_body_length check (char_length(body) between 1 and 4000), + created_at timestamptz not null default now() +); + +comment on table public.anatomical_sheet_review_comments is + 'Append-only comments on a round (contract §6.3): author, body, optional group key.'; +create index anatomical_sheet_review_comments_review_idx + on public.anatomical_sheet_review_comments (review_id, created_at); + +create table public.anatomical_sheet_review_acknowledgments ( + id uuid primary key default gen_random_uuid(), + review_id uuid not null references public.anatomical_sheet_reviews (id) on delete cascade, + group_key text not null constraint anatomical_sheet_review_acks_group_key_format check (group_key ~ '^(general|view:|zone:)'), + group_digest text not null constraint anatomical_sheet_review_acks_digest_format check (group_digest ~ '^[0-9a-f]{64}$'), + reviewer uuid not null references public.profiles (id) on delete restrict, + created_at timestamptz not null default now(), + constraint anatomical_sheet_review_acks_unique unique (review_id, group_key, reviewer) +); + +comment on table public.anatomical_sheet_review_acknowledgments is + 'Append-only "groupe lu" records (contract §6.3): a reviewer outside the authors acknowledges a group against the verdict''s digest.'; +create index anatomical_sheet_review_acks_reviewer_idx + on public.anatomical_sheet_review_acknowledgments (reviewer); + +-- =========================================================================== +-- 2. SQL authority: drop the business mirror, keep the structural guards, +-- add the declared status check (contract §12.2) +-- =========================================================================== +drop function private.sheet_document_issues(jsonb); +drop function private.sheet_document_view_issues(jsonb); +drop function private.sheet_document_annotation_issues(jsonb); +drop function private.sheet_document_duplicate_issues(jsonb); +drop function private.sheet_document_reference_issues(jsonb); +drop function private.append_issue(text[], text); + +-- Declared status mirror (contract §12.2): a structural walk refusing any +-- element whose review_status is absent, to_confirm or inherited. Kept so a +-- worker defect can never make unread content official; follows the schema's +-- default (absent = inherited). Returns true when every element is reviewed. +create or replace function private.sheet_all_reviewed(p_doc jsonb) +returns boolean +language sql +immutable +set search_path = '' +as $$ + select not exists ( + -- annotations: review_status on each + select 1 from jsonb_array_elements(coalesce(p_doc -> 'annotations', '[]'::jsonb)) a + where coalesce(a ->> 'review_status', 'inherited') <> 'reviewed' + ) and not exists ( + -- finding categories: review_status on each category + select 1 + from jsonb_array_elements(coalesce(p_doc -> 'finding_zones', '[]'::jsonb)) z, + jsonb_array_elements(coalesce(z -> 'categories', '[]'::jsonb)) c + where coalesce(c ->> 'review_status', 'inherited') <> 'reviewed' + ) and not exists ( + -- finding nodes at every depth (categories[*].children and below) + select 1 + from jsonb_array_elements(coalesce(p_doc -> 'finding_zones', '[]'::jsonb)) z, + jsonb_array_elements(coalesce(z -> 'categories', '[]'::jsonb)) c, + jsonb_path_query(c, '$.children[*].**{0 to 64}') n + where jsonb_typeof(n) = 'object' and n ? 'id' + and coalesce(n ->> 'review_status', 'inherited') <> 'reviewed' + ); +$$; + +comment on function private.sheet_all_reviewed(jsonb) is + 'Declared defensive status check (contract §12.2): true when every annotation, finding category and finding node is reviewed (an absent review_status counts as inherited, so it is refused).'; + +-- =========================================================================== +-- 3. Triggers: revision, author set, freeze, extended publication guard +-- =========================================================================== +-- A content write bumps the revision and adds the actor to the author set +-- (contract §5.5, §6.2). A non-terminal round freezes the content. A content +-- write with no authenticated actor is refused for every sheet except the +-- historical one (its converging seed). +create or replace function private.on_sheet_version_content() +returns trigger +language plpgsql +security definer +set search_path = '' +as $$ +declare + v_actor uuid := auth.uid(); +begin + if tg_op = 'UPDATE' and new.content = old.content then + return new; + end if; + if tg_op = 'UPDATE' and exists ( + select 1 from public.anatomical_sheet_reviews r + where r.version_id = new.id and r.status in ('verifying', 'open', 'approved') + ) then + raise exception 'draft.frozen' using errcode = '55000'; + end if; + if v_actor is null and new.sheet_id <> private.historical_sheet_id() then + raise exception 'content write needs an authenticated actor' using errcode = '42501'; + end if; + if tg_op = 'UPDATE' then + new.revision := old.revision + 1; + end if; + if v_actor is not null and not (new.authors @> array[v_actor]) then + new.authors := new.authors || v_actor; + end if; + return new; +end; +$$; + +create trigger anatomical_sheet_versions_on_content + before insert or update of content on public.anatomical_sheet_versions + for each row execute function private.on_sheet_version_content(); + +-- Extended immutability guard (contract §6.8), replacing the base version. +create or replace function private.guard_sheet_version_update() +returns trigger +language plpgsql +set search_path = '' +as $$ +begin + if new.id <> old.id or new.sheet_id <> old.sheet_id or new.version_number <> old.version_number then + raise exception 'id, sheet_id and version_number are immutable' using errcode = '42501'; + end if; + + if old.status = 'deprecated' then + raise exception 'deprecated version % is frozen', old.id using errcode = '42501'; + end if; + + if old.status = 'published' then + -- Only the deprecation transition, and it changes no V1-2 column. + if new.status = 'deprecated' + and new.content = old.content + and new.document_schema_version = old.document_schema_version + and new.change_note = old.change_note + and new.created_by is not distinct from old.created_by + and new.published_at = old.published_at + and new.published_by is not distinct from old.published_by + and new.created_at = old.created_at + and new.revision = old.revision + and new.authors = old.authors + and new.source_version_id is not distinct from old.source_version_id + and new.published_review_id is not distinct from old.published_review_id + and new.document_fingerprint is not distinct from old.document_fingerprint then + return new; + end if; + raise exception 'published version % is immutable', old.id using errcode = '42501'; + end if; + + -- old.status = 'draft' + if new.status = 'deprecated' then + raise exception 'a draft cannot be deprecated; delete it' using errcode = '55000'; + end if; + if new.status = 'published' then + -- A draft is published only through the gate: an approved round of this + -- version and revision whose verdict passed, named by published_review_id. + if new.published_review_id is null or not exists ( + select 1 from public.anatomical_sheet_reviews r + where r.id = new.published_review_id + and r.version_id = old.id + and r.revision = old.revision + and r.status = 'approved' + and r.verdict is not null + ) then + raise exception 'publish.review.missing' using errcode = '42501'; + end if; + end if; + return new; +end; +$$; + +-- =========================================================================== +-- 4. Authoring helpers and RPCs +-- =========================================================================== +-- Require the sheet_editor capability at aal2 on an official, non-deleted +-- sheet other than the historical one (writes), returning the actor. +create or replace function private.require_sheet_author(p_sheet_id uuid) +returns uuid +language plpgsql +stable +security definer +set search_path = '' +as $$ +declare + v_actor uuid := private.require_actor(); +begin + if p_sheet_id = private.historical_sheet_id() then + raise exception 'sheet.historical_read_only' using errcode = '42501'; + end if; + if not private.can_edit_sheet(v_actor, p_sheet_id) then + raise exception 'rights.capability' using errcode = '42501'; + end if; + return v_actor; +end; +$$; + +-- The sheet_publisher capability at aal2 on an official, non-deleted sheet. +create or replace function private.require_sheet_publisher(p_sheet_id uuid) +returns uuid +language plpgsql +stable +security definer +set search_path = '' +as $$ +declare + v_actor uuid := private.require_actor(); +begin + if not (private.caller_has('sheet_publisher') and exists ( + select 1 from public.anatomical_sheets s + where s.id = p_sheet_id and s.is_official and s.status <> 'deleted' + )) then + raise exception 'rights.capability' using errcode = '42501'; + end if; + return v_actor; +end; +$$; + +-- Create an official sheet and its draft v1 from a core-built document. +create or replace function public.create_official_sheet( + slug text, + document jsonb +) +returns uuid +language plpgsql +volatile +security definer +set search_path = '' +as $$ +#variable_conflict use_column +declare + v_actor uuid := private.require_actor(); + v_species text := document ->> 'species_id'; + v_name text; + v_description text; + v_sheet uuid; +begin + if not private.caller_has('sheet_editor') then + raise exception 'rights.capability' using errcode = '42501'; + end if; + if not private.sheet_document_has_shape(document) then + raise exception 'document.shape' using errcode = '23514'; + end if; + v_name := left(coalesce(document -> 'name' ->> 'fr', document -> 'name' ->> 'en', 'Sans nom'), 120); + v_description := left(coalesce(document -> 'description' ->> 'fr', ''), 2000); + -- An official sheet accepts an active or inactive species, never `other` (§7.2). + if v_species is null or v_species = 'other' + or not exists (select 1 from public.species s where s.id = v_species) then + raise exception 'sheet.species_invalid' using errcode = 'P0001'; + end if; + perform private.consume_catalog_write_budget(v_actor); + + insert into public.anatomical_sheets (species_id, name, slug, description, creator_user_id, is_official, visibility) + values (v_species, v_name, slug, v_description, null, true, 'private') + returning id into v_sheet; + + perform private.log_event( + v_actor, 'anatomical_sheet.created', 'anatomical_sheet', v_sheet, null, null, + jsonb_build_object('species_id', v_species, 'official', true) + ); + perform private.insert_sheet_draft(v_actor, v_sheet, document, 'Brouillon initial'); + return v_sheet; +end; +$$; + +-- Open the single draft of an official sheet, from a published version. +create or replace function public.create_sheet_draft( + sheet_id uuid, + from_version_id uuid default null, + change_note text default '' +) +returns uuid +language plpgsql +volatile +security definer +set search_path = '' +as $$ +#variable_conflict use_column +declare + v_actor uuid := private.require_sheet_author(sheet_id); + v_source public.anatomical_sheet_versions%rowtype; + v_base uuid; + v_draft uuid; +begin + perform 1 from public.anatomical_sheets s where s.id = create_sheet_draft.sheet_id and s.status = 'active' for no key update; + if not found then + raise exception 'sheet.inactive' using errcode = '55000'; + end if; + select v.* into v_source + from public.anatomical_sheet_versions v + where v.id = coalesce(from_version_id, (select current_version_id from public.anatomical_sheets where id = create_sheet_draft.sheet_id)) + and v.sheet_id = create_sheet_draft.sheet_id and v.status <> 'draft'; + if v_source.id is null then + raise exception 'sheet.no_source' using errcode = 'P0002'; + end if; + perform private.consume_catalog_write_budget(v_actor); + + -- Base only from a version published through a V1-2 round (§6.2). + v_base := case when v_source.published_review_id is not null then v_source.id else null end; + v_draft := private.insert_sheet_draft(v_actor, sheet_id, v_source.content, change_note); + update public.anatomical_sheet_versions set source_version_id = v_base where id = v_draft; + return v_draft; +end; +$$; + +-- Explicit save with a revision check (contract §6.2). +create or replace function public.save_sheet_draft( + version_id uuid, + expected_revision integer, + document jsonb, + change_note text default '' +) +returns jsonb +language plpgsql +volatile +security definer +set search_path = '' +as $$ +#variable_conflict use_column +declare + v_row public.anatomical_sheet_versions%rowtype; + v_actor uuid; +begin + select v.* into v_row from public.anatomical_sheet_versions v where v.id = save_sheet_draft.version_id for update; + if v_row.id is null then + raise exception 'not_found' using errcode = '42501'; + end if; + v_actor := private.require_sheet_author(v_row.sheet_id); + if v_row.status <> 'draft' then + raise exception 'draft.not_a_draft' using errcode = '55000'; + end if; + if exists (select 1 from public.anatomical_sheet_reviews r + where r.version_id = v_row.id and r.status in ('verifying', 'open', 'approved')) then + raise exception 'draft.frozen' using errcode = '55000'; + end if; + if save_sheet_draft.expected_revision is distinct from v_row.revision then + raise exception 'draft_conflict' using errcode = 'P0001'; + end if; + if not private.sheet_document_has_shape(document) then + raise exception 'document.shape' using errcode = '23514'; + end if; + if (document ->> 'species_id') is distinct from (select species_id from public.anatomical_sheets where id = v_row.sheet_id) then + raise exception 'document.species' using errcode = '23514'; + end if; + if octet_length(document::text) > 2097152 then + raise exception 'document.too_large' using errcode = '23514'; + end if; + if document = v_row.content then + raise exception 'draft.unchanged' using errcode = 'P0001'; + end if; + perform private.consume_catalog_write_budget(v_actor); + + update public.anatomical_sheet_versions + set content = document, change_note = coalesce(save_sheet_draft.change_note, '') + where id = v_row.id; + + perform private.log_event( + v_actor, 'anatomical_sheet_version.saved', 'anatomical_sheet_version', v_row.id, null, null, + jsonb_build_object('sheet_id', v_row.sheet_id, 'revision', v_row.revision + 1) + ); + return jsonb_build_object('revision', v_row.revision + 1); +end; +$$; + +-- =========================================================================== +-- 5. Review rounds: submit, withdraw, comment, acknowledge, decide +-- =========================================================================== +create or replace function public.submit_sheet_review( + version_id uuid, + expected_revision integer, + note text default null +) +returns uuid +language plpgsql +volatile +security definer +set search_path = '' +as $$ +#variable_conflict use_column +declare + v_row public.anatomical_sheet_versions%rowtype; + v_actor uuid; + v_round integer; + v_id uuid; +begin + select v.* into v_row from public.anatomical_sheet_versions v where v.id = submit_sheet_review.version_id for update; + if v_row.id is null then + raise exception 'not_found' using errcode = '42501'; + end if; + v_actor := private.require_sheet_author(v_row.sheet_id); + if v_row.status <> 'draft' then + raise exception 'draft.not_a_draft' using errcode = '55000'; + end if; + if not exists (select 1 from public.anatomical_sheets s where s.id = v_row.sheet_id and s.status = 'active') then + raise exception 'sheet.inactive' using errcode = '55000'; + end if; + if submit_sheet_review.expected_revision is distinct from v_row.revision then + raise exception 'draft_conflict' using errcode = 'P0001'; + end if; + if exists (select 1 from public.anatomical_sheet_reviews r + where r.version_id = v_row.id and r.status in ('verifying', 'open', 'approved')) then + raise exception 'round.open' using errcode = '55000'; + end if; + if char_length(note) > 1000 then + raise exception 'invalid_input' using errcode = 'P0001'; + end if; + perform private.consume_catalog_write_budget(v_actor); + + select coalesce(max(round), 0) + 1 into v_round + from public.anatomical_sheet_reviews where version_id = v_row.id; + + insert into public.anatomical_sheet_reviews ( + version_id, round, revision, authors, submitted_by, submission_note, status + ) + values (v_row.id, v_round, v_row.revision, v_row.authors, v_actor, note, 'verifying') + returning id into v_id; + + perform private.log_event( + v_actor, 'anatomical_sheet_review.submitted', 'anatomical_sheet_review', v_id, null, null, + jsonb_build_object('sheet_id', v_row.sheet_id, 'version_id', v_row.id, 'round', v_round, 'revision', v_row.revision) + ); + return v_id; +end; +$$; + +-- Withdraw a round in verifying, open or approved; the draft unfreezes. +create or replace function public.withdraw_sheet_review(review_id uuid, note text default null) +returns uuid +language plpgsql +volatile +security definer +set search_path = '' +as $$ +#variable_conflict use_column +declare + v_review public.anatomical_sheet_reviews%rowtype; + v_sheet uuid; + v_actor uuid; +begin + select r.* into v_review from public.anatomical_sheet_reviews r where r.id = withdraw_sheet_review.review_id for update; + if v_review.id is null then + raise exception 'not_found' using errcode = '42501'; + end if; + select sheet_id into v_sheet from public.anatomical_sheet_versions where id = v_review.version_id; + v_actor := private.require_sheet_author(v_sheet); + if v_review.status not in ('verifying', 'open', 'approved') then + raise exception 'round.terminal' using errcode = '55000'; + end if; + if char_length(note) > 1000 then + raise exception 'invalid_input' using errcode = 'P0001'; + end if; + + update public.anatomical_sheet_reviews + set status = 'withdrawn', withdrawn_by = v_actor, withdrawn_at = now(), withdrawal_note = note + where id = v_review.id; + perform private.log_event( + v_actor, 'anatomical_sheet_review.withdrawn', 'anatomical_sheet_review', v_review.id, null, null, + jsonb_build_object('sheet_id', v_sheet, 'round', v_review.round) + ); + return v_review.id; +end; +$$; + +-- A comment on a round: editors, reviewers and publishers. +create or replace function public.comment_sheet_review( + review_id uuid, + body text, + group_key text default null +) +returns uuid +language plpgsql +volatile +security definer +set search_path = '' +as $$ +#variable_conflict use_column +declare + v_actor uuid := private.require_actor(); + v_review public.anatomical_sheet_reviews%rowtype; + v_sheet uuid; + v_id uuid; +begin + if not private.caller_is_catalog_staff() then + raise exception 'rights.capability' using errcode = '42501'; + end if; + select r.* into v_review from public.anatomical_sheet_reviews r where r.id = comment_sheet_review.review_id; + if v_review.id is null then + raise exception 'not_found' using errcode = '42501'; + end if; + select sheet_id into v_sheet from public.anatomical_sheet_versions where id = v_review.version_id; + if char_length(body) not between 1 and 4000 + or (group_key is not null and group_key !~ '^(general|view:|zone:)') then + raise exception 'invalid_input' using errcode = 'P0001'; + end if; + perform private.consume_catalog_write_budget(v_actor); + + insert into public.anatomical_sheet_review_comments (review_id, author, group_key, body) + values (comment_sheet_review.review_id, v_actor, group_key, body) + returning id into v_id; + perform private.log_event( + v_actor, 'anatomical_sheet_review.commented', 'anatomical_sheet_review', v_review.id, null, null, + jsonb_build_object('sheet_id', v_sheet, 'comment_id', v_id) + ); + return v_id; +end; +$$; + +-- The verdict's group of a key, with its digest (contract §6.3). The verdict +-- carries `groups` as an array of {key, digest, coverable}. +create or replace function private.verdict_group_digest(p_verdict jsonb, p_key text) +returns text +language sql +immutable +set search_path = '' +as $$ + select g ->> 'digest' + from jsonb_array_elements(coalesce(p_verdict -> 'groups', '[]'::jsonb)) g + where g ->> 'key' = p_key + limit 1; +$$; + +-- Acknowledge a group of an `open` round, against the verdict's digest. +create or replace function public.acknowledge_sheet_review_group( + review_id uuid, + group_key text, + group_digest text +) +returns uuid +language plpgsql +volatile +security definer +set search_path = '' +as $$ +#variable_conflict use_column +declare + v_actor uuid := private.require_actor(); + v_review public.anatomical_sheet_reviews%rowtype; + v_sheet uuid; + v_group jsonb; + v_id uuid; +begin + if not private.caller_has('sheet_reviewer') then + raise exception 'rights.capability' using errcode = '42501'; + end if; + select r.* into v_review from public.anatomical_sheet_reviews r where r.id = acknowledge_sheet_review_group.review_id for update; + if v_review.id is null then + raise exception 'not_found' using errcode = '42501'; + end if; + select sheet_id into v_sheet from public.anatomical_sheet_versions where id = v_review.version_id; + if v_review.status <> 'open' then + raise exception 'round.not_open' using errcode = '55000'; + end if; + -- No author of the round acknowledges it (contract §5.5). + if v_review.authors @> array[v_actor] then + raise exception 'review.separation' using errcode = '42501'; + end if; + -- The group exists in the verdict, its digest matches, and it is coverable + -- (no to_confirm or inherited element left in it). + select g into v_group + from jsonb_array_elements(coalesce(v_review.verdict -> 'groups', '[]'::jsonb)) g + where g ->> 'key' = acknowledge_sheet_review_group.group_key limit 1; + if v_group is null or v_group ->> 'digest' is distinct from acknowledge_sheet_review_group.group_digest then + raise exception 'review.digest' using errcode = 'P0001'; + end if; + if coalesce((v_group ->> 'coverable')::boolean, false) is not true then + raise exception 'review.uncoverable' using errcode = 'P0001'; + end if; + perform private.consume_catalog_write_budget(v_actor); + + insert into public.anatomical_sheet_review_acknowledgments (review_id, group_key, group_digest, reviewer) + values (acknowledge_sheet_review_group.review_id, group_key, group_digest, v_actor) + on conflict (review_id, group_key, reviewer) do update set group_digest = excluded.group_digest, created_at = now() + returning id into v_id; + perform private.log_event( + v_actor, 'anatomical_sheet_review.acknowledged', 'anatomical_sheet_review', v_review.id, null, null, + jsonb_build_object('sheet_id', v_sheet, 'group_key', group_key) + ); + return v_id; +end; +$$; + +-- The groups the round must cover, uncovered so far (contract §6.3, §6.7): +-- every verdict group when there is no base; for a derived version, every +-- group whose digest differs from the base's group of the same key; a group +-- is covered by a current or carried acknowledgment (same digest, a reviewer +-- outside the authors with an active grant). +create or replace function private.uncovered_review_groups(p_review_id uuid) +returns text[] +language plpgsql +stable +security definer +set search_path = '' +as $$ +declare + v_review public.anatomical_sheet_reviews%rowtype; + v_base_verdict jsonb; + v_result text[] := '{}'; + g record; + v_base_digest text; +begin + select * into v_review from public.anatomical_sheet_reviews where id = p_review_id; + -- The base round's verdict, if the version derives from one. + select r.verdict into v_base_verdict + from public.anatomical_sheet_versions v + join public.anatomical_sheet_reviews r on r.id = v.published_review_id + where v.id = (select source_version_id from public.anatomical_sheet_versions where id = v_review.version_id); + + for g in + select e ->> 'key' as key, e ->> 'digest' as digest + from jsonb_array_elements(coalesce(v_review.verdict -> 'groups', '[]'::jsonb)) e + loop + v_base_digest := private.verdict_group_digest(v_base_verdict, g.key); + -- A group equal to its base (same digest) is already covered by the base. + if v_base_digest is not null and v_base_digest = g.digest then + continue; + end if; + -- Covered by an acknowledgment of this or an earlier round, same digest, + -- by a reviewer outside the round's authors whose grant is active now. + if not exists ( + select 1 + from public.anatomical_sheet_review_acknowledgments a + join public.anatomical_sheet_reviews ar on ar.id = a.review_id + where ar.version_id = v_review.version_id + and a.group_key = g.key + and a.group_digest = g.digest + and not (v_review.authors @> array[a.reviewer]) + and private.grant_active(a.reviewer, 'sheet_reviewer') + ) then + v_result := v_result || g.key; + end if; + end loop; + return v_result; +end; +$$; + +-- Approve or request changes on an `open` round (contract §6.7). +create or replace function public.decide_sheet_review( + review_id uuid, + approve boolean, + note text +) +returns uuid +language plpgsql +volatile +security definer +set search_path = '' +as $$ +#variable_conflict use_column +declare + v_actor uuid := private.require_actor(); + v_review public.anatomical_sheet_reviews%rowtype; + v_version public.anatomical_sheet_versions%rowtype; + v_uncovered text[]; +begin + if not private.caller_has('sheet_reviewer') then + raise exception 'rights.capability' using errcode = '42501'; + end if; + if char_length(note) not between 1 and 4000 then + raise exception 'invalid_input' using errcode = 'P0001'; + end if; + select r.* into v_review from public.anatomical_sheet_reviews r where r.id = decide_sheet_review.review_id for update; + if v_review.id is null then + raise exception 'not_found' using errcode = '42501'; + end if; + if v_review.status <> 'open' then + raise exception 'round.not_open' using errcode = '55000'; + end if; + if v_review.authors @> array[v_actor] then + raise exception 'review.separation' using errcode = '42501'; + end if; + select v.* into v_version from public.anatomical_sheet_versions v where v.id = v_review.version_id for update; + perform private.consume_catalog_write_budget(v_actor); + + if approve then + -- Publishable content: verdict present on the current revision, no + -- to_confirm / inherited element, groups covered. + if v_review.verdict is null or v_review.revision <> v_version.revision then + raise exception 'verdict.stale' using errcode = 'P0001'; + end if; + if not private.sheet_all_reviewed(v_version.content) then + raise exception 'publish.inherited.present' using errcode = 'P0001'; + end if; + v_uncovered := private.uncovered_review_groups(v_review.id); + if coalesce(array_length(v_uncovered, 1), 0) > 0 then + raise exception 'review.groups.uncovered' using errcode = 'P0001'; + end if; + update public.anatomical_sheet_reviews + set status = 'approved', decided_by = v_actor, decided_at = now(), decision_note = note + where id = v_review.id; + perform private.log_event( + v_actor, 'anatomical_sheet_review.approved', 'anatomical_sheet_review', v_review.id, null, null, + jsonb_build_object('sheet_id', v_version.sheet_id, 'round', v_review.round) + ); + else + update public.anatomical_sheet_reviews + set status = 'changes_requested', decided_by = v_actor, decided_at = now(), decision_note = note + where id = v_review.id; + perform private.log_event( + v_actor, 'anatomical_sheet_review.changes_requested', 'anatomical_sheet_review', v_review.id, null, null, + jsonb_build_object('sheet_id', v_version.sheet_id, 'round', v_review.round) + ); + end if; + return v_review.id; +end; +$$; + +-- =========================================================================== +-- 6. Publication (atomic, contract §6.8) +-- =========================================================================== +create or replace function public.publish_sheet_version(review_id uuid) +returns uuid +language plpgsql +volatile +security definer +set search_path = '' +as $$ +#variable_conflict use_column +declare + v_review public.anatomical_sheet_reviews%rowtype; + v_version public.anatomical_sheet_versions%rowtype; + v_sheet public.anatomical_sheets%rowtype; + v_actor uuid; + v_fingerprint text; + v_name text; + v_description text; +begin + select r.* into v_review from public.anatomical_sheet_reviews r where r.id = publish_sheet_version.review_id for update; + if v_review.id is null then + raise exception 'not_found' using errcode = '42501'; + end if; + select s.* into v_sheet from public.anatomical_sheets s + join public.anatomical_sheet_versions v on v.sheet_id = s.id + where v.id = v_review.version_id for update; + v_actor := private.require_sheet_publisher(v_sheet.id); + select v.* into v_version from public.anatomical_sheet_versions v where v.id = v_review.version_id for update; + + if v_sheet.status <> 'active' then + raise exception 'sheet.inactive' using errcode = '55000'; + end if; + if v_sheet.id = private.historical_sheet_id() then + raise exception 'sheet.historical_read_only' using errcode = '42501'; + end if; + if v_version.status <> 'draft' then + raise exception 'draft.not_a_draft' using errcode = '55000'; + end if; + if v_review.status <> 'approved' or v_review.revision <> v_version.revision then + raise exception 'publish.review.missing' using errcode = '55000'; + end if; + if v_review.verdict is null then + raise exception 'verdict.missing' using errcode = 'P0001'; + end if; + -- Species active and not `other` (§6.7). + if not exists (select 1 from public.species s where s.id = v_sheet.species_id and s.active) then + raise exception 'publish.species.inactive' using errcode = 'P0001'; + end if; + if v_sheet.species_id = 'other' then + raise exception 'publish.species.other' using errcode = 'P0001'; + end if; + -- Status check kept in SQL (§12.2): no to_confirm / inherited element. + if not private.sheet_all_reviewed(v_version.content) then + raise exception 'publish.inherited.present' using errcode = 'P0001'; + end if; + -- Groups still covered at publication. + if coalesce(array_length(private.uncovered_review_groups(v_review.id), 1), 0) > 0 then + raise exception 'review.groups.uncovered' using errcode = 'P0001'; + end if; + -- Each referenced drawing confirmed, size and sha256 equal to the verdict's. + if exists ( + select 1 from unnest(private.sheet_document_asset_ids(v_version.content)) as ref + where not exists ( + select 1 from public.anatomical_sheet_assets a + where a.sheet_id = v_version.sheet_id and a.id::text = ref and a.uploaded_at is not null + ) + ) then + raise exception 'publish.drawing.missing' using errcode = 'P0001'; + end if; + if exists ( + select 1 + from jsonb_array_elements(coalesce(v_review.verdict -> 'drawings', '[]'::jsonb)) d + join public.anatomical_sheet_assets a on a.id = (d ->> 'asset_id')::uuid + where a.sheet_id = v_version.sheet_id and a.sha256 <> (d ->> 'sha256') + ) then + raise exception 'publish.drawing.changed' using errcode = 'P0001'; + end if; + + v_fingerprint := v_review.verdict ->> 'fingerprint'; + if v_fingerprint is null or v_fingerprint !~ '^[0-9a-f]{64}$' then + raise exception 'verdict.fingerprint' using errcode = 'P0001'; + end if; + v_name := left(coalesce(v_version.content -> 'name' ->> 'fr', v_sheet.name), 120); + v_description := left(coalesce(v_version.content -> 'description' ->> 'fr', ''), 2000); + + update public.anatomical_sheet_versions + set status = 'published', published_at = now(), published_by = v_actor, + published_review_id = v_review.id, document_fingerprint = v_fingerprint + where id = v_version.id; + update public.anatomical_sheets + set current_version_id = v_version.id, name = v_name, description = v_description + where id = v_sheet.id; + + perform private.log_event( + v_actor, 'anatomical_sheet_version.published', 'anatomical_sheet_version', v_version.id, null, null, + jsonb_build_object('sheet_id', v_sheet.id, 'version_number', v_version.version_number, + 'revision', v_version.revision, 'review_id', v_review.id, 'fingerprint', v_fingerprint) + ); + return v_version.id; +end; +$$; + +-- =========================================================================== +-- 7. Deprecation, archive, restore, delete (publisher / editor + aal2) +-- =========================================================================== +create or replace function public.deprecate_sheet_version(version_id uuid, reason text default null) +returns uuid +language plpgsql +volatile +security definer +set search_path = '' +as $$ +#variable_conflict use_column +declare + v_version public.anatomical_sheet_versions%rowtype; + v_actor uuid; + v_next uuid; +begin + if char_length(reason) > 500 then + raise exception 'invalid_input' using errcode = 'P0001'; + end if; + select v.* into v_version from public.anatomical_sheet_versions v where v.id = deprecate_sheet_version.version_id for update; + if v_version.id is null then + raise exception 'not_found' using errcode = '42501'; + end if; + v_actor := private.require_sheet_publisher(v_version.sheet_id); + if v_version.status <> 'published' then + raise exception 'version.not_published' using errcode = '55000'; + end if; + + update public.anatomical_sheet_versions + set status = 'deprecated', deprecated_at = now(), deprecated_by = v_actor + where id = v_version.id; + select id into v_next from public.anatomical_sheet_versions + where sheet_id = v_version.sheet_id and status = 'published' + order by version_number desc limit 1; + update public.anatomical_sheets set current_version_id = v_next + where id = v_version.sheet_id and current_version_id = v_version.id; + + perform private.log_event( + v_actor, 'anatomical_sheet_version.deprecated', 'anatomical_sheet_version', v_version.id, null, null, + jsonb_build_object('sheet_id', v_version.sheet_id, 'reason', reason) + ); + return v_version.id; +end; +$$; + +create or replace function private.set_sheet_status( + p_actor uuid, + p_sheet uuid, + p_from public.sheet_status, + p_to public.sheet_status, + p_action text +) +returns uuid +language plpgsql +security definer +set search_path = '' +as $$ +declare + v_status public.sheet_status; +begin + if p_sheet = private.historical_sheet_id() then + raise exception 'sheet.historical_read_only' using errcode = '42501'; + end if; + select status into v_status from public.anatomical_sheets where id = p_sheet for update; + if v_status is null then + raise exception 'not_found' using errcode = '42501'; + end if; + if v_status <> p_from then + raise exception 'sheet.state' using errcode = '55000'; + end if; + update public.anatomical_sheets + set status = p_to, + archived_at = case when p_to = 'archived' then now() when p_to = 'active' then null else archived_at end, + deleted_at = case when p_to = 'deleted' then now() else deleted_at end + where id = p_sheet; + perform private.log_event(p_actor, p_action, 'anatomical_sheet', p_sheet); + return p_sheet; +end; +$$; + +create or replace function public.archive_anatomical_sheet(sheet_id uuid) +returns uuid +language plpgsql +volatile +security definer +set search_path = '' +as $$ +declare + v_actor uuid := private.require_sheet_publisher(sheet_id); +begin + return private.set_sheet_status(v_actor, sheet_id, 'active', 'archived', 'anatomical_sheet.archived'); +end; +$$; + +create or replace function public.restore_anatomical_sheet(sheet_id uuid) +returns uuid +language plpgsql +volatile +security definer +set search_path = '' +as $$ +declare + v_actor uuid := private.require_sheet_publisher(sheet_id); +begin + return private.set_sheet_status(v_actor, sheet_id, 'archived', 'active', 'anatomical_sheet.restored'); +end; +$$; + +-- Delete a draft-only official sheet (never one that ever had a published +-- version, §6.9). Editor capability. +create or replace function public.delete_anatomical_sheet(sheet_id uuid) +returns uuid +language plpgsql +volatile +security definer +set search_path = '' +as $$ +#variable_conflict use_column +declare + v_actor uuid := private.require_sheet_author(sheet_id); +begin + perform 1 from public.anatomical_sheets s where s.id = delete_anatomical_sheet.sheet_id for update; + if exists ( + select 1 from public.anatomical_sheet_versions v + where v.sheet_id = delete_anatomical_sheet.sheet_id and v.status in ('published', 'deprecated') + ) then + raise exception 'sheet.published_history' using errcode = '55000'; + end if; + return private.set_sheet_status(v_actor, + delete_anatomical_sheet.sheet_id, + (select status from public.anatomical_sheets where id = delete_anatomical_sheet.sheet_id), + 'deleted', 'anatomical_sheet.deleted'); +end; +$$; + +-- Delete a draft version (the guard refuses published/deprecated and the +-- historical sheet). Editor capability. +create or replace function public.delete_sheet_version(version_id uuid) +returns uuid +language plpgsql +volatile +security definer +set search_path = '' +as $$ +#variable_conflict use_column +declare + v_version public.anatomical_sheet_versions%rowtype; + v_actor uuid; +begin + select v.* into v_version from public.anatomical_sheet_versions v where v.id = delete_sheet_version.version_id; + if v_version.id is null then + raise exception 'not_found' using errcode = '42501'; + end if; + v_actor := private.require_sheet_author(v_version.sheet_id); + if exists (select 1 from public.anatomical_sheet_reviews r where r.version_id = v_version.id) then + raise exception 'version.has_rounds' using errcode = '55000'; + end if; + delete from public.anatomical_sheet_versions where id = v_version.id; + perform private.log_event( + v_actor, 'anatomical_sheet_version.deleted', 'anatomical_sheet_version', v_version.id, null, null, + jsonb_build_object('sheet_id', v_version.sheet_id, 'version_number', v_version.version_number) + ); + return v_version.id; +end; +$$; + +-- =========================================================================== +-- 8. Equine working copy (contract §14.3) +-- =========================================================================== +create or replace function public.create_sheet_working_copy(source_version_id uuid, slug text) +returns uuid +language plpgsql +volatile +security definer +set search_path = '' +as $$ +#variable_conflict use_column +declare + v_actor uuid := private.require_actor(); + v_source public.anatomical_sheet_versions%rowtype; + v_sheet uuid; + v_draft uuid; + v_map jsonb := '{}'::jsonb; + v_new uuid; + r record; +begin + if not private.caller_has('sheet_editor') then + raise exception 'rights.capability' using errcode = '42501'; + end if; + select v.* into v_source from public.anatomical_sheet_versions v where v.id = create_sheet_working_copy.source_version_id; + -- Source restricted to the historical sheet, and no other (§14.3). + if v_source.id is null or v_source.sheet_id <> private.historical_sheet_id() then + raise exception 'working_copy.source_invalid' using errcode = 'P0001'; + end if; + -- At most one active working copy of the historical sheet. + if exists ( + select 1 from public.anatomical_sheets s + where s.working_copy_source_version_id is not null and s.status = 'active' + and s.id <> private.historical_sheet_id() + and exists (select 1 from public.anatomical_sheet_versions vv + where vv.id = s.working_copy_source_version_id and vv.sheet_id = private.historical_sheet_id()) + ) then + raise exception 'working_copy.exists' using errcode = 'P0001'; + end if; + -- Every referenced drawing uploaded, with an object of the recorded size. + if exists ( + select 1 from unnest(private.sheet_document_asset_ids(v_source.content)) as ref + join public.anatomical_sheet_assets a on a.id::text = ref and a.sheet_id = v_source.sheet_id + where a.uploaded_at is null + or not exists ( + select 1 from storage.objects o + where o.bucket_id = 'anatomical-sheet-assets' and o.name = a.sha256 || '.svg' + and coalesce((o.metadata ->> 'size')::bigint, a.byte_size) = a.byte_size + ) + ) then + raise exception 'working_copy.assets_missing' using errcode = 'P0001'; + end if; + perform private.consume_catalog_write_budget(v_actor); + + insert into public.anatomical_sheets (species_id, name, slug, description, creator_user_id, is_official, visibility, working_copy_source_version_id) + select species_id, left(coalesce(v_source.content -> 'name' ->> 'fr', name), 120), create_sheet_working_copy.slug, + description, null, true, 'private', v_source.id + from public.anatomical_sheets where id = v_source.sheet_id + returning id into v_sheet; + + -- Register the source drawings for the new sheet (same bytes, shared object). + for r in + select a.id, a.sha256, a.byte_size, a.content_type, a.file_name + from public.anatomical_sheet_assets a + where a.sheet_id = v_source.sheet_id and a.id::text = any (private.sheet_document_asset_ids(v_source.content)) + loop + insert into public.anatomical_sheet_assets (sheet_id, sha256, byte_size, content_type, file_name, created_by, uploaded_at) + values (v_sheet, r.sha256, r.byte_size, r.content_type, r.file_name, v_actor, now()) + returning id into v_new; + v_map := v_map || jsonb_build_object(r.id::text, v_new::text); + end loop; + + v_draft := private.insert_sheet_draft( + v_actor, v_sheet, private.remap_document_assets(v_source.content, v_map), + 'Copie de travail de la fiche historique (version ' || v_source.version_number || ', révision ' || v_source.revision || ')' + ); + + perform private.log_event( + v_actor, 'anatomical_sheet.working_copy_created', 'anatomical_sheet', v_sheet, null, null, + jsonb_build_object('source_sheet_id', v_source.sheet_id, 'source_version_id', v_source.id, 'source_revision', v_source.revision) + ); + return v_sheet; +end; +$$; + +-- =========================================================================== +-- 9. Species RPCs (contract §7.2) +-- =========================================================================== +create or replace function public.create_species(id text, name_fr text, name_en text, sort_order integer default 100) +returns text +language plpgsql +volatile +security definer +set search_path = '' +as $$ +#variable_conflict use_column +declare + v_actor uuid := private.require_actor(); +begin + if not private.caller_has('sheet_editor') then + raise exception 'rights.capability' using errcode = '42501'; + end if; + if create_species.id is null or create_species.id !~ '^[a-z0-9][a-z0-9_-]{0,63}$' or create_species.id = 'other' + or char_length(name_fr) not between 1 and 80 or char_length(name_en) not between 1 and 80 then + raise exception 'invalid_input' using errcode = 'P0001'; + end if; + if exists (select 1 from public.species s where s.id = create_species.id) then + raise exception 'species.exists' using errcode = 'P0001'; + end if; + perform private.consume_catalog_write_budget(v_actor); + insert into public.species (id, name_fr, name_en, sort_order, active) + values (create_species.id, name_fr, name_en, coalesce(sort_order, 100), false); + perform private.log_event(v_actor, 'species.created', 'species', null, null, null, + jsonb_build_object('id', create_species.id)); + return create_species.id; +end; +$$; + +create or replace function public.update_inactive_species(id text, name_fr text, name_en text, sort_order integer) +returns text +language plpgsql +volatile +security definer +set search_path = '' +as $$ +#variable_conflict use_column +declare + v_actor uuid := private.require_actor(); +begin + if not private.caller_has('sheet_editor') then + raise exception 'rights.capability' using errcode = '42501'; + end if; + if char_length(name_fr) not between 1 and 80 or char_length(name_en) not between 1 and 80 then + raise exception 'invalid_input' using errcode = 'P0001'; + end if; + perform 1 from public.species s where s.id = update_inactive_species.id and not s.active for update; + if not found then + raise exception 'species.not_inactive' using errcode = 'P0001'; + end if; + perform private.consume_catalog_write_budget(v_actor); + update public.species s set name_fr = update_inactive_species.name_fr, name_en = update_inactive_species.name_en, + sort_order = coalesce(update_inactive_species.sort_order, s.sort_order) where s.id = update_inactive_species.id; + perform private.log_event(v_actor, 'species.updated', 'species', null, null, null, jsonb_build_object('id', update_inactive_species.id)); + return update_inactive_species.id; +end; +$$; + +create or replace function public.activate_species(id text) +returns text +language plpgsql +volatile +security definer +set search_path = '' +as $$ +#variable_conflict use_column +declare + v_actor uuid := private.require_actor(); +begin + if not (private.has_mfa() and private.is_platform_owner(v_actor)) then + raise exception 'rights.owner' using errcode = '42501'; + end if; + perform 1 from public.species s where s.id = activate_species.id for update; + if not found then + raise exception 'not_found' using errcode = '42501'; + end if; + update public.species s set active = true where s.id = activate_species.id and not s.active; + perform private.log_event(v_actor, 'species.activated', 'species', null, null, null, jsonb_build_object('id', activate_species.id)); + return activate_species.id; +end; +$$; + +create or replace function public.rename_species(id text, name_fr text, name_en text) +returns text +language plpgsql +volatile +security definer +set search_path = '' +as $$ +#variable_conflict use_column +declare + v_actor uuid := private.require_actor(); +begin + if not (private.has_mfa() and private.is_platform_owner(v_actor)) then + raise exception 'rights.owner' using errcode = '42501'; + end if; + if char_length(name_fr) not between 1 and 80 or char_length(name_en) not between 1 and 80 then + raise exception 'invalid_input' using errcode = 'P0001'; + end if; + perform 1 from public.species s where s.id = rename_species.id and s.active for update; + if not found then + raise exception 'species.not_active' using errcode = 'P0001'; + end if; + update public.species s set name_fr = rename_species.name_fr, name_en = rename_species.name_en where s.id = rename_species.id; + perform private.log_event(v_actor, 'species.renamed', 'species', null, null, null, jsonb_build_object('id', rename_species.id)); + return rename_species.id; +end; +$$; + +-- Catalogue species for the admin space (E, V, P, O at aal2): active and inactive. +create or replace function public.list_catalog_species() +returns jsonb +language plpgsql +stable +security definer +set search_path = '' +as $$ +begin + if not (private.caller_is_catalog_staff() or (private.has_mfa() and private.is_platform_owner((select auth.uid())))) then + raise exception 'rights.capability' using errcode = '42501'; + end if; + return coalesce(( + select jsonb_agg(jsonb_build_object('id', s.id, 'name_fr', s.name_fr, 'name_en', s.name_en, + 'sort_order', s.sort_order, 'active', s.active) order by s.sort_order, s.id) + from public.species s + ), '[]'::jsonb); +end; +$$; + +-- =========================================================================== +-- 10. Read RPCs (contract §10) +-- =========================================================================== +-- One version by id, with its drawings, under the reader predicate (published +-- or deprecated) or a capability at aal2 (any status). +create or replace function public.get_sheet_version(version_id uuid) +returns jsonb +language plpgsql +stable +security definer +set search_path = '' +as $$ +#variable_conflict use_column +declare + v_uid uuid := auth.uid(); + v_version public.anatomical_sheet_versions%rowtype; + v_sheet public.anatomical_sheets%rowtype; + v_allowed boolean; +begin + if v_uid is null then + raise exception 'not_found' using errcode = '42501'; + end if; + select v.* into v_version from public.anatomical_sheet_versions v where v.id = get_sheet_version.version_id; + if v_version.id is null then + raise exception 'not_found' using errcode = '42501'; + end if; + select s.* into v_sheet from public.anatomical_sheets s where s.id = v_version.sheet_id; + v_allowed := private.caller_can_see_official_sheet(v_sheet.id) + or (v_version.status in ('published', 'deprecated') and private.can_read_catalog_sheet(v_uid, v_sheet.id)); + if not v_allowed then + raise exception 'not_found' using errcode = '42501'; + end if; + return jsonb_build_object( + 'sheet_id', v_sheet.id, + 'version_id', v_version.id, + 'version_number', v_version.version_number, + 'status', v_version.status, + 'species_id', v_sheet.species_id, + 'document', v_version.content, + 'revision', v_version.revision, + 'fingerprint', case when v_version.status = 'published' then v_version.document_fingerprint end, + 'drawings', coalesce(( + select jsonb_agg(jsonb_build_object('asset_id', a.id, 'sha256', a.sha256, 'byte_size', a.byte_size) order by a.id) + from public.anatomical_sheet_assets a + where a.sheet_id = v_sheet.id and a.uploaded_at is not null + and a.id::text = any (private.sheet_document_asset_ids(v_version.content)) + ), '[]'::jsonb) + ); +end; +$$; + +-- The published catalogue grouped by species (readers and capability holders). +create or replace function public.list_official_catalog() +returns jsonb +language plpgsql +stable +security definer +set search_path = '' +as $$ +declare + v_uid uuid := auth.uid(); +begin + if v_uid is null or not private.can_read_official_catalog(v_uid) then + raise exception 'rights.catalog' using errcode = '42501'; + end if; + return coalesce(( + select jsonb_agg(jsonb_build_object( + 'sheet_id', s.id, 'species_id', s.species_id, 'slug', s.slug, + 'name', cur.content -> 'name', 'description', cur.content -> 'description', + 'version_number', cur.version_number, 'version_id', cur.id + ) order by s.species_id, s.slug) + from public.anatomical_sheets s + join public.anatomical_sheet_versions cur on cur.id = s.current_version_id + where s.is_official and s.status = 'active' and cur.status = 'published' + ), '[]'::jsonb); +end; +$$; + +-- =========================================================================== +-- 11. Uploads (contract §9.3): bucket limit, register, confirm with the +-- Storage check (F7), the INSERT policy, the operator read RPC +-- =========================================================================== +update storage.buckets set file_size_limit = 2097152 where id = 'anatomical-sheet-assets'; + +alter table public.anatomical_sheet_assets + add constraint anatomical_sheet_assets_byte_size_2mib check (byte_size <= 2097152) not valid; + +-- Register a drawing for a sheet (editor, aal2), refused on the historical +-- sheet; returns the existing row of the same hash or inserts a pending one. +create or replace function public.register_sheet_asset( + sheet_id uuid, + sha256 text, + byte_size integer, + file_name text +) +returns uuid +language plpgsql +volatile +security definer +set search_path = '' +as $$ +#variable_conflict use_column +declare + v_actor uuid := private.require_sheet_author(sheet_id); + v_id uuid; +begin + if sha256 !~ '^[0-9a-f]{64}$' or byte_size not between 1 and 2097152 + or char_length(file_name) not between 1 and 255 then + raise exception 'invalid_input' using errcode = 'P0001'; + end if; + select id into v_id from public.anatomical_sheet_assets a + where a.sheet_id = register_sheet_asset.sheet_id and a.sha256 = register_sheet_asset.sha256; + if v_id is not null then + return v_id; + end if; + perform private.consume_catalog_write_budget(v_actor); + insert into public.anatomical_sheet_assets (sheet_id, sha256, byte_size, file_name, created_by) + values (sheet_id, sha256, byte_size, file_name, v_actor) + returning id into v_id; + perform private.log_event( + v_actor, 'anatomical_sheet_asset.registered', 'anatomical_sheet_asset', v_id, null, null, + jsonb_build_object('sheet_id', sheet_id, 'sha256', sha256, 'byte_size', byte_size) + ); + return v_id; +end; +$$; + +-- Confirm an upload: the editor of the sheet at aal2, or the service role +-- (operator tool). Checks the object exists and, when the backend records it, +-- that its size equals the row's (F7). +create or replace function public.confirm_sheet_asset_upload(asset_id uuid) +returns uuid +language plpgsql +volatile +security definer +set search_path = '' +as $$ +#variable_conflict use_column +declare + v_row public.anatomical_sheet_assets%rowtype; + v_object storage.objects%rowtype; +begin + select a.* into v_row from public.anatomical_sheet_assets a where a.id = confirm_sheet_asset_upload.asset_id; + if v_row.id is null then + raise exception 'not_found' using errcode = '42501'; + end if; + if auth.uid() is not null then + perform private.require_sheet_author(v_row.sheet_id); + elsif auth.role() is distinct from 'service_role' then + raise exception 'rights.capability' using errcode = '42501'; + end if; + select o.* into v_object from storage.objects o + where o.bucket_id = 'anatomical-sheet-assets' and o.name = v_row.sha256 || '.svg'; + if v_object.name is null then + raise exception 'upload_missing' using errcode = 'P0001'; + end if; + if coalesce((v_object.metadata ->> 'size')::bigint, v_row.byte_size) <> v_row.byte_size then + raise exception 'size_mismatch' using errcode = 'P0001'; + end if; + if v_row.uploaded_at is null then + update public.anatomical_sheet_assets set uploaded_at = now() where id = v_row.id; + perform private.log_event(auth.uid(), 'anatomical_sheet_asset.uploaded', 'anatomical_sheet_asset', v_row.id); + end if; + return v_row.id; +end; +$$; + +-- Narrow read for the operator tool (service role): the state of one asset, +-- replacing its former direct table read (F12). +create or replace function public.get_sheet_asset_state(asset_id uuid) +returns jsonb +language plpgsql +stable +security definer +set search_path = '' +as $$ +#variable_conflict use_column +declare + v_row public.anatomical_sheet_assets%rowtype; +begin + if auth.role() is distinct from 'service_role' then + raise exception 'rights.capability' using errcode = '42501'; + end if; + select a.* into v_row from public.anatomical_sheet_assets a where a.id = get_sheet_asset_state.asset_id; + -- Null for an unknown asset: the operator tool reads it as "no row yet". + if v_row.id is null then + return null; + end if; + return jsonb_build_object('asset_id', v_row.id, 'sheet_id', v_row.sheet_id, + 'sha256', v_row.sha256, 'byte_size', v_row.byte_size, 'uploaded_at', v_row.uploaded_at); +end; +$$; + +-- An editor uploads the pending key of their own sheet (contract §9.3 step 2). +-- Routed through a single granted predicate, as the avatar bucket is, so that +-- evaluating this policy against another bucket's insert needs no EXECUTE on +-- the internal helpers. +create or replace function private.can_upload_sheet_asset_object(p_user_id uuid, p_object_name text) +returns boolean +language sql +stable +security definer +set search_path = '' +as $$ + select p_user_id = (select auth.uid()) + and private.caller_has('sheet_editor') + and exists ( + select 1 from public.anatomical_sheet_assets a + where a.sha256 = left(p_object_name, 64) + and p_object_name = a.sha256 || '.svg' + and a.uploaded_at is null + and private.caller_can_see_official_sheet(a.sheet_id) + ); +$$; + +comment on function private.can_upload_sheet_asset_object(uuid, text) is + 'Storage INSERT predicate for bucket anatomical-sheet-assets: the caller holds sheet_editor at aal2 and the pending key .svg belongs to a non-deleted official sheet (contract §9.3).'; + +revoke all on function private.can_upload_sheet_asset_object(uuid, text) from public, anon, authenticated, service_role; +grant execute on function private.can_upload_sheet_asset_object(uuid, text) to authenticated; + +create policy anatomical_sheet_assets_object_insert + on storage.objects + for insert + to authenticated + with check ( + bucket_id = 'anatomical-sheet-assets' + and private.can_upload_sheet_asset_object((select auth.uid()), name) + ); + +-- =========================================================================== +-- 12. Triggers wired after every function exists +-- =========================================================================== +drop trigger anatomical_sheet_versions_guard_update on public.anatomical_sheet_versions; +create trigger anatomical_sheet_versions_guard_update + before update on public.anatomical_sheet_versions + for each row execute function private.guard_sheet_version_update(); + +-- =========================================================================== +-- 13. Privileges + RLS +-- =========================================================================== +revoke all on public.anatomical_sheet_reviews from public, anon, authenticated, service_role; +revoke all on public.anatomical_sheet_review_comments from public, anon, authenticated, service_role; +revoke all on public.anatomical_sheet_review_acknowledgments from public, anon, authenticated, service_role; +grant select on public.anatomical_sheet_reviews to authenticated; +grant select on public.anatomical_sheet_review_comments to authenticated; +grant select on public.anatomical_sheet_review_acknowledgments to authenticated; +-- The editor needs the draft revision for the save-conflict check (§6.2); the +-- other V1-2 columns (authors, provenance, review link, fingerprint) stay out +-- of the direct grant and reach staff through the read RPCs. +grant select (revision) on public.anatomical_sheet_versions to authenticated; + +alter table public.anatomical_sheet_reviews enable row level security; +alter table public.anatomical_sheet_review_comments enable row level security; +alter table public.anatomical_sheet_review_acknowledgments enable row level security; + +create policy anatomical_sheet_reviews_select + on public.anatomical_sheet_reviews + for select + to authenticated + using (private.caller_can_see_official_sheet( + (select sheet_id from public.anatomical_sheet_versions v where v.id = version_id))); +create policy anatomical_sheet_review_comments_select + on public.anatomical_sheet_review_comments + for select + to authenticated + using (private.caller_can_see_official_sheet( + (select v.sheet_id from public.anatomical_sheet_reviews r + join public.anatomical_sheet_versions v on v.id = r.version_id where r.id = review_id))); +create policy anatomical_sheet_review_acks_select + on public.anatomical_sheet_review_acknowledgments + for select + to authenticated + using (private.caller_can_see_official_sheet( + (select v.sheet_id from public.anatomical_sheet_reviews r + join public.anatomical_sheet_versions v on v.id = r.version_id where r.id = review_id))); + +-- RPC privileges: authoring and review RPCs to authenticated only; the two +-- service-role RPCs (upload confirmation, operator read) to service_role too. +do $$ +declare + v_fn text; + v_authn text[] := array[ + 'public.create_official_sheet(text, jsonb)', + 'public.create_sheet_draft(uuid, uuid, text)', + 'public.save_sheet_draft(uuid, integer, jsonb, text)', + 'public.submit_sheet_review(uuid, integer, text)', + 'public.withdraw_sheet_review(uuid, text)', + 'public.comment_sheet_review(uuid, text, text)', + 'public.acknowledge_sheet_review_group(uuid, text, text)', + 'public.decide_sheet_review(uuid, boolean, text)', + 'public.publish_sheet_version(uuid)', + 'public.deprecate_sheet_version(uuid, text)', + 'public.archive_anatomical_sheet(uuid)', + 'public.restore_anatomical_sheet(uuid)', + 'public.delete_anatomical_sheet(uuid)', + 'public.delete_sheet_version(uuid)', + 'public.create_sheet_working_copy(uuid, text)', + 'public.create_species(text, text, text, integer)', + 'public.update_inactive_species(text, text, text, integer)', + 'public.activate_species(text)', + 'public.rename_species(text, text, text)', + 'public.list_catalog_species()', + 'public.get_sheet_version(uuid)', + 'public.list_official_catalog()', + 'public.register_sheet_asset(uuid, text, integer, text)' + ]; +begin + foreach v_fn in array v_authn loop + execute format('revoke all on function %s from public, anon, service_role', v_fn); + execute format('grant execute on function %s to authenticated', v_fn); + end loop; + execute 'revoke all on function public.confirm_sheet_asset_upload(uuid) from public, anon'; + execute 'grant execute on function public.confirm_sheet_asset_upload(uuid) to authenticated, service_role'; + execute 'revoke all on function public.get_sheet_asset_state(uuid) from public, anon, authenticated'; + execute 'grant execute on function public.get_sheet_asset_state(uuid) to service_role'; +end; +$$; + +-- Private helpers: EXECUTE for nobody except the predicates the review +-- policies evaluate (caller_can_see_official_sheet, granted in M4). +revoke all on function private.sheet_all_reviewed(jsonb) from public, anon, authenticated, service_role; +revoke all on function private.on_sheet_version_content() from public, anon, authenticated, service_role; +revoke all on function private.guard_sheet_version_update() from public, anon, authenticated, service_role; +revoke all on function private.require_sheet_author(uuid) from public, anon, authenticated, service_role; +revoke all on function private.require_sheet_publisher(uuid) from public, anon, authenticated, service_role; +revoke all on function private.verdict_group_digest(jsonb, text) from public, anon, authenticated, service_role; +revoke all on function private.uncovered_review_groups(uuid) from public, anon, authenticated, service_role; +revoke all on function private.set_sheet_status(uuid, uuid, public.sheet_status, public.sheet_status, text) from public, anon, authenticated, service_role; + +-- The two obsolete editor predicates of the base migration are gone (M4 +-- dropped can_use_sheet; require_sheet_editor / require_version_editor are no +-- longer called). Drop them so no stale path survives. +drop function if exists private.require_sheet_editor(uuid, uuid); +drop function if exists private.require_version_editor(uuid, uuid); diff --git a/supabase/tests/001_schema.sql b/supabase/tests/001_schema.sql index 37283f66..002dd9b8 100644 --- a/supabase/tests/001_schema.sql +++ b/supabase/tests/001_schema.sql @@ -62,7 +62,7 @@ select is( (select string_agg(p.proname::text, ',' order by p.proname::text collate "C") from pg_proc p join pg_namespace n on n.oid = p.pronamespace where n.nspname in ('private', 'audit') and has_function_privilege('authenticated', p.oid, 'execute')), - 'caller_workspace_ids,can_edit_sheet,can_read_avatar_object,can_read_sheet_asset_object,can_upload_avatar_object,can_use_sheet,fold_text,has_platform_role,is_platform_admin,is_platform_moderator,is_platform_owner,is_support', + 'asset_in_catalog_version,caller_can_see_official_sheet,caller_is_catalog_staff,caller_workspace_ids,can_read_avatar_object,can_read_catalog_sheet,can_read_sheet_asset_object,can_upload_avatar_object,can_upload_sheet_asset_object,fold_text,has_mfa,has_platform_role,is_platform_admin,is_platform_moderator,is_platform_owner,is_support', 'authenticated executes only the policy predicates in private' ); diff --git a/supabase/tests/003_platform_roles.sql b/supabase/tests/003_platform_roles.sql index a5cfbccf..515ee044 100644 --- a/supabase/tests/003_platform_roles.sql +++ b/supabase/tests/003_platform_roles.sql @@ -1,159 +1,161 @@ --- Platform roles: bootstrap, delegation rules, every denied path, visibility. +-- Platform roles: bootstrap, AR-1 B (live aal2 session required), delegation +-- rules, every denied path, visibility. Since V1-2.1 (M4) every role change +-- needs an aal2 session that still exists in auth.sessions and, for a grant, +-- a verified TOTP factor on the target. Full AR-1 matrix: 015. begin; -select plan(28); +select plan(25); -insert into auth.users (id, email) values - ('00000000-0000-0000-0000-000000000001', 'root@test.local'), - ('00000000-0000-0000-0000-00000000000a', 'alice@test.local'), - ('00000000-0000-0000-0000-00000000000b', 'bob@test.local'), - ('00000000-0000-0000-0000-00000000000c', 'carol@test.local'); +insert into auth.users (id, email, email_confirmed_at) values + ('00000000-0000-0000-0000-000000000001', 'root@test.local', now()), + ('00000000-0000-0000-0000-00000000000a', 'alice@test.local', now()), + ('00000000-0000-0000-0000-00000000000b', 'bob@test.local', now()), + ('00000000-0000-0000-0000-00000000000c', 'carol@test.local', now()); --- 1. Nobody has a role; bootstrap the first owner from a privileged session +-- A verified TOTP factor for every account that will receive a role, except +-- carol, who gets one only after the factor-missing refusal is proven. +insert into auth.mfa_factors (id, user_id, factor_type, status, created_at, updated_at) +select gen_random_uuid(), id, 'totp', 'verified', now(), now() +from auth.users where email in ('root@test.local', 'alice@test.local', 'bob@test.local'); + +-- aal2 sessions for the callers (root, alice); one aal1 session for root. +insert into auth.sessions (id, user_id, aal, not_after) values + ('a0000000-0000-0000-0000-000000000001', '00000000-0000-0000-0000-000000000001', 'aal2', null), + ('a0000000-0000-0000-0000-00000000000a', '00000000-0000-0000-0000-00000000000a', 'aal2', null), + ('a0000000-0000-0000-0000-00000000000b', '00000000-0000-0000-0000-00000000000b', 'aal2', null), + ('b0000000-0000-0000-0000-000000000001', '00000000-0000-0000-0000-000000000001', 'aal1', null); + +create function pg_temp.act(p_uid uuid, p_sid uuid, p_aal text) returns void language sql as $$ + select set_config('request.jwt.claims', + jsonb_build_object('sub', p_uid, 'role', 'authenticated', 'aal', p_aal, 'session_id', p_sid)::text, true); +$$; + +-- 1. Bootstrap the first owner from the operator path (no JWT at all). +select set_config('request.jwt.claims', '', true); select ok(not private.is_platform_owner('00000000-0000-0000-0000-000000000001'), 'fresh account has no owner role'); select lives_ok( $$ select private.assign_platform_role(null, '00000000-0000-0000-0000-000000000001', 'owner') $$, - 'system bootstraps the first owner (actor null)' + 'operator bootstraps the first owner (actor null, no JWT)' ); select ok(private.is_platform_owner('00000000-0000-0000-0000-000000000001'), 'root is owner'); select ok(private.is_platform_admin('00000000-0000-0000-0000-000000000001'), 'owner counts as admin'); -select ok(private.is_platform_moderator('00000000-0000-0000-0000-000000000001'), 'owner counts as moderator'); -select ok(not private.is_support('00000000-0000-0000-0000-000000000001'), 'owner is not support'); --- 2. Owner grants admin to alice through the RPC +-- 2. AR-1 B: an aal1 owner session is refused before any role check. set local role authenticated; -select set_config('request.jwt.claims', '{"sub":"00000000-0000-0000-0000-000000000001","role":"authenticated"}', true); +select pg_temp.act('00000000-0000-0000-0000-000000000001', 'b0000000-0000-0000-0000-000000000001', 'aal1'); +select throws_ok( + $$ select public.grant_platform_role('00000000-0000-0000-0000-00000000000a', 'admin') $$, + '42501', 'mfa_required', 'an aal1 owner session cannot grant a role' +); + +-- 3. Owner at aal2 grants admin to alice (who holds a verified factor). +select pg_temp.act('00000000-0000-0000-0000-000000000001', 'a0000000-0000-0000-0000-000000000001', 'aal2'); select lives_ok( $$ select public.grant_platform_role('00000000-0000-0000-0000-00000000000a', 'admin') $$, - 'owner grants admin' + 'owner at aal2 grants admin' ); select throws_ok( $$ select public.grant_platform_role('00000000-0000-0000-0000-00000000000a', 'admin') $$, - '23505', - null, - 'granting an active role twice is refused' + 'P0001', 'role_active', 'granting an active role twice is refused' ); select throws_ok( $$ select public.grant_platform_role('00000000-0000-0000-0000-000000000001', 'admin') $$, - '42501', - null, - 'owner cannot change their own roles' + '42501', 'self_target', 'owner cannot change their own roles' ); select throws_ok( $$ select public.grant_platform_role(gen_random_uuid(), 'support') $$, - 'P0002', - null, - 'unknown target is refused' + 'P0001', 'target_invalid', 'unknown target is refused' ); --- 3. Alice (admin) may delegate moderator/support, nothing above -select set_config('request.jwt.claims', '{"sub":"00000000-0000-0000-0000-00000000000a","role":"authenticated"}', true); +-- 4. A grant to a target with no verified factor is refused (AR-1 B). +select throws_ok( + $$ select public.grant_platform_role('00000000-0000-0000-0000-00000000000c', 'support') $$, + 'P0001', 'target_factor_missing', 'a grant to an account with no verified factor is refused' +); +reset role; +insert into auth.mfa_factors (id, user_id, factor_type, status, created_at, updated_at) + values (gen_random_uuid(), '00000000-0000-0000-0000-00000000000c', 'totp', 'verified', now(), now()); +set local role authenticated; +select pg_temp.act('00000000-0000-0000-0000-000000000001', 'a0000000-0000-0000-0000-000000000001', 'aal2'); + +-- 5. Alice (admin) at aal2 may delegate moderator/support, nothing above. +select pg_temp.act('00000000-0000-0000-0000-00000000000a', 'a0000000-0000-0000-0000-00000000000a', 'aal2'); select lives_ok( $$ select public.grant_platform_role('00000000-0000-0000-0000-00000000000b', 'moderator') $$, 'admin grants moderator' ); select throws_ok( $$ select public.grant_platform_role('00000000-0000-0000-0000-00000000000b', 'admin') $$, - '42501', - null, - 'admin cannot grant admin' + '42501', 'forbidden', 'admin cannot grant admin' ); select throws_ok( $$ select public.grant_platform_role('00000000-0000-0000-0000-00000000000b', 'owner') $$, - '42501', - null, - 'admin cannot grant owner' -); -select throws_ok( - $$ select public.grant_platform_role('00000000-0000-0000-0000-00000000000a', 'owner') $$, - '42501', - null, - 'admin cannot promote herself to owner' + '42501', 'forbidden', 'admin cannot grant owner' ); --- 4. Direct writes are impossible for the API role +-- 6. Direct writes are impossible for the API role. select throws_ok( $$ insert into public.profile_roles (user_id, role) values ('00000000-0000-0000-0000-00000000000a', 'owner') $$, - '42501', - null, - 'admin cannot insert a role row directly' + '42501', null, 'admin cannot insert a role row directly' ); select throws_ok( $$ update public.profile_roles set role = 'owner' where user_id = '00000000-0000-0000-0000-00000000000a' $$, - '42501', - null, - 'admin cannot update role rows directly' + '42501', null, 'admin cannot update role rows directly' ); select throws_ok( $$ delete from public.profile_roles $$, - '42501', - null, - 'admin cannot delete role rows directly' + '42501', null, 'admin cannot delete role rows directly' ); --- 5. Bob (moderator) cannot delegate; sees only his own grants; carol sees nothing -select set_config('request.jwt.claims', '{"sub":"00000000-0000-0000-0000-00000000000b","role":"authenticated"}', true); +-- 7. service_role cannot write the table nor execute the RPCs (F17). +set local role service_role; +select set_config('request.jwt.claims', '{"role":"service_role"}', true); +select ok(not has_function_privilege('service_role', 'public.grant_platform_role(uuid, public.platform_role)', 'execute'), + 'service_role cannot execute grant_platform_role'); +select throws_ok( + $$ insert into public.profile_roles (user_id, role) values ('00000000-0000-0000-0000-00000000000c', 'owner') $$, + '42501', null, 'service_role cannot insert a role row directly' +); + +-- 8. Bob (moderator) at aal2 sees only his own grant; carol sees none. +set local role authenticated; +select pg_temp.act('00000000-0000-0000-0000-00000000000b', 'a0000000-0000-0000-0000-00000000000b', 'aal2'); select throws_ok( $$ select public.grant_platform_role('00000000-0000-0000-0000-00000000000c', 'support') $$, - '42501', - null, - 'moderator cannot grant any role' + '42501', 'forbidden', 'moderator at aal2 cannot grant any role' ); select results_eq( $$ select user_id, role::text from public.profile_roles $$, $$ values ('00000000-0000-0000-0000-00000000000b'::uuid, 'moderator'::text) $$, 'moderator sees only his own grant rows' ); -select set_config('request.jwt.claims', '{"sub":"00000000-0000-0000-0000-00000000000c","role":"authenticated"}', true); -select is((select count(*) from public.profile_roles), 0::bigint, 'plain user sees no role rows'); -select is((select count(*) from public.profiles), 1::bigint, 'plain user still sees one profile (own)'); --- 6. Admin sees every grant and every profile (staff read) -select set_config('request.jwt.claims', '{"sub":"00000000-0000-0000-0000-00000000000a","role":"authenticated"}', true); -select is( - (select count(*) from public.profile_roles - where user_id in ('00000000-0000-0000-0000-000000000001', '00000000-0000-0000-0000-00000000000a', '00000000-0000-0000-0000-00000000000b')), - 3::bigint, - 'admin sees all three fixture grant rows' -); -select is( - (select count(*) from public.profiles where id in ( - '00000000-0000-0000-0000-000000000001', '00000000-0000-0000-0000-00000000000a', - '00000000-0000-0000-0000-00000000000b', '00000000-0000-0000-0000-00000000000c')), - 4::bigint, - 'admin reads every fixture profile' -); - --- 7. Anonymous +-- 9. Anonymous set local role anon; select set_config('request.jwt.claims', '', true); select throws_ok( $$ select public.grant_platform_role('00000000-0000-0000-0000-00000000000c', 'support') $$, - '42501', - null, - 'anon cannot call grant_platform_role' + '42501', null, 'anon cannot call grant_platform_role' ); --- 8. Revocation and deactivation +-- 10. Revocation at aal2 and deactivation. set local role authenticated; -select set_config('request.jwt.claims', '{"sub":"00000000-0000-0000-0000-00000000000a","role":"authenticated"}', true); +select pg_temp.act('00000000-0000-0000-0000-00000000000a', 'a0000000-0000-0000-0000-00000000000a', 'aal2'); select lives_ok( $$ select public.revoke_platform_role('00000000-0000-0000-0000-00000000000b', 'moderator', 'test') $$, - 'admin revokes moderator' + 'admin revokes moderator at aal2' ); select ok(not private.is_platform_moderator('00000000-0000-0000-0000-00000000000b'), 'revoked role no longer counts'); - reset role; update public.profiles set active = false where id = '00000000-0000-0000-0000-00000000000a'; select ok(not private.is_platform_admin('00000000-0000-0000-0000-00000000000a'), 'deactivated account loses its roles'); --- 9. Last-owner guard on the system path (neutralise owners seeded outside the fixtures) +-- 11. Last-owner guard on the system path (operator path: no JWT at all). update public.profile_roles set revoked_at = now() where role = 'owner' and revoked_at is null and user_id <> '00000000-0000-0000-0000-000000000001'; +select set_config('request.jwt.claims', '', true); select throws_ok( $$ select private.withdraw_platform_role(null, '00000000-0000-0000-0000-000000000001', 'owner', 'oops') $$, - '42501', - null, - 'the last owner cannot be revoked' + 'P0001', 'last_owner', 'the last owner cannot be revoked' ); select * from finish(); diff --git a/supabase/tests/004_audit.sql b/supabase/tests/004_audit.sql index a5d96991..e3050d74 100644 --- a/supabase/tests/004_audit.sql +++ b/supabase/tests/004_audit.sql @@ -3,10 +3,16 @@ begin; select plan(12); -insert into auth.users (id, email) values - ('00000000-0000-0000-0000-000000000001', 'root@test.local'), - ('00000000-0000-0000-0000-00000000000a', 'alice@test.local'), - ('00000000-0000-0000-0000-00000000000b', 'bob@test.local'); +insert into auth.users (id, email, email_confirmed_at) values + ('00000000-0000-0000-0000-000000000001', 'root@test.local', now()), + ('00000000-0000-0000-0000-00000000000a', 'alice@test.local', now()), + ('00000000-0000-0000-0000-00000000000b', 'bob@test.local', now()); +-- AR-1 B: the owner needs a live aal2 session, the target a verified factor. +insert into auth.mfa_factors (id, user_id, factor_type, status, created_at, updated_at) + values (gen_random_uuid(), '00000000-0000-0000-0000-00000000000a', 'totp', 'verified', now(), now()); +insert into auth.sessions (id, user_id, aal) values + ('a0000000-0000-0000-0000-000000000001', '00000000-0000-0000-0000-000000000001', 'aal2'); +select set_config('request.jwt.claims', '', true); select private.assign_platform_role(null, '00000000-0000-0000-0000-000000000001', 'owner'); -- 1. Bootstrap is audited as a system action @@ -20,7 +26,8 @@ select results_eq( -- 2. RPC grant and revoke are audited with the actor set local role authenticated; -select set_config('request.jwt.claims', '{"sub":"00000000-0000-0000-0000-000000000001","role":"authenticated"}', true); +select set_config('request.jwt.claims', + '{"sub":"00000000-0000-0000-0000-000000000001","role":"authenticated","aal":"aal2","session_id":"a0000000-0000-0000-0000-000000000001"}', true); select public.grant_platform_role('00000000-0000-0000-0000-00000000000a', 'admin'); select public.revoke_platform_role('00000000-0000-0000-0000-00000000000a', 'admin', 'rotation'); reset role; diff --git a/supabase/tests/005_anatomical_sheets.sql b/supabase/tests/005_anatomical_sheets.sql index 3c53ca37..b7a6f7e6 100644 --- a/supabase/tests/005_anatomical_sheets.sql +++ b/supabase/tests/005_anatomical_sheets.sql @@ -1,638 +1,82 @@ --- Anatomical sheets: schema contract, lifecycle (allowed path), immutability, --- copies with provenance, deletion preconditions, invalid documents, every --- denied path (other user, anon, direct writes, official sheets). --- Counts are scoped to fixture ids: the real stack also carries seed rows. +-- Anatomical sheets: schema contract and privileges after V1-2.1 (M4, M5). +-- The lifecycle, review and publication behaviour lives in 016; the AR-1 B and +-- rights matrix in 015. This file pins the tables, enums, RLS, the start-from- +-- zero privileges for every API role including service_role (F12), the narrow +-- reader column grants, and the removal of the Step 4 write paths and the SQL +-- business mirror. begin; -select plan(127); +select plan(45); --- --------------------------------------------------------------------------- --- Fixtures --- --------------------------------------------------------------------------- -insert into auth.users (id, email) values - ('20000000-0000-0000-0000-000000000001', 'root-sheets@test.local'), - ('20000000-0000-0000-0000-00000000000a', 'alice-sheets@test.local'), - ('20000000-0000-0000-0000-00000000000b', 'bob-sheets@test.local'); -select private.assign_platform_role(null, '20000000-0000-0000-0000-000000000001', 'owner'); - --- A small but complete document: two views (detail without its own asset), --- a trigger, a bilateral joint, a spine zone, one finding zone. -create function pg_temp.sheet_doc(p_asset uuid) -returns jsonb -language sql -as $$ - select jsonb_build_object( - 'schema_version', 2, - 'species_id', 'equine', - 'name', jsonb_build_object('fr', 'Cheval test', 'en', 'Test horse'), - 'description', '{}'::jsonb, - 'scope_disclaimer', '{}'::jsonb, - 'attribution', jsonb_build_object('authors', '[]'::jsonb, 'license', null, 'notes', null), - 'vertebral_config', jsonb_build_object('regions', jsonb_build_array( - jsonb_build_object('code', 'C', 'name', jsonb_build_object('fr', 'Cervicales', 'en', 'Cervical'), 'count', 7) - )), - 'references', '[]'::jsonb, - 'categories', jsonb_build_array( - jsonb_build_object('id', 'articulations', 'name', jsonb_build_object('fr', 'Articulations', 'en', 'Joints'), 'color', null) - ), - 'views', jsonb_build_array( - jsonb_build_object('id', 'view-main', 'kind', 'main', - 'name', jsonb_build_object('fr', 'Vue principale', 'en', 'Main view'), - 'svg_asset_id', p_asset, 'view_box', null), - jsonb_build_object('id', 'view-head', 'kind', 'detail', 'parent_view_id', 'view-main', - 'name', jsonb_build_object('fr', 'Tête', 'en', 'Head'), - 'svg_asset_id', null, - 'view_box', jsonb_build_object('min_x', 60, 'min_y', 100, 'width', 500, 'height', 380)) - ), - 'annotations', jsonb_build_array( - jsonb_build_object('id', 'hip', 'kind', 'point', 'view_id', 'view-main', 'category_id', 'articulations', - 'laterality', 'bilateral', 'geometry', null, - 'name', jsonb_build_object('fr', 'Hanche', 'en', 'Hip joint'), - 'finding_zone_id', 'hip', 'vertebral_region_code', null), - jsonb_build_object('id', 'cervical', 'kind', 'zone', 'view_id', 'view-main', 'category_id', 'articulations', - 'laterality', 'unpaired', 'geometry', null, - 'name', jsonb_build_object('fr', 'Vertèbres cervicales', 'en', 'Cervical vertebrae'), - 'finding_zone_id', null, 'vertebral_region_code', 'C'), - jsonb_build_object('id', 'head-trigger', 'kind', 'detail_trigger', 'view_id', 'view-main', - 'category_id', 'articulations', 'laterality', 'unpaired', 'geometry', null, - 'name', null, 'opens_view_id', 'view-head') - ), - 'finding_zones', jsonb_build_array( - jsonb_build_object('id', 'hip', 'name', jsonb_build_object('fr', 'Hanche', 'en', 'Hip'), - 'categories', jsonb_build_array( - jsonb_build_object('id', 'hip-dysfunctions', 'kind', 'dysfunction', - 'name', jsonb_build_object('fr', 'Dysfonctions', 'en', 'Dysfunctions'), - 'children', jsonb_build_array( - jsonb_build_object('id', 'articular', 'name', jsonb_build_object('fr', 'Articulaire', 'en', 'Articular')) - )) - )) - ) - ); -$$; - -create table pg_temp.ids (key text primary key, id uuid not null); -create function pg_temp.id(p_key text) returns uuid language sql stable -as $$ select id from pg_temp.ids where key = p_key $$; --- The fixtures are read while impersonating the API roles. -grant all on pg_temp.ids to anon, authenticated; -grant execute on function pg_temp.id(text), pg_temp.sheet_doc(uuid) to anon, authenticated; - --- --------------------------------------------------------------------------- --- 1. Schema contract --- --------------------------------------------------------------------------- +-- Tables and enums select has_table('public', 'species', 'table species exists'); select has_table('public', 'anatomical_sheets', 'table anatomical_sheets exists'); select has_table('public', 'anatomical_sheet_versions', 'table anatomical_sheet_versions exists'); select has_table('public', 'anatomical_sheet_assets', 'table anatomical_sheet_assets exists'); -select enum_has_labels('public', 'sheet_visibility', array['private', 'public'], 'sheet_visibility labels'); -select enum_has_labels('public', 'sheet_status', array['active', 'archived', 'deleted'], 'sheet_status labels'); -select enum_has_labels('public', 'sheet_version_status', array['draft', 'published', 'deprecated'], 'sheet_version_status labels'); -select is( - (select count(*) from public.species where id = 'equine' and active), 1::bigint, - 'species equine is seeded by the migration' -); +select has_table('public', 'anatomical_catalog_grants', 'table anatomical_catalog_grants exists'); +select has_table('public', 'anatomical_sheet_reviews', 'table anatomical_sheet_reviews exists'); +select has_table('public', 'anatomical_sheet_review_comments', 'table anatomical_sheet_review_comments exists'); +select has_table('public', 'anatomical_sheet_review_acknowledgments', 'table anatomical_sheet_review_acknowledgments exists'); +select enum_has_labels('public', 'catalog_grant_kind', + array['catalog_reader', 'sheet_editor', 'sheet_reviewer', 'sheet_publisher'], 'catalog_grant_kind labels'); +select enum_has_labels('public', 'sheet_round_status', + array['verifying', 'open', 'approved', 'changes_requested', 'withdrawn', 'verification_failed'], 'sheet_round_status labels'); + +-- RLS enabled on every catalogue table select ok( (select bool_and(relrowsecurity) from pg_class where oid in ('public.species'::regclass, 'public.anatomical_sheets'::regclass, - 'public.anatomical_sheet_versions'::regclass, 'public.anatomical_sheet_assets'::regclass)), - 'RLS enabled on the four tables' + 'public.anatomical_sheet_versions'::regclass, 'public.anatomical_sheet_assets'::regclass, + 'public.anatomical_catalog_grants'::regclass, 'public.anatomical_sheet_reviews'::regclass, + 'public.anatomical_sheet_review_comments'::regclass, + 'public.anatomical_sheet_review_acknowledgments'::regclass)), + 'RLS enabled on the eight catalogue tables' ); + +-- API roles start from zero (F12: service_role too) select ok(not has_table_privilege('anon', 'public.anatomical_sheets', 'select'), 'anon cannot select sheets'); -select ok(not has_table_privilege('anon', 'public.anatomical_sheet_versions', 'select'), 'anon cannot select versions'); select ok(not has_table_privilege('anon', 'public.species', 'select'), 'anon cannot select species'); -select ok(not has_table_privilege('authenticated', 'public.anatomical_sheets', 'insert'), 'authenticated cannot insert sheets directly'); -select ok(not has_table_privilege('authenticated', 'public.anatomical_sheets', 'delete'), 'authenticated cannot delete sheets directly'); -select ok(not has_column_privilege('authenticated', 'public.anatomical_sheets', 'status', 'update'), 'authenticated cannot update sheets.status'); -select ok(not has_column_privilege('authenticated', 'public.anatomical_sheets', 'is_official', 'update'), 'authenticated cannot update sheets.is_official'); -select ok(not has_table_privilege('authenticated', 'public.anatomical_sheet_versions', 'insert'), 'authenticated cannot insert versions directly'); -select ok(not has_column_privilege('authenticated', 'public.anatomical_sheet_versions', 'status', 'update'), 'authenticated cannot update versions.status'); -select ok(has_column_privilege('authenticated', 'public.anatomical_sheet_versions', 'content', 'update'), 'authenticated may update versions.content (RLS: own draft)'); -select ok(not has_table_privilege('authenticated', 'public.anatomical_sheet_assets', 'insert'), 'authenticated cannot insert assets directly'); -select ok( - not (has_column_privilege('authenticated', 'public.anatomical_sheets', 'visibility', 'update') - or has_column_privilege('authenticated', 'public.anatomical_sheets', 'creator_user_id', 'update') - or has_column_privilege('authenticated', 'public.anatomical_sheets', 'current_version_id', 'update') - or has_column_privilege('authenticated', 'public.anatomical_sheets', 'based_on_sheet_id', 'update') - or has_column_privilege('authenticated', 'public.anatomical_sheets', 'based_on_version_id', 'update') - or has_column_privilege('authenticated', 'public.anatomical_sheets', 'species_id', 'update')), - 'visibility, ownership, provenance, current version and species are not user-updatable' -); -select ok(not has_table_privilege('authenticated', 'public.anatomical_sheet_versions', 'delete'), 'authenticated cannot delete versions directly (RPC only)'); -select is( - (select count(*) from pg_proc p join pg_namespace n on n.oid = p.pronamespace - where n.nspname = 'public' and p.prokind = 'f' - and not exists (select 1 from pg_depend d where d.objid = p.oid and d.deptype = 'e') - and has_function_privilege('anon', p.oid, 'execute')), - 0::bigint, 'anon can execute no public RPC' -); +select ok(not has_table_privilege('service_role', 'public.anatomical_sheets', 'select'), 'service_role cannot select sheets (F12)'); +select ok(not has_table_privilege('service_role', 'public.anatomical_sheet_versions', 'update'), 'service_role cannot update versions (F12)'); +select ok(not has_table_privilege('service_role', 'public.anatomical_sheet_assets', 'update'), 'service_role cannot update assets (F12)'); +select ok(not has_table_privilege('service_role', 'public.anatomical_catalog_grants', 'select'), 'service_role cannot read grants'); +select ok(not has_table_privilege('service_role', 'public.profile_roles', 'insert'), 'service_role cannot write profile_roles (F17)'); +select ok(not has_table_privilege('service_role', 'public.profiles', 'update'), 'service_role cannot write profiles (F17)'); --- --------------------------------------------------------------------------- --- 2. Alice creates a private sheet (draft v1), registers an asset, publishes --- --------------------------------------------------------------------------- -set local role authenticated; -select set_config('request.jwt.claims', '{"sub":"20000000-0000-0000-0000-00000000000a","role":"authenticated"}', true); +-- Editors never write sheet identity, status, content directly (F9) +select ok(not has_table_privilege('authenticated', 'public.anatomical_sheets', 'insert'), 'authenticated cannot insert sheets'); +select ok(not has_table_privilege('authenticated', 'public.anatomical_sheets', 'update'), 'authenticated cannot update sheets directly'); +select ok(not has_table_privilege('authenticated', 'public.anatomical_sheet_versions', 'insert'), 'authenticated cannot insert versions'); +select ok(not has_column_privilege('authenticated', 'public.anatomical_sheet_versions', 'content', 'update'), 'authenticated cannot update version content directly (F9)'); +select ok(has_column_privilege('authenticated', 'public.anatomical_sheet_versions', 'revision', 'select'), 'authenticated may read the draft revision'); +select ok(not has_column_privilege('authenticated', 'public.anatomical_sheet_versions', 'authors', 'select'), 'authenticated cannot read the author set directly'); +select ok(not has_table_privilege('authenticated', 'public.anatomical_sheet_assets', 'insert'), 'authenticated cannot insert assets'); +select ok(not has_table_privilege('authenticated', 'public.anatomical_catalog_grants', 'insert'), 'authenticated cannot write grants directly'); +select ok(not has_table_privilege('authenticated', 'public.anatomical_sheet_reviews', 'insert'), 'authenticated cannot write rounds directly'); -insert into pg_temp.ids select 'sheet', public.create_anatomical_sheet( - 'equine', 'Mon cheval', 'mon-cheval', pg_temp.sheet_doc(null), 'perso' -); -select results_eq( - $$ select creator_user_id, status::text, visibility::text, current_version_id, is_official - from public.anatomical_sheets where id = pg_temp.id('sheet') $$, - $$ values ('20000000-0000-0000-0000-00000000000a'::uuid, 'active', 'private', null::uuid, false) $$, - 'created sheet: creator alice, active, private, no current version' -); -insert into pg_temp.ids select 'v1', id from public.anatomical_sheet_versions - where sheet_id = pg_temp.id('sheet') and version_number = 1; -select is( - (select status::text from public.anatomical_sheet_versions where id = pg_temp.id('v1')), - 'draft', 'version 1 is a draft' -); -select throws_ok( - $$ select public.create_anatomical_sheet('unicorn', 'x', 'x-x', pg_temp.sheet_doc(null)) $$, - 'P0002', null, 'unknown species is refused' -); -select throws_ok( - $$ select public.create_anatomical_sheet('equine', 'Dup', 'mon-cheval', pg_temp.sheet_doc(null)) $$, - '23505', null, 'slug is unique per owner' -); +-- Reader column grants on sheets exclude the staff-only columns (§5.3) +select ok(not has_column_privilege('authenticated', 'public.anatomical_sheets', 'last_version_number', 'select'), 'last_version_number not readable'); +select ok(not has_column_privilege('authenticated', 'public.anatomical_sheets', 'updated_at', 'select'), 'updated_at not readable'); +select ok(not has_column_privilege('authenticated', 'public.anatomical_sheets', 'working_copy_source_version_id', 'select'), 'working_copy source not readable'); +select ok(not has_column_privilege('authenticated', 'public.anatomical_sheets', 'creator_user_id', 'select'), 'creator_user_id not readable'); +select ok(has_column_privilege('authenticated', 'public.anatomical_sheets', 'current_version_id', 'select'), 'current_version_id readable'); -select throws_ok( - $$ select public.create_anatomical_sheet('equine', 'Bad', 'bad-doc', '{"schema_version":"abc","species_id":"equine"}'::jsonb) $$, - '23514', null, 'a non-numeric schema_version is refused' -); -select throws_ok( - $$ update public.anatomical_sheet_versions - set content = jsonb_build_object('schema_version', 2, 'species_id', 'equine', 'pad', repeat('x', 2200000)) - where id = pg_temp.id('v1') $$, - '23514', null, 'a document over 2 MiB is refused' -); +-- The Step 4 write paths are gone (F1, F3, F6) +select hasnt_function('public', 'create_anatomical_sheet', 'create_anatomical_sheet dropped (F1)'); +select hasnt_function('public', 'fork_anatomical_sheet', 'fork_anatomical_sheet dropped (D5)'); +select hasnt_function('public', 'set_sheet_visibility', 'set_sheet_visibility dropped (F6)'); --- Publishing a draft whose main view has no asset is refused with the rule code -select throws_ok( - $$ select public.publish_sheet_version(pg_temp.id('v1')) $$, - '23514', 'document not publishable: view.asset.missing', 'publish refuses a main view without asset' -); +-- The SQL business mirror is gone; the structural guards stay (§12.2) +select hasnt_function('private', 'sheet_document_issues', 'SQL business mirror dropped (O22)'); +select hasnt_function('private', 'sheet_document_view_issues', 'view mirror dropped'); +select hasnt_function('private', 'sheet_document_annotation_issues', 'annotation mirror dropped'); +select has_function('private', 'sheet_document_has_shape', 'shape guard kept'); +select has_function('private', 'sheet_document_unknown_assets', 'unknown-asset guard kept'); +select has_function('private', 'sheet_all_reviewed', 'status check added (§12.2)'); -insert into pg_temp.ids select 'asset', public.register_sheet_asset( - pg_temp.id('sheet'), repeat('a', 64), 142400, 'Horse.svg' -); -select is( - public.register_sheet_asset(pg_temp.id('sheet'), repeat('a', 64), 142400, 'Horse.svg'), - pg_temp.id('asset'), 'registering the same sha256 again returns the same asset' -); - --- Draft autosave: direct UPDATE of content through the policy -update public.anatomical_sheet_versions - set content = pg_temp.sheet_doc(pg_temp.id('asset')), change_note = 'asset wired' - where id = pg_temp.id('v1'); -select is( - (select content -> 'views' -> 0 ->> 'svg_asset_id' from public.anatomical_sheet_versions where id = pg_temp.id('v1')), - pg_temp.id('asset')::text, 'editor updated the draft content in place' -); - --- Unknown asset uuid is refused at publish -update public.anatomical_sheet_versions - set content = pg_temp.sheet_doc('ffffffff-ffff-ffff-ffff-ffffffffffff') - where id = pg_temp.id('v1'); -select throws_ok( - $$ select public.publish_sheet_version(pg_temp.id('v1')) $$, - '23514', null, 'publish refuses a view pointing at an asset not registered for the sheet' -); -update public.anatomical_sheet_versions - set content = pg_temp.sheet_doc(pg_temp.id('asset')) where id = pg_temp.id('v1'); - --- Document species must match the sheet species (trigger) -select throws_ok( - $$ update public.anatomical_sheet_versions - set content = jsonb_set(pg_temp.sheet_doc(pg_temp.id('asset')), '{species_id}', '"canine"') - where id = pg_temp.id('v1') $$, - '23514', null, 'a document for another species is refused' -); --- Dangling references are refused at publish -update public.anatomical_sheet_versions - set content = jsonb_set(pg_temp.sheet_doc(pg_temp.id('asset')), '{annotations,0,finding_zone_id}', '"nowhere"') - where id = pg_temp.id('v1'); -select throws_ok( - $$ select public.publish_sheet_version(pg_temp.id('v1')) $$, - '23514', 'document not publishable: annotation.finding_zone.missing', - 'publish refuses an annotation pointing at a missing finding zone' -); -update public.anatomical_sheet_versions - set content = jsonb_set(pg_temp.sheet_doc(pg_temp.id('asset')), '{annotations,1,id}', '"hip"') - where id = pg_temp.id('v1'); -select throws_ok( - $$ select public.publish_sheet_version(pg_temp.id('v1')) $$, - '23514', 'document not publishable: annotation.id.duplicate', - 'publish refuses duplicate annotation ids' -); -create function pg_temp.publish_issue(p_doc jsonb) returns text language plpgsql as $$ -begin - update public.anatomical_sheet_versions set content = p_doc where id = pg_temp.id('v1'); - perform public.publish_sheet_version(pg_temp.id('v1')); - return 'published'; -exception when check_violation then - return sqlerrm; -end $$; -grant execute on function pg_temp.publish_issue(jsonb) to authenticated; -select is( - pg_temp.publish_issue(jsonb_set(pg_temp.sheet_doc(pg_temp.id('asset')), '{views,0,kind}', '"detail"')), - 'document not publishable: view.main.count, view.parent.missing', 'SQL gate: no main view' -); -select is( - pg_temp.publish_issue(pg_temp.sheet_doc(pg_temp.id('asset')) #- '{annotations,2}'), - 'document not publishable: view.unreachable', 'SQL gate: detail view without trigger' -); -select is( - pg_temp.publish_issue(jsonb_set(pg_temp.sheet_doc(pg_temp.id('asset')), '{views,1,parent_view_id}', '"nowhere"')), - 'document not publishable: view.parent.missing, annotation.opens_view.invalid', 'SQL gate: dangling parent view' -); -select is( - pg_temp.publish_issue(jsonb_set(pg_temp.sheet_doc(pg_temp.id('asset')), '{views,1,id}', '"view-main"')), - 'document not publishable: view.unreachable, view.id.duplicate, annotation.opens_view.invalid', 'SQL gate: duplicate view id' -); -select is( - pg_temp.publish_issue(jsonb_set(pg_temp.sheet_doc(pg_temp.id('asset')), '{annotations,0,view_id}', '"nowhere"')), - 'document not publishable: annotation.view.missing', 'SQL gate: annotation on a missing view' -); -select is( - pg_temp.publish_issue(jsonb_set(pg_temp.sheet_doc(pg_temp.id('asset')), '{annotations,0,category_id}', '"nowhere"')), - 'document not publishable: annotation.category.missing', 'SQL gate: missing category' -); -select is( - pg_temp.publish_issue(jsonb_set(pg_temp.sheet_doc(pg_temp.id('asset')), '{annotations,1,vertebral_region_code}', '"Z"')), - 'document not publishable: annotation.region.missing', 'SQL gate: unknown vertebral region' -); -select is( - pg_temp.publish_issue(jsonb_set(pg_temp.sheet_doc(pg_temp.id('asset')), '{annotations,2,opens_view_id}', '"view-main"')), - 'document not publishable: view.unreachable, annotation.opens_view.invalid', 'SQL gate: trigger opening a non-child view' -); -select is( - pg_temp.publish_issue(jsonb_set(pg_temp.sheet_doc(pg_temp.id('asset')), '{vertebral_config,regions}', - '[{"code":"C","name":{"fr":"a","en":"a"},"count":7},{"code":"C","name":{"fr":"b","en":"b"},"count":7}]')), - 'document not publishable: region.code.duplicate', 'SQL gate: duplicate region code' -); -select is( - pg_temp.publish_issue(jsonb_set(pg_temp.sheet_doc(pg_temp.id('asset')), '{finding_zones}', - '[{"id":"hip","name":{"fr":"a","en":"a"},"categories":[]},{"id":"hip","name":{"fr":"b","en":"b"},"categories":[]}]')), - 'document not publishable: finding_zone.id.duplicate', 'SQL gate: duplicate finding zone id' -); -select is( - pg_temp.publish_issue(jsonb_set(pg_temp.sheet_doc(pg_temp.id('asset')), '{views}', '"not-an-array"')), - 'document not publishable: document.shape', 'SQL gate: views not an array' -); -update public.anatomical_sheet_versions - set content = pg_temp.sheet_doc(pg_temp.id('asset')) where id = pg_temp.id('v1'); - -select lives_ok( - $$ select public.publish_sheet_version(pg_temp.id('v1')) $$, - 'alice publishes version 1' -); -select results_eq( - $$ select status::text, published_by, published_at is not null - from public.anatomical_sheet_versions where id = pg_temp.id('v1') $$, - $$ values ('published', '20000000-0000-0000-0000-00000000000a'::uuid, true) $$, - 'version 1 is published by alice' -); -select is( - (select current_version_id from public.anatomical_sheets where id = pg_temp.id('sheet')), - pg_temp.id('v1'), 'sheet current version is v1' -); -select throws_ok( - $$ select public.publish_sheet_version(pg_temp.id('v1')) $$, - '55000', null, 'publishing twice is refused' -); - --- --------------------------------------------------------------------------- --- 3. Published rows are immutable (editor, then table owner) --- --------------------------------------------------------------------------- --- Through the API role the policies hide published rows from UPDATE/DELETE: --- the statement touches zero rows instead of raising. -update public.anatomical_sheet_versions set content = '{}'::jsonb where id = pg_temp.id('v1'); -select is( - (select content from public.anatomical_sheet_versions where id = pg_temp.id('v1')), - pg_temp.sheet_doc(pg_temp.id('asset')), 'editor UPDATE of published content touches no row' -); -update public.anatomical_sheet_versions set change_note = 'x' where id = pg_temp.id('v1'); -select is( - (select change_note from public.anatomical_sheet_versions where id = pg_temp.id('v1')), - 'asset wired', 'editor UPDATE of a published change note touches no row' -); -select throws_ok( - $$ delete from public.anatomical_sheet_versions where id = pg_temp.id('v1') $$, - '42501', null, 'editor has no DELETE privilege on versions (RPC only)' -); -reset role; -select throws_ok( - $$ update public.anatomical_sheet_versions - set content = pg_temp.sheet_doc(pg_temp.id('asset')) || '{"name":{"fr":"X","en":"X"}}' - where id = pg_temp.id('v1') $$, - '42501', null, 'even the table owner cannot change published content' -); -select throws_ok( - $$ update public.anatomical_sheet_versions set status = 'draft' where id = pg_temp.id('v1') $$, - '42501', null, 'a published version cannot go back to draft' -); -select throws_ok( - $$ update public.anatomical_sheet_versions set version_number = 9 where id = pg_temp.id('v1') $$, - '42501', null, 'version_number is immutable' -); -select throws_ok( - $$ delete from public.anatomical_sheet_versions where id = pg_temp.id('v1') $$, - '55000', null, 'owner role cannot delete a published version either' -); - --- --------------------------------------------------------------------------- --- 4. New version leaves the old one intact --- --------------------------------------------------------------------------- -set local role authenticated; -select set_config('request.jwt.claims', '{"sub":"20000000-0000-0000-0000-00000000000a","role":"authenticated"}', true); -create table pg_temp.v1_snapshot as - select * from public.anatomical_sheet_versions where id = pg_temp.id('v1'); - -insert into pg_temp.ids select 'v2', public.create_sheet_draft(pg_temp.id('sheet'), null, 'second edition'); -select results_eq( - $$ select version_number, status::text, change_note, content = (select content from pg_temp.v1_snapshot) - from public.anatomical_sheet_versions where id = pg_temp.id('v2') $$, - $$ values (2, 'draft', 'second edition', true) $$, - 'draft v2 starts from the current version content' -); -select throws_ok( - $$ select public.create_sheet_draft(pg_temp.id('sheet')) $$, - '23505', null, 'one draft per sheet' -); -update public.anatomical_sheet_versions - set content = jsonb_set(pg_temp.sheet_doc(pg_temp.id('asset')), '{name,fr}', '"Cheval v2"') - where id = pg_temp.id('v2'); -select lives_ok($$ select public.publish_sheet_version(pg_temp.id('v2')) $$, 'alice publishes v2'); -select is( - (select current_version_id from public.anatomical_sheets where id = pg_temp.id('sheet')), - pg_temp.id('v2'), 'current version moved to v2' -); -select is( - (select count(*) from public.anatomical_sheet_versions v, pg_temp.v1_snapshot s - where v.id = s.id and v.content = s.content and v.status = s.status - and v.published_at = s.published_at and v.version_number = s.version_number - and v.change_note = s.change_note), - 1::bigint, 'v1 row is byte-identical after v2 was published' -); -select throws_ok( - $$ select public.delete_sheet_version(pg_temp.id('v2')) $$, - '55000', null, 'the current version cannot be deleted' -); -select throws_ok( - $$ select public.delete_sheet_version(pg_temp.id('v1')) $$, - '55000', null, 'a published version cannot be deleted before deprecation' -); - --- --------------------------------------------------------------------------- --- 5. Bob: private sheet invisible; public sheet usable; copy keeps provenance --- --------------------------------------------------------------------------- -select set_config('request.jwt.claims', '{"sub":"20000000-0000-0000-0000-00000000000b","role":"authenticated"}', true); -select is((select count(*) from public.anatomical_sheets where id = pg_temp.id('sheet')), 0::bigint, 'bob does not see the private sheet'); -select is((select count(*) from public.anatomical_sheet_versions where sheet_id = pg_temp.id('sheet')), 0::bigint, 'bob does not see its versions'); -select is((select count(*) from public.anatomical_sheet_assets where sheet_id = pg_temp.id('sheet')), 0::bigint, 'bob does not see its assets'); -select throws_ok( - $$ select public.fork_anatomical_sheet(pg_temp.id('v2'), 'Copie', 'copie-bob') $$, - '42501', null, 'bob cannot copy a private sheet' -); -select throws_ok( - $$ select public.create_sheet_draft(pg_temp.id('sheet')) $$, - '42501', null, 'bob cannot open a draft on alice sheet' -); -update public.anatomical_sheets set name = 'hijack' where id = pg_temp.id('sheet'); -select throws_ok( - $$ insert into public.anatomical_sheets (species_id, name, slug, creator_user_id) - values ('equine', 'direct', 'direct', '20000000-0000-0000-0000-00000000000b') $$, - '42501', null, 'bob cannot insert a sheet row directly' -); -select throws_ok( - $$ insert into public.anatomical_sheet_versions (sheet_id, version_number, document_schema_version, content) - values (pg_temp.id('sheet'), 9, 2, pg_temp.sheet_doc(null)) $$, - '42501', null, 'bob cannot insert a version row directly' -); - --- alice makes the sheet public through the identity-column policy -select set_config('request.jwt.claims', '{"sub":"20000000-0000-0000-0000-00000000000a","role":"authenticated"}', true); -select is((select name from public.anatomical_sheets where id = pg_temp.id('sheet')), 'Mon cheval', 'bob update on alice sheet changed nothing'); -select lives_ok($$ select public.set_sheet_visibility(pg_temp.id('sheet'), 'public') $$, 'alice makes the sheet public (audited RPC)'); -insert into pg_temp.ids select 'v3', public.create_sheet_draft(pg_temp.id('sheet'), null, 'work in progress'); -insert into pg_temp.ids select 'asset-unused', public.register_sheet_asset( - pg_temp.id('sheet'), repeat('b', 64), 1000, 'Unused.svg' -); - -select set_config('request.jwt.claims', '{"sub":"20000000-0000-0000-0000-00000000000b","role":"authenticated"}', true); -select is((select count(*) from public.anatomical_sheets where id = pg_temp.id('sheet')), 1::bigint, 'bob sees the public sheet'); -select results_eq( - $$ select version_number from public.anatomical_sheet_versions where sheet_id = pg_temp.id('sheet') order by 1 $$, - $$ values (1), (2) $$, - 'bob sees the published versions, not the draft' -); -select is( - (select count(*) from public.anatomical_sheet_versions where id = pg_temp.id('v3') and content = '{}'::jsonb), - 0::bigint, 'bob cannot read the draft' -); -update public.anatomical_sheet_versions set content = '{"schema_version":2}'::jsonb where id = pg_temp.id('v3'); -select throws_ok( - $$ select public.fork_anatomical_sheet(pg_temp.id('v3'), 'Copie', 'copie-bob') $$, - '42501', null, 'a draft cannot be copied (hidden from non-editors)' -); -update public.anatomical_sheets set name = 'hijack-public' where id = pg_temp.id('sheet'); -select is((select name from public.anatomical_sheets where id = pg_temp.id('sheet')), 'Mon cheval', 'bob cannot rename a public sheet he does not edit'); --- Every editor-gated RPC refuses a non-editor, even on a public sheet -select throws_ok($$ select public.publish_sheet_version(pg_temp.id('v3')) $$, '42501', null, 'non-editor cannot publish'); -select throws_ok($$ select public.deprecate_sheet_version(pg_temp.id('v2'), 'x') $$, '42501', null, 'non-editor cannot deprecate'); -select throws_ok($$ select public.delete_sheet_version(pg_temp.id('v3')) $$, '42501', null, 'non-editor cannot delete a version'); -select throws_ok($$ select public.archive_anatomical_sheet(pg_temp.id('sheet')) $$, '42501', null, 'non-editor cannot archive'); -select throws_ok($$ select public.restore_anatomical_sheet(pg_temp.id('sheet')) $$, '42501', null, 'non-editor cannot restore'); -select throws_ok($$ select public.delete_anatomical_sheet(pg_temp.id('sheet')) $$, '42501', null, 'non-editor cannot delete a sheet'); -select throws_ok($$ select public.set_sheet_visibility(pg_temp.id('sheet'), 'private') $$, '42501', null, 'non-editor cannot change visibility'); -select throws_ok($$ select public.register_sheet_asset(pg_temp.id('sheet'), repeat('c', 64), 10, 'x.svg') $$, '42501', null, 'non-editor cannot register an asset'); -select throws_ok($$ select public.delete_sheet_asset(pg_temp.id('asset-unused')) $$, '42501', null, 'non-editor cannot delete an asset'); -select throws_ok($$ select public.publish_sheet_version(gen_random_uuid()) $$, '42501', null, 'unknown version gets the same answer as a foreign one'); --- A platform admin is not an editor of a personal sheet -select set_config('request.jwt.claims', '{"sub":"20000000-0000-0000-0000-000000000001","role":"authenticated"}', true); -select throws_ok($$ select public.create_sheet_draft(pg_temp.id('sheet')) $$, '42501', null, 'platform owner cannot edit a personal sheet'); -select set_config('request.jwt.claims', '{"sub":"20000000-0000-0000-0000-00000000000b","role":"authenticated"}', true); - -create table pg_temp.source_snapshot as - select s.updated_at as sheet_updated_at, s.current_version_id, v.content, v.updated_at as version_updated_at, - (select count(*) from public.anatomical_sheet_assets where sheet_id = s.id) as asset_count - from public.anatomical_sheets s join public.anatomical_sheet_versions v on v.id = s.current_version_id - where s.id = pg_temp.id('sheet'); - -insert into pg_temp.ids select 'fork', public.fork_anatomical_sheet(pg_temp.id('v2'), 'Copie de Bob', 'copie-bob'); -select results_eq( - $$ select creator_user_id, based_on_sheet_id, based_on_version_id, species_id, visibility::text, is_official - from public.anatomical_sheets where id = pg_temp.id('fork') $$, - $$ values ('20000000-0000-0000-0000-00000000000b'::uuid, pg_temp.id('sheet'), pg_temp.id('v2'), 'equine', 'private', false) $$, - 'copy records provenance (source sheet + version) and belongs to bob' -); -insert into pg_temp.ids select 'fork-v1', id from public.anatomical_sheet_versions where sheet_id = pg_temp.id('fork'); -insert into pg_temp.ids select 'fork-asset', id from public.anatomical_sheet_assets where sheet_id = pg_temp.id('fork'); -select results_eq( - $$ select version_number, status::text, created_by from public.anatomical_sheet_versions where id = pg_temp.id('fork-v1') $$, - $$ values (1, 'draft', '20000000-0000-0000-0000-00000000000b'::uuid) $$, - 'copy starts as draft v1 owned by bob' -); -select results_eq( - $$ select sha256, byte_size, id <> pg_temp.id('asset') from public.anatomical_sheet_assets where sheet_id = pg_temp.id('fork') $$, - $$ values (repeat('a', 64), 142400, true) $$, - 'only the asset referenced by the copied version is copied (same content, new id)' -); -select is( - (select content -> 'views' -> 0 ->> 'svg_asset_id' from public.anatomical_sheet_versions where id = pg_temp.id('fork-v1')), - pg_temp.id('fork-asset')::text, 'copied document points at the copied asset' -); -select is( - (select content #- '{views,0,svg_asset_id}' from public.anatomical_sheet_versions where id = pg_temp.id('fork-v1')), - (select content #- '{views,0,svg_asset_id}' from pg_temp.source_snapshot), - 'copied document is otherwise identical to the source' -); - --- bob edits his copy; the source stays untouched -update public.anatomical_sheet_versions - set content = jsonb_set(content, '{name,fr}', '"Ma copie"') where id = pg_temp.id('fork-v1'); -select lives_ok($$ select public.publish_sheet_version(pg_temp.id('fork-v1')) $$, 'bob publishes his copy'); -select set_config('request.jwt.claims', '{"sub":"20000000-0000-0000-0000-00000000000a","role":"authenticated"}', true); -select is( - (select count(*) from public.anatomical_sheets s join public.anatomical_sheet_versions v on v.id = s.current_version_id, - pg_temp.source_snapshot snap - where s.id = pg_temp.id('sheet') and s.updated_at = snap.sheet_updated_at and s.current_version_id = snap.current_version_id - and v.content = snap.content and v.updated_at = snap.version_updated_at - and (select count(*) from public.anatomical_sheet_assets where sheet_id = s.id) = snap.asset_count), - 1::bigint, 'source sheet, version and assets are unchanged by the copy and its edits' -); - --- --------------------------------------------------------------------------- --- 6. Deprecation, deletion preconditions, archive, soft delete --- --------------------------------------------------------------------------- -select lives_ok($$ select public.deprecate_sheet_version(pg_temp.id('v2'), 'superseded') $$, 'alice deprecates v2'); -select results_eq( - $$ select status::text, deprecated_by from public.anatomical_sheet_versions where id = pg_temp.id('v2') $$, - $$ values ('deprecated', '20000000-0000-0000-0000-00000000000a'::uuid) $$, - 'v2 is deprecated' -); -select is( - (select current_version_id from public.anatomical_sheets where id = pg_temp.id('sheet')), - pg_temp.id('v1'), 'current version falls back to the latest published one (v1)' -); -update public.anatomical_sheet_versions set content = '{}'::jsonb where id = pg_temp.id('v2'); -select is( - (select content ->> 'schema_version' from public.anatomical_sheet_versions where id = pg_temp.id('v2')), - '2', 'a deprecated version is hidden from editor UPDATE' -); -reset role; -select throws_ok( - $$ update public.anatomical_sheet_versions set change_note = 'late edit' where id = pg_temp.id('v2') $$, - '42501', null, 'a deprecated version is frozen for the table owner too' -); -set local role authenticated; -select set_config('request.jwt.claims', '{"sub":"20000000-0000-0000-0000-00000000000a","role":"authenticated"}', true); -select throws_ok( - $$ select public.delete_sheet_version(pg_temp.id('v2')) $$, - '55000', null, 'v2 cannot be deleted while bob copy derives from it' -); -select throws_ok( - $$ select public.delete_anatomical_sheet(pg_temp.id('sheet')) $$, - '55000', null, 'the sheet cannot be deleted while a copy is active' -); -select lives_ok($$ select public.archive_anatomical_sheet(pg_temp.id('sheet')) $$, 'alice archives the sheet'); -select is((select count(*) from public.anatomical_sheets where id = pg_temp.id('sheet')), 1::bigint, 'the editor still reads her archived sheet'); -select set_config('request.jwt.claims', '{"sub":"20000000-0000-0000-0000-00000000000b","role":"authenticated"}', true); -select is((select count(*) from public.anatomical_sheets where id = pg_temp.id('sheet')), 0::bigint, 'an archived sheet is no longer usable by others'); -select throws_ok( - $$ select public.delete_sheet_version(pg_temp.id('fork-v1')) $$, - '55000', null, 'bob cannot delete the published version of his copy' -); -select lives_ok($$ select public.delete_anatomical_sheet(pg_temp.id('fork')) $$, 'bob soft-deletes his copy'); -select is((select count(*) from public.anatomical_sheets where id = pg_temp.id('fork')), 0::bigint, 'a deleted sheet is invisible to its creator'); - -select set_config('request.jwt.claims', '{"sub":"20000000-0000-0000-0000-00000000000a","role":"authenticated"}', true); -select lives_ok($$ select public.restore_anatomical_sheet(pg_temp.id('sheet')) $$, 'alice restores the sheet'); -select lives_ok($$ select public.delete_sheet_version(pg_temp.id('v2')) $$, 'deprecated v2 is deleted once no active copy depends on it'); -select is((select count(*) from public.anatomical_sheet_versions where id = pg_temp.id('v2')), 0::bigint, 'v2 row is gone'); -select lives_ok($$ select public.delete_sheet_version(pg_temp.id('v3')) $$, 'editor drops her own draft through the RPC'); -insert into pg_temp.ids select 'v4', public.create_sheet_draft(pg_temp.id('sheet'), null, 'after deletion'); -select is( - (select version_number from public.anatomical_sheet_versions where id = pg_temp.id('v4')), - 4, 'a deleted version number is never reused' -); -select lives_ok($$ select public.delete_sheet_asset(pg_temp.id('asset-unused')) $$, 'an unreferenced asset can be deleted'); -select throws_ok( - $$ select public.delete_sheet_asset(pg_temp.id('asset')) $$, - '55000', null, 'an asset referenced by a version cannot be deleted' -); - --- --------------------------------------------------------------------------- --- 7. Deactivated account --- --------------------------------------------------------------------------- -reset role; -update public.profiles set active = false where id = '20000000-0000-0000-0000-00000000000b'; -set local role authenticated; -select set_config('request.jwt.claims', '{"sub":"20000000-0000-0000-0000-00000000000b","role":"authenticated"}', true); -select throws_ok( - $$ select public.create_anatomical_sheet('equine', 'Nope', 'nope', pg_temp.sheet_doc(null)) $$, - '42501', null, 'a deactivated account cannot write' -); -reset role; -update public.profiles set active = true where id = '20000000-0000-0000-0000-00000000000b'; -set local role authenticated; -select set_config('request.jwt.claims', '{"sub":"20000000-0000-0000-0000-00000000000a","role":"authenticated"}', true); - --- --------------------------------------------------------------------------- --- 8. Official sheets: platform admins only --- --------------------------------------------------------------------------- -select throws_ok( - $$ select public.create_anatomical_sheet('equine', 'Officielle', 'officielle', pg_temp.sheet_doc(null), '', 'public', true) $$, - '42501', null, 'a plain user cannot create an official sheet' -); -select set_config('request.jwt.claims', '{"sub":"20000000-0000-0000-0000-000000000001","role":"authenticated"}', true); -insert into pg_temp.ids select 'official', public.create_anatomical_sheet( - 'equine', 'Officielle test', 'officielle-test', pg_temp.sheet_doc(null), 'Fiche officielle', 'public', true -); -select results_eq( - $$ select creator_user_id, is_official, visibility::text from public.anatomical_sheets where id = pg_temp.id('official') $$, - $$ values (null::uuid, true, 'public') $$, - 'official sheet is platform-owned' -); -select set_config('request.jwt.claims', '{"sub":"20000000-0000-0000-0000-00000000000a","role":"authenticated"}', true); -select is((select count(*) from public.anatomical_sheets where id = pg_temp.id('official')), 1::bigint, 'alice sees the public official sheet'); -select is( - (select count(*) from public.anatomical_sheet_versions where sheet_id = pg_temp.id('official')), - 0::bigint, 'alice does not see the official draft' -); -select throws_ok( - $$ select public.create_sheet_draft(pg_temp.id('official')) $$, - '42501', null, 'alice cannot edit the official sheet' -); - --- --------------------------------------------------------------------------- --- 9. Anonymous --- --------------------------------------------------------------------------- -set local role anon; -select set_config('request.jwt.claims', '', true); -select throws_ok($$ select * from public.species $$, '42501', null, 'anon cannot read species'); -select throws_ok($$ select * from public.anatomical_sheets $$, '42501', null, 'anon cannot read sheets'); -select throws_ok( - $$ select public.create_anatomical_sheet('equine', 'x', 'x-x', '{}'::jsonb) $$, - '42501', null, 'anon cannot call create_anatomical_sheet' -); - --- --------------------------------------------------------------------------- --- 10. Audit trail --- --------------------------------------------------------------------------- -reset role; -select results_eq( - $$ select action from audit.audit_logs - where resource_id in (pg_temp.id('sheet'), pg_temp.id('v1'), pg_temp.id('v2'), pg_temp.id('v3'), pg_temp.id('fork'), - pg_temp.id('asset'), pg_temp.id('asset-unused')) - group by action order by action collate "C" $$, - $$ values ('anatomical_sheet.archived'), ('anatomical_sheet.created'), ('anatomical_sheet.deleted'), - ('anatomical_sheet.forked'), ('anatomical_sheet.restored'), ('anatomical_sheet.visibility_changed'), - ('anatomical_sheet_asset.deleted'), ('anatomical_sheet_asset.registered'), - ('anatomical_sheet_version.created'), ('anatomical_sheet_version.deleted'), - ('anatomical_sheet_version.deprecated'), ('anatomical_sheet_version.published') $$, - 'every lifecycle step left an audit event' -); +-- The new workflow RPCs exist +select has_function('public', 'create_official_sheet', 'create_official_sheet exists'); +select has_function('public', 'publish_sheet_version', 'publish_sheet_version exists'); +select has_function('public', 'create_sheet_working_copy', 'create_sheet_working_copy exists'); select * from finish(); rollback; diff --git a/supabase/tests/006_sheet_asset_storage.sql b/supabase/tests/006_sheet_asset_storage.sql index e2510019..04cea5cc 100644 --- a/supabase/tests/006_sheet_asset_storage.sql +++ b/supabase/tests/006_sheet_asset_storage.sql @@ -1,155 +1,173 @@ --- Storage read policy on bucket anatomical-sheet-assets: an object is readable --- through a sheet (published reference for users, any version for editors), --- never through its hash alone. No API writes. +-- Sheet-asset Storage after V1-2.1 (M4, M5): the bucket is private and 2 MiB, +-- the read predicate follows the catalogue rules (contract §9.4), the editor +-- upload INSERT policy exists, no UPDATE/DELETE policy. Rows are seeded +-- directly (table owner) to exercise the policy, not the RPCs (those are 016). begin; -select plan(28); +select plan(15); -insert into auth.users (id, email) values - ('30000000-0000-0000-0000-00000000000a', 'alice-assets@test.local'), - ('30000000-0000-0000-0000-00000000000b', 'bob-assets@test.local'); +-- Bucket +select is((select public from storage.buckets where id = 'anatomical-sheet-assets'), false, 'the bucket is private'); +select is((select file_size_limit from storage.buckets where id = 'anatomical-sheet-assets'), 2097152::bigint, 'the bucket limit is 2 MiB (M5)'); -create table pg_temp.ids (key text primary key, id uuid not null); -create function pg_temp.id(p_key text) returns uuid language sql stable -as $$ select id from pg_temp.ids where key = p_key $$; -grant all on pg_temp.ids to anon, authenticated, service_role; -grant execute on function pg_temp.id(text) to anon, authenticated, service_role; +-- Policies on storage.objects for the bucket: read + editor insert, nothing else. +select is( + (select count(*) from pg_policies where schemaname='storage' and tablename='objects' + and (coalesce(qual,'')||coalesce(with_check,'')) like '%anatomical-sheet-assets%'), + 2::bigint, 'two policies name the bucket (read, editor insert)' +); +select is( + (select count(*) from pg_policies where schemaname='storage' and tablename='objects' and cmd in ('UPDATE','DELETE') + and (coalesce(qual,'')||coalesce(with_check,'')) like '%anatomical-sheet-assets%'), + 0::bigint, 'no UPDATE or DELETE policy on the bucket' +); + +-- Accounts: owner, editor (admin + capability), reader (catalog_reader), plain. +insert into auth.users (id, email, email_confirmed_at) values + ('30000000-0000-0000-0000-000000000001', 'own-st@test.local', now()), + ('30000000-0000-0000-0000-00000000000e', 'ed-st@test.local', now()), + ('30000000-0000-0000-0000-0000000000d0', 'rd-st@test.local', now()), + ('30000000-0000-0000-0000-0000000000d1', 'pl-st@test.local', now()); +insert into auth.mfa_factors (id, user_id, factor_type, status, created_at, updated_at) + values (gen_random_uuid(), '30000000-0000-0000-0000-00000000000e', 'totp', 'verified', now(), now()); +insert into auth.sessions (id, user_id, aal) values + ('31000000-0000-0000-0000-000000000001', '30000000-0000-0000-0000-000000000001', 'aal2'), + ('31000000-0000-0000-0000-00000000000e', '30000000-0000-0000-0000-00000000000e', 'aal2'); +select set_config('request.jwt.claims', '', true); +select private.assign_platform_role(null, '30000000-0000-0000-0000-000000000001', 'owner'); +select private.assign_platform_role(null, '30000000-0000-0000-0000-00000000000e', 'admin'); +insert into public.anatomical_catalog_grants (user_id, grant_kind, reason, verification_note, granted_by) values + ('30000000-0000-0000-0000-00000000000e', 'sheet_editor', 'author', 'checked', '30000000-0000-0000-0000-000000000001'), + ('30000000-0000-0000-0000-0000000000d0', 'catalog_reader', 'beta', null, '30000000-0000-0000-0000-000000000001'); + +-- An official sheet with a published version (asset A), a deprecated version +-- (asset B), and a draft (asset C, confirmed). A and B are referenced by +-- non-draft versions; C only by the draft. +insert into public.anatomical_sheets (id, species_id, name, slug, is_official, visibility, status, current_version_id) + values ('32000000-0000-0000-0000-000000000001', 'equine', 'Pub', 'pub-storage', true, 'private', 'active', null); +insert into public.anatomical_sheet_assets (id, sheet_id, sha256, byte_size, file_name, uploaded_at) values + ('32000000-0000-0000-0000-00000000000a', '32000000-0000-0000-0000-000000000001', repeat('a',64), 100, 'a.svg', now()), + ('32000000-0000-0000-0000-00000000000b', '32000000-0000-0000-0000-000000000001', repeat('b',64), 100, 'b.svg', now()), + ('32000000-0000-0000-0000-00000000000c', '32000000-0000-0000-0000-000000000001', repeat('c',64), 100, 'c.svg', now()); + +-- The content trigger needs an authenticated actor for a non-historical +-- sheet, so the direct version seeding carries the owner's claim. +select set_config('request.jwt.claims', '{"sub":"30000000-0000-0000-0000-000000000001"}', true); --- Minimal publishable document with one main view on a given asset. create function pg_temp.doc(p_asset uuid) returns jsonb language sql as $$ - select jsonb_build_object( - 'schema_version', 2, 'species_id', 'equine', - 'name', jsonb_build_object('fr', 'A', 'en', 'A'), - 'description', '{}'::jsonb, 'scope_disclaimer', '{}'::jsonb, - 'attribution', jsonb_build_object('authors', '[]'::jsonb, 'license', null, 'notes', null), - 'vertebral_config', jsonb_build_object('regions', '[]'::jsonb), - 'categories', '[]'::jsonb, - 'views', jsonb_build_array(jsonb_build_object('id', 'main', 'kind', 'main', - 'name', jsonb_build_object('fr', 'V', 'en', 'V'), 'svg_asset_id', p_asset, 'view_box', null)), - 'annotations', '[]'::jsonb, 'finding_zones', '[]'::jsonb); + select jsonb_build_object('schema_version',2,'species_id','equine', + 'name',jsonb_build_object('fr','P','en','P'),'description','{}'::jsonb,'scope_disclaimer','{}'::jsonb, + 'attribution',jsonb_build_object('authors','[]'::jsonb,'license',null,'notes',null), + 'vertebral_config',jsonb_build_object('regions','[]'::jsonb),'references','[]'::jsonb, + 'categories','[]'::jsonb, + 'views',jsonb_build_array(jsonb_build_object('id','main','kind','main','name',jsonb_build_object('fr','V','en','V'),'svg_asset_id',p_asset,'view_box',null)), + 'annotations','[]'::jsonb,'finding_zones','[]'::jsonb); $$; -grant execute on function pg_temp.doc(uuid) to authenticated, service_role; +insert into public.anatomical_sheet_versions (id, sheet_id, version_number, status, document_schema_version, content, published_at, document_fingerprint) + values ('33000000-0000-0000-0000-000000000001', '32000000-0000-0000-0000-000000000001', 1, 'published', 2, pg_temp.doc('32000000-0000-0000-0000-00000000000a'), now(), repeat('0',64)); +insert into public.anatomical_sheet_versions (id, sheet_id, version_number, status, document_schema_version, content, published_at, deprecated_at, document_fingerprint) + values ('33000000-0000-0000-0000-000000000002', '32000000-0000-0000-0000-000000000001', 2, 'deprecated', 2, pg_temp.doc('32000000-0000-0000-0000-00000000000b'), now(), now(), repeat('0',64)); +insert into public.anatomical_sheet_versions (id, sheet_id, version_number, status, document_schema_version, content) + values ('33000000-0000-0000-0000-000000000003', '32000000-0000-0000-0000-000000000001', 3, 'draft', 2, pg_temp.doc('32000000-0000-0000-0000-00000000000c')); +update public.anatomical_sheets set current_version_id = '33000000-0000-0000-0000-000000000001' where id = '32000000-0000-0000-0000-000000000001'; +insert into storage.objects (bucket_id, name, metadata) values + ('anatomical-sheet-assets', repeat('a',64)||'.svg', '{"size":100}'), + ('anatomical-sheet-assets', repeat('b',64)||'.svg', '{"size":100}'), + ('anatomical-sheet-assets', repeat('c',64)||'.svg', '{"size":100}'); +-- A fourth object whose row is pending (never confirmed): readable by nobody. +insert into public.anatomical_sheet_assets (id, sheet_id, sha256, byte_size, file_name) + values ('32000000-0000-0000-0000-00000000000d', '32000000-0000-0000-0000-000000000001', repeat('d',64), 100, 'd.svg'); +insert into storage.objects (bucket_id, name, metadata) values ('anatomical-sheet-assets', repeat('d',64)||'.svg', '{"size":100}'); --- 1. Bucket contract -select is((select public from storage.buckets where id = 'anatomical-sheet-assets'), false, 'bucket is private'); -select is( - (select allowed_mime_types from storage.buckets where id = 'anatomical-sheet-assets'), - array['image/svg+xml'], 'bucket accepts SVG only' -); -select is( - (select count(*) from pg_policies where schemaname = 'storage' and tablename = 'objects' - and policyname = 'anatomical_sheet_assets_read' and cmd = 'SELECT'), - 1::bigint, 'one SELECT policy on storage.objects for the bucket' -); -select is( - (select count(*) from pg_policies where schemaname = 'storage' and tablename = 'objects' - and policyname like 'anatomical_sheet_assets%' and cmd <> 'SELECT'), - 0::bigint, 'no write policy on the bucket for API roles' -); +create function pg_temp.act(p_uid uuid, p_sid uuid, p_aal text) returns void language sql as $$ + select set_config('request.jwt.claims', jsonb_build_object('sub',p_uid,'role','authenticated','aal',p_aal,'session_id',p_sid)::text, true); +$$; +grant execute on function pg_temp.act(uuid,uuid,text) to authenticated; --- 2. Alice: sheet with published v1 on asset A, draft v2 on asset B; C is registered but unreferenced +-- Reader (catalog_reader, aal1): the published and deprecated drawings only. set local role authenticated; -select set_config('request.jwt.claims', '{"sub":"30000000-0000-0000-0000-00000000000a","role":"authenticated"}', true); -insert into pg_temp.ids select 'sheet', public.create_anatomical_sheet('equine', 'Assets', 'assets-test', pg_temp.doc(null)); -insert into pg_temp.ids select 'a', public.register_sheet_asset(pg_temp.id('sheet'), repeat('a', 64), 100, 'A.svg'); -insert into pg_temp.ids select 'b', public.register_sheet_asset(pg_temp.id('sheet'), repeat('b', 64), 100, 'B.svg'); -insert into pg_temp.ids select 'c', public.register_sheet_asset(pg_temp.id('sheet'), repeat('c', 64), 100, 'C.svg'); -insert into pg_temp.ids select 'v1', id from public.anatomical_sheet_versions where sheet_id = pg_temp.id('sheet'); -update public.anatomical_sheet_versions set content = pg_temp.doc(pg_temp.id('a')) where id = pg_temp.id('v1'); -select lives_ok($$ select public.publish_sheet_version(pg_temp.id('v1')) $$, 'v1 published on asset A'); -insert into pg_temp.ids select 'v2', public.create_sheet_draft(pg_temp.id('sheet')); -update public.anatomical_sheet_versions set content = pg_temp.doc(pg_temp.id('b')) where id = pg_temp.id('v2'); +select pg_temp.act('30000000-0000-0000-0000-0000000000d0', gen_random_uuid(), 'aal1'); +select results_eq( + $$ select name from storage.objects where bucket_id='anatomical-sheet-assets' order by name $$, + $$ values (repeat('a',64)||'.svg'), (repeat('b',64)||'.svg') $$, + 'a catalogue reader reads the published and deprecated drawings, not the draft or pending ones' +); --- Objects uploaded by the operator (owner session), then confirmed through the --- service-role RPC for A and B only; C stays metadata without bytes. -reset role; -insert into storage.objects (bucket_id, name) values - ('anatomical-sheet-assets', repeat('a', 64) || '.svg'), - ('anatomical-sheet-assets', repeat('b', 64) || '.svg'), - ('anatomical-sheet-assets', repeat('c', 64) || '.svg'), - ('anatomical-sheet-assets', repeat('d', 64) || '.svg'); -set local role authenticated; -select set_config('request.jwt.claims', '{"sub":"30000000-0000-0000-0000-00000000000a","role":"authenticated"}', true); -select is((select count(*) from storage.objects where bucket_id = 'anatomical-sheet-assets'), 0::bigint, 'nothing is readable before the upload is confirmed'); +-- Editor at aal2: every uploaded drawing of the official sheet (a, b, c), not the pending d. +select pg_temp.act('30000000-0000-0000-0000-00000000000e', '31000000-0000-0000-0000-00000000000e', 'aal2'); +select results_eq( + $$ select name from storage.objects where bucket_id='anatomical-sheet-assets' order by name $$, + $$ values (repeat('a',64)||'.svg'), (repeat('b',64)||'.svg'), (repeat('c',64)||'.svg') $$, + 'an editor at aal2 reads every confirmed drawing of the official sheet, not the pending one' +); + +-- Editor at aal1 (no live aal2 session): the capability branch does not apply, +-- but a capability holder also has catalogue access, so the reader branch still +-- shows the published and deprecated drawings (not the draft's). +select pg_temp.act('30000000-0000-0000-0000-00000000000e', gen_random_uuid(), 'aal1'); +select results_eq( + $$ select name from storage.objects where bucket_id='anatomical-sheet-assets' order by name $$, + $$ values (repeat('a',64)||'.svg'), (repeat('b',64)||'.svg') $$, + 'the editor at aal1 falls back to the reader branch: published and deprecated only' +); + +-- A plain confirmed account with no right: nothing. +select pg_temp.act('30000000-0000-0000-0000-0000000000d1', gen_random_uuid(), 'aal1'); +select is((select count(*) from storage.objects where bucket_id='anatomical-sheet-assets'), 0::bigint, + 'a confirmed account without any right reads nothing'); + +-- The INSERT policy only allows a pending key of one''s own sheet: a confirmed +-- key is refused by its WITH CHECK (no UPDATE/DELETE policy exists at all, per +-- the census above; the runtime refusal of those is a storage-API concern, not +-- RLS, so it is not asserted here). +select pg_temp.act('30000000-0000-0000-0000-00000000000e', '31000000-0000-0000-0000-00000000000e', 'aal2'); select throws_ok( - $$ select public.confirm_sheet_asset_upload(pg_temp.id('a')) $$, - '42501', null, 'an editor cannot confirm an upload (service role only)' + $$ insert into storage.objects (bucket_id, name) values ('anatomical-sheet-assets', repeat('a',64)||'.svg') $$, + '42501', null, 'an editor cannot insert a confirmed (non-pending) object key' +); + +-- A fifth asset, pending, with no object yet: the editor uploads its key. +reset role; +select set_config('request.jwt.claims', '{"sub":"30000000-0000-0000-0000-000000000001"}', true); +insert into public.anatomical_sheet_assets (id, sheet_id, sha256, byte_size, file_name) + values ('32000000-0000-0000-0000-00000000000e', '32000000-0000-0000-0000-000000000001', repeat('e',64), 100, 'e.svg'); +set local role authenticated; +select pg_temp.act('30000000-0000-0000-0000-00000000000e', '31000000-0000-0000-0000-00000000000e', 'aal2'); +select lives_ok( + $$ insert into storage.objects (bucket_id, name, metadata) values ('anatomical-sheet-assets', repeat('e',64)||'.svg', '{"size":100}') $$, + 'an editor uploads the pending key of their own sheet' +); + +-- confirm with the storage check: a wrong size is refused, the right one works. +reset role; +update storage.objects set metadata = '{"size":999}' where bucket_id='anatomical-sheet-assets' and name = repeat('d',64)||'.svg'; +set local role authenticated; +select pg_temp.act('30000000-0000-0000-0000-00000000000e', '31000000-0000-0000-0000-00000000000e', 'aal2'); +select throws_ok( + $$ select public.confirm_sheet_asset_upload('32000000-0000-0000-0000-00000000000d') $$, + 'P0001', 'size_mismatch', 'confirm refuses a size that does not match the row (F7)' +); +reset role; +update storage.objects set metadata = '{"size":100}' where bucket_id='anatomical-sheet-assets' and name = repeat('d',64)||'.svg'; +set local role authenticated; +select pg_temp.act('30000000-0000-0000-0000-00000000000e', '31000000-0000-0000-0000-00000000000e', 'aal2'); +select lives_ok( + $$ select public.confirm_sheet_asset_upload('32000000-0000-0000-0000-00000000000d') $$, + 'confirm succeeds when the object exists and the size matches' +); +select is((select uploaded_at is not null from public.anatomical_sheet_assets where id='32000000-0000-0000-0000-00000000000d'), + true, 'the row is now confirmed'); + +-- The operator read RPC: service role only. +select throws_ok( + $$ select public.get_sheet_asset_state('32000000-0000-0000-0000-00000000000a') $$, + '42501', null, 'an editor cannot call the operator read RPC (EXECUTE is service_role only)' ); set local role service_role; -select lives_ok($$ select public.confirm_sheet_asset_upload(pg_temp.id('a')) $$, 'service role confirms asset A'); -select lives_ok($$ select public.confirm_sheet_asset_upload(pg_temp.id('b')) $$, 'service role confirms asset B'); -select is(public.confirm_sheet_asset_upload(pg_temp.id('a')), pg_temp.id('a'), 'confirming twice is idempotent'); -reset role; - --- 3. Editor reads every object of her sheet (published, draft, unreferenced), not foreign ones -set local role authenticated; -select set_config('request.jwt.claims', '{"sub":"30000000-0000-0000-0000-00000000000a","role":"authenticated"}', true); -select results_eq( - $$ select name from storage.objects where bucket_id = 'anatomical-sheet-assets' order by name $$, - $$ values (repeat('a', 64) || '.svg'), (repeat('b', 64) || '.svg') $$, - 'editor reads the confirmed objects of her sheet; unconfirmed and foreign objects stay hidden' -); - --- 4. Bob: private sheet → nothing; claiming the hash on his own sheet opens nothing -select set_config('request.jwt.claims', '{"sub":"30000000-0000-0000-0000-00000000000b","role":"authenticated"}', true); -select is((select count(*) from storage.objects where bucket_id = 'anatomical-sheet-assets'), 0::bigint, 'other user reads nothing from a private sheet'); -insert into pg_temp.ids select 'bob-sheet', public.create_anatomical_sheet('equine', 'Claim', 'claim-test', pg_temp.doc(null)); -select lives_ok( - $$ select public.register_sheet_asset(pg_temp.id('bob-sheet'), repeat('a', 64), 100, 'A.svg') $$, - 'bob registers the known hash on his own sheet' -); -select is((select count(*) from storage.objects where bucket_id = 'anatomical-sheet-assets'), 0::bigint, 'a self-registered hash without a confirmed upload opens no object'); -select set_config('request.jwt.claims', '{"sub":"30000000-0000-0000-0000-00000000000a","role":"authenticated"}', true); -select lives_ok($$ select public.set_sheet_visibility(pg_temp.id('sheet'), 'public') $$, 'alice makes the sheet public'); -select set_config('request.jwt.claims', '{"sub":"30000000-0000-0000-0000-00000000000b","role":"authenticated"}', true); -select results_eq( - $$ select name from storage.objects where bucket_id = 'anatomical-sheet-assets' order by name $$, - $$ values (repeat('a', 64) || '.svg') $$, - 'other user reads only the object a published version references (not the draft asset, not the unreferenced one)' -); -select throws_ok( - $$ insert into storage.objects (bucket_id, name) values ('anatomical-sheet-assets', 'x.svg') $$, - '42501', null, 'authenticated cannot upload into the bucket' -); --- The real image also carries storage.protect_delete (statement trigger), so a --- direct DELETE is asserted through the policy census, not by running it. +select set_config('request.jwt.claims', '{"role":"service_role"}', true); select is( - (select count(*) from pg_policies where schemaname = 'storage' and tablename = 'objects' - and cmd in ('INSERT', 'UPDATE', 'DELETE') - and (coalesce(qual, '') like '%anatomical-sheet-assets%' or coalesce(with_check, '') like '%anatomical-sheet-assets%')), - 0::bigint, 'no API role has an insert/update/delete policy on the bucket objects' + (select public.get_sheet_asset_state('32000000-0000-0000-0000-00000000000a') ->> 'sha256'), + repeat('a',64), 'the operator read RPC returns the asset state for the service role' ); --- Name variants never match the strict key -select set_config('request.jwt.claims', '{"sub":"30000000-0000-0000-0000-00000000000a","role":"authenticated"}', true); -select ok( - not private.can_read_sheet_asset_object('30000000-0000-0000-0000-00000000000a', repeat('a', 64)) - and not private.can_read_sheet_asset_object('30000000-0000-0000-0000-00000000000a', upper(repeat('a', 64)) || '.svg') - and not private.can_read_sheet_asset_object('30000000-0000-0000-0000-00000000000a', 'x/' || repeat('a', 64) || '.svg') - and not private.can_read_sheet_asset_object('30000000-0000-0000-0000-00000000000a', repeat('a', 64) || '.svg/'), - 'object name must be exactly .svg' -); --- A deprecated version still publishes its asset -select lives_ok($$ select public.publish_sheet_version(pg_temp.id('v2')) $$, 'v2 (asset B) published'); -select lives_ok($$ select public.deprecate_sheet_version(pg_temp.id('v1'), 'old') $$, 'v1 (asset A) deprecated'); -select set_config('request.jwt.claims', '{"sub":"30000000-0000-0000-0000-00000000000b","role":"authenticated"}', true); -select results_eq( - $$ select name from storage.objects where bucket_id = 'anatomical-sheet-assets' order by name $$, - $$ values (repeat('a', 64) || '.svg'), (repeat('b', 64) || '.svg') $$, - 'published and deprecated references both open the object for users of a public sheet' -); - --- 5. Archived sheet hides objects from others; anon sees nothing -select set_config('request.jwt.claims', '{"sub":"30000000-0000-0000-0000-00000000000a","role":"authenticated"}', true); -select lives_ok($$ select public.archive_anatomical_sheet(pg_temp.id('sheet')) $$, 'alice archives'); -select set_config('request.jwt.claims', '{"sub":"30000000-0000-0000-0000-00000000000b","role":"authenticated"}', true); -select is((select count(*) from storage.objects where bucket_id = 'anatomical-sheet-assets'), 0::bigint, 'archived sheet: others read nothing'); -select set_config('request.jwt.claims', '{"sub":"30000000-0000-0000-0000-00000000000a","role":"authenticated"}', true); -select lives_ok($$ select public.restore_anatomical_sheet(pg_temp.id('sheet')) $$, 'alice restores'); -select lives_ok($$ select public.delete_anatomical_sheet(pg_temp.id('sheet')) $$, 'alice soft-deletes the sheet'); -select is((select count(*) from storage.objects where bucket_id = 'anatomical-sheet-assets'), 0::bigint, 'deleted sheet: even the creator reads nothing'); -set local role anon; -select set_config('request.jwt.claims', '', true); -select is((select count(*) from storage.objects where bucket_id = 'anatomical-sheet-assets'), 0::bigint, 'anon reads nothing'); - select * from finish(); rollback; diff --git a/supabase/tests/007_equine_seed.sql b/supabase/tests/007_equine_seed.sql index 1923ab6b..fa3b1f25 100644 --- a/supabase/tests/007_equine_seed.sql +++ b/supabase/tests/007_equine_seed.sql @@ -1,62 +1,38 @@ --- Official equine sheet seed (supabase/seed/anatomical-sheets/equine/draft): --- present as a platform-owned DRAFT, never published by the seed, publishable --- by platform admins only, content accepted by the SQL referential gate. +-- Official equine seed after V1-2.1: the historical sheet is present as a +-- platform-owned DRAFT, protected on the server (never saved, submitted, +-- published, archived or deleted), visible to capability holders at aal2 and +-- to no one else (no published version → not in the catalogue). Contract §14.2. begin; -select plan(20); - -insert into auth.users (id, email) values - ('40000000-0000-0000-0000-000000000001', 'root-seed@test.local'), - ('40000000-0000-0000-0000-00000000000a', 'alice-seed@test.local'); -select private.assign_platform_role(null, '40000000-0000-0000-0000-000000000001', 'owner'); +select plan(17); create table pg_temp.ids (key text primary key, id uuid not null); -create function pg_temp.id(p_key text) returns uuid language sql stable -as $$ select id from pg_temp.ids where key = p_key $$; +create function pg_temp.id(p_key text) returns uuid language sql stable as $$ select id from pg_temp.ids where key = p_key $$; grant all on pg_temp.ids to anon, authenticated, service_role; grant execute on function pg_temp.id(text) to anon, authenticated, service_role; - insert into pg_temp.ids select 'sheet', id from public.anatomical_sheets where slug = 'faunosteo-cheval' and is_official; insert into pg_temp.ids select 'draft', id from public.anatomical_sheet_versions where sheet_id = pg_temp.id('sheet'); -- 1. Seeded state +select is(pg_temp.id('sheet'), '503dc301-a8b1-50d4-9e44-0919b2fc2916'::uuid, 'the historical sheet keeps its fixed id'); select results_eq( $$ select species_id, creator_user_id, is_official, visibility::text, status::text, current_version_id from public.anatomical_sheets where id = pg_temp.id('sheet') $$, $$ values ('equine', null::uuid, true, 'private', 'active', null::uuid) $$, - 'official equine sheet: platform-owned, private, active, no published version' + 'historical sheet: platform-owned, private, active, no published version' ); select results_eq( - $$ select version_number, status::text, document_schema_version, published_at - from public.anatomical_sheet_versions where sheet_id = pg_temp.id('sheet') $$, - $$ values (1, 'draft', 2, null::timestamptz) $$, - 'exactly one version, draft v1, never published' -); -select is((select count(*) from public.anatomical_sheet_assets where sheet_id = pg_temp.id('sheet')), 1::bigint, 'one SVG asset registered (the cleaned drawing)'); -select is( - (select content ->> 'species_id' from public.anatomical_sheet_versions where id = pg_temp.id('draft')), - 'equine', 'document species is equine' -); -select is( - (select jsonb_array_length(content -> 'views') from public.anatomical_sheet_versions where id = pg_temp.id('draft')), - 2, 'document has two views' + $$ select version_number, status::text, document_schema_version, revision, coalesce(array_length(authors,1),0), published_at + from public.anatomical_sheet_versions where id = pg_temp.id('draft') $$, + $$ values (1, 'draft', 2, 0, 0, null::timestamptz) $$, + 'one version: draft v1, schema 2, revision 0, empty author set, never published' ); +select is((select count(*) from public.anatomical_sheet_assets where sheet_id = pg_temp.id('sheet')), 1::bigint, 'one SVG asset registered'); +select is((select content ->> 'species_id' from public.anatomical_sheet_versions where id = pg_temp.id('draft')), 'equine', 'document species is equine'); +select is((select jsonb_array_length(content -> 'annotations') from public.anatomical_sheet_versions where id = pg_temp.id('draft')), 28, '28 annotations'); +select is((select jsonb_array_length(content -> 'finding_zones') from public.anatomical_sheet_versions where id = pg_temp.id('draft')), 27, '27 finding zones'); select ok( - (select content -> 'views' -> 1 -> 'svg_asset_id' = 'null'::jsonb - and jsonb_typeof(content -> 'views' -> 1 -> 'view_box') = 'object' - from public.anatomical_sheet_versions where id = pg_temp.id('draft')), - 'head view is a crop of the main drawing: no asset, a view_box' -); -select is( - (select jsonb_array_length(content -> 'annotations') from public.anatomical_sheet_versions where id = pg_temp.id('draft')), - 28, 'document has 28 annotations (27 legacy + carpus)' -); -select is( - (select jsonb_array_length(content -> 'finding_zones') from public.anatomical_sheet_versions where id = pg_temp.id('draft')), - 27, 'document has 27 finding zones (26 legacy + carpus)' -); -select is( - (select private.sheet_document_issues(content) from public.anatomical_sheet_versions where id = pg_temp.id('draft')), - '{}'::text[], 'SQL referential gate finds no issue' + (select private.sheet_document_has_shape(content) from public.anatomical_sheet_versions where id = pg_temp.id('draft')), + 'the seeded document has the structural shape SQL still checks' ); select is( (select private.sheet_document_unknown_assets(sheet_id, content) from public.anatomical_sheet_versions where id = pg_temp.id('draft')), @@ -67,54 +43,58 @@ select is( 1::bigint, 'the seed import is audited as a system action' ); --- 2. Nobody publishes it by accident: plain users cannot even see the draft -set local role authenticated; -select set_config('request.jwt.claims', '{"sub":"40000000-0000-0000-0000-00000000000a","role":"authenticated"}', true); -select is((select count(*) from public.anatomical_sheets where id = pg_temp.id('sheet')), 0::bigint, 'a private official draft is invisible to plain users'); -select throws_ok( - $$ select public.publish_sheet_version(pg_temp.id('draft')) $$, - '42501', null, 'a plain user cannot publish the official draft' -); --- A platform admin can (the explicit decision step), and the gate would accept the document -select set_config('request.jwt.claims', '{"sub":"40000000-0000-0000-0000-000000000001","role":"authenticated"}', true); -select is((select count(*) from public.anatomical_sheet_versions where id = pg_temp.id('draft')), 1::bigint, 'a platform admin sees the official draft'); -select lives_ok($$ select public.publish_sheet_version(pg_temp.id('draft')) $$, 'a platform admin could publish it (rolled back here)'); +-- 2. An editor with the capability (aal2) is set up, then the protections. +insert into auth.users (id, email, email_confirmed_at) values + ('40000000-0000-0000-0000-000000000001', 'own-eq@test.local', now()), + ('40000000-0000-0000-0000-00000000000e', 'ed-eq@test.local', now()), + ('40000000-0000-0000-0000-0000000000a0', 'pl-eq@test.local', now()); +insert into auth.mfa_factors (id, user_id, factor_type, status, created_at, updated_at) + values (gen_random_uuid(), '40000000-0000-0000-0000-00000000000e', 'totp', 'verified', now(), now()); +insert into auth.sessions (id, user_id, aal) values ('41000000-0000-0000-0000-00000000000e', '40000000-0000-0000-0000-00000000000e', 'aal2'); +select set_config('request.jwt.claims', '', true); +select private.assign_platform_role(null, '40000000-0000-0000-0000-000000000001', 'owner'); +select private.assign_platform_role(null, '40000000-0000-0000-0000-00000000000e', 'admin'); +insert into public.anatomical_catalog_grants (user_id, grant_kind, reason, verification_note, granted_by) values + ('40000000-0000-0000-0000-00000000000e', 'sheet_editor', 'equine work', 'checked', '40000000-0000-0000-0000-000000000001'), + ('40000000-0000-0000-0000-00000000000e', 'sheet_publisher', 'equine work', 'checked', '40000000-0000-0000-0000-000000000001'); + +create function pg_temp.act(p_uid uuid, p_sid uuid, p_aal text) returns void language sql as $$ + select set_config('request.jwt.claims', jsonb_build_object('sub',p_uid,'role','authenticated','aal',p_aal,'session_id',p_sid)::text, true); +$$; +grant execute on function pg_temp.act(uuid,uuid,text) to authenticated; --- 3. Storage: the seed registers metadata only; after the operator upload + confirmation, --- a platform admin reads the object and a plain user none. A base where the operator --- already uploaded and confirmed the drawing (DEV) is brought back to the seed's state --- inside this transaction: the confirmation is cleared, and the object already in the --- bucket stands for the upload (content-addressed key, never written twice). Reads are --- counted on the seed's own key: other objects of the bucket do not count. -reset role; -create table pg_temp.seed_objects as - select a.sha256 || '.svg' as name from public.anatomical_sheet_assets a where a.sheet_id = pg_temp.id('sheet'); -grant select on pg_temp.seed_objects to authenticated, service_role; -update public.anatomical_sheet_assets set uploaded_at = null where sheet_id = pg_temp.id('sheet'); -insert into storage.objects (bucket_id, name) - select 'anatomical-sheet-assets', k.name from pg_temp.seed_objects k - where not exists (select 1 from storage.objects o where o.bucket_id = 'anatomical-sheet-assets' and o.name = k.name); -select is( - (select count(*) from storage.objects o join pg_temp.seed_objects k on k.name = o.name where o.bucket_id = 'anatomical-sheet-assets'), - 1::bigint, 'the drawing is in the bucket once, under its content address' -); set local role authenticated; -select set_config('request.jwt.claims', '{"sub":"40000000-0000-0000-0000-000000000001","role":"authenticated"}', true); -select is((select count(*) from storage.objects where bucket_id = 'anatomical-sheet-assets' and name in (select name from pg_temp.seed_objects)), - 0::bigint, 'seed objects are not readable before confirmation'); -set local role service_role; -select is( - (select count(*) from public.anatomical_sheet_assets a where a.sheet_id = pg_temp.id('sheet') - and public.confirm_sheet_asset_upload(a.id) = a.id), - 1::bigint, 'operator confirms the upload' +select pg_temp.act('40000000-0000-0000-0000-00000000000e', '41000000-0000-0000-0000-00000000000e', 'aal2'); +-- The capability holder sees the draft (caller_can_see_official_sheet). +select is((select count(*) from public.anatomical_sheet_versions where id = pg_temp.id('draft')), 1::bigint, + 'a capability holder at aal2 sees the historical draft'); + +-- Every write path refuses the historical sheet. +select throws_ok( + $$ select public.save_sheet_draft(pg_temp.id('draft'), 0, '{"schema_version":2,"species_id":"equine"}'::jsonb, 'x') $$, + '42501', 'sheet.historical_read_only', 'save refused on the historical sheet' ); -set local role authenticated; -select set_config('request.jwt.claims', '{"sub":"40000000-0000-0000-0000-000000000001","role":"authenticated"}', true); -select is((select count(*) from storage.objects where bucket_id = 'anatomical-sheet-assets' and name in (select name from pg_temp.seed_objects)), - 1::bigint, 'a platform admin reads the official SVG'); -select set_config('request.jwt.claims', '{"sub":"40000000-0000-0000-0000-00000000000a","role":"authenticated"}', true); -select is((select count(*) from storage.objects where bucket_id = 'anatomical-sheet-assets' and name in (select name from pg_temp.seed_objects)), - 0::bigint, 'a plain user reads no official draft SVG'); +select throws_ok( + $$ select public.submit_sheet_review(pg_temp.id('draft'), 0, 'x') $$, + '42501', 'sheet.historical_read_only', 'submit refused on the historical sheet' +); +select throws_ok( + $$ select public.register_sheet_asset(pg_temp.id('sheet'), repeat('e',64), 100, 'x.svg') $$, + '42501', 'sheet.historical_read_only', 'register refused on the historical sheet' +); +select throws_ok( + $$ select public.archive_anatomical_sheet(pg_temp.id('sheet')) $$, + '42501', 'sheet.historical_read_only', 'archive refused on the historical sheet' +); +select throws_ok( + $$ delete from public.anatomical_sheet_versions where id = pg_temp.id('draft') $$, + '42501', null, 'the historical draft cannot be deleted (trigger)' +); + +-- 3. A plain confirmed account sees nothing (no published version, no capability). +select pg_temp.act('40000000-0000-0000-0000-0000000000a0', gen_random_uuid(), 'aal1'); +select is((select count(*) from public.anatomical_sheets where id = pg_temp.id('sheet')), 0::bigint, + 'a plain account does not see the historical sheet (no published version)'); select * from finish(); rollback; diff --git a/supabase/tests/008_sheet_document_schema_v2.sql b/supabase/tests/008_sheet_document_schema_v2.sql deleted file mode 100644 index 6f60463c..00000000 --- a/supabase/tests/008_sheet_document_schema_v2.sql +++ /dev/null @@ -1,98 +0,0 @@ --- Document schema_version 2: references registry, review status, count --- ranges. Only version 2 is stored; the SQL gate re-checks the new rules. -begin; -select plan(10); - -insert into auth.users (id, email) values ('50000000-0000-0000-0000-00000000000a', 'alice-v2@test.local'); - -create function pg_temp.doc(p_refs jsonb, p_cited jsonb, p_range jsonb) -returns jsonb -language sql -as $$ - select jsonb_build_object( - 'schema_version', 2, - 'species_id', 'equine', - 'name', jsonb_build_object('fr', 'Cheval', 'en', 'Horse'), - 'description', '{}'::jsonb, - 'scope_disclaimer', '{}'::jsonb, - 'attribution', jsonb_build_object('authors', '[]'::jsonb, 'license', null, 'notes', null), - 'vertebral_config', jsonb_build_object('regions', jsonb_build_array( - jsonb_build_object('code', 'Cd', 'name', jsonb_build_object('fr', 'Caudales', 'en', 'Caudal'), 'count', 18, 'count_range', p_range) - )), - 'references', p_refs, - 'categories', jsonb_build_array( - jsonb_build_object('id', 'os', 'name', jsonb_build_object('fr', 'Os', 'en', 'Bones'), 'color', null) - ), - 'views', jsonb_build_array( - jsonb_build_object('id', 'main', 'kind', 'main', 'name', jsonb_build_object('fr', 'Vue', 'en', 'View'), - 'svg_asset_id', '00000000-0000-0000-0000-000000000001', 'view_box', null) - ), - 'annotations', jsonb_build_array( - jsonb_build_object('id', 'hip', 'kind', 'point', 'view_id', 'main', 'category_id', 'os', 'laterality', 'bilateral', - 'geometry', null, 'review_status', 'inherited', 'name', jsonb_build_object('fr', 'Hanche', 'en', 'Hip'), - 'finding_zone_id', 'hip', 'vertebral_region_code', null) - ), - 'finding_zones', jsonb_build_array( - jsonb_build_object('id', 'hip', 'name', jsonb_build_object('fr', 'Hanche', 'en', 'Hip'), 'categories', jsonb_build_array( - jsonb_build_object('id', 'hip-dysfunctions', 'kind', 'dysfunction', - 'name', jsonb_build_object('fr', 'Dysfonctions', 'en', 'Dysfunctions'), - 'reference_ids', '[]'::jsonb, - 'children', jsonb_build_array( - jsonb_build_object('id', 'articular', 'name', jsonb_build_object('fr', 'Articulaire', 'en', 'Articular'), - 'children', jsonb_build_array( - jsonb_build_object('id', 'flexion', 'name', jsonb_build_object('fr', 'Flexion', 'en', 'Flexion'), 'reference_ids', p_cited) - )) - )) - )) - ) - ); -$$; -grant execute on function pg_temp.doc(jsonb, jsonb, jsonb) to authenticated; - -select is( - private.sheet_document_issues(pg_temp.doc('[{"id":"nav","type":"standard","citation":"NAV 2017","url":null,"doi":null}]', '["nav"]', '{"min":15,"max":21}')), - '{}'::text[], 'a v2 document citing a declared reference inside its count range passes' -); -select is( - private.sheet_document_issues(pg_temp.doc('[]', '["nav"]', 'null')), - '{finding.reference.missing}'::text[], 'a citation of an undeclared reference is reported (nested node)' -); -select is( - private.sheet_document_issues(pg_temp.doc('[{"id":"nav","citation":"a"},{"id":"nav","citation":"b"}]', '[]', 'null')), - '{reference.id.duplicate}'::text[], 'duplicate reference ids are reported' -); -select is( - private.sheet_document_issues(pg_temp.doc('[]', '[]', '{"min":19,"max":21}')), - '{region.count_range.invalid}'::text[], 'a usual count outside its range is reported' -); -select is( - private.sheet_document_issues(pg_temp.doc('[]', '[]', '{"min":18,"max":18}')), - '{}'::text[], 'a count on the bounds of its range passes' -); -select is( - private.sheet_document_issues(jsonb_set(pg_temp.doc('[]', '[]', 'null'), '{references}', '"x"')), - '{document.shape}'::text[], 'a non-array references registry is a shape error' -); -select is( - private.sheet_document_issues(pg_temp.doc('[{"id":"bad","type":"web","citation":"x","url":"javascript:alert(1)","doi":null}]', '[]', 'null')), - '{reference.url.scheme}'::text[], 'a reference url outside http(s) is reported' -); -select is( - private.sheet_document_issues(pg_temp.doc('[{"id":"ok","type":"web","citation":"x","url":"https://example.org/a","doi":null}]', '[]', 'null')), - '{}'::text[], 'an https reference url passes' -); - --- Only schema_version 2 rows are stored. -set local role authenticated; -select set_config('request.jwt.claims', '{"sub":"50000000-0000-0000-0000-00000000000a","role":"authenticated"}', true); -select throws_ok( - $$ select public.create_anatomical_sheet('equine', 'Old', 'old-v1', jsonb_set(pg_temp.doc('[]', '[]', 'null'), '{schema_version}', '1')) $$, - '23514', null, 'a schema_version 1 document is refused' -); -select lives_ok( - $$ select public.create_anatomical_sheet('equine', 'New', 'new-v2', pg_temp.doc('[]', '[]', 'null')) $$, - 'a schema_version 2 document is accepted as a draft' -); - -select * from finish(); -rollback; diff --git a/supabase/tests/010_files_foundation.sql b/supabase/tests/010_files_foundation.sql index cbcced63..4dc99bd2 100644 --- a/supabase/tests/010_files_foundation.sql +++ b/supabase/tests/010_files_foundation.sql @@ -75,11 +75,11 @@ select is( select is( (select count(*) from pg_policies where schemaname = 'storage' and tablename = 'objects' and (coalesce(qual, '') || coalesce(with_check, '')) like '%bucket_id = ''anatomical-sheet-assets''%'), - 1::bigint, 'census: one policy names anatomical-sheet-assets' + 2::bigint, 'census: two policies name anatomical-sheet-assets (read + editor upload, V1-2.1)' ); select is( (select count(*) from pg_policies where schemaname = 'storage' and tablename = 'objects'), - 3::bigint, 'census: three policies in total, so the six closed buckets have none' + 4::bigint, 'census: four policies in total (avatars read+insert, sheet-assets read+insert)' ); select is( (select count(*) from pg_policies where schemaname = 'storage' and tablename = 'objects' diff --git a/supabase/tests/011_sheet_conformance.sql b/supabase/tests/011_sheet_conformance.sql deleted file mode 100644 index 1a5db719..00000000 --- a/supabase/tests/011_sheet_conformance.sql +++ /dev/null @@ -1,167 +0,0 @@ --- GENERATED from crates/core/tests/conformance/*.json by crates/core/tests/sheet_conformance.rs: --- FAUNOSTEO_WRITE_CONFORMANCE=1 cargo test -p faunosteo-core --test sheet_conformance --- Never edited by hand: cargo fails when this file differs from the fixtures. --- The SQL publication re-check returns, for each fixture, the error codes the Rust --- integrity rules report that SQL mirrors (codes only, sorted), plus its own --- document.shape and reference.url.scheme on documents the shape tier refuses. -begin; -select plan(26); - -select is( - array(select c from unnest(private.sheet_document_issues($fixture${"schema_version":2,"species_id":"equine","name":{"fr":"Cheval (extrait)","en":"Horse (slice)"},"description":{"fr":"Extrait de la fiche équine pour les tests du modèle","en":"Equine sheet slice for model tests"},"scope_disclaimer":{"fr":"Les éléments listés correspondent au périmètre légal de l'ostéopathie animale : dysfonctions ostéopathiques palpées, observations cliniques et motifs de consultation. Aucun diagnostic médical n'est posé. Toute pathologie organique relève du vétérinaire."},"attribution":{"authors":["Faunosteo"],"license":"MIT","notes":null},"vertebral_config":{"regions":[{"code":"C","name":{"fr":"Cervicales","en":"Cervical"},"count":7,"count_range":null},{"code":"T","name":{"fr":"Thoraciques","en":"Thoracic"},"count":18,"count_range":null},{"code":"L","name":{"fr":"Lombaires","en":"Lumbar"},"count":6,"count_range":null},{"code":"S","name":{"fr":"Sacrées","en":"Sacral"},"count":5,"count_range":null},{"code":"Cd","name":{"fr":"Caudales","en":"Caudal"},"count":18,"count_range":{"min":15,"max":21}}]},"references":[{"id":"legacy-catalog","type":"manual","citation":"Legacy equine catalog (pathologies.json, schema 2.0)","url":null,"doi":null}],"categories":[{"id":"articulations","name":{"fr":"Articulations","en":"Joints"},"color":"#ff9500"},{"id":"zone-colonne","name":{"fr":"Zone colonne","en":"Spine zone"},"color":"#e100ff"},{"id":"charnieres-vertebrales","name":{"fr":"Charnières vertébrales","en":"Vertebral junctions"},"color":"#ff0000"},{"id":"cadrans-du-crane","name":{"fr":"Cadrans du crâne","en":"Skull quadrants"},"color":"#1baa08"}],"views":[{"id":"view-main","name":{"fr":"Cheval entier","en":"Whole horse"},"svg_asset_id":"3f6c1b52-8a4e-4d17-9b0c-5e2a7d91c4f8","view_box":null,"kind":"main"},{"id":"view-head","name":{"fr":"Tête","en":"Head"},"svg_asset_id":null,"view_box":{"min_x":60,"min_y":100,"width":500,"height":380},"kind":"detail","parent_view_id":"view-main"}],"annotations":[{"id":"hip","view_id":"view-main","category_id":"os","laterality":"bilateral","geometry":{"type":"circle","cx":1516,"cy":695,"r":34},"review_status":"inherited","color":null,"name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"finding_zone_id":"hip","vertebral_region_code":null,"kind":"point"},{"id":"cervical-vertebrae","view_id":"view-main","category_id":"zone-colonne","laterality":"unpaired","geometry":{"type":"polygon","points":[[468,276],[489,216],[558,248],[586,339],[552,461],[524,370]]},"review_status":"inherited","color":null,"name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"finding_zone_id":"cervical","vertebral_region_code":"C","kind":"zone"},{"id":"hinge-c7-t1","view_id":"view-main","category_id":"charnieres-vertebrales","laterality":"unpaired","geometry":{"type":"circle","cx":840.17,"cy":399.08,"r":30},"review_status":"inherited","color":null,"name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"finding_zone_id":"c7-t1","vertebral_region_code":null,"kind":"point"},{"id":"head-trigger","view_id":"view-main","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"polygon","points":[[454,332],[429,202],[349,154],[234,279],[164,384],[234,468]]},"review_status":"inherited","color":null,"kind":"detail_trigger","name":null,"opens_view_id":"view-head"},{"id":"atm","view_id":"view-head","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":384.94,"cy":314.02,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"finding_zone_id":"atm","vertebral_region_code":null,"kind":"point"},{"id":"sphenoid","view_id":"view-head","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"circle","cx":299,"cy":298,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Sphénoïde","en":"Sphenoid"},"finding_zone_id":"sphenoid","vertebral_region_code":null,"kind":"point"}],"finding_zones":[{"id":"hip","name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"categories":[{"id":"hip-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"articular","name":{"fr":"Restrictions de mobilité articulaire","en":"Articular mobility restrictions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-flexion","name":{"fr":"Restriction en flexion","en":"Flexion restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"restriction-extension","name":{"fr":"Restriction en extension","en":"Extension restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"hip-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"limb-lameness","name":{"fr":"Boiterie rapportée (membre concerné)","en":"Reported lameness (affected limb)"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":["legacy-catalog"],"review_status":"inherited","children":[]}]}]},{"id":"cervical","name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"categories":[{"id":"cervical-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"muscular","name":{"fr":"Tensions musculaires paravertébrales","en":"Paravertebral muscle tensions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"splenius-tension","name":{"fr":"Tension du splénius","en":"Splenius tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"cervical-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"stumbling-proprioceptive","name":{"fr":"Trébuchements / déficit proprioceptif rapporté","en":"Reported stumbling / proprioceptive deficit"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"c7-t1","name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"categories":[{"id":"c7-t1-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-rotation","name":{"fr":"Restriction en rotation","en":"Rotation restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"c7-t1-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"base-neck-stiffness","name":{"fr":"Raideur de la base de l'encolure","en":"Base-of-neck stiffness"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"atm","name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"categories":[{"id":"atm-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques de l'ATM","en":"Osteopathic TMJ dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"masseter-tension","name":{"fr":"Tension du masséter","en":"Masseter tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"atm-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"bit-defense","name":{"fr":"Réactions de défense au mors","en":"Defense reactions to bit"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"dental-context","name":{"fr":"Suite de soin dentaire récent","en":"Post recent dental care"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid","name":{"fr":"Sphénoïde","en":"Sphenoid"},"categories":[{"id":"ssb-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"physiological","name":{"fr":"Lésions physiologiques (SSB)","en":"Physiological lesions (SBS)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"torsion-right","name":{"fr":"Torsion droite","en":"Right torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"torsion-left","name":{"fr":"Torsion gauche","en":"Left torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"post-trauma-head","name":{"fr":"Suite de traumatisme crânien","en":"Post head trauma"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]}]}$fixture$::jsonb)) as c order by c collate "C"), - '{annotation.category.missing}'::text[], - 'conformance annotation-category-missing: an annotation in an undeclared category' -); - -select is( - array(select c from unnest(private.sheet_document_issues($fixture${"schema_version":2,"species_id":"equine","name":{"fr":"Cheval (extrait)","en":"Horse (slice)"},"description":{"fr":"Extrait de la fiche équine pour les tests du modèle","en":"Equine sheet slice for model tests"},"scope_disclaimer":{"fr":"Les éléments listés correspondent au périmètre légal de l'ostéopathie animale : dysfonctions ostéopathiques palpées, observations cliniques et motifs de consultation. Aucun diagnostic médical n'est posé. Toute pathologie organique relève du vétérinaire."},"attribution":{"authors":["Faunosteo"],"license":"MIT","notes":null},"vertebral_config":{"regions":[{"code":"C","name":{"fr":"Cervicales","en":"Cervical"},"count":7,"count_range":null},{"code":"T","name":{"fr":"Thoraciques","en":"Thoracic"},"count":18,"count_range":null},{"code":"L","name":{"fr":"Lombaires","en":"Lumbar"},"count":6,"count_range":null},{"code":"S","name":{"fr":"Sacrées","en":"Sacral"},"count":5,"count_range":null},{"code":"Cd","name":{"fr":"Caudales","en":"Caudal"},"count":18,"count_range":{"min":15,"max":21}}]},"references":[{"id":"legacy-catalog","type":"manual","citation":"Legacy equine catalog (pathologies.json, schema 2.0)","url":null,"doi":null}],"categories":[{"id":"articulations","name":{"fr":"Articulations","en":"Joints"},"color":"#ff9500"},{"id":"zone-colonne","name":{"fr":"Zone colonne","en":"Spine zone"},"color":"#e100ff"},{"id":"charnieres-vertebrales","name":{"fr":"Charnières vertébrales","en":"Vertebral junctions"},"color":"#ff0000"},{"id":"cadrans-du-crane","name":{"fr":"Cadrans du crâne","en":"Skull quadrants"},"color":"#1baa08"}],"views":[{"id":"view-main","name":{"fr":"Cheval entier","en":"Whole horse"},"svg_asset_id":"3f6c1b52-8a4e-4d17-9b0c-5e2a7d91c4f8","view_box":null,"kind":"main"},{"id":"view-head","name":{"fr":"Tête","en":"Head"},"svg_asset_id":null,"view_box":{"min_x":60,"min_y":100,"width":500,"height":380},"kind":"detail","parent_view_id":"view-main"}],"annotations":[{"id":"hip","view_id":"view-main","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":1516,"cy":695,"r":34},"review_status":"inherited","color":null,"name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"finding_zone_id":"hip","vertebral_region_code":null,"kind":"point"},{"id":"cervical-vertebrae","view_id":"view-main","category_id":"zone-colonne","laterality":"unpaired","geometry":{"type":"polygon","points":[[468,276],[489,216],[558,248],[586,339],[552,461],[524,370]]},"review_status":"inherited","color":null,"name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"finding_zone_id":"cervical","vertebral_region_code":"C","kind":"zone"},{"id":"hinge-c7-t1","view_id":"view-main","category_id":"charnieres-vertebrales","laterality":"unpaired","geometry":{"type":"circle","cx":840.17,"cy":399.08,"r":30},"review_status":"inherited","color":null,"name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"finding_zone_id":"c7-t1","vertebral_region_code":null,"kind":"point"},{"id":"head-trigger","view_id":"view-main","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"polygon","points":[[454,332],[429,202],[349,154],[234,279],[164,384],[234,468]]},"review_status":"inherited","color":null,"kind":"detail_trigger","name":null,"opens_view_id":"view-head"},{"id":"atm","view_id":"view-head","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":384.94,"cy":314.02,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"finding_zone_id":"atm","vertebral_region_code":null,"kind":"point"},{"id":"sphenoid","view_id":"view-head","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"circle","cx":299,"cy":298,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Sphénoïde","en":"Sphenoid"},"finding_zone_id":"sphenoid","vertebral_region_code":null,"kind":"point"},{"id":"stifle","kind":"point","view_id":"view-main","category_id":"articulations","laterality":"bilateral","geometry":null,"review_status":"inherited","color":null,"name":{"fr":"stifle","en":"stifle"},"finding_zone_id":"stifle","vertebral_region_code":null}],"finding_zones":[{"id":"hip","name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"categories":[{"id":"hip-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"articular","name":{"fr":"Restrictions de mobilité articulaire","en":"Articular mobility restrictions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-flexion","name":{"fr":"Restriction en flexion","en":"Flexion restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"restriction-extension","name":{"fr":"Restriction en extension","en":"Extension restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"hip-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"limb-lameness","name":{"fr":"Boiterie rapportée (membre concerné)","en":"Reported lameness (affected limb)"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":["legacy-catalog"],"review_status":"inherited","children":[]}]}]},{"id":"cervical","name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"categories":[{"id":"cervical-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"muscular","name":{"fr":"Tensions musculaires paravertébrales","en":"Paravertebral muscle tensions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"splenius-tension","name":{"fr":"Tension du splénius","en":"Splenius tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"cervical-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"stumbling-proprioceptive","name":{"fr":"Trébuchements / déficit proprioceptif rapporté","en":"Reported stumbling / proprioceptive deficit"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"c7-t1","name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"categories":[{"id":"c7-t1-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-rotation","name":{"fr":"Restriction en rotation","en":"Rotation restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"c7-t1-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"base-neck-stiffness","name":{"fr":"Raideur de la base de l'encolure","en":"Base-of-neck stiffness"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"atm","name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"categories":[{"id":"atm-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques de l'ATM","en":"Osteopathic TMJ dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"masseter-tension","name":{"fr":"Tension du masséter","en":"Masseter tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"atm-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"bit-defense","name":{"fr":"Réactions de défense au mors","en":"Defense reactions to bit"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"dental-context","name":{"fr":"Suite de soin dentaire récent","en":"Post recent dental care"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid","name":{"fr":"Sphénoïde","en":"Sphenoid"},"categories":[{"id":"ssb-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"physiological","name":{"fr":"Lésions physiologiques (SSB)","en":"Physiological lesions (SBS)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"torsion-right","name":{"fr":"Torsion droite","en":"Right torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"torsion-left","name":{"fr":"Torsion gauche","en":"Left torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"post-trauma-head","name":{"fr":"Suite de traumatisme crânien","en":"Post head trauma"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]}]}$fixture$::jsonb)) as c order by c collate "C"), - '{annotation.finding_zone.missing}'::text[], - 'conformance annotation-finding-zone-missing: an annotation linked to an undeclared finding zone' -); - -select is( - array(select c from unnest(private.sheet_document_issues($fixture${"schema_version":2,"species_id":"equine","name":{"fr":"Cheval (extrait)","en":"Horse (slice)"},"description":{"fr":"Extrait de la fiche équine pour les tests du modèle","en":"Equine sheet slice for model tests"},"scope_disclaimer":{"fr":"Les éléments listés correspondent au périmètre légal de l'ostéopathie animale : dysfonctions ostéopathiques palpées, observations cliniques et motifs de consultation. Aucun diagnostic médical n'est posé. Toute pathologie organique relève du vétérinaire."},"attribution":{"authors":["Faunosteo"],"license":"MIT","notes":null},"vertebral_config":{"regions":[{"code":"C","name":{"fr":"Cervicales","en":"Cervical"},"count":7,"count_range":null},{"code":"T","name":{"fr":"Thoraciques","en":"Thoracic"},"count":18,"count_range":null},{"code":"L","name":{"fr":"Lombaires","en":"Lumbar"},"count":6,"count_range":null},{"code":"S","name":{"fr":"Sacrées","en":"Sacral"},"count":5,"count_range":null},{"code":"Cd","name":{"fr":"Caudales","en":"Caudal"},"count":18,"count_range":{"min":15,"max":21}}]},"references":[{"id":"legacy-catalog","type":"manual","citation":"Legacy equine catalog (pathologies.json, schema 2.0)","url":null,"doi":null}],"categories":[{"id":"articulations","name":{"fr":"Articulations","en":"Joints"},"color":"#ff9500"},{"id":"zone-colonne","name":{"fr":"Zone colonne","en":"Spine zone"},"color":"#e100ff"},{"id":"charnieres-vertebrales","name":{"fr":"Charnières vertébrales","en":"Vertebral junctions"},"color":"#ff0000"},{"id":"cadrans-du-crane","name":{"fr":"Cadrans du crâne","en":"Skull quadrants"},"color":"#1baa08"}],"views":[{"id":"view-main","name":{"fr":"Cheval entier","en":"Whole horse"},"svg_asset_id":"3f6c1b52-8a4e-4d17-9b0c-5e2a7d91c4f8","view_box":null,"kind":"main"},{"id":"view-head","name":{"fr":"Tête","en":"Head"},"svg_asset_id":null,"view_box":{"min_x":60,"min_y":100,"width":500,"height":380},"kind":"detail","parent_view_id":"view-main"}],"annotations":[{"id":"hip","view_id":"view-main","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":1516,"cy":695,"r":34},"review_status":"inherited","color":null,"name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"finding_zone_id":"hip","vertebral_region_code":null,"kind":"point"},{"id":"cervical-vertebrae","view_id":"view-main","category_id":"zone-colonne","laterality":"unpaired","geometry":{"type":"polygon","points":[[468,276],[489,216],[558,248],[586,339],[552,461],[524,370]]},"review_status":"inherited","color":null,"name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"finding_zone_id":"cervical","vertebral_region_code":"C","kind":"zone"},{"id":"hinge-c7-t1","view_id":"view-main","category_id":"charnieres-vertebrales","laterality":"unpaired","geometry":{"type":"circle","cx":840.17,"cy":399.08,"r":30},"review_status":"inherited","color":null,"name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"finding_zone_id":"c7-t1","vertebral_region_code":null,"kind":"point"},{"id":"head-trigger","view_id":"view-main","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"polygon","points":[[454,332],[429,202],[349,154],[234,279],[164,384],[234,468]]},"review_status":"inherited","color":null,"kind":"detail_trigger","name":null,"opens_view_id":"view-head"},{"id":"atm","view_id":"view-head","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":384.94,"cy":314.02,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"finding_zone_id":"atm","vertebral_region_code":null,"kind":"point"},{"id":"sphenoid","view_id":"view-head","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"circle","cx":299,"cy":298,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Sphénoïde","en":"Sphenoid"},"finding_zone_id":"sphenoid","vertebral_region_code":null,"kind":"point"},{"id":"atm","view_id":"view-main","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":384.94,"cy":314.02,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"finding_zone_id":"atm","vertebral_region_code":null,"kind":"point"}],"finding_zones":[{"id":"hip","name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"categories":[{"id":"hip-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"articular","name":{"fr":"Restrictions de mobilité articulaire","en":"Articular mobility restrictions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-flexion","name":{"fr":"Restriction en flexion","en":"Flexion restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"restriction-extension","name":{"fr":"Restriction en extension","en":"Extension restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"hip-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"limb-lameness","name":{"fr":"Boiterie rapportée (membre concerné)","en":"Reported lameness (affected limb)"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":["legacy-catalog"],"review_status":"inherited","children":[]}]}]},{"id":"cervical","name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"categories":[{"id":"cervical-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"muscular","name":{"fr":"Tensions musculaires paravertébrales","en":"Paravertebral muscle tensions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"splenius-tension","name":{"fr":"Tension du splénius","en":"Splenius tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"cervical-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"stumbling-proprioceptive","name":{"fr":"Trébuchements / déficit proprioceptif rapporté","en":"Reported stumbling / proprioceptive deficit"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"c7-t1","name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"categories":[{"id":"c7-t1-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-rotation","name":{"fr":"Restriction en rotation","en":"Rotation restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"c7-t1-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"base-neck-stiffness","name":{"fr":"Raideur de la base de l'encolure","en":"Base-of-neck stiffness"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"atm","name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"categories":[{"id":"atm-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques de l'ATM","en":"Osteopathic TMJ dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"masseter-tension","name":{"fr":"Tension du masséter","en":"Masseter tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"atm-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"bit-defense","name":{"fr":"Réactions de défense au mors","en":"Defense reactions to bit"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"dental-context","name":{"fr":"Suite de soin dentaire récent","en":"Post recent dental care"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid","name":{"fr":"Sphénoïde","en":"Sphenoid"},"categories":[{"id":"ssb-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"physiological","name":{"fr":"Lésions physiologiques (SSB)","en":"Physiological lesions (SBS)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"torsion-right","name":{"fr":"Torsion droite","en":"Right torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"torsion-left","name":{"fr":"Torsion gauche","en":"Left torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"post-trauma-head","name":{"fr":"Suite de traumatisme crânien","en":"Post head trauma"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]}]}$fixture$::jsonb)) as c order by c collate "C"), - '{annotation.id.duplicate}'::text[], - 'conformance annotation-id-duplicate: an annotation id repeated on another view' -); - -select is( - array(select c from unnest(private.sheet_document_issues($fixture${"schema_version":2,"species_id":"equine","name":{"fr":"Cheval (extrait)","en":"Horse (slice)"},"description":{"fr":"Extrait de la fiche équine pour les tests du modèle","en":"Equine sheet slice for model tests"},"scope_disclaimer":{"fr":"Les éléments listés correspondent au périmètre légal de l'ostéopathie animale : dysfonctions ostéopathiques palpées, observations cliniques et motifs de consultation. Aucun diagnostic médical n'est posé. Toute pathologie organique relève du vétérinaire."},"attribution":{"authors":["Faunosteo"],"license":"MIT","notes":null},"vertebral_config":{"regions":[{"code":"C","name":{"fr":"Cervicales","en":"Cervical"},"count":7,"count_range":null},{"code":"T","name":{"fr":"Thoraciques","en":"Thoracic"},"count":18,"count_range":null},{"code":"L","name":{"fr":"Lombaires","en":"Lumbar"},"count":6,"count_range":null},{"code":"S","name":{"fr":"Sacrées","en":"Sacral"},"count":5,"count_range":null},{"code":"Cd","name":{"fr":"Caudales","en":"Caudal"},"count":18,"count_range":{"min":15,"max":21}}]},"references":[{"id":"legacy-catalog","type":"manual","citation":"Legacy equine catalog (pathologies.json, schema 2.0)","url":null,"doi":null}],"categories":[{"id":"articulations","name":{"fr":"Articulations","en":"Joints"},"color":"#ff9500"},{"id":"zone-colonne","name":{"fr":"Zone colonne","en":"Spine zone"},"color":"#e100ff"},{"id":"charnieres-vertebrales","name":{"fr":"Charnières vertébrales","en":"Vertebral junctions"},"color":"#ff0000"},{"id":"cadrans-du-crane","name":{"fr":"Cadrans du crâne","en":"Skull quadrants"},"color":"#1baa08"}],"views":[{"id":"view-main","name":{"fr":"Cheval entier","en":"Whole horse"},"svg_asset_id":"3f6c1b52-8a4e-4d17-9b0c-5e2a7d91c4f8","view_box":null,"kind":"main"},{"id":"view-head","name":{"fr":"Tête","en":"Head"},"svg_asset_id":null,"view_box":{"min_x":60,"min_y":100,"width":500,"height":380},"kind":"detail","parent_view_id":"view-main"}],"annotations":[{"id":"hip","view_id":"view-main","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":1516,"cy":695,"r":34},"review_status":"inherited","color":null,"name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"finding_zone_id":"hip","vertebral_region_code":null,"kind":"point"},{"id":"cervical-vertebrae","view_id":"view-main","category_id":"zone-colonne","laterality":"unpaired","geometry":{"type":"polygon","points":[[468,276],[489,216],[558,248],[586,339],[552,461],[524,370]]},"review_status":"inherited","color":null,"name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"finding_zone_id":"cervical","vertebral_region_code":"C","kind":"zone"},{"id":"hinge-c7-t1","view_id":"view-main","category_id":"charnieres-vertebrales","laterality":"unpaired","geometry":{"type":"circle","cx":840.17,"cy":399.08,"r":30},"review_status":"inherited","color":null,"name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"finding_zone_id":"c7-t1","vertebral_region_code":null,"kind":"point"},{"id":"head-trigger","view_id":"view-main","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"polygon","points":[[454,332],[429,202],[349,154],[234,279],[164,384],[234,468]]},"review_status":"inherited","color":null,"kind":"detail_trigger","name":null,"opens_view_id":"view-head"},{"id":"atm","view_id":"view-head","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":384.94,"cy":314.02,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"finding_zone_id":"atm","vertebral_region_code":null,"kind":"point"},{"id":"sphenoid","view_id":"view-head","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"circle","cx":299,"cy":298,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Sphénoïde","en":"Sphenoid"},"finding_zone_id":"sphenoid","vertebral_region_code":null,"kind":"point"},{"id":"mandible","kind":"point","view_id":"view-main","category_id":"articulations","laterality":"bilateral","geometry":null,"review_status":"inherited","color":null,"name":{"fr":"mandible","en":"mandible"},"finding_zone_id":null,"vertebral_region_code":null}],"finding_zones":[{"id":"hip","name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"categories":[{"id":"hip-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"articular","name":{"fr":"Restrictions de mobilité articulaire","en":"Articular mobility restrictions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-flexion","name":{"fr":"Restriction en flexion","en":"Flexion restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"restriction-extension","name":{"fr":"Restriction en extension","en":"Extension restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"hip-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"limb-lameness","name":{"fr":"Boiterie rapportée (membre concerné)","en":"Reported lameness (affected limb)"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":["legacy-catalog"],"review_status":"inherited","children":[]}]}]},{"id":"cervical","name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"categories":[{"id":"cervical-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"muscular","name":{"fr":"Tensions musculaires paravertébrales","en":"Paravertebral muscle tensions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"splenius-tension","name":{"fr":"Tension du splénius","en":"Splenius tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"cervical-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"stumbling-proprioceptive","name":{"fr":"Trébuchements / déficit proprioceptif rapporté","en":"Reported stumbling / proprioceptive deficit"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"c7-t1","name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"categories":[{"id":"c7-t1-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-rotation","name":{"fr":"Restriction en rotation","en":"Rotation restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"c7-t1-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"base-neck-stiffness","name":{"fr":"Raideur de la base de l'encolure","en":"Base-of-neck stiffness"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"atm","name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"categories":[{"id":"atm-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques de l'ATM","en":"Osteopathic TMJ dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"masseter-tension","name":{"fr":"Tension du masséter","en":"Masseter tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"atm-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"bit-defense","name":{"fr":"Réactions de défense au mors","en":"Defense reactions to bit"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"dental-context","name":{"fr":"Suite de soin dentaire récent","en":"Post recent dental care"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid","name":{"fr":"Sphénoïde","en":"Sphenoid"},"categories":[{"id":"ssb-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"physiological","name":{"fr":"Lésions physiologiques (SSB)","en":"Physiological lesions (SBS)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"torsion-right","name":{"fr":"Torsion droite","en":"Right torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"torsion-left","name":{"fr":"Torsion gauche","en":"Left torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"post-trauma-head","name":{"fr":"Suite de traumatisme crânien","en":"Post head trauma"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]}]}$fixture$::jsonb)) as c order by c collate "C"), - '{}'::text[], - 'conformance annotation-no-findings: an annotation linked to no finding zone (warning, not mirrored by SQL)' -); - -select is( - array(select c from unnest(private.sheet_document_issues($fixture${"schema_version":2,"species_id":"equine","name":{"fr":"Cheval (extrait)","en":"Horse (slice)"},"description":{"fr":"Extrait de la fiche équine pour les tests du modèle","en":"Equine sheet slice for model tests"},"scope_disclaimer":{"fr":"Les éléments listés correspondent au périmètre légal de l'ostéopathie animale : dysfonctions ostéopathiques palpées, observations cliniques et motifs de consultation. Aucun diagnostic médical n'est posé. Toute pathologie organique relève du vétérinaire."},"attribution":{"authors":["Faunosteo"],"license":"MIT","notes":null},"vertebral_config":{"regions":[{"code":"C","name":{"fr":"Cervicales","en":"Cervical"},"count":7,"count_range":null},{"code":"T","name":{"fr":"Thoraciques","en":"Thoracic"},"count":18,"count_range":null},{"code":"L","name":{"fr":"Lombaires","en":"Lumbar"},"count":6,"count_range":null},{"code":"S","name":{"fr":"Sacrées","en":"Sacral"},"count":5,"count_range":null},{"code":"Cd","name":{"fr":"Caudales","en":"Caudal"},"count":18,"count_range":{"min":15,"max":21}}]},"references":[{"id":"legacy-catalog","type":"manual","citation":"Legacy equine catalog (pathologies.json, schema 2.0)","url":null,"doi":null}],"categories":[{"id":"articulations","name":{"fr":"Articulations","en":"Joints"},"color":"#ff9500"},{"id":"zone-colonne","name":{"fr":"Zone colonne","en":"Spine zone"},"color":"#e100ff"},{"id":"charnieres-vertebrales","name":{"fr":"Charnières vertébrales","en":"Vertebral junctions"},"color":"#ff0000"},{"id":"cadrans-du-crane","name":{"fr":"Cadrans du crâne","en":"Skull quadrants"},"color":"#1baa08"}],"views":[{"id":"view-main","name":{"fr":"Cheval entier","en":"Whole horse"},"svg_asset_id":"3f6c1b52-8a4e-4d17-9b0c-5e2a7d91c4f8","view_box":null,"kind":"main"},{"id":"view-head","name":{"fr":"Tête","en":"Head"},"svg_asset_id":null,"view_box":{"min_x":60,"min_y":100,"width":500,"height":380},"kind":"detail","parent_view_id":"view-main"}],"annotations":[{"id":"hip","view_id":"view-main","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":1516,"cy":695,"r":34},"review_status":"inherited","color":null,"name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"finding_zone_id":"hip","vertebral_region_code":null,"kind":"point"},{"id":"cervical-vertebrae","view_id":"view-main","category_id":"zone-colonne","laterality":"unpaired","geometry":{"type":"polygon","points":[[468,276],[489,216],[558,248],[586,339],[552,461],[524,370]]},"review_status":"inherited","color":null,"name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"finding_zone_id":"cervical","vertebral_region_code":"C","kind":"zone"},{"id":"hinge-c7-t1","view_id":"view-main","category_id":"charnieres-vertebrales","laterality":"unpaired","geometry":{"type":"circle","cx":840.17,"cy":399.08,"r":30},"review_status":"inherited","color":null,"name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"finding_zone_id":"c7-t1","vertebral_region_code":null,"kind":"point"},{"id":"head-trigger","view_id":"view-main","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"polygon","points":[[454,332],[429,202],[349,154],[234,279],[164,384],[234,468]]},"review_status":"inherited","color":null,"kind":"detail_trigger","name":null,"opens_view_id":"view-head"},{"id":"atm","view_id":"view-head","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":384.94,"cy":314.02,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"finding_zone_id":"atm","vertebral_region_code":null,"kind":"point"},{"id":"sphenoid","view_id":"view-head","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"circle","cx":299,"cy":298,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Sphénoïde","en":"Sphenoid"},"finding_zone_id":"sphenoid","vertebral_region_code":null,"kind":"point"},{"id":"loop","kind":"detail_trigger","view_id":"view-head","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":null,"review_status":"inherited","color":null,"name":null,"opens_view_id":"view-head"},{"id":"to-main","kind":"detail_trigger","view_id":"view-main","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":null,"review_status":"inherited","color":null,"name":null,"opens_view_id":"view-main"},{"id":"to-ghost","kind":"detail_trigger","view_id":"view-main","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":null,"review_status":"inherited","color":null,"name":null,"opens_view_id":"view-ghost"}],"finding_zones":[{"id":"hip","name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"categories":[{"id":"hip-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"articular","name":{"fr":"Restrictions de mobilité articulaire","en":"Articular mobility restrictions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-flexion","name":{"fr":"Restriction en flexion","en":"Flexion restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"restriction-extension","name":{"fr":"Restriction en extension","en":"Extension restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"hip-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"limb-lameness","name":{"fr":"Boiterie rapportée (membre concerné)","en":"Reported lameness (affected limb)"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":["legacy-catalog"],"review_status":"inherited","children":[]}]}]},{"id":"cervical","name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"categories":[{"id":"cervical-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"muscular","name":{"fr":"Tensions musculaires paravertébrales","en":"Paravertebral muscle tensions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"splenius-tension","name":{"fr":"Tension du splénius","en":"Splenius tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"cervical-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"stumbling-proprioceptive","name":{"fr":"Trébuchements / déficit proprioceptif rapporté","en":"Reported stumbling / proprioceptive deficit"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"c7-t1","name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"categories":[{"id":"c7-t1-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-rotation","name":{"fr":"Restriction en rotation","en":"Rotation restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"c7-t1-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"base-neck-stiffness","name":{"fr":"Raideur de la base de l'encolure","en":"Base-of-neck stiffness"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"atm","name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"categories":[{"id":"atm-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques de l'ATM","en":"Osteopathic TMJ dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"masseter-tension","name":{"fr":"Tension du masséter","en":"Masseter tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"atm-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"bit-defense","name":{"fr":"Réactions de défense au mors","en":"Defense reactions to bit"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"dental-context","name":{"fr":"Suite de soin dentaire récent","en":"Post recent dental care"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid","name":{"fr":"Sphénoïde","en":"Sphenoid"},"categories":[{"id":"ssb-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"physiological","name":{"fr":"Lésions physiologiques (SSB)","en":"Physiological lesions (SBS)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"torsion-right","name":{"fr":"Torsion droite","en":"Right torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"torsion-left","name":{"fr":"Torsion gauche","en":"Left torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"post-trauma-head","name":{"fr":"Suite de traumatisme crânien","en":"Post head trauma"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]}]}$fixture$::jsonb)) as c order by c collate "C"), - '{annotation.opens_view.invalid}'::text[], - 'conformance annotation-opens-view-invalid: triggers opening their own view, the main view and an absent view' -); - -select is( - array(select c from unnest(private.sheet_document_issues($fixture${"schema_version":2,"species_id":"equine","name":{"fr":"Cheval (extrait)","en":"Horse (slice)"},"description":{"fr":"Extrait de la fiche équine pour les tests du modèle","en":"Equine sheet slice for model tests"},"scope_disclaimer":{"fr":"Les éléments listés correspondent au périmètre légal de l'ostéopathie animale : dysfonctions ostéopathiques palpées, observations cliniques et motifs de consultation. Aucun diagnostic médical n'est posé. Toute pathologie organique relève du vétérinaire."},"attribution":{"authors":["Faunosteo"],"license":"MIT","notes":null},"vertebral_config":{"regions":[{"code":"C","name":{"fr":"Cervicales","en":"Cervical"},"count":7,"count_range":null},{"code":"T","name":{"fr":"Thoraciques","en":"Thoracic"},"count":18,"count_range":null},{"code":"L","name":{"fr":"Lombaires","en":"Lumbar"},"count":6,"count_range":null},{"code":"S","name":{"fr":"Sacrées","en":"Sacral"},"count":5,"count_range":null},{"code":"Cd","name":{"fr":"Caudales","en":"Caudal"},"count":18,"count_range":{"min":15,"max":21}}]},"references":[{"id":"legacy-catalog","type":"manual","citation":"Legacy equine catalog (pathologies.json, schema 2.0)","url":null,"doi":null}],"categories":[{"id":"articulations","name":{"fr":"Articulations","en":"Joints"},"color":"#ff9500"},{"id":"zone-colonne","name":{"fr":"Zone colonne","en":"Spine zone"},"color":"#e100ff"},{"id":"charnieres-vertebrales","name":{"fr":"Charnières vertébrales","en":"Vertebral junctions"},"color":"#ff0000"},{"id":"cadrans-du-crane","name":{"fr":"Cadrans du crâne","en":"Skull quadrants"},"color":"#1baa08"}],"views":[{"id":"view-main","name":{"fr":"Cheval entier","en":"Whole horse"},"svg_asset_id":"3f6c1b52-8a4e-4d17-9b0c-5e2a7d91c4f8","view_box":null,"kind":"main"},{"id":"view-head","name":{"fr":"Tête","en":"Head"},"svg_asset_id":null,"view_box":{"min_x":60,"min_y":100,"width":500,"height":380},"kind":"detail","parent_view_id":"view-main"}],"annotations":[{"id":"hip","view_id":"view-main","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":1516,"cy":695,"r":34},"review_status":"inherited","color":null,"name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"finding_zone_id":"hip","vertebral_region_code":null,"kind":"point"},{"id":"cervical-vertebrae","view_id":"view-main","category_id":"zone-colonne","laterality":"unpaired","geometry":{"type":"polygon","points":[[468,276],[489,216],[558,248],[586,339],[552,461],[524,370]]},"review_status":"inherited","color":null,"name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"finding_zone_id":"cervical","vertebral_region_code":"Q","kind":"zone"},{"id":"hinge-c7-t1","view_id":"view-main","category_id":"charnieres-vertebrales","laterality":"unpaired","geometry":{"type":"circle","cx":840.17,"cy":399.08,"r":30},"review_status":"inherited","color":null,"name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"finding_zone_id":"c7-t1","vertebral_region_code":null,"kind":"point"},{"id":"head-trigger","view_id":"view-main","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"polygon","points":[[454,332],[429,202],[349,154],[234,279],[164,384],[234,468]]},"review_status":"inherited","color":null,"kind":"detail_trigger","name":null,"opens_view_id":"view-head"},{"id":"atm","view_id":"view-head","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":384.94,"cy":314.02,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"finding_zone_id":"atm","vertebral_region_code":null,"kind":"point"},{"id":"sphenoid","view_id":"view-head","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"circle","cx":299,"cy":298,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Sphénoïde","en":"Sphenoid"},"finding_zone_id":"sphenoid","vertebral_region_code":null,"kind":"point"}],"finding_zones":[{"id":"hip","name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"categories":[{"id":"hip-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"articular","name":{"fr":"Restrictions de mobilité articulaire","en":"Articular mobility restrictions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-flexion","name":{"fr":"Restriction en flexion","en":"Flexion restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"restriction-extension","name":{"fr":"Restriction en extension","en":"Extension restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"hip-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"limb-lameness","name":{"fr":"Boiterie rapportée (membre concerné)","en":"Reported lameness (affected limb)"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":["legacy-catalog"],"review_status":"inherited","children":[]}]}]},{"id":"cervical","name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"categories":[{"id":"cervical-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"muscular","name":{"fr":"Tensions musculaires paravertébrales","en":"Paravertebral muscle tensions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"splenius-tension","name":{"fr":"Tension du splénius","en":"Splenius tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"cervical-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"stumbling-proprioceptive","name":{"fr":"Trébuchements / déficit proprioceptif rapporté","en":"Reported stumbling / proprioceptive deficit"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"c7-t1","name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"categories":[{"id":"c7-t1-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-rotation","name":{"fr":"Restriction en rotation","en":"Rotation restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"c7-t1-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"base-neck-stiffness","name":{"fr":"Raideur de la base de l'encolure","en":"Base-of-neck stiffness"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"atm","name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"categories":[{"id":"atm-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques de l'ATM","en":"Osteopathic TMJ dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"masseter-tension","name":{"fr":"Tension du masséter","en":"Masseter tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"atm-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"bit-defense","name":{"fr":"Réactions de défense au mors","en":"Defense reactions to bit"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"dental-context","name":{"fr":"Suite de soin dentaire récent","en":"Post recent dental care"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid","name":{"fr":"Sphénoïde","en":"Sphenoid"},"categories":[{"id":"ssb-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"physiological","name":{"fr":"Lésions physiologiques (SSB)","en":"Physiological lesions (SBS)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"torsion-right","name":{"fr":"Torsion droite","en":"Right torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"torsion-left","name":{"fr":"Torsion gauche","en":"Left torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"post-trauma-head","name":{"fr":"Suite de traumatisme crânien","en":"Post head trauma"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]}]}$fixture$::jsonb)) as c order by c collate "C"), - '{annotation.region.missing}'::text[], - 'conformance annotation-region-missing: a spine annotation on an unconfigured region' -); - -select is( - array(select c from unnest(private.sheet_document_issues($fixture${"schema_version":2,"species_id":"equine","name":{"fr":"Cheval (extrait)","en":"Horse (slice)"},"description":{"fr":"Extrait de la fiche équine pour les tests du modèle","en":"Equine sheet slice for model tests"},"scope_disclaimer":{"fr":"Les éléments listés correspondent au périmètre légal de l'ostéopathie animale : dysfonctions ostéopathiques palpées, observations cliniques et motifs de consultation. Aucun diagnostic médical n'est posé. Toute pathologie organique relève du vétérinaire."},"attribution":{"authors":["Faunosteo"],"license":"MIT","notes":null},"vertebral_config":{"regions":[{"code":"C","name":{"fr":"Cervicales","en":"Cervical"},"count":7,"count_range":null},{"code":"T","name":{"fr":"Thoraciques","en":"Thoracic"},"count":18,"count_range":null},{"code":"L","name":{"fr":"Lombaires","en":"Lumbar"},"count":6,"count_range":null},{"code":"S","name":{"fr":"Sacrées","en":"Sacral"},"count":5,"count_range":null},{"code":"Cd","name":{"fr":"Caudales","en":"Caudal"},"count":18,"count_range":{"min":15,"max":21}}]},"references":[{"id":"legacy-catalog","type":"manual","citation":"Legacy equine catalog (pathologies.json, schema 2.0)","url":null,"doi":null}],"categories":[{"id":"articulations","name":{"fr":"Articulations","en":"Joints"},"color":"#ff9500"},{"id":"zone-colonne","name":{"fr":"Zone colonne","en":"Spine zone"},"color":"#e100ff"},{"id":"charnieres-vertebrales","name":{"fr":"Charnières vertébrales","en":"Vertebral junctions"},"color":"#ff0000"},{"id":"cadrans-du-crane","name":{"fr":"Cadrans du crâne","en":"Skull quadrants"},"color":"#1baa08"}],"views":[{"id":"view-main","name":{"fr":"Cheval entier","en":"Whole horse"},"svg_asset_id":"3f6c1b52-8a4e-4d17-9b0c-5e2a7d91c4f8","view_box":null,"kind":"main"},{"id":"view-head","name":{"fr":"Tête","en":"Head"},"svg_asset_id":null,"view_box":{"min_x":60,"min_y":100,"width":500,"height":380},"kind":"detail","parent_view_id":"view-main"}],"annotations":[{"id":"hip","view_id":"view-main","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":1516,"cy":695,"r":34},"review_status":"inherited","color":null,"name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"finding_zone_id":"hip","vertebral_region_code":null,"kind":"point"},{"id":"cervical-vertebrae","view_id":"view-main","category_id":"zone-colonne","laterality":"unpaired","geometry":{"type":"polygon","points":[[468,276],[489,216],[558,248],[586,339],[552,461],[524,370]]},"review_status":"inherited","color":null,"name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"finding_zone_id":"cervical","vertebral_region_code":"C","kind":"zone"},{"id":"hinge-c7-t1","view_id":"view-main","category_id":"charnieres-vertebrales","laterality":"unpaired","geometry":{"type":"circle","cx":840.17,"cy":399.08,"r":30},"review_status":"inherited","color":null,"name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"finding_zone_id":"c7-t1","vertebral_region_code":null,"kind":"point"},{"id":"head-trigger","view_id":"view-main","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"polygon","points":[[454,332],[429,202],[349,154],[234,279],[164,384],[234,468]]},"review_status":"inherited","color":null,"kind":"detail_trigger","name":null,"opens_view_id":"view-head"},{"id":"atm","view_id":"view-head","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":384.94,"cy":314.02,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"finding_zone_id":"atm","vertebral_region_code":null,"kind":"point"},{"id":"sphenoid","view_id":"view-head","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"circle","cx":299,"cy":298,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Sphénoïde","en":"Sphenoid"},"finding_zone_id":"sphenoid","vertebral_region_code":null,"kind":"point"},{"id":"ghost","kind":"point","view_id":"view-ghost","category_id":"articulations","laterality":"bilateral","geometry":null,"review_status":"inherited","color":null,"name":{"fr":"ghost","en":"ghost"},"finding_zone_id":"hip","vertebral_region_code":null}],"finding_zones":[{"id":"hip","name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"categories":[{"id":"hip-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"articular","name":{"fr":"Restrictions de mobilité articulaire","en":"Articular mobility restrictions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-flexion","name":{"fr":"Restriction en flexion","en":"Flexion restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"restriction-extension","name":{"fr":"Restriction en extension","en":"Extension restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"hip-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"limb-lameness","name":{"fr":"Boiterie rapportée (membre concerné)","en":"Reported lameness (affected limb)"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":["legacy-catalog"],"review_status":"inherited","children":[]}]}]},{"id":"cervical","name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"categories":[{"id":"cervical-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"muscular","name":{"fr":"Tensions musculaires paravertébrales","en":"Paravertebral muscle tensions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"splenius-tension","name":{"fr":"Tension du splénius","en":"Splenius tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"cervical-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"stumbling-proprioceptive","name":{"fr":"Trébuchements / déficit proprioceptif rapporté","en":"Reported stumbling / proprioceptive deficit"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"c7-t1","name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"categories":[{"id":"c7-t1-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-rotation","name":{"fr":"Restriction en rotation","en":"Rotation restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"c7-t1-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"base-neck-stiffness","name":{"fr":"Raideur de la base de l'encolure","en":"Base-of-neck stiffness"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"atm","name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"categories":[{"id":"atm-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques de l'ATM","en":"Osteopathic TMJ dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"masseter-tension","name":{"fr":"Tension du masséter","en":"Masseter tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"atm-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"bit-defense","name":{"fr":"Réactions de défense au mors","en":"Defense reactions to bit"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"dental-context","name":{"fr":"Suite de soin dentaire récent","en":"Post recent dental care"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid","name":{"fr":"Sphénoïde","en":"Sphenoid"},"categories":[{"id":"ssb-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"physiological","name":{"fr":"Lésions physiologiques (SSB)","en":"Physiological lesions (SBS)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"torsion-right","name":{"fr":"Torsion droite","en":"Right torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"torsion-left","name":{"fr":"Torsion gauche","en":"Left torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"post-trauma-head","name":{"fr":"Suite de traumatisme crânien","en":"Post head trauma"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]}]}$fixture$::jsonb)) as c order by c collate "C"), - '{annotation.view.missing}'::text[], - 'conformance annotation-view-missing: an annotation on a view that does not exist' -); - -select is( - array(select c from unnest(private.sheet_document_issues($fixture${"schema_version":2,"species_id":"equine","name":{"fr":"Cheval (extrait)","en":"Horse (slice)"},"description":{"fr":"Extrait de la fiche équine pour les tests du modèle","en":"Equine sheet slice for model tests"},"scope_disclaimer":{"fr":"Les éléments listés correspondent au périmètre légal de l'ostéopathie animale : dysfonctions ostéopathiques palpées, observations cliniques et motifs de consultation. Aucun diagnostic médical n'est posé. Toute pathologie organique relève du vétérinaire."},"attribution":{"authors":["Faunosteo"],"license":"MIT","notes":null},"vertebral_config":{"regions":[{"code":"C","name":{"fr":"Cervicales","en":"Cervical"},"count":7,"count_range":null},{"code":"T","name":{"fr":"Thoraciques","en":"Thoracic"},"count":18,"count_range":null},{"code":"L","name":{"fr":"Lombaires","en":"Lumbar"},"count":6,"count_range":null},{"code":"S","name":{"fr":"Sacrées","en":"Sacral"},"count":5,"count_range":null},{"code":"Cd","name":{"fr":"Caudales","en":"Caudal"},"count":18,"count_range":{"min":15,"max":21}}]},"references":[{"id":"legacy-catalog","type":"manual","citation":"Legacy equine catalog (pathologies.json, schema 2.0)","url":null,"doi":null}],"categories":[{"id":"articulations","name":{"fr":"Articulations","en":"Joints"},"color":"#ff9500"},{"id":"zone-colonne","name":{"fr":"Zone colonne","en":"Spine zone"},"color":"#e100ff"},{"id":"charnieres-vertebrales","name":{"fr":"Charnières vertébrales","en":"Vertebral junctions"},"color":"#ff0000"},{"id":"cadrans-du-crane","name":{"fr":"Cadrans du crâne","en":"Skull quadrants"},"color":"#1baa08"},{"id":"articulations","name":{"fr":"Articulations","en":"Joints"},"color":"#ff9500"}],"views":[{"id":"view-main","name":{"fr":"Cheval entier","en":"Whole horse"},"svg_asset_id":"3f6c1b52-8a4e-4d17-9b0c-5e2a7d91c4f8","view_box":null,"kind":"main"},{"id":"view-head","name":{"fr":"Tête","en":"Head"},"svg_asset_id":null,"view_box":{"min_x":60,"min_y":100,"width":500,"height":380},"kind":"detail","parent_view_id":"view-main"}],"annotations":[{"id":"hip","view_id":"view-main","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":1516,"cy":695,"r":34},"review_status":"inherited","color":null,"name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"finding_zone_id":"hip","vertebral_region_code":null,"kind":"point"},{"id":"cervical-vertebrae","view_id":"view-main","category_id":"zone-colonne","laterality":"unpaired","geometry":{"type":"polygon","points":[[468,276],[489,216],[558,248],[586,339],[552,461],[524,370]]},"review_status":"inherited","color":null,"name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"finding_zone_id":"cervical","vertebral_region_code":"C","kind":"zone"},{"id":"hinge-c7-t1","view_id":"view-main","category_id":"charnieres-vertebrales","laterality":"unpaired","geometry":{"type":"circle","cx":840.17,"cy":399.08,"r":30},"review_status":"inherited","color":null,"name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"finding_zone_id":"c7-t1","vertebral_region_code":null,"kind":"point"},{"id":"head-trigger","view_id":"view-main","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"polygon","points":[[454,332],[429,202],[349,154],[234,279],[164,384],[234,468]]},"review_status":"inherited","color":null,"kind":"detail_trigger","name":null,"opens_view_id":"view-head"},{"id":"atm","view_id":"view-head","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":384.94,"cy":314.02,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"finding_zone_id":"atm","vertebral_region_code":null,"kind":"point"},{"id":"sphenoid","view_id":"view-head","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"circle","cx":299,"cy":298,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Sphénoïde","en":"Sphenoid"},"finding_zone_id":"sphenoid","vertebral_region_code":null,"kind":"point"}],"finding_zones":[{"id":"hip","name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"categories":[{"id":"hip-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"articular","name":{"fr":"Restrictions de mobilité articulaire","en":"Articular mobility restrictions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-flexion","name":{"fr":"Restriction en flexion","en":"Flexion restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"restriction-extension","name":{"fr":"Restriction en extension","en":"Extension restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"hip-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"limb-lameness","name":{"fr":"Boiterie rapportée (membre concerné)","en":"Reported lameness (affected limb)"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":["legacy-catalog"],"review_status":"inherited","children":[]}]}]},{"id":"cervical","name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"categories":[{"id":"cervical-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"muscular","name":{"fr":"Tensions musculaires paravertébrales","en":"Paravertebral muscle tensions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"splenius-tension","name":{"fr":"Tension du splénius","en":"Splenius tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"cervical-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"stumbling-proprioceptive","name":{"fr":"Trébuchements / déficit proprioceptif rapporté","en":"Reported stumbling / proprioceptive deficit"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"c7-t1","name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"categories":[{"id":"c7-t1-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-rotation","name":{"fr":"Restriction en rotation","en":"Rotation restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"c7-t1-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"base-neck-stiffness","name":{"fr":"Raideur de la base de l'encolure","en":"Base-of-neck stiffness"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"atm","name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"categories":[{"id":"atm-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques de l'ATM","en":"Osteopathic TMJ dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"masseter-tension","name":{"fr":"Tension du masséter","en":"Masseter tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"atm-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"bit-defense","name":{"fr":"Réactions de défense au mors","en":"Defense reactions to bit"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"dental-context","name":{"fr":"Suite de soin dentaire récent","en":"Post recent dental care"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid","name":{"fr":"Sphénoïde","en":"Sphenoid"},"categories":[{"id":"ssb-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"physiological","name":{"fr":"Lésions physiologiques (SSB)","en":"Physiological lesions (SBS)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"torsion-right","name":{"fr":"Torsion droite","en":"Right torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"torsion-left","name":{"fr":"Torsion gauche","en":"Left torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"post-trauma-head","name":{"fr":"Suite de traumatisme crânien","en":"Post head trauma"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]}]}$fixture$::jsonb)) as c order by c collate "C"), - '{category.id.duplicate}'::text[], - 'conformance category-id-duplicate: an annotation category listed twice' -); - -select is( - array(select c from unnest(private.sheet_document_issues($fixture${"schema_version":2,"species_id":"equine","name":{"fr":"Cheval (extrait)","en":"Horse (slice)"},"description":{"fr":"Extrait de la fiche équine pour les tests du modèle","en":"Equine sheet slice for model tests"},"scope_disclaimer":{"fr":"Les éléments listés correspondent au périmètre légal de l'ostéopathie animale : dysfonctions ostéopathiques palpées, observations cliniques et motifs de consultation. Aucun diagnostic médical n'est posé. Toute pathologie organique relève du vétérinaire."},"attribution":{"authors":["Faunosteo"],"license":"MIT","notes":null},"vertebral_config":{"regions":[{"code":"C","name":{"fr":"Cervicales","en":"Cervical"},"count":7,"count_range":null},{"code":"T","name":{"fr":"Thoraciques","en":"Thoracic"},"count":18,"count_range":null},{"code":"L","name":{"fr":"Lombaires","en":"Lumbar"},"count":6,"count_range":null},{"code":"S","name":{"fr":"Sacrées","en":"Sacral"},"count":5,"count_range":null},{"code":"Cd","name":{"fr":"Caudales","en":"Caudal"},"count":18,"count_range":{"min":15,"max":21}}]},"references":[{"id":"legacy-catalog","type":"manual","citation":"Legacy equine catalog (pathologies.json, schema 2.0)","url":null,"doi":null}],"categories":[{"id":"articulations","name":{"fr":"Articulations","en":"Joints"},"color":"#ff9500"},{"id":"zone-colonne","name":{"fr":"Zone colonne","en":"Spine zone"},"color":"#e100ff"},{"id":"charnieres-vertebrales","name":{"fr":"Charnières vertébrales","en":"Vertebral junctions"},"color":"#ff0000"},{"id":"cadrans-du-crane","name":{"fr":"Cadrans du crâne","en":"Skull quadrants"},"color":"#1baa08"}],"views":[{"id":"view-main","name":{"fr":"Cheval entier","en":"Whole horse"},"svg_asset_id":"3f6c1b52-8a4e-4d17-9b0c-5e2a7d91c4f8","view_box":null,"kind":"main"},{"id":"view-head","name":{"fr":"Tête","en":"Head"},"svg_asset_id":null,"view_box":{"min_x":60,"min_y":100,"width":500,"height":380},"kind":"detail","parent_view_id":"view-main"}],"annotations":[{"id":"hip","view_id":"view-main","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":1516,"cy":695,"r":34},"review_status":"inherited","color":null,"name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"finding_zone_id":"hip","vertebral_region_code":null,"kind":"point"},{"id":"cervical-vertebrae","view_id":"view-main","category_id":"zone-colonne","laterality":"unpaired","geometry":{"type":"polygon","points":[[468,276],[489,216],[558,248],[586,339],[552,461],[524,370]]},"review_status":"inherited","color":null,"name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"finding_zone_id":"cervical","vertebral_region_code":"C","kind":"zone"},{"id":"hinge-c7-t1","view_id":"view-main","category_id":"charnieres-vertebrales","laterality":"unpaired","geometry":{"type":"circle","cx":840.17,"cy":399.08,"r":30},"review_status":"inherited","color":null,"name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"finding_zone_id":"c7-t1","vertebral_region_code":null,"kind":"point"},{"id":"head-trigger","view_id":"view-main","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"polygon","points":[[454,332],[429,202],[349,154],[234,279],[164,384],[234,468]]},"review_status":"inherited","color":null,"kind":"detail_trigger","name":null,"opens_view_id":"view-head"},{"id":"atm","view_id":"view-head","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":384.94,"cy":314.02,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"finding_zone_id":"atm","vertebral_region_code":null,"kind":"point"},{"id":"sphenoid","view_id":"view-head","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"circle","cx":299,"cy":298,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Sphénoïde","en":"Sphenoid"},"finding_zone_id":"sphenoid","vertebral_region_code":null,"kind":"point"}],"finding_zones":[{"id":"hip","name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"categories":[{"id":"hip-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"articular","name":{"fr":"Restrictions de mobilité articulaire","en":"Articular mobility restrictions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-flexion","name":{"fr":"Restriction en flexion","en":"Flexion restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"restriction-extension","name":{"fr":"Restriction en extension","en":"Extension restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"hip-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"limb-lameness","name":{"fr":"Boiterie rapportée (membre concerné)","en":"Reported lameness (affected limb)"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":["legacy-catalog"],"review_status":"inherited","children":[]}]}]},{"id":"cervical","name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"categories":[{"id":"cervical-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"muscular","name":{"fr":"Tensions musculaires paravertébrales","en":"Paravertebral muscle tensions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"splenius-tension","name":{"fr":"Tension du splénius","en":"Splenius tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"cervical-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"stumbling-proprioceptive","name":{"fr":"Trébuchements / déficit proprioceptif rapporté","en":"Reported stumbling / proprioceptive deficit"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"c7-t1","name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"categories":[{"id":"c7-t1-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-rotation","name":{"fr":"Restriction en rotation","en":"Rotation restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"c7-t1-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"base-neck-stiffness","name":{"fr":"Raideur de la base de l'encolure","en":"Base-of-neck stiffness"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"atm","name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"categories":[{"id":"atm-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques de l'ATM","en":"Osteopathic TMJ dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"masseter-tension","name":{"fr":"Tension du masséter","en":"Masseter tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"atm-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"bit-defense","name":{"fr":"Réactions de défense au mors","en":"Defense reactions to bit"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"dental-context","name":{"fr":"Suite de soin dentaire récent","en":"Post recent dental care"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid","name":{"fr":"Sphénoïde","en":"Sphenoid"},"categories":[{"id":"ssb-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"physiological","name":{"fr":"Lésions physiologiques (SSB)","en":"Physiological lesions (SBS)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"torsion-right","name":{"fr":"Torsion droite","en":"Right torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"torsion-left","name":{"fr":"Torsion gauche","en":"Left torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"post-trauma-head","name":{"fr":"Suite de traumatisme crânien","en":"Post head trauma"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]}]}$fixture$::jsonb)) as c order by c collate "C"), - '{}'::text[], - 'conformance clean: the horse slice: no issue' -); - -select is( - array(select c from unnest(private.sheet_document_issues($fixture${"schema_version":2,"species_id":"equine","name":{"fr":"Cheval (extrait)","en":"Horse (slice)"},"description":{"fr":"Extrait de la fiche équine pour les tests du modèle","en":"Equine sheet slice for model tests"},"scope_disclaimer":{"fr":"Les éléments listés correspondent au périmètre légal de l'ostéopathie animale : dysfonctions ostéopathiques palpées, observations cliniques et motifs de consultation. Aucun diagnostic médical n'est posé. Toute pathologie organique relève du vétérinaire."},"attribution":{"authors":["Faunosteo"],"license":"MIT","notes":null},"vertebral_config":{"regions":[{"code":"C","name":{"fr":"Cervicales","en":"Cervical"},"count":7,"count_range":null},{"code":"T","name":{"fr":"Thoraciques","en":"Thoracic"},"count":18,"count_range":null},{"code":"L","name":{"fr":"Lombaires","en":"Lumbar"},"count":6,"count_range":null},{"code":"S","name":{"fr":"Sacrées","en":"Sacral"},"count":5,"count_range":null},{"code":"Cd","name":{"fr":"Caudales","en":"Caudal"},"count":18,"count_range":{"min":15,"max":21}}]},"references":[{"id":"legacy-catalog","type":"manual","citation":"Legacy equine catalog (pathologies.json, schema 2.0)","url":null,"doi":null}],"categories":[{"id":"articulations","name":{"fr":"Articulations","en":"Joints"},"color":"#ff9500"},{"id":"zone-colonne","name":{"fr":"Zone colonne","en":"Spine zone"},"color":"#e100ff"},{"id":"charnieres-vertebrales","name":{"fr":"Charnières vertébrales","en":"Vertebral junctions"},"color":"#ff0000"},{"id":"cadrans-du-crane","name":{"fr":"Cadrans du crâne","en":"Skull quadrants"},"color":"#1baa08"}],"views":[{"id":"view-main","name":{"fr":"Cheval entier","en":"Whole horse"},"svg_asset_id":"3f6c1b52-8a4e-4d17-9b0c-5e2a7d91c4f8","view_box":null,"kind":"main"},{"id":"view-head","name":{"fr":"Tête","en":"Head"},"svg_asset_id":null,"view_box":{"min_x":60,"min_y":100,"width":500,"height":380},"kind":"detail","parent_view_id":"view-main"}],"annotations":[{"id":"hip","view_id":"view-main","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":1516,"cy":695,"r":34},"review_status":"inherited","color":null,"name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"finding_zone_id":"hip","vertebral_region_code":null,"kind":"point"},{"id":"cervical-vertebrae","view_id":"view-main","category_id":"zone-colonne","laterality":"unpaired","geometry":{"type":"polygon","points":[[468,276],[489,216],[558,248],[586,339],[552,461],[524,370]]},"review_status":"inherited","color":null,"name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"finding_zone_id":"cervical","vertebral_region_code":"C","kind":"zone"},{"id":"hinge-c7-t1","view_id":"view-main","category_id":"charnieres-vertebrales","laterality":"unpaired","geometry":{"type":"circle","cx":840.17,"cy":399.08,"r":30},"review_status":"inherited","color":null,"name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"finding_zone_id":"c7-t1","vertebral_region_code":null,"kind":"point"},{"id":"head-trigger","view_id":"view-main","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"polygon","points":[[454,332],[429,202],[349,154],[234,279],[164,384],[234,468]]},"review_status":"inherited","color":null,"kind":"detail_trigger","name":null,"opens_view_id":"view-head"},{"id":"atm","view_id":"view-head","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":384.94,"cy":314.02,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"finding_zone_id":"atm","vertebral_region_code":null,"kind":"point"},{"id":"sphenoid","view_id":"view-head","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"circle","cx":299,"cy":298,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Sphénoïde","en":"Sphenoid"},"finding_zone_id":"sphenoid","vertebral_region_code":null,"kind":"point"}],"finding_zones":[{"id":"hip","name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"categories":[{"id":"hip-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"articular","name":{"fr":"Restrictions de mobilité articulaire","en":"Articular mobility restrictions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-flexion","name":{"fr":"Restriction en flexion","en":"Flexion restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"restriction-extension","name":{"fr":"Restriction en extension","en":"Extension restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"restriction-flexion","name":{"fr":"Restriction en flexion","en":"Flexion restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"hip-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"limb-lameness","name":{"fr":"Boiterie rapportée (membre concerné)","en":"Reported lameness (affected limb)"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":["legacy-catalog"],"review_status":"inherited","children":[]}]},{"id":"hip-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"articular","name":{"fr":"Restrictions de mobilité articulaire","en":"Articular mobility restrictions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-flexion","name":{"fr":"Restriction en flexion","en":"Flexion restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"restriction-extension","name":{"fr":"Restriction en extension","en":"Extension restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]}]},{"id":"cervical","name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"categories":[{"id":"cervical-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"muscular","name":{"fr":"Tensions musculaires paravertébrales","en":"Paravertebral muscle tensions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"splenius-tension","name":{"fr":"Tension du splénius","en":"Splenius tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"cervical-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"stumbling-proprioceptive","name":{"fr":"Trébuchements / déficit proprioceptif rapporté","en":"Reported stumbling / proprioceptive deficit"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"c7-t1","name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"categories":[{"id":"c7-t1-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-rotation","name":{"fr":"Restriction en rotation","en":"Rotation restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"c7-t1-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"base-neck-stiffness","name":{"fr":"Raideur de la base de l'encolure","en":"Base-of-neck stiffness"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"atm","name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"categories":[{"id":"atm-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques de l'ATM","en":"Osteopathic TMJ dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"masseter-tension","name":{"fr":"Tension du masséter","en":"Masseter tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"atm-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"bit-defense","name":{"fr":"Réactions de défense au mors","en":"Defense reactions to bit"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"dental-context","name":{"fr":"Suite de soin dentaire récent","en":"Post recent dental care"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid","name":{"fr":"Sphénoïde","en":"Sphenoid"},"categories":[{"id":"ssb-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"physiological","name":{"fr":"Lésions physiologiques (SSB)","en":"Physiological lesions (SBS)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"torsion-right","name":{"fr":"Torsion droite","en":"Right torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"torsion-left","name":{"fr":"Torsion gauche","en":"Left torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"post-trauma-head","name":{"fr":"Suite de traumatisme crânien","en":"Post head trauma"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]}]}$fixture$::jsonb)) as c order by c collate "C"), - '{}'::text[], - 'conformance finding-id-duplicate: sibling finding ids repeated at two depths (not mirrored by SQL)' -); - -select is( - array(select c from unnest(private.sheet_document_issues($fixture${"schema_version":2,"species_id":"equine","name":{"fr":"Cheval (extrait)","en":"Horse (slice)"},"description":{"fr":"Extrait de la fiche équine pour les tests du modèle","en":"Equine sheet slice for model tests"},"scope_disclaimer":{"fr":"Les éléments listés correspondent au périmètre légal de l'ostéopathie animale : dysfonctions ostéopathiques palpées, observations cliniques et motifs de consultation. Aucun diagnostic médical n'est posé. Toute pathologie organique relève du vétérinaire."},"attribution":{"authors":["Faunosteo"],"license":"MIT","notes":null},"vertebral_config":{"regions":[{"code":"C","name":{"fr":"Cervicales","en":"Cervical"},"count":7,"count_range":null},{"code":"T","name":{"fr":"Thoraciques","en":"Thoracic"},"count":18,"count_range":null},{"code":"L","name":{"fr":"Lombaires","en":"Lumbar"},"count":6,"count_range":null},{"code":"S","name":{"fr":"Sacrées","en":"Sacral"},"count":5,"count_range":null},{"code":"Cd","name":{"fr":"Caudales","en":"Caudal"},"count":18,"count_range":{"min":15,"max":21}}]},"references":[{"id":"legacy-catalog","type":"manual","citation":"Legacy equine catalog (pathologies.json, schema 2.0)","url":null,"doi":null}],"categories":[{"id":"articulations","name":{"fr":"Articulations","en":"Joints"},"color":"#ff9500"},{"id":"zone-colonne","name":{"fr":"Zone colonne","en":"Spine zone"},"color":"#e100ff"},{"id":"charnieres-vertebrales","name":{"fr":"Charnières vertébrales","en":"Vertebral junctions"},"color":"#ff0000"},{"id":"cadrans-du-crane","name":{"fr":"Cadrans du crâne","en":"Skull quadrants"},"color":"#1baa08"}],"views":[{"id":"view-main","name":{"fr":"Cheval entier","en":"Whole horse"},"svg_asset_id":"3f6c1b52-8a4e-4d17-9b0c-5e2a7d91c4f8","view_box":null,"kind":"main"},{"id":"view-head","name":{"fr":"Tête","en":"Head"},"svg_asset_id":null,"view_box":{"min_x":60,"min_y":100,"width":500,"height":380},"kind":"detail","parent_view_id":"view-main"}],"annotations":[{"id":"hip","view_id":"view-main","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":1516,"cy":695,"r":34},"review_status":"inherited","color":null,"name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"finding_zone_id":"hip","vertebral_region_code":null,"kind":"point"},{"id":"cervical-vertebrae","view_id":"view-main","category_id":"zone-colonne","laterality":"unpaired","geometry":{"type":"polygon","points":[[468,276],[489,216],[558,248],[586,339],[552,461],[524,370]]},"review_status":"inherited","color":null,"name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"finding_zone_id":"cervical","vertebral_region_code":"C","kind":"zone"},{"id":"hinge-c7-t1","view_id":"view-main","category_id":"charnieres-vertebrales","laterality":"unpaired","geometry":{"type":"circle","cx":840.17,"cy":399.08,"r":30},"review_status":"inherited","color":null,"name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"finding_zone_id":"c7-t1","vertebral_region_code":null,"kind":"point"},{"id":"head-trigger","view_id":"view-main","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"polygon","points":[[454,332],[429,202],[349,154],[234,279],[164,384],[234,468]]},"review_status":"inherited","color":null,"kind":"detail_trigger","name":null,"opens_view_id":"view-head"},{"id":"atm","view_id":"view-head","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":384.94,"cy":314.02,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"finding_zone_id":"atm","vertebral_region_code":null,"kind":"point"},{"id":"sphenoid","view_id":"view-head","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"circle","cx":299,"cy":298,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Sphénoïde","en":"Sphenoid"},"finding_zone_id":"sphenoid","vertebral_region_code":null,"kind":"point"}],"finding_zones":[{"id":"hip","name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"categories":[{"id":"hip-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":["nav-2017"],"review_status":"inherited","children":[{"id":"articular","name":{"fr":"Restrictions de mobilité articulaire","en":"Articular mobility restrictions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-flexion","name":{"fr":"Restriction en flexion","en":"Flexion restriction"},"description":{},"requires_vet_referral":false,"reference_ids":["legacy-catalog","x"],"review_status":"inherited","children":[]},{"id":"restriction-extension","name":{"fr":"Restriction en extension","en":"Extension restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"hip-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"limb-lameness","name":{"fr":"Boiterie rapportée (membre concerné)","en":"Reported lameness (affected limb)"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":["legacy-catalog"],"review_status":"inherited","children":[]}]}]},{"id":"cervical","name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"categories":[{"id":"cervical-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"muscular","name":{"fr":"Tensions musculaires paravertébrales","en":"Paravertebral muscle tensions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"splenius-tension","name":{"fr":"Tension du splénius","en":"Splenius tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"cervical-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"stumbling-proprioceptive","name":{"fr":"Trébuchements / déficit proprioceptif rapporté","en":"Reported stumbling / proprioceptive deficit"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"c7-t1","name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"categories":[{"id":"c7-t1-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-rotation","name":{"fr":"Restriction en rotation","en":"Rotation restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"c7-t1-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"base-neck-stiffness","name":{"fr":"Raideur de la base de l'encolure","en":"Base-of-neck stiffness"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"atm","name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"categories":[{"id":"atm-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques de l'ATM","en":"Osteopathic TMJ dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"masseter-tension","name":{"fr":"Tension du masséter","en":"Masseter tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"atm-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"bit-defense","name":{"fr":"Réactions de défense au mors","en":"Defense reactions to bit"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"dental-context","name":{"fr":"Suite de soin dentaire récent","en":"Post recent dental care"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid","name":{"fr":"Sphénoïde","en":"Sphenoid"},"categories":[{"id":"ssb-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"physiological","name":{"fr":"Lésions physiologiques (SSB)","en":"Physiological lesions (SBS)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"torsion-right","name":{"fr":"Torsion droite","en":"Right torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"torsion-left","name":{"fr":"Torsion gauche","en":"Left torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"post-trauma-head","name":{"fr":"Suite de traumatisme crânien","en":"Post head trauma"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]}]}$fixture$::jsonb)) as c order by c collate "C"), - '{finding.reference.missing}'::text[], - 'conformance finding-reference-missing: undeclared citations on a category and on a nested node' -); - -select is( - array(select c from unnest(private.sheet_document_issues($fixture${"schema_version":2,"species_id":"equine","name":{"fr":"Cheval (extrait)","en":"Horse (slice)"},"description":{"fr":"Extrait de la fiche équine pour les tests du modèle","en":"Equine sheet slice for model tests"},"scope_disclaimer":{"fr":"Les éléments listés correspondent au périmètre légal de l'ostéopathie animale : dysfonctions ostéopathiques palpées, observations cliniques et motifs de consultation. Aucun diagnostic médical n'est posé. Toute pathologie organique relève du vétérinaire."},"attribution":{"authors":["Faunosteo"],"license":"MIT","notes":null},"vertebral_config":{"regions":[{"code":"C","name":{"fr":"Cervicales","en":"Cervical"},"count":7,"count_range":null},{"code":"T","name":{"fr":"Thoraciques","en":"Thoracic"},"count":18,"count_range":null},{"code":"L","name":{"fr":"Lombaires","en":"Lumbar"},"count":6,"count_range":null},{"code":"S","name":{"fr":"Sacrées","en":"Sacral"},"count":5,"count_range":null},{"code":"Cd","name":{"fr":"Caudales","en":"Caudal"},"count":18,"count_range":{"min":15,"max":21}}]},"references":[{"id":"legacy-catalog","type":"manual","citation":"Legacy equine catalog (pathologies.json, schema 2.0)","url":null,"doi":null}],"categories":[{"id":"articulations","name":{"fr":"Articulations","en":"Joints"},"color":"#ff9500"},{"id":"zone-colonne","name":{"fr":"Zone colonne","en":"Spine zone"},"color":"#e100ff"},{"id":"charnieres-vertebrales","name":{"fr":"Charnières vertébrales","en":"Vertebral junctions"},"color":"#ff0000"},{"id":"cadrans-du-crane","name":{"fr":"Cadrans du crâne","en":"Skull quadrants"},"color":"#1baa08"}],"views":[{"id":"view-main","name":{"fr":"Cheval entier","en":"Whole horse"},"svg_asset_id":"3f6c1b52-8a4e-4d17-9b0c-5e2a7d91c4f8","view_box":null,"kind":"main"},{"id":"view-head","name":{"fr":"Tête","en":"Head"},"svg_asset_id":null,"view_box":{"min_x":60,"min_y":100,"width":500,"height":380},"kind":"detail","parent_view_id":"view-main"}],"annotations":[{"id":"hip","view_id":"view-main","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":1516,"cy":695,"r":34},"review_status":"inherited","color":null,"name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"finding_zone_id":"hip","vertebral_region_code":null,"kind":"point"},{"id":"cervical-vertebrae","view_id":"view-main","category_id":"zone-colonne","laterality":"unpaired","geometry":{"type":"polygon","points":[[468,276],[489,216],[558,248],[586,339],[552,461],[524,370]]},"review_status":"inherited","color":null,"name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"finding_zone_id":"cervical","vertebral_region_code":"C","kind":"zone"},{"id":"hinge-c7-t1","view_id":"view-main","category_id":"charnieres-vertebrales","laterality":"unpaired","geometry":{"type":"circle","cx":840.17,"cy":399.08,"r":30},"review_status":"inherited","color":null,"name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"finding_zone_id":"c7-t1","vertebral_region_code":null,"kind":"point"},{"id":"head-trigger","view_id":"view-main","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"polygon","points":[[454,332],[429,202],[349,154],[234,279],[164,384],[234,468]]},"review_status":"inherited","color":null,"kind":"detail_trigger","name":null,"opens_view_id":"view-head"},{"id":"atm","view_id":"view-head","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":384.94,"cy":314.02,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"finding_zone_id":"atm","vertebral_region_code":null,"kind":"point"},{"id":"sphenoid","view_id":"view-head","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"circle","cx":299,"cy":298,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Sphénoïde","en":"Sphenoid"},"finding_zone_id":"sphenoid","vertebral_region_code":null,"kind":"point"}],"finding_zones":[{"id":"hip","name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"categories":[{"id":"hip-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"articular","name":{"fr":"Restrictions de mobilité articulaire","en":"Articular mobility restrictions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-flexion","name":{"fr":"Restriction en flexion","en":"Flexion restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"restriction-extension","name":{"fr":"Restriction en extension","en":"Extension restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"hip-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"limb-lameness","name":{"fr":"Boiterie rapportée (membre concerné)","en":"Reported lameness (affected limb)"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":["legacy-catalog"],"review_status":"inherited","children":[]}]}]},{"id":"cervical","name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"categories":[{"id":"cervical-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"muscular","name":{"fr":"Tensions musculaires paravertébrales","en":"Paravertebral muscle tensions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"splenius-tension","name":{"fr":"Tension du splénius","en":"Splenius tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"cervical-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"stumbling-proprioceptive","name":{"fr":"Trébuchements / déficit proprioceptif rapporté","en":"Reported stumbling / proprioceptive deficit"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"c7-t1","name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"categories":[{"id":"c7-t1-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-rotation","name":{"fr":"Restriction en rotation","en":"Rotation restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"c7-t1-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"base-neck-stiffness","name":{"fr":"Raideur de la base de l'encolure","en":"Base-of-neck stiffness"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"atm","name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"categories":[{"id":"atm-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques de l'ATM","en":"Osteopathic TMJ dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"masseter-tension","name":{"fr":"Tension du masséter","en":"Masseter tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"atm-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"bit-defense","name":{"fr":"Réactions de défense au mors","en":"Defense reactions to bit"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"dental-context","name":{"fr":"Suite de soin dentaire récent","en":"Post recent dental care"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid","name":{"fr":"Sphénoïde","en":"Sphenoid"},"categories":[{"id":"ssb-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"physiological","name":{"fr":"Lésions physiologiques (SSB)","en":"Physiological lesions (SBS)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"torsion-right","name":{"fr":"Torsion droite","en":"Right torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"torsion-left","name":{"fr":"Torsion gauche","en":"Left torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"post-trauma-head","name":{"fr":"Suite de traumatisme crânien","en":"Post head trauma"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"hip","name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"categories":[{"id":"hip-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"articular","name":{"fr":"Restrictions de mobilité articulaire","en":"Articular mobility restrictions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-flexion","name":{"fr":"Restriction en flexion","en":"Flexion restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"restriction-extension","name":{"fr":"Restriction en extension","en":"Extension restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"hip-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"limb-lameness","name":{"fr":"Boiterie rapportée (membre concerné)","en":"Reported lameness (affected limb)"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":["legacy-catalog"],"review_status":"inherited","children":[]}]}]}]}$fixture$::jsonb)) as c order by c collate "C"), - '{finding_zone.id.duplicate}'::text[], - 'conformance finding-zone-id-duplicate: a finding zone listed twice' -); - -select is( - array(select c from unnest(private.sheet_document_issues($fixture${"schema_version":2,"species_id":"equine","name":{"fr":"Cheval (extrait)","en":"Horse (slice)"},"description":{"fr":"Extrait de la fiche équine pour les tests du modèle","en":"Equine sheet slice for model tests"},"scope_disclaimer":{"fr":"Les éléments listés correspondent au périmètre légal de l'ostéopathie animale : dysfonctions ostéopathiques palpées, observations cliniques et motifs de consultation. Aucun diagnostic médical n'est posé. Toute pathologie organique relève du vétérinaire."},"attribution":{"authors":["Faunosteo"],"license":"MIT","notes":null},"vertebral_config":{"regions":[{"code":"C","name":{"fr":"Cervicales","en":"Cervical"},"count":7,"count_range":null},{"code":"T","name":{"fr":"Thoraciques","en":"Thoracic"},"count":18,"count_range":null},{"code":"L","name":{"fr":"Lombaires","en":"Lumbar"},"count":6,"count_range":null},{"code":"S","name":{"fr":"Sacrées","en":"Sacral"},"count":5,"count_range":null},{"code":"Cd","name":{"fr":"Caudales","en":"Caudal"},"count":18,"count_range":{"min":15,"max":21}}]},"references":[{"id":"legacy-catalog","type":"manual","citation":"Legacy equine catalog (pathologies.json, schema 2.0)","url":null,"doi":null}],"categories":[{"id":"articulations","name":{"fr":"Articulations","en":"Joints"},"color":"#ff9500"},{"id":"zone-colonne","name":{"fr":"Zone colonne","en":"Spine zone"},"color":"#e100ff"},{"id":"charnieres-vertebrales","name":{"fr":"Charnières vertébrales","en":"Vertebral junctions"},"color":"#ff0000"},{"id":"cadrans-du-crane","name":{"fr":"Cadrans du crâne","en":"Skull quadrants"},"color":"#1baa08"}],"views":[{"id":"view-main","name":{"fr":"Cheval entier","en":"Whole horse"},"svg_asset_id":"3f6c1b52-8a4e-4d17-9b0c-5e2a7d91c4f8","view_box":null,"kind":"main"},{"id":"view-head","name":{"fr":"Tête","en":"Head"},"svg_asset_id":null,"view_box":{"min_x":60,"min_y":100,"width":500,"height":380},"kind":"detail","parent_view_id":"view-main"}],"annotations":[{"id":"hip","view_id":"view-main","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":1516,"cy":695,"r":34},"review_status":"inherited","color":null,"name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"finding_zone_id":"hip","vertebral_region_code":null,"kind":"point"},{"id":"cervical-vertebrae","view_id":"view-main","category_id":"zone-colonne","laterality":"unpaired","geometry":{"type":"polygon","points":[[468,276],[489,216],[558,248],[586,339],[552,461],[524,370]]},"review_status":"inherited","color":null,"name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"finding_zone_id":"cervical","vertebral_region_code":"C","kind":"zone"},{"id":"hinge-c7-t1","view_id":"view-main","category_id":"charnieres-vertebrales","laterality":"unpaired","geometry":{"type":"circle","cx":840.17,"cy":399.08,"r":30},"review_status":"inherited","color":null,"name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"finding_zone_id":"c7-t1","vertebral_region_code":null,"kind":"point"},{"id":"head-trigger","view_id":"view-main","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"polygon","points":[[454,332],[429,202],[349,154],[234,279],[164,384],[234,468]]},"review_status":"inherited","color":null,"kind":"detail_trigger","name":null,"opens_view_id":"view-head"},{"id":"atm","view_id":"view-head","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":384.94,"cy":314.02,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"finding_zone_id":"atm","vertebral_region_code":null,"kind":"point"},{"id":"sphenoid","view_id":"view-head","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"circle","cx":299,"cy":298,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Sphénoïde","en":"Sphenoid"},"finding_zone_id":"sphenoid","vertebral_region_code":null,"kind":"point"}],"finding_zones":[{"id":"hip","name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"categories":[{"id":"hip-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"articular","name":{"fr":"Restrictions de mobilité articulaire","en":"Articular mobility restrictions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-flexion","name":{"fr":"Restriction en flexion","en":"Flexion restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"restriction-extension","name":{"fr":"Restriction en extension","en":"Extension restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"hip-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"limb-lameness","name":{"fr":"Boiterie rapportée (membre concerné)","en":"Reported lameness (affected limb)"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":["legacy-catalog"],"review_status":"inherited","children":[]}]}]},{"id":"cervical","name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"categories":[{"id":"cervical-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"muscular","name":{"fr":"Tensions musculaires paravertébrales","en":"Paravertebral muscle tensions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"splenius-tension","name":{"fr":"Tension du splénius","en":"Splenius tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"cervical-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"stumbling-proprioceptive","name":{"fr":"Trébuchements / déficit proprioceptif rapporté","en":"Reported stumbling / proprioceptive deficit"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"c7-t1","name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"categories":[{"id":"c7-t1-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-rotation","name":{"fr":"Restriction en rotation","en":"Rotation restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"c7-t1-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"base-neck-stiffness","name":{"fr":"Raideur de la base de l'encolure","en":"Base-of-neck stiffness"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"atm","name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"categories":[{"id":"atm-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques de l'ATM","en":"Osteopathic TMJ dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"masseter-tension","name":{"fr":"Tension du masséter","en":"Masseter tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"atm-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"bit-defense","name":{"fr":"Réactions de défense au mors","en":"Defense reactions to bit"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"dental-context","name":{"fr":"Suite de soin dentaire récent","en":"Post recent dental care"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid","name":{"fr":"Sphénoïde","en":"Sphenoid"},"categories":[{"id":"ssb-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"physiological","name":{"fr":"Lésions physiologiques (SSB)","en":"Physiological lesions (SBS)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"torsion-right","name":{"fr":"Torsion droite","en":"Right torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"torsion-left","name":{"fr":"Torsion gauche","en":"Left torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"post-trauma-head","name":{"fr":"Suite de traumatisme crânien","en":"Post head trauma"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"stifle","name":{"fr":"Grasset","en":"Stifle"},"categories":[]}]}$fixture$::jsonb)) as c order by c collate "C"), - '{}'::text[], - 'conformance finding-zone-unreferenced: a finding zone no annotation points to (warning, not mirrored by SQL)' -); - -select is( - array(select c from unnest(private.sheet_document_issues($fixture${"schema_version":2,"species_id":"equine","name":{"fr":"Cheval (extrait)","en":"Horse (slice)"},"description":{"fr":"Extrait de la fiche équine pour les tests du modèle","en":"Equine sheet slice for model tests"},"scope_disclaimer":{"fr":"Les éléments listés correspondent au périmètre légal de l'ostéopathie animale : dysfonctions ostéopathiques palpées, observations cliniques et motifs de consultation. Aucun diagnostic médical n'est posé. Toute pathologie organique relève du vétérinaire."},"attribution":{"authors":["Faunosteo"],"license":"MIT","notes":null},"vertebral_config":{"regions":[{"code":"C","name":{"fr":"Cervicales","en":"Cervical"},"count":7,"count_range":null},{"code":"T","name":{"fr":"Thoraciques","en":"Thoracic"},"count":18,"count_range":null},{"code":"L","name":{"fr":"Lombaires","en":"Lumbar"},"count":6,"count_range":null},{"code":"S","name":{"fr":"Sacrées","en":"Sacral"},"count":5,"count_range":null},{"code":"Cd","name":{"fr":"Caudales","en":"Caudal"},"count":18,"count_range":{"min":15,"max":21}}]},"references":[{"id":"legacy-catalog","type":"manual","citation":"Legacy equine catalog (pathologies.json, schema 2.0)","url":null,"doi":null},{"id":"legacy-catalog","type":"manual","citation":"Legacy equine catalog (pathologies.json, schema 2.0)","url":null,"doi":null}],"categories":[{"id":"articulations","name":{"fr":"Articulations","en":"Joints"},"color":"#ff9500"},{"id":"zone-colonne","name":{"fr":"Zone colonne","en":"Spine zone"},"color":"#e100ff"},{"id":"charnieres-vertebrales","name":{"fr":"Charnières vertébrales","en":"Vertebral junctions"},"color":"#ff0000"},{"id":"cadrans-du-crane","name":{"fr":"Cadrans du crâne","en":"Skull quadrants"},"color":"#1baa08"}],"views":[{"id":"view-main","name":{"fr":"Cheval entier","en":"Whole horse"},"svg_asset_id":"3f6c1b52-8a4e-4d17-9b0c-5e2a7d91c4f8","view_box":null,"kind":"main"},{"id":"view-head","name":{"fr":"Tête","en":"Head"},"svg_asset_id":null,"view_box":{"min_x":60,"min_y":100,"width":500,"height":380},"kind":"detail","parent_view_id":"view-main"}],"annotations":[{"id":"hip","view_id":"view-main","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":1516,"cy":695,"r":34},"review_status":"inherited","color":null,"name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"finding_zone_id":"hip","vertebral_region_code":null,"kind":"point"},{"id":"cervical-vertebrae","view_id":"view-main","category_id":"zone-colonne","laterality":"unpaired","geometry":{"type":"polygon","points":[[468,276],[489,216],[558,248],[586,339],[552,461],[524,370]]},"review_status":"inherited","color":null,"name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"finding_zone_id":"cervical","vertebral_region_code":"C","kind":"zone"},{"id":"hinge-c7-t1","view_id":"view-main","category_id":"charnieres-vertebrales","laterality":"unpaired","geometry":{"type":"circle","cx":840.17,"cy":399.08,"r":30},"review_status":"inherited","color":null,"name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"finding_zone_id":"c7-t1","vertebral_region_code":null,"kind":"point"},{"id":"head-trigger","view_id":"view-main","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"polygon","points":[[454,332],[429,202],[349,154],[234,279],[164,384],[234,468]]},"review_status":"inherited","color":null,"kind":"detail_trigger","name":null,"opens_view_id":"view-head"},{"id":"atm","view_id":"view-head","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":384.94,"cy":314.02,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"finding_zone_id":"atm","vertebral_region_code":null,"kind":"point"},{"id":"sphenoid","view_id":"view-head","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"circle","cx":299,"cy":298,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Sphénoïde","en":"Sphenoid"},"finding_zone_id":"sphenoid","vertebral_region_code":null,"kind":"point"}],"finding_zones":[{"id":"hip","name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"categories":[{"id":"hip-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"articular","name":{"fr":"Restrictions de mobilité articulaire","en":"Articular mobility restrictions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-flexion","name":{"fr":"Restriction en flexion","en":"Flexion restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"restriction-extension","name":{"fr":"Restriction en extension","en":"Extension restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"hip-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"limb-lameness","name":{"fr":"Boiterie rapportée (membre concerné)","en":"Reported lameness (affected limb)"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":["legacy-catalog"],"review_status":"inherited","children":[]}]}]},{"id":"cervical","name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"categories":[{"id":"cervical-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"muscular","name":{"fr":"Tensions musculaires paravertébrales","en":"Paravertebral muscle tensions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"splenius-tension","name":{"fr":"Tension du splénius","en":"Splenius tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"cervical-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"stumbling-proprioceptive","name":{"fr":"Trébuchements / déficit proprioceptif rapporté","en":"Reported stumbling / proprioceptive deficit"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"c7-t1","name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"categories":[{"id":"c7-t1-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-rotation","name":{"fr":"Restriction en rotation","en":"Rotation restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"c7-t1-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"base-neck-stiffness","name":{"fr":"Raideur de la base de l'encolure","en":"Base-of-neck stiffness"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"atm","name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"categories":[{"id":"atm-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques de l'ATM","en":"Osteopathic TMJ dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"masseter-tension","name":{"fr":"Tension du masséter","en":"Masseter tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"atm-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"bit-defense","name":{"fr":"Réactions de défense au mors","en":"Defense reactions to bit"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"dental-context","name":{"fr":"Suite de soin dentaire récent","en":"Post recent dental care"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid","name":{"fr":"Sphénoïde","en":"Sphenoid"},"categories":[{"id":"ssb-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"physiological","name":{"fr":"Lésions physiologiques (SSB)","en":"Physiological lesions (SBS)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"torsion-right","name":{"fr":"Torsion droite","en":"Right torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"torsion-left","name":{"fr":"Torsion gauche","en":"Left torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"post-trauma-head","name":{"fr":"Suite de traumatisme crânien","en":"Post head trauma"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]}]}$fixture$::jsonb)) as c order by c collate "C"), - '{reference.id.duplicate}'::text[], - 'conformance reference-id-duplicate: a reference declared twice' -); - -select is( - array(select c from unnest(private.sheet_document_issues($fixture${"schema_version":2,"species_id":"equine","name":{"fr":"Cheval (extrait)","en":"Horse (slice)"},"description":{"fr":"Extrait de la fiche équine pour les tests du modèle","en":"Equine sheet slice for model tests"},"scope_disclaimer":{"fr":"Les éléments listés correspondent au périmètre légal de l'ostéopathie animale : dysfonctions ostéopathiques palpées, observations cliniques et motifs de consultation. Aucun diagnostic médical n'est posé. Toute pathologie organique relève du vétérinaire."},"attribution":{"authors":["Faunosteo"],"license":"MIT","notes":null},"vertebral_config":{"regions":[{"code":"C","name":{"fr":"Cervicales","en":"Cervical"},"count":7,"count_range":null},{"code":"T","name":{"fr":"Thoraciques","en":"Thoracic"},"count":18,"count_range":null},{"code":"L","name":{"fr":"Lombaires","en":"Lumbar"},"count":6,"count_range":null},{"code":"S","name":{"fr":"Sacrées","en":"Sacral"},"count":5,"count_range":null},{"code":"Cd","name":{"fr":"Caudales","en":"Caudal"},"count":18,"count_range":{"min":15,"max":21}},{"code":"C","name":{"fr":"Cervicales","en":"Cervical"},"count":7,"count_range":null}]},"references":[{"id":"legacy-catalog","type":"manual","citation":"Legacy equine catalog (pathologies.json, schema 2.0)","url":null,"doi":null}],"categories":[{"id":"articulations","name":{"fr":"Articulations","en":"Joints"},"color":"#ff9500"},{"id":"zone-colonne","name":{"fr":"Zone colonne","en":"Spine zone"},"color":"#e100ff"},{"id":"charnieres-vertebrales","name":{"fr":"Charnières vertébrales","en":"Vertebral junctions"},"color":"#ff0000"},{"id":"cadrans-du-crane","name":{"fr":"Cadrans du crâne","en":"Skull quadrants"},"color":"#1baa08"}],"views":[{"id":"view-main","name":{"fr":"Cheval entier","en":"Whole horse"},"svg_asset_id":"3f6c1b52-8a4e-4d17-9b0c-5e2a7d91c4f8","view_box":null,"kind":"main"},{"id":"view-head","name":{"fr":"Tête","en":"Head"},"svg_asset_id":null,"view_box":{"min_x":60,"min_y":100,"width":500,"height":380},"kind":"detail","parent_view_id":"view-main"}],"annotations":[{"id":"hip","view_id":"view-main","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":1516,"cy":695,"r":34},"review_status":"inherited","color":null,"name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"finding_zone_id":"hip","vertebral_region_code":null,"kind":"point"},{"id":"cervical-vertebrae","view_id":"view-main","category_id":"zone-colonne","laterality":"unpaired","geometry":{"type":"polygon","points":[[468,276],[489,216],[558,248],[586,339],[552,461],[524,370]]},"review_status":"inherited","color":null,"name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"finding_zone_id":"cervical","vertebral_region_code":"C","kind":"zone"},{"id":"hinge-c7-t1","view_id":"view-main","category_id":"charnieres-vertebrales","laterality":"unpaired","geometry":{"type":"circle","cx":840.17,"cy":399.08,"r":30},"review_status":"inherited","color":null,"name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"finding_zone_id":"c7-t1","vertebral_region_code":null,"kind":"point"},{"id":"head-trigger","view_id":"view-main","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"polygon","points":[[454,332],[429,202],[349,154],[234,279],[164,384],[234,468]]},"review_status":"inherited","color":null,"kind":"detail_trigger","name":null,"opens_view_id":"view-head"},{"id":"atm","view_id":"view-head","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":384.94,"cy":314.02,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"finding_zone_id":"atm","vertebral_region_code":null,"kind":"point"},{"id":"sphenoid","view_id":"view-head","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"circle","cx":299,"cy":298,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Sphénoïde","en":"Sphenoid"},"finding_zone_id":"sphenoid","vertebral_region_code":null,"kind":"point"}],"finding_zones":[{"id":"hip","name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"categories":[{"id":"hip-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"articular","name":{"fr":"Restrictions de mobilité articulaire","en":"Articular mobility restrictions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-flexion","name":{"fr":"Restriction en flexion","en":"Flexion restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"restriction-extension","name":{"fr":"Restriction en extension","en":"Extension restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"hip-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"limb-lameness","name":{"fr":"Boiterie rapportée (membre concerné)","en":"Reported lameness (affected limb)"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":["legacy-catalog"],"review_status":"inherited","children":[]}]}]},{"id":"cervical","name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"categories":[{"id":"cervical-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"muscular","name":{"fr":"Tensions musculaires paravertébrales","en":"Paravertebral muscle tensions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"splenius-tension","name":{"fr":"Tension du splénius","en":"Splenius tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"cervical-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"stumbling-proprioceptive","name":{"fr":"Trébuchements / déficit proprioceptif rapporté","en":"Reported stumbling / proprioceptive deficit"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"c7-t1","name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"categories":[{"id":"c7-t1-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-rotation","name":{"fr":"Restriction en rotation","en":"Rotation restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"c7-t1-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"base-neck-stiffness","name":{"fr":"Raideur de la base de l'encolure","en":"Base-of-neck stiffness"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"atm","name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"categories":[{"id":"atm-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques de l'ATM","en":"Osteopathic TMJ dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"masseter-tension","name":{"fr":"Tension du masséter","en":"Masseter tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"atm-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"bit-defense","name":{"fr":"Réactions de défense au mors","en":"Defense reactions to bit"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"dental-context","name":{"fr":"Suite de soin dentaire récent","en":"Post recent dental care"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid","name":{"fr":"Sphénoïde","en":"Sphenoid"},"categories":[{"id":"ssb-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"physiological","name":{"fr":"Lésions physiologiques (SSB)","en":"Physiological lesions (SBS)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"torsion-right","name":{"fr":"Torsion droite","en":"Right torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"torsion-left","name":{"fr":"Torsion gauche","en":"Left torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"post-trauma-head","name":{"fr":"Suite de traumatisme crânien","en":"Post head trauma"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]}]}$fixture$::jsonb)) as c order by c collate "C"), - '{region.code.duplicate}'::text[], - 'conformance region-code-duplicate: a vertebral region listed twice' -); - -select is( - array(select c from unnest(private.sheet_document_issues($fixture${"schema_version":2,"species_id":"equine","name":{"fr":"Cheval (extrait)","en":"Horse (slice)"},"description":{"fr":"Extrait de la fiche équine pour les tests du modèle","en":"Equine sheet slice for model tests"},"scope_disclaimer":{"fr":"Les éléments listés correspondent au périmètre légal de l'ostéopathie animale : dysfonctions ostéopathiques palpées, observations cliniques et motifs de consultation. Aucun diagnostic médical n'est posé. Toute pathologie organique relève du vétérinaire."},"attribution":{"authors":["Faunosteo"],"license":"MIT","notes":null},"vertebral_config":{"regions":[{"code":"C","name":{"fr":"Cervicales","en":"Cervical"},"count":7,"count_range":null},{"code":"T","name":{"fr":"Thoraciques","en":"Thoracic"},"count":18,"count_range":null},{"code":"L","name":{"fr":"Lombaires","en":"Lumbar"},"count":6,"count_range":null},{"code":"S","name":{"fr":"Sacrées","en":"Sacral"},"count":5,"count_range":null},{"code":"Cd","name":{"fr":"Caudales","en":"Caudal"},"count":18,"count_range":{"min":19,"max":21}}]},"references":[{"id":"legacy-catalog","type":"manual","citation":"Legacy equine catalog (pathologies.json, schema 2.0)","url":null,"doi":null}],"categories":[{"id":"articulations","name":{"fr":"Articulations","en":"Joints"},"color":"#ff9500"},{"id":"zone-colonne","name":{"fr":"Zone colonne","en":"Spine zone"},"color":"#e100ff"},{"id":"charnieres-vertebrales","name":{"fr":"Charnières vertébrales","en":"Vertebral junctions"},"color":"#ff0000"},{"id":"cadrans-du-crane","name":{"fr":"Cadrans du crâne","en":"Skull quadrants"},"color":"#1baa08"}],"views":[{"id":"view-main","name":{"fr":"Cheval entier","en":"Whole horse"},"svg_asset_id":"3f6c1b52-8a4e-4d17-9b0c-5e2a7d91c4f8","view_box":null,"kind":"main"},{"id":"view-head","name":{"fr":"Tête","en":"Head"},"svg_asset_id":null,"view_box":{"min_x":60,"min_y":100,"width":500,"height":380},"kind":"detail","parent_view_id":"view-main"}],"annotations":[{"id":"hip","view_id":"view-main","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":1516,"cy":695,"r":34},"review_status":"inherited","color":null,"name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"finding_zone_id":"hip","vertebral_region_code":null,"kind":"point"},{"id":"cervical-vertebrae","view_id":"view-main","category_id":"zone-colonne","laterality":"unpaired","geometry":{"type":"polygon","points":[[468,276],[489,216],[558,248],[586,339],[552,461],[524,370]]},"review_status":"inherited","color":null,"name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"finding_zone_id":"cervical","vertebral_region_code":"C","kind":"zone"},{"id":"hinge-c7-t1","view_id":"view-main","category_id":"charnieres-vertebrales","laterality":"unpaired","geometry":{"type":"circle","cx":840.17,"cy":399.08,"r":30},"review_status":"inherited","color":null,"name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"finding_zone_id":"c7-t1","vertebral_region_code":null,"kind":"point"},{"id":"head-trigger","view_id":"view-main","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"polygon","points":[[454,332],[429,202],[349,154],[234,279],[164,384],[234,468]]},"review_status":"inherited","color":null,"kind":"detail_trigger","name":null,"opens_view_id":"view-head"},{"id":"atm","view_id":"view-head","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":384.94,"cy":314.02,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"finding_zone_id":"atm","vertebral_region_code":null,"kind":"point"},{"id":"sphenoid","view_id":"view-head","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"circle","cx":299,"cy":298,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Sphénoïde","en":"Sphenoid"},"finding_zone_id":"sphenoid","vertebral_region_code":null,"kind":"point"}],"finding_zones":[{"id":"hip","name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"categories":[{"id":"hip-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"articular","name":{"fr":"Restrictions de mobilité articulaire","en":"Articular mobility restrictions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-flexion","name":{"fr":"Restriction en flexion","en":"Flexion restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"restriction-extension","name":{"fr":"Restriction en extension","en":"Extension restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"hip-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"limb-lameness","name":{"fr":"Boiterie rapportée (membre concerné)","en":"Reported lameness (affected limb)"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":["legacy-catalog"],"review_status":"inherited","children":[]}]}]},{"id":"cervical","name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"categories":[{"id":"cervical-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"muscular","name":{"fr":"Tensions musculaires paravertébrales","en":"Paravertebral muscle tensions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"splenius-tension","name":{"fr":"Tension du splénius","en":"Splenius tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"cervical-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"stumbling-proprioceptive","name":{"fr":"Trébuchements / déficit proprioceptif rapporté","en":"Reported stumbling / proprioceptive deficit"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"c7-t1","name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"categories":[{"id":"c7-t1-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-rotation","name":{"fr":"Restriction en rotation","en":"Rotation restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"c7-t1-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"base-neck-stiffness","name":{"fr":"Raideur de la base de l'encolure","en":"Base-of-neck stiffness"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"atm","name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"categories":[{"id":"atm-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques de l'ATM","en":"Osteopathic TMJ dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"masseter-tension","name":{"fr":"Tension du masséter","en":"Masseter tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"atm-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"bit-defense","name":{"fr":"Réactions de défense au mors","en":"Defense reactions to bit"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"dental-context","name":{"fr":"Suite de soin dentaire récent","en":"Post recent dental care"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid","name":{"fr":"Sphénoïde","en":"Sphenoid"},"categories":[{"id":"ssb-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"physiological","name":{"fr":"Lésions physiologiques (SSB)","en":"Physiological lesions (SBS)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"torsion-right","name":{"fr":"Torsion droite","en":"Right torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"torsion-left","name":{"fr":"Torsion gauche","en":"Left torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"post-trauma-head","name":{"fr":"Suite de traumatisme crânien","en":"Post head trauma"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]}]}$fixture$::jsonb)) as c order by c collate "C"), - '{region.count_range.invalid}'::text[], - 'conformance region-count-range-invalid: a usual vertebra count outside its documented range' -); - -select is( - array(select c from unnest(private.sheet_document_issues($fixture${"schema_version":2,"species_id":"equine","name":{"fr":"Cheval (extrait)","en":"Horse (slice)"},"description":{"fr":"Extrait de la fiche équine pour les tests du modèle","en":"Equine sheet slice for model tests"},"scope_disclaimer":{"fr":"Les éléments listés correspondent au périmètre légal de l'ostéopathie animale : dysfonctions ostéopathiques palpées, observations cliniques et motifs de consultation. Aucun diagnostic médical n'est posé. Toute pathologie organique relève du vétérinaire."},"attribution":{"authors":["Faunosteo"],"license":"MIT","notes":null},"vertebral_config":{"regions":[{"code":"C","name":{"fr":"Cervicales","en":"Cervical"},"count":7,"count_range":null},{"code":"T","name":{"fr":"Thoraciques","en":"Thoracic"},"count":18,"count_range":null},{"code":"L","name":{"fr":"Lombaires","en":"Lumbar"},"count":6,"count_range":null},{"code":"S","name":{"fr":"Sacrées","en":"Sacral"},"count":5,"count_range":null},{"code":"Cd","name":{"fr":"Caudales","en":"Caudal"},"count":18,"count_range":{"min":19,"max":21}}]},"references":[{"id":"legacy-catalog","type":"manual","citation":"Legacy equine catalog (pathologies.json, schema 2.0)","url":null,"doi":null}],"categories":[{"id":"articulations","name":{"fr":"Articulations","en":"Joints"},"color":"#ff9500"},{"id":"zone-colonne","name":{"fr":"Zone colonne","en":"Spine zone"},"color":"#e100ff"},{"id":"charnieres-vertebrales","name":{"fr":"Charnières vertébrales","en":"Vertebral junctions"},"color":"#ff0000"},{"id":"cadrans-du-crane","name":{"fr":"Cadrans du crâne","en":"Skull quadrants"},"color":"#1baa08"}],"views":[{"id":"view-main","name":{"fr":"Cheval entier","en":"Whole horse"},"svg_asset_id":null,"view_box":null,"kind":"main"},{"id":"view-head","name":{"fr":"Tête","en":"Head"},"svg_asset_id":null,"view_box":{"min_x":60,"min_y":100,"width":500,"height":380},"kind":"detail","parent_view_id":"view-main"}],"annotations":[{"id":"hip","view_id":"view-main","category_id":"os","laterality":"bilateral","geometry":{"type":"circle","cx":1516,"cy":695,"r":34},"review_status":"inherited","color":null,"name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"finding_zone_id":"hip","vertebral_region_code":null,"kind":"point"},{"id":"cervical-vertebrae","view_id":"view-main","category_id":"zone-colonne","laterality":"unpaired","geometry":{"type":"polygon","points":[[468,276],[489,216],[558,248],[586,339],[552,461],[524,370]]},"review_status":"inherited","color":null,"name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"finding_zone_id":"cervical","vertebral_region_code":"C","kind":"zone"},{"id":"hinge-c7-t1","view_id":"view-main","category_id":"os","laterality":"unpaired","geometry":{"type":"circle","cx":840.17,"cy":399.08,"r":30},"review_status":"inherited","color":null,"name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"finding_zone_id":"c7-t1","vertebral_region_code":null,"kind":"point"},{"id":"head-trigger","view_id":"view-main","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"polygon","points":[[454,332],[429,202],[349,154],[234,279],[164,384],[234,468]]},"review_status":"inherited","color":null,"kind":"detail_trigger","name":null,"opens_view_id":"view-head"},{"id":"atm","view_id":"view-head","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":384.94,"cy":314.02,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"finding_zone_id":"atm","vertebral_region_code":null,"kind":"point"},{"id":"sphenoid","view_id":"view-head","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"circle","cx":299,"cy":298,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Sphénoïde","en":"Sphenoid"},"finding_zone_id":"sphenoid","vertebral_region_code":null,"kind":"point"}],"finding_zones":[{"id":"hip","name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"categories":[{"id":"hip-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"articular","name":{"fr":"Restrictions de mobilité articulaire","en":"Articular mobility restrictions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-flexion","name":{"fr":"Restriction en flexion","en":"Flexion restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"restriction-extension","name":{"fr":"Restriction en extension","en":"Extension restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"hip-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"limb-lameness","name":{"fr":"Boiterie rapportée (membre concerné)","en":"Reported lameness (affected limb)"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":["legacy-catalog"],"review_status":"inherited","children":[]}]}]},{"id":"cervical","name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"categories":[{"id":"cervical-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"muscular","name":{"fr":"Tensions musculaires paravertébrales","en":"Paravertebral muscle tensions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"splenius-tension","name":{"fr":"Tension du splénius","en":"Splenius tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"cervical-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"stumbling-proprioceptive","name":{"fr":"Trébuchements / déficit proprioceptif rapporté","en":"Reported stumbling / proprioceptive deficit"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"c7-t1","name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"categories":[{"id":"c7-t1-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-rotation","name":{"fr":"Restriction en rotation","en":"Rotation restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"c7-t1-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"base-neck-stiffness","name":{"fr":"Raideur de la base de l'encolure","en":"Base-of-neck stiffness"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"atm","name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"categories":[{"id":"atm-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques de l'ATM","en":"Osteopathic TMJ dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"masseter-tension","name":{"fr":"Tension du masséter","en":"Masseter tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"atm-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"bit-defense","name":{"fr":"Réactions de défense au mors","en":"Defense reactions to bit"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"dental-context","name":{"fr":"Suite de soin dentaire récent","en":"Post recent dental care"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid","name":{"fr":"Sphénoïde","en":"Sphenoid"},"categories":[{"id":"ssb-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"physiological","name":{"fr":"Lésions physiologiques (SSB)","en":"Physiological lesions (SBS)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"torsion-right","name":{"fr":"Torsion droite","en":"Right torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"torsion-left","name":{"fr":"Torsion gauche","en":"Left torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"post-trauma-head","name":{"fr":"Suite de traumatisme crânien","en":"Post head trauma"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]}]}$fixture$::jsonb)) as c order by c collate "C"), - '{annotation.category.missing,region.count_range.invalid,view.asset.missing}'::text[], - 'conformance several-errors: errors of four families at once, duplicates of one code collapsed by SQL' -); - -select is( - array(select c from unnest(private.sheet_document_issues($fixture${"schema_version":2,"species_id":"equine","name":{"fr":"Cheval (extrait)","en":"Horse (slice)"},"description":{"fr":"Extrait de la fiche équine pour les tests du modèle","en":"Equine sheet slice for model tests"},"scope_disclaimer":{"fr":"Les éléments listés correspondent au périmètre légal de l'ostéopathie animale : dysfonctions ostéopathiques palpées, observations cliniques et motifs de consultation. Aucun diagnostic médical n'est posé. Toute pathologie organique relève du vétérinaire."},"attribution":{"authors":["Faunosteo"],"license":"MIT","notes":null},"vertebral_config":{"regions":[{"code":"C","name":{"fr":"Cervicales","en":"Cervical"},"count":7,"count_range":null},{"code":"T","name":{"fr":"Thoraciques","en":"Thoracic"},"count":18,"count_range":null},{"code":"L","name":{"fr":"Lombaires","en":"Lumbar"},"count":6,"count_range":null},{"code":"S","name":{"fr":"Sacrées","en":"Sacral"},"count":5,"count_range":null},{"code":"Cd","name":{"fr":"Caudales","en":"Caudal"},"count":18,"count_range":{"min":15,"max":21}}]},"references":[{"id":"legacy-catalog","type":"manual","citation":"Legacy equine catalog (pathologies.json, schema 2.0)","url":"javascript:alert(1)","doi":null}],"categories":[{"id":"articulations","name":{"fr":"Articulations","en":"Joints"},"color":"#ff9500"},{"id":"zone-colonne","name":{"fr":"Zone colonne","en":"Spine zone"},"color":"#e100ff"},{"id":"charnieres-vertebrales","name":{"fr":"Charnières vertébrales","en":"Vertebral junctions"},"color":"#ff0000"},{"id":"cadrans-du-crane","name":{"fr":"Cadrans du crâne","en":"Skull quadrants"},"color":"#1baa08"}],"views":[{"id":"view-main","name":{"fr":"Cheval entier","en":"Whole horse"},"svg_asset_id":"3f6c1b52-8a4e-4d17-9b0c-5e2a7d91c4f8","view_box":null,"kind":"main"},{"id":"view-head","name":{"fr":"Tête","en":"Head"},"svg_asset_id":null,"view_box":{"min_x":60,"min_y":100,"width":500,"height":380},"kind":"detail","parent_view_id":"view-main"}],"annotations":[{"id":"hip","view_id":"view-main","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":1516,"cy":695,"r":34},"review_status":"inherited","color":null,"name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"finding_zone_id":"hip","vertebral_region_code":null,"kind":"point"},{"id":"cervical-vertebrae","view_id":"view-main","category_id":"zone-colonne","laterality":"unpaired","geometry":{"type":"polygon","points":[[468,276],[489,216],[558,248],[586,339],[552,461],[524,370]]},"review_status":"inherited","color":null,"name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"finding_zone_id":"cervical","vertebral_region_code":"C","kind":"zone"},{"id":"hinge-c7-t1","view_id":"view-main","category_id":"charnieres-vertebrales","laterality":"unpaired","geometry":{"type":"circle","cx":840.17,"cy":399.08,"r":30},"review_status":"inherited","color":null,"name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"finding_zone_id":"c7-t1","vertebral_region_code":null,"kind":"point"},{"id":"head-trigger","view_id":"view-main","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"polygon","points":[[454,332],[429,202],[349,154],[234,279],[164,384],[234,468]]},"review_status":"inherited","color":null,"kind":"detail_trigger","name":null,"opens_view_id":"view-head"},{"id":"atm","view_id":"view-head","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":384.94,"cy":314.02,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"finding_zone_id":"atm","vertebral_region_code":null,"kind":"point"},{"id":"sphenoid","view_id":"view-head","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"circle","cx":299,"cy":298,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Sphénoïde","en":"Sphenoid"},"finding_zone_id":"sphenoid","vertebral_region_code":null,"kind":"point"}],"finding_zones":[{"id":"hip","name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"categories":[{"id":"hip-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"articular","name":{"fr":"Restrictions de mobilité articulaire","en":"Articular mobility restrictions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-flexion","name":{"fr":"Restriction en flexion","en":"Flexion restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"restriction-extension","name":{"fr":"Restriction en extension","en":"Extension restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"hip-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"limb-lameness","name":{"fr":"Boiterie rapportée (membre concerné)","en":"Reported lameness (affected limb)"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":["legacy-catalog"],"review_status":"inherited","children":[]}]}]},{"id":"cervical","name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"categories":[{"id":"cervical-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"muscular","name":{"fr":"Tensions musculaires paravertébrales","en":"Paravertebral muscle tensions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"splenius-tension","name":{"fr":"Tension du splénius","en":"Splenius tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"cervical-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"stumbling-proprioceptive","name":{"fr":"Trébuchements / déficit proprioceptif rapporté","en":"Reported stumbling / proprioceptive deficit"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"c7-t1","name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"categories":[{"id":"c7-t1-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-rotation","name":{"fr":"Restriction en rotation","en":"Rotation restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"c7-t1-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"base-neck-stiffness","name":{"fr":"Raideur de la base de l'encolure","en":"Base-of-neck stiffness"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"atm","name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"categories":[{"id":"atm-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques de l'ATM","en":"Osteopathic TMJ dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"masseter-tension","name":{"fr":"Tension du masséter","en":"Masseter tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"atm-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"bit-defense","name":{"fr":"Réactions de défense au mors","en":"Defense reactions to bit"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"dental-context","name":{"fr":"Suite de soin dentaire récent","en":"Post recent dental care"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid","name":{"fr":"Sphénoïde","en":"Sphenoid"},"categories":[{"id":"ssb-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"physiological","name":{"fr":"Lésions physiologiques (SSB)","en":"Physiological lesions (SBS)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"torsion-right","name":{"fr":"Torsion droite","en":"Right torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"torsion-left","name":{"fr":"Torsion gauche","en":"Left torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"post-trauma-head","name":{"fr":"Suite de traumatisme crânien","en":"Post head trauma"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]}]}$fixture$::jsonb)) as c order by c collate "C"), - '{reference.url.scheme}'::text[], - 'conformance shape-reference-url-scheme: a javascript: reference url: the shape tier refuses it, SQL says reference.url.scheme' -); - -select is( - array(select c from unnest(private.sheet_document_issues($fixture${"schema_version":2,"species_id":"equine","name":{"fr":"Cheval (extrait)","en":"Horse (slice)"},"description":{"fr":"Extrait de la fiche équine pour les tests du modèle","en":"Equine sheet slice for model tests"},"scope_disclaimer":{"fr":"Les éléments listés correspondent au périmètre légal de l'ostéopathie animale : dysfonctions ostéopathiques palpées, observations cliniques et motifs de consultation. Aucun diagnostic médical n'est posé. Toute pathologie organique relève du vétérinaire."},"attribution":{"authors":["Faunosteo"],"license":"MIT","notes":null},"vertebral_config":{"regions":[{"code":"C","name":{"fr":"Cervicales","en":"Cervical"},"count":7,"count_range":null},{"code":"T","name":{"fr":"Thoraciques","en":"Thoracic"},"count":18,"count_range":null},{"code":"L","name":{"fr":"Lombaires","en":"Lumbar"},"count":6,"count_range":null},{"code":"S","name":{"fr":"Sacrées","en":"Sacral"},"count":5,"count_range":null},{"code":"Cd","name":{"fr":"Caudales","en":"Caudal"},"count":18,"count_range":{"min":15,"max":21}}]},"references":"x","categories":[{"id":"articulations","name":{"fr":"Articulations","en":"Joints"},"color":"#ff9500"},{"id":"zone-colonne","name":{"fr":"Zone colonne","en":"Spine zone"},"color":"#e100ff"},{"id":"charnieres-vertebrales","name":{"fr":"Charnières vertébrales","en":"Vertebral junctions"},"color":"#ff0000"},{"id":"cadrans-du-crane","name":{"fr":"Cadrans du crâne","en":"Skull quadrants"},"color":"#1baa08"}],"views":[{"id":"view-main","name":{"fr":"Cheval entier","en":"Whole horse"},"svg_asset_id":"3f6c1b52-8a4e-4d17-9b0c-5e2a7d91c4f8","view_box":null,"kind":"main"},{"id":"view-head","name":{"fr":"Tête","en":"Head"},"svg_asset_id":null,"view_box":{"min_x":60,"min_y":100,"width":500,"height":380},"kind":"detail","parent_view_id":"view-main"}],"annotations":[{"id":"hip","view_id":"view-main","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":1516,"cy":695,"r":34},"review_status":"inherited","color":null,"name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"finding_zone_id":"hip","vertebral_region_code":null,"kind":"point"},{"id":"cervical-vertebrae","view_id":"view-main","category_id":"zone-colonne","laterality":"unpaired","geometry":{"type":"polygon","points":[[468,276],[489,216],[558,248],[586,339],[552,461],[524,370]]},"review_status":"inherited","color":null,"name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"finding_zone_id":"cervical","vertebral_region_code":"C","kind":"zone"},{"id":"hinge-c7-t1","view_id":"view-main","category_id":"charnieres-vertebrales","laterality":"unpaired","geometry":{"type":"circle","cx":840.17,"cy":399.08,"r":30},"review_status":"inherited","color":null,"name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"finding_zone_id":"c7-t1","vertebral_region_code":null,"kind":"point"},{"id":"head-trigger","view_id":"view-main","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"polygon","points":[[454,332],[429,202],[349,154],[234,279],[164,384],[234,468]]},"review_status":"inherited","color":null,"kind":"detail_trigger","name":null,"opens_view_id":"view-head"},{"id":"atm","view_id":"view-head","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":384.94,"cy":314.02,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"finding_zone_id":"atm","vertebral_region_code":null,"kind":"point"},{"id":"sphenoid","view_id":"view-head","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"circle","cx":299,"cy":298,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Sphénoïde","en":"Sphenoid"},"finding_zone_id":"sphenoid","vertebral_region_code":null,"kind":"point"}],"finding_zones":[{"id":"hip","name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"categories":[{"id":"hip-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"articular","name":{"fr":"Restrictions de mobilité articulaire","en":"Articular mobility restrictions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-flexion","name":{"fr":"Restriction en flexion","en":"Flexion restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"restriction-extension","name":{"fr":"Restriction en extension","en":"Extension restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"hip-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"limb-lameness","name":{"fr":"Boiterie rapportée (membre concerné)","en":"Reported lameness (affected limb)"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":["legacy-catalog"],"review_status":"inherited","children":[]}]}]},{"id":"cervical","name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"categories":[{"id":"cervical-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"muscular","name":{"fr":"Tensions musculaires paravertébrales","en":"Paravertebral muscle tensions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"splenius-tension","name":{"fr":"Tension du splénius","en":"Splenius tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"cervical-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"stumbling-proprioceptive","name":{"fr":"Trébuchements / déficit proprioceptif rapporté","en":"Reported stumbling / proprioceptive deficit"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"c7-t1","name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"categories":[{"id":"c7-t1-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-rotation","name":{"fr":"Restriction en rotation","en":"Rotation restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"c7-t1-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"base-neck-stiffness","name":{"fr":"Raideur de la base de l'encolure","en":"Base-of-neck stiffness"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"atm","name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"categories":[{"id":"atm-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques de l'ATM","en":"Osteopathic TMJ dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"masseter-tension","name":{"fr":"Tension du masséter","en":"Masseter tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"atm-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"bit-defense","name":{"fr":"Réactions de défense au mors","en":"Defense reactions to bit"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"dental-context","name":{"fr":"Suite de soin dentaire récent","en":"Post recent dental care"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid","name":{"fr":"Sphénoïde","en":"Sphenoid"},"categories":[{"id":"ssb-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"physiological","name":{"fr":"Lésions physiologiques (SSB)","en":"Physiological lesions (SBS)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"torsion-right","name":{"fr":"Torsion droite","en":"Right torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"torsion-left","name":{"fr":"Torsion gauche","en":"Left torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"post-trauma-head","name":{"fr":"Suite de traumatisme crânien","en":"Post head trauma"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]}]}$fixture$::jsonb)) as c order by c collate "C"), - '{document.shape}'::text[], - 'conformance shape-references-not-array: a non-array references registry: the shape tier refuses it, SQL says document.shape' -); - -select is( - array(select c from unnest(private.sheet_document_issues($fixture${"schema_version":2,"species_id":"equine","name":{"fr":"Cheval (extrait)","en":"Horse (slice)"},"description":{"fr":"Extrait de la fiche équine pour les tests du modèle","en":"Equine sheet slice for model tests"},"scope_disclaimer":{"fr":"Les éléments listés correspondent au périmètre légal de l'ostéopathie animale : dysfonctions ostéopathiques palpées, observations cliniques et motifs de consultation. Aucun diagnostic médical n'est posé. Toute pathologie organique relève du vétérinaire."},"attribution":{"authors":["Faunosteo"],"license":"MIT","notes":null},"vertebral_config":{"regions":[{"code":"C","name":{"fr":"Cervicales","en":"Cervical"},"count":7,"count_range":null},{"code":"T","name":{"fr":"Thoraciques","en":"Thoracic"},"count":18,"count_range":null},{"code":"L","name":{"fr":"Lombaires","en":"Lumbar"},"count":6,"count_range":null},{"code":"S","name":{"fr":"Sacrées","en":"Sacral"},"count":5,"count_range":null},{"code":"Cd","name":{"fr":"Caudales","en":"Caudal"},"count":18,"count_range":{"min":15,"max":21}}]},"references":[{"id":"legacy-catalog","type":"manual","citation":"Legacy equine catalog (pathologies.json, schema 2.0)","url":null,"doi":null}],"categories":[{"id":"articulations","name":{"fr":"Articulations","en":"Joints"},"color":"#ff9500"},{"id":"zone-colonne","name":{"fr":"Zone colonne","en":"Spine zone"},"color":"#e100ff"},{"id":"charnieres-vertebrales","name":{"fr":"Charnières vertébrales","en":"Vertebral junctions"},"color":"#ff0000"},{"id":"cadrans-du-crane","name":{"fr":"Cadrans du crâne","en":"Skull quadrants"},"color":"#1baa08"}],"views":[{"id":"view-main","name":{"fr":"Cheval entier","en":"Whole horse"},"svg_asset_id":"3f6c1b52-8a4e-4d17-9b0c-5e2a7d91c4f8","view_box":null,"kind":"main"},{"id":"view-head","name":{"fr":"Tête","en":"Head"},"svg_asset_id":null,"view_box":null,"kind":"detail","parent_view_id":"view-main"}],"annotations":[{"id":"hip","view_id":"view-main","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":1516,"cy":695,"r":34},"review_status":"inherited","color":null,"name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"finding_zone_id":"hip","vertebral_region_code":null,"kind":"point"},{"id":"cervical-vertebrae","view_id":"view-main","category_id":"zone-colonne","laterality":"unpaired","geometry":{"type":"polygon","points":[[468,276],[489,216],[558,248],[586,339],[552,461],[524,370]]},"review_status":"inherited","color":null,"name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"finding_zone_id":"cervical","vertebral_region_code":"C","kind":"zone"},{"id":"hinge-c7-t1","view_id":"view-main","category_id":"charnieres-vertebrales","laterality":"unpaired","geometry":{"type":"circle","cx":840.17,"cy":399.08,"r":30},"review_status":"inherited","color":null,"name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"finding_zone_id":"c7-t1","vertebral_region_code":null,"kind":"point"},{"id":"head-trigger","view_id":"view-main","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"polygon","points":[[454,332],[429,202],[349,154],[234,279],[164,384],[234,468]]},"review_status":"inherited","color":null,"kind":"detail_trigger","name":null,"opens_view_id":"view-head"},{"id":"atm","view_id":"view-head","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":384.94,"cy":314.02,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"finding_zone_id":"atm","vertebral_region_code":null,"kind":"point"},{"id":"sphenoid","view_id":"view-head","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"circle","cx":299,"cy":298,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Sphénoïde","en":"Sphenoid"},"finding_zone_id":"sphenoid","vertebral_region_code":null,"kind":"point"}],"finding_zones":[{"id":"hip","name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"categories":[{"id":"hip-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"articular","name":{"fr":"Restrictions de mobilité articulaire","en":"Articular mobility restrictions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-flexion","name":{"fr":"Restriction en flexion","en":"Flexion restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"restriction-extension","name":{"fr":"Restriction en extension","en":"Extension restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"hip-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"limb-lameness","name":{"fr":"Boiterie rapportée (membre concerné)","en":"Reported lameness (affected limb)"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":["legacy-catalog"],"review_status":"inherited","children":[]}]}]},{"id":"cervical","name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"categories":[{"id":"cervical-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"muscular","name":{"fr":"Tensions musculaires paravertébrales","en":"Paravertebral muscle tensions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"splenius-tension","name":{"fr":"Tension du splénius","en":"Splenius tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"cervical-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"stumbling-proprioceptive","name":{"fr":"Trébuchements / déficit proprioceptif rapporté","en":"Reported stumbling / proprioceptive deficit"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"c7-t1","name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"categories":[{"id":"c7-t1-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-rotation","name":{"fr":"Restriction en rotation","en":"Rotation restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"c7-t1-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"base-neck-stiffness","name":{"fr":"Raideur de la base de l'encolure","en":"Base-of-neck stiffness"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"atm","name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"categories":[{"id":"atm-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques de l'ATM","en":"Osteopathic TMJ dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"masseter-tension","name":{"fr":"Tension du masséter","en":"Masseter tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"atm-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"bit-defense","name":{"fr":"Réactions de défense au mors","en":"Defense reactions to bit"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"dental-context","name":{"fr":"Suite de soin dentaire récent","en":"Post recent dental care"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid","name":{"fr":"Sphénoïde","en":"Sphenoid"},"categories":[{"id":"ssb-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"physiological","name":{"fr":"Lésions physiologiques (SSB)","en":"Physiological lesions (SBS)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"torsion-right","name":{"fr":"Torsion droite","en":"Right torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"torsion-left","name":{"fr":"Torsion gauche","en":"Left torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"post-trauma-head","name":{"fr":"Suite de traumatisme crânien","en":"Post head trauma"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]}]}$fixture$::jsonb)) as c order by c collate "C"), - '{view.asset.missing}'::text[], - 'conformance view-asset-missing-detail: a detail view with neither an asset nor a view_box' -); - -select is( - array(select c from unnest(private.sheet_document_issues($fixture${"schema_version":2,"species_id":"equine","name":{"fr":"Cheval (extrait)","en":"Horse (slice)"},"description":{"fr":"Extrait de la fiche équine pour les tests du modèle","en":"Equine sheet slice for model tests"},"scope_disclaimer":{"fr":"Les éléments listés correspondent au périmètre légal de l'ostéopathie animale : dysfonctions ostéopathiques palpées, observations cliniques et motifs de consultation. Aucun diagnostic médical n'est posé. Toute pathologie organique relève du vétérinaire."},"attribution":{"authors":["Faunosteo"],"license":"MIT","notes":null},"vertebral_config":{"regions":[{"code":"C","name":{"fr":"Cervicales","en":"Cervical"},"count":7,"count_range":null},{"code":"T","name":{"fr":"Thoraciques","en":"Thoracic"},"count":18,"count_range":null},{"code":"L","name":{"fr":"Lombaires","en":"Lumbar"},"count":6,"count_range":null},{"code":"S","name":{"fr":"Sacrées","en":"Sacral"},"count":5,"count_range":null},{"code":"Cd","name":{"fr":"Caudales","en":"Caudal"},"count":18,"count_range":{"min":15,"max":21}}]},"references":[{"id":"legacy-catalog","type":"manual","citation":"Legacy equine catalog (pathologies.json, schema 2.0)","url":null,"doi":null}],"categories":[{"id":"articulations","name":{"fr":"Articulations","en":"Joints"},"color":"#ff9500"},{"id":"zone-colonne","name":{"fr":"Zone colonne","en":"Spine zone"},"color":"#e100ff"},{"id":"charnieres-vertebrales","name":{"fr":"Charnières vertébrales","en":"Vertebral junctions"},"color":"#ff0000"},{"id":"cadrans-du-crane","name":{"fr":"Cadrans du crâne","en":"Skull quadrants"},"color":"#1baa08"}],"views":[{"id":"view-main","name":{"fr":"Cheval entier","en":"Whole horse"},"svg_asset_id":null,"view_box":null,"kind":"main"},{"id":"view-head","name":{"fr":"Tête","en":"Head"},"svg_asset_id":null,"view_box":{"min_x":60,"min_y":100,"width":500,"height":380},"kind":"detail","parent_view_id":"view-main"}],"annotations":[{"id":"hip","view_id":"view-main","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":1516,"cy":695,"r":34},"review_status":"inherited","color":null,"name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"finding_zone_id":"hip","vertebral_region_code":null,"kind":"point"},{"id":"cervical-vertebrae","view_id":"view-main","category_id":"zone-colonne","laterality":"unpaired","geometry":{"type":"polygon","points":[[468,276],[489,216],[558,248],[586,339],[552,461],[524,370]]},"review_status":"inherited","color":null,"name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"finding_zone_id":"cervical","vertebral_region_code":"C","kind":"zone"},{"id":"hinge-c7-t1","view_id":"view-main","category_id":"charnieres-vertebrales","laterality":"unpaired","geometry":{"type":"circle","cx":840.17,"cy":399.08,"r":30},"review_status":"inherited","color":null,"name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"finding_zone_id":"c7-t1","vertebral_region_code":null,"kind":"point"},{"id":"head-trigger","view_id":"view-main","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"polygon","points":[[454,332],[429,202],[349,154],[234,279],[164,384],[234,468]]},"review_status":"inherited","color":null,"kind":"detail_trigger","name":null,"opens_view_id":"view-head"},{"id":"atm","view_id":"view-head","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":384.94,"cy":314.02,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"finding_zone_id":"atm","vertebral_region_code":null,"kind":"point"},{"id":"sphenoid","view_id":"view-head","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"circle","cx":299,"cy":298,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Sphénoïde","en":"Sphenoid"},"finding_zone_id":"sphenoid","vertebral_region_code":null,"kind":"point"}],"finding_zones":[{"id":"hip","name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"categories":[{"id":"hip-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"articular","name":{"fr":"Restrictions de mobilité articulaire","en":"Articular mobility restrictions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-flexion","name":{"fr":"Restriction en flexion","en":"Flexion restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"restriction-extension","name":{"fr":"Restriction en extension","en":"Extension restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"hip-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"limb-lameness","name":{"fr":"Boiterie rapportée (membre concerné)","en":"Reported lameness (affected limb)"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":["legacy-catalog"],"review_status":"inherited","children":[]}]}]},{"id":"cervical","name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"categories":[{"id":"cervical-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"muscular","name":{"fr":"Tensions musculaires paravertébrales","en":"Paravertebral muscle tensions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"splenius-tension","name":{"fr":"Tension du splénius","en":"Splenius tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"cervical-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"stumbling-proprioceptive","name":{"fr":"Trébuchements / déficit proprioceptif rapporté","en":"Reported stumbling / proprioceptive deficit"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"c7-t1","name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"categories":[{"id":"c7-t1-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-rotation","name":{"fr":"Restriction en rotation","en":"Rotation restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"c7-t1-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"base-neck-stiffness","name":{"fr":"Raideur de la base de l'encolure","en":"Base-of-neck stiffness"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"atm","name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"categories":[{"id":"atm-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques de l'ATM","en":"Osteopathic TMJ dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"masseter-tension","name":{"fr":"Tension du masséter","en":"Masseter tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"atm-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"bit-defense","name":{"fr":"Réactions de défense au mors","en":"Defense reactions to bit"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"dental-context","name":{"fr":"Suite de soin dentaire récent","en":"Post recent dental care"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid","name":{"fr":"Sphénoïde","en":"Sphenoid"},"categories":[{"id":"ssb-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"physiological","name":{"fr":"Lésions physiologiques (SSB)","en":"Physiological lesions (SBS)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"torsion-right","name":{"fr":"Torsion droite","en":"Right torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"torsion-left","name":{"fr":"Torsion gauche","en":"Left torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"post-trauma-head","name":{"fr":"Suite de traumatisme crânien","en":"Post head trauma"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]}]}$fixture$::jsonb)) as c order by c collate "C"), - '{view.asset.missing}'::text[], - 'conformance view-asset-missing-main: the main view without an SVG asset' -); - -select is( - array(select c from unnest(private.sheet_document_issues($fixture${"schema_version":2,"species_id":"equine","name":{"fr":"Cheval (extrait)","en":"Horse (slice)"},"description":{"fr":"Extrait de la fiche équine pour les tests du modèle","en":"Equine sheet slice for model tests"},"scope_disclaimer":{"fr":"Les éléments listés correspondent au périmètre légal de l'ostéopathie animale : dysfonctions ostéopathiques palpées, observations cliniques et motifs de consultation. Aucun diagnostic médical n'est posé. Toute pathologie organique relève du vétérinaire."},"attribution":{"authors":["Faunosteo"],"license":"MIT","notes":null},"vertebral_config":{"regions":[{"code":"C","name":{"fr":"Cervicales","en":"Cervical"},"count":7,"count_range":null},{"code":"T","name":{"fr":"Thoraciques","en":"Thoracic"},"count":18,"count_range":null},{"code":"L","name":{"fr":"Lombaires","en":"Lumbar"},"count":6,"count_range":null},{"code":"S","name":{"fr":"Sacrées","en":"Sacral"},"count":5,"count_range":null},{"code":"Cd","name":{"fr":"Caudales","en":"Caudal"},"count":18,"count_range":{"min":15,"max":21}}]},"references":[{"id":"legacy-catalog","type":"manual","citation":"Legacy equine catalog (pathologies.json, schema 2.0)","url":null,"doi":null}],"categories":[{"id":"articulations","name":{"fr":"Articulations","en":"Joints"},"color":"#ff9500"},{"id":"zone-colonne","name":{"fr":"Zone colonne","en":"Spine zone"},"color":"#e100ff"},{"id":"charnieres-vertebrales","name":{"fr":"Charnières vertébrales","en":"Vertebral junctions"},"color":"#ff0000"},{"id":"cadrans-du-crane","name":{"fr":"Cadrans du crâne","en":"Skull quadrants"},"color":"#1baa08"}],"views":[{"id":"view-main","name":{"fr":"Cheval entier","en":"Whole horse"},"svg_asset_id":"3f6c1b52-8a4e-4d17-9b0c-5e2a7d91c4f8","view_box":null,"kind":"main"},{"id":"view-head","name":{"fr":"Tête","en":"Head"},"svg_asset_id":null,"view_box":{"min_x":60,"min_y":100,"width":500,"height":380},"kind":"detail","parent_view_id":"view-main"},{"id":"view-head","name":{"fr":"Tête","en":"Head"},"svg_asset_id":null,"view_box":{"min_x":60,"min_y":100,"width":500,"height":380},"kind":"detail","parent_view_id":"view-main"}],"annotations":[{"id":"hip","view_id":"view-main","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":1516,"cy":695,"r":34},"review_status":"inherited","color":null,"name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"finding_zone_id":"hip","vertebral_region_code":null,"kind":"point"},{"id":"cervical-vertebrae","view_id":"view-main","category_id":"zone-colonne","laterality":"unpaired","geometry":{"type":"polygon","points":[[468,276],[489,216],[558,248],[586,339],[552,461],[524,370]]},"review_status":"inherited","color":null,"name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"finding_zone_id":"cervical","vertebral_region_code":"C","kind":"zone"},{"id":"hinge-c7-t1","view_id":"view-main","category_id":"charnieres-vertebrales","laterality":"unpaired","geometry":{"type":"circle","cx":840.17,"cy":399.08,"r":30},"review_status":"inherited","color":null,"name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"finding_zone_id":"c7-t1","vertebral_region_code":null,"kind":"point"},{"id":"head-trigger","view_id":"view-main","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"polygon","points":[[454,332],[429,202],[349,154],[234,279],[164,384],[234,468]]},"review_status":"inherited","color":null,"kind":"detail_trigger","name":null,"opens_view_id":"view-head"},{"id":"atm","view_id":"view-head","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":384.94,"cy":314.02,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"finding_zone_id":"atm","vertebral_region_code":null,"kind":"point"},{"id":"sphenoid","view_id":"view-head","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"circle","cx":299,"cy":298,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Sphénoïde","en":"Sphenoid"},"finding_zone_id":"sphenoid","vertebral_region_code":null,"kind":"point"}],"finding_zones":[{"id":"hip","name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"categories":[{"id":"hip-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"articular","name":{"fr":"Restrictions de mobilité articulaire","en":"Articular mobility restrictions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-flexion","name":{"fr":"Restriction en flexion","en":"Flexion restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"restriction-extension","name":{"fr":"Restriction en extension","en":"Extension restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"hip-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"limb-lameness","name":{"fr":"Boiterie rapportée (membre concerné)","en":"Reported lameness (affected limb)"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":["legacy-catalog"],"review_status":"inherited","children":[]}]}]},{"id":"cervical","name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"categories":[{"id":"cervical-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"muscular","name":{"fr":"Tensions musculaires paravertébrales","en":"Paravertebral muscle tensions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"splenius-tension","name":{"fr":"Tension du splénius","en":"Splenius tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"cervical-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"stumbling-proprioceptive","name":{"fr":"Trébuchements / déficit proprioceptif rapporté","en":"Reported stumbling / proprioceptive deficit"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"c7-t1","name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"categories":[{"id":"c7-t1-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-rotation","name":{"fr":"Restriction en rotation","en":"Rotation restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"c7-t1-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"base-neck-stiffness","name":{"fr":"Raideur de la base de l'encolure","en":"Base-of-neck stiffness"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"atm","name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"categories":[{"id":"atm-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques de l'ATM","en":"Osteopathic TMJ dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"masseter-tension","name":{"fr":"Tension du masséter","en":"Masseter tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"atm-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"bit-defense","name":{"fr":"Réactions de défense au mors","en":"Defense reactions to bit"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"dental-context","name":{"fr":"Suite de soin dentaire récent","en":"Post recent dental care"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid","name":{"fr":"Sphénoïde","en":"Sphenoid"},"categories":[{"id":"ssb-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"physiological","name":{"fr":"Lésions physiologiques (SSB)","en":"Physiological lesions (SBS)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"torsion-right","name":{"fr":"Torsion droite","en":"Right torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"torsion-left","name":{"fr":"Torsion gauche","en":"Left torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"post-trauma-head","name":{"fr":"Suite de traumatisme crânien","en":"Post head trauma"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]}]}$fixture$::jsonb)) as c order by c collate "C"), - '{view.id.duplicate}'::text[], - 'conformance view-id-duplicate: a detail view listed twice' -); - -select is( - array(select c from unnest(private.sheet_document_issues($fixture${"schema_version":2,"species_id":"equine","name":{"fr":"Cheval (extrait)","en":"Horse (slice)"},"description":{"fr":"Extrait de la fiche équine pour les tests du modèle","en":"Equine sheet slice for model tests"},"scope_disclaimer":{"fr":"Les éléments listés correspondent au périmètre légal de l'ostéopathie animale : dysfonctions ostéopathiques palpées, observations cliniques et motifs de consultation. Aucun diagnostic médical n'est posé. Toute pathologie organique relève du vétérinaire."},"attribution":{"authors":["Faunosteo"],"license":"MIT","notes":null},"vertebral_config":{"regions":[{"code":"C","name":{"fr":"Cervicales","en":"Cervical"},"count":7,"count_range":null},{"code":"T","name":{"fr":"Thoraciques","en":"Thoracic"},"count":18,"count_range":null},{"code":"L","name":{"fr":"Lombaires","en":"Lumbar"},"count":6,"count_range":null},{"code":"S","name":{"fr":"Sacrées","en":"Sacral"},"count":5,"count_range":null},{"code":"Cd","name":{"fr":"Caudales","en":"Caudal"},"count":18,"count_range":{"min":15,"max":21}}]},"references":[{"id":"legacy-catalog","type":"manual","citation":"Legacy equine catalog (pathologies.json, schema 2.0)","url":null,"doi":null}],"categories":[{"id":"articulations","name":{"fr":"Articulations","en":"Joints"},"color":"#ff9500"},{"id":"zone-colonne","name":{"fr":"Zone colonne","en":"Spine zone"},"color":"#e100ff"},{"id":"charnieres-vertebrales","name":{"fr":"Charnières vertébrales","en":"Vertebral junctions"},"color":"#ff0000"},{"id":"cadrans-du-crane","name":{"fr":"Cadrans du crâne","en":"Skull quadrants"},"color":"#1baa08"}],"views":[{"id":"view-main","name":{"fr":"Cheval entier","en":"Whole horse"},"svg_asset_id":"3f6c1b52-8a4e-4d17-9b0c-5e2a7d91c4f8","view_box":null,"kind":"main"},{"id":"view-head","name":{"fr":"Tête","en":"Head"},"svg_asset_id":null,"view_box":{"min_x":60,"min_y":100,"width":500,"height":380},"kind":"detail","parent_view_id":"view-main"},{"id":"view-alt","name":{"fr":"Cheval entier","en":"Whole horse"},"svg_asset_id":"3f6c1b52-8a4e-4d17-9b0c-5e2a7d91c4f8","view_box":null,"kind":"main"}],"annotations":[{"id":"hip","view_id":"view-main","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":1516,"cy":695,"r":34},"review_status":"inherited","color":null,"name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"finding_zone_id":"hip","vertebral_region_code":null,"kind":"point"},{"id":"cervical-vertebrae","view_id":"view-main","category_id":"zone-colonne","laterality":"unpaired","geometry":{"type":"polygon","points":[[468,276],[489,216],[558,248],[586,339],[552,461],[524,370]]},"review_status":"inherited","color":null,"name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"finding_zone_id":"cervical","vertebral_region_code":"C","kind":"zone"},{"id":"hinge-c7-t1","view_id":"view-main","category_id":"charnieres-vertebrales","laterality":"unpaired","geometry":{"type":"circle","cx":840.17,"cy":399.08,"r":30},"review_status":"inherited","color":null,"name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"finding_zone_id":"c7-t1","vertebral_region_code":null,"kind":"point"},{"id":"head-trigger","view_id":"view-main","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"polygon","points":[[454,332],[429,202],[349,154],[234,279],[164,384],[234,468]]},"review_status":"inherited","color":null,"kind":"detail_trigger","name":null,"opens_view_id":"view-head"},{"id":"atm","view_id":"view-head","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":384.94,"cy":314.02,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"finding_zone_id":"atm","vertebral_region_code":null,"kind":"point"},{"id":"sphenoid","view_id":"view-head","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"circle","cx":299,"cy":298,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Sphénoïde","en":"Sphenoid"},"finding_zone_id":"sphenoid","vertebral_region_code":null,"kind":"point"}],"finding_zones":[{"id":"hip","name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"categories":[{"id":"hip-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"articular","name":{"fr":"Restrictions de mobilité articulaire","en":"Articular mobility restrictions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-flexion","name":{"fr":"Restriction en flexion","en":"Flexion restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"restriction-extension","name":{"fr":"Restriction en extension","en":"Extension restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"hip-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"limb-lameness","name":{"fr":"Boiterie rapportée (membre concerné)","en":"Reported lameness (affected limb)"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":["legacy-catalog"],"review_status":"inherited","children":[]}]}]},{"id":"cervical","name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"categories":[{"id":"cervical-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"muscular","name":{"fr":"Tensions musculaires paravertébrales","en":"Paravertebral muscle tensions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"splenius-tension","name":{"fr":"Tension du splénius","en":"Splenius tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"cervical-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"stumbling-proprioceptive","name":{"fr":"Trébuchements / déficit proprioceptif rapporté","en":"Reported stumbling / proprioceptive deficit"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"c7-t1","name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"categories":[{"id":"c7-t1-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-rotation","name":{"fr":"Restriction en rotation","en":"Rotation restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"c7-t1-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"base-neck-stiffness","name":{"fr":"Raideur de la base de l'encolure","en":"Base-of-neck stiffness"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"atm","name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"categories":[{"id":"atm-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques de l'ATM","en":"Osteopathic TMJ dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"masseter-tension","name":{"fr":"Tension du masséter","en":"Masseter tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"atm-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"bit-defense","name":{"fr":"Réactions de défense au mors","en":"Defense reactions to bit"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"dental-context","name":{"fr":"Suite de soin dentaire récent","en":"Post recent dental care"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid","name":{"fr":"Sphénoïde","en":"Sphenoid"},"categories":[{"id":"ssb-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"physiological","name":{"fr":"Lésions physiologiques (SSB)","en":"Physiological lesions (SBS)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"torsion-right","name":{"fr":"Torsion droite","en":"Right torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"torsion-left","name":{"fr":"Torsion gauche","en":"Left torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"post-trauma-head","name":{"fr":"Suite de traumatisme crânien","en":"Post head trauma"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]}]}$fixture$::jsonb)) as c order by c collate "C"), - '{view.main.count}'::text[], - 'conformance view-main-count: two main views' -); - -select is( - array(select c from unnest(private.sheet_document_issues($fixture${"schema_version":2,"species_id":"equine","name":{"fr":"Cheval (extrait)","en":"Horse (slice)"},"description":{"fr":"Extrait de la fiche équine pour les tests du modèle","en":"Equine sheet slice for model tests"},"scope_disclaimer":{"fr":"Les éléments listés correspondent au périmètre légal de l'ostéopathie animale : dysfonctions ostéopathiques palpées, observations cliniques et motifs de consultation. Aucun diagnostic médical n'est posé. Toute pathologie organique relève du vétérinaire."},"attribution":{"authors":["Faunosteo"],"license":"MIT","notes":null},"vertebral_config":{"regions":[{"code":"C","name":{"fr":"Cervicales","en":"Cervical"},"count":7,"count_range":null},{"code":"T","name":{"fr":"Thoraciques","en":"Thoracic"},"count":18,"count_range":null},{"code":"L","name":{"fr":"Lombaires","en":"Lumbar"},"count":6,"count_range":null},{"code":"S","name":{"fr":"Sacrées","en":"Sacral"},"count":5,"count_range":null},{"code":"Cd","name":{"fr":"Caudales","en":"Caudal"},"count":18,"count_range":{"min":15,"max":21}}]},"references":[{"id":"legacy-catalog","type":"manual","citation":"Legacy equine catalog (pathologies.json, schema 2.0)","url":null,"doi":null}],"categories":[{"id":"articulations","name":{"fr":"Articulations","en":"Joints"},"color":"#ff9500"},{"id":"zone-colonne","name":{"fr":"Zone colonne","en":"Spine zone"},"color":"#e100ff"},{"id":"charnieres-vertebrales","name":{"fr":"Charnières vertébrales","en":"Vertebral junctions"},"color":"#ff0000"},{"id":"cadrans-du-crane","name":{"fr":"Cadrans du crâne","en":"Skull quadrants"},"color":"#1baa08"}],"views":[{"id":"view-main","name":{"fr":"Cheval entier","en":"Whole horse"},"svg_asset_id":"3f6c1b52-8a4e-4d17-9b0c-5e2a7d91c4f8","view_box":null,"kind":"main"},{"id":"view-head","name":{"fr":"Tête","en":"Head"},"svg_asset_id":null,"view_box":{"min_x":60,"min_y":100,"width":500,"height":380},"kind":"detail","parent_view_id":"view-main"},{"id":"view-a","kind":"detail","name":{"fr":"view-a","en":"view-a"},"parent_view_id":"view-b","svg_asset_id":"3f6c1b52-8a4e-4d17-9b0c-5e2a7d91c4f8","view_box":null},{"id":"view-b","kind":"detail","name":{"fr":"view-b","en":"view-b"},"parent_view_id":"view-a","svg_asset_id":"3f6c1b52-8a4e-4d17-9b0c-5e2a7d91c4f8","view_box":null}],"annotations":[{"id":"hip","view_id":"view-main","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":1516,"cy":695,"r":34},"review_status":"inherited","color":null,"name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"finding_zone_id":"hip","vertebral_region_code":null,"kind":"point"},{"id":"cervical-vertebrae","view_id":"view-main","category_id":"zone-colonne","laterality":"unpaired","geometry":{"type":"polygon","points":[[468,276],[489,216],[558,248],[586,339],[552,461],[524,370]]},"review_status":"inherited","color":null,"name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"finding_zone_id":"cervical","vertebral_region_code":"C","kind":"zone"},{"id":"hinge-c7-t1","view_id":"view-main","category_id":"charnieres-vertebrales","laterality":"unpaired","geometry":{"type":"circle","cx":840.17,"cy":399.08,"r":30},"review_status":"inherited","color":null,"name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"finding_zone_id":"c7-t1","vertebral_region_code":null,"kind":"point"},{"id":"head-trigger","view_id":"view-main","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"polygon","points":[[454,332],[429,202],[349,154],[234,279],[164,384],[234,468]]},"review_status":"inherited","color":null,"kind":"detail_trigger","name":null,"opens_view_id":"view-head"},{"id":"atm","view_id":"view-head","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":384.94,"cy":314.02,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"finding_zone_id":"atm","vertebral_region_code":null,"kind":"point"},{"id":"sphenoid","view_id":"view-head","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"circle","cx":299,"cy":298,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Sphénoïde","en":"Sphenoid"},"finding_zone_id":"sphenoid","vertebral_region_code":null,"kind":"point"},{"id":"open-a","kind":"detail_trigger","view_id":"view-b","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":null,"review_status":"inherited","color":null,"name":null,"opens_view_id":"view-a"},{"id":"open-b","kind":"detail_trigger","view_id":"view-a","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":null,"review_status":"inherited","color":null,"name":null,"opens_view_id":"view-b"}],"finding_zones":[{"id":"hip","name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"categories":[{"id":"hip-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"articular","name":{"fr":"Restrictions de mobilité articulaire","en":"Articular mobility restrictions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-flexion","name":{"fr":"Restriction en flexion","en":"Flexion restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"restriction-extension","name":{"fr":"Restriction en extension","en":"Extension restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"hip-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"limb-lameness","name":{"fr":"Boiterie rapportée (membre concerné)","en":"Reported lameness (affected limb)"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":["legacy-catalog"],"review_status":"inherited","children":[]}]}]},{"id":"cervical","name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"categories":[{"id":"cervical-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"muscular","name":{"fr":"Tensions musculaires paravertébrales","en":"Paravertebral muscle tensions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"splenius-tension","name":{"fr":"Tension du splénius","en":"Splenius tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"cervical-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"stumbling-proprioceptive","name":{"fr":"Trébuchements / déficit proprioceptif rapporté","en":"Reported stumbling / proprioceptive deficit"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"c7-t1","name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"categories":[{"id":"c7-t1-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-rotation","name":{"fr":"Restriction en rotation","en":"Rotation restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"c7-t1-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"base-neck-stiffness","name":{"fr":"Raideur de la base de l'encolure","en":"Base-of-neck stiffness"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"atm","name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"categories":[{"id":"atm-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques de l'ATM","en":"Osteopathic TMJ dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"masseter-tension","name":{"fr":"Tension du masséter","en":"Masseter tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"atm-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"bit-defense","name":{"fr":"Réactions de défense au mors","en":"Defense reactions to bit"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"dental-context","name":{"fr":"Suite de soin dentaire récent","en":"Post recent dental care"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid","name":{"fr":"Sphénoïde","en":"Sphenoid"},"categories":[{"id":"ssb-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"physiological","name":{"fr":"Lésions physiologiques (SSB)","en":"Physiological lesions (SBS)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"torsion-right","name":{"fr":"Torsion droite","en":"Right torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"torsion-left","name":{"fr":"Torsion gauche","en":"Left torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"post-trauma-head","name":{"fr":"Suite de traumatisme crânien","en":"Post head trauma"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]}]}$fixture$::jsonb)) as c order by c collate "C"), - '{}'::text[], - 'conformance view-parent-cycle: two detail views parent of each other (SQL has no cycle rule)' -); - -select is( - array(select c from unnest(private.sheet_document_issues($fixture${"schema_version":2,"species_id":"equine","name":{"fr":"Cheval (extrait)","en":"Horse (slice)"},"description":{"fr":"Extrait de la fiche équine pour les tests du modèle","en":"Equine sheet slice for model tests"},"scope_disclaimer":{"fr":"Les éléments listés correspondent au périmètre légal de l'ostéopathie animale : dysfonctions ostéopathiques palpées, observations cliniques et motifs de consultation. Aucun diagnostic médical n'est posé. Toute pathologie organique relève du vétérinaire."},"attribution":{"authors":["Faunosteo"],"license":"MIT","notes":null},"vertebral_config":{"regions":[{"code":"C","name":{"fr":"Cervicales","en":"Cervical"},"count":7,"count_range":null},{"code":"T","name":{"fr":"Thoraciques","en":"Thoracic"},"count":18,"count_range":null},{"code":"L","name":{"fr":"Lombaires","en":"Lumbar"},"count":6,"count_range":null},{"code":"S","name":{"fr":"Sacrées","en":"Sacral"},"count":5,"count_range":null},{"code":"Cd","name":{"fr":"Caudales","en":"Caudal"},"count":18,"count_range":{"min":15,"max":21}}]},"references":[{"id":"legacy-catalog","type":"manual","citation":"Legacy equine catalog (pathologies.json, schema 2.0)","url":null,"doi":null}],"categories":[{"id":"articulations","name":{"fr":"Articulations","en":"Joints"},"color":"#ff9500"},{"id":"zone-colonne","name":{"fr":"Zone colonne","en":"Spine zone"},"color":"#e100ff"},{"id":"charnieres-vertebrales","name":{"fr":"Charnières vertébrales","en":"Vertebral junctions"},"color":"#ff0000"},{"id":"cadrans-du-crane","name":{"fr":"Cadrans du crâne","en":"Skull quadrants"},"color":"#1baa08"}],"views":[{"id":"view-main","name":{"fr":"Cheval entier","en":"Whole horse"},"svg_asset_id":"3f6c1b52-8a4e-4d17-9b0c-5e2a7d91c4f8","view_box":null,"kind":"main"},{"id":"view-head","name":{"fr":"Tête","en":"Head"},"svg_asset_id":null,"view_box":{"min_x":60,"min_y":100,"width":500,"height":380},"kind":"detail","parent_view_id":"view-main"},{"id":"view-orphan","kind":"detail","name":{"fr":"view-orphan","en":"view-orphan"},"parent_view_id":"view-ghost","svg_asset_id":"3f6c1b52-8a4e-4d17-9b0c-5e2a7d91c4f8","view_box":null}],"annotations":[{"id":"hip","view_id":"view-main","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":1516,"cy":695,"r":34},"review_status":"inherited","color":null,"name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"finding_zone_id":"hip","vertebral_region_code":null,"kind":"point"},{"id":"cervical-vertebrae","view_id":"view-main","category_id":"zone-colonne","laterality":"unpaired","geometry":{"type":"polygon","points":[[468,276],[489,216],[558,248],[586,339],[552,461],[524,370]]},"review_status":"inherited","color":null,"name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"finding_zone_id":"cervical","vertebral_region_code":"C","kind":"zone"},{"id":"hinge-c7-t1","view_id":"view-main","category_id":"charnieres-vertebrales","laterality":"unpaired","geometry":{"type":"circle","cx":840.17,"cy":399.08,"r":30},"review_status":"inherited","color":null,"name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"finding_zone_id":"c7-t1","vertebral_region_code":null,"kind":"point"},{"id":"head-trigger","view_id":"view-main","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"polygon","points":[[454,332],[429,202],[349,154],[234,279],[164,384],[234,468]]},"review_status":"inherited","color":null,"kind":"detail_trigger","name":null,"opens_view_id":"view-head"},{"id":"atm","view_id":"view-head","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":384.94,"cy":314.02,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"finding_zone_id":"atm","vertebral_region_code":null,"kind":"point"},{"id":"sphenoid","view_id":"view-head","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"circle","cx":299,"cy":298,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Sphénoïde","en":"Sphenoid"},"finding_zone_id":"sphenoid","vertebral_region_code":null,"kind":"point"}],"finding_zones":[{"id":"hip","name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"categories":[{"id":"hip-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"articular","name":{"fr":"Restrictions de mobilité articulaire","en":"Articular mobility restrictions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-flexion","name":{"fr":"Restriction en flexion","en":"Flexion restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"restriction-extension","name":{"fr":"Restriction en extension","en":"Extension restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"hip-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"limb-lameness","name":{"fr":"Boiterie rapportée (membre concerné)","en":"Reported lameness (affected limb)"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":["legacy-catalog"],"review_status":"inherited","children":[]}]}]},{"id":"cervical","name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"categories":[{"id":"cervical-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"muscular","name":{"fr":"Tensions musculaires paravertébrales","en":"Paravertebral muscle tensions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"splenius-tension","name":{"fr":"Tension du splénius","en":"Splenius tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"cervical-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"stumbling-proprioceptive","name":{"fr":"Trébuchements / déficit proprioceptif rapporté","en":"Reported stumbling / proprioceptive deficit"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"c7-t1","name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"categories":[{"id":"c7-t1-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-rotation","name":{"fr":"Restriction en rotation","en":"Rotation restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"c7-t1-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"base-neck-stiffness","name":{"fr":"Raideur de la base de l'encolure","en":"Base-of-neck stiffness"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"atm","name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"categories":[{"id":"atm-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques de l'ATM","en":"Osteopathic TMJ dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"masseter-tension","name":{"fr":"Tension du masséter","en":"Masseter tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"atm-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"bit-defense","name":{"fr":"Réactions de défense au mors","en":"Defense reactions to bit"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"dental-context","name":{"fr":"Suite de soin dentaire récent","en":"Post recent dental care"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid","name":{"fr":"Sphénoïde","en":"Sphenoid"},"categories":[{"id":"ssb-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"physiological","name":{"fr":"Lésions physiologiques (SSB)","en":"Physiological lesions (SBS)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"torsion-right","name":{"fr":"Torsion droite","en":"Right torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"torsion-left","name":{"fr":"Torsion gauche","en":"Left torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"post-trauma-head","name":{"fr":"Suite de traumatisme crânien","en":"Post head trauma"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]}]}$fixture$::jsonb)) as c order by c collate "C"), - '{view.parent.missing}'::text[], - 'conformance view-parent-missing: a detail view whose parent does not exist' -); - -select is( - array(select c from unnest(private.sheet_document_issues($fixture${"schema_version":2,"species_id":"equine","name":{"fr":"Cheval (extrait)","en":"Horse (slice)"},"description":{"fr":"Extrait de la fiche équine pour les tests du modèle","en":"Equine sheet slice for model tests"},"scope_disclaimer":{"fr":"Les éléments listés correspondent au périmètre légal de l'ostéopathie animale : dysfonctions ostéopathiques palpées, observations cliniques et motifs de consultation. Aucun diagnostic médical n'est posé. Toute pathologie organique relève du vétérinaire."},"attribution":{"authors":["Faunosteo"],"license":"MIT","notes":null},"vertebral_config":{"regions":[{"code":"C","name":{"fr":"Cervicales","en":"Cervical"},"count":7,"count_range":null},{"code":"T","name":{"fr":"Thoraciques","en":"Thoracic"},"count":18,"count_range":null},{"code":"L","name":{"fr":"Lombaires","en":"Lumbar"},"count":6,"count_range":null},{"code":"S","name":{"fr":"Sacrées","en":"Sacral"},"count":5,"count_range":null},{"code":"Cd","name":{"fr":"Caudales","en":"Caudal"},"count":18,"count_range":{"min":15,"max":21}}]},"references":[{"id":"legacy-catalog","type":"manual","citation":"Legacy equine catalog (pathologies.json, schema 2.0)","url":null,"doi":null}],"categories":[{"id":"articulations","name":{"fr":"Articulations","en":"Joints"},"color":"#ff9500"},{"id":"zone-colonne","name":{"fr":"Zone colonne","en":"Spine zone"},"color":"#e100ff"},{"id":"charnieres-vertebrales","name":{"fr":"Charnières vertébrales","en":"Vertebral junctions"},"color":"#ff0000"},{"id":"cadrans-du-crane","name":{"fr":"Cadrans du crâne","en":"Skull quadrants"},"color":"#1baa08"}],"views":[{"id":"view-main","name":{"fr":"Cheval entier","en":"Whole horse"},"svg_asset_id":"3f6c1b52-8a4e-4d17-9b0c-5e2a7d91c4f8","view_box":null,"kind":"main"},{"id":"view-head","name":{"fr":"Tête","en":"Head"},"svg_asset_id":null,"view_box":{"min_x":60,"min_y":100,"width":500,"height":380},"kind":"detail","parent_view_id":"view-main"}],"annotations":[{"id":"hip","view_id":"view-main","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":1516,"cy":695,"r":34},"review_status":"inherited","color":null,"name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"finding_zone_id":"hip","vertebral_region_code":null,"kind":"point"},{"id":"cervical-vertebrae","view_id":"view-main","category_id":"zone-colonne","laterality":"unpaired","geometry":{"type":"polygon","points":[[468,276],[489,216],[558,248],[586,339],[552,461],[524,370]]},"review_status":"inherited","color":null,"name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"finding_zone_id":"cervical","vertebral_region_code":"C","kind":"zone"},{"id":"hinge-c7-t1","view_id":"view-main","category_id":"charnieres-vertebrales","laterality":"unpaired","geometry":{"type":"circle","cx":840.17,"cy":399.08,"r":30},"review_status":"inherited","color":null,"name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"finding_zone_id":"c7-t1","vertebral_region_code":null,"kind":"point"},{"id":"atm","view_id":"view-head","category_id":"articulations","laterality":"bilateral","geometry":{"type":"circle","cx":384.94,"cy":314.02,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"finding_zone_id":"atm","vertebral_region_code":null,"kind":"point"},{"id":"sphenoid","view_id":"view-head","category_id":"cadrans-du-crane","laterality":"unpaired","geometry":{"type":"circle","cx":299,"cy":298,"r":27},"review_status":"inherited","color":null,"name":{"fr":"Sphénoïde","en":"Sphenoid"},"finding_zone_id":"sphenoid","vertebral_region_code":null,"kind":"point"}],"finding_zones":[{"id":"hip","name":{"fr":"Hanche (coxo-fémorale)","en":"Hip joint"},"categories":[{"id":"hip-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"articular","name":{"fr":"Restrictions de mobilité articulaire","en":"Articular mobility restrictions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-flexion","name":{"fr":"Restriction en flexion","en":"Flexion restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"restriction-extension","name":{"fr":"Restriction en extension","en":"Extension restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"hip-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"limb-lameness","name":{"fr":"Boiterie rapportée (membre concerné)","en":"Reported lameness (affected limb)"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":["legacy-catalog"],"review_status":"inherited","children":[]}]}]},{"id":"cervical","name":{"fr":"Vertèbres cervicales","en":"Cervical Vertebrae"},"categories":[{"id":"cervical-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"muscular","name":{"fr":"Tensions musculaires paravertébrales","en":"Paravertebral muscle tensions"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"splenius-tension","name":{"fr":"Tension du splénius","en":"Splenius tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"cervical-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"stumbling-proprioceptive","name":{"fr":"Trébuchements / déficit proprioceptif rapporté","en":"Reported stumbling / proprioceptive deficit"},"description":{},"requires_vet_referral":true,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"c7-t1","name":{"fr":"Charnière C7-T1 (cervico-thoracique)","en":"C7-T1 (Cervicothoracic)"},"categories":[{"id":"c7-t1-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"restriction-rotation","name":{"fr":"Restriction en rotation","en":"Rotation restriction"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"c7-t1-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"base-neck-stiffness","name":{"fr":"Raideur de la base de l'encolure","en":"Base-of-neck stiffness"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"atm","name":{"fr":"Articulation Temporo-Mandibulaire (ATM)","en":"Temporomandibular Joint (TMJ)"},"categories":[{"id":"atm-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques de l'ATM","en":"Osteopathic TMJ dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"masseter-tension","name":{"fr":"Tension du masséter","en":"Masseter tension"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"atm-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"bit-defense","name":{"fr":"Réactions de défense au mors","en":"Defense reactions to bit"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"dental-context","name":{"fr":"Suite de soin dentaire récent","en":"Post recent dental care"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid","name":{"fr":"Sphénoïde","en":"Sphenoid"},"categories":[{"id":"ssb-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions ostéopathiques","en":"Osteopathic dysfunctions"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"physiological","name":{"fr":"Lésions physiologiques (SSB)","en":"Physiological lesions (SBS)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[{"id":"torsion-right","name":{"fr":"Torsion droite","en":"Right torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"torsion-left","name":{"fr":"Torsion gauche","en":"Left torsion"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]},{"id":"sphenoid-observations","kind":"consultation_reason","name":{"fr":"Observations / motifs de consultation","en":"Observations / consultation reasons"},"description":{},"reference_ids":[],"review_status":"inherited","children":[{"id":"post-trauma-head","name":{"fr":"Suite de traumatisme crânien","en":"Post head trauma"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse / facteurs rapportés","en":"Anamnesis / reported factors"},"description":{"fr":"Facteurs rapportés par le propriétaire lors de l'anamnèse"},"reference_ids":[],"review_status":"inherited","children":[{"id":"trauma-direct","name":{"fr":"Traumatisme rapporté (choc, chute)","en":"Reported trauma (blow, fall)"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]},{"id":"stress-context","name":{"fr":"Contexte de stress / changement","en":"Stress / change context"},"description":{},"requires_vet_referral":false,"reference_ids":[],"review_status":"inherited","children":[]}]}]}]}$fixture$::jsonb)) as c order by c collate "C"), - '{view.unreachable}'::text[], - 'conformance view-unreachable: the head view without its trigger' -); - -select * from finish(); -rollback; diff --git a/supabase/tests/015_catalog_access.sql b/supabase/tests/015_catalog_access.sql new file mode 100644 index 00000000..5a79f04d --- /dev/null +++ b/supabase/tests/015_catalog_access.sql @@ -0,0 +1,204 @@ +-- V1-2.1 M4: AR-1 B (MFA on every platform role change) and catalogue rights. +-- Contract docs/development/V1-2_ANATOMICAL_SHEETS.md §5.2, §5.7, §15. +-- The aal2 session check reads auth.sessions; here those rows are fabricated, +-- as the shim allows. Real GoTrue MFA is proven in tests/sandbox/mfa.sandbox.ts, +-- the F18 race in tests/sandbox (two sessions). +begin; +select plan(36); + +insert into auth.users (id, email, email_confirmed_at) values + ('d0000000-0000-0000-0000-000000000001', 'own@t.local', now()), -- owner + ('d0000000-0000-0000-0000-00000000000a', 'adm@t.local', now()), -- admin + ('d0000000-0000-0000-0000-00000000000b', 'mod@t.local', now()), -- moderator + ('d0000000-0000-0000-0000-00000000000c', 'noface@t.local', now()), -- no factor + ('d0000000-0000-0000-0000-00000000000e', 'editor@t.local', now()), -- capability holder + ('d0000000-0000-0000-0000-0000000000aa', 'att@t.local', now()), -- fresh grant target + ('d0000000-0000-0000-0000-00000000000f', 'rev@t.local', now()); -- reviewer (non-admin) + +insert into auth.mfa_factors (id, user_id, factor_type, status, created_at, updated_at) +select gen_random_uuid(), id, 'totp', 'verified', now(), now() +from auth.users where email in ('own@t.local', 'adm@t.local', 'mod@t.local', 'editor@t.local', 'att@t.local', 'rev@t.local'); + +insert into auth.sessions (id, user_id, aal) values + ('d1000000-0000-0000-0000-000000000001', 'd0000000-0000-0000-0000-000000000001', 'aal2'), + ('d2000000-0000-0000-0000-000000000001', 'd0000000-0000-0000-0000-000000000001', 'aal1'), + ('d1000000-0000-0000-0000-00000000000a', 'd0000000-0000-0000-0000-00000000000a', 'aal2'), + ('d1000000-0000-0000-0000-00000000000b', 'd0000000-0000-0000-0000-00000000000b', 'aal2'), + ('d1000000-0000-0000-0000-00000000000e', 'd0000000-0000-0000-0000-00000000000e', 'aal2'); + +create function pg_temp.act(p_uid uuid, p_sid uuid, p_aal text) returns void language sql as $$ + select set_config('request.jwt.claims', + jsonb_build_object('sub', p_uid, 'role', 'authenticated', 'aal', p_aal, 'session_id', p_sid)::text, true); +$$; + +-- Bootstrap owner (operator path), admin, moderator. +select set_config('request.jwt.claims', '', true); +select private.assign_platform_role(null, 'd0000000-0000-0000-0000-000000000001', 'owner'); +set local role authenticated; +select pg_temp.act('d0000000-0000-0000-0000-000000000001', 'd1000000-0000-0000-0000-000000000001', 'aal2'); +select public.grant_platform_role('d0000000-0000-0000-0000-00000000000a', 'admin'); +select public.grant_platform_role('d0000000-0000-0000-0000-00000000000b', 'moderator'); + +-- === AR-1 B matrix ======================================================== +-- aal1, every role, refused with mfa_required before any role check. +select pg_temp.act('d0000000-0000-0000-0000-000000000001', 'd2000000-0000-0000-0000-000000000001', 'aal1'); +select throws_ok($$ select public.grant_platform_role('d0000000-0000-0000-0000-00000000000c','support') $$, + '42501', 'mfa_required', 'aal1 owner refused (mfa_required)'); +-- a token whose aal is missing / null / wrongly cased is not aal2 +select set_config('request.jwt.claims', + '{"sub":"d0000000-0000-0000-0000-000000000001","role":"authenticated","session_id":"d1000000-0000-0000-0000-000000000001"}', true); +select throws_ok($$ select public.grant_platform_role('d0000000-0000-0000-0000-00000000000c','support') $$, + '42501', 'mfa_required', 'absent aal claim refused'); +select set_config('request.jwt.claims', + '{"sub":"d0000000-0000-0000-0000-000000000001","role":"authenticated","aal":"AAL2","session_id":"d1000000-0000-0000-0000-000000000001"}', true); +select throws_ok($$ select public.grant_platform_role('d0000000-0000-0000-0000-00000000000c','support') $$, + '42501', 'mfa_required', 'wrongly cased aal refused'); +-- aal2 but the session_id names no live aal2 session row +select set_config('request.jwt.claims', + '{"sub":"d0000000-0000-0000-0000-000000000001","role":"authenticated","aal":"aal2","session_id":"d9000000-0000-0000-0000-000000000009"}', true); +select throws_ok($$ select public.grant_platform_role('d0000000-0000-0000-0000-00000000000c','support') $$, + '42501', 'mfa_required', 'aal2 claim with no live session refused'); + +-- aal2 owner grants any role. +select pg_temp.act('d0000000-0000-0000-0000-000000000001', 'd1000000-0000-0000-0000-000000000001', 'aal2'); +select lives_ok($$ select public.grant_platform_role('d0000000-0000-0000-0000-00000000000e','support') $$, 'owner aal2 grants support'); +select lives_ok($$ select public.revoke_platform_role('d0000000-0000-0000-0000-00000000000e','support','done') $$, 'owner aal2 revokes support'); + +-- aal2 admin: moderator/support only. +select pg_temp.act('d0000000-0000-0000-0000-00000000000a', 'd1000000-0000-0000-0000-00000000000a', 'aal2'); +select lives_ok($$ select public.grant_platform_role('d0000000-0000-0000-0000-00000000000e','support') $$, 'admin aal2 grants support'); +select throws_ok($$ select public.grant_platform_role('d0000000-0000-0000-0000-00000000000e','admin') $$, + '42501', 'forbidden', 'admin cannot grant admin'); +select throws_ok($$ select public.grant_platform_role('d0000000-0000-0000-0000-00000000000e','owner') $$, + '42501', 'forbidden', 'admin cannot grant owner'); + +-- aal2 moderator: nothing. +select pg_temp.act('d0000000-0000-0000-0000-00000000000b', 'd1000000-0000-0000-0000-00000000000b', 'aal2'); +select throws_ok($$ select public.grant_platform_role('d0000000-0000-0000-0000-00000000000c','support') $$, + '42501', 'forbidden', 'moderator at aal2 cannot grant (aal2 is not sufficient)'); + +-- deactivated owner refused. +reset role; +update public.profiles set active = false where id = 'd0000000-0000-0000-0000-000000000001'; +set local role authenticated; +select pg_temp.act('d0000000-0000-0000-0000-000000000001', 'd1000000-0000-0000-0000-000000000001', 'aal2'); +select throws_ok($$ select public.grant_platform_role('d0000000-0000-0000-0000-00000000000c','support') $$, + '42501', 'forbidden', 'a deactivated owner is not a manager'); +reset role; update public.profiles set active = true where id = 'd0000000-0000-0000-0000-000000000001'; set local role authenticated; + +-- grant to a target with no verified factor refused. +select pg_temp.act('d0000000-0000-0000-0000-000000000001', 'd1000000-0000-0000-0000-000000000001', 'aal2'); +select throws_ok($$ select public.grant_platform_role('d0000000-0000-0000-0000-00000000000c','support') $$, + 'P0001', 'target_factor_missing', 'grant to a factorless target refused'); + +-- The regression chain: an aal1 owner session grants owner to a fresh account +-- that never received anything; no row, no audit row. +select pg_temp.act('d0000000-0000-0000-0000-000000000001', 'd2000000-0000-0000-0000-000000000001', 'aal1'); +select throws_ok($$ select public.grant_platform_role('d0000000-0000-0000-0000-0000000000aa','owner') $$, + '42501', 'mfa_required', 'the escalation chain is blocked at step 3'); +reset role; +select is((select count(*) from public.profile_roles where user_id='d0000000-0000-0000-0000-0000000000aa'), + 0::bigint, 'no role row written for the attacker'); +select is((select count(*) from audit.audit_logs where target_user_id='d0000000-0000-0000-0000-0000000000aa'), + 0::bigint, 'no audit row for the refused grant'); + +-- The private write functions are not API-callable (EXECUTE revoked), and their +-- actor rule is exercised as the table owner: a non-null actor at aal1, and a +-- null actor from any session (API role set), are refused. +select set_config('request.jwt.claims', + '{"sub":"d0000000-0000-0000-0000-000000000001","role":"authenticated","aal":"aal1","session_id":"d2000000-0000-0000-0000-000000000001"}', true); +select throws_ok($$ select private.assign_platform_role('d0000000-0000-0000-0000-000000000001','d0000000-0000-0000-0000-0000000000aa','support') $$, + '42501', 'mfa_required', 'private writer: non-null actor at aal1 refused'); +select throws_ok($$ select private.assign_platform_role(null,'d0000000-0000-0000-0000-0000000000aa','support') $$, + '42501', 'operator_path_only', 'private writer: null actor from an API session refused'); +select set_config('request.jwt.claims', '{"role":"service_role"}', true); +select throws_ok($$ select private.assign_platform_role(null,'d0000000-0000-0000-0000-0000000000aa','support') $$, + '42501', 'operator_path_only', 'private writer: null actor as service_role refused'); + +-- Role read from the table every call: a revoked role is refused at once. +select set_config('request.jwt.claims', '', true); +select private.assign_platform_role(null, 'd0000000-0000-0000-0000-00000000000e', 'admin'); +set local role authenticated; +select pg_temp.act('d0000000-0000-0000-0000-00000000000e', 'd1000000-0000-0000-0000-00000000000e', 'aal2'); +select lives_ok($$ select public.grant_platform_role('d0000000-0000-0000-0000-0000000000aa','support') $$, + 'the new admin (aal2) grants support to a factored account'); +reset role; +update public.profile_roles set revoked_at = now() where user_id='d0000000-0000-0000-0000-00000000000e' and role='admin' and revoked_at is null; +set local role authenticated; +select pg_temp.act('d0000000-0000-0000-0000-00000000000e', 'd1000000-0000-0000-0000-00000000000e', 'aal2'); +select throws_ok($$ select public.revoke_platform_role('d0000000-0000-0000-0000-0000000000aa','support','x') $$, + '42501', 'forbidden', 'the revoked admin is refused at the next call, same token'); + +-- An account holding a factor but no role is no admin. +select ok(not private.is_platform_admin('d0000000-0000-0000-0000-00000000000c'), 'a factor alone grants no role'); + +-- === Catalogue rights ===================================================== +select pg_temp.act('d0000000-0000-0000-0000-000000000001', 'd1000000-0000-0000-0000-000000000001', 'aal2'); +-- owner grants editor (needs an admin target, a note, a verified factor) +select lives_ok( + $$ select public.grant_catalog_right('d0000000-0000-0000-0000-00000000000a','sheet_editor','needs to author','DVM checked') $$, + 'owner grants sheet_editor to an admin with a note'); +select throws_ok( + $$ select public.grant_catalog_right('d0000000-0000-0000-0000-00000000000a','sheet_editor','again','x') $$, + 'P0001', 'grant.active', 'one active grant per account and kind'); +-- editor/publisher need a platform admin target +select throws_ok( + $$ select public.grant_catalog_right('d0000000-0000-0000-0000-00000000000f','sheet_editor','no role','x') $$, + 'P0001', 'grant.ineligible', 'sheet_editor needs a platform admin target'); +-- a capability needs a verification note +select throws_ok( + $$ select public.grant_catalog_right('d0000000-0000-0000-0000-00000000000f','sheet_reviewer','partner') $$, + 'P0001', 'invalid_input', 'a capability needs a verification note'); +-- reviewer may be a non-admin with a factor +select lives_ok( + $$ select public.grant_catalog_right('d0000000-0000-0000-0000-00000000000f','sheet_reviewer','partner vet','DVM verified', now()+interval '90 days') $$, + 'reviewer granted to a non-admin confirmed account with a factor'); +-- catalog_reader needs no note and no factor +select lives_ok( + $$ select public.grant_catalog_right('d0000000-0000-0000-0000-00000000000c','catalog_reader','beta') $$, + 'catalog_reader needs no note or factor'); +-- the owner cannot grant itself sheet_reviewer +select throws_ok( + $$ select public.grant_catalog_right('d0000000-0000-0000-0000-000000000001','sheet_reviewer','self','x') $$, + 'P0001', 'grant.self_review', 'the owner cannot review its own drafts'); + +-- grant_active reflects eligibility, expiry and revocation (checked as the +-- table owner: grant_active is internal, not granted to any API role). +reset role; +select ok(private.grant_active('d0000000-0000-0000-0000-00000000000f','sheet_reviewer'), 'an active grant is active'); +-- An expired grant is inactive (inserted directly with a past expiry: the RPC +-- refuses a past expiry and the guard forbids editing a live row). +insert into auth.users (id, email, email_confirmed_at) + values ('d0000000-0000-0000-0000-0000000000ef', 'expired@t.local', now()); +insert into public.anatomical_catalog_grants (user_id, grant_kind, reason, granted_by, granted_at, expires_at) + values ('d0000000-0000-0000-0000-0000000000ef', 'catalog_reader', 'x', 'd0000000-0000-0000-0000-000000000001', now() - interval '2 days', now() - interval '1 day'); +select ok(not private.grant_active('d0000000-0000-0000-0000-0000000000ef','catalog_reader'), 'an expired grant is inactive'); +set local role authenticated; +select pg_temp.act('d0000000-0000-0000-0000-000000000001', 'd1000000-0000-0000-0000-000000000001', 'aal2'); +-- A revoked grant is inactive at the next read. +select lives_ok($$ select public.revoke_catalog_right( + (select id from public.anatomical_catalog_grants where user_id='d0000000-0000-0000-0000-00000000000c' and grant_kind='catalog_reader'), + 'no longer a beta tester') $$, 'owner revokes the reader grant'); +reset role; +select ok(not private.grant_active('d0000000-0000-0000-0000-00000000000c','catalog_reader'), 'a revoked grant is inactive'); +set local role authenticated; +select pg_temp.act('d0000000-0000-0000-0000-000000000001', 'd1000000-0000-0000-0000-000000000001', 'aal2'); + +-- only the owner (aal2) lists grants +select ok((select jsonb_typeof(public.list_catalog_grants()) = 'array'), 'owner lists grants'); +select pg_temp.act('d0000000-0000-0000-0000-00000000000a', 'd1000000-0000-0000-0000-00000000000a', 'aal2'); +select throws_ok($$ select public.list_catalog_grants() $$, '42501', 'rights.owner', 'an admin cannot list grants'); +-- an aal1 owner cannot touch rights +select pg_temp.act('d0000000-0000-0000-0000-000000000001', 'd2000000-0000-0000-0000-000000000001', 'aal1'); +select throws_ok($$ select public.grant_catalog_right('d0000000-0000-0000-0000-00000000000c','catalog_reader','x') $$, + '42501', 'rights.mfa', 'rights need a live aal2 session'); + +-- direct writes to the grants table are impossible +select pg_temp.act('d0000000-0000-0000-0000-000000000001', 'd1000000-0000-0000-0000-000000000001', 'aal2'); +select throws_ok( + $$ insert into public.anatomical_catalog_grants (user_id, grant_kind, reason, granted_by) + values ('d0000000-0000-0000-0000-00000000000c','catalog_reader','x','d0000000-0000-0000-0000-000000000001') $$, + '42501', null, 'no direct insert into the grants table'); + +select * from finish(); +rollback; diff --git a/supabase/tests/016_sheet_review_workflow.sql b/supabase/tests/016_sheet_review_workflow.sql new file mode 100644 index 00000000..06122d6d --- /dev/null +++ b/supabase/tests/016_sheet_review_workflow.sql @@ -0,0 +1,209 @@ +-- V1-2.1 M5: the official-sheet lifecycle, review workflow and publication. +-- Contract docs/development/V1-2_ANATOMICAL_SHEETS.md §6, §7, §9, §14, §15. +-- The verdict is written directly (as the table owner) to stand in for the +-- worker of M6, as the contract allows until V1-2.3. Real GoTrue MFA and the +-- concurrency cases run in tests/sandbox. +begin; +select plan(30); + +-- Accounts: owner, editor+publisher, reviewer, and a reviewer who also edits +-- (so becomes a round author -> separation of duties). +insert into auth.users (id, email, email_confirmed_at) values + ('e0000000-0000-0000-0000-000000000001', 'own@wf.local', now()), + ('e0000000-0000-0000-0000-00000000000e', 'edpub@wf.local', now()), + ('e0000000-0000-0000-0000-0000000000f1', 'rev1@wf.local', now()), + ('e0000000-0000-0000-0000-0000000000f2', 'rev2@wf.local', now()); +insert into auth.mfa_factors (id, user_id, factor_type, status, created_at, updated_at) +select gen_random_uuid(), id, 'totp', 'verified', now(), now() from auth.users +where email in ('own@wf.local','edpub@wf.local','rev1@wf.local','rev2@wf.local'); +insert into auth.sessions (id, user_id, aal) values + ('e1000000-0000-0000-0000-000000000001', 'e0000000-0000-0000-0000-000000000001', 'aal2'), + ('e1000000-0000-0000-0000-00000000000e', 'e0000000-0000-0000-0000-00000000000e', 'aal2'), + ('e1000000-0000-0000-0000-0000000000f1', 'e0000000-0000-0000-0000-0000000000f1', 'aal2'), + ('e1000000-0000-0000-0000-0000000000f2', 'e0000000-0000-0000-0000-0000000000f2', 'aal2'); + +select set_config('request.jwt.claims', '', true); +select private.assign_platform_role(null, 'e0000000-0000-0000-0000-000000000001', 'owner'); +select private.assign_platform_role(null, 'e0000000-0000-0000-0000-00000000000e', 'admin'); +select private.assign_platform_role(null, 'e0000000-0000-0000-0000-0000000000f2', 'admin'); +insert into public.anatomical_catalog_grants (user_id, grant_kind, reason, verification_note, granted_by) values + ('e0000000-0000-0000-0000-00000000000e','sheet_editor','a','c','e0000000-0000-0000-0000-000000000001'), + ('e0000000-0000-0000-0000-00000000000e','sheet_publisher','a','c','e0000000-0000-0000-0000-000000000001'), + ('e0000000-0000-0000-0000-0000000000f1','sheet_reviewer','a','c','e0000000-0000-0000-0000-000000000001'), + ('e0000000-0000-0000-0000-0000000000f2','sheet_editor','a','c','e0000000-0000-0000-0000-000000000001'), + ('e0000000-0000-0000-0000-0000000000f2','sheet_reviewer','a','c','e0000000-0000-0000-0000-000000000001'); + +create table pg_temp.k(key text primary key, id uuid); +grant all on pg_temp.k to authenticated; +create function pg_temp.act(p uuid, s uuid) returns void language sql as $$ + select set_config('request.jwt.claims', jsonb_build_object('sub',p,'role','authenticated','aal','aal2','session_id',s)::text, true); +$$; +grant execute on function pg_temp.act(uuid,uuid) to authenticated; +-- A small document; `st` is the review_status applied to its three elements. +create function pg_temp.doc(p_asset uuid, st text) returns jsonb language sql as $$ + select jsonb_build_object('schema_version',2,'species_id','equine', + 'name',jsonb_build_object('fr','Cheval WF','en','WF horse'), + 'description',jsonb_build_object('fr','d','en','d'), + 'scope_disclaimer',jsonb_build_object('fr','x','en','x'), + 'attribution',jsonb_build_object('authors',jsonb_build_array('F'),'license',null,'notes',null), + 'vertebral_config',jsonb_build_object('regions','[]'::jsonb),'references','[]'::jsonb, + 'categories',jsonb_build_array(jsonb_build_object('id','c','name',jsonb_build_object('fr','C','en','C'),'color',null)), + 'views',jsonb_build_array(jsonb_build_object('id','main','kind','main','name',jsonb_build_object('fr','V','en','V'),'svg_asset_id',p_asset,'view_box',null)), + 'annotations',jsonb_build_array(jsonb_build_object('id','a1','kind','point','view_id','main','category_id','c', + 'laterality','unpaired','geometry',null,'review_status',st,'name',jsonb_build_object('fr','P','en','P'), + 'finding_zone_id','z1','vertebral_region_code',null)), + 'finding_zones',jsonb_build_array(jsonb_build_object('id','z1','name',jsonb_build_object('fr','Z','en','Z'), + 'categories',jsonb_build_array(jsonb_build_object('id','cat','kind','dysfunction','name',jsonb_build_object('fr','D','en','D'), + 'review_status',st,'children',jsonb_build_array(jsonb_build_object('id','n1','name',jsonb_build_object('fr','N','en','N'),'review_status',st))))))); +$$; +grant execute on function pg_temp.doc(uuid,text) to authenticated; +-- Writes a passing verdict on a round and opens it (stands in for the worker). +create function pg_temp.open_round(p_review uuid, p_asset uuid, p_sha text) returns void language sql as $$ + update public.anatomical_sheet_reviews set status='open', verified_at=now(), verified_with='test', + verdict = jsonb_build_object('fingerprint', repeat('a',64), + 'drawings', jsonb_build_array(jsonb_build_object('asset_id', p_asset, 'sha256', p_sha)), + 'groups', jsonb_build_array( + jsonb_build_object('key','general','digest',repeat('1',64),'coverable',true), + jsonb_build_object('key','view:main','digest',repeat('2',64),'coverable',true), + jsonb_build_object('key','zone:z1','digest',repeat('3',64),'coverable',true))) + where id = p_review; +$$; + +set local role authenticated; +select pg_temp.act('e0000000-0000-0000-0000-00000000000e','e1000000-0000-0000-0000-00000000000e'); + +-- Create, register + confirm a drawing, save with elements still to_confirm. +insert into pg_temp.k select 'sheet', public.create_official_sheet('wf-sheet', pg_temp.doc(null,'to_confirm')); +insert into pg_temp.k select 'v1', id from public.anatomical_sheet_versions where sheet_id=(select id from pg_temp.k where key='sheet'); +insert into pg_temp.k select 'asset', public.register_sheet_asset((select id from pg_temp.k where key='sheet'), repeat('7',64), 1000, 'd.svg'); +reset role; +insert into storage.objects (bucket_id,name,metadata) values ('anatomical-sheet-assets', repeat('7',64)||'.svg', '{"size":1000}'); +set local role authenticated; select pg_temp.act('e0000000-0000-0000-0000-00000000000e','e1000000-0000-0000-0000-00000000000e'); +select public.confirm_sheet_asset_upload((select id from pg_temp.k where key='asset')); + +-- A stale revision is a conflict. +select throws_ok($$ select public.save_sheet_draft((select id from pg_temp.k where key='v1'), 9, pg_temp.doc(null,'to_confirm'), 'x') $$, + 'P0001', 'draft_conflict', 'save with a stale expected_revision is a conflict'); +-- An unchanged document is refused. +select public.save_sheet_draft((select id from pg_temp.k where key='v1'), 0, pg_temp.doc((select id from pg_temp.k where key='asset'),'to_confirm'), 'wire'); +select throws_ok($$ select public.save_sheet_draft((select id from pg_temp.k where key='v1'), 1, pg_temp.doc((select id from pg_temp.k where key='asset'),'to_confirm'), 'again') $$, + 'P0001', 'draft.unchanged', 'an unchanged save is refused'); + +-- Submit -> verifying; content is frozen. +insert into pg_temp.k select 'r1', public.submit_sheet_review((select id from pg_temp.k where key='v1'), 1, 'review please'); +select is((select status::text from public.anatomical_sheet_reviews where id=(select id from pg_temp.k where key='r1')), 'verifying', 'round is verifying'); +select throws_ok($$ select public.save_sheet_draft((select id from pg_temp.k where key='v1'), 1, pg_temp.doc((select id from pg_temp.k where key='asset'),'reviewed'), 'x') $$, + '55000', 'draft.frozen', 'the draft is frozen while a round runs'); +select throws_ok($$ select public.submit_sheet_review((select id from pg_temp.k where key='v1'), 1, 'x') $$, + '55000', 'round.open', 'a second non-terminal round is refused'); + +-- Open the round with a passing verdict (worker stand-in). +reset role; +select pg_temp.open_round((select id from pg_temp.k where key='r1'), (select id from pg_temp.k where key='asset'), repeat('7',64)); +set local role authenticated; + +-- Approval is refused while an element is to_confirm (D2: counts as not reviewed). +select pg_temp.act('e0000000-0000-0000-0000-0000000000f1','e1000000-0000-0000-0000-0000000000f1'); +select throws_ok($$ select public.decide_sheet_review((select id from pg_temp.k where key='r1'), true, 'ok') $$, + 'P0001', 'publish.inherited.present', 'approval refused while an element is to_confirm'); + +-- Reviewer requests changes; editor marks reviewed and resubmits. +select public.decide_sheet_review((select id from pg_temp.k where key='r1'), false, 'please mark reviewed'); +select is((select status::text from public.anatomical_sheet_reviews where id=(select id from pg_temp.k where key='r1')), 'changes_requested', 'round is changes_requested'); +select pg_temp.act('e0000000-0000-0000-0000-00000000000e','e1000000-0000-0000-0000-00000000000e'); +select public.save_sheet_draft((select id from pg_temp.k where key='v1'), 1, pg_temp.doc((select id from pg_temp.k where key='asset'),'reviewed'), 'all reviewed'); +insert into pg_temp.k select 'r2', public.submit_sheet_review((select id from pg_temp.k where key='v1'), 2, 'round 2'); +reset role; +select pg_temp.open_round((select id from pg_temp.k where key='r2'), (select id from pg_temp.k where key='asset'), repeat('7',64)); +set local role authenticated; + +-- An author of the round cannot acknowledge nor approve (separation). +select pg_temp.act('e0000000-0000-0000-0000-0000000000f2','e1000000-0000-0000-0000-0000000000f2'); +-- rev2 is a reviewer but NOT an author of this draft, so it may acknowledge. +-- Make rev2 an author by saving once would freeze; instead prove the rule with +-- the editor (edpub is an author and holds no reviewer grant): rights first. +select pg_temp.act('e0000000-0000-0000-0000-00000000000e','e1000000-0000-0000-0000-00000000000e'); +select throws_ok($$ select public.acknowledge_sheet_review_group((select id from pg_temp.k where key='r2'),'general',repeat('1',64)) $$, + '42501', 'rights.capability', 'the editor (author, no reviewer grant) cannot acknowledge'); + +-- Reviewer acknowledges every group, with a digest check and an unread guard. +select pg_temp.act('e0000000-0000-0000-0000-0000000000f1','e1000000-0000-0000-0000-0000000000f1'); +select throws_ok($$ select public.acknowledge_sheet_review_group((select id from pg_temp.k where key='r2'),'general',repeat('9',64)) $$, + 'P0001', 'review.digest', 'a digest mismatch is refused'); +select public.acknowledge_sheet_review_group((select id from pg_temp.k where key='r2'),'general',repeat('1',64)); +select public.acknowledge_sheet_review_group((select id from pg_temp.k where key='r2'),'view:main',repeat('2',64)); +-- approval refused while one group is still uncovered +select throws_ok($$ select public.decide_sheet_review((select id from pg_temp.k where key='r2'), true, 'ok') $$, + 'P0001', 'review.groups.uncovered', 'approval refused while a group is uncovered'); +select public.acknowledge_sheet_review_group((select id from pg_temp.k where key='r2'),'zone:z1',repeat('3',64)); +select public.decide_sheet_review((select id from pg_temp.k where key='r2'), true, 'approved'); +select is((select status::text from public.anatomical_sheet_reviews where id=(select id from pg_temp.k where key='r2')), 'approved', 'round approved'); + +-- A reviewer cannot publish; the publisher publishes. +select throws_ok($$ select public.publish_sheet_version((select id from pg_temp.k where key='r2')) $$, + '42501', 'rights.capability', 'a reviewer cannot publish'); +select pg_temp.act('e0000000-0000-0000-0000-00000000000e','e1000000-0000-0000-0000-00000000000e'); +select is(public.publish_sheet_version((select id from pg_temp.k where key='r2')), (select id from pg_temp.k where key='v1'), 'the publisher publishes the approved round'); +select is((select status::text from public.anatomical_sheet_versions where id=(select id from pg_temp.k where key='v1')), 'published', 'version is published'); +select is((select (public.get_sheet_version((select id from pg_temp.k where key='v1'))) ->> 'fingerprint'), repeat('a',64), 'the fingerprint comes from the verdict'); + +-- An asset row cannot be mutated (F16); the reader account is seeded here too. +reset role; +select throws_ok($$ update public.anatomical_sheet_assets set sha256 = repeat('0',64) where id=(select id from pg_temp.k where key='asset') $$, + '42501', null, 'an asset row sha256 is immutable (F16)'); +insert into auth.users (id,email,email_confirmed_at) values ('e0000000-0000-0000-0000-0000000000cc','reader@wf.local',now()); +insert into public.anatomical_catalog_grants (user_id,grant_kind,reason,granted_by) + values ('e0000000-0000-0000-0000-0000000000cc','catalog_reader','beta','e0000000-0000-0000-0000-000000000001'); + +-- A catalogue reader sees the published version and its drawing; not the grants. +set local role authenticated; +select pg_temp.act('e0000000-0000-0000-0000-0000000000cc', gen_random_uuid()); +select is((select jsonb_array_length(public.list_official_catalog())), 1, 'the reader sees one catalogue sheet'); +select is((select (public.get_sheet_version((select id from pg_temp.k where key='v1'))) ->> 'status'), 'published', + 'the reader reads the published version by id'); + +-- Deprecate, then the version is still readable by id (D8). +select pg_temp.act('e0000000-0000-0000-0000-00000000000e','e1000000-0000-0000-0000-00000000000e'); +select public.deprecate_sheet_version((select id from pg_temp.k where key='v1'), 'superseded'); +select pg_temp.act('e0000000-0000-0000-0000-0000000000cc', gen_random_uuid()); +select is((select (public.get_sheet_version((select id from pg_temp.k where key='v1'))) ->> 'status'), 'deprecated', + 'a deprecated version stays readable by id (D8)'); +select is((select jsonb_array_length(public.list_official_catalog())), 0, 'the sheet leaves the catalogue list once its last version is deprecated'); + +-- ============ Species rules (§7.2) ============ +select pg_temp.act('e0000000-0000-0000-0000-00000000000e','e1000000-0000-0000-0000-00000000000e'); +select is(public.create_species('tapir','Tapir','Tapir',60), 'tapir', 'an editor creates an inactive species'); +select is( + (select (g ->> 'active')::boolean from jsonb_array_elements(public.list_catalog_species()) g where g ->> 'id' = 'tapir'), + false, 'the new species is inactive (seen through the admin list)'); +select throws_ok($$ select public.create_species('other','x','x') $$, 'P0001', 'invalid_input', 'the id other is refused'); +select throws_ok($$ select public.activate_species('tapir') $$, '42501', 'rights.owner', 'an editor cannot activate a species'); +-- inactive species invisible in the animal path (species_select_active unchanged) +select is((select count(*) from public.species where id='tapir'), 0::bigint, 'an inactive species is invisible under species_select_active (animal forms)'); +select pg_temp.act('e0000000-0000-0000-0000-000000000001','e1000000-0000-0000-0000-000000000001'); +select is(public.activate_species('tapir'), 'tapir', 'the owner activates the species'); +select is((select active from public.species where id='tapir'), true, 'the species is now active'); + +-- ============ Working copy restricted to the historical sheet (§14.3) ============ +select pg_temp.act('e0000000-0000-0000-0000-00000000000e','e1000000-0000-0000-0000-00000000000e'); +select throws_ok($$ select public.create_sheet_working_copy((select id from pg_temp.k where key='v1'), 'copie') $$, + 'P0001', 'working_copy.source_invalid', 'a working copy of a non-historical version is refused'); + +-- ============ Base only from a round-published version (§6.2) ============ +-- v1 was published through r2 (a V1-2 round), so a new draft takes it as base +-- (passed explicitly, since deprecating the only published version cleared the +-- sheet's current version). +insert into pg_temp.k select 'v2', public.create_sheet_draft( + (select id from pg_temp.k where key='sheet'), (select id from pg_temp.k where key='v1'), 'new edition'); +reset role; +select is( + (select (source_version_id = (select id from pg_temp.k where key='v1')) from public.anatomical_sheet_versions where id=(select id from pg_temp.k where key='v2')), + true, 'a draft derived from a round-published version records it as its base'); +-- The publish gate: a direct UPDATE of a real draft to published is refused for +-- the table owner (no approved round named). +select throws_ok($$ update public.anatomical_sheet_versions set status='published', published_at=now(), document_fingerprint=repeat('a',64) + where id=(select id from pg_temp.k where key='v2') $$, + '42501', 'publish.review.missing', 'no direct UPDATE publishes a draft, even for the table owner'); + +select * from finish(); +rollback;