From 4d13f167df2bbcdff1a77fc5cbd7eb3ceaac0dfa Mon Sep 17 00:00:00 2001 From: Doug Mealing Date: Thu, 19 Nov 2026 20:17:35 -0500 Subject: [PATCH 1/5] feat(rust): cargo meta init, verify and eject, and the client and commands generators Phase 2 of the Rust port (preview, ADR-0065 Amendment 1): a Rust developer can run the whole codegen loop on a JSON or YAML model. Run engine and CLI - gen removes a generated file nothing emits any more (an edited one is refused by name) and prints a change report with the crates to re-check. - cargo meta init scaffolds the config, the ignore rules and a first metadata file, writing only what is missing. - cargo meta verify --codegen renders in memory, compares with disk and exits 1 on drift; --db, --templates and --deps exit 2 with the reason. - cargo meta eject writes a codegen/ crate the project owns; gen and verify then build and run it. --undo takes back copies still identical. - Exit codes follow the shared contract: 0, 1, 2. Generators - entity: Create and Patch bodies, validate(), exact decimals and signed durations in a generated meta_support crate, wire.nullMembers. - client (new): a typed reqwest client per served entity, derived from the REST contract, with typed filters and sorts. - commands (new, Rust-only by decision): clap command groups over the client, as a library with no main. Gates - validation-conformance through the generated validate(), the decimal and duration wire vectors, the core writer corpus, both columns of the skip corpus, and the generator registry with the eject contract. - A compile gate builds and format-checks every generator's output and drives the generated client and commands over HTTP, from a committed lockfile. A scale gate holds twenty copies of the fitness model to linear growth and a size budget. The generator registry records client and commands with rust as their only port. Schema migrations and database checks stay with the Node meta tool. Nothing is published. --- CHANGELOG.md | 41 +- README.md | 4 +- docs/CONFORMANCE.md | 34 +- docs/README.md | 2 +- docs/features/cli.md | 5 +- docs/features/own-your-codegen.md | 5 + docs/ports/rust.md | 253 ++- .../generator-registry-conformance/README.md | 22 +- .../registry.json | 32 +- scripts/bench-load/README.md | 2 +- scripts/bench-load/stages.py | 6 +- scripts/ci-local.sh | 11 +- server/rust/Cargo.lock | 2 + server/rust/Cargo.toml | 1 + server/rust/metaobjects-cli/Cargo.toml | 3 + server/rust/metaobjects-cli/src/lib.rs | 913 ++++++-- server/rust/metaobjects-cli/tests/cli.rs | 516 ++++- server/rust/metaobjects-codegen/Cargo.toml | 1 + .../metaobjects-codegen/examples/gen_bench.rs | 7 +- server/rust/metaobjects-codegen/src/client.rs | 879 ++++++++ .../rust/metaobjects-codegen/src/commands.rs | 830 +++++++ server/rust/metaobjects-codegen/src/eject.rs | 525 +++++ .../metaobjects-codegen/src/emitted/mod.rs | 24 + .../src/emitted/pattern.rs | 520 +++++ .../src/emitted/validation.rs | 449 ++++ .../metaobjects-codegen/src/emitted/wire.rs | 434 ++++ server/rust/metaobjects-codegen/src/engine.rs | 495 ++++- server/rust/metaobjects-codegen/src/entity.rs | 1759 +++++++-------- .../rust/metaobjects-codegen/src/generator.rs | 15 +- server/rust/metaobjects-codegen/src/lib.rs | 33 +- server/rust/metaobjects-codegen/src/plan.rs | 1854 ++++++++++++++++ server/rust/metaobjects-codegen/src/writer.rs | 625 ++++++ .../metaobjects-codegen/tests/client_edges.rs | 181 ++ .../metaobjects-codegen/tests/common/mod.rs | 210 +- .../rust/metaobjects-codegen/tests/compile.rs | 457 ++-- .../metaobjects-codegen/tests/entity_edges.rs | 1 + .../metaobjects-codegen/tests/gen-check.lock | 1905 +++++++++++++++++ .../tests/generator_registry.rs | 190 ++ .../rust/metaobjects-codegen/tests/golden.rs | 56 +- .../tests/golden/shop/meta_cli/Cargo.toml | 13 + .../tests/golden/shop/meta_cli/rustfmt.toml | 8 + .../tests/golden/shop/meta_client/Cargo.toml | 12 + .../golden/shop/meta_client/rustfmt.toml | 8 + .../tests/golden/shop/meta_support/Cargo.toml | 10 + .../golden/shop/meta_support/rustfmt.toml | 8 + .../tests/golden/shop/meta_support/src/lib.rs | 8 + .../tests/golden/shop/shop/Cargo.toml | 1 + .../tests/golden/shop/shop/rustfmt.toml | 4 +- .../tests/golden/shop/shop/src/address.rs | 10 + .../tests/golden/shop/shop/src/category.rs | 64 + .../tests/golden/shop/shop/src/lib.rs | 8 + .../tests/golden/shop/shop/src/order.rs | 124 +- .../golden/shop/shop/src/order_category.rs | 37 + .../tests/golden/shop/shop_billing/Cargo.toml | 1 + .../golden/shop/shop_billing/rustfmt.toml | 4 +- .../golden/shop/shop_billing/src/invoice.rs | 37 + .../tests/golden/shop/shop_billing/src/lib.rs | 2 + .../tests/golden/shop/shop_cli/Cargo.toml | 15 + .../tests/golden/shop/shop_cli/rustfmt.toml | 8 + .../golden/shop/shop_cli/src/category.rs | 114 + .../tests/golden/shop/shop_cli/src/lib.rs | 36 + .../tests/golden/shop/shop_cli/src/order.rs | 196 ++ .../shop/shop_cli/src/order_category.rs | 71 + .../tests/golden/shop/shop_client/Cargo.toml | 12 + .../golden/shop/shop_client/rustfmt.toml | 8 + .../golden/shop/shop_client/src/category.rs | 203 ++ .../tests/golden/shop/shop_client/src/lib.rs | 16 + .../golden/shop/shop_client/src/order.rs | 340 +++ .../shop/shop_client/src/order_category.rs | 84 + .../rust/metaobjects-codegen/tests/pattern.rs | 240 +++ .../metaobjects-codegen/tests/run_engine.rs | 265 ++- .../rust/metaobjects-codegen/tests/scale.rs | 184 ++ .../tests/skip_conformance.rs | 181 +- .../tests/validation_conformance.rs | 123 ++ .../metaobjects-codegen/tests/wire_vectors.rs | 175 ++ .../tests/writer_conformance.rs | 134 ++ .../ADR-0065-rust-is-the-sixth-port.md | 113 + spec/decisions/README.md | 2 +- 78 files changed, 14770 insertions(+), 1411 deletions(-) create mode 100644 server/rust/metaobjects-codegen/src/client.rs create mode 100644 server/rust/metaobjects-codegen/src/commands.rs create mode 100644 server/rust/metaobjects-codegen/src/eject.rs create mode 100644 server/rust/metaobjects-codegen/src/emitted/mod.rs create mode 100644 server/rust/metaobjects-codegen/src/emitted/pattern.rs create mode 100644 server/rust/metaobjects-codegen/src/emitted/validation.rs create mode 100644 server/rust/metaobjects-codegen/src/emitted/wire.rs create mode 100644 server/rust/metaobjects-codegen/src/plan.rs create mode 100644 server/rust/metaobjects-codegen/src/writer.rs create mode 100644 server/rust/metaobjects-codegen/tests/client_edges.rs create mode 100644 server/rust/metaobjects-codegen/tests/gen-check.lock create mode 100644 server/rust/metaobjects-codegen/tests/generator_registry.rs create mode 100644 server/rust/metaobjects-codegen/tests/golden/shop/meta_cli/Cargo.toml create mode 100644 server/rust/metaobjects-codegen/tests/golden/shop/meta_cli/rustfmt.toml create mode 100644 server/rust/metaobjects-codegen/tests/golden/shop/meta_client/Cargo.toml create mode 100644 server/rust/metaobjects-codegen/tests/golden/shop/meta_client/rustfmt.toml create mode 100644 server/rust/metaobjects-codegen/tests/golden/shop/meta_support/Cargo.toml create mode 100644 server/rust/metaobjects-codegen/tests/golden/shop/meta_support/rustfmt.toml create mode 100644 server/rust/metaobjects-codegen/tests/golden/shop/meta_support/src/lib.rs create mode 100644 server/rust/metaobjects-codegen/tests/golden/shop/shop/src/order_category.rs create mode 100644 server/rust/metaobjects-codegen/tests/golden/shop/shop_cli/Cargo.toml create mode 100644 server/rust/metaobjects-codegen/tests/golden/shop/shop_cli/rustfmt.toml create mode 100644 server/rust/metaobjects-codegen/tests/golden/shop/shop_cli/src/category.rs create mode 100644 server/rust/metaobjects-codegen/tests/golden/shop/shop_cli/src/lib.rs create mode 100644 server/rust/metaobjects-codegen/tests/golden/shop/shop_cli/src/order.rs create mode 100644 server/rust/metaobjects-codegen/tests/golden/shop/shop_cli/src/order_category.rs create mode 100644 server/rust/metaobjects-codegen/tests/golden/shop/shop_client/Cargo.toml create mode 100644 server/rust/metaobjects-codegen/tests/golden/shop/shop_client/rustfmt.toml create mode 100644 server/rust/metaobjects-codegen/tests/golden/shop/shop_client/src/category.rs create mode 100644 server/rust/metaobjects-codegen/tests/golden/shop/shop_client/src/lib.rs create mode 100644 server/rust/metaobjects-codegen/tests/golden/shop/shop_client/src/order.rs create mode 100644 server/rust/metaobjects-codegen/tests/golden/shop/shop_client/src/order_category.rs create mode 100644 server/rust/metaobjects-codegen/tests/pattern.rs create mode 100644 server/rust/metaobjects-codegen/tests/scale.rs create mode 100644 server/rust/metaobjects-codegen/tests/validation_conformance.rs create mode 100644 server/rust/metaobjects-codegen/tests/wire_vectors.rs create mode 100644 server/rust/metaobjects-codegen/tests/writer_conformance.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 0132e8bd3e..dd835941ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,8 +50,7 @@ here.** project config, the engine's built code, each generator's identity and the flags match the stored key in `.fingerprint-rust.json` and every recorded output is still as the last run left it. The shared `fixtures/codegen-skip-conformance` corpus runs against it: every case the port can meet - runs, and the ones it cannot (templates, ejected generators, `verify`, a kept hand edit) are named - with the reason. The `entity` generator writes one crate per metadata package: serde structs for + runs, and the ones it cannot (templates, a kept hand edit) are named with the reason. The `entity` generator writes one crate per metadata package: serde structs for `object.entity` and `object.value` (inherited fields included, optional fields as `Option`, arrays as `Vec`, a map as `BTreeMap`), enums for `field.enum` (shared enums once, in their declaration's package) with the member symbols as the wire form, `Box` only where a by-value cycle needs it, and @@ -67,8 +66,42 @@ here.** must be a sub-directory of the project (the project root itself is refused), so every manifest key is project-relative; a named run (`cargo meta gen Order`) never skips and regenerates every file of the crates that contain the named objects, plus the transitive closure of the crates those - depend on, rather than merging; and there is no `verify`, `eject`, template or client generator - yet. Relationships, projections and reports are not emitted. Nothing is published. + depend on, rather than merging. Navigation across relationships is not emitted. Nothing is + published. + +- **Rust port's command line, in preview: `cargo meta init`, `verify --codegen` and `eject`, and + the `client` and `commands` generators (ADR-0065 Amendment 1).** A Rust developer can now run the + whole codegen loop on a JSON or YAML model. `init` scaffolds `.metaobjects/config.json`, the + ignore rules that keep `.hashes.json` committed and a first metadata file, writing only what is + missing. `gen` now removes a generated file nothing emits any more (an edited one is refused by + name) and prints what it created, updated and removed and which crates to re-check. `verify + --codegen` renders in memory, compares with disk, writes nothing and exits 1 on drift; locally it + may answer from the stored skip key, and `--full` or a set `CI` always renders. `--db`, + `--templates` and `--deps` exit 2 and say where that check lives. Exit codes are the shared ones + (0, 1, 2). `eject ` writes a `codegen/` crate the project owns (the copied generator + and the generator list); `gen` and `verify` then build and run it, `gen --list` shows how each + copy compares with the shipped source, and `eject --undo` takes back copies still identical. + There is no plugin contract: the engine's Rust API has no stability promise in preview. + The `entity` generator now also writes `Create` and `Patch` for every entity and a + `validate()` on value objects and both bodies (lengths, bounds, item counts, patterns, text + forms, nested value objects and the rules across members), exact decimals and signed durations + in a generated `meta_support` crate, and honors `wire.nullMembers`. The new `client` generator + writes a typed `reqwest` client per served entity from the REST contract: `list`, `page`, `get`, + `create`, `update`, `delete` and many-to-many traversal, with a query type that has one method + per `@filterable` field and operator and an enum of the `@sortable` fields, so a filter or sort + the server would refuse does not compile. The new `commands` generator writes `clap` command + groups over that client as a library (a `Subcommand` and an async `run`, no `main`), with + bodies checked by `validate()` before anything is sent. **`commands` is Rust-only by decision**, + recorded with `client` in the shared generator registry with `rust` as the only port. Generated + crates import nothing from MetaObjects. Gates: the port now runs `validation-conformance` + through the generated `validate()`, the `decimal-wire` and `duration-wire` vectors, the `core` + cases of `writer-conformance`, both columns of the skip corpus, and the generator registry with + the eject contract; a compile gate builds and format-checks every generator's output for two + models and drives the generated client and commands over HTTP against a local stub, from a + committed lockfile; and a scale gate holds twenty copies of the fitness model to linear growth + and a size budget. Not there yet: `fmt`, a template gate, server-side generators, and clients + for projections and reports. Schema migrations and database checks stay with the Node `meta` + tool for every server language (ADR-0015). Nothing is published. - **Cross-port stage benchmark and Rust port documentation.** `scripts/bench-load/stages.py` runs every port (TypeScript, Python, C#, Java, Kotlin, Rust) over the same model, stage by stage: load diff --git a/README.md b/README.md index 24988c552c..37429778fb 100644 --- a/README.md +++ b/README.md @@ -169,7 +169,7 @@ first-week wedge plan — and `meta init` picks up from there. | Kotlin | **Maven Central `8.2.0`** — codegen tier on top of Java: 17 generators (entity, Exposed table, names, relations, repository, output-parser, output-prompt, render-helper, extractor, filter-allowlist, validator, Spring config, storedProc, Spring controller, requirement-tests, api-docs, report-export); 24 / 24 persistence-conformance | [`docs/ports/kotlin.md`](docs/ports/kotlin.md) | [`server/java/codegen-kotlin/`](server/java/codegen-kotlin/) · [`server/java/metadata-ktx/`](server/java/metadata-ktx/) | | C# | **NuGet `1.2.0`** — loader + conformance + EF Core codegen + render engine + `dotnet meta` CLI all shipped | [`docs/ports/csharp.md`](docs/ports/csharp.md) | [`server/csharp/`](server/csharp/) | | Python | **PyPI `1.2.0`** — loader + conformance + render + entity-model codegen + ObjectManager runtime shipped; schema migrations are TS-owned (ADR-0015) | [`docs/ports/python.md`](docs/ports/python.md) | [`server/python/`](server/python/) | -| Rust | **Preview, unpublished** — loader (JSON + YAML), project and source resolution, naming and all 40 validation passes; 526 / 526 metamodel conformance; `cargo meta gen` with the `entity` generator only (ADR-0065) | [`docs/ports/rust.md`](docs/ports/rust.md) | [`server/rust/`](server/rust/) | +| Rust | **Preview, unpublished** — loader (JSON + YAML), project and source resolution, naming and all 40 validation passes; 526 / 526 metamodel conformance; `cargo meta init` / `gen` / `verify --codegen` / `eject` with the `entity`, `client` and `commands` generators (ADR-0065). Schema migrations stay with the Node `meta` tool | [`docs/ports/rust.md`](docs/ports/rust.md) | [`server/rust/`](server/rust/) | ## Capability matrix @@ -331,7 +331,7 @@ metaobjects/ │ ├── java/ # Java port (incl. codegen-kotlin + metadata-ktx) │ ├── csharp/ # C# port │ ├── python/ # Python port -│ └── rust/ # Rust port (preview, ADR-0065 — unpublished; entity generator only) +│ └── rust/ # Rust port (preview, ADR-0065 — unpublished; cargo meta + entity/client/commands generators) │ └── client/ └── web/ # universal browser packages (React, TanStack, Angular, framework-agnostic) diff --git a/docs/CONFORMANCE.md b/docs/CONFORMANCE.md index bd9b129eac..83831f53ce 100644 --- a/docs/CONFORMANCE.md +++ b/docs/CONFORMANCE.md @@ -69,21 +69,27 @@ regenerate with `ls -d fixtures//*/ | wc -l` for directory-shaped corpor | [`fixtures/contract-conformance/`](../fixtures/contract-conformance/) (FR-022 — the `contract-schema` and `openapi` generators' golden trees and refusals) | 19 cases (14 trees + 5 errors) | ✓ (one neutral engine, ADR-0034 Amendment 10; the generated API lanes also hold real traffic to the documents) | — | — | — | — | | [`fixtures/explorer-conformance/`](../fixtures/explorer-conformance/) (the `explorer.json` data spine: `meta export --effective` + `meta verify --format json` + the generated-file manifest in, one explorer document out) | 1 case (`shop`) | ✓ (the builder is TypeScript, and reads only port-neutral inputs) | — | — | — | — | -**Rust (preview, ADR-0065) is not a column yet.** The sixth port runs six corpora +**Rust (preview, ADR-0065) is not a column yet.** The sixth port runs these corpora today: `registry-conformance` (byte-identical manifest); the metamodel corpus, all 526 green, with every validation pass the TypeScript loader runs, in the same order, so `server/rust/metaobjects/tests/conformance-expected-failures.json` is empty; `yaml-conformance`, 18 of 19 (the one on `yaml-conformance-expected-failures.json`, `yaml-ref-root-escape`, waits for the ADR-0059 root-level `::` reference rules, which are reference resolution, not a validation pass); `source-resolution-conformance` (all 28 -cases); `naming-conformance` (all of it); and `codegen-skip-conformance` (ADR-0064), for the -cases its `gen` can meet (the rest are named with their reason in its runner). The ledgers -above may only shrink; the skip corpus has none, because each case it runs asserts its result -outright. While the port is in preview, a new fixture that fails in Rust and is not on -the ledger prints a warning and does not fail the lane; it becomes a hard failure when the port -leaves preview. A regression still fails: the ledger's `minPassing` (526) is the number of -fixtures known to pass, and the run fails when fewer do. The column joins this table when -the port leaves preview. +cases); `naming-conformance` (all of it); `codegen-skip-conformance` (ADR-0064), on both its +`gen` and its `verify` columns, for every case the port can meet (the three it cannot, two +about templates and one about the three-way merge, are named with their reason in its +runner); `validation-conformance`, every case, through the generated `validate()`; +`decimal-wire` and `duration-wire`, every vector, against the code the generated support +crate carries; the `core` cases of `writer-conformance` (ADR-0063); and +`generator-registry-conformance`, with the eject contract's census, completeness and depth +(ADR-0034 Amendment 8). It also runs the codegen-compile gate (below) with every shipped +generator, and a scale gate over twenty copies of the fitness model. The ledgers above may +only shrink; the corpora without one assert each case outright. While the port is in +preview, a new fixture that fails in Rust and is not on the ledger prints a warning and does +not fail the lane; it becomes a hard failure when the port leaves preview. A regression +still fails: the ledger's `minPassing` (526) is the number of fixtures known to pass, and the +run fails when fewer do. The column joins this table when the port leaves preview. A ✓ means the port runs the corpus green; an explicit `n / m` is used where a port carries a ledgered divergence. The two ledgered YAML fixtures are documented @@ -237,7 +243,10 @@ Amendment 8). A gate, not a corpus: it has no fixtures of its own, and reads and emits what the packaged generator emits (depth). TypeScript: `cli/test/eject-contract.test.ts`. C#: `EjectContractTests`. Java: `EjectContractTest` in `maven-plugin`. Kotlin: `EjectContractTest` in `codegen-kotlin`. Python: - `tests/conformance/test_eject_contract.py`. + `tests/conformance/test_eject_contract.py`. Rust (preview) holds its three generators to + the same assertions: census, completeness and the reference scan in + `metaobjects-codegen/tests/generator_registry.rs`, and the ejected-alone build in + `metaobjects-cli/tests/cli.rs`. - *A gap is listed, never silent.* `eject.pending` lists every generator that still fails an assertion; it is empty (`[]`) for 1.1.0, so every reference passes every assertion. A port's test fails when an unlisted gap appears and when a listed one closes without its entry being @@ -326,6 +335,9 @@ manifest contains without moving these boundaries. — Python having no static compiler — importing the generated package (which is what resolves the imports BETWEEN modules) plus `ruff` F821 for the branches importing never executes. +- *Rust (preview) runs it too*, with `cargo check` and `rustfmt --check`, over every + generator it ships: it has no framework-bound route tier to exclude, and its generated + client and commands are driven over HTTP against a local stub in the same test. - *Every port excludes its framework-bound route tier* — TS `routesFile`, C# `RoutesGenerator`, Java `SpringControllerGenerator`, Kotlin `KotlinSpringControllerGenerator`. Those imports are not on an in-memory compile's @@ -399,7 +411,7 @@ Per-port runners + commands: | Kotlin | `cd server/java && mvn -pl codegen-kotlin test` (snapshot suite) | `mvn -f server/java/integration-tests-kotlin/pom.xml test` (needs Docker) | `mvn -f server/java/integration-tests-kotlin/pom.xml test -Dtest=ApiContractConformanceTest` (needs Docker) | | C# | `dotnet test` (per project) | `scripts/integration-test.sh csharp` (needs Docker) | `dotnet test server/csharp/MetaObjects.IntegrationTests/MetaObjects.IntegrationTests.csproj --filter "FullyQualifiedName~ApiContractConformanceTest"` (needs Docker) | | Python | `pytest` (per package) | `scripts/integration-test.sh python` (needs Docker) | `cd server/python && uv run --extra integration pytest tests/integration/test_api_contract.py` (needs Docker) | -| Rust (preview) | `cd server/rust && cargo test` (registry, metamodel, YAML, source-resolution and naming corpora; the codegen suites, which run `cargo check` on generated crates) | — | — | +| Rust (preview) | `cd server/rust && cargo test` (registry, metamodel, YAML, source-resolution, naming, skip, validation, wire-vector, writer and generator-registry corpora; the codegen-compile and scale gates, which run `cargo check` on generated crates and drive the generated client over HTTP against a local stub) | — | — | The `persistence-conformance` corpus is intentionally **on-demand** — none of the unit-test runners (`bun test`, `dotnet test`, `pytest`, `mvn test`) pull Docker. diff --git a/docs/README.md b/docs/README.md index f09826a23c..917e7d5709 100644 --- a/docs/README.md +++ b/docs/README.md @@ -58,7 +58,7 @@ docs/ ├── kotlin.md ├── csharp.md ├── python.md - └── rust.md # the Rust port, in preview: loader, validation and the entity generator (cargo meta gen) + └── rust.md # the Rust port, in preview: loader, validation, cargo meta (init/gen/verify/eject) and its three generators ``` If this list and `ls docs/features/` ever disagree, trust the directory listing — diff --git a/docs/features/cli.md b/docs/features/cli.md index cfa166fbe4..aa0af796fe 100644 --- a/docs/features/cli.md +++ b/docs/features/cli.md @@ -41,7 +41,7 @@ command surface splits in two: | Java/Kotlin codegen | Maven plugin | `mvn metaobjects:generate` (`metaobjects:generate`) | Kotlin generators run through the same goal — see below. **No `--template-spec` flag, deliberately** — `` already loads a consumer class from the project classpath, so the declarative surface is `com.metaobjects.generator.template.TemplateScopeGenerator` wired as an ordinary `` with `