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.
This commit is contained in:
bchanot committed 2026-11-17 01:04:27 +01:00
1 parent 1e5058577f
commit 3bea19f16b
4 files changed
+30 -16

No files matched your search

@@ -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)) {
+3 -1
View File
@@ -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<string> {
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. */
+12 -10
View File
@@ -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<string> {
export async function archiveOwnSheet(
sheetId: string,
seededName: string,
): Promise<string> {
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}'`)
+8
View File
@@ -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