From 0f4377f16cde628d5af14d1ef0ab09a759d42690 Mon Sep 17 00:00:00 2001 From: Hong Jiarong Date: Thu, 30 Jul 2026 14:24:05 +0800 Subject: [PATCH] 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. --- .gitea/workflows/hub-check.yml | 3 +-- hub/test/integration/helpers.ts | 8 +++++--- hub/vitest.config.ts | 1 + 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.gitea/workflows/hub-check.yml b/.gitea/workflows/hub-check.yml index 1518179..7b7e010 100644 --- a/.gitea/workflows/hub-check.yml +++ b/.gitea/workflows/hub-check.yml @@ -7,11 +7,10 @@ name: hub check on: push: - pull_request: workflow_dispatch: concurrency: - group: hub-check-${{ github.workflow }}-${{ github.ref }} + group: hub-check-${{ github.ref }} cancel-in-progress: true jobs: diff --git a/hub/test/integration/helpers.ts b/hub/test/integration/helpers.ts index 60f8ed2..29491b3 100644 --- a/hub/test/integration/helpers.ts +++ b/hub/test/integration/helpers.ts @@ -69,16 +69,18 @@ export async function resetDb(): Promise { END IF; END $$; `); + const leftover = await prisma.organization.count(); + if (leftover !== 0) { + throw new Error(`resetDb truncate left ${leftover} organization row(s)`); + } await seedTestOrganization(); } + export async function seedTestOrganization( id: string = DEFAULT_ORG_ID, slug: string = "test-default", ): Promise { - // 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 tx.organization.deleteMany({ where: { OR: [{ id }, { slug }] } }); await tx.organization.create({ data: { id, diff --git a/hub/vitest.config.ts b/hub/vitest.config.ts index f9623a9..0b64ad5 100644 --- a/hub/vitest.config.ts +++ b/hub/vitest.config.ts @@ -7,6 +7,7 @@ export default defineConfig({ // concurrent truncate/insert races. Unit tests are fast either way. pool: "forks", fileParallelism: false, + maxWorkers: 1, env: { NODE_ENV: "test" }, }, });