fix(supabase): confirmed uploads gate asset reads (hash claim), seeds-listed test, Dockerfile workspace manifests; importer declares every authored label, real in=out control

This commit is contained in:
bchanot committed 2026-10-09 00:50:36 +02:00
1 parent bbfb8d6203
commit dee4ce43d9
28 files changed
+511 -87

No files matched your search

+23 -3
View File
@@ -2,7 +2,7 @@
-- 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);
select plan(18);
insert into auth.users (id, email) values
('40000000-0000-0000-0000-000000000001', 'root-seed@test.local'),
@@ -12,8 +12,8 @@ select private.assign_platform_role(null, '40000000-0000-0000-0000-000000000001'
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;
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');
@@ -74,5 +74,25 @@ select set_config('request.jwt.claims', '{"sub":"40000000-0000-0000-0000-0000000
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)');
-- 3. Storage: the seed registers metadata only; after the operator upload + confirmation,
-- a platform admin reads both objects and a plain user none.
reset role;
insert into storage.objects (bucket_id, name)
select 'anatomical-sheet-assets', a.sha256 || '.svg' from public.anatomical_sheet_assets a where a.sheet_id = pg_temp.id('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'), 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),
2::bigint, 'operator confirms the two uploads'
);
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'), 2::bigint, 'a platform admin reads both official SVGs');
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'), 0::bigint, 'a plain user reads no official draft SVG');
select * from finish();
rollback;