diff --git a/supabase/migrations/20261101100000_sheet_verification_jobs.sql b/supabase/migrations/20261101100000_sheet_verification_jobs.sql index 970cc2f5..76579b2d 100644 --- a/supabase/migrations/20261101100000_sheet_verification_jobs.sql +++ b/supabase/migrations/20261101100000_sheet_verification_jobs.sql @@ -248,7 +248,8 @@ declare begin perform private.require_service_role(); select r.* into v_review from public.anatomical_sheet_reviews r where r.id = review_id; - if v_review.id is null or v_review.status <> 'verifying' or v_review.lease_token is distinct from lease_token then + if v_review.id is null or v_review.status <> 'verifying' + or lease_token is null or v_review.lease_token is distinct from lease_token then return null; end if; select v.* into v_version from public.anatomical_sheet_versions v where v.id = v_review.version_id; @@ -298,7 +299,8 @@ declare begin perform private.require_service_role(); select r.* into v_review from public.anatomical_sheet_reviews r where r.id = review_id for update; - if v_review.id is null or v_review.status <> 'verifying' or v_review.lease_token is distinct from lease_token then + if v_review.id is null or v_review.status <> 'verifying' + or lease_token is null or v_review.lease_token is distinct from lease_token then return 'stale'; end if; select v.* into v_version from public.anatomical_sheet_versions v where v.id = v_review.version_id; @@ -386,7 +388,8 @@ begin raise exception 'invalid_input' using errcode = 'P0001'; end if; select r.* into v_review from public.anatomical_sheet_reviews r where r.id = review_id for update; - if v_review.id is null or v_review.status <> 'verifying' or v_review.lease_token is distinct from lease_token then + if v_review.id is null or v_review.status <> 'verifying' + or lease_token is null or v_review.lease_token is distinct from lease_token then return 'stale'; end if; v_final := v_review.attempts >= private.sheet_verification_attempt_limit(); diff --git a/supabase/tests/021_sheet_verification_jobs.sql b/supabase/tests/021_sheet_verification_jobs.sql index 5049b584..25f35d64 100644 --- a/supabase/tests/021_sheet_verification_jobs.sql +++ b/supabase/tests/021_sheet_verification_jobs.sql @@ -4,7 +4,7 @@ -- nothing), technical failures up to the attempt limit with their progressive -- delay (`not_before`), dead leases. begin; -select plan(68); +select plan(72); insert into auth.users (id, email, email_confirmed_at) values ('f0000000-0000-0000-0000-000000000001', 'own@vj.local', now()), @@ -219,6 +219,11 @@ select ok(exists (select 1 from audit.audit_logs where action = 'anatomical_shee set local role service_role; select pg_temp.worker(); select is(public.fail_sheet_verification(pg_temp.id('r3'), gen_random_uuid(), 'verification.worker.timeout'), 'stale', 'a stale failure again'); select ok(pg_temp.delayed('r3', interval '2 seconds'), 'a stale failure leaves the delay unchanged'); +-- A round holding no lease is not an open door: a null token is stale everywhere. +select is(public.get_sheet_verification_input(pg_temp.id('r3'), null), null, 'a null token reads no input'); +select is(public.fail_sheet_verification(pg_temp.id('r3'), null, 'verification.worker.timeout'), 'stale', 'a null token fails nothing'); +select is(public.complete_sheet_verification(pg_temp.id('r3'), null, pg_temp.verdict(pg_temp.id('r3'),'failed')), 'stale', 'a null token completes nothing'); +select ok(pg_temp.delayed('r3', interval '2 seconds'), 'a null token leaves the delay unchanged'); select is((select count(*)::int from public.claim_sheet_verifications(1)), 0, 'no claim before the delay is over'); -- The delay over exactly now: claimable. select pg_temp.set_not_before('r3', interval '0');