Repository navigation
TML-2854: generic PSL printer + contract infer for declarative blocks (Slice 2 — write side) - #754
Conversation
|
Warning Review limit reached
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 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 configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (14)
📝 WalkthroughWalkthroughAdds 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. ChangesExtension Block Printing Pipeline
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
@prisma-next/extension-author-tools
@prisma-next/mongo-runtime
@prisma-next/family-mongo
@prisma-next/sql-runtime
@prisma-next/family-sql
@prisma-next/extension-arktype-json
@prisma-next/middleware-cache
@prisma-next/mongo
@prisma-next/extension-paradedb
@prisma-next/extension-pgvector
@prisma-next/extension-postgis
@prisma-next/postgres
@prisma-next/sql-orm-client
@prisma-next/sqlite
@prisma-next/extension-supabase
@prisma-next/target-mongo
@prisma-next/adapter-mongo
@prisma-next/driver-mongo
@prisma-next/contract
@prisma-next/utils
@prisma-next/config
@prisma-next/errors
@prisma-next/framework-components
@prisma-next/operations
@prisma-next/ts-render
@prisma-next/contract-authoring
@prisma-next/ids
@prisma-next/psl-parser
@prisma-next/psl-printer
@prisma-next/cli
@prisma-next/cli-telemetry
@prisma-next/emitter
@prisma-next/migration-tools
prisma-next
@prisma-next/vite-plugin-contract-emit
@prisma-next/mongo-codec
@prisma-next/mongo-contract
@prisma-next/mongo-value
@prisma-next/mongo-contract-psl
@prisma-next/mongo-contract-ts
@prisma-next/mongo-emitter
@prisma-next/mongo-schema-ir
@prisma-next/mongo-query-ast
@prisma-next/mongo-orm
@prisma-next/mongo-query-builder
@prisma-next/mongo-lowering
@prisma-next/mongo-wire
@prisma-next/sql-contract
@prisma-next/sql-errors
@prisma-next/sql-operations
@prisma-next/sql-schema-ir
@prisma-next/sql-contract-psl
@prisma-next/sql-contract-ts
@prisma-next/sql-contract-emitter
@prisma-next/sql-lane-query-builder
@prisma-next/sql-relational-core
@prisma-next/sql-builder
@prisma-next/target-postgres
@prisma-next/target-sqlite
@prisma-next/adapter-postgres
@prisma-next/adapter-sqlite
@prisma-next/driver-postgres
@prisma-next/driver-sqlite
commit: |
size-limit report 📦
|
71ffbca to
0ca207e
Compare
contract infer for declarative blocks (Slice 2 — write side)
wmadden
left a comment
There was a problem hiding this comment.
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?
| }), | ||
| ); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
Wouldn't a better test be to compare the contract hashes of the two documents?
There was a problem hiding this comment.
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). | ||
| */ |
There was a problem hiding this comment.
Do we test consistent output ordering?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)
…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]>
…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]>
b3d7dab to
bd57d14
Compare
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]>
bd57d14 to
9416e8d
Compare
… 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]>
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]>
…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]>
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]>
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 inferthreads 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_selectkeyword — it reads the descriptor (keyword,name, typedparameters) and renders each parameter by its declared kind.What's in this PR
psl-printer) —serializePrintDocumentbuilds a discriminator-keyed dispatch map from the registeredpslBlockDescriptorsand 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.valueparams are serialized through the codec, not echoed —renderValueParamruns a value literal throughJSON.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 inferthreading (cli) — the assembledpslBlockDescriptorsnamespace flows frominspectLiveSchemaintoprintPsl, so an inferred contract can print extension blocks.policy_selectfixture 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 ontomainwith that hook commit dropped and the printer reworked toencodeJson/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:decodeJsoncoerces a quoted"42"to the number42,encodeJsonemits a bare JSON number, and the printed literal isusing = 42(unquoted) — which can only come from the codec running on the value. MutatingrenderValueParamto echorawfails 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 224entriesmigration — Slice 3, TML-2849 (#757, to be rebased onto this).value → rawlowering 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 storesraw, and there is no production contributor yet to fix a helper's signature against.Verification
pnpm build(framework-components → psl-parser → psl-printer)pnpm typecheck(psl-printer / cli)pnpm test— psl-printer / clipnpm lint:depspnpm lint:castsdelta=0(the one new cast is ablindCastwith reason, not a bareas)pnpm fixtures:checksupabaseexample failure (prisma-next: command not found, an env/PATH issue in that example) that reproduces independently of this PRRelationships
main; the superseded codec-PSL-hook commit was dropped.Refs TML-2854.
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Tests