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

+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);