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

TML-2775: add control-policy IR primitive (control field + effectiveControl) - #691

Merged
wmadden merged 6 commits into
mainfrom
tml-2775-control-policy-slice-1-ir-primitive
Jun 2, 2026
Merged

wmadden merged 6 commits into
mainfrom
tml-2775-control-policy-slice-1-ir-primitive

Conversation

@wmadden-electric

@wmadden-electric wmadden-electric commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

Linked issue

Refs TML-2775 — first slice of the Control Policy project, umbrella TML-2493. No GitHub issue (tracked in Linear).

At a glance

Every persisted object in a contract can now declare a control policy, and the contract carries a defaultControl. A single pure resolver computes the effective policy:

export type ControlPolicy = 'managed' | 'tolerated' | 'external' | 'observed';

export function effectiveControl(
  nodeControl: ControlPolicy | undefined,
  defaultControl: ControlPolicy | undefined,
): ControlPolicy {
  return nodeControl ?? defaultControl ?? 'managed';
}

In a contract that looks like this — the motivating shape for an externally-managed schema such as Supabase's auth tables:

{
  "target": "postgres",
  "defaultControl": "external",
  "storage": {
    "namespaces": {
      "auth": { "tables": { "users": { "control": "external", "columns": { /* … */ } } } }
    }
  }
}

Absent any control / defaultControl, behaviour and serialized output are byte-for-byte identical to today (managed), so existing contracts hash unchanged.

Decision

This PR lands the control-policy IR primitive — the substrate the rest of the project (verifier dispatch, planner dispatch, TS/PSL authoring) builds on. Concretely it ships, in order:

  1. ControlPolicy — a framework-locked four-value vocabulary (managed | tolerated | external | observed) in the foundation contract package.
  2. effectiveControl(node, default) — one pure, family-agnostic resolver (node → contract default → 'managed') that the verifier and planner will both call, so the policy is resolved in exactly one place.
  3. control? on every storage-plane IR node — SQL StorageTable / StorageColumn, the Postgres target-only enum kind, and Mongo MongoCollection — plus defaultControl? on the top-level Contract.
  4. arktype validators for all of those entities accept the new optional fields.

Per ADR 221 the policy lives on storage-plane entities (the persistence projection), not domain models. Because the framework Namespace interface is { id, kind } only, there is no single base to hang control on — it is added to each concrete storage leaf, following the repo's three-layer polymorphic IR pattern.

As the project's first PR it also carries the project shaping docs under projects/control-policy/ (spec + plan); see Reviewer notes for the close-out plan.

How it fits together

  1. Foundation first. The ControlPolicy type, the effectiveControl resolver (with unit tests pinning the three precedence rungs), and the Contract.defaultControl type field land in @prisma-next/contract, exported via its ./types barrel. No other package changes yet.
  2. Fan the field out. control? is threaded through every storage-plane leaf using the idiom those classes already use for optional fields (declare readonly x? + if (input.x !== undefined) this.x = input.x), so an unset value is never assigned, never enumerated, never serialized. Every affected arktype validator gains an optional control, and the SQL + Mongo contract-shape validators gain defaultControl.
  3. Prove fidelity. Serialize→deserialize round-trip tests for Postgres, SQLite, and Mongo construct contracts with mixed set/unset control plus a defaultControl, then assert per-node effective control survives — using the resolver itself as the oracle. pnpm fixtures:check confirms zero hash churn.

What lands in this PR

Commit What it adds
a2785ee69 Project spec + plan rewritten on current Drive templates (docs under projects/)
d4991ab8b Slice spec + dispatch plan (docs under projects/)
36fdb4c47 Plan tweak keeping the foundation change isolated (docs under projects/)
354249f59 ControlPolicy type + effectiveControl resolver + Contract.defaultControl (foundation)
adb4ea556 control? fanned across storage-plane IR + validators (defaultControl? on contract validators)
ce1fcc928 Cross-target round-trip fidelity tests (Postgres / SQLite / Mongo)

This is substrate: no verify/plan/authoring behaviour changes, and the resolver intentionally ships with no production callers yet — its consumers arrive in later slices. It is exercised by its own unit tests, so it is not dead code.

Reviewer notes

  • Project artefacts on disk. projects/control-policy/ (spec + plan) is part of this PR; the per-round review log under projects/control-policy/reviews/ is gitignored and not in the diff. Both are transient and migrate to durable docs (or drop) at project close-out.
  • No production code was needed to make round-trip pass. The field-bearing IR + validators from step 2 round-trip as-is — the Postgres enum factory forwards control, and all three serializers preserve top-level defaultControl through their spread. The round-trip commit is test-only.
  • PostgresEnumStorageEntry is an interface, so its control? field is mirrored onto the concrete PostgresEnumType class (+ its input) where the runtime idiom lives.
  • ControlPolicy validator union is duplicated as a one-line module-local constant in the SQL and Mongo validator files rather than a shared export — there is no cross-package validator-schema barrel and the four-value vocabulary is framework-locked, so drift risk is negligible.
  • Stale-dist build cascade. A cold worktree can surface a transient module-resolution failure in @prisma-next/postgres + sibling extensions on first pnpm typecheck; rebuilding the changed contract/target packages clears it. It is environmental build state, not a code issue (verified by stashing the diff — typecheck clean).

Testing performed

Run on final HEAD:

  • pnpm typecheck (workspace) — 135/135 tasks.
  • pnpm fixtures:check — clean, zero churn.
  • pnpm --filter @prisma-next/contract test; SQL contract / Mongo contract / Postgres / SQLite / Mongo target suites — all green.
  • pnpm lint:deps — 972 modules, 0 violations.

Skill update

n/a — internal IR substrate. This PR adds no user-facing authoring surface (TS/PSL authoring of control lands in later slices) and changes no runtime behaviour.

Checklist

  • All commits are signed off (git commit -s).
  • I read CONTRIBUTING.md and the change is scoped to one logical concern (the control-policy IR substrate).
  • Tests are updated (resolver unit tests, per-family construction/validator tests, cross-target round-trip tests).
  • The PR title is in TML-NNNN: <sentence-case title> form.
  • The Skill update section above is filled in.

Alternatives considered

  • Namespace-level control inheritance (mark a namespace external, contents inherit). Deferred: policy boundaries align with contract-space boundaries in v0.1 (each space ships its own defaultControl), so no current consumer mixes policies within one space. Additive on the wire later — an optional namespace field + one rung in the resolver.
  • Per-column control override. Deferred; columns inherit their table's effective control until a real mixed-strictness case lands.
  • A single framework base carrying control. Not available — ADR 221's Namespace interface is { id, kind } only; the field goes on each concrete storage leaf instead.
  • effectiveControl taking a node/IR object. Rejected in favour of two raw ControlPolicy | undefined values, so the resolver is family-agnostic and callable identically from the verifier and the planner without importing their node types.

Summary by CodeRabbit

  • New Features

    • Added support for control policies for storage contracts and nodes with four states: managed, tolerated, external, observed.
    • Contract-level default + per-node overrides; resolution order is node → contract default → managed.
    • Validation and serializers updated to accept/emit these optional control fields and to omit redundant values when inherited.
  • Tests

    • Added comprehensive tests covering resolution precedence, schema validation, and serialization round-trip fidelity.

@wmadden-electric
wmadden-electric requested a review from a team as a code owner June 2, 2026 11:45
@coderabbitai

coderabbitai Bot commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 4d6dc838-af80-4dc4-93e3-0686d10b120a

📥 Commits

Reviewing files that changed from the base of the PR and between ce1fcc9 and 95c94c5.

⛔ Files ignored due to path filters (4)
  • projects/control-policy/plan.md is excluded by !projects/**
  • projects/control-policy/slices/ir-primitive/plan.md is excluded by !projects/**
  • projects/control-policy/slices/ir-primitive/spec.md is excluded by !projects/**
  • projects/control-policy/spec.md is excluded by !projects/**
📒 Files selected for processing (17)
  • packages/1-framework/0-foundation/contract/src/contract-types.ts
  • packages/1-framework/0-foundation/contract/src/control-policy.ts
  • packages/1-framework/0-foundation/contract/src/exports/types.ts
  • packages/1-framework/0-foundation/contract/test/control-policy.test.ts
  • packages/2-mongo-family/1-foundation/mongo-contract/src/contract-schema.ts
  • packages/2-mongo-family/1-foundation/mongo-contract/src/ir/mongo-collection.ts
  • packages/2-mongo-family/1-foundation/mongo-contract/test/ir/control-field.test.ts
  • packages/2-sql/1-core/contract/src/ir/postgres-enum-storage-entry.ts
  • packages/2-sql/1-core/contract/src/ir/storage-column.ts
  • packages/2-sql/1-core/contract/src/ir/storage-table.ts
  • packages/2-sql/1-core/contract/src/validators.ts
  • packages/2-sql/1-core/contract/test/control-field.test.ts
  • packages/3-mongo-target/1-mongo-target/test/mongo-target-contract-serializer.test.ts
  • packages/3-targets/3-targets/postgres/src/core/postgres-enum-type.ts
  • packages/3-targets/3-targets/postgres/test/control-field.test.ts
  • packages/3-targets/3-targets/postgres/test/postgres-contract-serializer.test.ts
  • packages/3-targets/3-targets/sqlite/test/sqlite-contract-serializer.test.ts

📝 Walkthrough

Walkthrough

This PR adds a ControlPolicy type and effectiveControl resolution, wires optional per-node control and contract-level defaultControl into foundation, Mongo, SQL, and PostgreSQL target IR and schemas, and adds validator and serializer round-trip tests that verify resolution and canonicalization.

Changes

Control Policy Implementation

Layer / File(s) Summary
Foundation: Control policy type and contract integration
packages/1-framework/0-foundation/contract/src/control-policy.ts, packages/1-framework/0-foundation/contract/src/contract-types.ts, packages/1-framework/0-foundation/contract/src/exports/types.ts, packages/1-framework/0-foundation/contract/test/control-policy.test.ts
ControlPolicy union and effectiveControl function added; Contract gains optional defaultControl; re-exports updated and tests validate precedence and fallback.
Mongo contract: Collection control field and schema validation
packages/2-mongo-family/1-foundation/mongo-contract/src/ir/mongo-collection.ts, packages/2-mongo-family/1-foundation/mongo-contract/src/contract-schema.ts, packages/2-mongo-family/1-foundation/mongo-contract/test/ir/control-field.test.ts
MongoCollection IR/input accept optional control, constructor wiring added, ControlPolicySchema added to storage collection and contract-level defaultControl, and tests verify property retention/omission and schema validation.
SQL contract: Column, table, enum control fields and schema validation
packages/2-sql/1-core/contract/src/ir/storage-column.ts, packages/2-sql/1-core/contract/src/ir/storage-table.ts, packages/2-sql/1-core/contract/src/ir/postgres-enum-storage-entry.ts, packages/2-sql/1-core/contract/src/validators.ts, packages/2-sql/1-core/contract/test/control-field.test.ts
StorageColumn, StorageTable, and PostgresEnumStorageEntry accept optional control, constructors assign the property, a central ControlPolicySchema validates allowed values across columns, tables, and enum entries, and tests cover IR and schema behavior including defaultControl.
PostgreSQL target: Enum type control field
packages/3-targets/3-targets/postgres/src/core/postgres-enum-type.ts, packages/3-targets/3-targets/postgres/test/control-field.test.ts
PostgresEnumTypeInput and PostgresEnumType accept optional control, constructor wiring added, and tests assert property presence when set and omission when unset.
Round-trip serialization: Control policy preservation and canonicalization
packages/3-mongo-target/1-mongo-target/test/mongo-target-contract-serializer.test.ts, packages/3-targets/3-targets/postgres/test/postgres-contract-serializer.test.ts, packages/3-targets/3-targets/sqlite/test/sqlite-contract-serializer.test.ts
Serializer tests for Mongo, PostgreSQL, and SQLite verify defaultControl and per-node control survive serialize→deserialize, effective per-node control resolves via effectiveControl, and control fields are omitted when equal to inherited defaults.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 I nibble at defaults and nibble at node,
Managed or tolerated, the choices bestowed,
External or observed, each one in sight,
Effective control makes the governance right,
A tiny rabbit cheers when the round-trip is tight!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 27.27% 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 accurately describes the main change: introducing a control-policy IR primitive with a control field and effectiveControl resolver function across multiple storage-plane modules.
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-2775-control-policy-slice-1-ir-primitive

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

❤️ Share

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

@pkg-pr-new

pkg-pr-new Bot commented Jun 2, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@prisma-next/extension-author-tools

npm i https://pkg.pr.new/@prisma-next/extension-author-tools@691

@prisma-next/mongo-runtime

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

@prisma-next/family-mongo

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

@prisma-next/sql-runtime

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

@prisma-next/family-sql

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

@prisma-next/extension-arktype-json

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

@prisma-next/middleware-cache

npm i https://pkg.pr.new/@prisma-next/middleware-cache@691

@prisma-next/mongo

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

@prisma-next/extension-paradedb

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

@prisma-next/extension-pgvector

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

@prisma-next/extension-postgis

npm i https://pkg.pr.new/@prisma-next/extension-postgis@691

@prisma-next/postgres

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

@prisma-next/sql-orm-client

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

@prisma-next/sqlite

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

@prisma-next/target-mongo

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

@prisma-next/adapter-mongo

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

@prisma-next/driver-mongo

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

@prisma-next/contract

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

@prisma-next/utils

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

@prisma-next/config

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

@prisma-next/errors

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

@prisma-next/framework-components

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

@prisma-next/operations

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

@prisma-next/ts-render

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

@prisma-next/contract-authoring

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

@prisma-next/ids

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

@prisma-next/psl-parser

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

@prisma-next/psl-printer

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

@prisma-next/cli

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

@prisma-next/cli-telemetry

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

@prisma-next/emitter

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

@prisma-next/migration-tools

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

prisma-next

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

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

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

@prisma-next/mongo-codec

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

@prisma-next/mongo-contract

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

@prisma-next/mongo-value

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

@prisma-next/mongo-contract-psl

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

@prisma-next/mongo-contract-ts

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

@prisma-next/mongo-emitter

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

@prisma-next/mongo-schema-ir

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

@prisma-next/mongo-query-ast

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

@prisma-next/mongo-orm

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

@prisma-next/mongo-query-builder

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

@prisma-next/mongo-lowering

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

@prisma-next/mongo-wire

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

@prisma-next/sql-contract

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

@prisma-next/sql-errors

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

@prisma-next/sql-operations

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

@prisma-next/sql-schema-ir

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

@prisma-next/sql-contract-psl

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

@prisma-next/sql-contract-ts

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

@prisma-next/sql-contract-emitter

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

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

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

@prisma-next/sql-relational-core

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

@prisma-next/sql-builder

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

@prisma-next/target-postgres

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

@prisma-next/target-sqlite

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

@prisma-next/adapter-postgres

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

@prisma-next/adapter-sqlite

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

@prisma-next/driver-postgres

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

@prisma-next/driver-sqlite

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

commit: 691381c

@github-actions

github-actions Bot commented Jun 2, 2026 •

Copy link
Copy Markdown

size-limit report 📦

Path Size
postgres / no-emit 136.03 KB (0%)
postgres / emit 108.33 KB (0%)
mongo / no-emit 75.76 KB (0%)
mongo / emit 70.75 KB (0%)
cf-worker / no-emit 164.72 KB (0%)
cf-worker / emit 133.77 KB (0%)

@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 (1)
packages/1-framework/0-foundation/contract/src/control-policy.ts (1)

10-24: ⚡ Quick win

Export the canonical control-policy value list from the foundation layer.

ControlPolicy is now hard-coded again in both Mongo and SQL Arktype schemas. That gives you a compile/runtime drift path: adding a new policy here will typecheck everywhere, but validators will still reject it until every schema is updated manually. Export a shared tuple/value source here and derive the type and downstream schemas from it instead.

♻️ Possible direction
-export type ControlPolicy = 'managed' | 'tolerated' | 'external' | 'observed';
+export const controlPolicies = ['managed', 'tolerated', 'external', 'observed'] as const;
+
+export type ControlPolicy = (typeof controlPolicies)[number];

Then build each validator from controlPolicies instead of repeating the string union.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/1-framework/0-foundation/contract/src/control-policy.ts` around
lines 10 - 24, Export a single canonical array/tuple of allowed policy strings
(e.g., controlPolicies) from this module and derive the ControlPolicy type from
it (use a string literal union from the tuple) instead of hard-coding the union;
update any consumers/validators (Mongo and SQL Arktype schema builders) to
import controlPolicies and build their validators/enums from that array rather
than repeating the string union; keep effectiveControl as-is but ensure it
accepts ControlPolicy | undefined derived from the new tuple.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@packages/3-targets/3-targets/postgres/test/postgres-contract-serializer.test.ts`:
- Around line 171-246: The test currently only leaves email.control unset so it
can't catch a serializer that preserves an explicit default-valued control;
update makeMixedControlContractJson to explicitly set the email column's control
to 'tolerated' (matching defaultControl) and keep the round-trip assertions:
after serialize→deserialize using PostgresContractSerializer, assert
effectiveControl(emailColumn.control, reparsed.defaultControl) is 'tolerated'
and assert the email column does NOT have a 'control' property (testing
omit-when-default). Refer to makeMixedControlContractJson,
PostgresContractSerializer, effectiveControl, and the emailColumn/table/ns
variables in the test to locate and change the fixture and assertions.

---

Nitpick comments:
In `@packages/1-framework/0-foundation/contract/src/control-policy.ts`:
- Around line 10-24: Export a single canonical array/tuple of allowed policy
strings (e.g., controlPolicies) from this module and derive the ControlPolicy
type from it (use a string literal union from the tuple) instead of hard-coding
the union; update any consumers/validators (Mongo and SQL Arktype schema
builders) to import controlPolicies and build their validators/enums from that
array rather than repeating the string union; keep effectiveControl as-is but
ensure it accepts ControlPolicy | undefined derived from the new tuple.
🪄 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: e5798517-9ca3-46a8-8b25-e70861180e67

📥 Commits

Reviewing files that changed from the base of the PR and between 3ff5e1f and ce1fcc9.

⛔ Files ignored due to path filters (4)
  • projects/control-policy/plan.md is excluded by !projects/**
  • projects/control-policy/slices/ir-primitive/plan.md is excluded by !projects/**
  • projects/control-policy/slices/ir-primitive/spec.md is excluded by !projects/**
  • projects/control-policy/spec.md is excluded by !projects/**
📒 Files selected for processing (17)
  • packages/1-framework/0-foundation/contract/src/contract-types.ts
  • packages/1-framework/0-foundation/contract/src/control-policy.ts
  • packages/1-framework/0-foundation/contract/src/exports/types.ts
  • packages/1-framework/0-foundation/contract/test/control-policy.test.ts
  • packages/2-mongo-family/1-foundation/mongo-contract/src/contract-schema.ts
  • packages/2-mongo-family/1-foundation/mongo-contract/src/ir/mongo-collection.ts
  • packages/2-mongo-family/1-foundation/mongo-contract/test/ir/control-field.test.ts
  • packages/2-sql/1-core/contract/src/ir/postgres-enum-storage-entry.ts
  • packages/2-sql/1-core/contract/src/ir/storage-column.ts
  • packages/2-sql/1-core/contract/src/ir/storage-table.ts
  • packages/2-sql/1-core/contract/src/validators.ts
  • packages/2-sql/1-core/contract/test/control-field.test.ts
  • packages/3-mongo-target/1-mongo-target/test/mongo-target-contract-serializer.test.ts
  • packages/3-targets/3-targets/postgres/src/core/postgres-enum-type.ts
  • packages/3-targets/3-targets/postgres/test/control-field.test.ts
  • packages/3-targets/3-targets/postgres/test/postgres-contract-serializer.test.ts
  • packages/3-targets/3-targets/sqlite/test/sqlite-contract-serializer.test.ts

Comment on lines +171 to +246
describe('control-policy round-trip fidelity', () => {
function makeMixedControlContractJson() {
const base = createSqlContract({
storage: {
namespaces: {
[UNBOUND_NAMESPACE_ID]: {
id: UNBOUND_NAMESPACE_ID,
tables: {
user: {
columns: {
id: {
nativeType: 'int4',
codecId: 'pg/int4@1',
nullable: false,
control: 'observed',
},
email: { nativeType: 'text', codecId: 'pg/text@1', nullable: false },
},
primaryKey: { columns: ['id'] },
uniques: [],
indexes: [],
foreignKeys: [],
control: 'external',
},
},
},
},
},
});
return {
...base,
defaultControl: 'tolerated',
storage: {
...base.storage,
namespaces: {
[UNBOUND_NAMESPACE_ID]: {
...base.storage.namespaces[UNBOUND_NAMESPACE_ID]!,
enum: {
Role: {
kind: 'postgres-enum',
name: 'Role',
nativeType: 'role',
values: ['admin', 'user'],
control: 'managed',
},
},
},
},
},
};
}

it('preserves effective control per node across serialize → deserialize', () => {
const serializer = new PostgresContractSerializer();
const input = makeMixedControlContractJson();

const contract = serializer.deserializeContract(input);
const reparsed = JSON.parse(JSON.stringify(serializer.serializeContract(contract)));

expect(reparsed.defaultControl).toBe('tolerated');

const ns = reparsed.storage.namespaces[UNBOUND_NAMESPACE_ID];
const table = ns.tables.user;
const idColumn = table.columns.id;
const emailColumn = table.columns.email;
const enumEntry = ns.enum.Role;

const def = reparsed.defaultControl;
expect(effectiveControl(table.control, def)).toBe('external');
expect(effectiveControl(idColumn.control, def)).toBe('observed');
expect(effectiveControl(emailColumn.control, def)).toBe('tolerated');
expect(effectiveControl(enumEntry.control, def)).toBe('managed');

// Omit-when-default holds: the unset column never grows a control property.
expect(emailColumn).not.toHaveProperty('control');
});

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

Exercise the explicit default-matching override case.

This fixture only covers an unset email.control, so the not.toHaveProperty('control') assertion proves omit-when-unset, not omit-when-default. A serializer that preserved an explicit control: 'tolerated' would still pass here.

Suggested test tweak
               user: {
                 columns: {
                   id: {
                     nativeType: 'int4',
                     codecId: 'pg/int4@1',
                     nullable: false,
                     control: 'observed',
                   },
-                  email: { nativeType: 'text', codecId: 'pg/text@1', nullable: false },
+                  email: {
+                    nativeType: 'text',
+                    codecId: 'pg/text@1',
+                    nullable: false,
+                    control: 'tolerated',
+                  },
                 },
                 primaryKey: { columns: ['id'] },
                 uniques: [],
                 indexes: [],
                 foreignKeys: [],
@@
-    // Omit-when-default holds: the unset column never grows a control property.
+    // Explicit overrides that match the inherited default are canonicalized away.
     expect(emailColumn).not.toHaveProperty('control');
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@packages/3-targets/3-targets/postgres/test/postgres-contract-serializer.test.ts`
around lines 171 - 246, The test currently only leaves email.control unset so it
can't catch a serializer that preserves an explicit default-valued control;
update makeMixedControlContractJson to explicitly set the email column's control
to 'tolerated' (matching defaultControl) and keep the round-trip assertions:
after serialize→deserialize using PostgresContractSerializer, assert
effectiveControl(emailColumn.control, reparsed.defaultControl) is 'tolerated'
and assert the email column does NOT have a 'control' property (testing
omit-when-default). Refer to makeMixedControlContractJson,
PostgresContractSerializer, effectiveControl, and the emailColumn/table/ns
variables in the test to locate and change the fixture and assertions.

@wmadden-electric
wmadden-electric enabled auto-merge (squash) June 2, 2026 11:52
@wmadden
wmadden disabled auto-merge June 2, 2026 12:03
wmadden added 6 commits June 2, 2026 14:03
…mplates

Restructure the control-policy project artefacts to the current Drive
project-spec / project-plan shape: the spec now carries only durable
system-level intent (purpose, non-goals, place in the world, cross-cutting
requirements, transitional-shape constraints, project-DoD), with per-slice
dispatch detail and acceptance criteria pushed down to the slice issues. The
plan carries slice composition (one substrate slice + a parallel consumer fan
+ a deferrable PSL slice) with conceptual focus only.

Reconcile the design with ADR 221: control lives on storage-plane entities,
not domain models. Record the namespace-level-inheritance deferral with its
promotion trigger.

Refs: TML-2493
Signed-off-by: Will Madden <[email protected]>
Slice spec + 3-dispatch plan for TML-2775: ControlPolicy type + effective
-control resolver (foundation), uniform control? fan-out across storage-plane
IR nodes + validators, then cross-target round-trip + no-hash-churn
verification.

Refs: TML-2775
Signed-off-by: Will Madden <[email protected]>
…n-only

Fold all arktype validator wiring (per-node control + contract-level
defaultControl) into dispatch 2, where the validators already get touched, so
dispatch 1 stays foundation-only (typecheck + unit-test gate, no cross-package
surface).

Refs: TML-2775
Signed-off-by: Will Madden <[email protected]>
Adds the ControlPolicy string-literal union and the effectiveControl pure
function to @prisma-next/contract, exported via the ./types barrel.
Also adds readonly defaultControl?: ControlPolicy to the Contract interface.

Resolver precedence: node value → contract default → managed.

Signed-off-by: Will Madden <[email protected]>
Adds the optional control?: ControlPolicy field to every storage-plane IR
leaf (SQL StorageTable/StorageColumn, PostgresEnumStorageEntry interface +
PostgresEnumType class, Mongo MongoCollection) using the declare-readonly +
assign-if-defined idiom so an unset value never serializes.

Teaches each entity arktype validator to accept an optional control
constrained to the four ControlPolicy literals, and the SQL + Mongo
contract-shape validators to accept an optional defaultControl.

No behaviour change; the resolver consumers wire in later.

Signed-off-by: Will Madden <[email protected]>
Add serialize/deserialize round-trip tests for Postgres, SQLite, and Mongo
asserting that per-node control and the top-level defaultControl survive a
round-trip with effective control preserved per node (oracle: effectiveControl).
Each suite mixes set and unset carriers and asserts unset nodes never grow a
control property, exercising the omit-when-default no-churn mechanism.

Signed-off-by: Will Madden <[email protected]>
@wmadden
wmadden force-pushed the tml-2775-control-policy-slice-1-ir-primitive branch from 691381c to 95c94c5 Compare June 2, 2026 12:03
@wmadden
wmadden merged commit d1ca9df into main Jun 2, 2026
9 checks passed
@wmadden
wmadden deleted the tml-2775-control-policy-slice-1-ir-primitive branch June 2, 2026 12:03
medz pushed a commit to medz/prisma-next that referenced this pull request Jun 5, 2026
…-2800) (prisma#707)

## At a glance

```ts
// before
const contract = defineContract({ ..., defaultControl: 'tolerated' });

// after
const contract = defineContract({ ..., defaultControlPolicy: 'tolerated' });
```

A pure mechanical rename of the contract-level default field. No
behaviour change.

## The decision

The control-policy primitive (`ControlPolicy = 'managed' | 'tolerated' |
'external' | 'observed'`) introduced a contract-level default named
`defaultControl`. Reading the merged slice PRs as a fresh team member,
"control" is overloaded: the codebase already uses **control plane** as
a load-bearing term, and the contract was using bare "control" as
shorthand for "control **policy**". This rename completes the
[`effectiveControl →
effectiveControlPolicy`](prisma#699)
cleanup landed in prisma#699 — the field-name half of the same
ubiquitous-language pass.

After this PR, every policy-bearing identifier on the storage plane
reads `…ControlPolicy` rather than bare `…Control` (the per-node
`.control` IR field is the deliberate exception — renaming it would
change every node's serialized contract hash, see "Alternatives
considered").

## Scope

In:
- `defaultControl` → `defaultControlPolicy` on the contract IR
(`@prisma-next/contract` and the Mongo contract foundation), its arktype
validators, the TS authoring builder option, and every reader (verifier,
planner).
- The serialized JSON key on the contract — and a regeneration of the
one committed example contract that exercises it
(`projects/supabase-integration/example/migrations/supabase/contract.{json,d.ts}`).
- Test fixtures and helpers that reference the old name.

Out (deliberately):
- The per-node `.control` field — renaming it would alter the serialized
JSON of every contract that uses control policies, regardless of the
value. The collision the rename addresses is the **default**-side
identifier; the per-node field stays `.control` for now.

## Hash impact

The feature was merged to `main` only yesterday (prisma#691 on 2026-06-02). No
downstream contract is yet using a non-default `defaultControl` value.
The omit-when-default idiom means the JSON key only appears when the
author explicitly sets a non-default policy; existing contracts in the
wild that don't set it will be byte-for-byte unchanged.

## Verification

- `@prisma-next/contract`, `@prisma-next/mongo-contract`, and
`@prisma-next/sql-contract` rebuilt — `dist/*.d.mts` exports the new
field.
- Tests green: contract (160), sql-contract (129), mongo-contract (117),
sql-contract-ts (270), family-sql (333), family-mongo (148),
target-postgres (377), target-sqlite (104), target-mongo (404) — **2042
passing**.
- Typecheck green across all touched packages.
- `pnpm lint:deps` clean.
- No stale `defaultControl` token remains in source/tests (the design
docs under `projects/control-policy/` continue to spell the pre-rename
name — they describe pre-rename state and are deleted at project
close-out, mirroring the precedent prisma#699 set for `plan.md`).

## Alternatives considered

- **Carry the rename inside the e2e demonstration slice (TML-2796)** —
no extra PR, but risks colliding with any open branch that reads the
field; landing it as substrate-first matches how prisma#699 sequenced
`effectiveControl`, removing the rebase hazard entirely.
- **Also rename the per-node `.control` field → `.controlPolicy`** —
would alter the serialized JSON of every node carrying a control policy,
churning contract hashes for every consumer regardless of value. Not
required to resolve the default-side ambiguity. Deliberately out of
scope.

Linear: TML-2800


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Refactor**
* Standardized contract control policy property naming across MongoDB,
SQL, and related packages for improved consistency and clarity in
contract definitions.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Signed-off-by: Will Madden <[email protected]>
Co-authored-by: Will Madden <[email protected]>
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.

2 participants