feat(supabase): V1-2.1 M4/M5 secure sheet access and review workflow

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.
This commit is contained in:
bchanot committed 2026-10-28 15:52:49 +01:00
1 parent 9c13bae4bc
commit 77e5fa4cf5
33 files changed
+4613 -1617

No files matched your search

+13
View File
@@ -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). 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. 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. 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`).
+3
View File
@@ -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. - 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. - 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. - 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.
+9
View File
@@ -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. 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. 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. 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.
+8 -1
View File
@@ -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) - [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 - [ ] 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 - [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) ## 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. 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.
@@ -156,21 +156,24 @@ impl Storage {
Ok(true) 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<RowState, UploadError> { pub fn row_state(&self, entry: &AssetEntry) -> Result<RowState, UploadError> {
let url = format!( let url = format!("{}/rest/v1/rpc/get_sheet_asset_state", self.origin);
"{}/rest/v1/anatomical_sheet_assets?id=eq.{}&select=sha256,uploaded_at", let body = json!({ "asset_id": entry.svg_asset_id });
self.origin, entry.svg_asset_id let reply = self.exchange(MAX_BODY, |agent, me| {
); me.authorised(agent.post(&url)).send_json(&body)
let reply = self.exchange(MAX_BODY, |agent, me| me.authorised(agent.get(&url)).call())?; })?;
check_access(&reply)?; check_access(&reply)?;
expect_status(&reply, 200, "row read")?; expect_status(&reply, 200, "row read")?;
let rows: Vec<Value> = serde_json::from_slice(&reply.body) let row: Value = serde_json::from_slice(&reply.body)
.map_err(|_| refuse(UploadKind::Handshake, "the row answer is not a JSON list"))?; .map_err(|_| refuse(UploadKind::Handshake, "the row answer is not JSON"))?;
Ok(match rows.first() { // The RPC returns JSON null for an unknown asset (no row yet).
None => RowState::Unknown, if row.is_null() {
Some(row) => row_state_of(row, &entry.sha256), return Ok(RowState::Unknown);
}) }
Ok(row_state_of(&row, &entry.sha256))
} }
/// Marks the asset bytes as present (idempotent on the server, service role only). /// Marks the asset bytes as present (idempotent on the server, service role only).
+27 -27
View File
@@ -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 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) > 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-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 > 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 ; 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-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 ; 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-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 ; 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-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 ; 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-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 ; 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-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 ; 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-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 ; 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 > 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 ; 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-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 ; 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-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 ; 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-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 ; 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-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 ; 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-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 ; 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-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 ; 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 > 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 ; 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 > 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 ; 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 > 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 ; 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-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 ; 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 > 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 ; 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 > 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 ; 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 > 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 ; 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 > 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 ; 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 > 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 ; 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 > 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 ; 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-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 ; 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 > 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_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 > 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-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.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 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
Can't render this file because it contains an unexpected character in line 12 and column 108.
+12 -112
View File
@@ -1,43 +1,22 @@
//! Conformance of the integrity rules across the three implementations (review III.4): //! Conformance of the integrity rules (review III.4): the fixtures under
//! the fixtures under `tests/conformance` carry what the TypeScript rules reported (frozen by //! `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. //! `packages/domain/tests/r2-conformance.test.ts`). This suite checks the Rust
//! This suite checks the Rust rules against the first and generates the pgTAP file that checks //! rules against them.
//! 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`). //! 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)] #![allow(clippy::disallowed_methods, clippy::unwrap_used, clippy::expect_used)]
mod common; mod common;
use std::collections::BTreeSet;
use faunosteo_core::domain::js::parse_json; 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; 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)> { fn fixtures() -> Vec<(String, Value)> {
let dir = format!("{}/tests/conformance", env!("CARGO_MANIFEST_DIR")); let dir = format!("{}/tests/conformance", env!("CARGO_MANIFEST_DIR"));
let mut names: Vec<String> = std::fs::read_dir(&dir) let mut names: Vec<String> = std::fs::read_dir(&dir)
@@ -55,14 +34,6 @@ fn fixtures() -> Vec<(String, Value)> {
.collect() .collect()
} }
fn sql_codes(fixture: &Value) -> Vec<String> {
let codes = fixture["sql"].as_array().unwrap();
codes
.iter()
.map(|c| c.as_str().unwrap().to_owned())
.collect()
}
#[test] #[test]
fn the_rust_rules_report_what_the_typescript_rules_reported() { fn the_rust_rules_report_what_the_typescript_rules_reported() {
let all = fixtures(); let all = fixtures();
@@ -78,74 +49,3 @@ fn the_rust_rules_report_what_the_typescript_rules_reported() {
assert_eq!(issues, fixture["rust"]["issues"], "{name}"); 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<String> = 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<String> = 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)"
);
}
+11 -6
View File
@@ -89,19 +89,21 @@ fn route(state: &mut State, method: &str, path: &str, body: Vec<u8>) -> (u16, Ve
state.objects.insert(key.to_owned(), body); state.objects.insert(key.to_owned(), body);
(200, b"{}".to_vec()) (200, b"{}".to_vec())
} }
("GET", None) if path.starts_with("/rest/v1/anatomical_sheet_assets") => { ("POST", None) if path.ends_with("/rpc/get_sheet_asset_state") => {
let rows = match &state.row { // The operator read RPC (V1-2.1 F12): JSON null when no row exists,
None => "[]".to_owned(), // else an object with sha256 and uploaded_at.
let reply = match &state.row {
None => "null".to_owned(),
Some((sha, confirmed)) => { Some((sha, confirmed)) => {
let at = if *confirmed { let at = if *confirmed {
"\"2026-10-23T00:00:00Z\"" "\"2026-10-23T00:00:00Z\""
} else { } else {
"null" "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") => { ("POST", None) if path.ends_with("/rpc/confirm_sheet_asset_upload") => {
if state.fail_confirm { if state.fail_confirm {
@@ -168,7 +170,10 @@ fn text(output: &Output) -> String {
fn writes(state: &Shared) -> usize { fn writes(state: &Shared) -> usize {
let log = &state.lock().unwrap().log; 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] #[test]
-105
View File
@@ -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<string> = 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<string> {
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
}
+410 -23
View File
@@ -9,6 +9,71 @@ export type Json =
export type Database = { export type Database = {
public: { public: {
Tables: { 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: { anatomical_sheet_assets: {
Row: { Row: {
byte_size: number 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: { anatomical_sheet_versions: {
Row: { Row: {
authors: string[]
change_note: string change_note: string
content: NonNullable<Json> content: NonNullable<Json>
created_at: string created_at: string
created_by: string | null created_by: string | null
deprecated_at: string | null deprecated_at: string | null
deprecated_by: string | null deprecated_by: string | null
document_fingerprint: string | null
document_schema_version: number document_schema_version: number
id: string id: string
published_at: string | null published_at: string | null
published_by: string | null published_by: string | null
published_review_id: string | null
revision: number
sheet_id: string sheet_id: string
source_version_id: string | null
status: Database['public']['Enums']['sheet_version_status'] status: Database['public']['Enums']['sheet_version_status']
updated_at: string updated_at: string
version_number: number version_number: number
} }
ComputedFields: never ComputedFields: never
Insert: { Insert: {
authors?: string[]
change_note?: string change_note?: string
content: NonNullable<Json> content: NonNullable<Json>
created_at?: string created_at?: string
created_by?: string | null created_by?: string | null
deprecated_at?: string | null deprecated_at?: string | null
deprecated_by?: string | null deprecated_by?: string | null
document_fingerprint?: string | null
document_schema_version: number document_schema_version: number
id?: string id?: string
published_at?: string | null published_at?: string | null
published_by?: string | null published_by?: string | null
published_review_id?: string | null
revision?: number
sheet_id: string sheet_id: string
source_version_id?: string | null
status?: Database['public']['Enums']['sheet_version_status'] status?: Database['public']['Enums']['sheet_version_status']
updated_at?: string updated_at?: string
version_number: number version_number: number
} }
Update: { Update: {
authors?: string[]
change_note?: string change_note?: string
content?: NonNullable<Json> content?: NonNullable<Json>
created_at?: string created_at?: string
created_by?: string | null created_by?: string | null
deprecated_at?: string | null deprecated_at?: string | null
deprecated_by?: string | null deprecated_by?: string | null
document_fingerprint?: string | null
document_schema_version?: number document_schema_version?: number
id?: string id?: string
published_at?: string | null published_at?: string | null
published_by?: string | null published_by?: string | null
published_review_id?: string | null
revision?: number
sheet_id?: string sheet_id?: string
source_version_id?: string | null
status?: Database['public']['Enums']['sheet_version_status'] status?: Database['public']['Enums']['sheet_version_status']
updated_at?: string updated_at?: string
version_number?: number version_number?: number
@@ -133,6 +416,13 @@ export type Database = {
referencedRelation: 'profiles' referencedRelation: 'profiles'
referencedColumns: ['id'] 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' foreignKeyName: 'anatomical_sheet_versions_sheet_id_fkey'
columns: ['sheet_id'] columns: ['sheet_id']
@@ -140,6 +430,13 @@ export type Database = {
referencedRelation: 'anatomical_sheets' referencedRelation: 'anatomical_sheets'
referencedColumns: ['id'] referencedColumns: ['id']
}, },
{
foreignKeyName: 'anatomical_sheet_versions_source_version_id_fkey'
columns: ['source_version_id']
isOneToOne: false
referencedRelation: 'anatomical_sheet_versions'
referencedColumns: ['id']
},
] ]
} }
anatomical_sheets: { anatomical_sheets: {
@@ -161,6 +458,7 @@ export type Database = {
status: Database['public']['Enums']['sheet_status'] status: Database['public']['Enums']['sheet_status']
updated_at: string updated_at: string
visibility: Database['public']['Enums']['sheet_visibility'] visibility: Database['public']['Enums']['sheet_visibility']
working_copy_source_version_id: string | null
} }
ComputedFields: never ComputedFields: never
Insert: { Insert: {
@@ -181,6 +479,7 @@ export type Database = {
status?: Database['public']['Enums']['sheet_status'] status?: Database['public']['Enums']['sheet_status']
updated_at?: string updated_at?: string
visibility?: Database['public']['Enums']['sheet_visibility'] visibility?: Database['public']['Enums']['sheet_visibility']
working_copy_source_version_id?: string | null
} }
Update: { Update: {
archived_at?: string | null archived_at?: string | null
@@ -200,6 +499,7 @@ export type Database = {
status?: Database['public']['Enums']['sheet_status'] status?: Database['public']['Enums']['sheet_status']
updated_at?: string updated_at?: string
visibility?: Database['public']['Enums']['sheet_visibility'] visibility?: Database['public']['Enums']['sheet_visibility']
working_copy_source_version_id?: string | null
} }
Relationships: [ Relationships: [
{ {
@@ -237,6 +537,13 @@ export type Database = {
referencedRelation: 'species' referencedRelation: 'species'
referencedColumns: ['id'] 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: { animal_client_relations: {
@@ -738,6 +1045,11 @@ export type Database = {
} }
Functions: { Functions: {
ack_purge: { Args: { purge_id: string }; Returns: undefined } 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 } archive_anatomical_sheet: { Args: { sheet_id: string }; Returns: string }
begin_avatar_upload: { begin_avatar_upload: {
Args: { declared_mime: string; declared_size: number } Args: { declared_mime: string; declared_size: number }
@@ -772,6 +1084,10 @@ export type Database = {
}[] }[]
} }
client_archive_preview: { Args: { client_id: string }; Returns: Json } 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: { complete_avatar_job: {
Args: { Args: {
asset_id: string asset_id: string
@@ -786,18 +1102,6 @@ export type Database = {
Args: { asset_id: string } Args: { asset_id: string }
Returns: 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: { create_animal: {
Args: { Args: {
birth_date?: string birth_date?: string
@@ -841,6 +1145,10 @@ export type Database = {
} }
Returns: Json Returns: Json
} }
create_official_sheet: {
Args: { document: Json; slug: string }
Returns: string
}
create_sheet_draft: { create_sheet_draft: {
Args: { Args: {
change_note?: string change_note?: string
@@ -849,6 +1157,23 @@ export type Database = {
} }
Returns: string 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_anatomical_sheet: { Args: { sheet_id: string }; Returns: string }
delete_sheet_asset: { Args: { asset_id: string }; Returns: string } delete_sheet_asset: { Args: { asset_id: string }; Returns: string }
delete_sheet_version: { Args: { version_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 } Args: { max_age_seconds: number }
Returns: 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: { Args: {
name: string expires_at?: string
slug: string kind: Database['public']['Enums']['catalog_grant_kind']
source_version_id: string reason: string
visibility?: Database['public']['Enums']['sheet_visibility'] user_id: string
verification_note?: string
} }
Returns: string Returns: string
} }
@@ -884,6 +1212,8 @@ export type Database = {
} }
Returns: string Returns: string
} }
list_catalog_grants: { Args: Record<PropertyKey, never>; Returns: Json }
list_catalog_species: { Args: Record<PropertyKey, never>; Returns: Json }
list_client_animals: { list_client_animals: {
Args: { Args: {
after_id?: string after_id?: string
@@ -909,8 +1239,10 @@ export type Database = {
started_on: string started_on: string
}[] }[]
} }
list_official_catalog: { Args: Record<PropertyKey, never>; Returns: Json }
lookup_catalog_account: { Args: { email: string }; Returns: Json }
mark_quarantine_purged: { Args: { asset_id: string }; Returns: undefined } 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: { register_sheet_asset: {
Args: { Args: {
byte_size: number byte_size: number
@@ -925,7 +1257,15 @@ export type Database = {
Returns: undefined Returns: undefined
} }
remove_avatar: { Args: Record<PropertyKey, never>; Returns: number } remove_avatar: { Args: Record<PropertyKey, never>; Returns: number }
rename_species: {
Args: { id: string; name_en: string; name_fr: string }
Returns: string
}
restore_anatomical_sheet: { Args: { sheet_id: 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: { revoke_platform_role: {
Args: { Args: {
reason?: string reason?: string
@@ -934,6 +1274,15 @@ export type Database = {
} }
Returns: string Returns: string
} }
save_sheet_draft: {
Args: {
change_note?: string
document: Json
expected_revision: number
version_id: string
}
Returns: Json
}
search_animals: { search_animals: {
Args: { Args: {
after_id?: string after_id?: string
@@ -987,11 +1336,8 @@ export type Database = {
Args: { archived: boolean; client_id: string } Args: { archived: boolean; client_id: string }
Returns: Json Returns: Json
} }
set_sheet_visibility: { submit_sheet_review: {
Args: { Args: { expected_revision: number; note?: string; version_id: string }
sheet_id: string
visibility: Database['public']['Enums']['sheet_visibility']
}
Returns: string Returns: string
} }
update_animal: { update_animal: {
@@ -1033,10 +1379,23 @@ export type Database = {
} }
Returns: Json Returns: Json
} }
update_inactive_species: {
Args: {
id: string
name_en: string
name_fr: string
sort_order: number
}
Returns: string
}
void_animal_client_relation: { void_animal_client_relation: {
Args: { expected_revision: number; relation_id: string } Args: { expected_revision: number; relation_id: string }
Returns: Json Returns: Json
} }
withdraw_sheet_review: {
Args: { note?: string; review_id: string }
Returns: string
}
} }
Enums: { Enums: {
animal_relation_role: 'owner' | 'keeper' | 'contact' animal_relation_role: 'owner' | 'keeper' | 'contact'
@@ -1047,9 +1406,22 @@ export type Database = {
| 'clean' | 'clean'
| 'rejected' | 'rejected'
| 'deleted' | 'deleted'
catalog_grant_kind:
| 'catalog_reader'
| 'sheet_editor'
| 'sheet_reviewer'
| 'sheet_publisher'
client_kind: 'person' | 'organization' client_kind: 'person' | 'organization'
platform_role: 'owner' | 'admin' | 'moderator' | 'support' platform_role: 'owner' | 'admin' | 'moderator' | 'support'
sheet_round_status:
| 'verifying'
| 'open'
| 'approved'
| 'changes_requested'
| 'withdrawn'
| 'verification_failed'
sheet_status: 'active' | 'archived' | 'deleted' sheet_status: 'active' | 'archived' | 'deleted'
sheet_verification_outcome: 'failed' | 'unavailable'
sheet_version_status: 'draft' | 'published' | 'deprecated' sheet_version_status: 'draft' | 'published' | 'deprecated'
sheet_visibility: 'private' | 'public' sheet_visibility: 'private' | 'public'
workspace_kind: 'personal' workspace_kind: 'personal'
@@ -1190,9 +1562,24 @@ export const Constants = {
'rejected', 'rejected',
'deleted', 'deleted',
], ],
catalog_grant_kind: [
'catalog_reader',
'sheet_editor',
'sheet_reviewer',
'sheet_publisher',
],
client_kind: ['person', 'organization'], client_kind: ['person', 'organization'],
platform_role: ['owner', 'admin', 'moderator', 'support'], platform_role: ['owner', 'admin', 'moderator', 'support'],
sheet_round_status: [
'verifying',
'open',
'approved',
'changes_requested',
'withdrawn',
'verification_failed',
],
sheet_status: ['active', 'archived', 'deleted'], sheet_status: ['active', 'archived', 'deleted'],
sheet_verification_outcome: ['failed', 'unavailable'],
sheet_version_status: ['draft', 'published', 'deprecated'], sheet_version_status: ['draft', 'published', 'deprecated'],
sheet_visibility: ['private', 'public'], sheet_visibility: ['private', 'public'],
workspace_kind: ['personal'], workspace_kind: ['personal'],
+15 -6
View File
@@ -44,13 +44,22 @@ export {
/** owner | admin | moderator | support. Not a professional status. */ /** owner | admin | moderator | support. Not a professional status. */
export { fetchOwnPlatformRoles, type PlatformRole } from './platform-roles' export { fetchOwnPlatformRoles, type PlatformRole } from './platform-roles'
export { export {
SHEET_FAILURE_KINDS,
SheetFailure,
classifySheetError,
failSheet,
grantCatalogRight,
revokeCatalogRight,
listCatalogGrants,
createOfficialSheet,
saveSheetDraft,
submitSheetReview,
decideSheetReview,
publishSheetVersion, publishSheetVersion,
SheetPublishError, getSheetVersion,
type SheetCheckOutcome, listOfficialCatalog,
type SheetIssue, type SheetFailureKind,
type SheetPublishErrorKind, } from './sheets'
type SheetValidator,
} from './anatomical-sheets'
export { export {
ASSET_FAILURE_KINDS, ASSET_FAILURE_KINDS,
ASSET_OWNER_COLUMNS, ASSET_OWNER_COLUMNS,
+227
View File
@@ -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.<kind>`), 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<string> = 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<string> {
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<string> {
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<Json> {
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<string> {
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<Json> {
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<string> {
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<string> {
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<string> {
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<Json> {
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<Json> {
const { data, error, status } = await client.rpc('list_official_catalog')
if (error) failSheet(error, status)
return data
}
@@ -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([])
})
})
+75 -12
View File
@@ -55,6 +55,19 @@ const expectedColumns = {
'updated_at', 'updated_at',
'workspace_id', '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: [ anatomical_sheet_assets: [
'byte_size', 'byte_size',
'content_type', 'content_type',
@@ -66,18 +79,58 @@ const expectedColumns = {
'sheet_id', 'sheet_id',
'uploaded_at', '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: [ anatomical_sheet_versions: [
'authors',
'change_note', 'change_note',
'content', 'content',
'created_at', 'created_at',
'created_by', 'created_by',
'deprecated_at', 'deprecated_at',
'deprecated_by', 'deprecated_by',
'document_fingerprint',
'document_schema_version', 'document_schema_version',
'id', 'id',
'published_at', 'published_at',
'published_by', 'published_by',
'published_review_id',
'revision',
'sheet_id', 'sheet_id',
'source_version_id',
'status', 'status',
'updated_at', 'updated_at',
'version_number', 'version_number',
@@ -100,6 +153,7 @@ const expectedColumns = {
'status', 'status',
'updated_at', 'updated_at',
'visibility', 'visibility',
'working_copy_source_version_id',
], ],
assets: [ assets: [
'attempts', 'attempts',
@@ -197,15 +251,26 @@ const expectedFunctionArgs = {
complete_avatar_job: ['asset_id', 'byte_size', 'lock_token', 'sha256'], complete_avatar_job: ['asset_id', 'byte_size', 'lock_token', 'sha256'],
confirm_asset_upload: ['asset_id'], confirm_asset_upload: ['asset_id'],
confirm_sheet_asset_upload: ['asset_id'], confirm_sheet_asset_upload: ['asset_id'],
create_anatomical_sheet: [ acknowledge_sheet_review_group: ['group_digest', 'group_key', 'review_id'],
'description', activate_species: ['id'],
'document', comment_sheet_review: ['body', 'group_key', 'review_id'],
'name', create_official_sheet: ['document', 'slug'],
'official', create_species: ['id', 'name_en', 'name_fr', 'sort_order'],
'slug', create_sheet_working_copy: ['slug', 'source_version_id'],
'species_id', decide_sheet_review: ['approve', 'note', 'review_id'],
'visibility', 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: [ create_animal: [
'birth_date', 'birth_date',
'birth_year', 'birth_year',
@@ -247,11 +312,10 @@ const expectedFunctionArgs = {
deprecate_sheet_version: ['reason', 'version_id'], deprecate_sheet_version: ['reason', 'version_id'],
end_animal_client_relation: ['ended_on', 'expected_revision', 'relation_id'], end_animal_client_relation: ['ended_on', 'expected_revision', 'relation_id'],
expire_pending_uploads: ['max_age_seconds'], expire_pending_uploads: ['max_age_seconds'],
fork_anatomical_sheet: ['name', 'slug', 'source_version_id', 'visibility'],
grant_platform_role: ['role', 'target_user_id'], grant_platform_role: ['role', 'target_user_id'],
list_client_animals: ['after_id', 'after_sort', 'client_id', 'page_size'], list_client_animals: ['after_id', 'after_sort', 'client_id', 'page_size'],
mark_quarantine_purged: ['asset_id'], 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'], register_sheet_asset: ['byte_size', 'file_name', 'sha256', 'sheet_id'],
reject_avatar_job: ['asset_id', 'lock_token', 'reason'], reject_avatar_job: ['asset_id', 'lock_token', 'reason'],
remove_avatar: [], remove_avatar: [],
@@ -276,7 +340,6 @@ const expectedFunctionArgs = {
], ],
set_animal_archived: ['animal_id', 'archived'], set_animal_archived: ['animal_id', 'archived'],
set_client_archived: ['archived', 'client_id'], set_client_archived: ['archived', 'client_id'],
set_sheet_visibility: ['sheet_id', 'visibility'],
update_animal: [ update_animal: [
'animal_id', 'animal_id',
'birth_date', 'birth_date',
@@ -26,6 +26,34 @@ create table auth.users (
updated_at timestamptz default now() 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() create or replace function auth.uid()
returns uuid returns uuid
language sql language sql
+103
View File
@@ -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<string, unknown>
}
async function authRequest(
method: string,
path: string,
token: string,
body?: unknown,
): Promise<MfaResult> {
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<string, unknown> = {}
try {
parsed = JSON.parse(text) as Record<string, unknown>
} 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<MfaResult> {
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<MfaResult> {
await new Promise((resolve) => setTimeout(resolve, msToNextStep() + 200))
return verifyTotp(token, factor)
}
export function unenrol(token: string, factorId: string): Promise<MfaResult> {
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<string, unknown> {
const payload = token.split('.')[1] ?? ''
return JSON.parse(Buffer.from(payload, 'base64url').toString('utf8')) as Record<
string,
unknown
>
}
@@ -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<string> {
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)
})
+45
View File
@@ -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)
}
@@ -18,6 +18,9 @@ import {
sql, sql,
sqlOutcome, sqlOutcome,
stack, stack,
} from './stack'
import { enrolTotp, verifyTotp } from './mfa'
import {
uniqueEmail, uniqueEmail,
type Account, type Account,
} from './stack' } 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 () => { 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( const owner = await signIn(
'owner@faunosteo.local', 'owner@faunosteo.local',
'LocalDev-only-password-1', '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( const grant = await rpc(
'grant_platform_role', 'grant_platform_role',
{ target_user_id: b.id, role: 'support' }, { target_user_id: b.id, role: 'support' },
+1 -1
View File
@@ -246,7 +246,7 @@ case "${1:-}" in
else else
printf '%s\n' "$out" > packages/supabase/src/database.types.ts; echo "== types written" printf '%s\n' "$out" > packages/supabase/src/database.types.ts; echo "== types written"
fi ;; 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 "$@" ;; e2e-shell) shift; load_secrets; with_sandbox_env node_modules/.bin/pnpm --filter @faunosteo/app e2e:shell "$@" ;;
sql) load_secrets; sb_psql ;; sql) load_secrets; sb_psql ;;
*) sed -n '2,23p' "$0"; exit 1 ;; *) sed -n '2,23p' "$0"; exit 1 ;;
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+1 -1
View File
@@ -62,7 +62,7 @@ select is(
(select string_agg(p.proname::text, ',' order by p.proname::text collate "C") (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 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')), 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' 'authenticated executes only the policy predicates in private'
); );
+85 -83
View File
@@ -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; begin;
select plan(28); select plan(25);
insert into auth.users (id, email) values insert into auth.users (id, email, email_confirmed_at) values
('00000000-0000-0000-0000-000000000001', 'root@test.local'), ('00000000-0000-0000-0000-000000000001', 'root@test.local', now()),
('00000000-0000-0000-0000-00000000000a', 'alice@test.local'), ('00000000-0000-0000-0000-00000000000a', 'alice@test.local', now()),
('00000000-0000-0000-0000-00000000000b', 'bob@test.local'), ('00000000-0000-0000-0000-00000000000b', 'bob@test.local', now()),
('00000000-0000-0000-0000-00000000000c', 'carol@test.local'); ('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 ok(not private.is_platform_owner('00000000-0000-0000-0000-000000000001'), 'fresh account has no owner role');
select lives_ok( select lives_ok(
$$ select private.assign_platform_role(null, '00000000-0000-0000-0000-000000000001', 'owner') $$, $$ 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_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_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; 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 lives_ok(
$$ select public.grant_platform_role('00000000-0000-0000-0000-00000000000a', 'admin') $$, $$ select public.grant_platform_role('00000000-0000-0000-0000-00000000000a', 'admin') $$,
'owner grants admin' 'owner at aal2 grants admin'
); );
select throws_ok( select throws_ok(
$$ select public.grant_platform_role('00000000-0000-0000-0000-00000000000a', 'admin') $$, $$ select public.grant_platform_role('00000000-0000-0000-0000-00000000000a', 'admin') $$,
'23505', 'P0001', 'role_active', 'granting an active role twice is refused'
null,
'granting an active role twice is refused'
); );
select throws_ok( select throws_ok(
$$ select public.grant_platform_role('00000000-0000-0000-0000-000000000001', 'admin') $$, $$ select public.grant_platform_role('00000000-0000-0000-0000-000000000001', 'admin') $$,
'42501', '42501', 'self_target', 'owner cannot change their own roles'
null,
'owner cannot change their own roles'
); );
select throws_ok( select throws_ok(
$$ select public.grant_platform_role(gen_random_uuid(), 'support') $$, $$ select public.grant_platform_role(gen_random_uuid(), 'support') $$,
'P0002', 'P0001', 'target_invalid', 'unknown target is refused'
null,
'unknown target is refused'
); );
-- 3. Alice (admin) may delegate moderator/support, nothing above -- 4. A grant to a target with no verified factor is refused (AR-1 B).
select set_config('request.jwt.claims', '{"sub":"00000000-0000-0000-0000-00000000000a","role":"authenticated"}', true); 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 lives_ok(
$$ select public.grant_platform_role('00000000-0000-0000-0000-00000000000b', 'moderator') $$, $$ select public.grant_platform_role('00000000-0000-0000-0000-00000000000b', 'moderator') $$,
'admin grants moderator' 'admin grants moderator'
); );
select throws_ok( select throws_ok(
$$ select public.grant_platform_role('00000000-0000-0000-0000-00000000000b', 'admin') $$, $$ select public.grant_platform_role('00000000-0000-0000-0000-00000000000b', 'admin') $$,
'42501', '42501', 'forbidden', 'admin cannot grant admin'
null,
'admin cannot grant admin'
); );
select throws_ok( select throws_ok(
$$ select public.grant_platform_role('00000000-0000-0000-0000-00000000000b', 'owner') $$, $$ select public.grant_platform_role('00000000-0000-0000-0000-00000000000b', 'owner') $$,
'42501', '42501', 'forbidden', 'admin cannot grant owner'
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'
); );
-- 4. Direct writes are impossible for the API role -- 6. Direct writes are impossible for the API role.
select throws_ok( select throws_ok(
$$ insert into public.profile_roles (user_id, role) values ('00000000-0000-0000-0000-00000000000a', 'owner') $$, $$ insert into public.profile_roles (user_id, role) values ('00000000-0000-0000-0000-00000000000a', 'owner') $$,
'42501', '42501', null, 'admin cannot insert a role row directly'
null,
'admin cannot insert a role row directly'
); );
select throws_ok( select throws_ok(
$$ update public.profile_roles set role = 'owner' where user_id = '00000000-0000-0000-0000-00000000000a' $$, $$ update public.profile_roles set role = 'owner' where user_id = '00000000-0000-0000-0000-00000000000a' $$,
'42501', '42501', null, 'admin cannot update role rows directly'
null,
'admin cannot update role rows directly'
); );
select throws_ok( select throws_ok(
$$ delete from public.profile_roles $$, $$ delete from public.profile_roles $$,
'42501', '42501', null, 'admin cannot delete role rows directly'
null,
'admin cannot delete role rows directly'
); );
-- 5. Bob (moderator) cannot delegate; sees only his own grants; carol sees nothing -- 7. service_role cannot write the table nor execute the RPCs (F17).
select set_config('request.jwt.claims', '{"sub":"00000000-0000-0000-0000-00000000000b","role":"authenticated"}', true); 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 throws_ok(
$$ select public.grant_platform_role('00000000-0000-0000-0000-00000000000c', 'support') $$, $$ select public.grant_platform_role('00000000-0000-0000-0000-00000000000c', 'support') $$,
'42501', '42501', 'forbidden', 'moderator at aal2 cannot grant any role'
null,
'moderator cannot grant any role'
); );
select results_eq( select results_eq(
$$ select user_id, role::text from public.profile_roles $$, $$ select user_id, role::text from public.profile_roles $$,
$$ values ('00000000-0000-0000-0000-00000000000b'::uuid, 'moderator'::text) $$, $$ values ('00000000-0000-0000-0000-00000000000b'::uuid, 'moderator'::text) $$,
'moderator sees only his own grant rows' '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) -- 9. Anonymous
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
set local role anon; set local role anon;
select set_config('request.jwt.claims', '', true); select set_config('request.jwt.claims', '', true);
select throws_ok( select throws_ok(
$$ select public.grant_platform_role('00000000-0000-0000-0000-00000000000c', 'support') $$, $$ select public.grant_platform_role('00000000-0000-0000-0000-00000000000c', 'support') $$,
'42501', '42501', null, 'anon cannot call grant_platform_role'
null,
'anon cannot call grant_platform_role'
); );
-- 8. Revocation and deactivation -- 10. Revocation at aal2 and deactivation.
set local role authenticated; 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 lives_ok(
$$ select public.revoke_platform_role('00000000-0000-0000-0000-00000000000b', 'moderator', 'test') $$, $$ 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'); select ok(not private.is_platform_moderator('00000000-0000-0000-0000-00000000000b'), 'revoked role no longer counts');
reset role; reset role;
update public.profiles set active = false where id = '00000000-0000-0000-0000-00000000000a'; 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'); 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() update public.profile_roles set revoked_at = now()
where role = 'owner' and revoked_at is null and user_id <> '00000000-0000-0000-0000-000000000001'; 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 throws_ok(
$$ select private.withdraw_platform_role(null, '00000000-0000-0000-0000-000000000001', 'owner', 'oops') $$, $$ select private.withdraw_platform_role(null, '00000000-0000-0000-0000-000000000001', 'owner', 'oops') $$,
'42501', 'P0001', 'last_owner', 'the last owner cannot be revoked'
null,
'the last owner cannot be revoked'
); );
select * from finish(); select * from finish();
+12 -5
View File
@@ -3,10 +3,16 @@
begin; begin;
select plan(12); select plan(12);
insert into auth.users (id, email) values insert into auth.users (id, email, email_confirmed_at) values
('00000000-0000-0000-0000-000000000001', 'root@test.local'), ('00000000-0000-0000-0000-000000000001', 'root@test.local', now()),
('00000000-0000-0000-0000-00000000000a', 'alice@test.local'), ('00000000-0000-0000-0000-00000000000a', 'alice@test.local', now()),
('00000000-0000-0000-0000-00000000000b', 'bob@test.local'); ('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'); select private.assign_platform_role(null, '00000000-0000-0000-0000-000000000001', 'owner');
-- 1. Bootstrap is audited as a system action -- 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 -- 2. RPC grant and revoke are audited with the actor
set local role authenticated; 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.grant_platform_role('00000000-0000-0000-0000-00000000000a', 'admin');
select public.revoke_platform_role('00000000-0000-0000-0000-00000000000a', 'admin', 'rotation'); select public.revoke_platform_role('00000000-0000-0000-0000-00000000000a', 'admin', 'rotation');
reset role; reset role;
+62 -618
View File
@@ -1,638 +1,82 @@
-- Anatomical sheets: schema contract, lifecycle (allowed path), immutability, -- Anatomical sheets: schema contract and privileges after V1-2.1 (M4, M5).
-- copies with provenance, deletion preconditions, invalid documents, every -- The lifecycle, review and publication behaviour lives in 016; the AR-1 B and
-- denied path (other user, anon, direct writes, official sheets). -- rights matrix in 015. This file pins the tables, enums, RLS, the start-from-
-- Counts are scoped to fixture ids: the real stack also carries seed rows. -- 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; begin;
select plan(127); select plan(45);
-- --------------------------------------------------------------------------- -- Tables and enums
-- 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
-- ---------------------------------------------------------------------------
select has_table('public', 'species', 'table species exists'); select has_table('public', 'species', 'table species exists');
select has_table('public', 'anatomical_sheets', 'table anatomical_sheets 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_versions', 'table anatomical_sheet_versions exists');
select has_table('public', 'anatomical_sheet_assets', 'table anatomical_sheet_assets 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 has_table('public', 'anatomical_catalog_grants', 'table anatomical_catalog_grants exists');
select enum_has_labels('public', 'sheet_status', array['active', 'archived', 'deleted'], 'sheet_status labels'); select has_table('public', 'anatomical_sheet_reviews', 'table anatomical_sheet_reviews exists');
select enum_has_labels('public', 'sheet_version_status', array['draft', 'published', 'deprecated'], 'sheet_version_status labels'); select has_table('public', 'anatomical_sheet_review_comments', 'table anatomical_sheet_review_comments exists');
select is( select has_table('public', 'anatomical_sheet_review_acknowledgments', 'table anatomical_sheet_review_acknowledgments exists');
(select count(*) from public.species where id = 'equine' and active), 1::bigint, select enum_has_labels('public', 'catalog_grant_kind',
'species equine is seeded by the migration' 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 ok(
(select bool_and(relrowsecurity) from pg_class (select bool_and(relrowsecurity) from pg_class
where oid in ('public.species'::regclass, 'public.anatomical_sheets'::regclass, where oid in ('public.species'::regclass, 'public.anatomical_sheets'::regclass,
'public.anatomical_sheet_versions'::regclass, 'public.anatomical_sheet_assets'::regclass)), 'public.anatomical_sheet_versions'::regclass, 'public.anatomical_sheet_assets'::regclass,
'RLS enabled on the four tables' '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_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('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('service_role', 'public.anatomical_sheets', 'select'), 'service_role cannot select sheets (F12)');
select ok(not has_table_privilege('authenticated', 'public.anatomical_sheets', 'delete'), 'authenticated cannot delete sheets directly'); select ok(not has_table_privilege('service_role', 'public.anatomical_sheet_versions', 'update'), 'service_role cannot update versions (F12)');
select ok(not has_column_privilege('authenticated', 'public.anatomical_sheets', 'status', 'update'), 'authenticated cannot update sheets.status'); select ok(not has_table_privilege('service_role', 'public.anatomical_sheet_assets', 'update'), 'service_role cannot update assets (F12)');
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('service_role', 'public.anatomical_catalog_grants', 'select'), 'service_role cannot read grants');
select ok(not has_table_privilege('authenticated', 'public.anatomical_sheet_versions', 'insert'), 'authenticated cannot insert versions directly'); select ok(not has_table_privilege('service_role', 'public.profile_roles', 'insert'), 'service_role cannot write profile_roles (F17)');
select ok(not has_column_privilege('authenticated', 'public.anatomical_sheet_versions', 'status', 'update'), 'authenticated cannot update versions.status'); select ok(not has_table_privilege('service_role', 'public.profiles', 'update'), 'service_role cannot write profiles (F17)');
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'
);
-- --------------------------------------------------------------------------- -- Editors never write sheet identity, status, content directly (F9)
-- 2. Alice creates a private sheet (draft v1), registers an asset, publishes 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');
set local role authenticated; select ok(not has_table_privilege('authenticated', 'public.anatomical_sheet_versions', 'insert'), 'authenticated cannot insert versions');
select set_config('request.jwt.claims', '{"sub":"20000000-0000-0000-0000-00000000000a","role":"authenticated"}', true); 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( -- Reader column grants on sheets exclude the staff-only columns (§5.3)
'equine', 'Mon cheval', 'mon-cheval', pg_temp.sheet_doc(null), 'perso' 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 results_eq( select ok(not has_column_privilege('authenticated', 'public.anatomical_sheets', 'working_copy_source_version_id', 'select'), 'working_copy source not readable');
$$ select creator_user_id, status::text, visibility::text, current_version_id, is_official select ok(not has_column_privilege('authenticated', 'public.anatomical_sheets', 'creator_user_id', 'select'), 'creator_user_id not readable');
from public.anatomical_sheets where id = pg_temp.id('sheet') $$, select ok(has_column_privilege('authenticated', 'public.anatomical_sheets', 'current_version_id', 'select'), 'current_version_id readable');
$$ 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'
);
select throws_ok( -- The Step 4 write paths are gone (F1, F3, F6)
$$ select public.create_anatomical_sheet('equine', 'Bad', 'bad-doc', '{"schema_version":"abc","species_id":"equine"}'::jsonb) $$, select hasnt_function('public', 'create_anatomical_sheet', 'create_anatomical_sheet dropped (F1)');
'23514', null, 'a non-numeric schema_version is refused' select hasnt_function('public', 'fork_anatomical_sheet', 'fork_anatomical_sheet dropped (D5)');
); select hasnt_function('public', 'set_sheet_visibility', 'set_sheet_visibility dropped (F6)');
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'
);
-- Publishing a draft whose main view has no asset is refused with the rule code -- The SQL business mirror is gone; the structural guards stay (§12.2)
select throws_ok( select hasnt_function('private', 'sheet_document_issues', 'SQL business mirror dropped (O22)');
$$ select public.publish_sheet_version(pg_temp.id('v1')) $$, select hasnt_function('private', 'sheet_document_view_issues', 'view mirror dropped');
'23514', 'document not publishable: view.asset.missing', 'publish refuses a main view without asset' 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( -- The new workflow RPCs exist
pg_temp.id('sheet'), repeat('a', 64), 142400, 'Horse.svg' select has_function('public', 'create_official_sheet', 'create_official_sheet exists');
); select has_function('public', 'publish_sheet_version', 'publish_sheet_version exists');
select is( select has_function('public', 'create_sheet_working_copy', 'create_sheet_working_copy exists');
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'
);
select * from finish(); select * from finish();
rollback; rollback;
+155 -137
View File
@@ -1,155 +1,173 @@
-- Storage read policy on bucket anatomical-sheet-assets: an object is readable -- Sheet-asset Storage after V1-2.1 (M4, M5): the bucket is private and 2 MiB,
-- through a sheet (published reference for users, any version for editors), -- the read predicate follows the catalogue rules (contract §9.4), the editor
-- never through its hash alone. No API writes. -- 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; begin;
select plan(28); select plan(15);
insert into auth.users (id, email) values -- Bucket
('30000000-0000-0000-0000-00000000000a', 'alice-assets@test.local'), select is((select public from storage.buckets where id = 'anatomical-sheet-assets'), false, 'the bucket is private');
('30000000-0000-0000-0000-00000000000b', 'bob-assets@test.local'); 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); -- Policies on storage.objects for the bucket: read + editor insert, nothing else.
create function pg_temp.id(p_key text) returns uuid language sql stable select is(
as $$ select id from pg_temp.ids where key = p_key $$; (select count(*) from pg_policies where schemaname='storage' and tablename='objects'
grant all on pg_temp.ids to anon, authenticated, service_role; and (coalesce(qual,'')||coalesce(with_check,'')) like '%anatomical-sheet-assets%'),
grant execute on function pg_temp.id(text) to anon, authenticated, service_role; 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 $$ create function pg_temp.doc(p_asset uuid) returns jsonb language sql as $$
select jsonb_build_object( select jsonb_build_object('schema_version',2,'species_id','equine',
'schema_version', 2, 'species_id', 'equine', 'name',jsonb_build_object('fr','P','en','P'),'description','{}'::jsonb,'scope_disclaimer','{}'::jsonb,
'name', jsonb_build_object('fr', 'A', 'en', 'A'), 'attribution',jsonb_build_object('authors','[]'::jsonb,'license',null,'notes',null),
'description', '{}'::jsonb, 'scope_disclaimer', '{}'::jsonb, 'vertebral_config',jsonb_build_object('regions','[]'::jsonb),'references','[]'::jsonb,
'attribution', jsonb_build_object('authors', '[]'::jsonb, 'license', null, 'notes', null), 'categories','[]'::jsonb,
'vertebral_config', jsonb_build_object('regions', '[]'::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)),
'categories', '[]'::jsonb, 'annotations','[]'::jsonb,'finding_zones','[]'::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 create function pg_temp.act(p_uid uuid, p_sid uuid, p_aal text) returns void language sql as $$
select is((select public from storage.buckets where id = 'anatomical-sheet-assets'), false, 'bucket is private'); select set_config('request.jwt.claims', jsonb_build_object('sub',p_uid,'role','authenticated','aal',p_aal,'session_id',p_sid)::text, true);
select is( $$;
(select allowed_mime_types from storage.buckets where id = 'anatomical-sheet-assets'), grant execute on function pg_temp.act(uuid,uuid,text) to authenticated;
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'
);
-- 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; set local role authenticated;
select set_config('request.jwt.claims', '{"sub":"30000000-0000-0000-0000-00000000000a","role":"authenticated"}', true); select pg_temp.act('30000000-0000-0000-0000-0000000000d0', gen_random_uuid(), 'aal1');
insert into pg_temp.ids select 'sheet', public.create_anatomical_sheet('equine', 'Assets', 'assets-test', pg_temp.doc(null)); select results_eq(
insert into pg_temp.ids select 'a', public.register_sheet_asset(pg_temp.id('sheet'), repeat('a', 64), 100, 'A.svg'); $$ select name from storage.objects where bucket_id='anatomical-sheet-assets' order by name $$,
insert into pg_temp.ids select 'b', public.register_sheet_asset(pg_temp.id('sheet'), repeat('b', 64), 100, 'B.svg'); $$ values (repeat('a',64)||'.svg'), (repeat('b',64)||'.svg') $$,
insert into pg_temp.ids select 'c', public.register_sheet_asset(pg_temp.id('sheet'), repeat('c', 64), 100, 'C.svg'); 'a catalogue reader reads the published and deprecated drawings, not the draft or pending ones'
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');
-- Objects uploaded by the operator (owner session), then confirmed through the -- Editor at aal2: every uploaded drawing of the official sheet (a, b, c), not the pending d.
-- service-role RPC for A and B only; C stays metadata without bytes. select pg_temp.act('30000000-0000-0000-0000-00000000000e', '31000000-0000-0000-0000-00000000000e', 'aal2');
reset role; select results_eq(
insert into storage.objects (bucket_id, name) values $$ select name from storage.objects where bucket_id='anatomical-sheet-assets' order by name $$,
('anatomical-sheet-assets', repeat('a', 64) || '.svg'), $$ values (repeat('a',64)||'.svg'), (repeat('b',64)||'.svg'), (repeat('c',64)||'.svg') $$,
('anatomical-sheet-assets', repeat('b', 64) || '.svg'), 'an editor at aal2 reads every confirmed drawing of the official sheet, not the pending one'
('anatomical-sheet-assets', repeat('c', 64) || '.svg'), );
('anatomical-sheet-assets', repeat('d', 64) || '.svg');
set local role authenticated; -- Editor at aal1 (no live aal2 session): the capability branch does not apply,
select set_config('request.jwt.claims', '{"sub":"30000000-0000-0000-0000-00000000000a","role":"authenticated"}', true); -- but a capability holder also has catalogue access, so the reader branch still
select is((select count(*) from storage.objects where bucket_id = 'anatomical-sheet-assets'), 0::bigint, 'nothing is readable before the upload is confirmed'); -- 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 throws_ok(
$$ select public.confirm_sheet_asset_upload(pg_temp.id('a')) $$, $$ insert into storage.objects (bucket_id, name) values ('anatomical-sheet-assets', repeat('a',64)||'.svg') $$,
'42501', null, 'an editor cannot confirm an upload (service role only)' '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; set local role service_role;
select lives_ok($$ select public.confirm_sheet_asset_upload(pg_temp.id('a')) $$, 'service role confirms asset A'); select set_config('request.jwt.claims', '{"role":"service_role"}', true);
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 is( select is(
(select count(*) from pg_policies where schemaname = 'storage' and tablename = 'objects' (select public.get_sheet_asset_state('32000000-0000-0000-0000-00000000000a') ->> 'sha256'),
and cmd in ('INSERT', 'UPDATE', 'DELETE') repeat('a',64), 'the operator read RPC returns the asset state for the service role'
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'
); );
-- 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 <sha256>.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(); select * from finish();
rollback; rollback;
+67 -87
View File
@@ -1,62 +1,38 @@
-- Official equine sheet seed (supabase/seed/anatomical-sheets/equine/draft): -- Official equine seed after V1-2.1: the historical sheet is present as a
-- present as a platform-owned DRAFT, never published by the seed, publishable -- platform-owned DRAFT, protected on the server (never saved, submitted,
-- by platform admins only, content accepted by the SQL referential gate. -- 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; begin;
select plan(20); select plan(17);
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');
create table pg_temp.ids (key text primary key, id uuid not null); 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 create function pg_temp.id(p_key text) returns uuid language sql stable as $$ select id from pg_temp.ids where key = p_key $$;
as $$ select id from pg_temp.ids where key = p_key $$;
grant all on pg_temp.ids to anon, authenticated, service_role; grant all on pg_temp.ids to anon, authenticated, service_role;
grant execute on function pg_temp.id(text) 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 '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'); insert into pg_temp.ids select 'draft', id from public.anatomical_sheet_versions where sheet_id = pg_temp.id('sheet');
-- 1. Seeded state -- 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 results_eq(
$$ select species_id, creator_user_id, is_official, visibility::text, status::text, current_version_id $$ 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') $$, from public.anatomical_sheets where id = pg_temp.id('sheet') $$,
$$ values ('equine', null::uuid, true, 'private', 'active', null::uuid) $$, $$ 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 results_eq(
$$ select version_number, status::text, document_schema_version, published_at $$ select version_number, status::text, document_schema_version, revision, coalesce(array_length(authors,1),0), published_at
from public.anatomical_sheet_versions where sheet_id = pg_temp.id('sheet') $$, from public.anatomical_sheet_versions where id = pg_temp.id('draft') $$,
$$ values (1, 'draft', 2, null::timestamptz) $$, $$ values (1, 'draft', 2, 0, 0, null::timestamptz) $$,
'exactly one version, draft v1, never published' '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 (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 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 ok(
(select content -> 'views' -> 1 -> 'svg_asset_id' = 'null'::jsonb (select private.sheet_document_has_shape(content) from public.anatomical_sheet_versions where id = pg_temp.id('draft')),
and jsonb_typeof(content -> 'views' -> 1 -> 'view_box') = 'object' 'the seeded document has the structural shape SQL still checks'
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 is( select is(
(select private.sheet_document_unknown_assets(sheet_id, content) from public.anatomical_sheet_versions where id = pg_temp.id('draft')), (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' 1::bigint, 'the seed import is audited as a system action'
); );
-- 2. Nobody publishes it by accident: plain users cannot even see the draft -- 2. An editor with the capability (aal2) is set up, then the protections.
set local role authenticated; insert into auth.users (id, email, email_confirmed_at) values
select set_config('request.jwt.claims', '{"sub":"40000000-0000-0000-0000-00000000000a","role":"authenticated"}', true); ('40000000-0000-0000-0000-000000000001', 'own-eq@test.local', now()),
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'); ('40000000-0000-0000-0000-00000000000e', 'ed-eq@test.local', now()),
select throws_ok( ('40000000-0000-0000-0000-0000000000a0', 'pl-eq@test.local', now());
$$ select public.publish_sheet_version(pg_temp.id('draft')) $$, insert into auth.mfa_factors (id, user_id, factor_type, status, created_at, updated_at)
'42501', null, 'a plain user cannot publish the official draft' 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');
-- A platform admin can (the explicit decision step), and the gate would accept the document select set_config('request.jwt.claims', '', true);
select set_config('request.jwt.claims', '{"sub":"40000000-0000-0000-0000-000000000001","role":"authenticated"}', true); select private.assign_platform_role(null, '40000000-0000-0000-0000-000000000001', 'owner');
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 private.assign_platform_role(null, '40000000-0000-0000-0000-00000000000e', 'admin');
select lives_ok($$ select public.publish_sheet_version(pg_temp.id('draft')) $$, 'a platform admin could publish it (rolled back here)'); 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; set local role authenticated;
select set_config('request.jwt.claims', '{"sub":"40000000-0000-0000-0000-000000000001","role":"authenticated"}', true); select pg_temp.act('40000000-0000-0000-0000-00000000000e', '41000000-0000-0000-0000-00000000000e', 'aal2');
select is((select count(*) from storage.objects where bucket_id = 'anatomical-sheet-assets' and name in (select name from pg_temp.seed_objects)), -- The capability holder sees the draft (caller_can_see_official_sheet).
0::bigint, 'seed objects are not readable before confirmation'); select is((select count(*) from public.anatomical_sheet_versions where id = pg_temp.id('draft')), 1::bigint,
set local role service_role; 'a capability holder at aal2 sees the historical draft');
select is(
(select count(*) from public.anatomical_sheet_assets a where a.sheet_id = pg_temp.id('sheet') -- Every write path refuses the historical sheet.
and public.confirm_sheet_asset_upload(a.id) = a.id), select throws_ok(
1::bigint, 'operator confirms the upload' $$ 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 throws_ok(
select set_config('request.jwt.claims', '{"sub":"40000000-0000-0000-0000-000000000001","role":"authenticated"}', true); $$ select public.submit_sheet_review(pg_temp.id('draft'), 0, 'x') $$,
select is((select count(*) from storage.objects where bucket_id = 'anatomical-sheet-assets' and name in (select name from pg_temp.seed_objects)), '42501', 'sheet.historical_read_only', 'submit refused on the historical sheet'
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 throws_ok(
select is((select count(*) from storage.objects where bucket_id = 'anatomical-sheet-assets' and name in (select name from pg_temp.seed_objects)), $$ select public.register_sheet_asset(pg_temp.id('sheet'), repeat('e',64), 100, 'x.svg') $$,
0::bigint, 'a plain user reads no official draft 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(); select * from finish();
rollback; rollback;
@@ -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;
+2 -2
View File
@@ -75,11 +75,11 @@ select is(
select is( select is(
(select count(*) from pg_policies where schemaname = 'storage' and tablename = 'objects' (select count(*) from pg_policies where schemaname = 'storage' and tablename = 'objects'
and (coalesce(qual, '') || coalesce(with_check, '')) like '%bucket_id = ''anatomical-sheet-assets''%'), 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 is(
(select count(*) from pg_policies where schemaname = 'storage' and tablename = 'objects'), (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 is(
(select count(*) from pg_policies where schemaname = 'storage' and tablename = 'objects' (select count(*) from pg_policies where schemaname = 'storage' and tablename = 'objects'
-167
View File
@@ -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":"consLine truncated
'{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":"inheritLine truncated
'{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 restrictioLine truncated
'{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":"inherLine truncated
'{}'::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":"arLine truncated
'{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","Line truncated
'{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","Line truncated
'{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,"refereLine truncated
'{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","Line truncated
'{}'::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","nLine truncated
'{}'::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":[]}]Line truncated
'{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","Line truncated
'{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","Line truncated
'{}'::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"},"descriptioLine truncated
'{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,"refereLine truncated
'{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","Line truncated
'{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 dLine truncated
'{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":"hiLine truncated
'{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"},"Line truncated
'{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":"ObsLine truncated
'{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"Line truncated
'{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 eLine truncated
'{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 reLine truncated
'{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 Line truncated
'{}'::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":"RestrictionLine truncated
'{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 (affecLine truncated
'{view.unreachable}'::text[],
'conformance view-unreachable: the head view without its trigger'
);
select * from finish();
rollback;
+204
View File
@@ -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;
@@ -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;