forked from EduCraft/curriculum-project-hub
fix(hub): assert DB wipe and single-worker integration tests
Fail fast if TRUNCATE left Organization rows, drop the extra deleteMany before seed create, and force vitest maxWorkers=1 so forks cannot race the shared Postgres.
This commit is contained in:
@@ -7,11 +7,10 @@ name: hub check
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
pull_request:
|
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
concurrency:
|
concurrency:
|
||||||
group: hub-check-${{ github.workflow }}-${{ github.ref }}
|
group: hub-check-${{ github.ref }}
|
||||||
cancel-in-progress: true
|
cancel-in-progress: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|||||||
@@ -69,16 +69,18 @@ export async function resetDb(): Promise<void> {
|
|||||||
END IF;
|
END IF;
|
||||||
END $$;
|
END $$;
|
||||||
`);
|
`);
|
||||||
|
const leftover = await prisma.organization.count();
|
||||||
|
if (leftover !== 0) {
|
||||||
|
throw new Error(`resetDb truncate left ${leftover} organization row(s)`);
|
||||||
|
}
|
||||||
await seedTestOrganization();
|
await seedTestOrganization();
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function seedTestOrganization(
|
export async function seedTestOrganization(
|
||||||
id: string = DEFAULT_ORG_ID,
|
id: string = DEFAULT_ORG_ID,
|
||||||
slug: string = "test-default",
|
slug: string = "test-default",
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
// Prefer explicit create-after-wipe over upsert: leftover half-states after
|
|
||||||
// interrupted tests made Prisma upsert hit unique(id) while where saw zero.
|
|
||||||
await prisma.$transaction(async (tx) => {
|
await prisma.$transaction(async (tx) => {
|
||||||
await tx.organization.deleteMany({ where: { OR: [{ id }, { slug }] } });
|
|
||||||
await tx.organization.create({
|
await tx.organization.create({
|
||||||
data: {
|
data: {
|
||||||
id,
|
id,
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ export default defineConfig({
|
|||||||
// concurrent truncate/insert races. Unit tests are fast either way.
|
// concurrent truncate/insert races. Unit tests are fast either way.
|
||||||
pool: "forks",
|
pool: "forks",
|
||||||
fileParallelism: false,
|
fileParallelism: false,
|
||||||
|
maxWorkers: 1,
|
||||||
env: { NODE_ENV: "test" },
|
env: { NODE_ENV: "test" },
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user