fix(supabase): targeted review LOWs on retry and sandbox isolation

fail_sheet_verification refuses lease_expired (the claim's record, never a
worker report); the sandbox state dir guard resolves the repository path; the
avatar suite also refuses keys not issued by the sandbox. pgTAP 021: 90.
This commit is contained in:
bchanot committed 2026-11-01 23:13:42 +01:00
1 parent 2762ad2aba
commit 3c141c942b
4 files changed
+18 -4

No files matched your search

@@ -33,7 +33,15 @@ const DB_CONTAINER = process.env.AVATAR_E2E_DB_CONTAINER
/** The only target accepted: the gateway and database of `pnpm db:sandbox avatar-e2e`. */
const SANDBOX_URL = 'http://127.0.0.1:57800'
const SANDBOX_DB = 'faunosteo_dbsandbox_db'
if (URL_ !== SANDBOX_URL || DB_CONTAINER !== SANDBOX_DB || !ANON || !SERVICE)
/** The sandbox signs its keys with issuer `db-sandbox` (scripts/db-sandbox.sh); no other stack's key does. */
const sandboxKey = (key: string | undefined): boolean => {
try {
return JSON.parse(Buffer.from(key?.split('.')[1] ?? '', 'base64url').toString()).iss === 'db-sandbox'
} catch {
return false
}
}
if (URL_ !== SANDBOX_URL || DB_CONTAINER !== SANDBOX_DB || !sandboxKey(ANON) || !sandboxKey(SERVICE))
throw new Error('avatar e2e: run it through pnpm e2e:avatar, on the sandbox stack only')
/** Per run, kept in memory only: both accounts are deleted after the suite. */
const PASSWORD = randomBytes(18).toString('base64url')
+3 -1
View File
@@ -53,8 +53,10 @@ SECRETS="$STATE/secrets.sh"
CLI=node_modules/.bin/supabase
die() { echo "db-sandbox: $*" >&2; exit 1; }
# Both sides resolved: a repository reached through a symlink is still the repository.
REPO="$(realpath "$PWD")"
case "$(realpath -m "$STATE")" in
"$PWD" | "$PWD"/*) die "FAUNOSTEO_SANDBOX_DIR must be outside the repository" ;;
"$REPO" | "$REPO"/*) die "FAUNOSTEO_SANDBOX_DIR must be outside the repository" ;;
esac
# Every value must be present: an empty password would turn --db-url into an
# argument the CLI might read as absent and fall back to the DEV database.
@@ -398,7 +398,9 @@ declare
v_definitive boolean;
begin
perform private.require_service_role();
if code is null or not (code = any (private.sheet_worker_codes())) then
-- `lease_expired` is the claim's own record of a dead lease, never a worker report.
if code is null or not (code = any (private.sheet_worker_codes()))
or code = 'verification.worker.lease_expired' then
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;
@@ -4,7 +4,7 @@
-- nothing), technical failures up to the attempt limit with their progressive
-- delay (`not_before`), dead leases.
begin;
select plan(89);
select plan(90);
insert into auth.users (id, email, email_confirmed_at) values
('f0000000-0000-0000-0000-000000000001', 'own@vj.local', now()),
@@ -209,6 +209,8 @@ set local role service_role; select pg_temp.worker();
select is((select count(*)::int from public.claim_sheet_verifications(1)), 1, 'third round claimed');
select throws_ok(format('select public.fail_sheet_verification(%L, %L, %L)', pg_temp.id('r3'), pg_temp.token('r3'), 'verification.worker.oops'),
'P0001', 'invalid_input', 'an unknown worker code is refused');
select throws_ok(format('select public.fail_sheet_verification(%L, %L, %L)', pg_temp.id('r3'), pg_temp.token('r3'), 'verification.worker.lease_expired'),
'P0001', 'invalid_input', 'lease_expired is the claim''s record, never a worker report');
select is(public.fail_sheet_verification(pg_temp.id('r3'), gen_random_uuid(), 'verification.worker.timeout'), 'stale', 'a failure with another token is stale');
select is(public.fail_sheet_verification(pg_temp.id('r3'), pg_temp.token('r3'), 'verification.worker.timeout'), 'retry', 'a timeout below the limit is retried');
select is(pg_temp.status('r3') || '/' || (pg_temp.token('r3') is null)::text, 'verifying/-/verification.worker.timeout/true', 'round stays verifying, code recorded, lease released');