Skip to content
This repository was archived by the owner on Nov 25, 2026. It is now read-only.

feat(migration): verify migration hash at load boundary - #384

Merged
wmadden merged 35 commits into
mainfrom
tml-2264-migration-runner-should-verify-migration-matches-its-hash
Apr 28, 2026
Merged

wmadden merged 35 commits into
mainfrom
tml-2264-migration-runner-should-verify-migration-matches-its-hash

Conversation

@wmadden

@wmadden wmadden commented Apr 27, 2026 •

Copy link
Copy Markdown
Contributor

closes TML-2264

Intent

Make every read of an on-disk migration package a verified read. Before this branch, hash verification of (metadata, ops) lived as a defensive loop inside migration apply only — every other migration command (plan, status, show, new, ref) and every future programmatic consumer trusted what came back from disk. The fix is to move the integrity check into the loader itself, so the apply path no longer carries a redundant loop, and any other caller that goes through readMigrationPackage inherits hash verification by construction.

The work also brings the migration-tools vocabulary in line with what the package now does: migrationHash (not migrationId), MigrationPackage (not MigrationBundle), MigrationMetadata (not MigrationManifest), hash.ts (not attestation.ts). Identity is computed by hashing; that's now the name of the field, the file, and the helper.

Change map

The story

  1. Move the integrity check to the load boundary. readMigrationPackage becomes the single point of trust: parse → structurally validate → rehash (metadata, ops) → fail closed if the recomputed hash doesn't match the stored migrationHash. Any caller — CLI command, programmatic apply, future consumer — inherits verification by virtue of using the loader. readMigrationsDir inherits transitively, so directory enumeration also fails closed on the first tampered child.
  2. Delete the apply-side loop that did the same thing. The per-bundle verify-loop in migration apply was the original (and only) integrity gate, and it became strictly redundant once the loader owned the check. Deleting it removes the second source of truth and the mismatched diagnostic shape it would have produced.
  3. Document who is and isn't responsible for verification. MigrationRunner.execute and executeMigrationApply now carry a JSDoc invariant: their plan / pendingMigrations parameters are trusted input. Programmatic callers must come through readMigrationPackage upstream. Author-time write paths (MigrationCLI.run from TML-2301) are intentionally non-verifying — re-authoring a migration is expected to invalidate the prior hash, so verifying there would block legitimate regenerations. The result is a clean two-loader split: verifying loader for apply-time reads, non-verifying loader for author-time writes.
  4. Unify the user-visible envelope across every command that loads a package. Five commands plus ref had drifted into three different envelope shapes for MigrationToolsError. Lift a single mapMigrationToolsError helper into cli-errors.ts; every command calls it, so the JSON envelope (code, dir, storedHash, computedHash, plus the rest of details) and the human-rendered diagnostic (summary, why, fix) are now identical regardless of which command triggered the load. While here, fix the divergence where migration new defaulted to a different contract.json path than its sister commands.
  5. Rename the vocabulary to match what the code actually does. migrationId → migrationHash (the value is a hash; "id" was historical); MigrationBundle → MigrationPackage (the on-disk thing was always called a package elsewhere); MigrationManifest → MigrationMetadata (it's a metadata envelope, not an Apple-style "manifest"); attestation.ts → hash.ts; verifyMigrationBundle → verifyMigrationHash; computeMigrationId → computeMigrationHash. The on-disk wire field renamed in lockstep across 113 example migrations via codemod. types.ts is gone; its contents are now split into metadata.ts, package.ts, graph.ts, and errors.ts — one concept per file.

Behavior changes & evidence

Compatibility / migration / risk

  • On-disk wire format: the top-level field in migration.json renames from migrationId to migrationHash. Identity is still computed by hashing the same payload — the field name is the only delta. The repo-internal codemod (commit f506fb2d6) renamed the field across all 113 example/fixture migrations. No downstream consumer outside prisma-next reads this field directly, so the change is internal.
  • Tamper diagnostic on existing checkouts: if a developer has a working tree with a hand-edited migration package, the next apply / plan / status / show / new will now fail with MIGRATION.HASH_MISMATCH instead of silently using the edited bytes. This is the intended behaviour, and the diagnostic includes a re-emit hint: node migrations/<dir>/migration.ts.
  • Trusted-input contract on MigrationRunner.execute and executeMigrationApply: documented in JSDoc, not enforced. Programmatic callers that bypass readMigrationPackage and feed a hand-built plan / pendingMigrations into the runner are responsible for verifying their own input. Inside this PR, every CLI call site routes through the verifying loader, so the invariant holds in practice.
  • No runtime perf concern: verifyMigrationHash rehashes (metadata, ops) per package on load. Migration packages are small, hashes are cheap, and the loader runs once per CLI invocation.

Follow-ups / open questions

  • TML-2316 — emit-drift detection is the natural successor: structural integrity ("the bytes still hash to their stored hash") is what this PR locks in; semantic emit-drift ("re-emitting the migration source produces the same ops.json") is a separate guarantee tracked under TML-2316.
  • Builds on TML-2301 — the MigrationCLI.run author-time orchestrator landed via merge mid-project. The two-loader split (verifying readMigrationPackage for apply-time reads, non-verifying readExistingMetadata inside MigrationCLI.run for author-time writes) is the resulting architecture and is documented inline at the non-verifying call site.

Non-goals / intentionally out of scope

  • Emit-drift detection is deferred to TML-2316. This PR verifies "does the package on disk match its recorded hash"; it does not verify "would re-emitting the package produce the same ops".
  • Retroactive ADR 199 edits. ADR 199 — Storage-only migration identity — predates this work and is preserved as a historical record; the new hash.ts JSDoc references it for the canonicalization-rule rationale, but the ADR itself is untouched.
  • Signing / attestation provenance. The signature field on MigrationMetadata is read through but is not part of the integrity check this PR adds; the field is intentionally stripped before hashing so a future signing scheme can co-exist with structural verification.

Summary by CodeRabbit

  • New Features

    • Migration identity is now a content-addressed migrationHash (visible in CLI outputs and migration.json).
  • Bug Fixes

    • Detects and surfaces MIGRATION.HASH_MISMATCH for tampered migration packages across commands.
  • Chores

    • Renamed migrationId → migrationHash across CLI, tooling, examples and fixtures.
    • Switched persisted artifacts from manifest/bundle to package/metadata and reorganized related exports.
  • Documentation

    • Updated CLI docs/help to describe migrationHash and package-based workflow.
  • Tests

    • Added/updated tests for hashing, verification, tamper detection, and CLI flows.

@coderabbitai

coderabbitai Bot commented Apr 27, 2026 •

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Replaces top-level migration identifier migrationId with migrationHash across fixtures, CLI, tooling, graph, IO, and tests; removes legacy attestation, introduces MigrationMetadata/MigrationPackage and hash compute/verify logic, and adds tamper/hash-mismatch tests and error mapping.

Changes

Cohort / File(s) Summary
Example fixtures
examples/.../migrations/*/migration.json, examples/.../migration-fixtures/**/migration.json
Renamed top-level JSON key migrationId → migrationHash in many example migration files.
Example & integration tests
examples/*/test/manual-migration.test.ts, test/**/*.e2e.test.ts
Updated assertions/comments to use migrationHash and adjusted tests to read metadata fields.
CLI commands & utilities
packages/1-framework/3-tooling/cli/src/commands/*, .../utils/*, .../migration-cli.ts, .../command-helpers.ts, .../cli-errors.ts
Shifted CLI to operate on MigrationPackage/metadata and migrationHash; swapped bundle APIs for package APIs; centralized MigrationToolsError → mapMigrationToolsError.
Migration tooling: hash & metadata
packages/.../migration/src/{hash.ts,metadata.ts,package.ts}
Added computeMigrationHash / verifyMigrationHash, MigrationMetadata, MigrationPackage and related types.
Migration IO & verification
packages/.../migration/src/io.ts, .../migration-base.ts
Switched read/write to metadata model (writeMigrationMetadata, writeMigrationPackage(metadata, ops)); readMigrationPackage/readMigrationsDir now return MigrationPackage and perform hash verification (throws HASH_MISMATCH).
Graph / dag / errors
packages/.../migration/src/dag.ts, .../errors.ts, src/graph.ts
Graph reconstruction keyed by migrationHash (migrationByHash); duplicate/mismatch errors renamed/added (e.g., DUPLICATE_MIGRATION_HASH, MIGRATION.HASH_MISMATCH).
Removed legacy attestation & types
packages/.../migration/src/attestation.ts, src/types.ts, src/exports/attestation.ts, src/exports/types.ts
Deleted attestation module and legacy types.ts; updated package exports to new subpaths (./hash, ./metadata, ./package, ./graph, ./errors).
CLI & migration tests updated / added
packages/.../cli/test/**, packages/.../migration/test/**, packages/.../cli/test/commands/migration-tamper.test.ts
Extensive test updates to use metadata/hash; new tamper e2e asserts MIGRATION.HASH_MISMATCH across commands; many fixtures/helpers switched to compute/write attested packages.
Docs, READMEs & package exports
packages/1-framework/3-tooling/cli/README.md, packages/.../migration/README.md, package.json, tsdown.config.ts
Docs updated to describe hash-centric API and verification model; package exports re-mapped to new entrypoints.
Minor comments / JSDoc
packages/1-framework/1-core/..., packages/2-mongo-family/...
Added/updated JSDoc clarifying trust/verification boundaries and renamed references in comments.

Sequence Diagram(s)

sequenceDiagram
  participant CLI as CLI Command
  participant IO as readMigrationPackage (disk)
  participant Hash as verifyMigrationHash
  participant Runner as MigrationRunner
  CLI->>IO: load migration package (migration.json + ops.json)
  IO->>Hash: computeMigrationHash(metadata, ops)
  Hash-->>IO: ok / mismatch (storedHash vs computedHash)
  alt ok
    IO-->>CLI: MigrationPackage(metadata, ops)
    CLI->>Runner: execute migrations (uses metadata.from/to)
    Runner-->>CLI: progress / result
  else mismatch
    IO-->>CLI: throw MIGRATION.HASH_MISMATCH error (dir, storedHash, computedHash)
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Poem

"I hopped through files with a twitchy nose,
Swapped ids for hashes where the pipeline goes.
I nibbled tests, rewrote the migration cache,
Now packages hum and errors point the path.
🐇 SHA256 hops — a rabbit's small splash."

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch tml-2264-migration-runner-should-verify-migration-matches-its-hash

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

@pkg-pr-new

pkg-pr-new Bot commented Apr 27, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@prisma-next/mongo-runtime

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

@prisma-next/family-mongo

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

@prisma-next/sql-runtime

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

@prisma-next/family-sql

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

@prisma-next/middleware-telemetry

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

@prisma-next/mongo

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

@prisma-next/extension-paradedb

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

@prisma-next/extension-pgvector

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

@prisma-next/postgres

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

@prisma-next/sql-orm-client

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

@prisma-next/sqlite

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

@prisma-next/target-mongo

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

@prisma-next/adapter-mongo

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

@prisma-next/driver-mongo

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

@prisma-next/contract

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

@prisma-next/utils

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

@prisma-next/config

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

@prisma-next/errors

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

@prisma-next/framework-components

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

@prisma-next/operations

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

@prisma-next/ts-render

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

@prisma-next/contract-authoring

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

@prisma-next/ids

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

@prisma-next/psl-parser

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

@prisma-next/psl-printer

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

@prisma-next/cli

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

@prisma-next/emitter

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

@prisma-next/migration-tools

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

prisma-next

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

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

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

@prisma-next/mongo-codec

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

@prisma-next/mongo-contract

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

@prisma-next/mongo-value

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

@prisma-next/mongo-contract-psl

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

@prisma-next/mongo-contract-ts

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

@prisma-next/mongo-emitter

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

@prisma-next/mongo-schema-ir

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

@prisma-next/mongo-query-ast

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

@prisma-next/mongo-orm

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

@prisma-next/mongo-query-builder

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

@prisma-next/mongo-lowering

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

@prisma-next/mongo-wire

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

@prisma-next/sql-contract

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

@prisma-next/sql-errors

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

@prisma-next/sql-operations

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

@prisma-next/sql-schema-ir

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

@prisma-next/sql-contract-psl

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

@prisma-next/sql-contract-ts

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

@prisma-next/sql-contract-emitter

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

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

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

@prisma-next/sql-relational-core

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

@prisma-next/sql-builder

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

@prisma-next/target-postgres

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

@prisma-next/target-sqlite

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

@prisma-next/adapter-postgres

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

@prisma-next/adapter-sqlite

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

@prisma-next/driver-postgres

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

@prisma-next/driver-sqlite

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

commit: be2d0d9

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/1-framework/3-tooling/cli/src/commands/migration-status.ts (1)

159-171: ⚠️ Potential issue | 🟠 Major

Track edge status by migration identity, not just endpoints.

assignedKeys currently collapses parallel migrations that share the same from/to. After this refactor, those edges are distinct by migrationHash, so one package can hide another package’s status in the rendered result.

Suggested fix
-  const edgeKey = (e: MigrationChainEntry) => `${e.from}\0${e.to}`;
+  const edgeKey = (e: MigrationChainEntry) => e.migrationHash;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/1-framework/3-tooling/cli/src/commands/migration-status.ts` around
lines 159 - 171, assignedKeys currently collapses parallel MigrationChainEntry
edges that share the same from/to by using edgeKey(e) = `${e.from}\0${e.to}`,
which hides distinct migrations; update the identity key to include the
migrationHash so edges are tracked by migration identity (e.g., change edgeKey
to include e.migrationHash and use that key everywhere assignedKeys is
populated/checked), and ensure any logic that constructs or compares edge keys
for statuses (references to edgeKey, assignedKeys, and the MigrationChainEntry
shape) uses the new three-part key so parallel migrations are rendered
separately.
🧹 Nitpick comments (1)
packages/1-framework/3-tooling/migration/test/fixtures.ts (1)

49-58: Keep the “attested package” helpers hash-safe.

Both helpers promise a computed, internally consistent migrationHash, but metadataOverrides can still smuggle in a custom hash through createTestMetadata(). That makes it easy for unrelated tests to create corrupt fixtures accidentally instead of via the explicit post-write tamper step.

Suggested tightening
 export function createAttestedPackage(
   dirName: string,
-  metadataOverrides: Partial<MigrationMetadata> = {},
+  metadataOverrides: Omit<Partial<MigrationMetadata>, 'migrationHash'> = {},
   ops: MigrationOps = createTestOps(),
 ): MigrationPackage {
 export async function writeTestPackage(
   dir: string,
-  metadataOverrides: Partial<MigrationMetadata> = {},
+  metadataOverrides: Omit<Partial<MigrationMetadata>, 'migrationHash'> = {},
   ops: MigrationOps = createTestOps(),
 ): Promise<{ metadata: MigrationMetadata; ops: MigrationOps }> {

Also applies to: 85-91

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/1-framework/3-tooling/migration/test/fixtures.ts` around lines 49 -
58, The attested-package helpers (e.g., createAttestedPackage) must ensure the
MigrationMetadata.migrationHash cannot be injected via metadataOverrides; after
building metadata with createTestMetadata(metadataOverrides, ops) strip any
provided migrationHash or recompute and set metadata.migrationHash
deterministically from the resulting metadata/ops so the returned
MigrationPackage always contains an internally consistent computed hash; apply
the same fix to the companion helper at lines 85–91 so neither helper accepts an
override that can smuggle in a custom migrationHash.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/1-framework/3-tooling/cli/src/commands/migration-plan.ts`:
- Around line 489-492: The "Next" message emitted after writeMigrationPackage()
incorrectly instructs users to run migration.ts to emit ops.json and attest the
migrationHash; update the message built where lines.push(...) constructs that
template string (the block that currently contains `Next: ${green_(`node
${result.dir ?? '<dir>'}/migration.ts`)} ...`) to instead show the correct next
step for the non-placeholder flow (for example instruct to run `prisma-next
migration apply` directly or otherwise reflect that ops.json and migration.json
have already been written). Modify the template string generation in the
migration-plan code path that follows writeMigrationPackage() so it no longer
references running migration.ts and accurately describes the next action for the
already-written package.

---

Outside diff comments:
In `@packages/1-framework/3-tooling/cli/src/commands/migration-status.ts`:
- Around line 159-171: assignedKeys currently collapses parallel
MigrationChainEntry edges that share the same from/to by using edgeKey(e) =
`${e.from}\0${e.to}`, which hides distinct migrations; update the identity key
to include the migrationHash so edges are tracked by migration identity (e.g.,
change edgeKey to include e.migrationHash and use that key everywhere
assignedKeys is populated/checked), and ensure any logic that constructs or
compares edge keys for statuses (references to edgeKey, assignedKeys, and the
MigrationChainEntry shape) uses the new three-part key so parallel migrations
are rendered separately.

---

Nitpick comments:
In `@packages/1-framework/3-tooling/migration/test/fixtures.ts`:
- Around line 49-58: The attested-package helpers (e.g., createAttestedPackage)
must ensure the MigrationMetadata.migrationHash cannot be injected via
metadataOverrides; after building metadata with
createTestMetadata(metadataOverrides, ops) strip any provided migrationHash or
recompute and set metadata.migrationHash deterministically from the resulting
metadata/ops so the returned MigrationPackage always contains an internally
consistent computed hash; apply the same fix to the companion helper at lines
85–91 so neither helper accepts an override that can smuggle in a custom
migrationHash.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 54693dc9-f095-40a1-b139-65312577fe5c

📥 Commits

Reviewing files that changed from the base of the PR and between 0c71270 and 014dd57.

📒 Files selected for processing (176)
  • examples/mongo-demo/migrations/20260409T1030_migration/migration.json
  • examples/mongo-demo/migrations/20260415_add-posts-author-index/migration.json
  • examples/mongo-demo/test/manual-migration.test.ts
  • examples/prisma-next-demo/migration-fixtures/complex/20260301T1000_init/migration.json
  • examples/prisma-next-demo/migration-fixtures/complex/20260302T1000_alice_add_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/complex/20260302T1100_bob_add_avatar/migration.json
  • examples/prisma-next-demo/migration-fixtures/complex/20260302T1200_staging_posts/migration.json
  • examples/prisma-next-demo/migration-fixtures/complex/20260303T1000_merge_alice/migration.json
  • examples/prisma-next-demo/migration-fixtures/complex/20260303T1100_merge_bob/migration.json
  • examples/prisma-next-demo/migration-fixtures/complex/20260304T1000_add_comments/migration.json
  • examples/prisma-next-demo/migration-fixtures/complex/20260305T1000_add_tags/migration.json
  • examples/prisma-next-demo/migration-fixtures/converging-branches/20260301T1000_init/migration.json
  • examples/prisma-next-demo/migration-fixtures/converging-branches/20260302T1000_add_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/converging-branches/20260302T1100_add_posts/migration.json
  • examples/prisma-next-demo/migration-fixtures/converging-branches/20260302T1200_add_avatar/migration.json
  • examples/prisma-next-demo/migration-fixtures/converging-branches/20260303T1000_merge_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/converging-branches/20260303T1100_merge_posts/migration.json
  • examples/prisma-next-demo/migration-fixtures/converging-branches/20260303T1200_merge_avatar/migration.json
  • examples/prisma-next-demo/migration-fixtures/diamond-sub-branch/20260301T1000_init/migration.json
  • examples/prisma-next-demo/migration-fixtures/diamond-sub-branch/20260302T1000_alice_add_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/diamond-sub-branch/20260302T1100_bob_add_avatar/migration.json
  • examples/prisma-next-demo/migration-fixtures/diamond-sub-branch/20260302T1200_bob_experiment/migration.json
  • examples/prisma-next-demo/migration-fixtures/diamond-sub-branch/20260303T1000_merge_alice/migration.json
  • examples/prisma-next-demo/migration-fixtures/diamond-sub-branch/20260303T1100_merge_bob/migration.json
  • examples/prisma-next-demo/migration-fixtures/diamond-sub-branch/20260303T1200_bob_experiment_2/migration.json
  • examples/prisma-next-demo/migration-fixtures/diamond/20260301T1000_init/migration.json
  • examples/prisma-next-demo/migration-fixtures/diamond/20260302T1000_alice_add_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/diamond/20260302T1100_bob_add_avatar/migration.json
  • examples/prisma-next-demo/migration-fixtures/diamond/20260303T1000_merge_alice/migration.json
  • examples/prisma-next-demo/migration-fixtures/diamond/20260303T1100_merge_bob/migration.json
  • examples/prisma-next-demo/migration-fixtures/kitchen-sink/20260301T1000_init/migration.json
  • examples/prisma-next-demo/migration-fixtures/kitchen-sink/20260302T1000_add_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/kitchen-sink/20260302T1100_widen_email/migration.json
  • examples/prisma-next-demo/migration-fixtures/kitchen-sink/20260303T1000_email_default/migration.json
  • examples/prisma-next-demo/migration-fixtures/kitchen-sink/20260304T1000_change_default/migration.json
  • examples/prisma-next-demo/migration-fixtures/kitchen-sink/20260305T1000_add_posts/migration.json
  • examples/prisma-next-demo/migration-fixtures/kitchen-sink/20260306T1000_add_comments/migration.json
  • examples/prisma-next-demo/migration-fixtures/kitchen-sink/20260307T1000_kitchen_sink/migration.json
  • examples/prisma-next-demo/migration-fixtures/kitchen-sink/20260308T1000_rollback/migration.json
  • examples/prisma-next-demo/migration-fixtures/kitchen-sink/20260326T1428_migration/migration.json
  • examples/prisma-next-demo/migration-fixtures/linear/20260301T1000_init/migration.json
  • examples/prisma-next-demo/migration-fixtures/linear/20260302T1000_add_posts/migration.json
  • examples/prisma-next-demo/migration-fixtures/long-spine/20260301T1000_init/migration.json
  • examples/prisma-next-demo/migration-fixtures/long-spine/20260302T1000_add_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/long-spine/20260303T1000_add_bio/migration.json
  • examples/prisma-next-demo/migration-fixtures/long-spine/20260304T1000_add_posts/migration.json
  • examples/prisma-next-demo/migration-fixtures/long-spine/20260305T1000_add_avatar/migration.json
  • examples/prisma-next-demo/migration-fixtures/long-spine/20260306T1000_add_comments/migration.json
  • examples/prisma-next-demo/migration-fixtures/long-spine/20260307T1000_add_tags/migration.json
  • examples/prisma-next-demo/migration-fixtures/long-spine/20260307T1100_late_branch/migration.json
  • examples/prisma-next-demo/migration-fixtures/long-spine/20260308T1000_add_everything/migration.json
  • examples/prisma-next-demo/migration-fixtures/multi-branch/20260301T1000_init/migration.json
  • examples/prisma-next-demo/migration-fixtures/multi-branch/20260302T1000_add_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/multi-branch/20260302T1100_add_posts/migration.json
  • examples/prisma-next-demo/migration-fixtures/multi-branch/20260302T1200_add_avatar/migration.json
  • examples/prisma-next-demo/migration-fixtures/multi-branch/20260303T1000_add_bio/migration.json
  • examples/prisma-next-demo/migration-fixtures/multi-branch/20260326T1430_migration/migration.json
  • examples/prisma-next-demo/migration-fixtures/multi-branch/20260326T1431_foobar/migration.json
  • examples/prisma-next-demo/migration-fixtures/multi-branch/20260326T1431_migration/migration.json
  • examples/prisma-next-demo/migration-fixtures/multi-branch/20260326T1432_foobar/migration.json
  • examples/prisma-next-demo/migration-fixtures/multi-rollback-branch/20260301T1000_init/migration.json
  • examples/prisma-next-demo/migration-fixtures/multi-rollback-branch/20260302T1000_add_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/multi-rollback-branch/20260302T1100_staging/migration.json
  • examples/prisma-next-demo/migration-fixtures/multi-rollback-branch/20260303T1000_add_bio/migration.json
  • examples/prisma-next-demo/migration-fixtures/multi-rollback-branch/20260304T1000_add_comments/migration.json
  • examples/prisma-next-demo/migration-fixtures/multi-rollback-branch/20260305T1000_add_tags/migration.json
  • examples/prisma-next-demo/migration-fixtures/multi-rollback-branch/20260306T1000_rollback_to_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/rollback-continue/20260301T1000_init/migration.json
  • examples/prisma-next-demo/migration-fixtures/rollback-continue/20260302T1000_add_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/rollback-continue/20260303T1000_add_bio/migration.json
  • examples/prisma-next-demo/migration-fixtures/rollback-continue/20260304T1000_rollback_bio/migration.json
  • examples/prisma-next-demo/migration-fixtures/rollback-continue/20260305T1000_rollback_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/rollback-continue/20260306T1000_add_posts/migration.json
  • examples/prisma-next-demo/migration-fixtures/rollback/20260301T1000_init/migration.json
  • examples/prisma-next-demo/migration-fixtures/rollback/20260302T1000_add_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/rollback/20260303T1000_add_bio/migration.json
  • examples/prisma-next-demo/migration-fixtures/rollback/20260304T1000_rollback_bio/migration.json
  • examples/prisma-next-demo/migration-fixtures/rollback/20260305T1000_rollback_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260301T1000_init/migration.json
  • examples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260302T1000_alice_add_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260302T1100_bob_add_avatar/migration.json
  • examples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260303T1000_merge_1a/migration.json
  • examples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260303T1100_merge_1b/migration.json
  • examples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260304T1000_add_comments/migration.json
  • examples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260304T1100_add_posts_branch/migration.json
  • examples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260305T1000_merge_2a/migration.json
  • examples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260305T1100_merge_2b/migration.json
  • examples/prisma-next-demo/migration-fixtures/single-branch/20260301T1000_init/migration.json
  • examples/prisma-next-demo/migration-fixtures/single-branch/20260302T1000_add_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/single-branch/20260302T1100_add_posts/migration.json
  • examples/prisma-next-demo/migration-fixtures/single-branch/20260303T1000_add_bio/migration.json
  • examples/prisma-next-demo/migration-fixtures/skip-rollback/20260301T1000_init/migration.json
  • examples/prisma-next-demo/migration-fixtures/skip-rollback/20260302T1000_add_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/skip-rollback/20260303T1000_add_bio/migration.json
  • examples/prisma-next-demo/migration-fixtures/skip-rollback/20260304T1000_add_posts/migration.json
  • examples/prisma-next-demo/migration-fixtures/skip-rollback/20260305T1000_rollback_to_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/skip-rollback/20260306T1000_rollback_to_init/migration.json
  • examples/prisma-next-demo/migration-fixtures/sub-branches/20260301T1000_init/migration.json
  • examples/prisma-next-demo/migration-fixtures/sub-branches/20260302T1000_add_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/sub-branches/20260302T1100_add_posts/migration.json
  • examples/prisma-next-demo/migration-fixtures/sub-branches/20260303T1000_add_bio/migration.json
  • examples/prisma-next-demo/migration-fixtures/sub-branches/20260303T1100_add_avatar/migration.json
  • examples/prisma-next-demo/migration-fixtures/wide-fan/20260301T1000_init/migration.json
  • examples/prisma-next-demo/migration-fixtures/wide-fan/20260302T1000_add_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/wide-fan/20260302T1100_add_posts/migration.json
  • examples/prisma-next-demo/migration-fixtures/wide-fan/20260302T1200_add_avatar/migration.json
  • examples/prisma-next-demo/migration-fixtures/wide-fan/20260302T1300_add_category/migration.json
  • examples/prisma-next-demo/migration-fixtures/wide-fan/20260302T1400_add_settings/migration.json
  • examples/prisma-next-demo/migrations/20260422T0720_initial/migration.json
  • examples/prisma-next-demo/migrations/20260422T0742_migration/migration.json
  • examples/prisma-next-demo/migrations/20260422T0748_migration/migration.json
  • examples/retail-store/migrations/20260413T0314_migration/migration.json
  • examples/retail-store/migrations/20260415_add-product-validation/migration.json
  • examples/retail-store/migrations/20260416_backfill-product-status/migration.json
  • examples/retail-store/test/manual-migration.test.ts
  • packages/1-framework/1-core/framework-components/src/control-migration-types.ts
  • packages/1-framework/3-tooling/cli/README.md
  • packages/1-framework/3-tooling/cli/src/commands/migration-apply.ts
  • packages/1-framework/3-tooling/cli/src/commands/migration-new.ts
  • packages/1-framework/3-tooling/cli/src/commands/migration-plan.ts
  • packages/1-framework/3-tooling/cli/src/commands/migration-ref.ts
  • packages/1-framework/3-tooling/cli/src/commands/migration-show.ts
  • packages/1-framework/3-tooling/cli/src/commands/migration-status.ts
  • packages/1-framework/3-tooling/cli/src/control-api/operations/migration-apply.ts
  • packages/1-framework/3-tooling/cli/src/migration-cli.ts
  • packages/1-framework/3-tooling/cli/src/utils/cli-errors.ts
  • packages/1-framework/3-tooling/cli/src/utils/command-helpers.ts
  • packages/1-framework/3-tooling/cli/src/utils/formatters/graph-migration-mapper.ts
  • packages/1-framework/3-tooling/cli/src/utils/formatters/migrations.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-apply.test.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-e2e.test.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-plan-command.test.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-plan.test.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-ref-error-mapping.test.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-ref.test.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-show.test.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-tamper.test.ts
  • packages/1-framework/3-tooling/cli/test/control-api/client.test.ts
  • packages/1-framework/3-tooling/cli/test/migration-cli.test.ts
  • packages/1-framework/3-tooling/cli/test/output.json-shapes.test.ts
  • packages/1-framework/3-tooling/cli/test/utils/graph-helpers.ts
  • packages/1-framework/3-tooling/migration/README.md
  • packages/1-framework/3-tooling/migration/package.json
  • packages/1-framework/3-tooling/migration/src/attestation.ts
  • packages/1-framework/3-tooling/migration/src/dag.ts
  • packages/1-framework/3-tooling/migration/src/errors.ts
  • packages/1-framework/3-tooling/migration/src/exports/attestation.ts
  • packages/1-framework/3-tooling/migration/src/exports/errors.ts
  • packages/1-framework/3-tooling/migration/src/exports/graph.ts
  • packages/1-framework/3-tooling/migration/src/exports/hash.ts
  • packages/1-framework/3-tooling/migration/src/exports/io.ts
  • packages/1-framework/3-tooling/migration/src/exports/metadata.ts
  • packages/1-framework/3-tooling/migration/src/exports/package.ts
  • packages/1-framework/3-tooling/migration/src/exports/types.ts
  • packages/1-framework/3-tooling/migration/src/graph.ts
  • packages/1-framework/3-tooling/migration/src/hash.ts
  • packages/1-framework/3-tooling/migration/src/io.ts
  • packages/1-framework/3-tooling/migration/src/metadata.ts
  • packages/1-framework/3-tooling/migration/src/migration-base.ts
  • packages/1-framework/3-tooling/migration/src/package.ts
  • packages/1-framework/3-tooling/migration/src/types.ts
  • packages/1-framework/3-tooling/migration/test/attestation.test.ts
  • packages/1-framework/3-tooling/migration/test/dag.test.ts
  • packages/1-framework/3-tooling/migration/test/fixtures.ts
  • packages/1-framework/3-tooling/migration/test/hash.test.ts
  • packages/1-framework/3-tooling/migration/test/io.test.ts
  • packages/1-framework/3-tooling/migration/test/migration-base.test.ts
  • packages/1-framework/3-tooling/migration/tsdown.config.ts
  • packages/2-mongo-family/9-family/src/core/mongo-target-descriptor.ts
  • test/integration/test/cli-journeys/data-transform-enum-rebuild.e2e.test.ts
  • test/integration/test/cli-journeys/data-transform-not-null-backfill.e2e.test.ts
  • test/integration/test/cli-journeys/data-transform-nullable-tightening.e2e.test.ts
  • test/integration/test/cli-journeys/data-transform-type-change.e2e.test.ts
  • test/integration/test/cli-journeys/migration-plan-details.e2e.test.ts
  • test/integration/test/cli-journeys/mongo-migration.e2e.test.ts
  • test/integration/test/cli.migration-apply.e2e.test.ts
💤 Files with no reviewable changes (5)
  • packages/1-framework/3-tooling/migration/src/exports/attestation.ts
  • packages/1-framework/3-tooling/migration/test/attestation.test.ts
  • packages/1-framework/3-tooling/migration/src/exports/types.ts
  • packages/1-framework/3-tooling/migration/src/types.ts
  • packages/1-framework/3-tooling/migration/src/attestation.ts

@wmadden

wmadden commented Apr 27, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review @coderabbitai. Responding to the two findings in your review body:

migration/test/fixtures.ts:49-58 + 85-91 (nitpick) — addressed in c011a52

Tightened metadataOverrides on both createAttestedPackage and writeTestPackage to Omit<Partial<MigrationMetadata>, migrationHash> so callers can no longer smuggle a custom hash past the always-attested fixture invariant — accidental hash injection is now a compile error. createTestMetadata stays as-is so hash.test.ts can still inject a migrationHash for the ignores existing migrationHash test (its job is to verify computeMigrationHash recomputes regardless).

cli/src/commands/migration-status.ts:159-171 (outside diff range, 🟠 Major) — declining as out of scope

Im going to skip this on this PR with rationale rather than a fix:

  • The block you flagged (deriveEdgeStatuses, edgeKey = (e.from, e.to)) is not touched by this PR. The PRs diff in migration-status.ts is a pure rename (MigrationBundle → MigrationPackage, migrationId → migrationHash, plus routing MigrationToolsError through mapMigrationToolsError). Lines 159-171 predate this PR.
  • Your framing — "After this refactor, those edges are distinct by migrationHash" — is a rename, not a semantic change: pre-refactor edges were equally distinct by migrationId (the field was renamed, not introduced). The collision concern for parallel migrations sharing identical (from, to) existed before this PR and is unchanged by it.
  • This PRs scope is hash-integrity verification at the load boundary; the suggested fix needs its own test (parallel-migration fixture exercising the collision) and would dilute the PRs narrative.

I do think the underlying concern has merit (two migrations with identical (from, to) and different ops would currently have one hide the others status entry), so Ive noted it for a follow-up scoped to status-rendering correctness. Decision recorded under wip/unattended-decisions.md (decision 6).

@coderabbitai

coderabbitai Bot commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

@wmadden Thanks for the detailed responses.

fixtures.ts nitpick — acknowledged. The Omit<Partial<MigrationMetadata>, 'migrationHash'> constraint is exactly the right shape: createAttestedPackage and writeTestPackage now enforce the "always-recomputed hash" invariant at the type level, while createTestMetadata retains the flexibility needed by hash.test.ts to probe computeMigrationHash's ignore-existing-hash behaviour. That's a clean separation of concerns.

migration-status.ts major — understood and accepted. Your reasoning is accurate on all three points: the lines predate this PR, the rename didn't introduce a new semantic (edges were equally distinct by migrationId before), and a proper fix needs a parallel-migration fixture and its own narrative. Noted.

Since you've flagged the underlying (from, to) collision concern as worth fixing in a follow-up, would you like me to open a GitHub issue to track it? I can capture the deriveEdgeStatuses / edgeKey collision scenario, link back to this PR and your wip/unattended-decisions.md note, and assign it appropriately.

wmadden added a commit that referenced this pull request Apr 27, 2026
When `migration plan` succeeds without placeholders, `writeMigrationPackage`
has already emitted ops.json + migration.json with a fully attested
migrationHash, so the previous `Next: node <dir>/migration.ts to emit ops.json
and attest migrationHash before running prisma-next migration apply` instruction
was actively misleading: it told the user to repeat work the planner had
already done. Replace with a direct pointer at `prisma-next migration apply`.

The placeholder branch keeps its existing `Then run: node <dir>/migration.ts`
instruction, which is correct (placeholders genuinely require a self-emit
round-trip).

Addresses CodeRabbit review on PR #384.
wmadden added a commit that referenced this pull request Apr 27, 2026
…lpers

createAttestedPackage and writeTestPackage are documented to always produce
internally-consistent (attested) packages — the migrationHash is computed
over the exact (metadata, ops) that get returned/written. The
metadataOverrides parameter was typed Partial<MigrationMetadata>, which let
callers smuggle a custom migrationHash past createTestMetadata's
`overrides.migrationHash ?? computeMigrationHash(...)` fallback and produce
an inconsistent fixture without going through the explicit post-write tamper
step the helpers are designed for.

Tighten the override type to Omit<Partial<MigrationMetadata>, 'migrationHash'>
on both helpers so accidental hash injection becomes a compile error.
createTestMetadata stays as-is — hash.test.ts intentionally injects a
migrationHash to verify computeMigrationHash ignores the existing field.

Addresses CodeRabbit review on PR #384 (review body, fixtures.ts:49-58 + 85-91).
@wmadden

wmadden commented Apr 27, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @coderabbitai. Going to leave the follow-up tracking decision to a human teammate — the wip/unattended-decisions.md entry captures the analysis locally, and whether it warrants a GitHub issue / Linear ticket is a call Id rather not unilaterally make under unattended mode. No further action needed on this PR.

@coderabbitai

coderabbitai Bot commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

@wmadden Understood — happy to leave it with the team. The wip/unattended-decisions.md entry is a solid local anchor for whoever picks it up. No further action from my side on this PR. Thanks for the thorough responses throughout the review!

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/1-framework/3-tooling/cli/src/commands/migration-plan.ts (1)

519-523: Clarify resolver docs to say “target contract hash”.

On Line 519 and Line 528, wording says generic “hash”, but implementation matches metadata.to (contract target hash), not metadata.migrationHash. Tightening wording avoids future misuse.

✏️ Suggested doc wording update
- * Resolve a migration package by exact hash or prefix match.
+ * Resolve a migration package by target contract hash (`metadata.to`) using
+ * exact match or prefix match.
@@
- * the needle omits the scheme). Returns the matched package on success, or a
+ * the needle omits the scheme). Returns the matched package on success, or a

Also applies to: 528-537

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/1-framework/3-tooling/cli/src/commands/migration-plan.ts` around
lines 519 - 523, Update the resolver docs that currently say “hash” to
explicitly say “target contract hash” (i.e., the contract target stored in
metadata.to) so the comments match the implementation which matches metadata.to
rather than metadata.migrationHash; change the two doc blocks around the
migration package resolver in migration-plan.ts (the comment starting “Resolve a
migration package by exact hash or prefix match” and the later block covering
lines ~528-537) to use the phrase “target contract hash” and briefly note that
the resolver matches metadata.to (prefix/exact with optional auto-prepended
sha256:) to avoid future confusion.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/1-framework/3-tooling/cli/src/commands/migration-plan.ts`:
- Around line 519-523: Update the resolver docs that currently say “hash” to
explicitly say “target contract hash” (i.e., the contract target stored in
metadata.to) so the comments match the implementation which matches metadata.to
rather than metadata.migrationHash; change the two doc blocks around the
migration package resolver in migration-plan.ts (the comment starting “Resolve a
migration package by exact hash or prefix match” and the later block covering
lines ~528-537) to use the phrase “target contract hash” and briefly note that
the resolver matches metadata.to (prefix/exact with optional auto-prepended
sha256:) to avoid future confusion.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 62ba2426-62a8-4a37-9fbb-5d6bfea37a8f

📥 Commits

Reviewing files that changed from the base of the PR and between 014dd57 and c011a52.

📒 Files selected for processing (2)
  • packages/1-framework/3-tooling/cli/src/commands/migration-plan.ts
  • packages/1-framework/3-tooling/migration/test/fixtures.ts

wmadden added a commit that referenced this pull request Apr 27, 2026
When `migration plan` succeeds without placeholders, `writeMigrationPackage`
has already emitted ops.json + migration.json with a fully attested
migrationHash, so the previous `Next: node <dir>/migration.ts to emit ops.json
and attest migrationHash before running prisma-next migration apply` instruction
was actively misleading: it told the user to repeat work the planner had
already done. Replace with a direct pointer at `prisma-next migration apply`.

The placeholder branch keeps its existing `Then run: node <dir>/migration.ts`
instruction, which is correct (placeholders genuinely require a self-emit
round-trip).

Addresses CodeRabbit review on PR #384.
wmadden added a commit that referenced this pull request Apr 27, 2026
…lpers

createAttestedPackage and writeTestPackage are documented to always produce
internally-consistent (attested) packages — the migrationHash is computed
over the exact (metadata, ops) that get returned/written. The
metadataOverrides parameter was typed Partial<MigrationMetadata>, which let
callers smuggle a custom migrationHash past createTestMetadata's
`overrides.migrationHash ?? computeMigrationHash(...)` fallback and produce
an inconsistent fixture without going through the explicit post-write tamper
step the helpers are designed for.

Tighten the override type to Omit<Partial<MigrationMetadata>, 'migrationHash'>
on both helpers so accidental hash injection becomes a compile error.
createTestMetadata stays as-is — hash.test.ts intentionally injects a
migrationHash to verify computeMigrationHash ignores the existing field.

Addresses CodeRabbit review on PR #384 (review body, fixtures.ts:49-58 + 85-91).
@wmadden
wmadden force-pushed the tml-2264-migration-runner-should-verify-migration-matches-its-hash branch from c011a52 to 5baddd5 Compare April 27, 2026 16:19
wmadden added 17 commits April 28, 2026 06:48
…y verification

Capture the design + execution plan for hoisting the apply-time
migrationHash integrity check out of the CLI 'migration apply' loop and
into the on-disk loader (readMigrationPackage), so every consumer
inherits package-integrity verification at the load boundary.

The spec also bundles a vocabulary + structure cleanup landing in the
same PR: rename migrationId -> migrationHash, MigrationBundle ->
MigrationPackage, MigrationManifest -> MigrationMetadata, split the
dumping-ground types.ts into one file per concept, rename attestation.ts
-> hash.ts, and codemod the 113 on-disk migration.json files
(safe because computeMigrationHash strips the field before hashing).

Plan sequences integrity behavior (Phases 1-3) before rename + restructure
(Phases 4-6) so each phase has a clear review frame.
readMigrationPackage now performs hash verification after structural
validation and throws MIGRATION.BUNDLE_CORRUPT on mismatch. The
attestation primitive (verifyMigrationBundle) is reused, so the on-disk
load boundary is the single point where every consumer (CLI commands,
the future in-process apply path, the control client) inherits
package-integrity verification by construction.

readMigrationsDir inherits this transitively: any tampered child causes
the directory enumeration to throw with the offending dir path in
details.

The convenience wrapper verifyMigration(dir) is removed since it is now
strictly redundant with readMigrationPackage; verifyMigrationBundle
remains the public in-memory primitive with an unchanged shape (and the
storedMigrationId/computedMigrationId fields are tightened from
optional to required to reflect the runtime invariant).

Phase 1 of TML-2264. The CLI loop deletion in migration-apply.ts and
the JSDoc invariants on the runner SPI are deferred to Phase 2.

Refs TML-2264.
…ize bundle-corrupt path

Address review-round-1 code findings on TML-2264 Phase 1.

F01: Add `writeAttestedTestPackage(dir, manifestOverrides?, ops?)` helper
to `migration-tools/test/fixtures.ts`. The previous fixture API required
every caller to thread the same `ops` value through both `createTestManifest`
(which seeds the `migrationId` hash) and `writeMigrationPackage` (which writes
the file); forgetting to do so produced an internally inconsistent bundle that
the post-Phase-1 verifying loader correctly rejects with `MIGRATION.BUNDLE_CORRUPT`.
The new helper owns the threading, eliminating the silent foot-gun for happy-path
tests. Migrate happy-path call sites in `io.test.ts` to use it; tampering tests
keep the explicit two-step form because the corruption is the test`s point. Add
an analogous local `writeAttestedPackage` helper to `migration-e2e.test.ts`
(the CLI test cannot import `writeAttestedTestPackage` from migration-tools test
fixtures across packages).

F08: Render a `cwd`-relative path in the `errorBundleCorrupt` `why` and `fix`
template strings (via `pathe.relative(process.cwd(), dir)`), keeping the
absolute path in `details.dir` for machine consumers. Users typically run CLI
commands from the project root and expect short relative paths in diagnostics;
without this fix, post-Phase-2 (when the CLI loop is removed) `migration apply`
would surface the absolute path instead of the friendlier relative path the
existing CLI loop produces today. Extend the existing tampering tests in
`io.test.ts` to assert the relative path appears in `why` and `fix`, and that
`details.dir` is still the absolute path.

Refs TML-2264.
Address review-round-1 planning-artifact findings.

F02: Spec/plan now state explicitly that `MigrationOps` lives in `package.ts`
(alongside `MigrationPackage`) after the Phase 4 file split. A package contains
ops, so the type belongs with the package definition, not in `metadata.ts` (which
is about the manifest envelope) or a new `ops.ts`. Update spec § File layout +
Changes 7 and plan "Where we are going" diagram + Phase 4 T4.2.

F03: Spec § Non-functional requirements `Plane-clean` claim now acknowledges
the JSDoc-only ripple into `framework-components` (1-core) added by Phase 2 T2.2.
JSDoc-only changes do not introduce code-level cross-plane edges, but the prior
wording omitted the package entirely and was inaccurate as written.

F04: Plan now states explicitly that Phase 1 and Phase 2 must ship together as a
commit pair on `main`. The intermediate state ships double-verification (the
loader recomputes the hash; the still-present CLI loop also recomputes it) — the
duplicated work is wasted, and a future test asserting on the loop`s `errorRuntime`
shape vs. the loader`s `errorBundleCorrupt` shape would surface confusing
divergence. A grep verified no such test exists today; the constraint is recorded
proactively. Both Phase 1`s validation gate and Phase 2`s intro carry the note.

F06: Move T2.4 (audit other on-disk loaders) from Phase 2 to a new pre-flight
section before Phase 1. The audit verifies the spec`s load-bearing claim that
`readMigrationPackage` is the only on-disk loader; if a non-loader path
constructed a `MigrationPackage` from disk, Phase 1`s design would be insufficient.
Sequencing the audit as a gate aligns the plan structure with its assumption.

F07: Phase 3 T3.1-T3.4 still assert `MIGRATION.BUNDLE_CORRUPT` substring presence,
but the new T3.5 explicitly asserts diagnostic text equality across all four
commands (`expect(new Set(diagnosticTexts).size).toBe(1)`). Substring presence is
a necessary but not sufficient condition for the spec`s "same human-readable
diagnostic regardless of which command triggered the load" criterion — without
the equality check, two commands could both contain the code while differing on
the surrounding `why`/`fix` text. T3.6 and T3.7 are renumbered accordingly; the
test-coverage matrix is updated to point the uniformity AC at T3.5 and the
intact-package and lint:deps ACs at T3.6.

Refs TML-2264.
…ackage helper

Replace writeAttestedTestPackage / writeAttestedPackage with a single
writeTestPackage that always produces an attested package. Rewrite
tampering tests to call writeTestPackage then surgically overwrite the
offending file (ops.json or migration.json), eliminating the
inconsistent-fixture foot-gun (F01) and making each tampering case
self-document which file is being corrupted.

Also migrate migration-plan.test.ts away from the attestedManifest()
+ writeMigrationPackage() two-step foot-gun pattern by introducing a
local writeTestPackage helper there too. After this, every remaining
writeMigrationPackage test call site is either the helper definition
itself or io.test.ts:DIR_EXISTS asserting on the writer, exactly the
two cases that genuinely require the production utility.

Capture the cross-package test-helper consolidation as a Phase 4/6
follow-up in plan.md Open items (F10) — the duplication is now visible
across three files all naming the helper writeTestPackage.

Refs: TML-2264
readMigrationPackage performs hash verification at the load boundary
(Phase 1, commit 6aad313ff), so the per-bundle loop in
cli/src/commands/migration-apply.ts is now redundant. Delete the loop
and its verifyMigrationBundle import. Add JSDoc invariant notes on
MigrationRunner.execute and executeMigrationApply documenting that
their plan/pendingMigrations parameters are trusted input requiring
upstream verification (typically via readMigrationPackage).

Refs TML-2264 (Phase 2).
Phase 2's CLI loop deletion (commit f427fd6d3) made the "Defense in
depth" paragraph at cli/README.md:1038 stale. Capture the rewrite
explicitly under T6.2 so it doesn't fall through Phase 6's docs-refresh
mandate, which is currently scoped to migration-tools/README.md only.

Refs TML-2264.
Commit `bd19d89791` raised `timeouts.databaseOperation` on three flaky
`client.emit()` tests but missed `passes declared source inputs to the
provider`, which still uses the package-default 100ms timeout. Same
mechanism (CPU contention under `pnpm -r test`), same fix, applied to
the fourth site.

Surfaced during TML-2264 Phase 2 review (incorrectly diagnosed as a
filesystem-isolation issue; actually a timeout asymmetry).
Adds an integration test (`migration-tamper.test.ts`) that drives all four
CLI commands which load migration packages — `migration apply`, `migration
plan`, `migration status`, `migration show` — against a tampered fixture
(valid `writeTestPackage` followed by a surgical `fs.writeFile` that appends
a synthetic op to `ops.json`). Each command is asserted to surface
MIGRATION.BUNDLE_CORRUPT (T3.1-T3.4); a final assertion proves the four
user-visible diagnostic envelopes are byte-equal (T3.5), pinning the spec
acceptance criterion that integrity failures render the same human-readable
diagnostic regardless of which command triggered the load.

`migration show` exercises the `readMigrationPackage` direct-call path,
distinct from the `loadAllBundles`/`readMigrationsDir` path used by the
other three; both reach the same `errorBundleCorrupt` site, so the
uniformity assertion confirms both code paths converge on identical output.

Tempdir paths are normalized to a stable `<TMP_DIR>` token before
comparison so the four diagnostics are byte-equal across per-test fixture
directories.

Refs TML-2264 (Phase 3, T3.1-T3.5).
…yMigration

Phase 1 of TML-2264 (commit 6aad313ff) folded `verifyMigration(dir)` into
`readMigrationPackage`'s load boundary, but the
`migration-plan-details.e2e.test.ts` Journey H assertion still imported
the removed helper. Replace the call with `readMigrationPackage(pkgDir)`
— a successful read is now proof of attestation, since any tamper would
throw MIGRATION.BUNDLE_CORRUPT.

Surfaced by Phase 3 validation (`pnpm test:integration`); not caught
during Phase 1 because integration tests were not part of that phase's
validation gate.

Refs TML-2264 (Phase 1 follow-up).
Phase 3 T3.7 filed [TML-2316](https://linear.app/prisma-company/issue/TML-2316)
("Implement ADR 192 step 2: emit-drift detection for migration.ts") under
WS4 / M11. Replace the placeholder "file a separate Linear issue" line in
spec.md § Out of scope with the actual ticket reference, and add a matching
entry to § References.

Refs TML-2264 (Phase 3, T3.7).
Phase 3 review round 1 (F14) overrode the original deferral of the
`migration new` tamper case. The motivator: when the user asks to
*create* a new migration but the diagnostic surfaces an *existing*
corrupt package, that UX is confusing on its face and deserves an
explicit pin — not just by-construction coverage from T1.2 + the
unified diagnostic.

Add T3.8 as a 5th `it()` block in `migration-tamper.test.ts`,
between T3.4 and T3.5, following the same co-located pattern. The
test mounts the existing `setupTamperFixture`, drives
`createMigrationNewCommand` (which calls `readMigrationsDir` to
compute the `from` reference), and asserts non-zero exit +
`MIGRATION.BUNDLE_CORRUPT` substring. The capture flows into the
shared `diagnostics` collection so T3.5's set-equality assertion
(`expect(new Set(canonical).size).toBe(1)` and the rendered-text
twin) automatically extends to 5 commands. Bump the length
assertion `expect(diagnostics).toHaveLength(4)` → `5`.

`migration new` resolves the contract path off `config.contract.output`
with a different default than the other commands (`contract.json`
next to the config vs. `src/prisma/contract.json`); align the shared
`setupConfigMock` by setting `contract.output` explicitly. For the
other four tests this is a no-op (their resolver already lands on
the same path); for `migration new` it lets the contract read
succeed so the flow reaches `readMigrationsDir` where the integrity
check fires.

Schema-mock complexity surfaced as a separate finding: the bail-out
at `readMigrationsDir` happens *before* `migration new` reaches any
schema/planner work, so no extra mocking was needed beyond the
existing `loadConfig` mock plus the `contract.output` alignment.

The user-visible envelope shape (summary/code/why/fix/where) is
identical across all five commands; uniformity holds. The structured
`meta` payload still diverges — `migration apply`/`plan` carry
`error.details` into meta while `migration status`/`new` drop them.
That divergence is captured separately in the plan as a Phase 6
follow-up (F12 → T6.4) and does not affect T3.5 (which only checks
the user-visible portion).

All gates green:
- `pnpm -F @prisma-next/cli test test/commands/migration-tamper.test.ts`
  — 6 tests pass (5 tamper + 1 equality).
- `pnpm -F @prisma-next/cli test` — 531 tests pass.
- `pnpm test:integration` — 518 tests pass.
- `pnpm lint:deps` — 0 violations.

Refs TML-2264 (Phase 3, F14).
… 6 T6.4

Phase 3 review captured F15 (`migration new` defaults to a different
contract path than `migration apply / plan / status / show`) as a
follow-up. F12 (the `mapMigrationToolsError` extraction) already lived
in Phase 6 T6.4. Both touch the same two files
(`migration-status.ts`, `migration-new.ts`) and share the same "fold
inline code into the shared helper" pattern, so they land in one task.

This is a Phase 3 close-out artifact recorded in this branch but not
committed before Phase 4 began.
…d → package/metadata/migrationHash (TML-2264 Phase 4 T4.1-T4.6)

Lands T4.1-T4.6 of TML-2264 Phase 4 in one atomic commit. The original
plan suggested splitting per-task, but T4.2 (rename `MigrationBundle.manifest`
field → `metadata`) and T4.3 (rename `MigrationChainEntry.migrationId`
field → `migrationHash`) are field-level renames that the type system
cannot bridge with legacy aliases — so any intermediate "barrel keeps
old names alive" commit would still break compilation. The split
collapses to two commits: this atomic rename, then T4.7 (deletion of
the transitional `types.ts` barrel) as a follow-up.

Renames (TS surface only — wire format `migrationId` field remains
on-disk until Phase 5):

  Type renames
  - `MigrationManifest`        → `MigrationMetadata`
  - `MigrationBundle`          → `MigrationPackage`
  - `bundle.manifest`          → `pkg.metadata`
  - `MigrationChainEntry.migrationId` → `migrationHash`

  Function/file renames
  - `attestation.ts`           → `hash.ts` (via git mv)
  - `computeMigrationId`       → `computeMigrationHash`
  - `verifyMigrationBundle`    → `verifyMigrationHash`
  - `VerifyResult.{stored,computed}MigrationId` → `{stored,computed}Hash`
  - parameter names: `manifest` → `metadata`, `bundle` → `pkg`

  Error factory + code renames
  - `errorBundleCorrupt`         → `errorMigrationHashMismatch`
  - `MIGRATION.BUNDLE_CORRUPT`   → `MIGRATION.HASH_MISMATCH`
  - `errorDuplicateMigrationId`  → `errorDuplicateMigrationHash`
  - `MIGRATION.DUPLICATE_MIGRATION_ID` → `MIGRATION.DUPLICATE_MIGRATION_HASH`

  File splits (`types.ts` decomposed into per-concept files)
  - new `metadata.ts` — `MigrationMetadata`, `MigrationHints`
  - new `package.ts`  — `MigrationPackage`, `MigrationOps`
  - new `graph.ts`    — `MigrationGraph`, `MigrationChainEntry`

`types.ts` is left as a transitional barrel re-exporting all of the
above (and `MigrationToolsError` from `./errors`) so consumers that
still import from `@prisma-next/migration-tools/types` keep resolving
through the boundary; T4.7 deletes the barrel.

Wire-format coordination (constraint 4 of the orchestrator brief):
The on-disk `migration.json` files retain the `migrationId` field and
are codemoded in Phase 5. To keep the in-memory type renamed without
breaking the on-disk schema, `metadata.ts` introduces a wire shape
(`MigrationMetadataWire` with `migrationId`) and translation helpers
(`metadataFromWire` / `metadataToWire`). `io.ts` translates at the
read/write boundary; `migration-base.ts` translates inline when
re-emitting an existing manifest. The arktype schema in `io.ts` still
validates the on-disk wire shape (with `migrationId`), so the schema
and the in-memory type remain consistent across the rename — no
transient validation gap.

`MigrationMeta` (in `migration-base.ts`) is intentionally untouched
per Decision 7 / open question 3 — it is a different concept owned by
TML-2301.

CLI helpers (`loadMigrationBundles`, `loadAllBundles`,
`MigrationBundleSet`) keep their function/interface names — those
renames are Phase 6 T6.1. The types they reference are updated.

The structural-canonicalization rationale required by `spec.md §
Documentation home` lives as JSDoc on `computeMigrationHash` in
`hash.ts`.

Validation gates (all green):
- pnpm -F @prisma-next/migration-tools test ........ 175/175
- pnpm -F @prisma-next/cli test .................... 531/531
- pnpm typecheck ................................... 120/120 tasks
- pnpm test:integration ............................ 518/518

Per-symbol greps (`packages/ test/ examples/`): zero hits for
`MigrationManifest`, `verifyMigrationBundle`, `computeMigrationId`,
`errorBundleCorrupt`, `errorDuplicateMigrationId`,
`MIGRATION.BUNDLE_CORRUPT`, `MIGRATION.DUPLICATE_MIGRATION_ID`,
`bundle.manifest`. `MigrationBundle` hits remain only on the deferred
CLI helpers (T6.1). `migrationId` hits remain only in on-disk JSON
fixtures and integration tests that read the wire format directly via
`JSON.parse` (Phase 5 codemod scope).
…nToolsError` via `./errors` (TML-2264 Phase 4 T4.7)

Removes the transitional `types.ts` barrel introduced by the previous
commit and migrates the remaining `@prisma-next/migration-tools/types`
consumers to the per-concept subpaths (`./metadata`, `./package`,
`./graph`, plus a new `./errors` for `MigrationToolsError`).

`MigrationToolsError` does not belong to any of the three concept
files (metadata, package, graph) — it is cross-cutting. Per the plan
T4.7 deferral protocol on task ambiguity ("pick the most-spec-consistent
interpretation, document the choice"), this commit gives it its own
`./errors` subpath. `errors.ts` is already its own source file in the
package, so the subpath simply re-exports the existing module.

Changes:
- new `src/exports/errors.ts` re-exports `MigrationToolsError`.
- `package.json` exports: `./types` removed; `./errors` added.
  Final shape replaces the single `./types` barrel with four
  per-concept subpaths (`./metadata`, `./package`, `./graph`,
  `./errors`).
- `tsdown.config.ts`: drop `exports/types`; add `exports/errors`.
- `src/types.ts` and `src/exports/types.ts` deleted.
- All `MigrationToolsError` consumers (six CLI commands plus two
  test files) re-pointed at `@prisma-next/migration-tools/errors`.
- The lone `MigrationGraph` consumer
  (`graph-migration-mapper.ts`) re-pointed at
  `@prisma-next/migration-tools/graph`.
- `migration-tools/README.md` Export Subpaths table extended with
  the new `./errors` row.

Validation gates (all green):
- pnpm -F @prisma-next/migration-tools test ........ 175/175
- pnpm -F @prisma-next/cli test .................... 531/531
- pnpm typecheck ................................... 120/120 tasks
- pnpm test:integration ............................ 518/518

Per-symbol greps (`packages/ test/ examples/`): zero hits for
`@prisma-next/migration-tools/types`,
`@prisma-next/migration-tools/attestation`,
`MigrationManifest`, `verifyMigrationBundle`, `computeMigrationId`,
`errorBundleCorrupt`, `errorDuplicateMigrationId`,
`MIGRATION.BUNDLE_CORRUPT`, `MIGRATION.DUPLICATE_MIGRATION_ID`.
The remaining `MigrationBundle*` hits are CLI helper names
(`MigrationBundleSet`, `loadMigrationBundles`, `loadAllBundles`)
explicitly deferred to Phase 6 T6.1.

This concludes Phase 4 of TML-2264.
…-2264 Phase 6 T6.5

Phase 4 review (commit 4b67994b4) surfaced a public-API naming
inconsistency: MigrationGraph.migrationById retains the migrationId
fragment while the Map indexes by what is now called migrationHash.

Filed as F16 (low severity, naming consistency) in code-review.md and
recommended as a Phase 6 fold-in. User accepted option (b): new sibling
task T6.5 rather than expanding T6.1, on the rationale that T6.1 is
scoped to cli-package helpers while F16 lives in migration-tools — one
PR-review pass per package surface reads cleaner.

T6.5 covers ~12 mechanical sites across migration-tools graph.ts /
dag.ts / dag.test.ts and cli/test/utils/graph-helpers.ts. Bounded;
typecheck-validated; no behavioral impact.
TML-2301 merged into main during this PR's development and was
integrated via merge commit 39157ef76. Three spec/plan revisions follow
from the merge:

1. Architectural reframing (Decision 6, was "TML-2301 coordination").
   The original spec assumed Migration.run() would be an in-process
   apply orchestrator that loads MigrationPackages from disk. That
   assumption was wrong. TML-2301 landed MigrationCLI.run as a *write*
   path (regenerating packages from authored sources), not a read path.
   It reads migration.json only for scaffolding-context preservation
   (createdAt, fromContract, hints, labels) and never reads ops.json.
   It is structurally incapable of verifying hashes. Decision 6
   rewritten to record the resulting two-loader architectural split:
   verifying loader at apply-time read paths; non-verifying loader at
   author-time write paths. The split is sharper than the original
   spec sketched and is recorded as the durable architectural picture.

2. Open questions resolved. Q3 (rename MigrationMeta?) resolved
   against renaming — TML-2301 chose to keep MigrationMeta as the
   durable name for the user-authored describe() return type, and the
   two names (MigrationMeta vs MigrationMetadata) coexist by design.
   Q2 (errorMigrationHashMismatch export visibility) reworded to drop
   the stale Migration.run() reference; default unchanged.

3. Phase 5 scope expansion. Phase 4's wire-translator pattern
   (MigrationMetadataWire, metadataFromWire, metadataToWire) was
   load-bearing for the merge — TML-2301's pure-function refactor
   integrated cleanly *because* the translator pattern already
   existed. After Phase 5 renames the on-disk field, the translator
   becomes redundant and must be deleted. New T5.3 task added
   covering deletion across migration-base.ts:234, migration-cli.ts's
   readExistingMetadata, and metadata.ts's type+helper exports.
   Existing T5.3 (test suite) renumbered to T5.4; T5.4 (sanity check)
   to T5.5. Validation gate strengthened with translator-pattern
   audit greps.

Also: critical-risks section updated to record the merge resolution
(TML-2301 timing + rename conflicts both resolved), Coordination
collaborator entry marked resolved, and Open items list updated.

Process learning recorded for the orchestrator skill: post-merge
validation should include pnpm build (not just pnpm install) — stale
dist/*.mjs from pre-merge builds caused 16 spurious test failures on
first validation pass after the merge. Class-of-merge issue.
@wmadden
wmadden force-pushed the tml-2264-migration-runner-should-verify-migration-matches-its-hash branch from 5baddd5 to 58735fc Compare April 28, 2026 04:59

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/1-framework/3-tooling/cli/src/commands/migration-plan.ts (1)

165-205: ⚠️ Potential issue | 🟠 Major

Return a structured error if loading existing migrations fails.

A non-MigrationToolsError from loadAllMigrationPackages() is rethrown here, but the outer catch only starts at Line 257. That means fs/runtime failures in the migration-loading phase bypass handleResult() and crash the command instead of producing the standard CLI envelope.

Suggested fix
   } catch (error) {
     if (MigrationToolsError.is(error)) {
       return notOk(mapMigrationToolsError(error));
     }
-    throw error;
+    const message = error instanceof Error ? error.message : String(error);
+    return notOk(
+      errorUnexpected(message, {
+        why: `Unexpected error while loading migrations: ${message}`,
+      }),
+    );
   }

As per coding guidelines, "CLI commands must use structured errors (CliStructuredError), the Result pattern (performAction), and process.exit() for exit codes. Commands should never throw errors except for unhandled failures that fail fast."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/1-framework/3-tooling/cli/src/commands/migration-plan.ts` around
lines 165 - 205, The try/catch around loadAllMigrationPackages currently
rethrows non-MigrationToolsError errors which crashes the CLI; instead catch any
non-MigrationToolsError thrown by loadAllMigrationPackages and return a
structured CLI error using the existing Result pattern (e.g., call notOk with
errorRuntime or a CliStructuredError mapper) so the command returns a proper
Result envelope; update the catch to: if MigrationToolsError ->
mapMigrationToolsError as before, else convert the raw error into a runtime
CliStructuredError (include the error message in the why field) and return
notOk(...) rather than throwing; references: loadAllMigrationPackages,
MigrationToolsError, mapMigrationToolsError, notOk, errorRuntime.
🧹 Nitpick comments (4)
packages/1-framework/3-tooling/cli/test/migration-cli.test.ts (1)

229-248: Assert the rewritten migrationHash in this preservation case.

This fixture starts with migrationHash: null, but the test never checks the output hash after MigrationCLI.run(). A regression that preserves null would still pass here while producing a package that readMigrationPackage() now rejects. Add a sha256: assertion on the rewritten migration.json.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/1-framework/3-tooling/cli/test/migration-cli.test.ts` around lines
229 - 248, Test currently omits asserting that MigrationCLI.run rewrites
migrationHash from null to the expected sha256 value; update the test after
reading manifest (manifest = JSON.parse(...)) to assert manifest.migrationHash
equals the expected "sha256:..." string so regressions that leave it null will
fail. Locate the test block around MigrationCLI.run(...) and the manifest
variable and add an expectation for migrationHash to match the generated sha256
value.
packages/1-framework/3-tooling/cli/test/output.json-shapes.test.ts (1)

42-44: Assert the selectedPath entry shape directly.

These snapshots only cover the top-level pathDecision keys. If the JSON serializer drops migrationHash from selectedPath, this test still passes because the object is constructed locally from the TS type. Add a key assertion for result.pathDecision!.selectedPath[0]!.

Also applies to: 85-87

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/1-framework/3-tooling/cli/test/output.json-shapes.test.ts` around
lines 42 - 44, Add an explicit assertion that checks the shape of the
selectedPath entry rather than relying on the surrounding snapshot: assert
result.pathDecision!.selectedPath[0]! includes the keys dirName, migrationHash,
from, and to with expected values (e.g., { dirName: 'm1', migrationHash:
'sha256:mid', from: 'sha256:a', to: 'sha256:b' }) so the test fails if
migrationHash (or any field) is dropped; repeat the same explicit key assertion
for the corresponding case at lines 85-87.
test/integration/test/cli-journeys/mongo-migration.e2e.test.ts (1)

265-268: Keep the parsed manifest type aligned with the current schema.

migrationHash is now a required string on disk, so these string | null casts still model the old shape and weaken the test. Tightening both annotations to migrationHash: string makes this file catch nullable regressions instead of silently permitting them in the test type. As per coding guidelines, "Update tests to only test the current approach, removing test fixtures and examples that show old patterns."

Also applies to: 483-486

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/integration/test/cli-journeys/mongo-migration.e2e.test.ts` around lines
265 - 268, The parsed manifest type is still declared as migrationHash: string |
null which models the old nullable schema; update the type annotation on the
JSON.parse result so manifest is typed as { migrationHash: string } (change both
occurrences where the manifest variable is declared, e.g., the const manifest =
JSON.parse(...) as { migrationHash: string | null } lines) so the test fails if
migrationHash is ever null.
packages/1-framework/3-tooling/cli/src/utils/command-helpers.ts (1)

155-178: Finish the rename instead of keeping a same-behavior alias.

loadAllMigrationPackages() now just forwards to loadMigrationPackages(), and both surfaces still return bundles. That preserves the old vocabulary/API shape after the draft/attested split was removed, which makes the new MigrationPackage terminology harder to follow.

As per coding guidelines, "Do not add backward-compatibility shims, migration scaffolding, deprecation warnings, or comments explaining legacy vs. new approaches" and "Update all references immediately to use new approaches instead of maintaining parallel implementations."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/1-framework/3-tooling/cli/src/utils/command-helpers.ts` around lines
155 - 178, Remove the alias function loadAllMigrationPackages and fold callers
to use loadMigrationPackages directly; delete the loadAllMigrationPackages
implementation and the MigrationPackageSet indirection (if unused) and update
any references that call loadAllMigrationPackages to call
loadMigrationPackages(migrationsDir) and expect the { bundles, graph } result
shape from loadMigrationPackages; ensure imports/exports are updated to remove
loadAllMigrationPackages and adjust any types to reference the concrete return
shape or MigrationGraph/MigrationPackage types instead.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/1-framework/3-tooling/migration/src/errors.ts`:
- Around line 76-77: Update the remediation text for the invalid manifest error
so it lists migrationHash as a required field; locate the object with keys why
and fix (the invalid-manifest message) and modify the fix string to read
something like "Ensure migration.json has all required fields (from, to, kind,
toContract, migrationHash). If corrupt, delete and re-plan." so users are guided
to include migrationHash.

In `@packages/1-framework/3-tooling/migration/test/dag.test.ts`:
- Around line 28-37: The migrationHash is computed from a synthetic createdAt
value but the returned metadata keeps the original createdAt, causing package
inconsistency; update the flow in the helper so the metadata object used to
compute computeMigrationHash is the exact same metadata object returned (i.e.,
generate the synthetic createdAt once, assign it into metadata from
createTestMetadata before calling computeMigrationHash, then compute
migrationHash from that metadata and return metadata with migrationHash),
referencing metadata, createTestMetadata, computeMigrationHash, and
migrationHash to locate the change.

---

Outside diff comments:
In `@packages/1-framework/3-tooling/cli/src/commands/migration-plan.ts`:
- Around line 165-205: The try/catch around loadAllMigrationPackages currently
rethrows non-MigrationToolsError errors which crashes the CLI; instead catch any
non-MigrationToolsError thrown by loadAllMigrationPackages and return a
structured CLI error using the existing Result pattern (e.g., call notOk with
errorRuntime or a CliStructuredError mapper) so the command returns a proper
Result envelope; update the catch to: if MigrationToolsError ->
mapMigrationToolsError as before, else convert the raw error into a runtime
CliStructuredError (include the error message in the why field) and return
notOk(...) rather than throwing; references: loadAllMigrationPackages,
MigrationToolsError, mapMigrationToolsError, notOk, errorRuntime.

---

Nitpick comments:
In `@packages/1-framework/3-tooling/cli/src/utils/command-helpers.ts`:
- Around line 155-178: Remove the alias function loadAllMigrationPackages and
fold callers to use loadMigrationPackages directly; delete the
loadAllMigrationPackages implementation and the MigrationPackageSet indirection
(if unused) and update any references that call loadAllMigrationPackages to call
loadMigrationPackages(migrationsDir) and expect the { bundles, graph } result
shape from loadMigrationPackages; ensure imports/exports are updated to remove
loadAllMigrationPackages and adjust any types to reference the concrete return
shape or MigrationGraph/MigrationPackage types instead.

In `@packages/1-framework/3-tooling/cli/test/migration-cli.test.ts`:
- Around line 229-248: Test currently omits asserting that MigrationCLI.run
rewrites migrationHash from null to the expected sha256 value; update the test
after reading manifest (manifest = JSON.parse(...)) to assert
manifest.migrationHash equals the expected "sha256:..." string so regressions
that leave it null will fail. Locate the test block around MigrationCLI.run(...)
and the manifest variable and add an expectation for migrationHash to match the
generated sha256 value.

In `@packages/1-framework/3-tooling/cli/test/output.json-shapes.test.ts`:
- Around line 42-44: Add an explicit assertion that checks the shape of the
selectedPath entry rather than relying on the surrounding snapshot: assert
result.pathDecision!.selectedPath[0]! includes the keys dirName, migrationHash,
from, and to with expected values (e.g., { dirName: 'm1', migrationHash:
'sha256:mid', from: 'sha256:a', to: 'sha256:b' }) so the test fails if
migrationHash (or any field) is dropped; repeat the same explicit key assertion
for the corresponding case at lines 85-87.

In `@test/integration/test/cli-journeys/mongo-migration.e2e.test.ts`:
- Around line 265-268: The parsed manifest type is still declared as
migrationHash: string | null which models the old nullable schema; update the
type annotation on the JSON.parse result so manifest is typed as {
migrationHash: string } (change both occurrences where the manifest variable is
declared, e.g., the const manifest = JSON.parse(...) as { migrationHash: string
| null } lines) so the test fails if migrationHash is ever null.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 164cbd7c-7190-4292-8253-df7cec69e129

📥 Commits

Reviewing files that changed from the base of the PR and between 5baddd5 and 58735fc.

📒 Files selected for processing (176)
  • examples/mongo-demo/migrations/20260409T1030_migration/migration.json
  • examples/mongo-demo/migrations/20260415_add-posts-author-index/migration.json
  • examples/mongo-demo/test/manual-migration.test.ts
  • examples/prisma-next-demo/migration-fixtures/complex/20260301T1000_init/migration.json
  • examples/prisma-next-demo/migration-fixtures/complex/20260302T1000_alice_add_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/complex/20260302T1100_bob_add_avatar/migration.json
  • examples/prisma-next-demo/migration-fixtures/complex/20260302T1200_staging_posts/migration.json
  • examples/prisma-next-demo/migration-fixtures/complex/20260303T1000_merge_alice/migration.json
  • examples/prisma-next-demo/migration-fixtures/complex/20260303T1100_merge_bob/migration.json
  • examples/prisma-next-demo/migration-fixtures/complex/20260304T1000_add_comments/migration.json
  • examples/prisma-next-demo/migration-fixtures/complex/20260305T1000_add_tags/migration.json
  • examples/prisma-next-demo/migration-fixtures/converging-branches/20260301T1000_init/migration.json
  • examples/prisma-next-demo/migration-fixtures/converging-branches/20260302T1000_add_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/converging-branches/20260302T1100_add_posts/migration.json
  • examples/prisma-next-demo/migration-fixtures/converging-branches/20260302T1200_add_avatar/migration.json
  • examples/prisma-next-demo/migration-fixtures/converging-branches/20260303T1000_merge_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/converging-branches/20260303T1100_merge_posts/migration.json
  • examples/prisma-next-demo/migration-fixtures/converging-branches/20260303T1200_merge_avatar/migration.json
  • examples/prisma-next-demo/migration-fixtures/diamond-sub-branch/20260301T1000_init/migration.json
  • examples/prisma-next-demo/migration-fixtures/diamond-sub-branch/20260302T1000_alice_add_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/diamond-sub-branch/20260302T1100_bob_add_avatar/migration.json
  • examples/prisma-next-demo/migration-fixtures/diamond-sub-branch/20260302T1200_bob_experiment/migration.json
  • examples/prisma-next-demo/migration-fixtures/diamond-sub-branch/20260303T1000_merge_alice/migration.json
  • examples/prisma-next-demo/migration-fixtures/diamond-sub-branch/20260303T1100_merge_bob/migration.json
  • examples/prisma-next-demo/migration-fixtures/diamond-sub-branch/20260303T1200_bob_experiment_2/migration.json
  • examples/prisma-next-demo/migration-fixtures/diamond/20260301T1000_init/migration.json
  • examples/prisma-next-demo/migration-fixtures/diamond/20260302T1000_alice_add_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/diamond/20260302T1100_bob_add_avatar/migration.json
  • examples/prisma-next-demo/migration-fixtures/diamond/20260303T1000_merge_alice/migration.json
  • examples/prisma-next-demo/migration-fixtures/diamond/20260303T1100_merge_bob/migration.json
  • examples/prisma-next-demo/migration-fixtures/kitchen-sink/20260301T1000_init/migration.json
  • examples/prisma-next-demo/migration-fixtures/kitchen-sink/20260302T1000_add_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/kitchen-sink/20260302T1100_widen_email/migration.json
  • examples/prisma-next-demo/migration-fixtures/kitchen-sink/20260303T1000_email_default/migration.json
  • examples/prisma-next-demo/migration-fixtures/kitchen-sink/20260304T1000_change_default/migration.json
  • examples/prisma-next-demo/migration-fixtures/kitchen-sink/20260305T1000_add_posts/migration.json
  • examples/prisma-next-demo/migration-fixtures/kitchen-sink/20260306T1000_add_comments/migration.json
  • examples/prisma-next-demo/migration-fixtures/kitchen-sink/20260307T1000_kitchen_sink/migration.json
  • examples/prisma-next-demo/migration-fixtures/kitchen-sink/20260308T1000_rollback/migration.json
  • examples/prisma-next-demo/migration-fixtures/kitchen-sink/20260326T1428_migration/migration.json
  • examples/prisma-next-demo/migration-fixtures/linear/20260301T1000_init/migration.json
  • examples/prisma-next-demo/migration-fixtures/linear/20260302T1000_add_posts/migration.json
  • examples/prisma-next-demo/migration-fixtures/long-spine/20260301T1000_init/migration.json
  • examples/prisma-next-demo/migration-fixtures/long-spine/20260302T1000_add_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/long-spine/20260303T1000_add_bio/migration.json
  • examples/prisma-next-demo/migration-fixtures/long-spine/20260304T1000_add_posts/migration.json
  • examples/prisma-next-demo/migration-fixtures/long-spine/20260305T1000_add_avatar/migration.json
  • examples/prisma-next-demo/migration-fixtures/long-spine/20260306T1000_add_comments/migration.json
  • examples/prisma-next-demo/migration-fixtures/long-spine/20260307T1000_add_tags/migration.json
  • examples/prisma-next-demo/migration-fixtures/long-spine/20260307T1100_late_branch/migration.json
  • examples/prisma-next-demo/migration-fixtures/long-spine/20260308T1000_add_everything/migration.json
  • examples/prisma-next-demo/migration-fixtures/multi-branch/20260301T1000_init/migration.json
  • examples/prisma-next-demo/migration-fixtures/multi-branch/20260302T1000_add_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/multi-branch/20260302T1100_add_posts/migration.json
  • examples/prisma-next-demo/migration-fixtures/multi-branch/20260302T1200_add_avatar/migration.json
  • examples/prisma-next-demo/migration-fixtures/multi-branch/20260303T1000_add_bio/migration.json
  • examples/prisma-next-demo/migration-fixtures/multi-branch/20260326T1430_migration/migration.json
  • examples/prisma-next-demo/migration-fixtures/multi-branch/20260326T1431_foobar/migration.json
  • examples/prisma-next-demo/migration-fixtures/multi-branch/20260326T1431_migration/migration.json
  • examples/prisma-next-demo/migration-fixtures/multi-branch/20260326T1432_foobar/migration.json
  • examples/prisma-next-demo/migration-fixtures/multi-rollback-branch/20260301T1000_init/migration.json
  • examples/prisma-next-demo/migration-fixtures/multi-rollback-branch/20260302T1000_add_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/multi-rollback-branch/20260302T1100_staging/migration.json
  • examples/prisma-next-demo/migration-fixtures/multi-rollback-branch/20260303T1000_add_bio/migration.json
  • examples/prisma-next-demo/migration-fixtures/multi-rollback-branch/20260304T1000_add_comments/migration.json
  • examples/prisma-next-demo/migration-fixtures/multi-rollback-branch/20260305T1000_add_tags/migration.json
  • examples/prisma-next-demo/migration-fixtures/multi-rollback-branch/20260306T1000_rollback_to_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/rollback-continue/20260301T1000_init/migration.json
  • examples/prisma-next-demo/migration-fixtures/rollback-continue/20260302T1000_add_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/rollback-continue/20260303T1000_add_bio/migration.json
  • examples/prisma-next-demo/migration-fixtures/rollback-continue/20260304T1000_rollback_bio/migration.json
  • examples/prisma-next-demo/migration-fixtures/rollback-continue/20260305T1000_rollback_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/rollback-continue/20260306T1000_add_posts/migration.json
  • examples/prisma-next-demo/migration-fixtures/rollback/20260301T1000_init/migration.json
  • examples/prisma-next-demo/migration-fixtures/rollback/20260302T1000_add_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/rollback/20260303T1000_add_bio/migration.json
  • examples/prisma-next-demo/migration-fixtures/rollback/20260304T1000_rollback_bio/migration.json
  • examples/prisma-next-demo/migration-fixtures/rollback/20260305T1000_rollback_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260301T1000_init/migration.json
  • examples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260302T1000_alice_add_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260302T1100_bob_add_avatar/migration.json
  • examples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260303T1000_merge_1a/migration.json
  • examples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260303T1100_merge_1b/migration.json
  • examples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260304T1000_add_comments/migration.json
  • examples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260304T1100_add_posts_branch/migration.json
  • examples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260305T1000_merge_2a/migration.json
  • examples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260305T1100_merge_2b/migration.json
  • examples/prisma-next-demo/migration-fixtures/single-branch/20260301T1000_init/migration.json
  • examples/prisma-next-demo/migration-fixtures/single-branch/20260302T1000_add_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/single-branch/20260302T1100_add_posts/migration.json
  • examples/prisma-next-demo/migration-fixtures/single-branch/20260303T1000_add_bio/migration.json
  • examples/prisma-next-demo/migration-fixtures/skip-rollback/20260301T1000_init/migration.json
  • examples/prisma-next-demo/migration-fixtures/skip-rollback/20260302T1000_add_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/skip-rollback/20260303T1000_add_bio/migration.json
  • examples/prisma-next-demo/migration-fixtures/skip-rollback/20260304T1000_add_posts/migration.json
  • examples/prisma-next-demo/migration-fixtures/skip-rollback/20260305T1000_rollback_to_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/skip-rollback/20260306T1000_rollback_to_init/migration.json
  • examples/prisma-next-demo/migration-fixtures/sub-branches/20260301T1000_init/migration.json
  • examples/prisma-next-demo/migration-fixtures/sub-branches/20260302T1000_add_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/sub-branches/20260302T1100_add_posts/migration.json
  • examples/prisma-next-demo/migration-fixtures/sub-branches/20260303T1000_add_bio/migration.json
  • examples/prisma-next-demo/migration-fixtures/sub-branches/20260303T1100_add_avatar/migration.json
  • examples/prisma-next-demo/migration-fixtures/wide-fan/20260301T1000_init/migration.json
  • examples/prisma-next-demo/migration-fixtures/wide-fan/20260302T1000_add_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/wide-fan/20260302T1100_add_posts/migration.json
  • examples/prisma-next-demo/migration-fixtures/wide-fan/20260302T1200_add_avatar/migration.json
  • examples/prisma-next-demo/migration-fixtures/wide-fan/20260302T1300_add_category/migration.json
  • examples/prisma-next-demo/migration-fixtures/wide-fan/20260302T1400_add_settings/migration.json
  • examples/prisma-next-demo/migrations/20260422T0720_initial/migration.json
  • examples/prisma-next-demo/migrations/20260422T0742_migration/migration.json
  • examples/prisma-next-demo/migrations/20260422T0748_migration/migration.json
  • examples/retail-store/migrations/20260413T0314_migration/migration.json
  • examples/retail-store/migrations/20260415_add-product-validation/migration.json
  • examples/retail-store/migrations/20260416_backfill-product-status/migration.json
  • examples/retail-store/test/manual-migration.test.ts
  • packages/1-framework/1-core/framework-components/src/control-migration-types.ts
  • packages/1-framework/3-tooling/cli/README.md
  • packages/1-framework/3-tooling/cli/src/commands/migration-apply.ts
  • packages/1-framework/3-tooling/cli/src/commands/migration-new.ts
  • packages/1-framework/3-tooling/cli/src/commands/migration-plan.ts
  • packages/1-framework/3-tooling/cli/src/commands/migration-ref.ts
  • packages/1-framework/3-tooling/cli/src/commands/migration-show.ts
  • packages/1-framework/3-tooling/cli/src/commands/migration-status.ts
  • packages/1-framework/3-tooling/cli/src/control-api/operations/migration-apply.ts
  • packages/1-framework/3-tooling/cli/src/migration-cli.ts
  • packages/1-framework/3-tooling/cli/src/utils/cli-errors.ts
  • packages/1-framework/3-tooling/cli/src/utils/command-helpers.ts
  • packages/1-framework/3-tooling/cli/src/utils/formatters/graph-migration-mapper.ts
  • packages/1-framework/3-tooling/cli/src/utils/formatters/migrations.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-apply.test.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-e2e.test.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-plan-command.test.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-plan.test.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-ref-error-mapping.test.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-ref.test.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-show.test.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-tamper.test.ts
  • packages/1-framework/3-tooling/cli/test/control-api/client.test.ts
  • packages/1-framework/3-tooling/cli/test/migration-cli.test.ts
  • packages/1-framework/3-tooling/cli/test/output.json-shapes.test.ts
  • packages/1-framework/3-tooling/cli/test/utils/graph-helpers.ts
  • packages/1-framework/3-tooling/migration/README.md
  • packages/1-framework/3-tooling/migration/package.json
  • packages/1-framework/3-tooling/migration/src/attestation.ts
  • packages/1-framework/3-tooling/migration/src/dag.ts
  • packages/1-framework/3-tooling/migration/src/errors.ts
  • packages/1-framework/3-tooling/migration/src/exports/attestation.ts
  • packages/1-framework/3-tooling/migration/src/exports/errors.ts
  • packages/1-framework/3-tooling/migration/src/exports/graph.ts
  • packages/1-framework/3-tooling/migration/src/exports/hash.ts
  • packages/1-framework/3-tooling/migration/src/exports/io.ts
  • packages/1-framework/3-tooling/migration/src/exports/metadata.ts
  • packages/1-framework/3-tooling/migration/src/exports/package.ts
  • packages/1-framework/3-tooling/migration/src/exports/types.ts
  • packages/1-framework/3-tooling/migration/src/graph.ts
  • packages/1-framework/3-tooling/migration/src/hash.ts
  • packages/1-framework/3-tooling/migration/src/io.ts
  • packages/1-framework/3-tooling/migration/src/metadata.ts
  • packages/1-framework/3-tooling/migration/src/migration-base.ts
  • packages/1-framework/3-tooling/migration/src/package.ts
  • packages/1-framework/3-tooling/migration/src/types.ts
  • packages/1-framework/3-tooling/migration/test/attestation.test.ts
  • packages/1-framework/3-tooling/migration/test/dag.test.ts
  • packages/1-framework/3-tooling/migration/test/fixtures.ts
  • packages/1-framework/3-tooling/migration/test/hash.test.ts
  • packages/1-framework/3-tooling/migration/test/io.test.ts
  • packages/1-framework/3-tooling/migration/test/migration-base.test.ts
  • packages/1-framework/3-tooling/migration/tsdown.config.ts
  • packages/2-mongo-family/9-family/src/core/mongo-target-descriptor.ts
  • test/integration/test/cli-journeys/data-transform-enum-rebuild.e2e.test.ts
  • test/integration/test/cli-journeys/data-transform-not-null-backfill.e2e.test.ts
  • test/integration/test/cli-journeys/data-transform-nullable-tightening.e2e.test.ts
  • test/integration/test/cli-journeys/data-transform-type-change.e2e.test.ts
  • test/integration/test/cli-journeys/migration-plan-details.e2e.test.ts
  • test/integration/test/cli-journeys/mongo-migration.e2e.test.ts
  • test/integration/test/cli.migration-apply.e2e.test.ts
💤 Files with no reviewable changes (5)
  • packages/1-framework/3-tooling/migration/src/types.ts
  • packages/1-framework/3-tooling/migration/src/exports/attestation.ts
  • packages/1-framework/3-tooling/migration/src/attestation.ts
  • packages/1-framework/3-tooling/migration/test/attestation.test.ts
  • packages/1-framework/3-tooling/migration/src/exports/types.ts
✅ Files skipped from review due to trivial changes (122)
  • examples/prisma-next-demo/migration-fixtures/diamond/20260303T1100_merge_bob/migration.json
  • examples/prisma-next-demo/migration-fixtures/long-spine/20260308T1000_add_everything/migration.json
  • examples/prisma-next-demo/migration-fixtures/kitchen-sink/20260307T1000_kitchen_sink/migration.json
  • examples/prisma-next-demo/migration-fixtures/complex/20260303T1000_merge_alice/migration.json
  • examples/prisma-next-demo/migration-fixtures/linear/20260302T1000_add_posts/migration.json
  • examples/prisma-next-demo/migration-fixtures/diamond/20260302T1100_bob_add_avatar/migration.json
  • examples/prisma-next-demo/migration-fixtures/converging-branches/20260303T1000_merge_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/long-spine/20260305T1000_add_avatar/migration.json
  • examples/prisma-next-demo/migration-fixtures/multi-branch/20260326T1432_foobar/migration.json
  • examples/prisma-next-demo/migration-fixtures/diamond-sub-branch/20260303T1000_merge_alice/migration.json
  • examples/prisma-next-demo/migration-fixtures/converging-branches/20260302T1000_add_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/kitchen-sink/20260302T1000_add_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/rollback-continue/20260306T1000_add_posts/migration.json
  • examples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260301T1000_init/migration.json
  • examples/prisma-next-demo/migration-fixtures/diamond-sub-branch/20260302T1200_bob_experiment/migration.json
  • examples/prisma-next-demo/migration-fixtures/converging-branches/20260303T1100_merge_posts/migration.json
  • examples/prisma-next-demo/migration-fixtures/wide-fan/20260302T1200_add_avatar/migration.json
  • examples/prisma-next-demo/migration-fixtures/single-branch/20260302T1100_add_posts/migration.json
  • examples/prisma-next-demo/migration-fixtures/wide-fan/20260302T1400_add_settings/migration.json
  • examples/prisma-next-demo/migration-fixtures/skip-rollback/20260306T1000_rollback_to_init/migration.json
  • examples/prisma-next-demo/migration-fixtures/diamond-sub-branch/20260303T1100_merge_bob/migration.json
  • examples/prisma-next-demo/migration-fixtures/long-spine/20260306T1000_add_comments/migration.json
  • examples/mongo-demo/migrations/20260415_add-posts-author-index/migration.json
  • packages/1-framework/3-tooling/cli/src/utils/formatters/graph-migration-mapper.ts
  • examples/prisma-next-demo/migration-fixtures/complex/20260301T1000_init/migration.json
  • examples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260305T1100_merge_2b/migration.json
  • examples/prisma-next-demo/migration-fixtures/long-spine/20260303T1000_add_bio/migration.json
  • examples/prisma-next-demo/migration-fixtures/rollback/20260302T1000_add_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/sub-branches/20260301T1000_init/migration.json
  • examples/prisma-next-demo/migration-fixtures/complex/20260305T1000_add_tags/migration.json
  • examples/prisma-next-demo/migration-fixtures/kitchen-sink/20260303T1000_email_default/migration.json
  • examples/prisma-next-demo/migration-fixtures/diamond-sub-branch/20260301T1000_init/migration.json
  • examples/prisma-next-demo/migration-fixtures/wide-fan/20260301T1000_init/migration.json
  • examples/prisma-next-demo/migration-fixtures/diamond-sub-branch/20260302T1000_alice_add_phone/migration.json
  • packages/2-mongo-family/9-family/src/core/mongo-target-descriptor.ts
  • examples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260304T1100_add_posts_branch/migration.json
  • examples/prisma-next-demo/migration-fixtures/multi-branch/20260301T1000_init/migration.json
  • examples/prisma-next-demo/migration-fixtures/multi-branch/20260326T1430_migration/migration.json
  • examples/prisma-next-demo/migration-fixtures/rollback-continue/20260303T1000_add_bio/migration.json
  • examples/prisma-next-demo/migration-fixtures/skip-rollback/20260303T1000_add_bio/migration.json
  • examples/prisma-next-demo/migration-fixtures/multi-branch/20260302T1100_add_posts/migration.json
  • examples/prisma-next-demo/migration-fixtures/kitchen-sink/20260301T1000_init/migration.json
  • examples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260302T1100_bob_add_avatar/migration.json
  • examples/prisma-next-demo/migration-fixtures/kitchen-sink/20260302T1100_widen_email/migration.json
  • examples/prisma-next-demo/migration-fixtures/converging-branches/20260301T1000_init/migration.json
  • examples/prisma-next-demo/migration-fixtures/complex/20260304T1000_add_comments/migration.json
  • examples/prisma-next-demo/migration-fixtures/rollback/20260303T1000_add_bio/migration.json
  • examples/retail-store/test/manual-migration.test.ts
  • examples/prisma-next-demo/migrations/20260422T0720_initial/migration.json
  • examples/prisma-next-demo/migration-fixtures/multi-rollback-branch/20260305T1000_add_tags/migration.json
  • examples/prisma-next-demo/migration-fixtures/rollback-continue/20260305T1000_rollback_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/linear/20260301T1000_init/migration.json
  • examples/prisma-next-demo/migration-fixtures/sub-branches/20260303T1100_add_avatar/migration.json
  • examples/prisma-next-demo/migration-fixtures/complex/20260302T1000_alice_add_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260302T1000_alice_add_phone/migration.json
  • examples/retail-store/migrations/20260415_add-product-validation/migration.json
  • examples/prisma-next-demo/migration-fixtures/single-branch/20260303T1000_add_bio/migration.json
  • examples/prisma-next-demo/migration-fixtures/long-spine/20260307T1000_add_tags/migration.json
  • examples/prisma-next-demo/migration-fixtures/wide-fan/20260302T1100_add_posts/migration.json
  • packages/1-framework/3-tooling/migration/src/exports/graph.ts
  • examples/prisma-next-demo/migration-fixtures/rollback-continue/20260302T1000_add_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/multi-branch/20260326T1431_migration/migration.json
  • packages/1-framework/3-tooling/migration/src/exports/io.ts
  • examples/prisma-next-demo/migration-fixtures/kitchen-sink/20260306T1000_add_comments/migration.json
  • examples/prisma-next-demo/migration-fixtures/diamond-sub-branch/20260303T1200_bob_experiment_2/migration.json
  • examples/prisma-next-demo/migration-fixtures/sub-branches/20260303T1000_add_bio/migration.json
  • examples/prisma-next-demo/migration-fixtures/kitchen-sink/20260308T1000_rollback/migration.json
  • examples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260303T1000_merge_1a/migration.json
  • examples/prisma-next-demo/migration-fixtures/long-spine/20260301T1000_init/migration.json
  • examples/prisma-next-demo/migration-fixtures/multi-rollback-branch/20260306T1000_rollback_to_phone/migration.json
  • packages/1-framework/3-tooling/migration/src/exports/package.ts
  • examples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260303T1100_merge_1b/migration.json
  • examples/prisma-next-demo/migration-fixtures/skip-rollback/20260305T1000_rollback_to_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/multi-branch/20260302T1000_add_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/diamond/20260303T1000_merge_alice/migration.json
  • examples/mongo-demo/migrations/20260409T1030_migration/migration.json
  • examples/prisma-next-demo/migration-fixtures/rollback/20260305T1000_rollback_phone/migration.json
  • packages/1-framework/3-tooling/cli/src/control-api/operations/migration-apply.ts
  • examples/prisma-next-demo/migration-fixtures/multi-branch/20260326T1431_foobar/migration.json
  • examples/prisma-next-demo/migration-fixtures/long-spine/20260304T1000_add_posts/migration.json
  • examples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260304T1000_add_comments/migration.json
  • examples/prisma-next-demo/migrations/20260422T0742_migration/migration.json
  • examples/prisma-next-demo/migration-fixtures/multi-rollback-branch/20260304T1000_add_comments/migration.json
  • examples/prisma-next-demo/migration-fixtures/diamond/20260302T1000_alice_add_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/wide-fan/20260302T1300_add_category/migration.json
  • examples/prisma-next-demo/migration-fixtures/multi-rollback-branch/20260302T1100_staging/migration.json
  • examples/prisma-next-demo/migration-fixtures/sub-branches/20260302T1000_add_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/diamond/20260301T1000_init/migration.json
  • examples/retail-store/migrations/20260416_backfill-product-status/migration.json
  • test/integration/test/cli-journeys/data-transform-type-change.e2e.test.ts
  • examples/prisma-next-demo/migration-fixtures/single-branch/20260302T1000_add_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/rollback-continue/20260301T1000_init/migration.json
  • examples/prisma-next-demo/migration-fixtures/single-branch/20260301T1000_init/migration.json
  • packages/1-framework/1-core/framework-components/src/control-migration-types.ts
  • examples/prisma-next-demo/migration-fixtures/wide-fan/20260302T1000_add_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/kitchen-sink/20260305T1000_add_posts/migration.json
  • examples/prisma-next-demo/migration-fixtures/multi-branch/20260302T1200_add_avatar/migration.json
  • examples/prisma-next-demo/migration-fixtures/long-spine/20260307T1100_late_branch/migration.json
  • examples/prisma-next-demo/migration-fixtures/converging-branches/20260302T1200_add_avatar/migration.json
  • examples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260305T1000_merge_2a/migration.json
  • examples/prisma-next-demo/migration-fixtures/skip-rollback/20260301T1000_init/migration.json
  • examples/prisma-next-demo/migration-fixtures/sub-branches/20260302T1100_add_posts/migration.json
  • packages/1-framework/3-tooling/migration/src/exports/metadata.ts
  • examples/prisma-next-demo/migration-fixtures/multi-branch/20260303T1000_add_bio/migration.json
  • examples/prisma-next-demo/migration-fixtures/rollback-continue/20260304T1000_rollback_bio/migration.json
  • examples/prisma-next-demo/migration-fixtures/complex/20260303T1100_merge_bob/migration.json
  • packages/1-framework/3-tooling/cli/test/control-api/client.test.ts
  • examples/prisma-next-demo/migration-fixtures/multi-rollback-branch/20260301T1000_init/migration.json
  • examples/prisma-next-demo/migration-fixtures/rollback/20260301T1000_init/migration.json
  • examples/prisma-next-demo/migration-fixtures/diamond-sub-branch/20260302T1100_bob_add_avatar/migration.json
  • packages/1-framework/3-tooling/migration/src/metadata.ts
  • examples/prisma-next-demo/migration-fixtures/long-spine/20260302T1000_add_phone/migration.json
  • packages/1-framework/3-tooling/migration/src/graph.ts
  • examples/prisma-next-demo/migration-fixtures/skip-rollback/20260302T1000_add_phone/migration.json
  • examples/prisma-next-demo/migration-fixtures/rollback/20260304T1000_rollback_bio/migration.json
  • examples/prisma-next-demo/migration-fixtures/kitchen-sink/20260326T1428_migration/migration.json
  • examples/prisma-next-demo/migration-fixtures/complex/20260302T1200_staging_posts/migration.json
  • examples/prisma-next-demo/migration-fixtures/converging-branches/20260302T1100_add_posts/migration.json
  • examples/prisma-next-demo/migration-fixtures/multi-rollback-branch/20260302T1000_add_phone/migration.json
  • examples/retail-store/migrations/20260413T0314_migration/migration.json
  • examples/prisma-next-demo/migrations/20260422T0748_migration/migration.json
  • examples/prisma-next-demo/migration-fixtures/kitchen-sink/20260304T1000_change_default/migration.json
🚧 Files skipped from review as they are similar to previous changes (21)
  • examples/prisma-next-demo/migration-fixtures/converging-branches/20260303T1200_merge_avatar/migration.json
  • examples/prisma-next-demo/migration-fixtures/skip-rollback/20260304T1000_add_posts/migration.json
  • packages/1-framework/3-tooling/migration/src/exports/errors.ts
  • examples/prisma-next-demo/migration-fixtures/multi-rollback-branch/20260303T1000_add_bio/migration.json
  • examples/prisma-next-demo/migration-fixtures/complex/20260302T1100_bob_add_avatar/migration.json
  • test/integration/test/cli-journeys/data-transform-nullable-tightening.e2e.test.ts
  • packages/1-framework/3-tooling/cli/src/utils/formatters/migrations.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-tamper.test.ts
  • test/integration/test/cli-journeys/data-transform-enum-rebuild.e2e.test.ts
  • packages/1-framework/3-tooling/migration/test/hash.test.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-ref-error-mapping.test.ts
  • test/integration/test/cli-journeys/data-transform-not-null-backfill.e2e.test.ts
  • packages/1-framework/3-tooling/migration/src/exports/hash.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-ref.test.ts
  • packages/1-framework/3-tooling/migration/tsdown.config.ts
  • packages/1-framework/3-tooling/cli/src/commands/migration-status.ts
  • packages/1-framework/3-tooling/cli/README.md
  • packages/1-framework/3-tooling/cli/test/commands/migration-plan-command.test.ts
  • packages/1-framework/3-tooling/cli/src/migration-cli.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-plan.test.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-show.test.ts

wmadden added 6 commits April 28, 2026 07:20
`MIGRATION.FILE_MISSING`, `MIGRATION.INVALID_JSON`, `MIGRATION.INVALID_MANIFEST`,
and `MIGRATION.SAME_SOURCE_AND_TARGET` previously instructed users to delete the
directory and re-run `migration plan`. That is the wrong primitive — `migration plan`
emits a *new* package, while every existing package can self-emit by running its
author-time `migration.ts`, regenerating `migration.json` and `ops.json` with the
correct hash + metadata. Mirror the existing `MIGRATION.HASH_MISMATCH` wording
via a shared `reemitHint(dir, fallback)` helper. `errorSameSourceAndTarget`
now takes the package `dirPath` so it can render the same cwd-relative hint;
`dag.ts` updated accordingly.

Addresses CodeRabbit thread on `errorInvalidManifest`
(#384 (comment)) and the
operator’s broader directive to standardise migration-tools remediation wording.
Previously the dag.test.ts `pkg()` helper computed `migrationHash` from a
synthetic `createdAt` (with the per-pkg counter appended) but returned metadata
with the original `createdAt`. Each fixture package was therefore internally
inconsistent and could never round-trip through `readMigrationPackage()`.

Bake the counter into the metadata `createdAt` once and hash that exact metadata,
so fixtures are loader-safe and would catch hash-verification regressions.

Addresses CodeRabbit thread
#384 (comment).
…lure (A12a)

`migration plan` previously rethrew non-`MigrationToolsError` exceptions from
the migration-load phase, bypassing `handleResult()` and crashing the command.
Wrap such failures in `errorUnexpected(...)` so the user sees the same
structured CLI envelope (Result pattern) as every other failure path.

Addresses CodeRabbit review-body finding
#384 (review)
(migration-plan.ts ~165-205, outside-diff major).
…t contract hash) (A11)

The JSDoc on `resolveBundleByPrefix` said "exact hash or prefix match" without
specifying which hash. The implementation matches `metadata.to` (the contract
hash a migration produces), not `metadata.migrationHash` (the package's
content-addressed identity). Tighten wording so future maintainers do not
mistakenly switch the resolver to migrationHash semantics.

Addresses CodeRabbit nitpick
#384 (review).
…12b, A12c, A12d)

Three small assertion tightenings flagged by CodeRabbit on the migrationHash
contract — each one currently a silent gap that would let a real regression
slip through:

- migration-cli.test.ts `preserves contract bookends`: assert that
  `migrationHash` is rewritten from on-disk `null` to a real `sha256:...`
  digest. Without this assertion, MigrationCLI.run could silently keep the
  null and produce a package readMigrationPackage() rejects.
- output.json-shapes.test.ts pathDecision blocks: assert `selectedPath[0]`
  shape directly (dirName / migrationHash / from / to). The surrounding
  Object.keys snapshot only covered top-level pathDecision keys, so dropping
  `migrationHash` from the wire shape would not have failed.
- mongo-migration.e2e.test.ts manifest casts: tighten from
  `{ migrationHash: string | null }` to `{ migrationHash: string }` so
  ever producing `null` on disk fails type-checking.

Addresses three nitpicks from CodeRabbit review
#384 (review).
…geSet (A12e)

`loadAllMigrationPackages` was a same-behaviour wrapper around
`loadMigrationPackages`, retained only for naming clarity from the era when
the CLI distinguished attested and draft package sets. The draft state was
removed earlier in this PR — the alias now just preserves stale vocabulary
and breaks the "no backward-compat shims" guideline.

Inline the alias and the `MigrationPackageSet` type at the three callers
(`migration plan` / `migration apply` / `migration status`); update mocks
and explanatory comments in `migration-plan-command.test.ts` and
`migration-tamper.test.ts`. The single `MigrationPackageSet` user
(`migration-apply.ts`) now uses
`Awaited<ReturnType<typeof loadMigrationPackages>>` directly so the
return shape stays in one place.

Addresses CodeRabbit nitpick
#384 (review)
(command-helpers.ts ~155-178).
@wmadden

wmadden commented Apr 28, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the second review pass @coderabbitai — addressed the review-body findings (PRR_kwDOQM0QJc75S_qP and PRR_kwDOQM0QJc75gWAF) below. Each item was committed individually so the diffs are easy to scan.

migration-plan.ts — resolveBundleByPrefix JSDoc clarifies "target contract hash"

Tightened wording to explicitly say the resolver matches metadata.to (target contract hash), not metadata.migrationHash — 153d74e.

migration-plan.ts — structured envelope on unexpected load failure (outside-diff major)

Wrapped non-MigrationToolsError exceptions from loadMigrationPackages() in errorUnexpected(...) so the failure flows through handleResult() instead of crashing the command — a5d8a4b.

Test tightenings

  • migration-cli.test.ts preserves contract bookends now asserts the rewritten migrationHash is sha256:... — would fail if MigrationCLI.run ever leaves the on-disk null in place.
  • output.json-shapes.test.ts pinned the selectedPath[0] shape directly (dirName / migrationHash / from / to) — would fail if a field is dropped from the wire shape.
  • mongo-migration.e2e.test.ts cast tightened to { migrationHash: string }, so emitting null on disk would fail type-check.

All three in aea2bd7.

command-helpers.ts — drop loadAllMigrationPackages alias and MigrationPackageSet indirection

Inlined the alias at the three callers (migration plan / migration apply / migration status); migration-apply.ts uses Awaited<ReturnType<typeof loadMigrationPackages>> so the return shape stays in one place. Mocks and explanatory comments updated. Aligns with the no-backward-compat-shims guideline. — be2d0d9.

Out of scope

I did not address migration-status.ts assignedKeys edge-identity (the only outside-diff finding from R1) — already declined as out-of-scope in #384 (comment). The collision risk for parallel migrations sharing identical (from,to) is preexisting (renamed-but-otherwise-untouched code) and not within this PR's scope of hash-integrity verification at the load boundary.

CLI tests stay green (757/757), migration-tools tests stay green (195/195), typecheck clean.

@coderabbitai

coderabbitai Bot commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

@wmadden — clean sweep across the board. Quick acknowledgement of each:

  • resolveBundleByPrefix JSDoc (153d74e) — "target contract hash" is exactly the right label; no ambiguity left between metadata.to and metadata.migrationHash.

  • Structured envelope on unexpected load failure (a5d8a4b) — errorUnexpected(...) wrapping closes the crash-on-unexpected-error path cleanly; handleResult() now owns all failure rendering uniformly.

  • Test tightenings (aea2bd7) — the three additions are good regression anchors: the sha256: format assertion on migrationHash, the pinned selectedPath[0] wire shape, and the tightened cast in the e2e test collectively make silent regressions on the on-disk contract much harder.

  • loadAllMigrationPackages alias dropped (be2d0d9) — inlining at the three callers and using Awaited<ReturnType<typeof loadMigrationPackages>> for the return shape is the right call; one source of truth, no shim layer.

  • migration-status.ts out-of-scope — already settled; no further action needed here.

All findings resolved, tests green, typecheck clean — this looks good to me.

[approve]

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (4)
packages/1-framework/3-tooling/cli/test/migration-cli.test.ts (1)

249-252: Assert the rewritten hash is valid, not just prefixed.

Line 252 only checks ^sha256:, so this test still passes if MigrationCLI.run writes any hash-looking placeholder. Since the comment explicitly ties this to loader acceptance, it would be stronger to recompute the expected hash from migration.json + ops.json (or round-trip through readMigrationPackage()) and assert equality here.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/1-framework/3-tooling/cli/test/migration-cli.test.ts` around lines
249 - 252, The test currently only checks that manifest.migrationHash starts
with "sha256:", which is weak; change it to compute the actual expected digest
and assert equality: after running MigrationCLI.run, either call
readMigrationPackage() on the generated package to obtain the normalized
migration hash or recompute the sha256 over the exact inputs (migration.json +
ops.json) the loader uses, then replace the toMatch assertion with
expect(manifest.migrationHash).toBe(expectedHash) so the test verifies the real
digest produced by MigrationCLI.run rather than just the prefix.
packages/1-framework/3-tooling/cli/src/utils/command-helpers.ts (1)

148-161: Finish the bundle → package rename in this helper API.

loadMigrationPackages() now returns MigrationPackage[], but the public property is still called bundles. That keeps the old vocabulary alive in every caller (migrations.bundles, statusResult.bundles) even though this PR is otherwise standardizing on “package”. Renaming the property here would make the migration/package split much clearer going forward.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/1-framework/3-tooling/cli/src/utils/command-helpers.ts` around lines
148 - 161, The public return property "bundles" still uses the old name; update
loadMigrationPackages to return "packages" instead. Rename the local variable
bundles (result of readMigrationsDir) to packages, keep using
reconstructGraph(packages) (or pass the same variable name), and change the
Promise return type from { bundles: readonly MigrationPackage[]; graph:
MigrationGraph } to { packages: readonly MigrationPackage[]; graph:
MigrationGraph } and return { packages, graph } so callers can use
migrations.packages instead of migrations.bundles.
packages/1-framework/3-tooling/cli/test/commands/migration-tamper.test.ts (1)

210-215: Avoid making the uniformity check depend on prior tests' side effects.

The module-scoped diagnostics array makes T3.5 order-dependent: if someone runs only that test, or if this file is re-used with persistent module state, expect(diagnostics).toHaveLength(5) fails before any CLI behavior is exercised. Collecting the five captures inside T3.5 itself (or in a local beforeAll) would keep the uniformity assertion deterministic and self-contained.

Also applies to: 395-439

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/1-framework/3-tooling/cli/test/commands/migration-tamper.test.ts`
around lines 210 - 215, The module-scoped diagnostics array causes
order-dependent failures; remove the top-level const diagnostics and instead
declare and populate a local diagnostics array inside the specific uniformity
test (the describe block "migration tamper diagnostic uniformity (T3.1-T3.5,
T3.8)") or in a beforeAll scoped to that describe so the expectation
expect(diagnostics).toHaveLength(5) in test T3.5 always observes exactly the
five captures after invoking the CLI behavior; update the places that push into
diagnostics to use this local variable (also apply the same fix for the
analogous code around the 395-439 region).
packages/1-framework/3-tooling/cli/test/commands/migration-plan-command.test.ts (1)

219-228: Assert the new migrationHash write path directly.

These checks prove the CLI result shape, but they do not pin the new behavior that writeMigrationPackage() receives a computed metadata.migrationHash. A regression in the package write path would still pass here as long as the JSON envelope stayed unchanged.

🧪 Suggested assertion
       expect(result).toMatchObject({
         ok: true,
         noOp: false,
         from: OLD_HASH,
         to: NEW_HASH,
         operations: [
           { id: 'table.user', label: 'Create table "user"', operationClass: 'additive' },
         ],
       });
       expect(result).not.toHaveProperty('migrationHash');
+      expect(mocks.writeMigrationPackage).toHaveBeenCalledWith(
+        expect.any(String),
+        expect.objectContaining({
+          from: OLD_HASH,
+          to: NEW_HASH,
+          migrationHash: expect.stringMatching(/^sha256:/),
+        }),
+        expect.any(Array),
+      );

I’d mirror the same assertion once in a placeholder case too, so both the real-ops and [] hash paths stay covered.

Also applies to: 299-305

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@packages/1-framework/3-tooling/cli/test/commands/migration-plan-command.test.ts`
around lines 219 - 228, The test currently asserts the CLI result shape but
doesn't verify that writeMigrationPackage was called with a computed
metadata.migrationHash; update the test to spy/mock writeMigrationPackage (the
existing spy used in this file) and add an assertion that the mock was called
with a metadata object containing migrationHash equal to the expected computed
hash for the real-ops case (the same value you expect from OLD_HASH -> NEW_HASH
run), and add the analogous assertion in the placeholder/empty-operations test
case to ensure writeMigrationPackage was called with the placeholder
migrationHash; refer to the writeMigrationPackage spy and the result object in
the assertions so the package write path is directly validated.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/1-framework/3-tooling/migration/test/dag.test.ts`:
- Around line 28-35: The helper currently appends `-<migrationCounter>` to
`createdAt` (producing values like `2026-02-25T14:00:00.000Z-0`) which breaks
loader-valid timestamp shape; instead keep `metadata.createdAt` a valid ISO
timestamp while still introducing per-package uniqueness for hashing: compute a
separate unique salt (e.g., `hashSalt = \`-${migrationCounter++}\``) and pass
the original `createdAt` into `createTestMetadata`, but include the `hashSalt`
when calling `computeMigrationHash(metadata, ops, hashSalt)` (or combine salt
into the hash input) so `uniqueCreatedAt` is not stored in metadata but the hash
remains per-package unique; update references to `uniqueCreatedAt`/`createdAt`
accordingly and ensure `readMigrationPackage()` can round-trip.

---

Nitpick comments:
In `@packages/1-framework/3-tooling/cli/src/utils/command-helpers.ts`:
- Around line 148-161: The public return property "bundles" still uses the old
name; update loadMigrationPackages to return "packages" instead. Rename the
local variable bundles (result of readMigrationsDir) to packages, keep using
reconstructGraph(packages) (or pass the same variable name), and change the
Promise return type from { bundles: readonly MigrationPackage[]; graph:
MigrationGraph } to { packages: readonly MigrationPackage[]; graph:
MigrationGraph } and return { packages, graph } so callers can use
migrations.packages instead of migrations.bundles.

In
`@packages/1-framework/3-tooling/cli/test/commands/migration-plan-command.test.ts`:
- Around line 219-228: The test currently asserts the CLI result shape but
doesn't verify that writeMigrationPackage was called with a computed
metadata.migrationHash; update the test to spy/mock writeMigrationPackage (the
existing spy used in this file) and add an assertion that the mock was called
with a metadata object containing migrationHash equal to the expected computed
hash for the real-ops case (the same value you expect from OLD_HASH -> NEW_HASH
run), and add the analogous assertion in the placeholder/empty-operations test
case to ensure writeMigrationPackage was called with the placeholder
migrationHash; refer to the writeMigrationPackage spy and the result object in
the assertions so the package write path is directly validated.

In `@packages/1-framework/3-tooling/cli/test/commands/migration-tamper.test.ts`:
- Around line 210-215: The module-scoped diagnostics array causes
order-dependent failures; remove the top-level const diagnostics and instead
declare and populate a local diagnostics array inside the specific uniformity
test (the describe block "migration tamper diagnostic uniformity (T3.1-T3.5,
T3.8)") or in a beforeAll scoped to that describe so the expectation
expect(diagnostics).toHaveLength(5) in test T3.5 always observes exactly the
five captures after invoking the CLI behavior; update the places that push into
diagnostics to use this local variable (also apply the same fix for the
analogous code around the 395-439 region).

In `@packages/1-framework/3-tooling/cli/test/migration-cli.test.ts`:
- Around line 249-252: The test currently only checks that
manifest.migrationHash starts with "sha256:", which is weak; change it to
compute the actual expected digest and assert equality: after running
MigrationCLI.run, either call readMigrationPackage() on the generated package to
obtain the normalized migration hash or recompute the sha256 over the exact
inputs (migration.json + ops.json) the loader uses, then replace the toMatch
assertion with expect(manifest.migrationHash).toBe(expectedHash) so the test
verifies the real digest produced by MigrationCLI.run rather than just the
prefix.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 4225fe01-3830-4204-a5fe-cc3fef928135

📥 Commits

Reviewing files that changed from the base of the PR and between 58735fc and be2d0d9.

📒 Files selected for processing (12)
  • packages/1-framework/3-tooling/cli/src/commands/migration-apply.ts
  • packages/1-framework/3-tooling/cli/src/commands/migration-plan.ts
  • packages/1-framework/3-tooling/cli/src/commands/migration-status.ts
  • packages/1-framework/3-tooling/cli/src/utils/command-helpers.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-plan-command.test.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-tamper.test.ts
  • packages/1-framework/3-tooling/cli/test/migration-cli.test.ts
  • packages/1-framework/3-tooling/cli/test/output.json-shapes.test.ts
  • packages/1-framework/3-tooling/migration/src/dag.ts
  • packages/1-framework/3-tooling/migration/src/errors.ts
  • packages/1-framework/3-tooling/migration/test/dag.test.ts
  • test/integration/test/cli-journeys/mongo-migration.e2e.test.ts
✅ Files skipped from review due to trivial changes (1)
  • test/integration/test/cli-journeys/mongo-migration.e2e.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/1-framework/3-tooling/migration/src/errors.ts

Comment on lines +28 to +35
// Bake a per-pkg counter into createdAt so distinct packages get distinct
// hashes — and use the same metadata for both hashing and the returned
// package, so each fixture is internally consistent (round-trips through
// readMigrationPackage()).
const uniqueCreatedAt = `${createdAt}-${migrationCounter++}`;
const metadata = createTestMetadata({ from, to, createdAt: uniqueCreatedAt, labels });
const ops = createTestOps();
const migrationId = computeMigrationId(
{ ...manifest, createdAt: `${createdAt}-${migrationCounter++}` },
ops,
);
const migrationHash = computeMigrationHash(metadata, ops);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Keep fixture createdAt loader-valid.

Line 32 now produces values like 2026-02-25T14:00:00.000Z-0, so these fixtures no longer have a timestamp shape that can round-trip through the same loader path the comment describes. That weakens the “loader-safe fixture” guarantee this helper is trying to preserve.

Suggested fix
-  const uniqueCreatedAt = `${createdAt}-${migrationCounter++}`;
+  const uniqueCreatedAt = new Date(
+    Date.parse(createdAt) + migrationCounter++,
+  ).toISOString();
   const metadata = createTestMetadata({ from, to, createdAt: uniqueCreatedAt, labels });
   const ops = createTestOps();
   const migrationHash = computeMigrationHash(metadata, ops);

Based on learnings: "Returned metadata.createdAt and the hashed createdAt now match, so each fixture is internally consistent and could round-trip through readMigrationPackage()."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/1-framework/3-tooling/migration/test/dag.test.ts` around lines 28 -
35, The helper currently appends `-<migrationCounter>` to `createdAt` (producing
values like `2026-02-25T14:00:00.000Z-0`) which breaks loader-valid timestamp
shape; instead keep `metadata.createdAt` a valid ISO timestamp while still
introducing per-package uniqueness for hashing: compute a separate unique salt
(e.g., `hashSalt = \`-${migrationCounter++}\``) and pass the original
`createdAt` into `createTestMetadata`, but include the `hashSalt` when calling
`computeMigrationHash(metadata, ops, hashSalt)` (or combine salt into the hash
input) so `uniqueCreatedAt` is not stored in metadata but the hash remains
per-package unique; update references to `uniqueCreatedAt`/`createdAt`
accordingly and ensure `readMigrationPackage()` can round-trip.

@wmadden
wmadden merged commit b6bfc7d into main Apr 28, 2026
15 checks passed
wmadden added a commit that referenced this pull request Apr 28, 2026
When `migration plan` succeeds without placeholders, `writeMigrationPackage`
has already emitted ops.json + migration.json with a fully attested
migrationHash, so the previous `Next: node <dir>/migration.ts to emit ops.json
and attest migrationHash before running prisma-next migration apply` instruction
was actively misleading: it told the user to repeat work the planner had
already done. Replace with a direct pointer at `prisma-next migration apply`.

The placeholder branch keeps its existing `Then run: node <dir>/migration.ts`
instruction, which is correct (placeholders genuinely require a self-emit
round-trip).

Addresses CodeRabbit review on PR #384.
wmadden added a commit that referenced this pull request Apr 28, 2026
…lpers

createAttestedPackage and writeTestPackage are documented to always produce
internally-consistent (attested) packages — the migrationHash is computed
over the exact (metadata, ops) that get returned/written. The
metadataOverrides parameter was typed Partial<MigrationMetadata>, which let
callers smuggle a custom migrationHash past createTestMetadata's
`overrides.migrationHash ?? computeMigrationHash(...)` fallback and produce
an inconsistent fixture without going through the explicit post-write tamper
step the helpers are designed for.

Tighten the override type to Omit<Partial<MigrationMetadata>, 'migrationHash'>
on both helpers so accidental hash injection becomes a compile error.
createTestMetadata stays as-is — hash.test.ts intentionally injects a
migrationHash to verify computeMigrationHash ignores the existing field.

Addresses CodeRabbit review on PR #384 (review body, fixtures.ts:49-58 + 85-91).
wmadden added a commit that referenced this pull request Apr 28, 2026
`MIGRATION.FILE_MISSING`, `MIGRATION.INVALID_JSON`, `MIGRATION.INVALID_MANIFEST`,
and `MIGRATION.SAME_SOURCE_AND_TARGET` previously instructed users to delete the
directory and re-run `migration plan`. That is the wrong primitive — `migration plan`
emits a *new* package, while every existing package can self-emit by running its
author-time `migration.ts`, regenerating `migration.json` and `ops.json` with the
correct hash + metadata. Mirror the existing `MIGRATION.HASH_MISMATCH` wording
via a shared `reemitHint(dir, fallback)` helper. `errorSameSourceAndTarget`
now takes the package `dirPath` so it can render the same cwd-relative hint;
`dag.ts` updated accordingly.

Addresses CodeRabbit thread on `errorInvalidManifest`
(#384 (comment)) and the
operator’s broader directive to standardise migration-tools remediation wording.
wmadden added a commit that referenced this pull request Apr 28, 2026
Previously the dag.test.ts `pkg()` helper computed `migrationHash` from a
synthetic `createdAt` (with the per-pkg counter appended) but returned metadata
with the original `createdAt`. Each fixture package was therefore internally
inconsistent and could never round-trip through `readMigrationPackage()`.

Bake the counter into the metadata `createdAt` once and hash that exact metadata,
so fixtures are loader-safe and would catch hash-verification regressions.

Addresses CodeRabbit thread
#384 (comment).
wmadden added a commit that referenced this pull request Apr 28, 2026
…lure (A12a)

`migration plan` previously rethrew non-`MigrationToolsError` exceptions from
the migration-load phase, bypassing `handleResult()` and crashing the command.
Wrap such failures in `errorUnexpected(...)` so the user sees the same
structured CLI envelope (Result pattern) as every other failure path.

Addresses CodeRabbit review-body finding
#384 (review)
(migration-plan.ts ~165-205, outside-diff major).
wmadden added a commit that referenced this pull request Apr 28, 2026
…t contract hash) (A11)

The JSDoc on `resolveBundleByPrefix` said "exact hash or prefix match" without
specifying which hash. The implementation matches `metadata.to` (the contract
hash a migration produces), not `metadata.migrationHash` (the package's
content-addressed identity). Tighten wording so future maintainers do not
mistakenly switch the resolver to migrationHash semantics.

Addresses CodeRabbit nitpick
#384 (review).
wmadden added a commit that referenced this pull request Apr 28, 2026
…12b, A12c, A12d)

Three small assertion tightenings flagged by CodeRabbit on the migrationHash
contract — each one currently a silent gap that would let a real regression
slip through:

- migration-cli.test.ts `preserves contract bookends`: assert that
  `migrationHash` is rewritten from on-disk `null` to a real `sha256:...`
  digest. Without this assertion, MigrationCLI.run could silently keep the
  null and produce a package readMigrationPackage() rejects.
- output.json-shapes.test.ts pathDecision blocks: assert `selectedPath[0]`
  shape directly (dirName / migrationHash / from / to). The surrounding
  Object.keys snapshot only covered top-level pathDecision keys, so dropping
  `migrationHash` from the wire shape would not have failed.
- mongo-migration.e2e.test.ts manifest casts: tighten from
  `{ migrationHash: string | null }` to `{ migrationHash: string }` so
  ever producing `null` on disk fails type-checking.

Addresses three nitpicks from CodeRabbit review
#384 (review).
@wmadden
wmadden deleted the tml-2264-migration-runner-should-verify-migration-matches-its-hash branch April 28, 2026 05:36
wmadden added a commit that referenced this pull request May 4, 2026
When `migration plan` succeeds without placeholders, `writeMigrationPackage`
has already emitted ops.json + migration.json with a fully attested
migrationHash, so the previous `Next: node <dir>/migration.ts to emit ops.json
and attest migrationHash before running prisma-next migration apply` instruction
was actively misleading: it told the user to repeat work the planner had
already done. Replace with a direct pointer at `prisma-next migration apply`.

The placeholder branch keeps its existing `Then run: node <dir>/migration.ts`
instruction, which is correct (placeholders genuinely require a self-emit
round-trip).

Addresses CodeRabbit review on PR #384.
wmadden added a commit that referenced this pull request May 4, 2026
…lpers

createAttestedPackage and writeTestPackage are documented to always produce
internally-consistent (attested) packages — the migrationHash is computed
over the exact (metadata, ops) that get returned/written. The
metadataOverrides parameter was typed Partial<MigrationMetadata>, which let
callers smuggle a custom migrationHash past createTestMetadata's
`overrides.migrationHash ?? computeMigrationHash(...)` fallback and produce
an inconsistent fixture without going through the explicit post-write tamper
step the helpers are designed for.

Tighten the override type to Omit<Partial<MigrationMetadata>, 'migrationHash'>
on both helpers so accidental hash injection becomes a compile error.
createTestMetadata stays as-is — hash.test.ts intentionally injects a
migrationHash to verify computeMigrationHash ignores the existing field.

Addresses CodeRabbit review on PR #384 (review body, fixtures.ts:49-58 + 85-91).
wmadden added a commit that referenced this pull request May 4, 2026
`MIGRATION.FILE_MISSING`, `MIGRATION.INVALID_JSON`, `MIGRATION.INVALID_MANIFEST`,
and `MIGRATION.SAME_SOURCE_AND_TARGET` previously instructed users to delete the
directory and re-run `migration plan`. That is the wrong primitive — `migration plan`
emits a *new* package, while every existing package can self-emit by running its
author-time `migration.ts`, regenerating `migration.json` and `ops.json` with the
correct hash + metadata. Mirror the existing `MIGRATION.HASH_MISMATCH` wording
via a shared `reemitHint(dir, fallback)` helper. `errorSameSourceAndTarget`
now takes the package `dirPath` so it can render the same cwd-relative hint;
`dag.ts` updated accordingly.

Addresses CodeRabbit thread on `errorInvalidManifest`
(#384 (comment)) and the
operator’s broader directive to standardise migration-tools remediation wording.
wmadden added a commit that referenced this pull request May 4, 2026
Previously the dag.test.ts `pkg()` helper computed `migrationHash` from a
synthetic `createdAt` (with the per-pkg counter appended) but returned metadata
with the original `createdAt`. Each fixture package was therefore internally
inconsistent and could never round-trip through `readMigrationPackage()`.

Bake the counter into the metadata `createdAt` once and hash that exact metadata,
so fixtures are loader-safe and would catch hash-verification regressions.

Addresses CodeRabbit thread
#384 (comment).
wmadden added a commit that referenced this pull request May 4, 2026
…lure (A12a)

`migration plan` previously rethrew non-`MigrationToolsError` exceptions from
the migration-load phase, bypassing `handleResult()` and crashing the command.
Wrap such failures in `errorUnexpected(...)` so the user sees the same
structured CLI envelope (Result pattern) as every other failure path.

Addresses CodeRabbit review-body finding
#384 (review)
(migration-plan.ts ~165-205, outside-diff major).
wmadden added a commit that referenced this pull request May 4, 2026
…t contract hash) (A11)

The JSDoc on `resolveBundleByPrefix` said "exact hash or prefix match" without
specifying which hash. The implementation matches `metadata.to` (the contract
hash a migration produces), not `metadata.migrationHash` (the package's
content-addressed identity). Tighten wording so future maintainers do not
mistakenly switch the resolver to migrationHash semantics.

Addresses CodeRabbit nitpick
#384 (review).
wmadden added a commit that referenced this pull request May 4, 2026
…12b, A12c, A12d)

Three small assertion tightenings flagged by CodeRabbit on the migrationHash
contract — each one currently a silent gap that would let a real regression
slip through:

- migration-cli.test.ts `preserves contract bookends`: assert that
  `migrationHash` is rewritten from on-disk `null` to a real `sha256:...`
  digest. Without this assertion, MigrationCLI.run could silently keep the
  null and produce a package readMigrationPackage() rejects.
- output.json-shapes.test.ts pathDecision blocks: assert `selectedPath[0]`
  shape directly (dirName / migrationHash / from / to). The surrounding
  Object.keys snapshot only covered top-level pathDecision keys, so dropping
  `migrationHash` from the wire shape would not have failed.
- mongo-migration.e2e.test.ts manifest casts: tighten from
  `{ migrationHash: string | null }` to `{ migrationHash: string }` so
  ever producing `null` on disk fails type-checking.

Addresses three nitpicks from CodeRabbit review
#384 (review).
wmadden added a commit that referenced this pull request May 4, 2026
…geSet (A12e)

`loadAllMigrationPackages` was a same-behaviour wrapper around
`loadMigrationPackages`, retained only for naming clarity from the era when
the CLI distinguished attested and draft package sets. The draft state was
removed earlier in this PR — the alias now just preserves stale vocabulary
and breaks the "no backward-compat shims" guideline.

Inline the alias and the `MigrationPackageSet` type at the three callers
(`migration plan` / `migration apply` / `migration status`); update mocks
and explanatory comments in `migration-plan-command.test.ts` and
`migration-tamper.test.ts`. The single `MigrationPackageSet` user
(`migration-apply.ts`) now uses
`Awaited<ReturnType<typeof loadMigrationPackages>>` directly so the
return shape stays in one place.

Addresses CodeRabbit nitpick
#384 (review)
(command-helpers.ts ~155-178).
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant