test(supabase): pgTAP 007 and 010 independent of the base's data

This commit is contained in:
bchanot committed 2026-10-27 14:44:03 +01:00
1 parent 6c36e2f22d
commit 7244648b4c
3 files changed
+80 -13

No files matched your search

+20 -2
View File
@@ -481,7 +481,7 @@ devsql postgres < "$B/counts.sql" > "$B/counts-after.txt"; diff "$B/counts-befor
# tables private 1 → 2, public 7 → 12; functions private 41 → 54, public 26 → 40; policies 15 → 20;
# rls tables public 7 → 12. Every count and md5 of the existing rows is unchanged.
pnpm db:types:check # no diff
pnpm db:test; echo "db:test exit $?" # pgTAP 001-014, exit 0 (see its effects below)
pnpm db:test; echo "db:test exit $?" # pgTAP 001-014, 921 assertions, exit 0 (see its effects and the 2026-10-27 run below)
echo "select 'pgtap ' || count(*) from pg_extension where extname = 'pgtap';" | devsql postgres
# 0, as before the run; 1 = left installed (interrupted run): report it, do not drop it by hand
devsql postgres < "$B/counts.sql" | diff "$B/counts-after.txt" - # no diff: the tests left no row
@@ -495,7 +495,25 @@ the scripts:
the `pgtap` extension before the run and drops it after when it was absent
(DEV: absent), a transient schema change; an interrupted run can leave
`pgtap` installed (`post.sql` shows it). Run it before the browser
acceptance, with no app session open.
acceptance, with no app session open and the worker stopped (010 leases
the queue rows it finds until its rollback). The files share the stack with the
data it already holds: 007 and 010 count only their own keys, and 010
first leases the base's own queued work (due purge entries, avatar jobs,
uploads begun more than 24 h ago) inside its transaction. Assumptions that
stay: the avatars bucket far below its 10 GiB ceiling; fewer than about 90
quarantine leftovers of the base (the sweep returns at most 100, oldest
first); the official equine sheet still at its seeded single draft (007
checks the seed as delivered).
- First run on DEV after M1 to M3 (2026-10-27, suites at `6c36e2f`): exit 1,
919 assertions planned, 915 run, 914 passed. 007 stopped at its storage
insert (the drawing was already uploaded and confirmed on DEV: duplicate
key, 4 assertions never run); 010 failed « nothing is due before its grace
elapsed » (13 due purge entries of DEV counted). 012 to 014 (V1-1) passed;
data, privileges and `pgtap` (absent) identical before and after. Both
files were fixed on the branch (007: 20 assertions, 010: 141) and validated
on the sandbox, clean and with those conditions reproduced (scenarios and
mutations in the journal of 2026-10-27). DEV is not validated by `db:test`
until a run there passes.
- `pnpm e2e:avatar`: not part of this procedure; optional, the owner's call.
It writes on DEV beyond its own fixture: it creates a temporary confirmed
account `e2e-avatar-<time>@faunosteo.local` (and, after M1, its workspace),
+22 -6
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(19);
select plan(20);
insert into auth.users (id, email) values
('40000000-0000-0000-0000-000000000001', 'root-seed@test.local'),
@@ -81,13 +81,27 @@ select is((select count(*) from public.anatomical_sheet_versions where id = pg_t
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 the object and a plain user none.
-- 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', a.sha256 || '.svg' from public.anatomical_sheet_assets a where a.sheet_id = pg_temp.id('sheet');
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'), 0::bigint, 'seed objects are not readable before confirmation');
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')
@@ -96,9 +110,11 @@ select is(
);
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'), 1::bigint, 'a platform admin reads the official SVG');
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'), 0::bigint, 'a plain user reads no official draft SVG');
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 * from finish();
rollback;
+38 -5
View File
@@ -2,7 +2,7 @@
-- browser and worker RPCs, the purge queue. Every allowed path has its denial
-- twin; the eight scenarios of the Step 8 brief are named in the descriptions.
begin;
select plan(140);
select plan(141);
insert into auth.users (id, email) values
('40000000-0000-0000-0000-00000000000a', 'alice-files@test.local'),
@@ -18,6 +18,32 @@ grant all on pg_temp.ids to anon, authenticated, service_role;
grant execute on function pg_temp.id(text) to anon, authenticated, service_role;
grant execute on function pg_temp.row(text) to anon, authenticated, service_role;
-- ---------------------------------------------------------------------------
-- 0. Work the base already holds
-- ---------------------------------------------------------------------------
-- A used stack (DEV) can hold due purge entries, uploaded avatars waiting for
-- the worker and uploads begun more than 24 h ago. The worker RPCs serve the
-- whole queue, oldest first: that work is leased (or expired) here, inside
-- this transaction and rolled back with it, so the queue assertions below
-- count this file's rows only. A clean base has nothing to lease.
set local role service_role;
select set_config('request.jwt.claims', '{"role":"service_role"}', true);
do $$
begin
for i in 1..1000 loop
exit when not exists (select 1 from public.claim_purges(100))
and not exists (select 1 from public.claim_avatar_jobs(10));
end loop;
perform public.expire_pending_uploads(86400);
end $$;
select ok(
not exists (select 1 from public.claim_purges(100))
and not exists (select 1 from public.claim_avatar_jobs(10))
and public.expire_pending_uploads(86400) = 0,
'setup: the base holds no claimable purge entry, avatar job or stale upload of its own'
);
reset role;
-- ---------------------------------------------------------------------------
-- 1. Buckets and the policy census
-- ---------------------------------------------------------------------------
@@ -414,12 +440,19 @@ select is(
-- ---------------------------------------------------------------------------
-- Objects still present under quarantine/: a1 (its row no longer references
-- it), a2, a3, a4, a5, a6, a7 (terminal rows). None pending or uploaded.
-- The sweep reads the whole bucket and holds no lease: leftovers of the base
-- (a used stack) are left out of the counts by this file's key prefix.
set local role service_role;
select set_config('request.jwt.claims', '{"role":"service_role"}', true);
select is((select count(*) from public.claim_quarantine_leftovers(0, 100)), 7::bigint, 'every quarantine object without a waiting row is a leftover');
select is((select count(*) from public.claim_quarantine_leftovers(0, 100) l where l.asset_id is null), 1::bigint,
'a leftover whose row forgot the key (purged earlier) has no asset_id');
select is((select count(*) from public.claim_quarantine_leftovers(3600, 100)), 0::bigint, 'nothing younger than the grace is a leftover');
select is((select count(*) from public.claim_quarantine_leftovers(0, 100) l
where l.object_name like 'quarantine/40000000-0000-0000-0000-00000000000_/%'),
7::bigint, 'every quarantine object without a waiting row is a leftover');
select is((select count(*) from public.claim_quarantine_leftovers(0, 100) l
where l.object_name like 'quarantine/40000000-0000-0000-0000-00000000000_/%' and l.asset_id is null),
1::bigint, 'a leftover whose row forgot the key (purged earlier) has no asset_id');
select is((select count(*) from public.claim_quarantine_leftovers(3600, 100) l
where l.object_name like 'quarantine/40000000-0000-0000-0000-00000000000_/%'),
0::bigint, 'nothing younger than the grace is a leftover');
reset role;
set local role authenticated;
select set_config('request.jwt.claims', '{"sub":"40000000-0000-0000-0000-00000000000a","role":"authenticated"}', true);