Skip to content

πŸ› generate the database client before any project's tests - #691

Merged
jrosseel merged 1 commit into
developfrom
fix/generate-prisma-client-for-tests
Aug 20, 2026
Merged

πŸ› generate the database client before any project's tests#691
jrosseel merged 1 commit into
developfrom
fix/generate-prisma-client-for-tests

Conversation

@jrosseel

Copy link
Copy Markdown
Collaborator

What broke

#688 failed the test job with 64 failures across suites it does not touch:

FAIL src/__tests__/prisma-child-run-reservation-repository.test.ts
TypeError: Cannot read properties of undefined (reading 'Preparing')
  at server/iam/authorization/main/src/run-approval-cancellation.ts:9:93

FAIL src/__tests__/prisma-run-cancellation-repository.test.ts   <- untouched by that PR
Caused by: TypeError: Right-hand side of 'instanceof' is not an object
  at PrismaRunAdmissionRepository.admit:167

ToolInvocationState.Preparing and Prisma.PrismaClientKnownRequestError are both generated Prisma exports. Both read as undefined, so the generated client was missing in that job.

Cause

db:generate was declared as a dependency of test and lint only on the opencrane project. Libraries across the workspace import generated enums and error classes at module scope but declared no such dependency, so whether the client existed when a library's tests ran depended on which projects the affected graph selected and in what order.

That is a race, and it fails in a way that reads like a code defect rather than a missing build step β€” whole suites break at import, in files the change never touched. It also means a fresh clone cannot run one library's tests successfully.

What changed

db:generate is now a dependency of the test and lint target defaults, so it holds for every project rather than one.

Verification

Removed the generated client entirely, then ran a single library's tests:

> nx run opencrane:"db:generate"
Test Files  22 passed (22)
     Tests  141 passed (141)

The same command before this change left 12 suites failing at import. No workflow edit is needed β€” fixing the graph fixes CI and local runs together.

Merge order

Merge this before #688; that PR is red only because of this race and needs no change of its own.

Review order

Single PR, no stack.

Only the opencrane project declared db:generate as a dependency of its test and
lint targets, but libraries across the workspace import generated Prisma enums
and error classes at module scope. Whether the client existed when a library's
tests ran therefore depended on what else the affected graph happened to select
and in what order β€” a race, not a contract.

When it lost, the client's exports read as undefined and the failure looked
nothing like its cause: "Cannot read properties of undefined (reading
'Preparing')" at module init, or "Right-hand side of 'instanceof' is not an
object" from a repository comparing against Prisma.PrismaClientKnownRequestError.
Whole suites failed in files the change under test never touched.

Making generation a dependency of the test and lint defaults fixes every project
at once, and fixes a fresh clone too: running one library's tests now generates
the client first instead of failing in a way that reads like a code defect.

Verified by removing the generated client entirely and running one library's
tests: Nx runs opencrane:db:generate first, then 22 files and 141 tests pass.
Before, the same command left 12 suites failing at import.
@jrosseel
jrosseel merged commit 67e1e79 into develop Aug 20, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant