test(tests): working-copy dialog checks independent of the shared slot

admin.spec opened the working-copy dialog on the historical sheet, whose
single slot was taken by a copy the sandbox suite leaked. The dialog checks
move to an e2e:ui page on the real component; the suite archives its own copies.
This commit is contained in:
bchanot committed 2026-11-12 17:06:42 +01:00
1 parent da298cfab1
commit 2cdee42fe1
9 files changed
+304 -25

No files matched your search

@@ -84,6 +84,8 @@ const wrongCode = (secret: string) =>
const created: string[] = []
const species: string[] = []
// Working copies created by this run (the slot is one per database): never anyone else's.
const copies: string[] = []
async function account(tag: string, role: 'owner' | 'admin' | null = null): Promise<Account> {
const a = await confirmedAccount(tag)
@@ -92,9 +94,21 @@ async function account(tag: string, role: 'owner' | 'admin' | null = null): Prom
return a
}
afterAll(async () => {
if (species.length > 0)
await sql(`delete from public.species where id in (${species.map((id) => `'${id}'`).join(', ')})`)
/** Archives the working copies this run created, and only them. */
async function archiveOwnCopies() {
if (copies.length === 0) return
const ids = copies.map((id) => `'${id}'`).join(', ')
const archived = await sql(`update public.anatomical_sheets set status = 'archived', archived_at = now()
where id in (${ids}) returning id`)
expect(archived.split('\n').sort()).toEqual([...copies].sort())
}
async function dropOwnSpecies() {
if (species.length === 0) return
await sql(`delete from public.species where id in (${species.map((id) => `'${id}'`).join(', ')})`)
}
async function dropOwnAccounts() {
if (created.length === 0) return
const ids = created.map((id) => `'${id}'`).join(', ')
// Grants are never deleted by design (guard trigger): the run's own rows are
@@ -105,6 +119,19 @@ afterAll(async () => {
set local session_replication_role = origin;
delete from auth.users where id in (${ids});
commit;`)
}
// Each step runs even when an earlier one fails; the first error is rethrown.
afterAll(async () => {
const failures: unknown[] = []
for (const step of [archiveOwnCopies, dropOwnSpecies, dropOwnAccounts]) {
try {
await step()
} catch (error) {
failures.push(error)
}
}
if (failures.length > 0) throw failures[0]
})
describe('TOTP wrappers on real GoTrue', () => {
@@ -183,9 +210,14 @@ describe('administration reads, species and account lookup', () => {
order by version_number limit 1`)
// A fresh sandbox has no working copy yet, so the first call may create it: both outcomes are valid.
const name = () => `wc-${randomUUID().slice(0, 8)}`
const first = await kindOf(createSheetWorkingCopy(editorAal2, source, name()))
const attempt = async () => {
const promise = createSheetWorkingCopy(editorAal2, source, name())
promise.then((id) => copies.push(id), () => undefined)
return kindOf(promise)
}
const first = await attempt()
if (first === 'no failure') {
expect(await kindOf(createSheetWorkingCopy(editorAal2, source, name()))).toBe('working_copy.exists')
expect(await attempt()).toBe('working_copy.exists')
} else {
expect(['working_copy.exists', 'working_copy.assets_missing']).toContain(first)
}