Skip to content

test(vite): add HMR recovery coverage for invalid PSL edits#366

Merged
jkomyno merged 58 commits intomainfrom
tml-2293-vite-plugin-test-coverage
Apr 22, 2026
Merged

test(vite): add HMR recovery coverage for invalid PSL edits#366
jkomyno merged 58 commits intomainfrom
tml-2293-vite-plugin-test-coverage

Conversation

@jkomyno
Copy link
Copy Markdown
Contributor

@jkomyno jkomyno commented Apr 22, 2026

Summary

  • add a PSL-first Vite plugin HMR integration test that exercises startup emit, bad edit, and recovery
  • assert invalid schema edits leave the last good contract.json and contract.d.ts on disk
  • assert the next valid edit re-emits both artifacts

Testing

  • pnpm --filter @prisma-next/integration-tests exec vitest run test/vite-plugin.hmr.e2e.test.ts
  • pnpm --filter @prisma-next/integration-tests typecheck
  • pnpm exec biome check test/integration/test/vite-plugin.hmr.e2e.test.ts

Notes

jkomyno and others added 30 commits April 19, 2026 23:37
The SQL provider was updated to use context.configDir but the mongo
provider was missed, causing watcher/loader path divergence when cwd
differs from the config directory.
…onfigDir

- Switch config-loader from node:path to pathe for consistency with
  the rest of the tooling layer.
- Resolve .ts contract paths inside load() via context.configDir instead
  of capturing process.cwd() at config-definition time, so the watcher
  and loader always reference the same file.
The paths branch omitted the config file from the watch set, so edits
to prisma-next.config.ts (e.g. changing paths or swapping provider)
would not trigger re-emit. Also surface a partial-coverage warning when
loadConfig fails instead of silently falling back.
Close D1 from the PR #356 review by driving a real Vite dev server
through both scenarios that were previously only unit-mocked:
modifying `contract.prisma` re-emits the contract, and editing the
config to swap the declared PSL input re-emits against the new file.
Align with the Mongo PSL provider and with the parser step's sourceId.
The absolute form stays accessible via meta.absoluteSchemaPath for
downstream consumers that need it.
Collapse the ~20-line inline provider that postgres and mongo facades
each build around a dynamic import of the user's `contract.ts`. The
logic (path resolution, pathToFileURL, default-export extraction) is
family-agnostic, so each contract-ts package exposes it as a sibling
to typescriptContract.
- handleTrackedFileChange now runs ctx.file through pathe.resolve
  before comparing against watchedFiles / ignoredOutputFiles, so
  symlinked or case-folded paths line up with the resolved entries.
- resolveContractOutputFiles no longer falls back to the hardcoded
  'src/prisma/contract.json' when contract.output is missing. The
  filter simply skips; defineConfig() guarantees output is present
  in the happy path, and raw-object configs get a clean no-op instead
  of a path the CLI never actually writes.
…ceContext

Left over from the split that moved configDir out of ContractSourceContext
into ContractSourceEnvironment — the context builder no longer needs it.
jkomyno and others added 18 commits April 21, 2026 16:04
`loadConfig()` now owns config-file-relative path resolution for
`contract.source.inputs` and `contract.output`, and enforces that no
declared input equals an emitted artifact path. Extension facades
(postgres, mongo `define-config`) propagate the new context shape to
providers; control-api call sites thread resolved inputs through.
Introduces `getEmittedArtifactPaths()` so `contract.json` / `contract.d.ts`
paths are derived from `contract.output` in one place. `emit()` takes the
output path and uses the helper, replacing the duplicated derivation that
had grown across config, CLI, and Vite.
SQL and Mongo PSL providers read absolute paths from `context.resolvedInputs`
instead of resolving schema paths themselves; they fail loudly when the list
is empty rather than silently defaulting. TypeScript contract facades gain a
`typescriptContractFromPath` helper so both families share path handling.
Plugin reads absolute inputs from the loader-finalized config instead of
re-resolving them; the config file itself is watched in paths mode and a
warning fires on load failure. Hot-update paths are normalized via `pathe`
so the plugin stops fabricating default outputs for unrelated files.
…rdening

Updates all `prisma-next.config.ts` fixtures under test/integration to the
new `contract.source.inputs` shape. Adds the vite-plugin PSL fixture used by
the HMR e2e test and makes that test wait until the rewritten
`contract.json` is readable before parsing. Raises timeout budgets on
DB-backed CLI and sql-builder integration tests that were flaky under full-
repo load.
Updates ADR 163 to describe provider-invoked source interpretation with the
resolvedInputs I/O boundary, and aligns the config / cli / vite-plugin
READMEs with the current `load()` signature and the one-call-site path
derivation.
…ma/prisma-next into tml-2276-authoritative-watch-inputs
…uts' into tml-2277-vite-plugin-watch-behavior
…watch-behavior

# Conflicts:
#	packages/1-framework/3-tooling/cli/src/config-path-validation.ts
#	packages/1-framework/3-tooling/cli/test/config-loader.test.ts
#	packages/1-framework/3-tooling/vite-plugin-contract-emit/README.md
#	packages/1-framework/3-tooling/vite-plugin-contract-emit/src/plugin.ts
#	packages/1-framework/3-tooling/vite-plugin-contract-emit/test/plugin.test.ts
Extend the Vite plugin HMR integration suite with a PSL recovery journey.
The new test proves a bad edit preserves the last good artifacts on disk
and that a subsequent valid edit re-emits both contract files.

