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

TML-2854: generic PSL printer + contract infer for declarative blocks (Slice 2 — write side) - #754

Merged
wmadden-electric merged 7 commits into
mainfrom
tml-2854-slice-2-generic-printer-contract-infer
Jun 8, 2026
Merged

wmadden-electric merged 7 commits into
mainfrom
tml-2854-slice-2-generic-printer-contract-infer

Conversation

@wmadden-electric

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

Copy link
Copy Markdown
Contributor

At a glance

Slice 2 of 4 of Target-contributed top-level PSL blocks — the write side of the declarative SPI. Slice 1 (#753, merged) gave the framework a generic read path (parse → validate → lower an extension-contributed block from its descriptor). This PR adds the matching write path: one generic descriptor-driven printer renders any registered block back to PSL, and contract infer threads the registered descriptors through so an inferred contract prints its extension blocks. No extension-supplied printer code runs.

policy_select ProfilesSelect {
  target = Post
  using  = "auth.uid() = author_id"
}

The printer never learns the policy_select keyword — it reads the descriptor (keyword, name, typed parameters) and renders each parameter by its declared kind.

What's in this PR

  • Generic descriptor-driven printer (psl-printer) — serializePrintDocument builds a discriminator-keyed dispatch map from the registered pslBlockDescriptors and renders each block's parameters by kind: ref → identifier, option → token, list → bracketed elements, value → the codec's JSON medium (below). An unregistered discriminator throws, naming it.
  • value params are serialized through the codec, not echoed — renderValueParam runs a value literal through JSON.stringify(codec.encodeJson(codec.decodeJson(JSON.parse(raw)))). This is the exact print-back mirror of Slice 1's parse-side validator (codecLookup.get(codecId).decodeJson(JSON.parse(raw))): a PSL value literal is the JSON serialization of the value, and the codec owns that medium. There is no bespoke codec PSL hook.
  • contract infer threading (cli) — the assembled pslBlockDescriptors namespace flows from inspectLiveSchema into printPsl, so an inferred contract can print extension blocks.
  • Round-trip + codec-drives-output coverage — the declarative policy_select fixture now round-trips the full pipeline (parse → validate → lower → IR → serialize → hydrate → IR → print → re-parse → structurally-equivalent AST), and a dedicated printer test proves the codec — not the captured raw text — produces the literal.

A design decision worth a look

The codec owns the serialized form of a value parameter, on both sides. The original cut of this slice shipped a bespoke codec PSL hook (parsePslLiteral / printPslLiteral); that was rejected in Slice 1 in favour of the codec's existing JSON medium, and this PR was rebased onto main with that hook commit dropped and the printer reworked to encodeJson/decodeJson + JSON.parse/JSON.stringify.

The risk with that path is a test that can't tell "the codec serialized the value" apart from "the raw text passed through untouched" — an identity codec (encodeJson(v) => v) makes them indistinguishable. So the proof test uses a non-identity codec: decodeJson coerces a quoted "42" to the number 42, encodeJson emits a bare JSON number, and the printed literal is using = 42 (unquoted) — which can only come from the codec running on the value. Mutating renderValueParam to echo raw fails this test (using = "42" ≠ using = 42). This is also the exact value path an IR/value source would take, fabricated directly rather than waiting on a production block contributor.

Out of scope (later slices / first consumer)

  • PslNamespace → ADR 224 entries migration — Slice 3, TML-2849 (#757, to be rebased onto this).
  • ADR 126 revision + three-layer ADR + close-out — Slice 4, TML-2806.
  • A standalone value → raw lowering helper for IR-originated blocks — deferred to the first real block-contributing extension. The print seam already routes through the codec and is proven; the node stores raw, and there is no production contributor yet to fix a helper's signature against.

Verification

Gate Result
pnpm build (framework-components → psl-parser → psl-printer) clean
pnpm typecheck (psl-printer / cli) clean
pnpm test — psl-printer / cli 50 / 1317 pass
pnpm lint:deps clean
pnpm lint:casts delta=0 (the one new cast is a blindCast with reason, not a bare as)
pnpm fixtures:check clean — except a pre-existing supabase example failure (prisma-next: command not found, an env/PATH issue in that example) that reproduces independently of this PR

Relationships

  • #753 / TML-2804 — Slice 1, merged; this is its write-side mirror. Rebased onto main; the superseded codec-PSL-hook commit was dropped.
  • #757 / TML-2849 — Slice 3, stacked; will be rebased onto this branch.

Refs TML-2854.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Extension blocks are now properly printed and serialized in PSL documents with support for codec-based parameter rendering and custom block descriptors.
  • Tests

    • Added comprehensive test coverage for extension block printing, round-trip validation, and command integration with extension blocks.

@wmadden-electric
wmadden-electric requested a review from a team as a code owner June 7, 2026 15:18
@coderabbitai

coderabbitai Bot commented Jun 7, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@wmadden-electric, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 21 minutes and 37 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 74ddb6e1-edf1-4e8b-9c04-e57a655a7abf

📥 Commits

Reviewing files that changed from the base of the PR and between b3d7dab and e7e72c6.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (14)
  • packages/1-framework/2-authoring/psl-printer/package.json
  • packages/1-framework/2-authoring/psl-printer/src/ast-to-print-document.ts
  • packages/1-framework/2-authoring/psl-printer/src/print-document.ts
  • packages/1-framework/2-authoring/psl-printer/src/print-psl.ts
  • packages/1-framework/2-authoring/psl-printer/src/serialize-print-document.ts
  • packages/1-framework/2-authoring/psl-printer/test/declarative-policy-select.round-trip.test.ts
  • packages/1-framework/2-authoring/psl-printer/test/generic-extension-block-printer.test.ts
  • packages/1-framework/3-tooling/cli/src/commands/contract-infer.ts
  • packages/1-framework/3-tooling/cli/src/commands/inspect-live-schema.ts
  • packages/1-framework/3-tooling/cli/src/control-api/client.ts
  • packages/1-framework/3-tooling/cli/src/control-api/types.ts
  • packages/1-framework/3-tooling/cli/test/commands/contract-infer.command.test.ts
  • packages/1-framework/3-tooling/cli/test/commands/db-schema.command.test.ts
  • packages/1-framework/3-tooling/cli/test/commands/inspect-live-schema.test.ts
📝 Walkthrough

Walkthrough

Adds extension-aware printing: carry extension blocks through print document, implement descriptor-dispatched serialization with param rendering (ref/value/option/list) and codec normalization, expose printer options, surface descriptors from control-client, and add tests and CLI wiring to pass descriptors to the printer.

Changes

Extension Block Printing Pipeline

Layer / File(s) Summary
Type contracts and print document shape
packages/1-framework/2-authoring/psl-printer/package.json, packages/1-framework/2-authoring/psl-printer/src/print-document.ts, packages/1-framework/2-authoring/psl-printer/src/ast-to-print-document.ts
PrintNamespaceSection adds extensionBlocks: readonly PslExtensionBlock[] to carry extension blocks from AST through print document. astDocumentToPrintDocument populates the field from namespace.extensionBlocks or empty array. Workspace dependency @prisma-next/utils added.
Dispatch map and parameter rendering
packages/1-framework/2-authoring/psl-printer/src/serialize-print-document.ts
Introduces SerializePrintDocumentOptions with optional pslBlockDescriptors and codecLookup. Builds a per-call dispatch map keyed by descriptor discriminator and implements serializeExtensionBlock with renderParamValue/renderValueParam handling ref/option/list/value kinds and codec-driven normalization.
Printer entry point
packages/1-framework/2-authoring/psl-printer/src/print-psl.ts
Adds PrintPslOptions and PslBlockDescriptorsNamespace alias; updates printPslFromAst(ast, options = {}) to conditionally forward pslBlockDescriptors and codecLookup into serializePrintDocument.
Control API and CLI wiring
packages/1-framework/3-tooling/cli/src/control-api/client.ts, packages/1-framework/3-tooling/cli/src/control-api/types.ts, packages/1-framework/3-tooling/cli/src/commands/inspect-live-schema.ts, packages/1-framework/3-tooling/cli/src/commands/contract-infer.ts
Adds ControlClient.getPslBlockDescriptors() and ControlClientImpl implementation, extends InspectLiveSchemaResult to include pslBlockDescriptors, retrieves descriptors from control client in inspect-live-schema, and passes namespace into printPsl in contract-infer.
Generic extension block printer tests
packages/1-framework/2-authoring/psl-printer/test/generic-extension-block-printer.test.ts
New suite with stub codec/descriptor and helpers for PslExtensionBlock params; verifies rendering of ref/value/option/list, deterministic param ordering, codec-driven value serialization, and error cases for unknown discriminators or missing codecs.
Round-trip and CLI command tests
packages/1-framework/2-authoring/psl-printer/test/declarative-policy-select.round-trip.test.ts, packages/1-framework/3-tooling/cli/test/commands/contract-infer.command.test.ts, packages/1-framework/3-tooling/cli/test/commands/db-schema.command.test.ts, packages/1-framework/3-tooling/cli/test/commands/inspect-live-schema.test.ts
Adds full round-trip test: parse → validate → print → re-parse and IR compare for policy_select. Updates CLI tests and hoisted mocks to include and exercise getPslBlockDescriptors, asserting printed policy_select block output contains expected parameters.

Sequence Diagram(s)

sequenceDiagram
  participant inspectLiveSchema as inspect-live-schema
  participant controlAPI as ControlClient
  participant contractInfer as contract-infer
  participant printer as printPslFromAst
  participant serializer as serializePrintDocument
  inspectLiveSchema->>controlAPI: init() / getPslBlockDescriptors()
  controlAPI-->>inspectLiveSchema: pslBlockDescriptors
  inspectLiveSchema-->>contractInfer: pslBlockDescriptors
  contractInfer->>printer: ast, { pslBlockDescriptors: namespace }
  printer->>serializer: doc, { pslBlockDescriptors, codecLookup }
  serializer->>serializer: buildBlockDispatchMap()
  serializer->>serializer: serializeNamespaceContents(blockDispatchMap, codecLookup)
  serializer->>serializer: serializeExtensionBlock(descriptor, params)
  serializer-->>printer: PSL text
  printer-->>contractInfer: PSL text
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • prisma/prisma-next#753: Adds parsing and validation of PslNamespace.extensionBlocks with descriptors and codec lookup; this PR serializes those blocks using the same descriptor/codec plumbing.

Poem

🐇 I hopped through AST and doc, then danced with block descriptors bright,

Ref, value, option, list — each rendered just right.
From control stack to CLI I carried the flow,
Printed PSL gleams where extension blocks grow. 🎨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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 title clearly and specifically describes the main changes: implementing a generic PSL printer for declarative blocks and updating contract infer for the write side (Slice 2).
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 unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch tml-2854-slice-2-generic-printer-contract-infer

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 7, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@prisma-next/extension-author-tools

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

@prisma-next/mongo-runtime

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

@prisma-next/family-mongo

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

@prisma-next/sql-runtime

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

@prisma-next/family-sql

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

@prisma-next/extension-arktype-json

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

@prisma-next/middleware-cache

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

@prisma-next/mongo

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

@prisma-next/extension-paradedb

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

@prisma-next/extension-pgvector

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

@prisma-next/extension-postgis

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

@prisma-next/postgres

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

@prisma-next/sql-orm-client

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

@prisma-next/sqlite

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

@prisma-next/extension-supabase

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/extension-supabase@754

@prisma-next/target-mongo

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

@prisma-next/adapter-mongo

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

@prisma-next/driver-mongo

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

@prisma-next/contract

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

@prisma-next/utils

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

@prisma-next/config

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

@prisma-next/errors

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

@prisma-next/framework-components

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

@prisma-next/operations

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

@prisma-next/ts-render

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

@prisma-next/contract-authoring

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

@prisma-next/ids

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

@prisma-next/psl-parser

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

@prisma-next/psl-printer

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

@prisma-next/cli

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

@prisma-next/cli-telemetry

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

@prisma-next/emitter

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

@prisma-next/migration-tools

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

prisma-next

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

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

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

@prisma-next/mongo-codec

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

@prisma-next/mongo-contract

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

@prisma-next/mongo-value

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

@prisma-next/mongo-contract-psl

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

@prisma-next/mongo-contract-ts

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

@prisma-next/mongo-emitter

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

@prisma-next/mongo-schema-ir

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

@prisma-next/mongo-query-ast

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

@prisma-next/mongo-orm

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

@prisma-next/mongo-query-builder

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

@prisma-next/mongo-lowering

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

@prisma-next/mongo-wire

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

@prisma-next/sql-contract

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

@prisma-next/sql-errors

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

@prisma-next/sql-operations

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

@prisma-next/sql-schema-ir

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

@prisma-next/sql-contract-psl

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

@prisma-next/sql-contract-ts

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

@prisma-next/sql-contract-emitter

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

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

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

@prisma-next/sql-relational-core

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

@prisma-next/sql-builder

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

@prisma-next/target-postgres

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

@prisma-next/target-sqlite

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

@prisma-next/adapter-postgres

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

@prisma-next/adapter-sqlite

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

@prisma-next/driver-postgres

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

@prisma-next/driver-sqlite

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

commit: e7e72c6

@github-actions

github-actions Bot commented Jun 7, 2026 •

Copy link
Copy Markdown

size-limit report 📦

Path Size
postgres / no-emit 147.85 KB (0%)
postgres / emit 117.65 KB (0%)
mongo / no-emit 76.67 KB (0%)
mongo / emit 70.96 KB (0%)
cf-worker / no-emit 177.77 KB (0%)
cf-worker / emit 144.31 KB (0%)

Base automatically changed from tml-2804-slice-1-declarative-block-descriptor-generic to main June 8, 2026 05:27
@wmadden-electric
wmadden-electric force-pushed the tml-2854-slice-2-generic-printer-contract-infer branch from 71ffbca to 0ca207e Compare June 8, 2026 05:51
@wmadden-electric wmadden-electric changed the title TML-2854: generic printer + contract infer for declarative PSL blocks (Slice 2 — write side) TML-2854: generic PSL printer + contract infer for declarative blocks (Slice 2 — write side) Jun 8, 2026

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

Overall the changes look good. But the terminology pslBlocksNamespace confuses me. This is the complete collection of available pslBlockDescriptors, right? Not related to a namespace in the contract?

In other places we called this simply pslBlockDescriptors. Why does it become a namespace here, a heavily overloaded term?

}),
);
});
});

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.

Wouldn't a better test be to compare the contract hashes of the two documents?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good call — the old assertion only matched a couple of AST fields. A literal contract hash is not available at this layer (the test works on the parsed AST; producing a contract hash means lowering to IR → emitting → hashing, which tests the emitter, not the round-trip). The right-sized equivalent: I now lower both the original and the printed-then-reparsed block to PolicySelectIr and compare the serialized IR — the contract-bound artifact, i.e. the semantic identity a hash stands for, and debuggable on failure. (b3d7dab)

* 1. A `policy_select` node with all four parameter kinds renders to the expected PSL text.
* 2. A node whose discriminator has no registered descriptor throws.
* 3. Built-in print round-trip is unchanged (enums, models).
*/

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.

Do we test consistent output ordering?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added a test for this. The printer iterates Object.entries(descriptor.parameters), so output order follows the descriptor, not AST insertion order — but nothing proved it. The new test builds a block with params in reversed insertion order and asserts the printed output is still target, as, roles, using. (b3d7dab)

* PSL block descriptors register here; downstream commands pass this through to
* `printPsl` so contributed-block AST nodes round-trip back to source.
*/
readonly pslBlocksNamespace: AuthoringPslBlockDescriptorNamespace;

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.

This terminology confuses me. This is the complete collection of available pslBlockDescriptors, right? Not related to a namespace in the contract?

In other places we called this simply pslBlockDescriptors. Why does it become a namespace here, a heavily overloaded term?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed — renamed the CLI surface to `pslBlockDescriptors` / `getPslBlockDescriptors()` (and updated the JSDoc) to match the term used everywhere else and drop the overloaded "namespace". The framework type AuthoringPslBlockDescriptorNamespace keeps "Namespace" because it is a genuinely nested registry ({ [name]: Descriptor | Namespace }); only the CLI flat-collection identifiers were misleading. (b3d7dab)

wmadden-electric pushed a commit that referenced this pull request Jun 8, 2026
…antic round-trip, ordering test

Three review points on #754:
- Rename the CLI surface pslBlocksNamespace -> pslBlockDescriptors (and
  getPslBlocksNamespace -> getPslBlockDescriptors), matching the term used
  everywhere else and dropping the overloaded "namespace". The framework type
  AuthoringPslBlockDescriptorNamespace keeps "Namespace" — it is a genuinely
  nested registry; only the CLI flat-collection identifiers were misleading.
- Round-trip re-parse now compares the lowered IR of the original vs the
  printed-then-reparsed block (the contract-bound artifact) instead of matching
  a couple of AST fields — the semantic equivalence a contract hash stands for,
  and debuggable on failure.
- Add a printer test proving parameter output order follows the descriptor, not
  AST insertion order (guards fixtures:check / diff stability).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
wmadden-electric pushed a commit that referenced this pull request Jun 8, 2026
…antic round-trip, ordering test

Three review points on #754:
- Rename the CLI surface pslBlocksNamespace -> pslBlockDescriptors (and
  getPslBlocksNamespace -> getPslBlockDescriptors), matching the term used
  everywhere else and dropping the overloaded "namespace". The framework type
  AuthoringPslBlockDescriptorNamespace keeps "Namespace" — it is a genuinely
  nested registry; only the CLI flat-collection identifiers were misleading.
- Round-trip re-parse now compares the lowered IR of the original vs the
  printed-then-reparsed block (the contract-bound artifact) instead of matching
  a couple of AST fields — the semantic equivalence a contract hash stands for,
  and debuggable on failure.
- Add a printer test proving parameter output order follows the descriptor, not
  AST insertion order (guards fixtures:check / diff stability).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
wmadden-electric enabled auto-merge (squash) June 8, 2026 06:48
@wmadden-electric
wmadden-electric force-pushed the tml-2854-slice-2-generic-printer-contract-infer branch from b3d7dab to bd57d14 Compare June 8, 2026 06:48
wmadden and others added 5 commits June 8, 2026 09:44
Two-phase printer renders any declared block from its descriptor + uniform node, no contributed printer functions. Phase 1 carries extensionBlocks into PrintNamespaceSection.extensionBlocks; phase 2 resolves the descriptor by discriminator and renders each parameter by kind: ref->identifier, value->codec parse-then-print via printPslLiteralFor (normalises the literal), option->token, list->[items]. Throws (named) on a block whose discriminator has no registered descriptor. pslBlocks + codecLookup threaded as options into printPslFromAst/serializePrintDocument (CLI wiring is P3). Cherry-picked the #718 plumbing + throw; replaced the contributed printer() call with the generic render; dropped PslExtensionBlockPrinterContext. Built-in printing unchanged.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
ControlClient.getPslBlocksNamespace() exposes the assembled pslBlocks; inspect-live-schema carries it; contract infer threads it into printPsl(ast, { pslBlocks }) so declared blocks survive inference to disk. The fixture round-trip extends to the full chain parse->validate->lower->IR->serialize->hydrate->IR->print->re-parse, asserting an equivalent block; a command-level contract-infer test drives a real policy_select block to disk. codecLookup is not threaded through ControlClient (printer raw-fallback re-emits the verbatim authored literal — correct for infer; normalization is a follow-up if a family infer emits codec-typed values). Tightens the codecLookup/refCtx JSDoc.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Slice 1 (declarative PSL-block SPI, #753) renamed pslBlocks -> pslBlockDescriptors
(and the namespace type to AuthoringPslBlockDescriptorNamespace) and removed the
codec PSL hooks (parsePslLiteralFor/printPslLiteralFor) in favour of the codec's
JSON medium. Rework the generic printer + contract-infer to match: renderValueParam
now validates and renders a value param via codecLookup.get(id).decodeJson(JSON.parse(raw))
then JSON.stringify(encodeJson(...)), mirroring the parse-side validator. Sweep the
pslBlocks -> pslBlockDescriptors rename across the printer and CLI, and drop the
obsolete parsePslLiteral/printPslLiteral fixture overrides from the printer tests.

The dropped P1 commit (codec PSL print-back hook) is superseded by this JSON-medium
approach; only P2 (generic printer) and P3 (contract-infer) were replayed in the rebase.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
The existing printer tests used an identity codec (encodeJson(v) => v), so they
could not distinguish "echo the captured raw text" from "round-trip through the
codec" — the codec-drives-the-literal behaviour was unproven. Add a printer test
with a non-identity codec whose decodeJson coerces a quoted "42" to the number 42
and whose encodeJson emits a bare JSON number: the printed literal is `using = 42`
(unquoted), which can only come from the codec. A mutation that echoes raw fails
this test. Also covers the unregistered-codec throw. This is the print-back mirror
of Slice 1's parse-side validator and is the value path an IR/value source would
take, fabricated directly rather than waiting on a production block contributor.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…antic round-trip, ordering test

Three review points on #754:
- Rename the CLI surface pslBlocksNamespace -> pslBlockDescriptors (and
  getPslBlocksNamespace -> getPslBlockDescriptors), matching the term used
  everywhere else and dropping the overloaded "namespace". The framework type
  AuthoringPslBlockDescriptorNamespace keeps "Namespace" — it is a genuinely
  nested registry; only the CLI flat-collection identifiers were misleading.
- Round-trip re-parse now compares the lowered IR of the original vs the
  printed-then-reparsed block (the contract-bound artifact) instead of matching
  a couple of AST fields — the semantic equivalence a contract hash stands for,
  and debuggable on failure.
- Add a printer test proving parameter output order follows the descriptor, not
  AST insertion order (guards fixtures:check / diff stability).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
wmadden-electric force-pushed the tml-2854-slice-2-generic-printer-contract-infer branch from bd57d14 to 9416e8d Compare June 8, 2026 07:45
wmadden and others added 2 commits June 8, 2026 09:59
… threshold

serialize-print-document.ts sat below the psl-printer package thresholds
(statements 92.26% < 95%, branches 80% < 85%) because the new extension-block
printer paths were untested. Add tests for the genuinely-uncovered behaviour:
value literal passed through verbatim when no codecLookup is supplied, a value
literal that is not valid JSON throws, an AST parameter whose kind mismatches
its descriptor kind throws (ref/value/option/list), and descriptors registered
under a nested namespace resolve. psl-printer now 97.09% stmts / 90.1% branches.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
The prior run failed only on prisma-next-demo#test with exit 132 and
"Check failed: jit_page_->allocations_.erase(addr) == 1" — a V8 JIT
engine-level crash, not a Slice 2 test failure. Empty commit to re-run CI;
the bot token cannot re-run individual workflow jobs.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
wmadden-electric merged commit b228c47 into main Jun 8, 2026
19 of 20 checks passed
@wmadden-electric
wmadden-electric deleted the tml-2854-slice-2-generic-printer-contract-infer branch June 8, 2026 08:20
wmadden-electric pushed a commit that referenced this pull request Jun 8, 2026
All four slices delivered (#753/#754/#757 + this PR); the durable architecture
decisions landed in ADR 126/225 and the retro lessons in adr-writing.mdc +
docs/Testing Guide.md. The transient project workspace (spec, plans, slice
plans) drops with the close-out. No external references to scrub.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
wmadden added a commit that referenced this pull request Jun 8, 2026
…ecture docs

Make the architecture record match what Slices 1-3 shipped (#753/#754/#757):
- Rewrite ADR 126 from the superseded parseFn/validateFn/emitFn function SPI to
  the declarative AuthoringPslBlockDescriptor design: keyword + name + typed
  parameters (ref/value/option/list), interpreted by one generic framework
  parser/validator/printer; value rides the codec JSON medium; option is an
  authoring-token constraint, not a domain enum; the block lowers via the
  entityTypes factory.
- Add ADR 225: how the three layers carry a pack-contributed entity kind, tied
  by its discriminator (IR class -> entityTypes lowering -> declarative
  parse+print). Subsystem doc 6 points at it.
- Fix the AuthoringContributions.entities -> entityTypes doc-bug in AGENTS.md
  (CLAUDE.md symlinks it) and docs/reference/typescript-patterns.md.

Markdown-only. Project close-out (project-dir deletion + retro) follows separately.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
wmadden added a commit that referenced this pull request Jun 8, 2026
All four slices delivered (#753/#754/#757 + this PR); the durable architecture
decisions landed in ADR 126/225 and the retro lessons in adr-writing.mdc +
docs/Testing Guide.md. The transient project workspace (spec, plans, slice
plans) drops with the close-out. No external references to scrub.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-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