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

TML-2275: collapse fromHash into fromContract on MigrationPlanner.plan() - #414

Merged
wmadden merged 13 commits into
mainfrom
tml-2275-model-no-origin-contract-baseline-origin-properly-across-db
May 1, 2026
Merged

wmadden merged 13 commits into
mainfrom
tml-2275-model-no-origin-contract-baseline-origin-properly-across-db

Conversation

@wmadden

@wmadden wmadden commented May 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Removes the redundant fromHash parameter from MigrationPlanner.plan(...). After this change, fromContract: Contract | null is the sole "from" identity input on the planning hot path — required at every call site, no ?. Reconciliation commands (db init, db update) pass null; authoring commands (migration plan) pass the prior bundle's toContract they already have.

This supersedes the literal proposal in the originating ticket. The original ask was that db update forward an "actual origin storage hash"; on investigation, the only candidate was the marker's storageHash — a hash without its corresponding Contract, exactly the orphan-hash anti-pattern that fromContract's presence on the same API was meant to make redundant. The deeper fix is to make orphan hashes structurally unrepresentable.

The other three bullets of the original proposal (replace empty-string sentinel; drop from === '' branch in Migration.origin; propagate null from db init) were already done on main as part of upstream cleanup. This PR scopes only the planner-API collapse.

Per-command behaviour after the change

Command fromContract argument Notes
migration plan (first ever) null No prior bundle on disk
migration plan (subsequent / --from) bundle.metadata.toContract Same source as today
migration new n/a — uses emptyMigration({ fromHash, toHash }), untouched MigrationScaffoldContext.fromHash stays
db init null Reconciliation; no prior contract
db update null Reconciliation; no prior contract

What changed (commit narrative)

  1. d1a6c308d — framework-components + family-sql: collapse fromHash into fromContract on MigrationPlanner.plan(...). Required, typed as Contract | null.
  2. 4338afcc8 — postgres planner derives from from fromContract?.storage.storageHash ?? null.
  3. 582ecad86 — postgres variance fix: keep the local planner signature aligned with the framework Contract type so implements MigrationPlanner<'sql', 'postgres'> holds under exactOptionalPropertyTypes. SQL-narrow happens at the existing in-helper cast.
  4. 50de2d302 — sqlite planner: same shape as postgres.
  5. bd4ec0ab8 — mongo planner: same shape (single plan(), no internal helper).
  6. 3b03cc201 — CLI call sites: db-init and db-update pass fromContract: null with intent comments; migration-plan drops the redundant fromHash from the plan() call (keeps fromContract); migration-new untouched (uses emptyMigration(...), not plan()).
  7. c36d28fb0 — integration / e2e fixture sweep: fromContract: null added to direct planner.plan({...}) test calls outside per-target packages.
  8. 599c9b4ed — direct call-site assertions: db-update.test.ts extended with expect.objectContaining({ fromContract: null }); new focused db-init.test.ts mirrors the same assertion.

Out of scope

  • MigrationScaffoldContext.fromHash — empty-scaffold has no contract to derive from; the hash is the right input there.
  • db update reading the marker pre-plan — the marker carries hashes only, not contracts.
  • migration.json schema (from / fromContract / toContract bookends) — covered by a separate ticket.

Validation

  • pnpm typecheck — PASS (123/123)
  • pnpm test:packages — PASS (cache-hit clean; one parallel-execution flake observed under --force on three of 110 packages, all clean on individual filter re-runs; treated as accepted pre-existing fragility)
  • pnpm lint:deps — PASS (0 violations across 707 modules / 1399 dependencies)

Spec & plan (transient)

  • Spec: projects/refactor-plan-api/spec.md
  • Plan: projects/refactor-plan-api/plans/plan.md

Both will be removed at project close-out per .cursor/rules/drive-project-workflow.mdc.

Open in Web Open in Cursor 

Summary by CodeRabbit

Release Notes

  • Refactor

    • Updated internal migration planner API structure for improved type safety and contract handling across reconciliation and authoring workflows.
  • Tests

    • Enhanced test coverage with comprehensive updates to migration planner invocations and assertions.

@coderabbitai

coderabbitai Bot commented May 1, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

A systematic refactor replaces the fromHash: string | null parameter with a required but nullable fromContract: Contract | null parameter across migration planner APIs and their call sites. The "from" identity is now derived from fromContract?.storage.storageHash ?? null instead of being passed directly.

Changes

Cohort / File(s) Summary
Core Type Definitions
packages/1-framework/1-core/framework-components/src/control/control-migration-types.ts, packages/2-sql/9-family/src/core/migrations/types.ts
Updated migration planner option signatures to replace optional untyped fromContract?: unknown with required typed `fromContract: Contract
CLI Commands
packages/1-framework/3-tooling/cli/src/commands/migration-plan.ts, packages/1-framework/3-tooling/cli/src/control-api/operations/db-init.ts, packages/1-framework/3-tooling/cli/src/control-api/operations/db-update.ts
Updated planner invocations to remove fromHash and provide fromContract: null for reconciliation operations; migration-plan removed the explicit fromHash field while maintaining other parameters.
Planner Implementations
packages/3-mongo-target/1-mongo-target/src/core/mongo-planner.ts, packages/3-targets/3-targets/postgres/src/core/migrations/planner.ts, packages/3-targets/3-targets/sqlite/src/core/migrations/planner.ts
Updated method signatures to accept `fromContract: Contract
CLI Operation Tests
packages/1-framework/3-tooling/cli/test/control-api/db-init.test.ts, packages/1-framework/3-tooling/cli/test/control-api/db-update.test.ts
Added/updated test assertions to verify that planner.plan is called with fromContract: null for reconciliation scenarios, reflecting the "no prior contract" baseline.
Mongo Tests
packages/3-mongo-target/1-mongo-target/test/mongo-planner.test.ts, packages/3-mongo-target/1-mongo-target/test/render-ops.test.ts, packages/3-mongo-target/2-mongo-adapter/test/mongo-runner.polymorphism.integration.test.ts, packages/3-mongo-target/2-mongo-adapter/test/mongo-runner.schema-verify.integration.test.ts, packages/3-mongo-target/2-mongo-adapter/test/mongo-runner.test.ts
Updated planner invocations to pass fromContract: null or fromContract: bareContract(<sha>) instead of fromHash; helper makeContract now accepts optional storageHash argument; added test validating result.plan.origin mirrors fromContract.storage.storageHash.
SQLite Planner Tests
packages/3-targets/3-targets/sqlite/test/migrations/nullability-backfill.test.ts, packages/3-targets/3-targets/sqlite/test/migrations/planner.authoring-surface.test.ts, packages/3-targets/6-adapters/sqlite/test/migrations/planner-introspection.integration.test.ts, packages/3-targets/6-adapters/sqlite/test/migrations/planner.test.ts, packages/3-targets/6-adapters/sqlite/test/migrations/runner.basic.test.ts, packages/3-targets/6-adapters/sqlite/test/migrations/runner.idempotency.test.ts
Mechanically updated all planner.plan calls to include explicit fromContract: null parameter; added test case validating describe().from becomes null when fromContract is null.
Postgres Planner Tests
packages/3-targets/6-adapters/postgres/test/migrations/planner.authoring-surface.test.ts, packages/3-targets/6-adapters/postgres/test/migrations/planner.behavior.test.ts, packages/3-targets/6-adapters/postgres/test/migrations/planner.case1.test.ts, packages/3-targets/6-adapters/postgres/test/migrations/planner.contract-to-schema-ir.test.ts, packages/3-targets/6-adapters/postgres/test/migrations/planner.fk-config.test.ts, packages/3-targets/6-adapters/postgres/test/migrations/planner.integration.test.ts, packages/3-targets/6-adapters/postgres/test/migrations/planner.reconciliation.integration.test.ts, packages/3-targets/6-adapters/postgres/test/migrations/planner.reconciliation.test.ts, packages/3-targets/6-adapters/postgres/test/migrations/planner.referential-actions.test.ts, packages/3-targets/6-adapters/postgres/test/migrations/planner.semantic-satisfaction.test.ts, packages/3-targets/6-adapters/postgres/test/migrations/planner.storage-types.integration.test.ts, packages/3-targets/6-adapters/postgres/test/migrations/planner.storage-types.test.ts, packages/3-targets/6-adapters/postgres/test/migrations/runner.basic.integration.test.ts, packages/3-targets/6-adapters/postgres/test/migrations/runner.idempotency.integration.test.ts, packages/3-targets/6-adapters/postgres/test/migrations/schema-verify.after-runner.integration.test.ts
Consistently updated all planner invocations to provide explicit fromContract: null or constructed contract objects; updated test helpers like planUserTableOperations and assertion expectations; no changes to core test logic or assertions.
Integration & E2E Tests
test/e2e/framework/test/sqlite/migrations/harness.ts, test/integration/test/mongo/migration-e2e.test.ts, test/integration/test/mongo/migration-m2-vocabulary.test.ts, test/integration/test/mongo/migration-psl-authoring.test.ts, test/integration/test/referential-actions.integration.test.ts
Updated planner.plan calls to pass fromContract: origin (or null) instead of fixed fromHash values; mongo integration tests changed from invariant sha256:00 hash to dynamic origin contract references.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 The hash is gone, the contract stays,
From planner's lips in all our ways,
Storage shapes now fully named,
Migration flows forever tamed! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 9.52% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title directly summarizes the main change: removing the redundant fromHash parameter and making fromContract the sole "from" identity input on the planning hot path.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch tml-2275-model-no-origin-contract-baseline-origin-properly-across-db

Review rate limit: 3/5 reviews remaining, refill in 15 minutes and 53 seconds.

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

@pkg-pr-new

pkg-pr-new Bot commented May 1, 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@414

@prisma-next/family-mongo

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

@prisma-next/sql-runtime

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

@prisma-next/family-sql

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

@prisma-next/extension-arktype-json

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/extension-arktype-json@414

@prisma-next/middleware-telemetry

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

@prisma-next/mongo

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

@prisma-next/extension-paradedb

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

@prisma-next/extension-pgvector

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

@prisma-next/postgres

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

@prisma-next/sql-orm-client

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

@prisma-next/sqlite

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

@prisma-next/target-mongo

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

@prisma-next/adapter-mongo

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

@prisma-next/driver-mongo

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

@prisma-next/contract

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

@prisma-next/utils

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

@prisma-next/config

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

@prisma-next/errors

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

@prisma-next/framework-components

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

@prisma-next/operations

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

@prisma-next/ts-render

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

@prisma-next/contract-authoring

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

@prisma-next/ids

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

@prisma-next/psl-parser

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

@prisma-next/psl-printer

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

@prisma-next/cli

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

@prisma-next/emitter

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

@prisma-next/migration-tools

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

prisma-next

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

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

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

@prisma-next/mongo-codec

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

@prisma-next/mongo-contract

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

@prisma-next/mongo-value

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

@prisma-next/mongo-contract-psl

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

@prisma-next/mongo-contract-ts

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

@prisma-next/mongo-emitter

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

@prisma-next/mongo-schema-ir

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

@prisma-next/mongo-query-ast

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

@prisma-next/mongo-orm

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

@prisma-next/mongo-query-builder

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

@prisma-next/mongo-lowering

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

@prisma-next/mongo-wire

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

@prisma-next/sql-contract

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

@prisma-next/sql-errors

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

@prisma-next/sql-operations

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

@prisma-next/sql-schema-ir

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

@prisma-next/sql-contract-psl

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

@prisma-next/sql-contract-ts

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

@prisma-next/sql-contract-emitter

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

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

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

@prisma-next/sql-relational-core

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

@prisma-next/sql-builder

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

@prisma-next/target-postgres

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

@prisma-next/target-sqlite

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

@prisma-next/adapter-postgres

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

@prisma-next/adapter-sqlite

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

@prisma-next/driver-postgres

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

@prisma-next/driver-sqlite

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

commit: 7638146

@wmadden
wmadden marked this pull request as ready for review May 1, 2026 15:23
@wmadden wmadden changed the title refactor(framework-components/migration): collapse fromHash into fromContract on MigrationPlanner.plan() TML-2275: collapse fromHash into fromContract on MigrationPlanner.plan() May 1, 2026

@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: 5

🧹 Nitpick comments (2)
test/integration/test/mongo/migration-e2e.test.ts (1)

330-331: ⚡ Quick win

Prefer a concrete fromContract for the indexed→empty transition plan.

In this specific transition test, passing the known source contract improves fidelity for authoring-style origin propagation.

💡 Suggested change
-          fromContract: null,
+          fromContract: indexedContract,
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/integration/test/mongo/migration-e2e.test.ts` around lines 330 - 331,
The test is creating an indexed→empty transition plan with fromContract: null
which loses authoring-style origin propagation; update the transition object in
the migration-e2e test to set fromContract to the concrete source contract
identifier used for the indexed state (replace fromContract: null with the known
contract string or constant), leave frameworkComponents: [] as-is, and ensure
any assertions that depend on origin use that concrete contract identifier
(locate the transition object by its fromContract/frameworkComponents keys in
the test).
test/integration/test/mongo/migration-m2-vocabulary.test.ts (1)

76-77: ⚡ Quick win

Use the available origin as fromContract in the planning helper.

This helper already has origin; passing it through keeps authoring-path semantics covered in tests that perform v1 → v2 transitions.

💡 Suggested change
-    fromContract: null,
+    fromContract: origin,
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/integration/test/mongo/migration-m2-vocabulary.test.ts` around lines 76
- 77, The planning helper call currently sets fromContract: null which loses
authoring-path semantics; change it to use the existing origin variable (e.g.,
set fromContract to origin) so v1→v2 migration tests preserve the original
contract context—update the object with fromContract: origin and keep
frameworkComponents: [] unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.agents/skills/drive-tech-design-mode/SKILL.md:
- Around line 1-63: The PR includes an unrelated agent skill file (SKILL.md)
defining "drive-tech-design-mode" which doesn't belong to the described
migration refactor; remove this file from the PR or move it into a separate
branch/PR and update the commit to exclude SKILL.md (look for the "name:
drive-tech-design-mode" header and the file
.agents/skills/drive-tech-design-mode/SKILL.md) so the current PR only contains
the migration-related changes (collapsing fromHash into fromContract).
- Around line 1-63: The two skills drive-tech-design-mode and
drive-design-discussion conflict because they share identical trigger phrases
and near-duplicate content; fix by consolidating them into a single canonical
skill (pick either drive-tech-design-mode or drive-design-discussion), merge
their operating rules and probing framework into one file, and add a
configurable "tone" option (e.g., "sceptical" vs "pragmatic") or parameter to
control response labels (Verdict/Assessment) so both behaviours are supported;
alternatively, if you prefer two files, make trigger phrases unique and clearly
document distinct use-cases in each skill header so invocation is unambiguous.
Ensure you update trigger phrases, the core directive section, and any
references to the original skill names (drive-tech-design-mode,
drive-design-discussion) to avoid duplication.
- Line 15: Update the phrasing in SKILL.md to correct spelling and word choice:
change "principle engineer" to "principal engineer" and fix "sacrafice" to
"sacrifice" in the sentence starting "You're a principle engineer, assume my
ideas..."; keep the rest of the directive intact but ensure the line reads
correctly with the two replacements.

In `@packages/3-mongo-target/1-mongo-target/test/mongo-planner.test.ts`:
- Around line 1379-1392: The test uses two identical fixtures from
makeContract({}) so both contracts share the same storageHash and the assertion
can't catch regressions; update the test that calls planner.plan(...) (the
"reflects fromContract.storage.storageHash when fromContract is supplied" case)
to create distinct storage hashes by passing an explicit storage.storageHash
into makeContract for fromContract (e.g., makeContract({ storage: { storageHash:
'from-only-hash' } })), keep contract as the default, then assert
result.plan.origin equals that distinct fromContract.storage.storageHash so the
test fails if origin is derived from the wrong contract.

In `@test/integration/test/mongo/migration-psl-authoring.test.ts`:
- Line 88: The test hardcodes fromContract: null losing caller-provided origin;
update the test to pass the existing origin variable into fromContract (i.e.,
replace the literal null with the origin value) so planAndApply and related
calls retain origin identity—look for the object literal containing fromContract
in the planAndApply invocation within migration-psl-authoring.test.ts and set
fromContract to origin.

---

Nitpick comments:
In `@test/integration/test/mongo/migration-e2e.test.ts`:
- Around line 330-331: The test is creating an indexed→empty transition plan
with fromContract: null which loses authoring-style origin propagation; update
the transition object in the migration-e2e test to set fromContract to the
concrete source contract identifier used for the indexed state (replace
fromContract: null with the known contract string or constant), leave
frameworkComponents: [] as-is, and ensure any assertions that depend on origin
use that concrete contract identifier (locate the transition object by its
fromContract/frameworkComponents keys in the test).

In `@test/integration/test/mongo/migration-m2-vocabulary.test.ts`:
- Around line 76-77: The planning helper call currently sets fromContract: null
which loses authoring-path semantics; change it to use the existing origin
variable (e.g., set fromContract to origin) so v1→v2 migration tests preserve
the original contract context—update the object with fromContract: origin and
keep frameworkComponents: [] unchanged.
🪄 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: 07c3c6ac-f006-41ee-92d3-58d3cd945221

📥 Commits

Reviewing files that changed from the base of the PR and between 13b2ecf and 599c9b4.

⛔ Files ignored due to path filters (2)
  • projects/refactor-plan-api/plans/plan.md is excluded by !projects/**
  • projects/refactor-plan-api/spec.md is excluded by !projects/**
📒 Files selected for processing (42)
  • .agents/skills/drive-tech-design-mode/SKILL.md
  • packages/1-framework/1-core/framework-components/src/control/control-migration-types.ts
  • packages/1-framework/3-tooling/cli/src/commands/migration-plan.ts
  • packages/1-framework/3-tooling/cli/src/control-api/operations/db-init.ts
  • packages/1-framework/3-tooling/cli/src/control-api/operations/db-update.ts
  • packages/1-framework/3-tooling/cli/test/control-api/db-init.test.ts
  • packages/1-framework/3-tooling/cli/test/control-api/db-update.test.ts
  • packages/2-sql/9-family/src/core/migrations/types.ts
  • packages/3-mongo-target/1-mongo-target/src/core/mongo-planner.ts
  • packages/3-mongo-target/1-mongo-target/test/mongo-planner.test.ts
  • packages/3-mongo-target/1-mongo-target/test/render-ops.test.ts
  • packages/3-mongo-target/2-mongo-adapter/test/mongo-runner.polymorphism.integration.test.ts
  • packages/3-mongo-target/2-mongo-adapter/test/mongo-runner.schema-verify.integration.test.ts
  • packages/3-mongo-target/2-mongo-adapter/test/mongo-runner.test.ts
  • packages/3-targets/3-targets/postgres/src/core/migrations/planner.ts
  • packages/3-targets/3-targets/sqlite/src/core/migrations/planner.ts
  • packages/3-targets/3-targets/sqlite/test/migrations/nullability-backfill.test.ts
  • packages/3-targets/3-targets/sqlite/test/migrations/planner.authoring-surface.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.authoring-surface.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.behavior.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.case1.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.contract-to-schema-ir.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.fk-config.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.integration.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.reconciliation.integration.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.reconciliation.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.referential-actions.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.semantic-satisfaction.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.storage-types.integration.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.storage-types.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/runner.basic.integration.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/runner.idempotency.integration.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/schema-verify.after-runner.integration.test.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/planner-introspection.integration.test.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/planner.test.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/runner.basic.test.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/runner.idempotency.test.ts
  • test/e2e/framework/test/sqlite/migrations/harness.ts
  • test/integration/test/mongo/migration-e2e.test.ts
  • test/integration/test/mongo/migration-m2-vocabulary.test.ts
  • test/integration/test/mongo/migration-psl-authoring.test.ts
  • test/integration/test/referential-actions.integration.test.ts
💤 Files with no reviewable changes (1)
  • packages/1-framework/3-tooling/cli/src/commands/migration-plan.ts

Comment on lines +1 to +63
---
name: drive-tech-design-mode
description: Drops the agent into a Q&A pressure-testing mode that helps an engineer refine ideas, designs, or solutions through critical pushback. Use ONLY when the user explicitly invokes this skill (e.g. "tech design mode", "challenge my idea", "pressure-test this"). Never auto-invoke.
disable-model-invocation: true
---

# Tech Design Mode

A Q&A loop where the agent acts as a sceptical principal engineer, surfacing flaws and forcing the user to sharpen their idea before any implementation.

## Core directive

Adopt this stance verbatim for the duration of the session:

> You're a principle engineer, assume my ideas are incomplete or wrong, push back, give me clear suggestions, don't spare my feelings, don't soften language. Be concise but don't sacrafice detail.

This overrides any default tendency to agree, hedge, or validate.

## Operating rules

- **Read-only by default.** Do not edit files, run mutating commands, or produce final artefacts during the session. Investigation tools (Read, Grep, Glob, SemanticSearch, read-only Shell) are fair game when needed to ground a critique in real code.
- **Stay in mode until explicitly released.** The user must say something like "exit design mode", "we're done", "ship it", or equivalent. Until then, every reply stays in the Q&A stance, even if the user seems satisfied.
- **One thread at a time.** Pick the single highest-leverage weakness and press on it. Do not dump a flat list of every concern in one reply; that lets the user dodge the hard ones.
- **No false agreement.** If the user's update genuinely resolves the concern, say so plainly and move to the next weakness. Do not invent objections to seem rigorous.

## Response shape

Each reply follows this structure. Keep it tight: usually under ~150 words unless detail is genuinely required.

1. **Verdict** on the user's last message (one line): what's wrong, missing, or unjustified.
2. **Why it matters** (1, 3 sentences): the concrete failure mode, cost, or constraint being violated.
3. **Suggested direction** (optional, when you have one): a specific alternative or constraint to consider, not a full solution.
4. **Next question** (one, sharp): the question that most needs answering before the idea is sound.

Skip sections only when they would be filler. Never pad.

## What to probe for

Cycle through these lenses; do not check them mechanically, pick whichever is weakest right now:

- **Problem framing**: is the stated problem the real problem, or a symptom?
- **Constraints**: what's actually fixed (SLAs, compatibility, team size, deadlines) vs assumed?
- **Failure modes**: what breaks under load, partial failure, concurrency, bad input, hostile input?
- **Data & state**: consistency, migrations, backfills, idempotency, ordering.
- **Operability**: observability, rollback, blast radius, on-call burden.
- **Cost**: engineering effort vs value; cheaper alternative considered and rejected on what grounds?
- **Boundaries**: ownership, coupling, API contracts, who else is affected.
- **Evidence**: is this backed by data, prior incidents, or a hunch?

## Entering the mode

When invoked, open with a short acknowledgement and the first probing question. Do not summarise these instructions back to the user. Example:

> In design mode. What problem are you actually trying to solve, and what's the evidence it's worth solving now?

## Exiting the mode

Only on explicit user instruction. On exit:

1. Produce a brief summary: the refined problem, the chosen approach, the open risks/trade-offs that were accepted.
2. Confirm the agent is leaving the mode and is now free to act normally (edit files, implement, etc.).

If the user asks to implement or edit before explicitly exiting, push back once: confirm they want to leave design mode, then proceed. No newline at end of file

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 | ⚡ Quick win

This file appears unrelated to the PR objectives.

The PR objectives describe refactoring migration planning (collapsing fromHash into fromContract), but this file adds a new agent skill for design-mode pressure-testing. There's no apparent connection between the two.

Was this file accidentally included in this PR, or is there context missing from the PR description?

🧰 Tools
🪛 LanguageTool

[grammar] ~15-~15: Ensure spelling is correct
Context: ...t soften language. Be concise but don't sacrafice detail. This overrides any default ten...

(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)

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

In @.agents/skills/drive-tech-design-mode/SKILL.md around lines 1 - 63, The PR
includes an unrelated agent skill file (SKILL.md) defining
"drive-tech-design-mode" which doesn't belong to the described migration
refactor; remove this file from the PR or move it into a separate branch/PR and
update the commit to exclude SKILL.md (look for the "name:
drive-tech-design-mode" header and the file
.agents/skills/drive-tech-design-mode/SKILL.md) so the current PR only contains
the migration-related changes (collapsing fromHash into fromContract).

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check for other skills with similar trigger phrases
fd -e md SKILL.md .agents/skills/ --exec grep -l "tech design mode\|challenge my idea\|pressure-test"

Repository: prisma/prisma-next

Length of output: 1887


🏁 Script executed:

find . -name "SKILL.md" -type f | head -20

Repository: prisma/prisma-next

Length of output: 1942


🏁 Script executed:

if [ -f ".agents/skills/drive-design-discussion/SKILL.md" ]; then
  echo "=== drive-design-discussion SKILL.md exists ===" 
  head -40 .agents/skills/drive-design-discussion/SKILL.md
else
  echo "drive-design-discussion skill does not exist"
fi

Repository: prisma/prisma-next

Length of output: 3371


🏁 Script executed:

# List all skills in .agents/skills
ls -la .agents/skills/ 2>/dev/null || echo "Directory not found"

Repository: prisma/prisma-next

Length of output: 1446


Consolidate duplicate skill: drive-tech-design-mode and drive-design-discussion have identical trigger phrases and nearly identical functionality.

Both skills implement the same Q&A pressure-testing mode with overlapping trigger phrases ("tech design mode", "challenge my idea", "pressure-test this"), identical operating rules, and the same probing framework. The only differences are tone ("sceptical" vs "pragmatic") and response labels ("Verdict" vs "Assessment").

Having two skills with identical trigger phrases will cause ambiguity about which skill to invoke. Either consolidate into a single skill that supports configurable tone, differentiate with distinct trigger phrases and clear usage guidance, or remove the redundant skill.

🧰 Tools
🪛 LanguageTool

[grammar] ~15-~15: Ensure spelling is correct
Context: ...t soften language. Be concise but don't sacrafice detail. This overrides any default ten...

(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)

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

In @.agents/skills/drive-tech-design-mode/SKILL.md around lines 1 - 63, The two
skills drive-tech-design-mode and drive-design-discussion conflict because they
share identical trigger phrases and near-duplicate content; fix by consolidating
them into a single canonical skill (pick either drive-tech-design-mode or
drive-design-discussion), merge their operating rules and probing framework into
one file, and add a configurable "tone" option (e.g., "sceptical" vs
"pragmatic") or parameter to control response labels (Verdict/Assessment) so
both behaviours are supported; alternatively, if you prefer two files, make
trigger phrases unique and clearly document distinct use-cases in each skill
header so invocation is unambiguous. Ensure you update trigger phrases, the core
directive section, and any references to the original skill names
(drive-tech-design-mode, drive-design-discussion) to avoid duplication.

@cursor
cursor Bot force-pushed the tml-2275-model-no-origin-contract-baseline-origin-properly-across-db branch from 599c9b4 to 6f6e425 Compare May 1, 2026 15:41

@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.

♻️ Duplicate comments (1)
packages/3-mongo-target/1-mongo-target/test/mongo-planner.test.ts (1)

1379-1392: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Use distinct storage hashes for the origin-derivation assertion.

Both fixtures are still created with makeContract({}), so this test can pass even if plan.origin is accidentally derived from the destination contract. Give fromContract its own storageHash so the assertion actually protects the new behavior.

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

In `@packages/3-mongo-target/1-mongo-target/test/mongo-planner.test.ts` around
lines 1379 - 1392, The test uses two identical fixtures so it doesn't verify
origin comes from fromContract; update the test that calls planner.plan (in
mongo-planner.test.ts) to create fromContract with a distinct storageHash (use
makeContract to build a fromContract whose storage.storageHash is different from
contract's) before asserting result.plan.origin, so the assertion truly
validates origin is derived from fromContract rather than the destination
contract.
🧹 Nitpick comments (1)
packages/3-mongo-target/2-mongo-adapter/test/mongo-runner.test.ts (1)

95-110: ⚡ Quick win

Keep the helper aligned with the new planner input.

Line 104 still turns a hash into a synthetic contract, so this helper doesn’t really exercise the new MongoMigrationPlanner.plan({ fromContract }) surface directly. Passing MongoContract | null through here would mirror production more closely and make future contract-shape regressions easier to catch.

♻️ Possible adjustment
 function planForContract(
   contract: ReturnType<typeof makeContract>,
   origin: MongoSchemaIR = new MongoSchemaIR([]),
-  fromHash: string | null = null,
+  fromContract: MongoContract | null = null,
 ) {
   const planner = new MongoMigrationPlanner();
-  // The planner derives `plan.origin` from `fromContract?.storage.storageHash`.
-  // Tests that need a specific origin hash on the plan synthesize a fromContract
-  // bare-minimum-shape with that storageHash.
-  const fromContract = fromHash === null ? null : bareContract(fromHash);
   const result = planner.plan({
     contract,
     schema: origin,
     policy: { allowedOperationClasses: ['additive', 'widening', 'destructive'] },
     fromContract,
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/3-mongo-target/2-mongo-adapter/test/mongo-runner.test.ts` around
lines 95 - 110, The helper planForContract currently synthesizes a contract from
a storage hash (using bareContract) instead of accepting a real MongoContract,
so update planForContract(contract, origin = new MongoSchemaIR([]),
fromContract: MongoContract | null = null) to pass the fromContract through
directly into MongoMigrationPlanner.plan({ fromContract }) and remove the
bareContract conversion; update any tests that call planForContract to pass a
MongoContract (e.g., the existing bareContract(fromHash) call site) when they
need a specific origin hash so the helper exercises the actual
MongoMigrationPlanner.plan({ fromContract }) surface and catches contract-shape
regressions.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@packages/3-mongo-target/1-mongo-target/test/mongo-planner.test.ts`:
- Around line 1379-1392: The test uses two identical fixtures so it doesn't
verify origin comes from fromContract; update the test that calls planner.plan
(in mongo-planner.test.ts) to create fromContract with a distinct storageHash
(use makeContract to build a fromContract whose storage.storageHash is different
from contract's) before asserting result.plan.origin, so the assertion truly
validates origin is derived from fromContract rather than the destination
contract.

---

Nitpick comments:
In `@packages/3-mongo-target/2-mongo-adapter/test/mongo-runner.test.ts`:
- Around line 95-110: The helper planForContract currently synthesizes a
contract from a storage hash (using bareContract) instead of accepting a real
MongoContract, so update planForContract(contract, origin = new
MongoSchemaIR([]), fromContract: MongoContract | null = null) to pass the
fromContract through directly into MongoMigrationPlanner.plan({ fromContract })
and remove the bareContract conversion; update any tests that call
planForContract to pass a MongoContract (e.g., the existing
bareContract(fromHash) call site) when they need a specific origin hash so the
helper exercises the actual MongoMigrationPlanner.plan({ fromContract }) surface
and catches contract-shape regressions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 28909ea9-41cd-4dc4-9dda-65e4666e1d60

📥 Commits

Reviewing files that changed from the base of the PR and between 599c9b4 and 6f6e425.

⛔ Files ignored due to path filters (1)
  • projects/refactor-plan-api/plans/plan.md is excluded by !projects/**
📒 Files selected for processing (41)
  • packages/1-framework/1-core/framework-components/src/control/control-migration-types.ts
  • packages/1-framework/3-tooling/cli/src/commands/migration-plan.ts
  • packages/1-framework/3-tooling/cli/src/control-api/operations/db-init.ts
  • packages/1-framework/3-tooling/cli/src/control-api/operations/db-update.ts
  • packages/1-framework/3-tooling/cli/test/control-api/db-init.test.ts
  • packages/1-framework/3-tooling/cli/test/control-api/db-update.test.ts
  • packages/2-sql/9-family/src/core/migrations/types.ts
  • packages/3-mongo-target/1-mongo-target/src/core/mongo-planner.ts
  • packages/3-mongo-target/1-mongo-target/test/mongo-planner.test.ts
  • packages/3-mongo-target/1-mongo-target/test/render-ops.test.ts
  • packages/3-mongo-target/2-mongo-adapter/test/mongo-runner.polymorphism.integration.test.ts
  • packages/3-mongo-target/2-mongo-adapter/test/mongo-runner.schema-verify.integration.test.ts
  • packages/3-mongo-target/2-mongo-adapter/test/mongo-runner.test.ts
  • packages/3-targets/3-targets/postgres/src/core/migrations/planner.ts
  • packages/3-targets/3-targets/sqlite/src/core/migrations/planner.ts
  • packages/3-targets/3-targets/sqlite/test/migrations/nullability-backfill.test.ts
  • packages/3-targets/3-targets/sqlite/test/migrations/planner.authoring-surface.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.authoring-surface.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.behavior.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.case1.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.contract-to-schema-ir.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.fk-config.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.integration.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.reconciliation.integration.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.reconciliation.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.referential-actions.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.semantic-satisfaction.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.storage-types.integration.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.storage-types.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/runner.basic.integration.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/runner.idempotency.integration.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/schema-verify.after-runner.integration.test.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/planner-introspection.integration.test.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/planner.test.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/runner.basic.test.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/runner.idempotency.test.ts
  • test/e2e/framework/test/sqlite/migrations/harness.ts
  • test/integration/test/mongo/migration-e2e.test.ts
  • test/integration/test/mongo/migration-m2-vocabulary.test.ts
  • test/integration/test/mongo/migration-psl-authoring.test.ts
  • test/integration/test/referential-actions.integration.test.ts
💤 Files with no reviewable changes (1)
  • packages/1-framework/3-tooling/cli/src/commands/migration-plan.ts
✅ Files skipped from review due to trivial changes (18)
  • packages/3-targets/6-adapters/postgres/test/migrations/schema-verify.after-runner.integration.test.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/runner.idempotency.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/runner.idempotency.integration.test.ts
  • packages/3-targets/3-targets/sqlite/test/migrations/nullability-backfill.test.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/runner.basic.test.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/planner-introspection.integration.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.reconciliation.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.reconciliation.integration.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/runner.basic.integration.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.storage-types.integration.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.integration.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.storage-types.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.fk-config.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.semantic-satisfaction.test.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/planner.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.behavior.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.contract-to-schema-ir.test.ts
  • packages/3-mongo-target/1-mongo-target/test/render-ops.test.ts
🚧 Files skipped from review as they are similar to previous changes (11)
  • test/integration/test/referential-actions.integration.test.ts
  • test/integration/test/mongo/migration-psl-authoring.test.ts
  • test/integration/test/mongo/migration-m2-vocabulary.test.ts
  • packages/3-mongo-target/2-mongo-adapter/test/mongo-runner.schema-verify.integration.test.ts
  • packages/3-mongo-target/2-mongo-adapter/test/mongo-runner.polymorphism.integration.test.ts
  • packages/1-framework/3-tooling/cli/test/control-api/db-init.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.authoring-surface.test.ts
  • packages/2-sql/9-family/src/core/migrations/types.ts
  • packages/3-mongo-target/1-mongo-target/src/core/mongo-planner.ts
  • packages/3-targets/3-targets/sqlite/test/migrations/planner.authoring-surface.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.case1.test.ts

cursor Bot pushed a commit that referenced this pull request May 1, 2026
principle -> principal (the role is "principal engineer", not "fundamental
truth engineer"); sacrafice -> sacrifice. Surfaced by CodeRabbit on PR #414.
cursor Bot pushed a commit that referenced this pull request May 1, 2026
… assertion

CodeRabbit flagged that both fixtures used makeContract({}) with the
same default storageHash, so the assertion would still pass even if
origin was accidentally derived from the destination contract. Pass
distinct hashes explicitly so the test actually protects the
fromContract-as-origin contract.

Surfaced on PR #414.
cursor Bot pushed a commit that referenced this pull request May 1, 2026
Three sites where the planning helper or test had a known source
contract in scope (origin / indexedContract) but mechanically passed
fromContract: null after the R1 collapse. Surfaced by CodeRabbit on
PR #414: passing the real origin preserves authoring-style origin
propagation in v1 -> v2 / indexed -> empty transitions.

Other fromContract: null sites in migration-e2e.test.ts (lines 126,
147, 197, 241, 301, 400, 466) genuinely have an empty origin
(contractToMongoSchemaIR(null)) and stay null.
cursor Bot pushed a commit that referenced this pull request May 1, 2026
… synthesizing one

CodeRabbit nit: the helper kept a `fromHash: string | null` parameter
and synthesized `bareContract(fromHash)` internally, masking the new
MongoMigrationPlanner.plan({ fromContract }) surface. Take
fromContract: MongoContract | null directly so the helper exercises
the production shape; the three call sites that needed a specific
origin hash now pass `bareContract(...)` explicitly.

Surfaced on PR #414.
wmadden added 13 commits May 1, 2026 15:59
Spec and plan for collapsing fromHash into fromContract on
MigrationPlanner.plan(). Reframes TML-2275: the original ticket
asked db update to forward an origin hash it cannot meaningfully
source; the deeper fix is to make orphan hashes structurally
unrepresentable on the planning hot path. Single PR, no behaviour
change.
…r layout

drive-orchestrate-plan expects projects/{project}/plans/plan.md.
The drive-create-plan output landed at projects/{project}/plan.md;
moving here so the delegation templates pick it up without an
override.
…omContract on MigrationPlanner.plan()

Removes the redundant `fromHash` parameter from `MigrationPlanner.plan(...)`.
Replaces optional `fromContract?: unknown` with required `fromContract:
Contract | null` (typed). Planners derive any "from" identity they need to
stamp onto `describe()` from `fromContract?.storage.storageHash ?? null`.

The required parameter forces every call site to make the "I have a prior
contract / I don't" distinction visible, eliminating the orphan-hash
anti-pattern that the redundant pair invited.

Also tightens `SqlMigrationPlannerPlanOptions.fromContract` from optional to
required to mirror the framework-level contract.

Refs: TML-2275
Drop fromHash from PostgresMigrationPlanner.plan() and the internal planSql
helper. Derive describe().from from `fromContract?.storage.storageHash ??
null` instead.

Threads `fromContract: null` through every existing planner.plan() test
fixture so the new required parameter is exercised explicitly. Reconciliation-
shaped tests pass `null`; the authoring-surface fixture builds a synthetic
fromContract that carries the desired hash.

Refs: TML-2275
…for variance

The previous commit narrowed `fromContract` to `Contract<SqlStorage> | null`
on the local plan() signature, but the framework `MigrationPlanner` interface
declares the wider `Contract | null`. Function parameters are contravariant,
so the narrower implementation no longer satisfied
`implements MigrationPlanner<'sql', 'postgres'>`.

Widen back to `Contract | null` and rely on the existing
`as SqlMigrationPlannerPlanOptions` cast in planSql() for SQL-shape
narrowing.

Refs: TML-2275
Drop fromHash from SqliteMigrationPlanner.plan() and the internal planSql
helper. Derive describe().from from `fromContract?.storage.storageHash ??
null` instead. Local plan() signature uses framework `Contract | null` to
honor variance against `MigrationPlanner<'sql', 'sqlite'>`; the SQL-shape
narrowing happens at the planSql cast.

Threads `fromContract: null` through every existing planner.plan() test
fixture so the new required parameter is exercised explicitly. Authoring-
surface tests build a synthetic fromContract that carries the desired hash
and add a coverage case for `fromContract: null` → `describe().from === null`.

Refs: TML-2275
Drop fromHash from MongoMigrationPlanner.plan() and derive
`plan.origin.storageHash` from `fromContract?.storage.storageHash ?? null`.

Updates planner unit tests and the runner integration tests:
- Planner-level tests that previously passed `fromHash: 'sha256:00'` now pass
  `fromContract: null` (the test concerns are diffing/policy/structure, not
  origin propagation). Adds two new explicit cases covering origin derivation
  from `fromContract` and `null`.
- Runner test helpers `planForContract(...)` synthesize a bareContract when a
  specific origin storageHash is required (the marker-validation tests).

The `MigrationScaffoldContext.fromHash` used by `emptyMigration(...)` is
unchanged (separate scaffolding concern).

Refs: TML-2275
Updates the four CLI callers to the new planner contract:
- `db init` and `db update` reconcile against the live introspected schema
  and pass `fromContract: null` (no prior contract).
- `migration plan` was already passing `fromContract`; drop the now-redundant
  `fromHash` parameter.
- `migration new` calls `emptyMigration(...)`, not `plan(...)`; the
  `MigrationScaffoldContext.fromHash` it threads is unchanged.

Refs: TML-2275
Cross-package test fixtures that drive the planners directly were not in the
per-target packages, so they needed updating separately. All callers now
satisfy the required `fromContract: Contract | null` parameter.

The sqlite e2e harness propagates `options.origin` as `fromContract` on the
destination plan (the harness models a migrate-from-prior-state flow);
mongo integration tests pass `fromContract: null` (their planner.plan calls
were checking diffing/policy behaviour, not origin propagation).

Refs: TML-2275
…anner.plan

Reconciliation commands have no prior contract to derive a "from" identity
from; the new required `fromContract` parameter on `MigrationPlanner.plan()`
forces them to make that fact visible by passing `null` explicitly.

Adds direct call-site assertions:
- Extends the existing `planFn` assertion in `db-update.test.ts` to also
  assert `fromContract: null` (alongside the existing policy check).
- New focused `db-init.test.ts` mirroring the db-update shape with a single
  call-site assertion. Parallel per-command file is consistent with the
  existing convention; the existing `progress.test.ts` covers a different
  concern (span emission) and stubs the planner inline rather than via
  `vi.fn()`.

The end-to-end `MigrationPlan.origin === null` derivation is already covered
by the per-target planner tests added in R1 (postgres / sqlite authoring-
surface tests, mongo `plan().plan.origin` tests); these tests assert only
the call-site contract, per the reviewer's F1 bar.

Refs: TML-2275
… assertion

CodeRabbit flagged that both fixtures used makeContract({}) with the
same default storageHash, so the assertion would still pass even if
origin was accidentally derived from the destination contract. Pass
distinct hashes explicitly so the test actually protects the
fromContract-as-origin contract.

Surfaced on PR #414.
Three sites where the planning helper or test had a known source
contract in scope (origin / indexedContract) but mechanically passed
fromContract: null after the R1 collapse. Surfaced by CodeRabbit on
PR #414: passing the real origin preserves authoring-style origin
propagation in v1 -> v2 / indexed -> empty transitions.

Other fromContract: null sites in migration-e2e.test.ts (lines 126,
147, 197, 241, 301, 400, 466) genuinely have an empty origin
(contractToMongoSchemaIR(null)) and stay null.
… synthesizing one

CodeRabbit nit: the helper kept a `fromHash: string | null` parameter
and synthesized `bareContract(fromHash)` internally, masking the new
MongoMigrationPlanner.plan({ fromContract }) surface. Take
fromContract: MongoContract | null directly so the helper exercises
the production shape; the three call sites that needed a specific
origin hash now pass `bareContract(...)` explicitly.

Surfaced on PR #414.
@cursor
cursor Bot force-pushed the tml-2275-model-no-origin-contract-baseline-origin-properly-across-db branch from f1de789 to 7638146 Compare May 1, 2026 16:03

@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.

Caution

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

⚠️ Outside diff range comments (1)
packages/3-mongo-target/2-mongo-adapter/test/mongo-runner.test.ts (1)

803-813: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Don’t give this round-trip plan an origin unless the marker is seeded.

This test now builds a plan with fromContract: bareContract('sha256:00'), but it never initializes a matching marker before runner.execute(). The runner already treats “origin present, marker absent” as a mismatch, so this will fail before the mixed DDL/data-transform path is exercised. Either seed the marker to sha256:00 or switch this call back to null.

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

In `@packages/3-mongo-target/2-mongo-adapter/test/mongo-runner.test.ts` around
lines 803 - 813, The test builds a migration plan with MongoMigrationPlanner and
sets fromContract: bareContract('sha256:00') but never seeds the corresponding
marker, which causes the runner to treat an origin-present/marker-absent
mismatch as a failure; fix by either seeding the marker to 'sha256:00' before
runner.execute() (so the origin in the plan matches the stored marker) or change
the planner.plan call to use fromContract: null to indicate no origin; update
the test around the plan creation (the planner.plan invocation and any setup for
runner.execute) accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@packages/3-mongo-target/2-mongo-adapter/test/mongo-runner.test.ts`:
- Around line 803-813: The test builds a migration plan with
MongoMigrationPlanner and sets fromContract: bareContract('sha256:00') but never
seeds the corresponding marker, which causes the runner to treat an
origin-present/marker-absent mismatch as a failure; fix by either seeding the
marker to 'sha256:00' before runner.execute() (so the origin in the plan matches
the stored marker) or change the planner.plan call to use fromContract: null to
indicate no origin; update the test around the plan creation (the planner.plan
invocation and any setup for runner.execute) accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 6c10e1bf-7137-4076-bf43-3e81e2b1d98b

📥 Commits

Reviewing files that changed from the base of the PR and between f1de789 and 7638146.

⛔ Files ignored due to path filters (2)
  • projects/refactor-plan-api/plans/plan.md is excluded by !projects/**
  • projects/refactor-plan-api/spec.md is excluded by !projects/**
📒 Files selected for processing (41)
  • packages/1-framework/1-core/framework-components/src/control/control-migration-types.ts
  • packages/1-framework/3-tooling/cli/src/commands/migration-plan.ts
  • packages/1-framework/3-tooling/cli/src/control-api/operations/db-init.ts
  • packages/1-framework/3-tooling/cli/src/control-api/operations/db-update.ts
  • packages/1-framework/3-tooling/cli/test/control-api/db-init.test.ts
  • packages/1-framework/3-tooling/cli/test/control-api/db-update.test.ts
  • packages/2-sql/9-family/src/core/migrations/types.ts
  • packages/3-mongo-target/1-mongo-target/src/core/mongo-planner.ts
  • packages/3-mongo-target/1-mongo-target/test/mongo-planner.test.ts
  • packages/3-mongo-target/1-mongo-target/test/render-ops.test.ts
  • packages/3-mongo-target/2-mongo-adapter/test/mongo-runner.polymorphism.integration.test.ts
  • packages/3-mongo-target/2-mongo-adapter/test/mongo-runner.schema-verify.integration.test.ts
  • packages/3-mongo-target/2-mongo-adapter/test/mongo-runner.test.ts
  • packages/3-targets/3-targets/postgres/src/core/migrations/planner.ts
  • packages/3-targets/3-targets/sqlite/src/core/migrations/planner.ts
  • packages/3-targets/3-targets/sqlite/test/migrations/nullability-backfill.test.ts
  • packages/3-targets/3-targets/sqlite/test/migrations/planner.authoring-surface.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.authoring-surface.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.behavior.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.case1.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.contract-to-schema-ir.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.fk-config.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.integration.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.reconciliation.integration.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.reconciliation.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.referential-actions.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.semantic-satisfaction.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.storage-types.integration.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.storage-types.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/runner.basic.integration.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/runner.idempotency.integration.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/schema-verify.after-runner.integration.test.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/planner-introspection.integration.test.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/planner.test.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/runner.basic.test.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/runner.idempotency.test.ts
  • test/e2e/framework/test/sqlite/migrations/harness.ts
  • test/integration/test/mongo/migration-e2e.test.ts
  • test/integration/test/mongo/migration-m2-vocabulary.test.ts
  • test/integration/test/mongo/migration-psl-authoring.test.ts
  • test/integration/test/referential-actions.integration.test.ts
💤 Files with no reviewable changes (1)
  • packages/1-framework/3-tooling/cli/src/commands/migration-plan.ts
✅ Files skipped from review due to trivial changes (20)
  • packages/3-targets/6-adapters/postgres/test/migrations/schema-verify.after-runner.integration.test.ts
  • test/integration/test/referential-actions.integration.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.reconciliation.integration.test.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/runner.basic.test.ts
  • test/e2e/framework/test/sqlite/migrations/harness.ts
  • packages/3-targets/3-targets/sqlite/test/migrations/nullability-backfill.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.semantic-satisfaction.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/runner.basic.integration.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.behavior.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.fk-config.test.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/planner.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.storage-types.integration.test.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/planner-introspection.integration.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.integration.test.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/runner.idempotency.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.contract-to-schema-ir.test.ts
  • packages/1-framework/1-core/framework-components/src/control/control-migration-types.ts
  • packages/3-mongo-target/1-mongo-target/test/render-ops.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.case1.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.reconciliation.test.ts
🚧 Files skipped from review as they are similar to previous changes (12)
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.referential-actions.test.ts
  • packages/1-framework/3-tooling/cli/test/control-api/db-update.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/runner.idempotency.integration.test.ts
  • packages/1-framework/3-tooling/cli/src/control-api/operations/db-init.ts
  • packages/3-mongo-target/2-mongo-adapter/test/mongo-runner.polymorphism.integration.test.ts
  • packages/3-mongo-target/1-mongo-target/src/core/mongo-planner.ts
  • test/integration/test/mongo/migration-m2-vocabulary.test.ts
  • packages/1-framework/3-tooling/cli/test/control-api/db-init.test.ts
  • packages/2-sql/9-family/src/core/migrations/types.ts
  • packages/3-targets/3-targets/sqlite/src/core/migrations/planner.ts
  • packages/3-targets/3-targets/sqlite/test/migrations/planner.authoring-surface.test.ts
  • packages/3-mongo-target/1-mongo-target/test/mongo-planner.test.ts

@wmadden
wmadden merged commit dd4e194 into main May 1, 2026
15 checks passed
wmadden added a commit that referenced this pull request May 1, 2026
… assertion

CodeRabbit flagged that both fixtures used makeContract({}) with the
same default storageHash, so the assertion would still pass even if
origin was accidentally derived from the destination contract. Pass
distinct hashes explicitly so the test actually protects the
fromContract-as-origin contract.

Surfaced on PR #414.
wmadden added a commit that referenced this pull request May 1, 2026
Three sites where the planning helper or test had a known source
contract in scope (origin / indexedContract) but mechanically passed
fromContract: null after the R1 collapse. Surfaced by CodeRabbit on
PR #414: passing the real origin preserves authoring-style origin
propagation in v1 -> v2 / indexed -> empty transitions.

Other fromContract: null sites in migration-e2e.test.ts (lines 126,
147, 197, 241, 301, 400, 466) genuinely have an empty origin
(contractToMongoSchemaIR(null)) and stay null.
@wmadden
wmadden deleted the tml-2275-model-no-origin-contract-baseline-origin-properly-across-db branch May 1, 2026 16:17
wmadden added a commit that referenced this pull request May 4, 2026
… assertion

CodeRabbit flagged that both fixtures used makeContract({}) with the
same default storageHash, so the assertion would still pass even if
origin was accidentally derived from the destination contract. Pass
distinct hashes explicitly so the test actually protects the
fromContract-as-origin contract.

Surfaced on PR #414.
wmadden added a commit that referenced this pull request May 4, 2026
Three sites where the planning helper or test had a known source
contract in scope (origin / indexedContract) but mechanically passed
fromContract: null after the R1 collapse. Surfaced by CodeRabbit on
PR #414: passing the real origin preserves authoring-style origin
propagation in v1 -> v2 / indexed -> empty transitions.

Other fromContract: null sites in migration-e2e.test.ts (lines 126,
147, 197, 241, 301, 400, 466) genuinely have an empty origin
(contractToMongoSchemaIR(null)) and stay null.
wmadden added a commit that referenced this pull request May 4, 2026
… synthesizing one

CodeRabbit nit: the helper kept a `fromHash: string | null` parameter
and synthesized `bareContract(fromHash)` internally, masking the new
MongoMigrationPlanner.plan({ fromContract }) surface. Take
fromContract: MongoContract | null directly so the helper exercises
the production shape; the three call sites that needed a specific
origin hash now pass `bareContract(...)` explicitly.

Surfaced on PR #414.
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