Repository navigation
feat(rust): ADR-0067 layer stack, prompt tier and crates.io release path - #655
Merged
Merged
Conversation
…s own their layout Three plan rows on the Rust lane, folded into one branch. - render-helper, output-parser and output-prompt generators over the metaobjects-render crate: a prompts, parsers and formats crate per package, held to the render, template-output and extract corpora; verify --templates checks prompt bodies; eject copies all three. - A6: the Rust crates join scripts/release.mjs as the fifth registry (crates.io after npm, dependency order, changed-since-tag selection, token and free-version preflight); a release-tag gate in ci-local. - W-RS-1 (ADR-0063): a syn-based layout ratchet whose allowlist only shrinks; nine rust writer-conformance cases, each a rustfmt fixed point under the generated crates' rustfmt.toml; generator options in metaobjects.config.json through Generator::configure, refused with ERR_UNKNOWN_GENERATOR_OPTION; a *Parts trait per shipped generator, one default method per output piece. Output is byte-identical except that assign now moves an array right-hand side to the next line where rustfmt does.
…s 0 and 1) rules-names writes a <package>_rules crate for a package with a lifecycle or a declared operation: lifecycle states and transitions (on the model's own enum), derived commands, operations, permissions and business errors as closed enums. contract-types writes a <package>_contract crate per package with a declared operation: input, output, business-error enum and error body per operation, the read shape of a returned projection, and the shared meta_contract wire error crate. Both are silent without the rules vocabulary, so default runs are unchanged; rules_inert holds them to adding files only.
…d update (ADR-0067 layer 3) A <package>_store crate per package with a stored entity, over the shared meta_store crate: list (nine filter operators, sort, paging), count, get, create, update, delete, and per lifecycle the guarded update transition_<field>(id, from, to). Postgres and SQLite. Tested on SQLite in memory against the persistence corpus rows; the rules-inert test holds the data-access layer to appending the guarded update only.
…tore on Postgres A throwaway Postgres (docker run --rm, tmpfs, durability off) per test run, a fresh database per scenario, the committed schema and seeds, and each query through the generated store functions, normalized per normalization.md. 25 of 55 scenarios pass; many-to-many, projections and reports are on a shrink-only ledger. Fixes it found in meta_store: a string field stored in its own SQL type (@dbColumnType uuid/jsonb) is cast on write and read; a negative duration binds as microseconds; temporals truncate to milliseconds.
…hed to report-shapes.json
…rated store A served read (a concrete projection or report whose read source is a view) gets a read-only struct in its model crate, from the report shape for a report, and a read-only store module. A view's numbers are read through a cast to their field's type. The persistence runner runs the 24 report and 3 projection scenarios; only the three many-to-many ones stay on its ledger.
… store A many-to-many relationship of a keyed entity gets <relation>_of, the related rows read through the junction in one statement: hetero, directed self-join, and symmetric self-join, which keeps a row relating a record to itself. The junction and its keys come from the core's derive_m2m_fields, the derivation the loader's pairing rule now runs too. The persistence runner runs all 55 scenarios on Postgres and its ledger is empty.
main added rules-names and contract-types for C#; this branch added them for Rust under the same keys, so the shared registry held each key twice and the later one won. One entry each now names both ports, with the Rust shape in its concept.
…e-gate sandbox scripts/lib/rust-release.mjs carried JSDoc but matched no include in tsconfig.scripts.json, so the scripts typecheck gate refused it; it is now included and fully typed. The eject-release-gate test copies the release scripts into a sandbox, and release.mjs imports rust-release.mjs, so the sandbox list names it too.
…h the generated store meta_store::transition takes a transition's @condition (a Condition over the CHECK subset: the six comparisons, null tests, and/or/not, coalesce) and ANDs it into the one guarded UPDATE; a literal compared with a field takes that field's stored form. The Rust persistence runner drives op: guardedUpdate, so all 56 Postgres scenarios run with an empty ledger.
…r 4) The `service` generator writes a `<package>_service` crate per package with a stored entity: `<Pkg>Service`, generic over the pool and the actor type, with the derived list (page 50, or `api.pagination`), get, traversal, create, update and delete, a command per derived transition and a shell per declared operation. Each write runs in one sqlx transaction, or in a caller's through its `_in` twin, with ADR-0066 §6's checks in order, `state_managed`, the initial-state create rule and `@autoSet` stamping (ADR-0045 Amendment 1). The app supplies `<Pkg>Policy`, `<Pkg>Bodies`, `<Pkg>Hooks` (before/after over the `<Pkg>Before`/`<Pkg>After` enums) and `<Pkg>Events`; the shared `meta_service` crate holds the error codes and the guarded move. The stored-entity and rules-names walks move into the engine module `metaobjects_codegen::layers`, so ejected generators call the same walk. The writer gains `where_block`. tests/service.rs runs the rules corpus scenarios through the service on SQLite and checks @autoset on the tph model; rules_inert pins what the service changes; the scale budget rises for the new crate. The HTTP transport is the next row (L-RS-4).
Conflicts: the Rust template gate was built on both sides. Main's CLI gate (templates.rs, with the @responseRef reply check) is kept; the branch's duplicate check_templates CLI path is dropped. Main's verify.rs is kept with the branch's const PayloadField constructors (Cow) that generated render helpers need, so the Rust override fixtures expected-drift.rust.json go. Plan::build takes main's reference set. CHANGELOG bullets move to changelog.d fragments.
…utes) The Rust port's sixth ADR-0067 layer: an opt-in `service-routes` generator writes a `<package>_http` crate per package and a shared `meta_http` crate, whose `router(service, actor)` mounts the generated service with the derived CRUD, traversal, transition and declared-operation routes, the REST-standard list query and the named refusals. - `cargo meta init --transport` lists it; a plain init and a project with no generator list leave it out, and `gen --list` marks it opt-in. - Credential fields are never returned; an entity with a read view beside its table is read back through the view (the store's `Table.read`). - A field with no `@sortable` is sortable when it is filterable, as in TS. - The shared service walk moves to `layers::service`, which an owned copy may name. - Tests: the api-contract generated lane over HTTP (core, write-through, secret-fields, list-query, rules and its settings, 77 scenarios; the rest ledgered), all 95 list-query cases, and `examples/rust-service/`, a tasks service the rust lane verifies and tests. - Docs: the Rust port page, ADR-0065 Amendment 7, a Rust column in CONFORMANCE.md, the corpus READMEs and a changelog fragment.
- A text key is borrowed and an int key read into its own type (int_key is generic, out of range is invalid_id); text_key is gone. - A declared route over a derived one is ERR_NAME_COLLISION at gen, not an axum panic at startup. - Handler locals are on_<name>, so no operation name shadows the router. - --generators naming an opt-in generator with no list is refused. - The service and transport crate names are claimed like the store's; the suffixes live once, in plan. - A report column carrying a credential's type stays a credential. - gen_bench writes the prompt body the fitness model references.
… build the plan once per generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Changed
rules-namesandcontract-types(layers 0–1, business-rules vocabulary as closed enums and per-operation input/output types),repository(layer 3 — a<package>_storecrate per package on sqlx for Postgres and SQLite, with the nine filter operators, sort/paging, and the guarded-updatetransition_<field>),service(layer 4 — transactional writes running the ADR-0066 check order in sequence, app-ownedPolicy/Bodies/Hooks/Eventstraits), and the opt-inservice-routes(layer 5 — an axumRouterover the service with derived CRUD, traversal, transition-command and declared-operation routes, the REST list query and named 400s, added bycargo meta init --transport). Also in this stack: the prompt tier (render-helper,output-parser,output-promptwriting<package>_prompts/_parsers/_formatscrates), report/projection reads through a view's cast columns (FR-044, shape derivation byte-matched toreport-shapes.json), and many-to-many traversal through the store (FR-018, incl. directed and@symmetricself-joins). The walks the layer generators share live inmetaobjects_codegen::layers, so an ejected generator calls the same walk the shipped one does.generatorsentries may be{"name": ..., "options": {...}}(unknown options refused withERR_UNKNOWN_GENERATOR_OPTION, including under--generatorsnarrowing); every shipped generator exposes a*Partstrait (eleven in all) so an owned generator overrides one piece and keeps the rest; asyn-based layout ratchet (tests/layout_ratchet.rs, shrink-only allowlist) and eight new Rustwriter-conformancecases pin the dialect — the one output change isassignmoving an array right-hand side to the next line where rustfmt puts it.guarded-updateandroundtripamong them; ledger holds only three many-to-many scenarios), the list-query corpus (95 cases), and the api-contract corpus's generated lane over HTTP (77 scenarios:core,write-through,secret-fields,list-query,rulesand its settings variants). The Rust crates join the release path as the fifth registry (ADR-0065 Amendment 3):scripts/lib/rust-release.mjspublishes the four crates to crates.io after npm behind the same confirm, with a--crates=publish|skipoverride and a preflight that checks the token and version before any bump — nothing is published.examples/rust-service/is a complete tasks service built by the new generators and checked by therustlane; docs (docs/ports/rust.md, feature pages, CONFORMANCE, RELEASING), ADR-0063/0065, the conformance READMEs and the changelog entries are updated to match.Validation
Risk Assessment
Testing
The configured test command scripts/ci-local.sh --affected --strict-toolchains had already run and passed at the target commit, supplying broad regression; this turn changed no source or test files, so it was not re-run. On top of that I drove three live scenarios: (1) the generated axum tasks API from examples/rust-service, built and served on a local port, answered every documented behavior over curl — create, the REST list query, lifecycle transitions with 403/409/400 named refusals, the state_managed rule, and the public reopen; (2) the restored cargo-meta CLI ran init, gen --list, gen, verify and then refused a hand-edited generated file in verify and gen on a disposable project, and the committed example estate regenerated byte-identical; (3) the review-fixed route-collision guard refused a declared GET /countries/{code} over the derived /countries/{id} with ERR_NAME_COLLISION through the real binary, while the focused service_routes_keys suite (4 passed) proved a same-shaped POST route still compiles and serves beside the derived GET in a real axum router. No screenshot was needed: all surfaces are CLI/HTTP, and the evidence is captured transcripts. Scratch fixtures were deleted, the app server was stopped, and the worktree is clean.
Evidence: Generated axum tasks API driven over HTTP with curl (create, list query, transitions, 403/409/400 refusals, public reopen)
Evidence: cargo-meta CLI on a fresh project: init (transport opt-in absent), gen --list counts, gen 41 files, verify green, example estate regenerates unchanged
Evidence: Adversarial drives: ERR_NAME_COLLISION on GET /countries/{code} vs derived /countries/{id} (exit 1), verify/gen hand-edit refusal (exit 1)
Evidence: Focused route-keys suite: 4 passed, including the placeholder-name collision refusal and the probe that builds and serves the mixed-method route pair in a real axum router
Pipeline
Updates from git push no-mistakes
✅ **Intent** - passed
✅ No issues found.
⏭️ **Rebase** - skipped
docs/CONFORMANCE.md- merge conflict rebasing onto origin/maindocs/ports/rust.md- merge conflict rebasing onto origin/mainscripts/release.mjs- merge conflict rebasing onto origin/mainserver/rust/metaobjects-cli/Cargo.toml- merge conflict rebasing onto origin/mainserver/rust/metaobjects-cli/src/lib.rs- merge conflict rebasing onto origin/mainserver/rust/metaobjects-cli/tests/cli.rs- merge conflict rebasing onto origin/mainserver/rust/metaobjects-render/src/lib.rs- merge conflict rebasing onto origin/mainserver/rust/metaobjects-render/src/verify.rs- merge conflict rebasing onto origin/mainserver/rust/metaobjects-render/tests/verify_conformance.rs- merge conflict rebasing onto origin/main✅ **Review** - 3 findings, all fixed
server/rust/metaobjects-codegen/src/service_routes.rs- the route-collision check compared paths as raw strings, soGET /countries/{code}over the derived/countries/{id}passed it and axum would panic building the router. Fixed in d2f3775: paths that differ only in placeholder names are one route, andgenrefuses the pair withERR_NAME_COLLISION.server/rust/metaobjects-cli/tests/cli.rs- an earlier merge of main had left thecargo metaend-to-end suite as an empty file. Fixed in bdbdb93: main's suite restored with this branch's changes re-applied, plus theservice-routesopt-in in the list counts.docs/CONFORMANCE.md:39anddocs/features/cli.md- stale port coverage text (list-query/rules named TypeScript and C# only; the Rust CLI called unpublished). Fixed in bdbdb93: the row names Rust forlist-query/andrules/, and the CLI line matchesdocs/RELEASING.md.scripts/ci-local.sh --affected --strict-toolchainsBaseline broad regression: scripts/ci-local.sh --affected --strict-toolchains (already ran and passed at target commit bdbdb93d35; no source or test files changed in this turn, so not re-run)Scenario 1: built examples/rust-service (cargo build --release -p tasks_app, exit 0), ran the binary on a local port with in-memory SQLite, drove it with curl over TCP: POST create (201), REST list query filter/sort/withCount, POST /1/start (200 doing), finish without lead (403 forbidden), finish as lead (200 done), double start (409 invalid_transition), PATCH naming a different state (409 state_managed), PATCH naming the current state (200 no-op), reopen with no caller (200), invalid filter field (400 invalid_filter_field), unknown create field (400 unknown_fields), DELETE (204)Scenario 2: server/rust/target/release/cargo-meta meta init --project (10 of 11 generators, service-routes absent), meta gen --list (service-routes [not configured]), meta gen on a Task model (41 files), meta verify (in sync, 1 lifecycle 3 transitions), hand-edited generated/tasks/src/task.rs then meta verify --codegen (exit 1 naming the drifted file) and meta gen (exit 1, refused to overwrite)Scenario 2b: cargo meta gen in examples/rust-service reported 35 files unchanged and git status stayed clean, proving the committed generated/ output is what gen writes todayScenario 3 adversarial: cargo meta gen on a fixture with Country keyed by code plus declared GET /countries/{code} (exit 1, ERR_NAME_COLLISION naming get_country and by_code, path normalized to /countries/{id})Scenario 3b: cargo test -p metaobjects-codegen --test service_routes_keys (4 passed), including a_declared_route_that_differs_from_a_derived_one_by_a_placeholder_name_is_refused and a_declared_route_that_shares_a_derived_paths_shape_under_another_method_serves_with_it, which generates the PUBLISH model, compiles the generated workspace and serves POST /countries/{code} beside derived GET /countries/{id} through a real axum routerfixtures/api-contract-conformance/jsonb/README.md:150- The api-contract sub-corpus READMEs (jsonb/ line 150, projection/ line 96, report/ line 161, tph/ line 107) still say lane coverage runs 'on all five ports'. Rust does not run these sub-corpora (its api_contract.rs LEDGER lists them), so the statements are not false — they describe the five ports wired to each sub-corpus — but a reader comparing with the updated CONFORMANCE.md matrix row sees six ports. Left untouched per the one-owner policy: docs/CONFORMANCE.md's matrix row (updated by this change) owns per-port corpus standing, and these sections flip naturally when each port's work lands. Follow-up option: add a one-line Rust carve-out to each lane-coverage section when the sub-corpus is built.docs/features/extending-with-providers.md:148- Several 'all five ports' claims predate this change and were already incomplete for Rust at the base commit (Rust providers, field.map BTreeMap codegen in docs/features/field-types.md line 78, and the cross-field validation cases in docs/features/entities.md line 391 all existed and passed at d9ddffa). This change did not alter those facts, so they are out of scope here and were left alone. A repo-wide 'five ports' sweep would touch many files and is better as its own pass, ideally alongside the next Rust capability landing.✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.
Gate: one no-mistakes run (rebase step skipped: the branch merges cleanly with main; review fixed three findings: a placeholder-name route collision, a test suite an earlier merge had emptied, stale Rust doc lines).