Skip to content

fix(prisma): isolate model tests from tracked database - #242

Merged
kattsushi merged 1 commit into
masterfrom
fix/prisma-test-db-isolation
Aug 28, 2026
Merged

kattsushi merged 1 commit into
masterfrom
fix/prisma-test-db-isolation

Conversation

@kattsushi

@kattsushi kattsushi commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Closes #241

Type

  • Bug fix
  • New feature
  • Documentation only
  • Code refactoring
  • Maintenance/tooling
  • Breaking change

Summary

  • Copy tracked Prisma dev.db into an OS temporary directory before either test client opens it.
  • Point the direct and Effect Prisma clients at the same temporary database.
  • Guarantee cleanup across normal teardown, test failure, setup failure, and immediate process exit while preserving error propagation.

Root cause

PREPARE run 33192329040 correctly rejected packages/prisma/prisma/dev.db as an extra changed path. The preceding Prisma model suite passed but modified the tracked SQLite fixture through two writable clients.

Changes

File Change
packages/prisma/test/utils.ts Create/copy/clean the isolated DB and construct the direct client against it.
packages/prisma/test/prisma-model.test.ts Share the temporary path and assert tracked-byte identity plus cleanup.

Test plan

  • RED: uncached suite passed 34 tests but changed tracked DB hash.
  • Two uncached isolated model-suite runs passed 18/18 with identical tracked hash.
  • Forced 1ms timeout propagated failure and removed the temporary directory.
  • Immediate child-process exit 23 removed the temporary directory.
  • Prisma typecheck, build, lint, and format checks passed.
  • git diff --exit-code -- packages/prisma/prisma/dev.db passed after every run.
  • Generated validation outputs were removed; tracked generated files remained identical.

Contributor checklist

  • Linked approved issue fix(prisma): isolate model tests from tracked database #241.
  • Added exactly one type:* label: type:bug.
  • Exactly two test files and 161 additions plus deletions.
  • Conventional commit with no Co-Authored-By trailer.
  • No workflow dispatch, release ref/tag, GitHub Release, or npm publication occurred while preparing this PR.

Summary by CodeRabbit

  • Tests
    • Improved Prisma test isolation by running each test suite against a temporary database copy.
    • Added teardown validation to confirm temporary files are cleaned up and tracked database snapshots remain unchanged.
    • Added cleanup handling when test database setup fails or the test process exits.

@kattsushi kattsushi added the type:bug Bug fix label Aug 28, 2026
@coderabbitai

coderabbitai Bot commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 53d7461d-6cf3-4977-9a91-bc882b739574

📥 Commits

Reviewing files that changed from the base of the PR and between 190fb99 and 5ba1ae3.

📒 Files selected for processing (2)
  • packages/prisma/test/prisma-model.test.ts
  • packages/prisma/test/utils.ts

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The Prisma test utilities now copy the tracked database into a temporary directory. The model suite uses that copy, disconnects Prisma during teardown, removes the directory, and verifies that the tracked fixture remains unchanged.

Changes

Prisma test isolation

Layer / File(s) Summary
Temporary database setup
packages/prisma/test/utils.ts, packages/prisma/test/prisma-model.test.ts
The tests create a temporary database copy, configure Prisma with that path, and clean up failed setup.
Model suite teardown and validation
packages/prisma/test/prisma-model.test.ts
The suite retains model assertions, adds teardown cleanup, and verifies temporary-path isolation and tracked database preservation.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 5ba1a

The PR isolates Prisma model tests in a temporary database and preserves the tracked fixture without changing production behavior. No actionable merge-blocking risk remains beyond normal checks and review.

Poem

A rabbit copies the database bright
Into a burrow safe from write
The tracked file rests untouched
Prisma disconnects as it must
Temp files vanish from sight
Tests close neatly for the night

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the primary change: isolating Prisma model tests from the tracked database.
Linked Issues check ✅ Passed The changes satisfy issue #241. They copy the tracked fixture to a temporary directory, use the isolated database for testing, preserve the tracked fixture, disconnect clients before cleanup, and limi…
Out of Scope Changes check ✅ Passed The changes are limited to packages/prisma/test/utils.ts and packages/prisma/test/prisma-model.test.ts. They directly support the linked issue and include no release, manifest, lockfile, generated-cli…
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
Full details: Linked Issues check

Explanation

The changes satisfy issue #241. They copy the tracked fixture to a temporary directory, use the isolated database for testing, preserve the tracked fixture, disconnect clients before cleanup, and limit changes to the approved test files.

Full details: Out of Scope Changes check

Explanation

The changes are limited to packages/prisma/test/utils.ts and packages/prisma/test/prisma-model.test.ts. They directly support the linked issue and include no release, manifest, lockfile, generated-client, migration, or publication changes.

Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2 files.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/prisma-test-db-isolation

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@kattsushi
kattsushi merged commit 35b2fbe into master Aug 28, 2026
7 checks passed
@kattsushi
kattsushi deleted the fix/prisma-test-db-isolation branch August 28, 2026 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:bug Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(prisma): isolate model tests from tracked database

1 participant