Refs TML-2293
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 22, 2026

Warning

Rate limit exceeded

@jkomyno has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 6 minutes and 39 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 6 minutes and 39 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: ffcf225c-24c7-4258-a848-d07acaacb7d1

📥 Commits

Reviewing files that changed from the base of the PR and between 73125a3 and d56d101.

📒 Files selected for processing (1)
  • test/integration/test/vite-plugin.hmr.e2e.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch tml-2293-vite-plugin-test-coverage

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 and usage tips.

@jkomyno jkomyno changed the title test(vite): cover bad-edit recovery in HMR e2e test(vite): add HMR recovery coverage for invalid PSL edits Apr 22, 2026
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 22, 2026

Open in StackBlitz

@prisma-next/mongo-runtime

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-runtime@366

@prisma-next/family-mongo

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/family-mongo@366

@prisma-next/sql-runtime

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-runtime@366

@prisma-next/family-sql

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/family-sql@366

@prisma-next/middleware-telemetry

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/middleware-telemetry@366

@prisma-next/mongo

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo@366

@prisma-next/extension-paradedb

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/extension-paradedb@366

@prisma-next/extension-pgvector

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/extension-pgvector@366

@prisma-next/postgres

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/postgres@366

@prisma-next/sql-orm-client

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-orm-client@366

@prisma-next/sqlite

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sqlite@366

@prisma-next/target-mongo

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/target-mongo@366

@prisma-next/adapter-mongo

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/adapter-mongo@366

@prisma-next/driver-mongo

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/driver-mongo@366

@prisma-next/contract

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/contract@366

@prisma-next/utils

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/utils@366

@prisma-next/config

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/config@366

@prisma-next/errors

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/errors@366

@prisma-next/framework-components

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/framework-components@366

@prisma-next/operations

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/operations@366

@prisma-next/ts-render

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/ts-render@366

@prisma-next/contract-authoring

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/contract-authoring@366

@prisma-next/ids

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/ids@366

@prisma-next/psl-parser

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/psl-parser@366

@prisma-next/psl-printer

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/psl-printer@366

@prisma-next/cli

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/cli@366

@prisma-next/emitter

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/emitter@366

@prisma-next/migration-tools

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/migration-tools@366

prisma-next

npm i https://pkg.pr.new/prisma/prisma-next@366

@prisma-next/vite-plugin-contract-emit

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/vite-plugin-contract-emit@366

@prisma-next/runtime-executor

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/runtime-executor@366

@prisma-next/mongo-codec

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-codec@366

@prisma-next/mongo-contract

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-contract@366

@prisma-next/mongo-value

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-value@366

@prisma-next/mongo-contract-psl

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-contract-psl@366

@prisma-next/mongo-contract-ts

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-contract-ts@366

@prisma-next/mongo-emitter

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-emitter@366

@prisma-next/mongo-schema-ir

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-schema-ir@366

@prisma-next/mongo-query-ast

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-query-ast@366

@prisma-next/mongo-orm

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-orm@366

@prisma-next/mongo-query-builder

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-query-builder@366

@prisma-next/mongo-lowering

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-lowering@366

@prisma-next/mongo-wire

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-wire@366

@prisma-next/sql-contract

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-contract@366

@prisma-next/sql-errors

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-errors@366

@prisma-next/sql-operations

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-operations@366

@prisma-next/sql-schema-ir

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-schema-ir@366

@prisma-next/sql-contract-psl

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-contract-psl@366

@prisma-next/sql-contract-ts

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-contract-ts@366

@prisma-next/sql-contract-emitter

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-contract-emitter@366

@prisma-next/sql-lane-query-builder

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-lane-query-builder@366

@prisma-next/sql-relational-core

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-relational-core@366

@prisma-next/sql-builder

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-builder@366

@prisma-next/target-postgres

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/target-postgres@366

@prisma-next/target-sqlite

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/target-sqlite@366

@prisma-next/adapter-postgres

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/adapter-postgres@366

@prisma-next/adapter-sqlite

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/adapter-sqlite@366

@prisma-next/driver-postgres

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/driver-postgres@366

@prisma-next/driver-sqlite

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/driver-sqlite@366

commit: d56d101

Add two short comments to the Vite HMR recovery integration test so the
intentional failure phase and the expected recovery phase are easier to
scan in review.
Comment thread test/integration/test/vite-plugin.hmr.e2e.test.ts Outdated
Copy link
Copy Markdown
Contributor

@wmadden wmadden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 👍🏻

Base automatically changed from tml-2277-vite-plugin-watch-behavior to main April 22, 2026 13:43
jkomyno added 2 commits April 22, 2026 16:02
…test-coverage

# Conflicts:
#	packages/1-framework/3-tooling/cli/src/config-path-validation.ts
#	packages/1-framework/3-tooling/vite-plugin-contract-emit/src/plugin.ts
#	packages/1-framework/3-tooling/vite-plugin-contract-emit/test/plugin.test.ts
@jkomyno jkomyno merged commit 5a8b0f1 into main Apr 22, 2026
16 checks passed
@jkomyno jkomyno deleted the tml-2293-vite-plugin-test-coverage branch April 22, 2026 14:21
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.

3 participants