Skip to content

feat(rust): read and enforce the reference facet in the Rust loader - #697

Merged
dmealing merged 1 commit into
mainfrom
fm/mo-140-w1-b1-rs
Dec 3, 2026
Merged

dmealing merged 1 commit into
mainfrom
fm/mo-140-w1-b1-rs

Conversation

@dmealing

@dmealing dmealing commented Dec 3, 2026

Copy link
Copy Markdown
Member

What Changed

  • The spec reader in server/rust/metaobjects/src/providers.rs accepts the ref facet on a type: "attr" entry, validates it (string attrs only, targetType, targetSubTypes, fieldPath, sameSystem, error codes) and carries it to a new AttrSchema::reference. A structural child carrying ref is refused.
  • The reference pass in validate/refs.rs enforces the facet through a kind-typed symbol table. It resolves System.child and pkg::System.child, and reports unresolved values (ERR_REF_UNRESOLVED), wrong-kind targets (ERR_REF_WRONG_KIND) and cross-system targets (sameSystem). It also writes a canonical walked path for references. ReferenceDescriptor is now { attr, facet: ReferenceFacet }, and registry.rs holds the new ReferenceFacet type.
  • The registry manifest (manifest.rs) writes ref only on attributes that carry one. A root-level node and a same-named package node in one document now stay two nodes, which closes the yaml-ref-root-escape fixture (yaml-conformance 19 of 19). Rust API users who build ReferenceDescriptor or AttrSchema by struct literal need the changed fields (see changelog.d/rust-reference-facet.md).
Validation

Risk Assessment

⚠️ Medium: The change follows the TypeScript reference closely and meets every acceptance criterion, but it changes core loader paths (all core reference validation now uses the new lookup, and the parser merges root-level nodes by package), and the corpora were not re-run during this review.

Testing

Ran the two proving suites named in the intent (Rust reference resolver unit tests and yaml-conformance; both pass). Drove the real cargo-meta CLI live on two throwaway projects: a valid root-escape model generates and verifies clean, and an unresolved reference fails the load with its error code and writes nothing. The unit-test and conformance results are not live scenarios and are marked untested for live purposes. The configured scripts/ci-local.sh --affected --strict-toolchains baseline passed at this commit and was not re-run. Facet-specific CLI scenarios (wrong kind, wrong subtype, cross-system) are covered only by unit tests because no shipped definition uses the facet yet, so they are not live.

  • Live validation: ✅ go - 2 of 4 scenarios driven live against the product
Scenario Result Live Evidence
Rust reference resolver unit tests cover unresolved, wrong kind, wrong subtype, crosses system, role and app both named api, and system.child resolution ⏸️ untested no Prior payload recorded this as a pass from cargo test -p metaobjects --lib refs (36 passed), which is a unit test, not a live product run. No live execution was recorded.
yaml-conformance Rust lane passes with yaml-ref-root-escape removed from the ledger ⏸️ untested no Prior payload recorded this as a pass from cargo test -p metaobjects --test yaml_conformance and a ledger inspection. That is a conformance test harness run, not a live product run. No live execution…
Live: valid root-level ::Apple shadow model generates and verifies through cargo-meta ✅ pass live cargo-meta init, gen (exit 0), verify --codegen (in sync, exit 0) on a throwaway project built from the yaml-ref-root-escape input
Live adversarial: unresolved ::Nope objectRef is refused at gen with nothing written ✅ pass live cargo-meta gen exit 1 with ERR_UNRESOLVED_OBJECT_REF message and 'Nothing was written.'

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - medium risk

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 2 of 4 scenarios driven live against the product
Scenario Result Live Evidence
Rust reference resolver unit tests cover unresolved, wrong kind, wrong subtype, crosses system, role and app both named api, and system.child resolution ⏸️ untested no Prior payload recorded this as a pass from cargo test -p metaobjects --lib refs (36 passed), which is a unit test, not a live product run. No live execution was recorded.
yaml-conformance Rust lane passes with yaml-ref-root-escape removed from the ledger ⏸️ untested no Prior payload recorded this as a pass from cargo test -p metaobjects --test yaml_conformance and a ledger inspection. That is a conformance test harness run, not a live product run. No live execution…
Live: valid root-level ::Apple shadow model generates and verifies through cargo-meta ✅ pass live cargo-meta init, gen (exit 0), verify --codegen (in sync, exit 0) on a throwaway project built from the yaml-ref-root-escape input
Live adversarial: unresolved ::Nope objectRef is refused at gen with nothing written ✅ pass live cargo-meta gen exit 1 with ERR_UNRESOLVED_OBJECT_REF message and 'Nothing was written.'
  • scripts/ci-local.sh --affected --strict-toolchains
  • cargo test -p metaobjects --lib refs (36 passed: unresolved, wrong kind, wrong subtype, crosses system, role and app both named api, system.child resolution, manifest ref key)
  • cargo test -p metaobjects --test yaml_conformance (yaml_corpus passed, covers yaml-ref-root-escape)
  • Inspected server/rust/metaobjects/tests/yaml-conformance-expected-failures.json: ledger notes and fixtures empty, minPassing 19
  • cargo build -p metaobjects-cli then live cargo-meta init + metadata with root-level ::Apple shadow model (from yaml-ref-root-escape input) + cargo-meta gen (exit 0) + cargo-meta verify --codegen (in sync, exit 0)
  • Live adversarial: cargo-meta gen on field.object objectRef ::Nope -> exit 1, ERR_UNRESOLVED_OBJECT_REF, nothing written
  • Removed throwaway projects under /mnt/scratch; worktree clean
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

The spec reader in providers.rs validates `ref` on an attr entry (refusing a bad facet, or
one on a structural child) and carries it to AttrSchema::reference. The registered walk
enforces it through a kind-typed symbol table: System.child and pkg::System.child, bare values
found in the referrer's containers first, an untyped lookup only for the wrong-kind code, and
sameSystem judged on the walked path. The reference pass writes the walked path and keeps a
value as written when its canonical spelling would not look up the same target. The registry
manifest writes `ref` only when present. A provider's own code keeps its spelling in
MetaError::provider_code. A parent-relative `..::Owner.field` value resolves its owner.

A same-document root-level node and a same-named packaged node are no longer merged, which
closes yaml-ref-root-escape: yaml-conformance is 19 of 19 with an empty ledger. No definition
file uses the facet, so no registry, manifest or generated output changes. Mirrors the
TypeScript (#695), C# (#694) and Java (#696) loaders.
@dmealing
dmealing merged commit 0ca1c70 into main Dec 3, 2026
11 checks passed
@dmealing
dmealing deleted the fm/mo-140-w1-b1-rs branch December 3, 2026 08:02
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