From 3bea19f16b4ec9cafdb2b78ca7a373ad1a975fab Mon Sep 17 00:00:00 2001 From: bchanot Date: Tue, 17 Nov 2026 01:04:27 +0100 Subject: [PATCH] test(app): e2e cleanup checks the seeded name before archiving D4 identity check: the integrity spec reads each own sheet's name by its captured id and archives it only when it is exactly the seeded name. seedGrant checks the account id as a captured id, now shared from records.ts. --- .../app/e2e/shell/catalogue-integrity.spec.ts | 12 +++++----- apps/app/e2e/support/admin.ts | 4 +++- apps/app/e2e/support/catalogue.ts | 22 ++++++++++--------- apps/app/e2e/support/records.ts | 8 +++++++ 4 files changed, 30 insertions(+), 16 deletions(-) diff --git a/apps/app/e2e/shell/catalogue-integrity.spec.ts b/apps/app/e2e/shell/catalogue-integrity.spec.ts index ef9a6a3f..eca0acda 100644 --- a/apps/app/e2e/shell/catalogue-integrity.spec.ts +++ b/apps/app/e2e/shell/catalogue-integrity.spec.ts @@ -60,7 +60,7 @@ interface RunFixtures { } let run: RunFixtures | null = null -const ownSheets: string[] = [] +const ownSheets: { id: string; name: string }[] = [] const ownGrants: { id: string; account: string }[] = [] const fixtures = (): RunFixtures => { @@ -74,13 +74,13 @@ test.beforeAll(async () => { test.setTimeout(120_000) const tag = randomUUID().slice(0, 8) const sound = await seedOfficialSheet(sameName(`R4 ${tag} saine`), 'listed') - ownSheets.push(sound.id) + ownSheets.push({ id: sound.id, name: sound.names.fr }) const altered = await seedOfficialSheet( sameName(`R4 ${tag} altérée`), 'listed', { storedFingerprint: '0'.repeat(64) }, ) - ownSheets.push(altered.id) + ownSheets.push({ id: altered.id, name: altered.names.fr }) const reader = await createAccount('fr', false) const grantId = await seedGrant(reader, 'catalog_reader') ownGrants.push({ id: grantId, account: reader.id }) @@ -101,8 +101,10 @@ test.beforeAll(async () => { test.afterAll(async () => { const failures: string[] = [] - for (const id of ownSheets.splice(0)) { - const status = await archiveOwnSheet(id).catch((e: Error) => e.message) + for (const { id, name } of ownSheets.splice(0)) { + const status = await archiveOwnSheet(id, name).catch( + (e: Error) => e.message, + ) if (status !== 'archived') failures.push(`sheet ${id}: ${status}`) } for (const grant of ownGrants.splice(0)) { diff --git a/apps/app/e2e/support/admin.ts b/apps/app/e2e/support/admin.ts index 2f6128eb..223f13e3 100644 --- a/apps/app/e2e/support/admin.ts +++ b/apps/app/e2e/support/admin.ts @@ -16,6 +16,7 @@ import { import { sql, stack } from '../../../../packages/supabase/tests/sandbox/stack' import { currentCode } from '../../../../packages/supabase/tests/sandbox/totp' import { expect, test } from './browser' +import { capturedId } from './records' import type { SandboxAccount } from './sandbox' export type GrantKind = @@ -40,8 +41,9 @@ export async function seedGrant( kind: GrantKind, ): Promise { const note = kind === 'catalog_reader' ? 'null' : "'sandbox'" + const id = capturedId(account.id) return sql(`insert into public.anatomical_catalog_grants (user_id, grant_kind, reason, verification_note, granted_by) - values ('${account.id}', '${kind}', 'sandbox', ${note}, '${account.id}') returning id`) + values ('${id}', '${kind}', 'sandbox', ${note}, '${id}') returning id`) } /** A password session of the account on GoTrue: always aal1. */ diff --git a/apps/app/e2e/support/catalogue.ts b/apps/app/e2e/support/catalogue.ts index a3de4128..7d09f623 100644 --- a/apps/app/e2e/support/catalogue.ts +++ b/apps/app/e2e/support/catalogue.ts @@ -18,7 +18,7 @@ import { type GlueModule, } from '@faunosteo/core-wasm' import { sql, stack } from '../../../../packages/supabase/tests/sandbox/stack' -import { literal } from './records' +import { capturedId, literal } from './records' const REPO = join(__dirname, '../../../..') const SEED = join(REPO, 'supabase/seed/anatomical-sheets/equine/draft') @@ -190,21 +190,23 @@ export async function seedOfficialSheet( return { id, names, currentVersionId } } -const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/ - -/** An id a run captured, checked before it is written into a statement. */ -function capturedId(id: string): string { - if (!UUID.test(id)) throw new Error(`cleanup: not a captured id (${id})`) - return id -} - /** * Cleanup of a run (D4): one sheet the run seeded archived through the * migrations' own path as the seed owner (audit row included), then its status * read back; resolves with that status. Names that one id, nothing by pattern. + * The row's name is read first and must be exactly the one the run seeded + * (owner D4, identity check): any other name archives nothing and fails. */ -export async function archiveOwnSheet(sheetId: string): Promise { +export async function archiveOwnSheet( + sheetId: string, + seededName: string, +): Promise { const id = capturedId(sheetId) + const name = await sql( + `select name from public.anatomical_sheets where id = '${id}'`, + ) + if (name !== seededName) + throw new Error(`cleanup: sheet ${id} is not the run's (name ${name})`) await sql(`select private.set_sheet_status('${SEED_OWNER}', '${id}', 'active', 'archived', 'anatomical_sheet.archived')`) return sql(`select status from public.anatomical_sheets where id = '${id}'`) diff --git a/apps/app/e2e/support/records.ts b/apps/app/e2e/support/records.ts index 4770b0e1..f711aab5 100644 --- a/apps/app/e2e/support/records.ts +++ b/apps/app/e2e/support/records.ts @@ -11,6 +11,14 @@ import { workspaceOf, type SandboxAccount } from './sandbox' export const literal = (value: string | null) => value === null ? 'null' : `'${value.replaceAll("'", "''")}'` +const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/ + +/** An id a run captured, checked before it is written into a statement. */ +export function capturedId(id: string): string { + if (!UUID.test(id)) throw new Error(`not a captured id (${id})`) + return id +} + export interface ClientSeed { kind?: 'person' | 'organization' city?: string | null