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

+1 -1
View File
@@ -62,7 +62,7 @@ select is(
(select string_agg(p.proname::text, ',' order by p.proname::text collate "C")
from pg_proc p join pg_namespace n on n.oid = p.pronamespace
where n.nspname in ('private', 'audit') and has_function_privilege('authenticated', p.oid, 'execute')),
'caller_workspace_ids,can_edit_sheet,can_read_avatar_object,can_read_sheet_asset_object,can_upload_avatar_object,can_use_sheet,fold_text,has_platform_role,is_platform_admin,is_platform_moderator,is_platform_owner,is_support',
'asset_in_catalog_version,caller_can_see_official_sheet,caller_is_catalog_staff,caller_workspace_ids,can_read_avatar_object,can_read_catalog_sheet,can_read_sheet_asset_object,can_upload_avatar_object,can_upload_sheet_asset_object,fold_text,has_mfa,has_platform_role,is_platform_admin,is_platform_moderator,is_platform_owner,is_support',
'authenticated executes only the policy predicates in private'
);
+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;
select plan(28);
select plan(25);
insert into auth.users (id, email) values
('00000000-0000-0000-0000-000000000001', 'root@test.local'),
('00000000-0000-0000-0000-00000000000a', 'alice@test.local'),
('00000000-0000-0000-0000-00000000000b', 'bob@test.local'),
('00000000-0000-0000-0000-00000000000c', 'carol@test.local');
insert into auth.users (id, email, email_confirmed_at) values
('00000000-0000-0000-0000-000000000001', 'root@test.local', now()),
('00000000-0000-0000-0000-00000000000a', 'alice@test.local', now()),
('00000000-0000-0000-0000-00000000000b', 'bob@test.local', now()),
('00000000-0000-0000-0000-00000000000c', 'carol@test.local', now());
-- 1. Nobody has a role; bootstrap the first owner from a privileged session
-- A verified TOTP factor for every account that will receive a role, except
-- carol, who gets one only after the factor-missing refusal is proven.
insert into auth.mfa_factors (id, user_id, factor_type, status, created_at, updated_at)
select gen_random_uuid(), id, 'totp', 'verified', now(), now()
from auth.users where email in ('root@test.local', 'alice@test.local', 'bob@test.local');
-- aal2 sessions for the callers (root, alice); one aal1 session for root.
insert into auth.sessions (id, user_id, aal, not_after) values
('a0000000-0000-0000-0000-000000000001', '00000000-0000-0000-0000-000000000001', 'aal2', null),
('a0000000-0000-0000-0000-00000000000a', '00000000-0000-0000-0000-00000000000a', 'aal2', null),
('a0000000-0000-0000-0000-00000000000b', '00000000-0000-0000-0000-00000000000b', 'aal2', null),
('b0000000-0000-0000-0000-000000000001', '00000000-0000-0000-0000-000000000001', 'aal1', null);
create function pg_temp.act(p_uid uuid, p_sid uuid, p_aal text) returns void language sql as $$
select set_config('request.jwt.claims',
jsonb_build_object('sub', p_uid, 'role', 'authenticated', 'aal', p_aal, 'session_id', p_sid)::text, true);
$$;
-- 1. Bootstrap the first owner from the operator path (no JWT at all).
select set_config('request.jwt.claims', '', true);
select ok(not private.is_platform_owner('00000000-0000-0000-0000-000000000001'), 'fresh account has no owner role');
select lives_ok(
$$ select private.assign_platform_role(null, '00000000-0000-0000-0000-000000000001', 'owner') $$,
'system bootstraps the first owner (actor null)'
'operator bootstraps the first owner (actor null, no JWT)'
);
select ok(private.is_platform_owner('00000000-0000-0000-0000-000000000001'), 'root is owner');
select ok(private.is_platform_admin('00000000-0000-0000-0000-000000000001'), 'owner counts as admin');
select ok(private.is_platform_moderator('00000000-0000-0000-0000-000000000001'), 'owner counts as moderator');
select ok(not private.is_support('00000000-0000-0000-0000-000000000001'), 'owner is not support');
-- 2. Owner grants admin to alice through the RPC
-- 2. AR-1 B: an aal1 owner session is refused before any role check.
set local role authenticated;
select set_config('request.jwt.claims', '{"sub":"00000000-0000-0000-0000-000000000001","role":"authenticated"}', true);
select pg_temp.act('00000000-0000-0000-0000-000000000001', 'b0000000-0000-0000-0000-000000000001', 'aal1');
select throws_ok(
$$ select public.grant_platform_role('00000000-0000-0000-0000-00000000000a', 'admin') $$,
'42501', 'mfa_required', 'an aal1 owner session cannot grant a role'
);
-- 3. Owner at aal2 grants admin to alice (who holds a verified factor).
select pg_temp.act('00000000-0000-0000-0000-000000000001', 'a0000000-0000-0000-0000-000000000001', 'aal2');
select lives_ok(
$$ select public.grant_platform_role('00000000-0000-0000-0000-00000000000a', 'admin') $$,
'owner grants admin'
'owner at aal2 grants admin'
);
select throws_ok(
$$ select public.grant_platform_role('00000000-0000-0000-0000-00000000000a', 'admin') $$,
'23505',
null,
'granting an active role twice is refused'
'P0001', 'role_active', 'granting an active role twice is refused'
);
select throws_ok(
$$ select public.grant_platform_role('00000000-0000-0000-0000-000000000001', 'admin') $$,
'42501',
null,
'owner cannot change their own roles'
'42501', 'self_target', 'owner cannot change their own roles'
);
select throws_ok(
$$ select public.grant_platform_role(gen_random_uuid(), 'support') $$,
'P0002',
null,
'unknown target is refused'
'P0001', 'target_invalid', 'unknown target is refused'
);
-- 3. Alice (admin) may delegate moderator/support, nothing above
select set_config('request.jwt.claims', '{"sub":"00000000-0000-0000-0000-00000000000a","role":"authenticated"}', true);
-- 4. A grant to a target with no verified factor is refused (AR-1 B).
select throws_ok(
$$ select public.grant_platform_role('00000000-0000-0000-0000-00000000000c', 'support') $$,
'P0001', 'target_factor_missing', 'a grant to an account with no verified factor is refused'
);
reset role;
insert into auth.mfa_factors (id, user_id, factor_type, status, created_at, updated_at)
values (gen_random_uuid(), '00000000-0000-0000-0000-00000000000c', 'totp', 'verified', now(), now());
set local role authenticated;
select pg_temp.act('00000000-0000-0000-0000-000000000001', 'a0000000-0000-0000-0000-000000000001', 'aal2');
-- 5. Alice (admin) at aal2 may delegate moderator/support, nothing above.
select pg_temp.act('00000000-0000-0000-0000-00000000000a', 'a0000000-0000-0000-0000-00000000000a', 'aal2');
select lives_ok(
$$ select public.grant_platform_role('00000000-0000-0000-0000-00000000000b', 'moderator') $$,
'admin grants moderator'
);
select throws_ok(
$$ select public.grant_platform_role('00000000-0000-0000-0000-00000000000b', 'admin') $$,
'42501',
null,
'admin cannot grant admin'
'42501', 'forbidden', 'admin cannot grant admin'
);
select throws_ok(
$$ select public.grant_platform_role('00000000-0000-0000-0000-00000000000b', 'owner') $$,
'42501',
null,
'admin cannot grant owner'
);
select throws_ok(
$$ select public.grant_platform_role('00000000-0000-0000-0000-00000000000a', 'owner') $$,
'42501',
null,
'admin cannot promote herself to owner'
'42501', 'forbidden', 'admin cannot grant owner'
);
-- 4. Direct writes are impossible for the API role
-- 6. Direct writes are impossible for the API role.
select throws_ok(
$$ insert into public.profile_roles (user_id, role) values ('00000000-0000-0000-0000-00000000000a', 'owner') $$,
'42501',
null,
'admin cannot insert a role row directly'
'42501', null, 'admin cannot insert a role row directly'
);
select throws_ok(
$$ update public.profile_roles set role = 'owner' where user_id = '00000000-0000-0000-0000-00000000000a' $$,
'42501',
null,
'admin cannot update role rows directly'
'42501', null, 'admin cannot update role rows directly'
);
select throws_ok(
$$ delete from public.profile_roles $$,
'42501',
null,
'admin cannot delete role rows directly'
'42501', null, 'admin cannot delete role rows directly'
);
-- 5. Bob (moderator) cannot delegate; sees only his own grants; carol sees nothing
select set_config('request.jwt.claims', '{"sub":"00000000-0000-0000-0000-00000000000b","role":"authenticated"}', true);
-- 7. service_role cannot write the table nor execute the RPCs (F17).
set local role service_role;
select set_config('request.jwt.claims', '{"role":"service_role"}', true);
select ok(not has_function_privilege('service_role', 'public.grant_platform_role(uuid, public.platform_role)', 'execute'),
'service_role cannot execute grant_platform_role');
select throws_ok(
$$ insert into public.profile_roles (user_id, role) values ('00000000-0000-0000-0000-00000000000c', 'owner') $$,
'42501', null, 'service_role cannot insert a role row directly'
);
-- 8. Bob (moderator) at aal2 sees only his own grant; carol sees none.
set local role authenticated;
select pg_temp.act('00000000-0000-0000-0000-00000000000b', 'a0000000-0000-0000-0000-00000000000b', 'aal2');
select throws_ok(
$$ select public.grant_platform_role('00000000-0000-0000-0000-00000000000c', 'support') $$,
'42501',
null,
'moderator cannot grant any role'
'42501', 'forbidden', 'moderator at aal2 cannot grant any role'
);
select results_eq(
$$ select user_id, role::text from public.profile_roles $$,
$$ values ('00000000-0000-0000-0000-00000000000b'::uuid, 'moderator'::text) $$,
'moderator sees only his own grant rows'
);
select set_config('request.jwt.claims', '{"sub":"00000000-0000-0000-0000-00000000000c","role":"authenticated"}', true);
select is((select count(*) from public.profile_roles), 0::bigint, 'plain user sees no role rows');
select is((select count(*) from public.profiles), 1::bigint, 'plain user still sees one profile (own)');
-- 6. Admin sees every grant and every profile (staff read)
select set_config('request.jwt.claims', '{"sub":"00000000-0000-0000-0000-00000000000a","role":"authenticated"}', true);
select is(
(select count(*) from public.profile_roles
where user_id in ('00000000-0000-0000-0000-000000000001', '00000000-0000-0000-0000-00000000000a', '00000000-0000-0000-0000-00000000000b')),
3::bigint,
'admin sees all three fixture grant rows'
);
select is(
(select count(*) from public.profiles where id in (
'00000000-0000-0000-0000-000000000001', '00000000-0000-0000-0000-00000000000a',
'00000000-0000-0000-0000-00000000000b', '00000000-0000-0000-0000-00000000000c')),
4::bigint,
'admin reads every fixture profile'
);
-- 7. Anonymous
-- 9. Anonymous
set local role anon;
select set_config('request.jwt.claims', '', true);
select throws_ok(
$$ select public.grant_platform_role('00000000-0000-0000-0000-00000000000c', 'support') $$,
'42501',
null,
'anon cannot call grant_platform_role'
'42501', null, 'anon cannot call grant_platform_role'
);
-- 8. Revocation and deactivation
-- 10. Revocation at aal2 and deactivation.
set local role authenticated;
select set_config('request.jwt.claims', '{"sub":"00000000-0000-0000-0000-00000000000a","role":"authenticated"}', true);
select pg_temp.act('00000000-0000-0000-0000-00000000000a', 'a0000000-0000-0000-0000-00000000000a', 'aal2');
select lives_ok(
$$ select public.revoke_platform_role('00000000-0000-0000-0000-00000000000b', 'moderator', 'test') $$,
'admin revokes moderator'
'admin revokes moderator at aal2'
);
select ok(not private.is_platform_moderator('00000000-0000-0000-0000-00000000000b'), 'revoked role no longer counts');
reset role;
update public.profiles set active = false where id = '00000000-0000-0000-0000-00000000000a';
select ok(not private.is_platform_admin('00000000-0000-0000-0000-00000000000a'), 'deactivated account loses its roles');
-- 9. Last-owner guard on the system path (neutralise owners seeded outside the fixtures)
-- 11. Last-owner guard on the system path (operator path: no JWT at all).
update public.profile_roles set revoked_at = now()
where role = 'owner' and revoked_at is null and user_id <> '00000000-0000-0000-0000-000000000001';
select set_config('request.jwt.claims', '', true);
select throws_ok(
$$ select private.withdraw_platform_role(null, '00000000-0000-0000-0000-000000000001', 'owner', 'oops') $$,
'42501',
null,
'the last owner cannot be revoked'
'P0001', 'last_owner', 'the last owner cannot be revoked'
);
select * from finish();
+12 -5
View File
@@ -3,10 +3,16 @@
begin;
select plan(12);
insert into auth.users (id, email) values
('00000000-0000-0000-0000-000000000001', 'root@test.local'),
('00000000-0000-0000-0000-00000000000a', 'alice@test.local'),
('00000000-0000-0000-0000-00000000000b', 'bob@test.local');
insert into auth.users (id, email, email_confirmed_at) values
('00000000-0000-0000-0000-000000000001', 'root@test.local', now()),
('00000000-0000-0000-0000-00000000000a', 'alice@test.local', now()),
('00000000-0000-0000-0000-00000000000b', 'bob@test.local', now());
-- AR-1 B: the owner needs a live aal2 session, the target a verified factor.
insert into auth.mfa_factors (id, user_id, factor_type, status, created_at, updated_at)
values (gen_random_uuid(), '00000000-0000-0000-0000-00000000000a', 'totp', 'verified', now(), now());
insert into auth.sessions (id, user_id, aal) values
('a0000000-0000-0000-0000-000000000001', '00000000-0000-0000-0000-000000000001', 'aal2');
select set_config('request.jwt.claims', '', true);
select private.assign_platform_role(null, '00000000-0000-0000-0000-000000000001', 'owner');
-- 1. Bootstrap is audited as a system action
@@ -20,7 +26,8 @@ select results_eq(
-- 2. RPC grant and revoke are audited with the actor
set local role authenticated;
select set_config('request.jwt.claims', '{"sub":"00000000-0000-0000-0000-000000000001","role":"authenticated"}', true);
select set_config('request.jwt.claims',
'{"sub":"00000000-0000-0000-0000-000000000001","role":"authenticated","aal":"aal2","session_id":"a0000000-0000-0000-0000-000000000001"}', true);
select public.grant_platform_role('00000000-0000-0000-0000-00000000000a', 'admin');
select public.revoke_platform_role('00000000-0000-0000-0000-00000000000a', 'admin', 'rotation');
reset role;
+62 -618
View File
@@ -1,638 +1,82 @@
-- Anatomical sheets: schema contract, lifecycle (allowed path), immutability,
-- copies with provenance, deletion preconditions, invalid documents, every
-- denied path (other user, anon, direct writes, official sheets).
-- Counts are scoped to fixture ids: the real stack also carries seed rows.
-- Anatomical sheets: schema contract and privileges after V1-2.1 (M4, M5).
-- The lifecycle, review and publication behaviour lives in 016; the AR-1 B and
-- rights matrix in 015. This file pins the tables, enums, RLS, the start-from-
-- zero privileges for every API role including service_role (F12), the narrow
-- reader column grants, and the removal of the Step 4 write paths and the SQL
-- business mirror.
begin;
select plan(127);
select plan(45);
-- ---------------------------------------------------------------------------
-- Fixtures
-- ---------------------------------------------------------------------------
insert into auth.users (id, email) values
('20000000-0000-0000-0000-000000000001', 'root-sheets@test.local'),
('20000000-0000-0000-0000-00000000000a', 'alice-sheets@test.local'),
('20000000-0000-0000-0000-00000000000b', 'bob-sheets@test.local');
select private.assign_platform_role(null, '20000000-0000-0000-0000-000000000001', 'owner');
-- A small but complete document: two views (detail without its own asset),
-- a trigger, a bilateral joint, a spine zone, one finding zone.
create function pg_temp.sheet_doc(p_asset uuid)
returns jsonb
language sql
as $$
select jsonb_build_object(
'schema_version', 2,
'species_id', 'equine',
'name', jsonb_build_object('fr', 'Cheval test', 'en', 'Test horse'),
'description', '{}'::jsonb,
'scope_disclaimer', '{}'::jsonb,
'attribution', jsonb_build_object('authors', '[]'::jsonb, 'license', null, 'notes', null),
'vertebral_config', jsonb_build_object('regions', jsonb_build_array(
jsonb_build_object('code', 'C', 'name', jsonb_build_object('fr', 'Cervicales', 'en', 'Cervical'), 'count', 7)
)),
'references', '[]'::jsonb,
'categories', jsonb_build_array(
jsonb_build_object('id', 'articulations', 'name', jsonb_build_object('fr', 'Articulations', 'en', 'Joints'), 'color', null)
),
'views', jsonb_build_array(
jsonb_build_object('id', 'view-main', 'kind', 'main',
'name', jsonb_build_object('fr', 'Vue principale', 'en', 'Main view'),
'svg_asset_id', p_asset, 'view_box', null),
jsonb_build_object('id', 'view-head', 'kind', 'detail', 'parent_view_id', 'view-main',
'name', jsonb_build_object('fr', 'Tête', 'en', 'Head'),
'svg_asset_id', null,
'view_box', jsonb_build_object('min_x', 60, 'min_y', 100, 'width', 500, 'height', 380))
),
'annotations', jsonb_build_array(
jsonb_build_object('id', 'hip', 'kind', 'point', 'view_id', 'view-main', 'category_id', 'articulations',
'laterality', 'bilateral', 'geometry', null,
'name', jsonb_build_object('fr', 'Hanche', 'en', 'Hip joint'),
'finding_zone_id', 'hip', 'vertebral_region_code', null),
jsonb_build_object('id', 'cervical', 'kind', 'zone', 'view_id', 'view-main', 'category_id', 'articulations',
'laterality', 'unpaired', 'geometry', null,
'name', jsonb_build_object('fr', 'Vertèbres cervicales', 'en', 'Cervical vertebrae'),
'finding_zone_id', null, 'vertebral_region_code', 'C'),
jsonb_build_object('id', 'head-trigger', 'kind', 'detail_trigger', 'view_id', 'view-main',
'category_id', 'articulations', 'laterality', 'unpaired', 'geometry', null,
'name', null, 'opens_view_id', 'view-head')
),
'finding_zones', jsonb_build_array(
jsonb_build_object('id', 'hip', 'name', jsonb_build_object('fr', 'Hanche', 'en', 'Hip'),
'categories', jsonb_build_array(
jsonb_build_object('id', 'hip-dysfunctions', 'kind', 'dysfunction',
'name', jsonb_build_object('fr', 'Dysfonctions', 'en', 'Dysfunctions'),
'children', jsonb_build_array(
jsonb_build_object('id', 'articular', 'name', jsonb_build_object('fr', 'Articulaire', 'en', 'Articular'))
))
))
)
);
$$;
create table pg_temp.ids (key text primary key, id uuid not null);
create function pg_temp.id(p_key text) returns uuid language sql stable
as $$ select id from pg_temp.ids where key = p_key $$;
-- The fixtures are read while impersonating the API roles.
grant all on pg_temp.ids to anon, authenticated;
grant execute on function pg_temp.id(text), pg_temp.sheet_doc(uuid) to anon, authenticated;
-- ---------------------------------------------------------------------------
-- 1. Schema contract
-- ---------------------------------------------------------------------------
-- Tables and enums
select has_table('public', 'species', 'table species exists');
select has_table('public', 'anatomical_sheets', 'table anatomical_sheets exists');
select has_table('public', 'anatomical_sheet_versions', 'table anatomical_sheet_versions exists');
select has_table('public', 'anatomical_sheet_assets', 'table anatomical_sheet_assets exists');
select enum_has_labels('public', 'sheet_visibility', array['private', 'public'], 'sheet_visibility labels');
select enum_has_labels('public', 'sheet_status', array['active', 'archived', 'deleted'], 'sheet_status labels');
select enum_has_labels('public', 'sheet_version_status', array['draft', 'published', 'deprecated'], 'sheet_version_status labels');
select is(
(select count(*) from public.species where id = 'equine' and active), 1::bigint,
'species equine is seeded by the migration'
);
select has_table('public', 'anatomical_catalog_grants', 'table anatomical_catalog_grants exists');
select has_table('public', 'anatomical_sheet_reviews', 'table anatomical_sheet_reviews exists');
select has_table('public', 'anatomical_sheet_review_comments', 'table anatomical_sheet_review_comments exists');
select has_table('public', 'anatomical_sheet_review_acknowledgments', 'table anatomical_sheet_review_acknowledgments exists');
select enum_has_labels('public', 'catalog_grant_kind',
array['catalog_reader', 'sheet_editor', 'sheet_reviewer', 'sheet_publisher'], 'catalog_grant_kind labels');
select enum_has_labels('public', 'sheet_round_status',
array['verifying', 'open', 'approved', 'changes_requested', 'withdrawn', 'verification_failed'], 'sheet_round_status labels');
-- RLS enabled on every catalogue table
select ok(
(select bool_and(relrowsecurity) from pg_class
where oid in ('public.species'::regclass, 'public.anatomical_sheets'::regclass,
'public.anatomical_sheet_versions'::regclass, 'public.anatomical_sheet_assets'::regclass)),
'RLS enabled on the four tables'
'public.anatomical_sheet_versions'::regclass, 'public.anatomical_sheet_assets'::regclass,
'public.anatomical_catalog_grants'::regclass, 'public.anatomical_sheet_reviews'::regclass,
'public.anatomical_sheet_review_comments'::regclass,
'public.anatomical_sheet_review_acknowledgments'::regclass)),
'RLS enabled on the eight catalogue tables'
);
-- API roles start from zero (F12: service_role too)
select ok(not has_table_privilege('anon', 'public.anatomical_sheets', 'select'), 'anon cannot select sheets');
select ok(not has_table_privilege('anon', 'public.anatomical_sheet_versions', 'select'), 'anon cannot select versions');
select ok(not has_table_privilege('anon', 'public.species', 'select'), 'anon cannot select species');
select ok(not has_table_privilege('authenticated', 'public.anatomical_sheets', 'insert'), 'authenticated cannot insert sheets directly');
select ok(not has_table_privilege('authenticated', 'public.anatomical_sheets', 'delete'), 'authenticated cannot delete sheets directly');
select ok(not has_column_privilege('authenticated', 'public.anatomical_sheets', 'status', 'update'), 'authenticated cannot update sheets.status');
select ok(not has_column_privilege('authenticated', 'public.anatomical_sheets', 'is_official', 'update'), 'authenticated cannot update sheets.is_official');
select ok(not has_table_privilege('authenticated', 'public.anatomical_sheet_versions', 'insert'), 'authenticated cannot insert versions directly');
select ok(not has_column_privilege('authenticated', 'public.anatomical_sheet_versions', 'status', 'update'), 'authenticated cannot update versions.status');
select ok(has_column_privilege('authenticated', 'public.anatomical_sheet_versions', 'content', 'update'), 'authenticated may update versions.content (RLS: own draft)');
select ok(not has_table_privilege('authenticated', 'public.anatomical_sheet_assets', 'insert'), 'authenticated cannot insert assets directly');
select ok(
not (has_column_privilege('authenticated', 'public.anatomical_sheets', 'visibility', 'update')
or has_column_privilege('authenticated', 'public.anatomical_sheets', 'creator_user_id', 'update')
or has_column_privilege('authenticated', 'public.anatomical_sheets', 'current_version_id', 'update')
or has_column_privilege('authenticated', 'public.anatomical_sheets', 'based_on_sheet_id', 'update')
or has_column_privilege('authenticated', 'public.anatomical_sheets', 'based_on_version_id', 'update')
or has_column_privilege('authenticated', 'public.anatomical_sheets', 'species_id', 'update')),
'visibility, ownership, provenance, current version and species are not user-updatable'
);
select ok(not has_table_privilege('authenticated', 'public.anatomical_sheet_versions', 'delete'), 'authenticated cannot delete versions directly (RPC only)');
select is(
(select count(*) from pg_proc p join pg_namespace n on n.oid = p.pronamespace
where n.nspname = 'public' and p.prokind = 'f'
and not exists (select 1 from pg_depend d where d.objid = p.oid and d.deptype = 'e')
and has_function_privilege('anon', p.oid, 'execute')),
0::bigint, 'anon can execute no public RPC'
);
select ok(not has_table_privilege('service_role', 'public.anatomical_sheets', 'select'), 'service_role cannot select sheets (F12)');
select ok(not has_table_privilege('service_role', 'public.anatomical_sheet_versions', 'update'), 'service_role cannot update versions (F12)');
select ok(not has_table_privilege('service_role', 'public.anatomical_sheet_assets', 'update'), 'service_role cannot update assets (F12)');
select ok(not has_table_privilege('service_role', 'public.anatomical_catalog_grants', 'select'), 'service_role cannot read grants');
select ok(not has_table_privilege('service_role', 'public.profile_roles', 'insert'), 'service_role cannot write profile_roles (F17)');
select ok(not has_table_privilege('service_role', 'public.profiles', 'update'), 'service_role cannot write profiles (F17)');
-- ---------------------------------------------------------------------------
-- 2. Alice creates a private sheet (draft v1), registers an asset, publishes
-- ---------------------------------------------------------------------------
set local role authenticated;
select set_config('request.jwt.claims', '{"sub":"20000000-0000-0000-0000-00000000000a","role":"authenticated"}', true);
-- Editors never write sheet identity, status, content directly (F9)
select ok(not has_table_privilege('authenticated', 'public.anatomical_sheets', 'insert'), 'authenticated cannot insert sheets');
select ok(not has_table_privilege('authenticated', 'public.anatomical_sheets', 'update'), 'authenticated cannot update sheets directly');
select ok(not has_table_privilege('authenticated', 'public.anatomical_sheet_versions', 'insert'), 'authenticated cannot insert versions');
select ok(not has_column_privilege('authenticated', 'public.anatomical_sheet_versions', 'content', 'update'), 'authenticated cannot update version content directly (F9)');
select ok(has_column_privilege('authenticated', 'public.anatomical_sheet_versions', 'revision', 'select'), 'authenticated may read the draft revision');
select ok(not has_column_privilege('authenticated', 'public.anatomical_sheet_versions', 'authors', 'select'), 'authenticated cannot read the author set directly');
select ok(not has_table_privilege('authenticated', 'public.anatomical_sheet_assets', 'insert'), 'authenticated cannot insert assets');
select ok(not has_table_privilege('authenticated', 'public.anatomical_catalog_grants', 'insert'), 'authenticated cannot write grants directly');
select ok(not has_table_privilege('authenticated', 'public.anatomical_sheet_reviews', 'insert'), 'authenticated cannot write rounds directly');
insert into pg_temp.ids select 'sheet', public.create_anatomical_sheet(
'equine', 'Mon cheval', 'mon-cheval', pg_temp.sheet_doc(null), 'perso'
);
select results_eq(
$$ select creator_user_id, status::text, visibility::text, current_version_id, is_official
from public.anatomical_sheets where id = pg_temp.id('sheet') $$,
$$ values ('20000000-0000-0000-0000-00000000000a'::uuid, 'active', 'private', null::uuid, false) $$,
'created sheet: creator alice, active, private, no current version'
);
insert into pg_temp.ids select 'v1', id from public.anatomical_sheet_versions
where sheet_id = pg_temp.id('sheet') and version_number = 1;
select is(
(select status::text from public.anatomical_sheet_versions where id = pg_temp.id('v1')),
'draft', 'version 1 is a draft'
);
select throws_ok(
$$ select public.create_anatomical_sheet('unicorn', 'x', 'x-x', pg_temp.sheet_doc(null)) $$,
'P0002', null, 'unknown species is refused'
);
select throws_ok(
$$ select public.create_anatomical_sheet('equine', 'Dup', 'mon-cheval', pg_temp.sheet_doc(null)) $$,
'23505', null, 'slug is unique per owner'
);
-- Reader column grants on sheets exclude the staff-only columns (§5.3)
select ok(not has_column_privilege('authenticated', 'public.anatomical_sheets', 'last_version_number', 'select'), 'last_version_number not readable');
select ok(not has_column_privilege('authenticated', 'public.anatomical_sheets', 'updated_at', 'select'), 'updated_at not readable');
select ok(not has_column_privilege('authenticated', 'public.anatomical_sheets', 'working_copy_source_version_id', 'select'), 'working_copy source not readable');
select ok(not has_column_privilege('authenticated', 'public.anatomical_sheets', 'creator_user_id', 'select'), 'creator_user_id not readable');
select ok(has_column_privilege('authenticated', 'public.anatomical_sheets', 'current_version_id', 'select'), 'current_version_id readable');
select throws_ok(
$$ select public.create_anatomical_sheet('equine', 'Bad', 'bad-doc', '{"schema_version":"abc","species_id":"equine"}'::jsonb) $$,
'23514', null, 'a non-numeric schema_version is refused'
);
select throws_ok(
$$ update public.anatomical_sheet_versions
set content = jsonb_build_object('schema_version', 2, 'species_id', 'equine', 'pad', repeat('x', 2200000))
where id = pg_temp.id('v1') $$,
'23514', null, 'a document over 2 MiB is refused'
);
-- The Step 4 write paths are gone (F1, F3, F6)
select hasnt_function('public', 'create_anatomical_sheet', 'create_anatomical_sheet dropped (F1)');
select hasnt_function('public', 'fork_anatomical_sheet', 'fork_anatomical_sheet dropped (D5)');
select hasnt_function('public', 'set_sheet_visibility', 'set_sheet_visibility dropped (F6)');
-- Publishing a draft whose main view has no asset is refused with the rule code
select throws_ok(
$$ select public.publish_sheet_version(pg_temp.id('v1')) $$,
'23514', 'document not publishable: view.asset.missing', 'publish refuses a main view without asset'
);
-- The SQL business mirror is gone; the structural guards stay (§12.2)
select hasnt_function('private', 'sheet_document_issues', 'SQL business mirror dropped (O22)');
select hasnt_function('private', 'sheet_document_view_issues', 'view mirror dropped');
select hasnt_function('private', 'sheet_document_annotation_issues', 'annotation mirror dropped');
select has_function('private', 'sheet_document_has_shape', 'shape guard kept');
select has_function('private', 'sheet_document_unknown_assets', 'unknown-asset guard kept');
select has_function('private', 'sheet_all_reviewed', 'status check added (§12.2)');
insert into pg_temp.ids select 'asset', public.register_sheet_asset(
pg_temp.id('sheet'), repeat('a', 64), 142400, 'Horse.svg'
);
select is(
public.register_sheet_asset(pg_temp.id('sheet'), repeat('a', 64), 142400, 'Horse.svg'),
pg_temp.id('asset'), 'registering the same sha256 again returns the same asset'
);
-- Draft autosave: direct UPDATE of content through the policy
update public.anatomical_sheet_versions
set content = pg_temp.sheet_doc(pg_temp.id('asset')), change_note = 'asset wired'
where id = pg_temp.id('v1');
select is(
(select content -> 'views' -> 0 ->> 'svg_asset_id' from public.anatomical_sheet_versions where id = pg_temp.id('v1')),
pg_temp.id('asset')::text, 'editor updated the draft content in place'
);
-- Unknown asset uuid is refused at publish
update public.anatomical_sheet_versions
set content = pg_temp.sheet_doc('ffffffff-ffff-ffff-ffff-ffffffffffff')
where id = pg_temp.id('v1');
select throws_ok(
$$ select public.publish_sheet_version(pg_temp.id('v1')) $$,
'23514', null, 'publish refuses a view pointing at an asset not registered for the sheet'
);
update public.anatomical_sheet_versions
set content = pg_temp.sheet_doc(pg_temp.id('asset')) where id = pg_temp.id('v1');
-- Document species must match the sheet species (trigger)
select throws_ok(
$$ update public.anatomical_sheet_versions
set content = jsonb_set(pg_temp.sheet_doc(pg_temp.id('asset')), '{species_id}', '"canine"')
where id = pg_temp.id('v1') $$,
'23514', null, 'a document for another species is refused'
);
-- Dangling references are refused at publish
update public.anatomical_sheet_versions
set content = jsonb_set(pg_temp.sheet_doc(pg_temp.id('asset')), '{annotations,0,finding_zone_id}', '"nowhere"')
where id = pg_temp.id('v1');
select throws_ok(
$$ select public.publish_sheet_version(pg_temp.id('v1')) $$,
'23514', 'document not publishable: annotation.finding_zone.missing',
'publish refuses an annotation pointing at a missing finding zone'
);
update public.anatomical_sheet_versions
set content = jsonb_set(pg_temp.sheet_doc(pg_temp.id('asset')), '{annotations,1,id}', '"hip"')
where id = pg_temp.id('v1');
select throws_ok(
$$ select public.publish_sheet_version(pg_temp.id('v1')) $$,
'23514', 'document not publishable: annotation.id.duplicate',
'publish refuses duplicate annotation ids'
);
create function pg_temp.publish_issue(p_doc jsonb) returns text language plpgsql as $$
begin
update public.anatomical_sheet_versions set content = p_doc where id = pg_temp.id('v1');
perform public.publish_sheet_version(pg_temp.id('v1'));
return 'published';
exception when check_violation then
return sqlerrm;
end $$;
grant execute on function pg_temp.publish_issue(jsonb) to authenticated;
select is(
pg_temp.publish_issue(jsonb_set(pg_temp.sheet_doc(pg_temp.id('asset')), '{views,0,kind}', '"detail"')),
'document not publishable: view.main.count, view.parent.missing', 'SQL gate: no main view'
);
select is(
pg_temp.publish_issue(pg_temp.sheet_doc(pg_temp.id('asset')) #- '{annotations,2}'),
'document not publishable: view.unreachable', 'SQL gate: detail view without trigger'
);
select is(
pg_temp.publish_issue(jsonb_set(pg_temp.sheet_doc(pg_temp.id('asset')), '{views,1,parent_view_id}', '"nowhere"')),
'document not publishable: view.parent.missing, annotation.opens_view.invalid', 'SQL gate: dangling parent view'
);
select is(
pg_temp.publish_issue(jsonb_set(pg_temp.sheet_doc(pg_temp.id('asset')), '{views,1,id}', '"view-main"')),
'document not publishable: view.unreachable, view.id.duplicate, annotation.opens_view.invalid', 'SQL gate: duplicate view id'
);
select is(
pg_temp.publish_issue(jsonb_set(pg_temp.sheet_doc(pg_temp.id('asset')), '{annotations,0,view_id}', '"nowhere"')),
'document not publishable: annotation.view.missing', 'SQL gate: annotation on a missing view'
);
select is(
pg_temp.publish_issue(jsonb_set(pg_temp.sheet_doc(pg_temp.id('asset')), '{annotations,0,category_id}', '"nowhere"')),
'document not publishable: annotation.category.missing', 'SQL gate: missing category'
);
select is(
pg_temp.publish_issue(jsonb_set(pg_temp.sheet_doc(pg_temp.id('asset')), '{annotations,1,vertebral_region_code}', '"Z"')),
'document not publishable: annotation.region.missing', 'SQL gate: unknown vertebral region'
);
select is(
pg_temp.publish_issue(jsonb_set(pg_temp.sheet_doc(pg_temp.id('asset')), '{annotations,2,opens_view_id}', '"view-main"')),
'document not publishable: view.unreachable, annotation.opens_view.invalid', 'SQL gate: trigger opening a non-child view'
);
select is(
pg_temp.publish_issue(jsonb_set(pg_temp.sheet_doc(pg_temp.id('asset')), '{vertebral_config,regions}',
'[{"code":"C","name":{"fr":"a","en":"a"},"count":7},{"code":"C","name":{"fr":"b","en":"b"},"count":7}]')),
'document not publishable: region.code.duplicate', 'SQL gate: duplicate region code'
);
select is(
pg_temp.publish_issue(jsonb_set(pg_temp.sheet_doc(pg_temp.id('asset')), '{finding_zones}',
'[{"id":"hip","name":{"fr":"a","en":"a"},"categories":[]},{"id":"hip","name":{"fr":"b","en":"b"},"categories":[]}]')),
'document not publishable: finding_zone.id.duplicate', 'SQL gate: duplicate finding zone id'
);
select is(
pg_temp.publish_issue(jsonb_set(pg_temp.sheet_doc(pg_temp.id('asset')), '{views}', '"not-an-array"')),
'document not publishable: document.shape', 'SQL gate: views not an array'
);
update public.anatomical_sheet_versions
set content = pg_temp.sheet_doc(pg_temp.id('asset')) where id = pg_temp.id('v1');
select lives_ok(
$$ select public.publish_sheet_version(pg_temp.id('v1')) $$,
'alice publishes version 1'
);
select results_eq(
$$ select status::text, published_by, published_at is not null
from public.anatomical_sheet_versions where id = pg_temp.id('v1') $$,
$$ values ('published', '20000000-0000-0000-0000-00000000000a'::uuid, true) $$,
'version 1 is published by alice'
);
select is(
(select current_version_id from public.anatomical_sheets where id = pg_temp.id('sheet')),
pg_temp.id('v1'), 'sheet current version is v1'
);
select throws_ok(
$$ select public.publish_sheet_version(pg_temp.id('v1')) $$,
'55000', null, 'publishing twice is refused'
);
-- ---------------------------------------------------------------------------
-- 3. Published rows are immutable (editor, then table owner)
-- ---------------------------------------------------------------------------
-- Through the API role the policies hide published rows from UPDATE/DELETE:
-- the statement touches zero rows instead of raising.
update public.anatomical_sheet_versions set content = '{}'::jsonb where id = pg_temp.id('v1');
select is(
(select content from public.anatomical_sheet_versions where id = pg_temp.id('v1')),
pg_temp.sheet_doc(pg_temp.id('asset')), 'editor UPDATE of published content touches no row'
);
update public.anatomical_sheet_versions set change_note = 'x' where id = pg_temp.id('v1');
select is(
(select change_note from public.anatomical_sheet_versions where id = pg_temp.id('v1')),
'asset wired', 'editor UPDATE of a published change note touches no row'
);
select throws_ok(
$$ delete from public.anatomical_sheet_versions where id = pg_temp.id('v1') $$,
'42501', null, 'editor has no DELETE privilege on versions (RPC only)'
);
reset role;
select throws_ok(
$$ update public.anatomical_sheet_versions
set content = pg_temp.sheet_doc(pg_temp.id('asset')) || '{"name":{"fr":"X","en":"X"}}'
where id = pg_temp.id('v1') $$,
'42501', null, 'even the table owner cannot change published content'
);
select throws_ok(
$$ update public.anatomical_sheet_versions set status = 'draft' where id = pg_temp.id('v1') $$,
'42501', null, 'a published version cannot go back to draft'
);
select throws_ok(
$$ update public.anatomical_sheet_versions set version_number = 9 where id = pg_temp.id('v1') $$,
'42501', null, 'version_number is immutable'
);
select throws_ok(
$$ delete from public.anatomical_sheet_versions where id = pg_temp.id('v1') $$,
'55000', null, 'owner role cannot delete a published version either'
);
-- ---------------------------------------------------------------------------
-- 4. New version leaves the old one intact
-- ---------------------------------------------------------------------------
set local role authenticated;
select set_config('request.jwt.claims', '{"sub":"20000000-0000-0000-0000-00000000000a","role":"authenticated"}', true);
create table pg_temp.v1_snapshot as
select * from public.anatomical_sheet_versions where id = pg_temp.id('v1');
insert into pg_temp.ids select 'v2', public.create_sheet_draft(pg_temp.id('sheet'), null, 'second edition');
select results_eq(
$$ select version_number, status::text, change_note, content = (select content from pg_temp.v1_snapshot)
from public.anatomical_sheet_versions where id = pg_temp.id('v2') $$,
$$ values (2, 'draft', 'second edition', true) $$,
'draft v2 starts from the current version content'
);
select throws_ok(
$$ select public.create_sheet_draft(pg_temp.id('sheet')) $$,
'23505', null, 'one draft per sheet'
);
update public.anatomical_sheet_versions
set content = jsonb_set(pg_temp.sheet_doc(pg_temp.id('asset')), '{name,fr}', '"Cheval v2"')
where id = pg_temp.id('v2');
select lives_ok($$ select public.publish_sheet_version(pg_temp.id('v2')) $$, 'alice publishes v2');
select is(
(select current_version_id from public.anatomical_sheets where id = pg_temp.id('sheet')),
pg_temp.id('v2'), 'current version moved to v2'
);
select is(
(select count(*) from public.anatomical_sheet_versions v, pg_temp.v1_snapshot s
where v.id = s.id and v.content = s.content and v.status = s.status
and v.published_at = s.published_at and v.version_number = s.version_number
and v.change_note = s.change_note),
1::bigint, 'v1 row is byte-identical after v2 was published'
);
select throws_ok(
$$ select public.delete_sheet_version(pg_temp.id('v2')) $$,
'55000', null, 'the current version cannot be deleted'
);
select throws_ok(
$$ select public.delete_sheet_version(pg_temp.id('v1')) $$,
'55000', null, 'a published version cannot be deleted before deprecation'
);
-- ---------------------------------------------------------------------------
-- 5. Bob: private sheet invisible; public sheet usable; copy keeps provenance
-- ---------------------------------------------------------------------------
select set_config('request.jwt.claims', '{"sub":"20000000-0000-0000-0000-00000000000b","role":"authenticated"}', true);
select is((select count(*) from public.anatomical_sheets where id = pg_temp.id('sheet')), 0::bigint, 'bob does not see the private sheet');
select is((select count(*) from public.anatomical_sheet_versions where sheet_id = pg_temp.id('sheet')), 0::bigint, 'bob does not see its versions');
select is((select count(*) from public.anatomical_sheet_assets where sheet_id = pg_temp.id('sheet')), 0::bigint, 'bob does not see its assets');
select throws_ok(
$$ select public.fork_anatomical_sheet(pg_temp.id('v2'), 'Copie', 'copie-bob') $$,
'42501', null, 'bob cannot copy a private sheet'
);
select throws_ok(
$$ select public.create_sheet_draft(pg_temp.id('sheet')) $$,
'42501', null, 'bob cannot open a draft on alice sheet'
);
update public.anatomical_sheets set name = 'hijack' where id = pg_temp.id('sheet');
select throws_ok(
$$ insert into public.anatomical_sheets (species_id, name, slug, creator_user_id)
values ('equine', 'direct', 'direct', '20000000-0000-0000-0000-00000000000b') $$,
'42501', null, 'bob cannot insert a sheet row directly'
);
select throws_ok(
$$ insert into public.anatomical_sheet_versions (sheet_id, version_number, document_schema_version, content)
values (pg_temp.id('sheet'), 9, 2, pg_temp.sheet_doc(null)) $$,
'42501', null, 'bob cannot insert a version row directly'
);
-- alice makes the sheet public through the identity-column policy
select set_config('request.jwt.claims', '{"sub":"20000000-0000-0000-0000-00000000000a","role":"authenticated"}', true);
select is((select name from public.anatomical_sheets where id = pg_temp.id('sheet')), 'Mon cheval', 'bob update on alice sheet changed nothing');
select lives_ok($$ select public.set_sheet_visibility(pg_temp.id('sheet'), 'public') $$, 'alice makes the sheet public (audited RPC)');
insert into pg_temp.ids select 'v3', public.create_sheet_draft(pg_temp.id('sheet'), null, 'work in progress');
insert into pg_temp.ids select 'asset-unused', public.register_sheet_asset(
pg_temp.id('sheet'), repeat('b', 64), 1000, 'Unused.svg'
);
select set_config('request.jwt.claims', '{"sub":"20000000-0000-0000-0000-00000000000b","role":"authenticated"}', true);
select is((select count(*) from public.anatomical_sheets where id = pg_temp.id('sheet')), 1::bigint, 'bob sees the public sheet');
select results_eq(
$$ select version_number from public.anatomical_sheet_versions where sheet_id = pg_temp.id('sheet') order by 1 $$,
$$ values (1), (2) $$,
'bob sees the published versions, not the draft'
);
select is(
(select count(*) from public.anatomical_sheet_versions where id = pg_temp.id('v3') and content = '{}'::jsonb),
0::bigint, 'bob cannot read the draft'
);
update public.anatomical_sheet_versions set content = '{"schema_version":2}'::jsonb where id = pg_temp.id('v3');
select throws_ok(
$$ select public.fork_anatomical_sheet(pg_temp.id('v3'), 'Copie', 'copie-bob') $$,
'42501', null, 'a draft cannot be copied (hidden from non-editors)'
);
update public.anatomical_sheets set name = 'hijack-public' where id = pg_temp.id('sheet');
select is((select name from public.anatomical_sheets where id = pg_temp.id('sheet')), 'Mon cheval', 'bob cannot rename a public sheet he does not edit');
-- Every editor-gated RPC refuses a non-editor, even on a public sheet
select throws_ok($$ select public.publish_sheet_version(pg_temp.id('v3')) $$, '42501', null, 'non-editor cannot publish');
select throws_ok($$ select public.deprecate_sheet_version(pg_temp.id('v2'), 'x') $$, '42501', null, 'non-editor cannot deprecate');
select throws_ok($$ select public.delete_sheet_version(pg_temp.id('v3')) $$, '42501', null, 'non-editor cannot delete a version');
select throws_ok($$ select public.archive_anatomical_sheet(pg_temp.id('sheet')) $$, '42501', null, 'non-editor cannot archive');
select throws_ok($$ select public.restore_anatomical_sheet(pg_temp.id('sheet')) $$, '42501', null, 'non-editor cannot restore');
select throws_ok($$ select public.delete_anatomical_sheet(pg_temp.id('sheet')) $$, '42501', null, 'non-editor cannot delete a sheet');
select throws_ok($$ select public.set_sheet_visibility(pg_temp.id('sheet'), 'private') $$, '42501', null, 'non-editor cannot change visibility');
select throws_ok($$ select public.register_sheet_asset(pg_temp.id('sheet'), repeat('c', 64), 10, 'x.svg') $$, '42501', null, 'non-editor cannot register an asset');
select throws_ok($$ select public.delete_sheet_asset(pg_temp.id('asset-unused')) $$, '42501', null, 'non-editor cannot delete an asset');
select throws_ok($$ select public.publish_sheet_version(gen_random_uuid()) $$, '42501', null, 'unknown version gets the same answer as a foreign one');
-- A platform admin is not an editor of a personal sheet
select set_config('request.jwt.claims', '{"sub":"20000000-0000-0000-0000-000000000001","role":"authenticated"}', true);
select throws_ok($$ select public.create_sheet_draft(pg_temp.id('sheet')) $$, '42501', null, 'platform owner cannot edit a personal sheet');
select set_config('request.jwt.claims', '{"sub":"20000000-0000-0000-0000-00000000000b","role":"authenticated"}', true);
create table pg_temp.source_snapshot as
select s.updated_at as sheet_updated_at, s.current_version_id, v.content, v.updated_at as version_updated_at,
(select count(*) from public.anatomical_sheet_assets where sheet_id = s.id) as asset_count
from public.anatomical_sheets s join public.anatomical_sheet_versions v on v.id = s.current_version_id
where s.id = pg_temp.id('sheet');
insert into pg_temp.ids select 'fork', public.fork_anatomical_sheet(pg_temp.id('v2'), 'Copie de Bob', 'copie-bob');
select results_eq(
$$ select creator_user_id, based_on_sheet_id, based_on_version_id, species_id, visibility::text, is_official
from public.anatomical_sheets where id = pg_temp.id('fork') $$,
$$ values ('20000000-0000-0000-0000-00000000000b'::uuid, pg_temp.id('sheet'), pg_temp.id('v2'), 'equine', 'private', false) $$,
'copy records provenance (source sheet + version) and belongs to bob'
);
insert into pg_temp.ids select 'fork-v1', id from public.anatomical_sheet_versions where sheet_id = pg_temp.id('fork');
insert into pg_temp.ids select 'fork-asset', id from public.anatomical_sheet_assets where sheet_id = pg_temp.id('fork');
select results_eq(
$$ select version_number, status::text, created_by from public.anatomical_sheet_versions where id = pg_temp.id('fork-v1') $$,
$$ values (1, 'draft', '20000000-0000-0000-0000-00000000000b'::uuid) $$,
'copy starts as draft v1 owned by bob'
);
select results_eq(
$$ select sha256, byte_size, id <> pg_temp.id('asset') from public.anatomical_sheet_assets where sheet_id = pg_temp.id('fork') $$,
$$ values (repeat('a', 64), 142400, true) $$,
'only the asset referenced by the copied version is copied (same content, new id)'
);
select is(
(select content -> 'views' -> 0 ->> 'svg_asset_id' from public.anatomical_sheet_versions where id = pg_temp.id('fork-v1')),
pg_temp.id('fork-asset')::text, 'copied document points at the copied asset'
);
select is(
(select content #- '{views,0,svg_asset_id}' from public.anatomical_sheet_versions where id = pg_temp.id('fork-v1')),
(select content #- '{views,0,svg_asset_id}' from pg_temp.source_snapshot),
'copied document is otherwise identical to the source'
);
-- bob edits his copy; the source stays untouched
update public.anatomical_sheet_versions
set content = jsonb_set(content, '{name,fr}', '"Ma copie"') where id = pg_temp.id('fork-v1');
select lives_ok($$ select public.publish_sheet_version(pg_temp.id('fork-v1')) $$, 'bob publishes his copy');
select set_config('request.jwt.claims', '{"sub":"20000000-0000-0000-0000-00000000000a","role":"authenticated"}', true);
select is(
(select count(*) from public.anatomical_sheets s join public.anatomical_sheet_versions v on v.id = s.current_version_id,
pg_temp.source_snapshot snap
where s.id = pg_temp.id('sheet') and s.updated_at = snap.sheet_updated_at and s.current_version_id = snap.current_version_id
and v.content = snap.content and v.updated_at = snap.version_updated_at
and (select count(*) from public.anatomical_sheet_assets where sheet_id = s.id) = snap.asset_count),
1::bigint, 'source sheet, version and assets are unchanged by the copy and its edits'
);
-- ---------------------------------------------------------------------------
-- 6. Deprecation, deletion preconditions, archive, soft delete
-- ---------------------------------------------------------------------------
select lives_ok($$ select public.deprecate_sheet_version(pg_temp.id('v2'), 'superseded') $$, 'alice deprecates v2');
select results_eq(
$$ select status::text, deprecated_by from public.anatomical_sheet_versions where id = pg_temp.id('v2') $$,
$$ values ('deprecated', '20000000-0000-0000-0000-00000000000a'::uuid) $$,
'v2 is deprecated'
);
select is(
(select current_version_id from public.anatomical_sheets where id = pg_temp.id('sheet')),
pg_temp.id('v1'), 'current version falls back to the latest published one (v1)'
);
update public.anatomical_sheet_versions set content = '{}'::jsonb where id = pg_temp.id('v2');
select is(
(select content ->> 'schema_version' from public.anatomical_sheet_versions where id = pg_temp.id('v2')),
'2', 'a deprecated version is hidden from editor UPDATE'
);
reset role;
select throws_ok(
$$ update public.anatomical_sheet_versions set change_note = 'late edit' where id = pg_temp.id('v2') $$,
'42501', null, 'a deprecated version is frozen for the table owner too'
);
set local role authenticated;
select set_config('request.jwt.claims', '{"sub":"20000000-0000-0000-0000-00000000000a","role":"authenticated"}', true);
select throws_ok(
$$ select public.delete_sheet_version(pg_temp.id('v2')) $$,
'55000', null, 'v2 cannot be deleted while bob copy derives from it'
);
select throws_ok(
$$ select public.delete_anatomical_sheet(pg_temp.id('sheet')) $$,
'55000', null, 'the sheet cannot be deleted while a copy is active'
);
select lives_ok($$ select public.archive_anatomical_sheet(pg_temp.id('sheet')) $$, 'alice archives the sheet');
select is((select count(*) from public.anatomical_sheets where id = pg_temp.id('sheet')), 1::bigint, 'the editor still reads her archived sheet');
select set_config('request.jwt.claims', '{"sub":"20000000-0000-0000-0000-00000000000b","role":"authenticated"}', true);
select is((select count(*) from public.anatomical_sheets where id = pg_temp.id('sheet')), 0::bigint, 'an archived sheet is no longer usable by others');
select throws_ok(
$$ select public.delete_sheet_version(pg_temp.id('fork-v1')) $$,
'55000', null, 'bob cannot delete the published version of his copy'
);
select lives_ok($$ select public.delete_anatomical_sheet(pg_temp.id('fork')) $$, 'bob soft-deletes his copy');
select is((select count(*) from public.anatomical_sheets where id = pg_temp.id('fork')), 0::bigint, 'a deleted sheet is invisible to its creator');
select set_config('request.jwt.claims', '{"sub":"20000000-0000-0000-0000-00000000000a","role":"authenticated"}', true);
select lives_ok($$ select public.restore_anatomical_sheet(pg_temp.id('sheet')) $$, 'alice restores the sheet');
select lives_ok($$ select public.delete_sheet_version(pg_temp.id('v2')) $$, 'deprecated v2 is deleted once no active copy depends on it');
select is((select count(*) from public.anatomical_sheet_versions where id = pg_temp.id('v2')), 0::bigint, 'v2 row is gone');
select lives_ok($$ select public.delete_sheet_version(pg_temp.id('v3')) $$, 'editor drops her own draft through the RPC');
insert into pg_temp.ids select 'v4', public.create_sheet_draft(pg_temp.id('sheet'), null, 'after deletion');
select is(
(select version_number from public.anatomical_sheet_versions where id = pg_temp.id('v4')),
4, 'a deleted version number is never reused'
);
select lives_ok($$ select public.delete_sheet_asset(pg_temp.id('asset-unused')) $$, 'an unreferenced asset can be deleted');
select throws_ok(
$$ select public.delete_sheet_asset(pg_temp.id('asset')) $$,
'55000', null, 'an asset referenced by a version cannot be deleted'
);
-- ---------------------------------------------------------------------------
-- 7. Deactivated account
-- ---------------------------------------------------------------------------
reset role;
update public.profiles set active = false where id = '20000000-0000-0000-0000-00000000000b';
set local role authenticated;
select set_config('request.jwt.claims', '{"sub":"20000000-0000-0000-0000-00000000000b","role":"authenticated"}', true);
select throws_ok(
$$ select public.create_anatomical_sheet('equine', 'Nope', 'nope', pg_temp.sheet_doc(null)) $$,
'42501', null, 'a deactivated account cannot write'
);
reset role;
update public.profiles set active = true where id = '20000000-0000-0000-0000-00000000000b';
set local role authenticated;
select set_config('request.jwt.claims', '{"sub":"20000000-0000-0000-0000-00000000000a","role":"authenticated"}', true);
-- ---------------------------------------------------------------------------
-- 8. Official sheets: platform admins only
-- ---------------------------------------------------------------------------
select throws_ok(
$$ select public.create_anatomical_sheet('equine', 'Officielle', 'officielle', pg_temp.sheet_doc(null), '', 'public', true) $$,
'42501', null, 'a plain user cannot create an official sheet'
);
select set_config('request.jwt.claims', '{"sub":"20000000-0000-0000-0000-000000000001","role":"authenticated"}', true);
insert into pg_temp.ids select 'official', public.create_anatomical_sheet(
'equine', 'Officielle test', 'officielle-test', pg_temp.sheet_doc(null), 'Fiche officielle', 'public', true
);
select results_eq(
$$ select creator_user_id, is_official, visibility::text from public.anatomical_sheets where id = pg_temp.id('official') $$,
$$ values (null::uuid, true, 'public') $$,
'official sheet is platform-owned'
);
select set_config('request.jwt.claims', '{"sub":"20000000-0000-0000-0000-00000000000a","role":"authenticated"}', true);
select is((select count(*) from public.anatomical_sheets where id = pg_temp.id('official')), 1::bigint, 'alice sees the public official sheet');
select is(
(select count(*) from public.anatomical_sheet_versions where sheet_id = pg_temp.id('official')),
0::bigint, 'alice does not see the official draft'
);
select throws_ok(
$$ select public.create_sheet_draft(pg_temp.id('official')) $$,
'42501', null, 'alice cannot edit the official sheet'
);
-- ---------------------------------------------------------------------------
-- 9. Anonymous
-- ---------------------------------------------------------------------------
set local role anon;
select set_config('request.jwt.claims', '', true);
select throws_ok($$ select * from public.species $$, '42501', null, 'anon cannot read species');
select throws_ok($$ select * from public.anatomical_sheets $$, '42501', null, 'anon cannot read sheets');
select throws_ok(
$$ select public.create_anatomical_sheet('equine', 'x', 'x-x', '{}'::jsonb) $$,
'42501', null, 'anon cannot call create_anatomical_sheet'
);
-- ---------------------------------------------------------------------------
-- 10. Audit trail
-- ---------------------------------------------------------------------------
reset role;
select results_eq(
$$ select action from audit.audit_logs
where resource_id in (pg_temp.id('sheet'), pg_temp.id('v1'), pg_temp.id('v2'), pg_temp.id('v3'), pg_temp.id('fork'),
pg_temp.id('asset'), pg_temp.id('asset-unused'))
group by action order by action collate "C" $$,
$$ values ('anatomical_sheet.archived'), ('anatomical_sheet.created'), ('anatomical_sheet.deleted'),
('anatomical_sheet.forked'), ('anatomical_sheet.restored'), ('anatomical_sheet.visibility_changed'),
('anatomical_sheet_asset.deleted'), ('anatomical_sheet_asset.registered'),
('anatomical_sheet_version.created'), ('anatomical_sheet_version.deleted'),
('anatomical_sheet_version.deprecated'), ('anatomical_sheet_version.published') $$,
'every lifecycle step left an audit event'
);
-- The new workflow RPCs exist
select has_function('public', 'create_official_sheet', 'create_official_sheet exists');
select has_function('public', 'publish_sheet_version', 'publish_sheet_version exists');
select has_function('public', 'create_sheet_working_copy', 'create_sheet_working_copy exists');
select * from finish();
rollback;
+155 -137
View File
@@ -1,155 +1,173 @@
-- Storage read policy on bucket anatomical-sheet-assets: an object is readable
-- through a sheet (published reference for users, any version for editors),
-- never through its hash alone. No API writes.
-- Sheet-asset Storage after V1-2.1 (M4, M5): the bucket is private and 2 MiB,
-- the read predicate follows the catalogue rules (contract §9.4), the editor
-- upload INSERT policy exists, no UPDATE/DELETE policy. Rows are seeded
-- directly (table owner) to exercise the policy, not the RPCs (those are 016).
begin;
select plan(28);
select plan(15);
insert into auth.users (id, email) values
('30000000-0000-0000-0000-00000000000a', 'alice-assets@test.local'),
('30000000-0000-0000-0000-00000000000b', 'bob-assets@test.local');
-- Bucket
select is((select public from storage.buckets where id = 'anatomical-sheet-assets'), false, 'the bucket is private');
select is((select file_size_limit from storage.buckets where id = 'anatomical-sheet-assets'), 2097152::bigint, 'the bucket limit is 2 MiB (M5)');
create table pg_temp.ids (key text primary key, id uuid not null);
create function pg_temp.id(p_key text) returns uuid language sql stable
as $$ select id from pg_temp.ids where key = p_key $$;
grant all on pg_temp.ids to anon, authenticated, service_role;
grant execute on function pg_temp.id(text) to anon, authenticated, service_role;
-- Policies on storage.objects for the bucket: read + editor insert, nothing else.
select is(
(select count(*) from pg_policies where schemaname='storage' and tablename='objects'
and (coalesce(qual,'')||coalesce(with_check,'')) like '%anatomical-sheet-assets%'),
2::bigint, 'two policies name the bucket (read, editor insert)'
);
select is(
(select count(*) from pg_policies where schemaname='storage' and tablename='objects' and cmd in ('UPDATE','DELETE')
and (coalesce(qual,'')||coalesce(with_check,'')) like '%anatomical-sheet-assets%'),
0::bigint, 'no UPDATE or DELETE policy on the bucket'
);
-- Accounts: owner, editor (admin + capability), reader (catalog_reader), plain.
insert into auth.users (id, email, email_confirmed_at) values
('30000000-0000-0000-0000-000000000001', 'own-st@test.local', now()),
('30000000-0000-0000-0000-00000000000e', 'ed-st@test.local', now()),
('30000000-0000-0000-0000-0000000000d0', 'rd-st@test.local', now()),
('30000000-0000-0000-0000-0000000000d1', 'pl-st@test.local', now());
insert into auth.mfa_factors (id, user_id, factor_type, status, created_at, updated_at)
values (gen_random_uuid(), '30000000-0000-0000-0000-00000000000e', 'totp', 'verified', now(), now());
insert into auth.sessions (id, user_id, aal) values
('31000000-0000-0000-0000-000000000001', '30000000-0000-0000-0000-000000000001', 'aal2'),
('31000000-0000-0000-0000-00000000000e', '30000000-0000-0000-0000-00000000000e', 'aal2');
select set_config('request.jwt.claims', '', true);
select private.assign_platform_role(null, '30000000-0000-0000-0000-000000000001', 'owner');
select private.assign_platform_role(null, '30000000-0000-0000-0000-00000000000e', 'admin');
insert into public.anatomical_catalog_grants (user_id, grant_kind, reason, verification_note, granted_by) values
('30000000-0000-0000-0000-00000000000e', 'sheet_editor', 'author', 'checked', '30000000-0000-0000-0000-000000000001'),
('30000000-0000-0000-0000-0000000000d0', 'catalog_reader', 'beta', null, '30000000-0000-0000-0000-000000000001');
-- An official sheet with a published version (asset A), a deprecated version
-- (asset B), and a draft (asset C, confirmed). A and B are referenced by
-- non-draft versions; C only by the draft.
insert into public.anatomical_sheets (id, species_id, name, slug, is_official, visibility, status, current_version_id)
values ('32000000-0000-0000-0000-000000000001', 'equine', 'Pub', 'pub-storage', true, 'private', 'active', null);
insert into public.anatomical_sheet_assets (id, sheet_id, sha256, byte_size, file_name, uploaded_at) values
('32000000-0000-0000-0000-00000000000a', '32000000-0000-0000-0000-000000000001', repeat('a',64), 100, 'a.svg', now()),
('32000000-0000-0000-0000-00000000000b', '32000000-0000-0000-0000-000000000001', repeat('b',64), 100, 'b.svg', now()),
('32000000-0000-0000-0000-00000000000c', '32000000-0000-0000-0000-000000000001', repeat('c',64), 100, 'c.svg', now());
-- The content trigger needs an authenticated actor for a non-historical
-- sheet, so the direct version seeding carries the owner's claim.
select set_config('request.jwt.claims', '{"sub":"30000000-0000-0000-0000-000000000001"}', true);
-- Minimal publishable document with one main view on a given asset.
create function pg_temp.doc(p_asset uuid) returns jsonb language sql as $$
select jsonb_build_object(
'schema_version', 2, 'species_id', 'equine',
'name', jsonb_build_object('fr', 'A', 'en', 'A'),
'description', '{}'::jsonb, 'scope_disclaimer', '{}'::jsonb,
'attribution', jsonb_build_object('authors', '[]'::jsonb, 'license', null, 'notes', null),
'vertebral_config', jsonb_build_object('regions', '[]'::jsonb),
'categories', '[]'::jsonb,
'views', jsonb_build_array(jsonb_build_object('id', 'main', 'kind', 'main',
'name', jsonb_build_object('fr', 'V', 'en', 'V'), 'svg_asset_id', p_asset, 'view_box', null)),
'annotations', '[]'::jsonb, 'finding_zones', '[]'::jsonb);
select jsonb_build_object('schema_version',2,'species_id','equine',
'name',jsonb_build_object('fr','P','en','P'),'description','{}'::jsonb,'scope_disclaimer','{}'::jsonb,
'attribution',jsonb_build_object('authors','[]'::jsonb,'license',null,'notes',null),
'vertebral_config',jsonb_build_object('regions','[]'::jsonb),'references','[]'::jsonb,
'categories','[]'::jsonb,
'views',jsonb_build_array(jsonb_build_object('id','main','kind','main','name',jsonb_build_object('fr','V','en','V'),'svg_asset_id',p_asset,'view_box',null)),
'annotations','[]'::jsonb,'finding_zones','[]'::jsonb);
$$;
grant execute on function pg_temp.doc(uuid) to authenticated, service_role;
insert into public.anatomical_sheet_versions (id, sheet_id, version_number, status, document_schema_version, content, published_at, document_fingerprint)
values ('33000000-0000-0000-0000-000000000001', '32000000-0000-0000-0000-000000000001', 1, 'published', 2, pg_temp.doc('32000000-0000-0000-0000-00000000000a'), now(), repeat('0',64));
insert into public.anatomical_sheet_versions (id, sheet_id, version_number, status, document_schema_version, content, published_at, deprecated_at, document_fingerprint)
values ('33000000-0000-0000-0000-000000000002', '32000000-0000-0000-0000-000000000001', 2, 'deprecated', 2, pg_temp.doc('32000000-0000-0000-0000-00000000000b'), now(), now(), repeat('0',64));
insert into public.anatomical_sheet_versions (id, sheet_id, version_number, status, document_schema_version, content)
values ('33000000-0000-0000-0000-000000000003', '32000000-0000-0000-0000-000000000001', 3, 'draft', 2, pg_temp.doc('32000000-0000-0000-0000-00000000000c'));
update public.anatomical_sheets set current_version_id = '33000000-0000-0000-0000-000000000001' where id = '32000000-0000-0000-0000-000000000001';
insert into storage.objects (bucket_id, name, metadata) values
('anatomical-sheet-assets', repeat('a',64)||'.svg', '{"size":100}'),
('anatomical-sheet-assets', repeat('b',64)||'.svg', '{"size":100}'),
('anatomical-sheet-assets', repeat('c',64)||'.svg', '{"size":100}');
-- A fourth object whose row is pending (never confirmed): readable by nobody.
insert into public.anatomical_sheet_assets (id, sheet_id, sha256, byte_size, file_name)
values ('32000000-0000-0000-0000-00000000000d', '32000000-0000-0000-0000-000000000001', repeat('d',64), 100, 'd.svg');
insert into storage.objects (bucket_id, name, metadata) values ('anatomical-sheet-assets', repeat('d',64)||'.svg', '{"size":100}');
-- 1. Bucket contract
select is((select public from storage.buckets where id = 'anatomical-sheet-assets'), false, 'bucket is private');
select is(
(select allowed_mime_types from storage.buckets where id = 'anatomical-sheet-assets'),
array['image/svg+xml'], 'bucket accepts SVG only'
);
select is(
(select count(*) from pg_policies where schemaname = 'storage' and tablename = 'objects'
and policyname = 'anatomical_sheet_assets_read' and cmd = 'SELECT'),
1::bigint, 'one SELECT policy on storage.objects for the bucket'
);
select is(
(select count(*) from pg_policies where schemaname = 'storage' and tablename = 'objects'
and policyname like 'anatomical_sheet_assets%' and cmd <> 'SELECT'),
0::bigint, 'no write policy on the bucket for API roles'
);
create function pg_temp.act(p_uid uuid, p_sid uuid, p_aal text) returns void language sql as $$
select set_config('request.jwt.claims', jsonb_build_object('sub',p_uid,'role','authenticated','aal',p_aal,'session_id',p_sid)::text, true);
$$;
grant execute on function pg_temp.act(uuid,uuid,text) to authenticated;
-- 2. Alice: sheet with published v1 on asset A, draft v2 on asset B; C is registered but unreferenced
-- Reader (catalog_reader, aal1): the published and deprecated drawings only.
set local role authenticated;
select set_config('request.jwt.claims', '{"sub":"30000000-0000-0000-0000-00000000000a","role":"authenticated"}', true);
insert into pg_temp.ids select 'sheet', public.create_anatomical_sheet('equine', 'Assets', 'assets-test', pg_temp.doc(null));
insert into pg_temp.ids select 'a', public.register_sheet_asset(pg_temp.id('sheet'), repeat('a', 64), 100, 'A.svg');
insert into pg_temp.ids select 'b', public.register_sheet_asset(pg_temp.id('sheet'), repeat('b', 64), 100, 'B.svg');
insert into pg_temp.ids select 'c', public.register_sheet_asset(pg_temp.id('sheet'), repeat('c', 64), 100, 'C.svg');
insert into pg_temp.ids select 'v1', id from public.anatomical_sheet_versions where sheet_id = pg_temp.id('sheet');
update public.anatomical_sheet_versions set content = pg_temp.doc(pg_temp.id('a')) where id = pg_temp.id('v1');
select lives_ok($$ select public.publish_sheet_version(pg_temp.id('v1')) $$, 'v1 published on asset A');
insert into pg_temp.ids select 'v2', public.create_sheet_draft(pg_temp.id('sheet'));
update public.anatomical_sheet_versions set content = pg_temp.doc(pg_temp.id('b')) where id = pg_temp.id('v2');
select pg_temp.act('30000000-0000-0000-0000-0000000000d0', gen_random_uuid(), 'aal1');
select results_eq(
$$ select name from storage.objects where bucket_id='anatomical-sheet-assets' order by name $$,
$$ values (repeat('a',64)||'.svg'), (repeat('b',64)||'.svg') $$,
'a catalogue reader reads the published and deprecated drawings, not the draft or pending ones'
);
-- Objects uploaded by the operator (owner session), then confirmed through the
-- service-role RPC for A and B only; C stays metadata without bytes.
reset role;
insert into storage.objects (bucket_id, name) values
('anatomical-sheet-assets', repeat('a', 64) || '.svg'),
('anatomical-sheet-assets', repeat('b', 64) || '.svg'),
('anatomical-sheet-assets', repeat('c', 64) || '.svg'),
('anatomical-sheet-assets', repeat('d', 64) || '.svg');
set local role authenticated;
select set_config('request.jwt.claims', '{"sub":"30000000-0000-0000-0000-00000000000a","role":"authenticated"}', true);
select is((select count(*) from storage.objects where bucket_id = 'anatomical-sheet-assets'), 0::bigint, 'nothing is readable before the upload is confirmed');
-- Editor at aal2: every uploaded drawing of the official sheet (a, b, c), not the pending d.
select pg_temp.act('30000000-0000-0000-0000-00000000000e', '31000000-0000-0000-0000-00000000000e', 'aal2');
select results_eq(
$$ select name from storage.objects where bucket_id='anatomical-sheet-assets' order by name $$,
$$ values (repeat('a',64)||'.svg'), (repeat('b',64)||'.svg'), (repeat('c',64)||'.svg') $$,
'an editor at aal2 reads every confirmed drawing of the official sheet, not the pending one'
);
-- Editor at aal1 (no live aal2 session): the capability branch does not apply,
-- but a capability holder also has catalogue access, so the reader branch still
-- shows the published and deprecated drawings (not the draft's).
select pg_temp.act('30000000-0000-0000-0000-00000000000e', gen_random_uuid(), 'aal1');
select results_eq(
$$ select name from storage.objects where bucket_id='anatomical-sheet-assets' order by name $$,
$$ values (repeat('a',64)||'.svg'), (repeat('b',64)||'.svg') $$,
'the editor at aal1 falls back to the reader branch: published and deprecated only'
);
-- A plain confirmed account with no right: nothing.
select pg_temp.act('30000000-0000-0000-0000-0000000000d1', gen_random_uuid(), 'aal1');
select is((select count(*) from storage.objects where bucket_id='anatomical-sheet-assets'), 0::bigint,
'a confirmed account without any right reads nothing');
-- The INSERT policy only allows a pending key of one''s own sheet: a confirmed
-- key is refused by its WITH CHECK (no UPDATE/DELETE policy exists at all, per
-- the census above; the runtime refusal of those is a storage-API concern, not
-- RLS, so it is not asserted here).
select pg_temp.act('30000000-0000-0000-0000-00000000000e', '31000000-0000-0000-0000-00000000000e', 'aal2');
select throws_ok(
$$ select public.confirm_sheet_asset_upload(pg_temp.id('a')) $$,
'42501', null, 'an editor cannot confirm an upload (service role only)'
$$ insert into storage.objects (bucket_id, name) values ('anatomical-sheet-assets', repeat('a',64)||'.svg') $$,
'42501', null, 'an editor cannot insert a confirmed (non-pending) object key'
);
-- A fifth asset, pending, with no object yet: the editor uploads its key.
reset role;
select set_config('request.jwt.claims', '{"sub":"30000000-0000-0000-0000-000000000001"}', true);
insert into public.anatomical_sheet_assets (id, sheet_id, sha256, byte_size, file_name)
values ('32000000-0000-0000-0000-00000000000e', '32000000-0000-0000-0000-000000000001', repeat('e',64), 100, 'e.svg');
set local role authenticated;
select pg_temp.act('30000000-0000-0000-0000-00000000000e', '31000000-0000-0000-0000-00000000000e', 'aal2');
select lives_ok(
$$ insert into storage.objects (bucket_id, name, metadata) values ('anatomical-sheet-assets', repeat('e',64)||'.svg', '{"size":100}') $$,
'an editor uploads the pending key of their own sheet'
);
-- confirm with the storage check: a wrong size is refused, the right one works.
reset role;
update storage.objects set metadata = '{"size":999}' where bucket_id='anatomical-sheet-assets' and name = repeat('d',64)||'.svg';
set local role authenticated;
select pg_temp.act('30000000-0000-0000-0000-00000000000e', '31000000-0000-0000-0000-00000000000e', 'aal2');
select throws_ok(
$$ select public.confirm_sheet_asset_upload('32000000-0000-0000-0000-00000000000d') $$,
'P0001', 'size_mismatch', 'confirm refuses a size that does not match the row (F7)'
);
reset role;
update storage.objects set metadata = '{"size":100}' where bucket_id='anatomical-sheet-assets' and name = repeat('d',64)||'.svg';
set local role authenticated;
select pg_temp.act('30000000-0000-0000-0000-00000000000e', '31000000-0000-0000-0000-00000000000e', 'aal2');
select lives_ok(
$$ select public.confirm_sheet_asset_upload('32000000-0000-0000-0000-00000000000d') $$,
'confirm succeeds when the object exists and the size matches'
);
select is((select uploaded_at is not null from public.anatomical_sheet_assets where id='32000000-0000-0000-0000-00000000000d'),
true, 'the row is now confirmed');
-- The operator read RPC: service role only.
select throws_ok(
$$ select public.get_sheet_asset_state('32000000-0000-0000-0000-00000000000a') $$,
'42501', null, 'an editor cannot call the operator read RPC (EXECUTE is service_role only)'
);
set local role service_role;
select lives_ok($$ select public.confirm_sheet_asset_upload(pg_temp.id('a')) $$, 'service role confirms asset A');
select lives_ok($$ select public.confirm_sheet_asset_upload(pg_temp.id('b')) $$, 'service role confirms asset B');
select is(public.confirm_sheet_asset_upload(pg_temp.id('a')), pg_temp.id('a'), 'confirming twice is idempotent');
reset role;
-- 3. Editor reads every object of her sheet (published, draft, unreferenced), not foreign ones
set local role authenticated;
select set_config('request.jwt.claims', '{"sub":"30000000-0000-0000-0000-00000000000a","role":"authenticated"}', true);
select results_eq(
$$ select name from storage.objects where bucket_id = 'anatomical-sheet-assets' order by name $$,
$$ values (repeat('a', 64) || '.svg'), (repeat('b', 64) || '.svg') $$,
'editor reads the confirmed objects of her sheet; unconfirmed and foreign objects stay hidden'
);
-- 4. Bob: private sheet → nothing; claiming the hash on his own sheet opens nothing
select set_config('request.jwt.claims', '{"sub":"30000000-0000-0000-0000-00000000000b","role":"authenticated"}', true);
select is((select count(*) from storage.objects where bucket_id = 'anatomical-sheet-assets'), 0::bigint, 'other user reads nothing from a private sheet');
insert into pg_temp.ids select 'bob-sheet', public.create_anatomical_sheet('equine', 'Claim', 'claim-test', pg_temp.doc(null));
select lives_ok(
$$ select public.register_sheet_asset(pg_temp.id('bob-sheet'), repeat('a', 64), 100, 'A.svg') $$,
'bob registers the known hash on his own sheet'
);
select is((select count(*) from storage.objects where bucket_id = 'anatomical-sheet-assets'), 0::bigint, 'a self-registered hash without a confirmed upload opens no object');
select set_config('request.jwt.claims', '{"sub":"30000000-0000-0000-0000-00000000000a","role":"authenticated"}', true);
select lives_ok($$ select public.set_sheet_visibility(pg_temp.id('sheet'), 'public') $$, 'alice makes the sheet public');
select set_config('request.jwt.claims', '{"sub":"30000000-0000-0000-0000-00000000000b","role":"authenticated"}', true);
select results_eq(
$$ select name from storage.objects where bucket_id = 'anatomical-sheet-assets' order by name $$,
$$ values (repeat('a', 64) || '.svg') $$,
'other user reads only the object a published version references (not the draft asset, not the unreferenced one)'
);
select throws_ok(
$$ insert into storage.objects (bucket_id, name) values ('anatomical-sheet-assets', 'x.svg') $$,
'42501', null, 'authenticated cannot upload into the bucket'
);
-- The real image also carries storage.protect_delete (statement trigger), so a
-- direct DELETE is asserted through the policy census, not by running it.
select set_config('request.jwt.claims', '{"role":"service_role"}', true);
select is(
(select count(*) from pg_policies where schemaname = 'storage' and tablename = 'objects'
and cmd in ('INSERT', 'UPDATE', 'DELETE')
and (coalesce(qual, '') like '%anatomical-sheet-assets%' or coalesce(with_check, '') like '%anatomical-sheet-assets%')),
0::bigint, 'no API role has an insert/update/delete policy on the bucket objects'
(select public.get_sheet_asset_state('32000000-0000-0000-0000-00000000000a') ->> 'sha256'),
repeat('a',64), 'the operator read RPC returns the asset state for the service role'
);
-- Name variants never match the strict key
select set_config('request.jwt.claims', '{"sub":"30000000-0000-0000-0000-00000000000a","role":"authenticated"}', true);
select ok(
not private.can_read_sheet_asset_object('30000000-0000-0000-0000-00000000000a', repeat('a', 64))
and not private.can_read_sheet_asset_object('30000000-0000-0000-0000-00000000000a', upper(repeat('a', 64)) || '.svg')
and not private.can_read_sheet_asset_object('30000000-0000-0000-0000-00000000000a', 'x/' || repeat('a', 64) || '.svg')
and not private.can_read_sheet_asset_object('30000000-0000-0000-0000-00000000000a', repeat('a', 64) || '.svg/'),
'object name must be exactly <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();
rollback;
+67 -87
View File
@@ -1,62 +1,38 @@
-- Official equine sheet seed (supabase/seed/anatomical-sheets/equine/draft):
-- present as a platform-owned DRAFT, never published by the seed, publishable
-- by platform admins only, content accepted by the SQL referential gate.
-- Official equine seed after V1-2.1: the historical sheet is present as a
-- platform-owned DRAFT, protected on the server (never saved, submitted,
-- published, archived or deleted), visible to capability holders at aal2 and
-- to no one else (no published version → not in the catalogue). Contract §14.2.
begin;
select plan(20);
insert into auth.users (id, email) values
('40000000-0000-0000-0000-000000000001', 'root-seed@test.local'),
('40000000-0000-0000-0000-00000000000a', 'alice-seed@test.local');
select private.assign_platform_role(null, '40000000-0000-0000-0000-000000000001', 'owner');
select plan(17);
create table pg_temp.ids (key text primary key, id uuid not null);
create function pg_temp.id(p_key text) returns uuid language sql stable
as $$ select id from pg_temp.ids where key = p_key $$;
create function pg_temp.id(p_key text) returns uuid language sql stable as $$ select id from pg_temp.ids where key = p_key $$;
grant all on pg_temp.ids to anon, authenticated, service_role;
grant execute on function pg_temp.id(text) to anon, authenticated, service_role;
insert into pg_temp.ids select 'sheet', id from public.anatomical_sheets where slug = 'faunosteo-cheval' and is_official;
insert into pg_temp.ids select 'draft', id from public.anatomical_sheet_versions where sheet_id = pg_temp.id('sheet');
-- 1. Seeded state
select is(pg_temp.id('sheet'), '503dc301-a8b1-50d4-9e44-0919b2fc2916'::uuid, 'the historical sheet keeps its fixed id');
select results_eq(
$$ select species_id, creator_user_id, is_official, visibility::text, status::text, current_version_id
from public.anatomical_sheets where id = pg_temp.id('sheet') $$,
$$ values ('equine', null::uuid, true, 'private', 'active', null::uuid) $$,
'official equine sheet: platform-owned, private, active, no published version'
'historical sheet: platform-owned, private, active, no published version'
);
select results_eq(
$$ select version_number, status::text, document_schema_version, published_at
from public.anatomical_sheet_versions where sheet_id = pg_temp.id('sheet') $$,
$$ values (1, 'draft', 2, null::timestamptz) $$,
'exactly one version, draft v1, never published'
);
select is((select count(*) from public.anatomical_sheet_assets where sheet_id = pg_temp.id('sheet')), 1::bigint, 'one SVG asset registered (the cleaned drawing)');
select is(
(select content ->> 'species_id' from public.anatomical_sheet_versions where id = pg_temp.id('draft')),
'equine', 'document species is equine'
);
select is(
(select jsonb_array_length(content -> 'views') from public.anatomical_sheet_versions where id = pg_temp.id('draft')),
2, 'document has two views'
$$ select version_number, status::text, document_schema_version, revision, coalesce(array_length(authors,1),0), published_at
from public.anatomical_sheet_versions where id = pg_temp.id('draft') $$,
$$ values (1, 'draft', 2, 0, 0, null::timestamptz) $$,
'one version: draft v1, schema 2, revision 0, empty author set, never published'
);
select is((select count(*) from public.anatomical_sheet_assets where sheet_id = pg_temp.id('sheet')), 1::bigint, 'one SVG asset registered');
select is((select content ->> 'species_id' from public.anatomical_sheet_versions where id = pg_temp.id('draft')), 'equine', 'document species is equine');
select is((select jsonb_array_length(content -> 'annotations') from public.anatomical_sheet_versions where id = pg_temp.id('draft')), 28, '28 annotations');
select is((select jsonb_array_length(content -> 'finding_zones') from public.anatomical_sheet_versions where id = pg_temp.id('draft')), 27, '27 finding zones');
select ok(
(select content -> 'views' -> 1 -> 'svg_asset_id' = 'null'::jsonb
and jsonb_typeof(content -> 'views' -> 1 -> 'view_box') = 'object'
from public.anatomical_sheet_versions where id = pg_temp.id('draft')),
'head view is a crop of the main drawing: no asset, a view_box'
);
select is(
(select jsonb_array_length(content -> 'annotations') from public.anatomical_sheet_versions where id = pg_temp.id('draft')),
28, 'document has 28 annotations (27 legacy + carpus)'
);
select is(
(select jsonb_array_length(content -> 'finding_zones') from public.anatomical_sheet_versions where id = pg_temp.id('draft')),
27, 'document has 27 finding zones (26 legacy + carpus)'
);
select is(
(select private.sheet_document_issues(content) from public.anatomical_sheet_versions where id = pg_temp.id('draft')),
'{}'::text[], 'SQL referential gate finds no issue'
(select private.sheet_document_has_shape(content) from public.anatomical_sheet_versions where id = pg_temp.id('draft')),
'the seeded document has the structural shape SQL still checks'
);
select is(
(select private.sheet_document_unknown_assets(sheet_id, content) from public.anatomical_sheet_versions where id = pg_temp.id('draft')),
@@ -67,54 +43,58 @@ select is(
1::bigint, 'the seed import is audited as a system action'
);
-- 2. Nobody publishes it by accident: plain users cannot even see the draft
set local role authenticated;
select set_config('request.jwt.claims', '{"sub":"40000000-0000-0000-0000-00000000000a","role":"authenticated"}', true);
select is((select count(*) from public.anatomical_sheets where id = pg_temp.id('sheet')), 0::bigint, 'a private official draft is invisible to plain users');
select throws_ok(
$$ select public.publish_sheet_version(pg_temp.id('draft')) $$,
'42501', null, 'a plain user cannot publish the official draft'
);
-- A platform admin can (the explicit decision step), and the gate would accept the document
select set_config('request.jwt.claims', '{"sub":"40000000-0000-0000-0000-000000000001","role":"authenticated"}', true);
select is((select count(*) from public.anatomical_sheet_versions where id = pg_temp.id('draft')), 1::bigint, 'a platform admin sees the official draft');
select lives_ok($$ select public.publish_sheet_version(pg_temp.id('draft')) $$, 'a platform admin could publish it (rolled back here)');
-- 2. An editor with the capability (aal2) is set up, then the protections.
insert into auth.users (id, email, email_confirmed_at) values
('40000000-0000-0000-0000-000000000001', 'own-eq@test.local', now()),
('40000000-0000-0000-0000-00000000000e', 'ed-eq@test.local', now()),
('40000000-0000-0000-0000-0000000000a0', 'pl-eq@test.local', now());
insert into auth.mfa_factors (id, user_id, factor_type, status, created_at, updated_at)
values (gen_random_uuid(), '40000000-0000-0000-0000-00000000000e', 'totp', 'verified', now(), now());
insert into auth.sessions (id, user_id, aal) values ('41000000-0000-0000-0000-00000000000e', '40000000-0000-0000-0000-00000000000e', 'aal2');
select set_config('request.jwt.claims', '', true);
select private.assign_platform_role(null, '40000000-0000-0000-0000-000000000001', 'owner');
select private.assign_platform_role(null, '40000000-0000-0000-0000-00000000000e', 'admin');
insert into public.anatomical_catalog_grants (user_id, grant_kind, reason, verification_note, granted_by) values
('40000000-0000-0000-0000-00000000000e', 'sheet_editor', 'equine work', 'checked', '40000000-0000-0000-0000-000000000001'),
('40000000-0000-0000-0000-00000000000e', 'sheet_publisher', 'equine work', 'checked', '40000000-0000-0000-0000-000000000001');
create function pg_temp.act(p_uid uuid, p_sid uuid, p_aal text) returns void language sql as $$
select set_config('request.jwt.claims', jsonb_build_object('sub',p_uid,'role','authenticated','aal',p_aal,'session_id',p_sid)::text, true);
$$;
grant execute on function pg_temp.act(uuid,uuid,text) to authenticated;
-- 3. Storage: the seed registers metadata only; after the operator upload + confirmation,
-- a platform admin reads the object and a plain user none. A base where the operator
-- already uploaded and confirmed the drawing (DEV) is brought back to the seed's state
-- inside this transaction: the confirmation is cleared, and the object already in the
-- bucket stands for the upload (content-addressed key, never written twice). Reads are
-- counted on the seed's own key: other objects of the bucket do not count.
reset role;
create table pg_temp.seed_objects as
select a.sha256 || '.svg' as name from public.anatomical_sheet_assets a where a.sheet_id = pg_temp.id('sheet');
grant select on pg_temp.seed_objects to authenticated, service_role;
update public.anatomical_sheet_assets set uploaded_at = null where sheet_id = pg_temp.id('sheet');
insert into storage.objects (bucket_id, name)
select 'anatomical-sheet-assets', k.name from pg_temp.seed_objects k
where not exists (select 1 from storage.objects o where o.bucket_id = 'anatomical-sheet-assets' and o.name = k.name);
select is(
(select count(*) from storage.objects o join pg_temp.seed_objects k on k.name = o.name where o.bucket_id = 'anatomical-sheet-assets'),
1::bigint, 'the drawing is in the bucket once, under its content address'
);
set local role authenticated;
select set_config('request.jwt.claims', '{"sub":"40000000-0000-0000-0000-000000000001","role":"authenticated"}', true);
select is((select count(*) from storage.objects where bucket_id = 'anatomical-sheet-assets' and name in (select name from pg_temp.seed_objects)),
0::bigint, 'seed objects are not readable before confirmation');
set local role service_role;
select is(
(select count(*) from public.anatomical_sheet_assets a where a.sheet_id = pg_temp.id('sheet')
and public.confirm_sheet_asset_upload(a.id) = a.id),
1::bigint, 'operator confirms the upload'
select pg_temp.act('40000000-0000-0000-0000-00000000000e', '41000000-0000-0000-0000-00000000000e', 'aal2');
-- The capability holder sees the draft (caller_can_see_official_sheet).
select is((select count(*) from public.anatomical_sheet_versions where id = pg_temp.id('draft')), 1::bigint,
'a capability holder at aal2 sees the historical draft');
-- Every write path refuses the historical sheet.
select throws_ok(
$$ select public.save_sheet_draft(pg_temp.id('draft'), 0, '{"schema_version":2,"species_id":"equine"}'::jsonb, 'x') $$,
'42501', 'sheet.historical_read_only', 'save refused on the historical sheet'
);
set local role authenticated;
select set_config('request.jwt.claims', '{"sub":"40000000-0000-0000-0000-000000000001","role":"authenticated"}', true);
select is((select count(*) from storage.objects where bucket_id = 'anatomical-sheet-assets' and name in (select name from pg_temp.seed_objects)),
1::bigint, 'a platform admin reads the official SVG');
select set_config('request.jwt.claims', '{"sub":"40000000-0000-0000-0000-00000000000a","role":"authenticated"}', true);
select is((select count(*) from storage.objects where bucket_id = 'anatomical-sheet-assets' and name in (select name from pg_temp.seed_objects)),
0::bigint, 'a plain user reads no official draft SVG');
select throws_ok(
$$ select public.submit_sheet_review(pg_temp.id('draft'), 0, 'x') $$,
'42501', 'sheet.historical_read_only', 'submit refused on the historical sheet'
);
select throws_ok(
$$ select public.register_sheet_asset(pg_temp.id('sheet'), repeat('e',64), 100, 'x.svg') $$,
'42501', 'sheet.historical_read_only', 'register refused on the historical sheet'
);
select throws_ok(
$$ select public.archive_anatomical_sheet(pg_temp.id('sheet')) $$,
'42501', 'sheet.historical_read_only', 'archive refused on the historical sheet'
);
select throws_ok(
$$ delete from public.anatomical_sheet_versions where id = pg_temp.id('draft') $$,
'42501', null, 'the historical draft cannot be deleted (trigger)'
);
-- 3. A plain confirmed account sees nothing (no published version, no capability).
select pg_temp.act('40000000-0000-0000-0000-0000000000a0', gen_random_uuid(), 'aal1');
select is((select count(*) from public.anatomical_sheets where id = pg_temp.id('sheet')), 0::bigint,
'a plain account does not see the historical sheet (no published version)');
select * from finish();
rollback;
@@ -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 count(*) from pg_policies where schemaname = 'storage' and tablename = 'objects'
and (coalesce(qual, '') || coalesce(with_check, '')) like '%bucket_id = ''anatomical-sheet-assets''%'),
1::bigint, 'census: one policy names anatomical-sheet-assets'
2::bigint, 'census: two policies name anatomical-sheet-assets (read + editor upload, V1-2.1)'
);
select is(
(select count(*) from pg_policies where schemaname = 'storage' and tablename = 'objects'),
3::bigint, 'census: three policies in total, so the six closed buckets have none'
4::bigint, 'census: four policies in total (avatars read+insert, sheet-assets read+insert)'
);
select is(
(select count(*) from pg_policies where schemaname = 'storage' and tablename = 'objects'
-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;