Skip to content

feat(rust): resolve metadata dependencies in the Rust loader - #701

Merged
dmealing merged 3 commits into
mainfrom
fm/mo-140-w0-r1a
Dec 3, 2026
Merged

dmealing merged 3 commits into
mainfrom
fm/mo-140-w0-r1a

Conversation

@dmealing

@dmealing dmealing commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

What Changed

  • The Rust resolve_collection now loads declared dependencies from their committed snapshots, verified against .metaobjects/deps.lock.json, ahead of the project's own files. It refuses stale, metamodel-incompatible and node-colliding snapshots. Collection gains imported, in_scope, in_ledger and in_migrate_scope, backed by new metaobjects::dependencies and metaobjects::scope modules. A declared dependency with no snapshot or lock, previously read and ignored, is now ERR_DEPENDENCY_SNAPSHOT_STALE. Collection also gains new fields and can no longer be built with a struct literal.
  • cargo meta gen refuses a new node declared into a dependency-owned package (ERR_DEPENDENCY_PACKAGE_NOT_OWNED) and generates nothing for imported objects unless scope.include names their package. verify --deps is still not available in Rust (its message is updated), and requirement ledger membership is exposed only through dependencies::requirement_ledger.
  • SHA-256 moves into the metaobjects crate; metaobjects-codegen re-exports it and adds metaobjects as a build dependency. Rust now runs the resolution arm of fixtures/dependency-conformance/ and the fixtures/scope-conformance/ corpus, and the docs, roadmap and a changelog fragment (with upgrade notes) are updated to match.
Validation

Risk Assessment

✅ Low: A Rust-only port that mirrors the Python reference function by function (lock validation, snapshot verification, predicates, ownership refusal, ledger walk), is gated by the shared 36-case and 10-case corpora, and reuses the existing reference-node exclusion mechanism. The one behaviour break (a declared dependency with no lock is now an error) is intended and documented in the changelog.

Testing

Broad regression came from the configured scripts/ci-local.sh --affected --strict-toolchains run, which had already passed and was not repeated. On top of it, I drove the real Rust CLI against a Node-synced dependency in a throwaway project, covering exclusion, opt-in, overlay and the refusal paths, compiled the generated crates, and ran the focused dependency, scope, config and imported-node tests; every scenario passed. The one limitation seen (referencing an imported value object under the default scope) is reported as information. The change has no UI, so the evidence is CLI transcripts. My scratch project was removed and the worktree is clean; no source files changed.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
A Rust user declares a path dependency, runs Node meta deps sync, then cargo meta gen and verify --codegen: only the project's own objects are generated; a wildcard scope.include adds nothing,… ✅ pass live rust-dependency-gen-e2e.txt (steps 1-2, 5-6); rust-dependency-references-e2e.txt (B: inherited created_at and cargo check -p app exit 0; C: opt-in compiles; D: cargo meta gen Customer is refused w…
Guards: cargo meta gen before any sync, after a hand edit of the snapshot, and after declaring a new object into the dependency's package fails with ERR_DEPENDENCY_SNAPSHOT_STALE or ERR_DEPENDENCY_P… ✅ pass live rust-dependency-gen-e2e.txt (steps 1, 3, 4; generated-tree hash is identical before and after steps 3 and 4)
The Rust library resolves and loads every shared dependency resolution case, including the 7 ledger cases, as the corpus expects, and passes the scope corpus, the config reader tests (including the ch… ✅ pass live rust-focused-tests.txt: cargo test -p metaobjects --test dependency_conformance --test scope_conformance --test config_reader and cargo test -p metaobjects-codegen --test imported_nodes, both exit…
Evidence: CLI transcript: sync, generate, refusals, overlay and scope opt-in
## 1. dependency declared, not yet synced
$ cargo meta gen
cargo meta gen failed:
ERR_DEPENDENCY_SNAPSHOT_STALE: 1 dependency is declared (acme-common) but there is no .metaobjects/deps.lock.json; run `meta deps sync`

Nothing was written.
[exit 1]
ls: cannot access 'generated': No such file or directory

## 2. Node meta deps sync writes snapshot + lock, then cargo meta gen
$ meta deps sync
warnings: []
dependencies[1]{name,action,message}:
  acme-common,sync,synced acme-common (new)→1.0.0 ((new)→10fbf886)
[exit 0]
{
  "schema_version": 1,
  "dependencies": {
    "acme-common": {
      "version": "1.0.0",
      "metamodelVersion": "1.0",
      "artifact": "acme-common.metaobjects.json",
      "integrity": "sha256-10fbf886e22faceca32c56e5e647c3ff1c82f503e638cba3bd3aa9390f7c409d",
      "packages": [
        "acme::common"
      ],
      "nodes": [
        "acme::common::Address",
        "acme::common::Audited",
        "acme::common::Customer"
      ],
      "resolvedFrom": {
        "path": "../acme-common/metaobjects"
      }
    }
  }
}
$ cargo meta gen
gen: 38 files (38 created, 0 updated, 0 unchanged) in 16.6 ms; did not skip: no stored key
  created generated/meta_support/Cargo.toml
  created generated/meta_support/rustfmt.toml
  created generated/meta_support/src/lib.rs
  created generated/meta_support/src/pattern.rs
  created generated/meta_support/src/validation.rs
  created generated/meta_support/src/wire.rs
  created generated/app/Cargo.toml
  created generated/app/rustfmt.toml
  created generated/app/src/order.rs
  created generated/app/src/lib.rs
  created generated/app_store/src/order.rs
  created generated/app_store/Cargo.toml
  created generated/app_store/rustfmt.toml
  created generated/app_store/src/lib.rs
  created generated/meta_store/Cargo.toml
  created generated/meta_store/rustfmt.toml
  created generated/meta_store/src/lib.rs
  created generated/app_service/Cargo.toml
  created generated/app_service/rustfmt.toml
  created generated/app_service/src/lib.rs
  ... and 18 more
changed crates: app, app_cli, app_client, app_service, app_store, meta_cli, meta_client, meta_service, meta_store, meta_support (cargo check -p app -p app_cli -p app_client -p app_service -p app_store -p meta_cli -p meta_client -p meta_service -p meta_store -p meta_support)
[exit 0]
generated files:
generated/app_client/src/lib.rs
generated/app_client/src/order.rs
generated/app_cli/src/lib.rs
generated/app_cli/src/order.rs
generated/app_service/src/lib.rs
generated/app_service/src/order.rs
generated/app/src/lib.rs
generated/app/src/order.rs
generated/app_store/src/lib.rs
generated/app_store/src/order.rs
generated/meta_client/src/lib.rs
generated/meta_cli/src/lib.rs
generated/meta_service/src/lib.rs
generated/meta_store/src/lib.rs
generated/meta_support/src/lib.rs
generated/meta_support/src/pattern.rs
generated/meta_support/src/validation.rs
generated/meta_support/src/wire.rs
mentions of imported names in generated .rs: 
$ cargo meta verify --codegen
cargo meta verify: in sync (the model and every recorded file are unchanged since the last gen; pass --full to render and compare).
[exit 0]

## 3. snapshot edited by hand
$ cargo meta gen --force
cargo meta gen failed:
ERR_DEPENDENCY_SNAPSHOT_STALE: the committed snapshot for "acme-common" does not match the lock — <scratch>/app/.metaobjects/deps/acme-common/acme-common.metaobjects.json hashes to sha256-8d674383b831293b7ab3638049f4e7f4f8501984ec06a4a1ad1407190b777d66, the lock records sha256-10fbf886e22faceca32c56e5e647c3ff1c82f503e638cba3bd3aa9390f7c409d; run `meta deps sync`

Nothing was written.
[exit 1]
$ cargo meta verify --codegen
cargo meta verify failed:
ERR_DEPENDENCY_SNAPSHOT_STALE: the committed snapshot for "acme-common" does not match the lock — <scratch>/app/.metaobjects/deps/acme-common/acme-common.metaobjects.json hashes to sha256-8d674383b831293b7ab3638049f4e7f4f8501984ec06a4a1ad1407190b777d66, the lock records sha256-10fbf886e22faceca32c56e5e647c3ff1c82f503e638cba3bd3aa9390f7c409d; run `meta deps sync`
[exit 1]
generated tree before/after: 14c87279259b25c4 / 14c87279259b25c4

## 4. new object declared into the dependency's package
metadata:
  package: "acme::common"
  children:
    - object.value:
        name: Note
        children:
          - field.string: { name: text }
$ cargo meta gen --force
cargo meta gen failed:
ERR_DEPENDENCY_PACKAGE_NOT_OWNED: "acme::common::Note" is declared here, but the package "acme::common" belongs to a metadata dependency this project imports, and "acme::common::Note" is not one of the nodes that dependency exports. Declare it in a package this project owns and 'extends' the dependency's node if it needs its shape; if it was meant to AMEND the dependency's node, give it that node's name and 'overlay: true'; if this project really does own "acme::common", name it in 'scope.include' and stop importing it.

Nothing was written.
[exit 1]
$ cargo meta verify --templates
cargo meta verify failed:
ERR_DEPENDENCY_PACKAGE_NOT_OWNED: "acme::common::Note" is declared here, but the package "acme::common" belongs to a metadata dependency this project imports, and "acme::common::Note" is not one of the nodes that dependency exports. Declare it in a package this project owns and 'extends' the dependency's node if it needs its shape; if it was meant to AMEND the dependency's node, give it that node's name and 'overlay: true'; if this project really does own "acme::common", name it in 'scope.include' and stop importing it.
[exit 1]
generated tree before/after: 14c87279259b25c4 / 14c87279259b25c4

## 5. overlay of an exported node is allowed and still not generated
metadata:
  package: "acme::common"
  children:
    - object.entity:
        name: Customer
        overlay: true
        children:
          - field.string: { name: nickname }
$ cargo meta gen --force
gen: 38 files (0 created, 0 updated, 38 unchanged) in 15.6 ms; did not skip: --force
[exit 0]
mentions of Customer/Address in generated: ''

## 6. scope.include wildcard (acme::**) does not name the package; naming it generates its objects
scope.include=["app::**","acme::**"]
gen: 38 files (0 created, 0 updated, 38 unchanged) in 16.1 ms; did not skip: --force
[exit 0]
imported modules: 
scope.include=["app::**","acme::common::**"]
gen: 59 files (21 created, 0 updated, 38 unchanged) in 19.1 ms; did not skip: --force
[exit 0]
imported modules: generated/acme_common_client/src/customer.rs generated/acme_common_cli/src/customer.rs generated/acme_common_service/src/customer.rs generated/acme_common/src/address.rs generated/acme_common/src/customer.rs generated/acme_common_store/src/customer.rs 
gen: 38 files (0 created, 0 updated, 38 unchanged, 21 removed) in 17.0 ms; did not skip: --force
  removed generated/acme_common/Cargo.toml
  removed generated/acme_common/rustfmt.toml
  removed generated/acme_common/src/lib.rs
  removed generated/acme_common_cli/Cargo.toml
  removed generated/acme_common_cli/rustfmt.toml
  removed generated/acme_common_cli/src/lib.rs
  removed generated/acme_common_client/Cargo.toml
  removed generated/acme_common_client/rustfmt.toml
  removed generated/acme_common_client/src/lib.rs
imported modules after removing scope: 
Evidence: CLI transcript: references to imported types and compile of generated crates
## A. own entity extends an imported abstract and holds an imported value object; default scope
metadata:
  package: app
  children:
    - object.entity:
        name: Order
        extends: "acme::common::Audited"
        children:
          - source.rdb: { "@table": orders }
          - field.long: { name: id }
          - field.object: { name: shipTo, "@objectRef": "acme::common::Address", "@storage": jsonb }
          - identity.primary: { name: pk, "@fields": [id] }
$ cargo meta gen --force
cargo meta gen failed:
ERR_RUST_UNSUPPORTED: app::Order.shipTo refers to acme::common::Address, which is not a concrete entity or value object the entity generator emits
[exit 1]

## B. only extends the imported abstract (default scope)
metadata:
  package: app
  children:
    - object.entity:
        name: Order
        extends: "acme::common::Audited"
        children:
          - source.rdb: { "@table": orders }
          - field.long: { name: id }
          - identity.primary: { name: pk, "@fields": [id] }
gen: 38 files (0 created, 3 updated, 35 unchanged) in 17.6 ms; did not skip: --force
[exit 0]
2-
3-#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
4:pub struct Order {
5-    #[serde(rename = "createdAt")]
6-    pub created_at: Option<String>,
7-    pub id: i64,
8-}
9-
10-/// What a caller sends to create one `Order`: the members the server does not fill itself.
11-#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
12-pub struct OrderCreate {
13-    #[serde(rename = "createdAt", skip_serializing_if = "Option::is_none")]
14-    pub created_at: Option<String>,
15-    pub id: i64,
16-}
17-
18-impl OrderCreate {

$ cargo check -p app -p app_store (generated crates, case B)
error: failed to select a version for the requirement `pin-project-lite = "^0.2.11"`
  version 0.2.17 is yanked
  version 0.2.18 is yanked
location searched: crates.io index
required by package `reqwest v0.13.5`
    ... which satisfies dependency `reqwest = "^0.13"` of package `meta_client v0.1.0 (<scratch>/app/generated/meta_client)`
    ... which satisfies path dependency `meta_client` of package `app_cli v0.1.0 (<scratch>/app/generated/app_cli)`
As a reminder, you're using offline mode (--offline) which can sometimes cause surprising resolution failures, if this error is too confusing you may wish to retry without `--offline`.
[exit 101]

$ cargo check -p app (generated entity crate, case B)
   Compiling serde v1.0.229
   Compiling syn v3.0.10
   Compiling serde_derive v1.0.229
    Checking meta_support v0.1.0 (<scratch>/app/generated/meta_support)
    Checking app v0.1.0 (<scratch>/app/generated/app)
    Finished `dev` profile [unoptimized] target(s) in 1.89s
[exit 0]

## C. case A again, with scope.include naming acme::common
gen: 59 files (21 created, 6 updated, 32 unchanged) in 20.4 ms; did not skip: --force
[exit 0]
$ cargo check -p app -p acme_common
    Checking acme_common v0.1.0 (<scratch>/app/generated/acme_common)
    Checking app v0.1.0 (<scratch>/app/generated/app)
    Finished `dev` profile [unoptimized] target(s) in 0.11s
[exit 0]

## D. naming an excluded imported entity on the command line
$ cargo meta gen Customer
cargo meta gen failed:
ERR_RUST_UNSUPPORTED: no entity or value object named Customer
[exit 1]
Evidence: Focused Rust test output (dependency, scope, config reader, imported nodes)
test a_walk_lists_files_before_subdirectories_and_skips_pending ... ok
test a_repo_root_project_is_found_from_a_subdirectory ... ok
test an_absolute_path_source_is_taken_as_written ... ok
test defaults_match_a_bare_schema_version ... ok
test an_unknown_library_in_a_config_is_refused_with_the_available_tokens ... ok
test extract_and_confidence_thresholds_ignore_unknown_keys_as_the_typescript_reader_does ... ok
test every_manifest_ref_has_embedded_text_matching_the_repo_file ... ok
test library_sources_order_core_first_and_a_layer_implies_its_core ... ok
test dependencies_are_validated_and_names_must_be_unique ... ok
test malformed_json_is_a_coded_error ... ok
test collection_carries_the_declared_settings ... ok
test discovery_finds_the_nearest_config_and_stops_at_git ... ok
test migrate_foreign_key_targets_is_refuse_or_warn ... ok
test migrate_verify_requirements_scope_and_csharp_are_kept ... ok
test enums_block_corpus ... ok
test api_block_corpus ... ok
test the_error_names_the_file_the_path_and_the_sources_hint ... ok
test the_shipped_tokens_and_manifests_are_embedded ... ok
test the_business_rules_settings_default_and_are_kept ... ok
test wire_resolves_to_typed_values ... ok
test read_sources_puts_libraries_first_then_own_files_and_reports_unreadable_ones ... ok
test wire_block_corpus ... ok
test naming_block_corpus_for_builtin_strategies ... ok

test result: ok. 33 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running tests/dependency_conformance.rs (target/debug/deps/dependency_conformance-0fe2bca788d28e45)

running 1 test
test every_resolution_case_resolves_and_loads_as_in_every_port ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.09s

     Running tests/scope_conformance.rs (target/debug/deps/scope_conformance-9ac5d8eaf9c450d1)

running 1 test
test every_scope_case_matches_as_in_every_port ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

[exit 0]
    Finished `test` profile [unoptimized + debuginfo] target(s) in 2.79s
     Running tests/imported_nodes.rs (target/debug/deps/imported_nodes-ac5a91bcba37367b)

running 4 tests
test a_declared_dependency_with_no_lock_is_stale ... ok
test a_new_node_in_a_dependency_package_is_refused_on_load ... ok
test a_scope_include_naming_the_package_generates_its_objects ... ok
test an_imported_entity_is_loaded_and_not_generated ... ok

test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.01s

[exit 0]
  • Outcome: ⚠️ 1 info across 1 run (9m40s)

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 2 infos
  • ℹ️ server/rust/metaobjects-cli/src/lib.rs:619 - The verify --deps usage error still says "metadata dependencies are resolved and checked by the Node meta command". After this change the Rust loader itself resolves and verifies dependency snapshots (resolve_collection plus deps.lock.json). Only the check arm (meta deps check) remains Node-only. Reword to e.g. "checking metadata dependencies against their publishers is the Node meta command's (meta deps check)". The file is outside the changed set, so this was not fixed inline.
  • ℹ️ server/rust/metaobjects/tests/config_reader.rs:506 - The test a_declared_dependency_resolves_against_its_lock asserts that resolution FAILS with ERR_DEPENDENCY_SNAPSHOT_STALE because no lock exists. The name says the opposite of what the test pins. Rename it to e.g. a_declared_dependency_without_a_lock_is_stale.
⚠️ **Test** - 1 info
  • ℹ️ server/rust/metaobjects-codegen/src/project.rs:57 - With the default scope, an app entity with field.object @objectRef: acme::common::Address (a value object exported by a dependency) makes cargo meta gen fail with ERR_RUST_UNSUPPORTED: app::Order.shipTo refers to acme::common::Address, which is not a concrete entity or value object the entity generator emits. Nothing is written, and the message does not mention scope.include. Adding acme::common::** to scope.include works and the generated crates compile, but it generates the whole package. Extending an imported abstract works under the default scope. This follows from reusing the existing reference-node set, and it is not a regression because dependencies were previously ignored. docs/features/metadata-dependencies.md says C# still emits such a reached value object, so this is a candidate follow-up before relying on cross-port reader parity. The same page's list of consuming ports also does not name Rust.
  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
A Rust user declares a path dependency, runs Node meta deps sync, then cargo meta gen and verify --codegen: only the project's own objects are generated; a wildcard scope.include adds nothing,… ✅ pass live rust-dependency-gen-e2e.txt (steps 1-2, 5-6); rust-dependency-references-e2e.txt (B: inherited created_at and cargo check -p app exit 0; C: opt-in compiles; D: cargo meta gen Customer is refused w…
Guards: cargo meta gen before any sync, after a hand edit of the snapshot, and after declaring a new object into the dependency's package fails with ERR_DEPENDENCY_SNAPSHOT_STALE or ERR_DEPENDENCY_P… ✅ pass live rust-dependency-gen-e2e.txt (steps 1, 3, 4; generated-tree hash is identical before and after steps 3 and 4)
The Rust library resolves and loads every shared dependency resolution case, including the 7 ledger cases, as the corpus expects, and passes the scope corpus, the config reader tests (including the ch… ✅ pass live rust-focused-tests.txt: cargo test -p metaobjects --test dependency_conformance --test scope_conformance --test config_reader and cargo test -p metaobjects-codegen --test imported_nodes, both exit…
  • scripts/ci-local.sh --affected --strict-toolchains
  • Broad regression came from the configured test command scripts/ci-local.sh --affected --strict-toolchains, which already ran and passed at this commit; it was not re-run
  • MO_CI_LIST_ONLY=1 scripts/ci-local.sh --affected --strict-toolchains (listing only: confirms the rust lane is among the selected lanes)
  • cargo build -p metaobjects-cli
  • cargo meta init, then meta deps sync (Node) and cargo meta gen / cargo meta verify --codegen on a throwaway consumer project
  • cargo meta gen --force and cargo meta verify after tampering with the snapshot and after declaring a new object into acme::common
  • cargo meta gen --force with an overlay, a wildcard scope.include, a naming scope.include, imported references, and cargo meta gen Customer
  • cargo check --offline -p app and cargo check --offline -p app -p acme_common on the generated crates
  • cargo test -p metaobjects --test dependency_conformance --test scope_conformance --test config_reader
  • cargo test -p metaobjects-codegen --test imported_nodes
🔧 **Document** - 2 issues found → auto-fixed ✅
  • ℹ️ server/rust/metaobjects-cli/src/lib.rs:619 - The cargo meta verify --deps usage error still says metadata dependencies are "resolved and checked by the Node meta command". The Rust loader now resolves committed snapshots itself, so only the sync and the upstream check are Node's. This is executable text, so the documentation phase did not edit it. R1b, which builds verify --deps, would replace it.
  • ℹ️ spec/roadmap.md:427 - This was stale before this change. The FR-023 paragraph's "Still deferred" list still names the npm/python/maven/nuget transports and Java/Kotlin/C# as consumers or publishers, which contradicts the same paragraph and docs/features/metadata-dependencies.md. A follow-up could reduce the paragraph to a short pointer to that page. Only the Rust consumer note and the stale corpus count were changed here.

🔧 Fix applied.
✅ Re-checked - no issues remain.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

resolve_collection loads each declared dependency from its committed
snapshot, verified against .metaobjects/deps.lock.json (stale, metamodel
and node-collision refusals), and Collection gains the imported, in_scope,
in_ledger and in_migrate_scope predicates. cargo meta gen generates
nothing for an imported object unless scope.include names its package,
and refuses a new node declared into a dependency's package
(ERR_DEPENDENCY_PACKAGE_NOT_OWNED).

Rust now runs the resolution arm of fixtures/dependency-conformance (all
36 cases, the 7 ledger cases included) and fixtures/scope-conformance.
The check arm (verify --deps) is not built yet. SHA-256 moves into the
metaobjects crate; metaobjects-codegen re-exports it.
@dmealing
dmealing merged commit ab71028 into main Dec 3, 2026
11 checks passed
@dmealing
dmealing deleted the fm/mo-140-w0-r1a branch December 3, 2026 10:12
dmealing added a commit that referenced this pull request Dec 3, 2026
* fix(ci): verify the Rust crates against fresh sibling builds in the publish dry run

cargo fingerprints a registry crate by version, not by its source, so a build
of the overlay registry's metaobjects 1.3.1 left in a restored target/ was
reported Fresh and linked into metaobjects-codegen's verify build, which then
failed with E0432 on runners whose cache predated #701. The dry run now uses
its own target directory and removes this workspace's crates from it first;
scripts/rust-publish-dry-run.sh is the one definition, run by the rust lane
and by the release pack-verify.

* no-mistakes(document): Docs follow rust publish dry-run script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant