feat(domain): equine legacy importer (packages/anatomy) + generated official equine sheet seed as draft

This commit is contained in:
bchanot committed 2026-10-09 00:38:48 +02:00
1 parent f4682cdba5
commit 52bfc11553
43 files changed
+18466 -33

No files matched your search

+1 -1
View File
@@ -586,7 +586,7 @@ select throws_ok(
);
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', 'Faunosteo / Cheval', 'faunosteo-cheval', pg_temp.sheet_doc(null), 'Fiche officielle', 'public', true
'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') $$,
+8 -4
View File
@@ -91,10 +91,14 @@ select throws_ok(
$$ insert into storage.objects (bucket_id, name) values ('anatomical-sheet-assets', 'x.svg') $$,
'42501', null, 'authenticated cannot upload into the bucket'
);
delete from storage.objects where bucket_id = 'anatomical-sheet-assets';
reset role;
select is((select count(*) from storage.objects where bucket_id = 'anatomical-sheet-assets'), 4::bigint, 'authenticated DELETE touches no bucket object');
set local role authenticated;
-- The real image also carries storage.protect_delete (statement trigger), so a
-- direct DELETE is asserted through the policy census, not by running it.
select is(
(select 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'
);
-- 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);
+78
View File
@@ -0,0 +1,78 @@
-- Official equine sheet seed (supabase/seed/anatomical-sheets/equine/v1):
-- present as a platform-owned DRAFT, never published by the seed, publishable
-- by platform admins only, content accepted by the SQL referential gate.
begin;
select plan(14);
insert into auth.users (id, email) values
('40000000-0000-0000-0000-000000000001', 'root-seed@test.local'),
('40000000-0000-0000-0000-00000000000a', 'alice-seed@test.local');
select private.assign_platform_role(null, '40000000-0000-0000-0000-000000000001', 'owner');
create table pg_temp.ids (key text primary key, id uuid not null);
create 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;
grant execute on function pg_temp.id(text) to anon, authenticated;
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 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'
);
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', 1, 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')), 2::bigint, 'two SVG assets 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 -> 'views') from public.anatomical_sheet_versions where id = pg_temp.id('draft')),
2, 'document has two views'
);
select is(
(select jsonb_array_length(content -> 'annotations') from public.anatomical_sheet_versions where id = pg_temp.id('draft')),
27, 'document has 27 annotations'
);
select is(
(select jsonb_array_length(content -> 'finding_zones') from public.anatomical_sheet_versions where id = pg_temp.id('draft')),
26, 'document has 26 finding zones'
);
select is(
(select private.sheet_document_issues(content) from public.anatomical_sheet_versions where id = pg_temp.id('draft')),
'{}'::text[], 'SQL referential gate finds no issue'
);
select is(
(select private.sheet_document_unknown_assets(sheet_id, content) from public.anatomical_sheet_versions where id = pg_temp.id('draft')),
'{}'::text[], 'every view asset is registered for the sheet'
);
select is(
(select count(*) from audit.audit_logs where resource_id = pg_temp.id('draft') and action = 'anatomical_sheet_version.created' and actor_user_id is null),
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)');
select * from finish();
rollback;