Repository navigation
feat(csharp): read and enforce the reference facet in the C# loader - #694
Merged
Merged
Conversation
The spec reader validates `ref` on an attr entry and carries it to AttrSchema.Ref; the registry-derived walk enforces it through a kind-typed symbol table (System.child, pkg::System.child, bare values found in the referrer's containers first, untyped lookup only for the wrong-kind code); the reference pass binds facet attributes to the walked path and keeps a value as written when its canonical spelling would not reload to the same target; the registry manifest writes `ref` only when present. Provider codes keep their spelling in MetaError.ProviderCode. Mirrors the TypeScript loader; no definition file uses the facet, so no registry, manifest or generated output changes.
dmealing
added a commit
that referenced
this pull request
Dec 3, 2026
…er (#696) * feat(java): read and enforce the reference facet in the Java loader The spec reader validates `ref` on an attr entry (refusing a bad facet, or one on a structural child) and carries it onto the attr's ChildRequirement / CommonAttributeDef; the registry-derived walk enforces it through a kind-typed symbol table (System.child, pkg::System.child, bare values found in the referrer's containers first, untyped lookup only for the wrong-kind code, sameSystem judged on the walked path); the reference pass binds facet attributes to the walked path and keeps a value as written when its canonical spelling would not reload to the same target; the registry manifest writes `ref` only when present. A provider's own code keeps its spelling (MetaDataException.getProviderCode / getCodeName). A parent-relative `..::` owner now resolves (the walk no longer cuts at the first dot), and a dotted `extends` whose owner is a non-object top-level node resolves, as in TS and C#. Kotlin runs on it. No definition file uses the facet, so no registry, manifest or generated output changes. Mirrors the C# loader (#694) case for case. * no-mistakes(review): apply reviewer inline fixes * no-mistakes(document): correct stale reference-facet notes for Java
dmealing
added a commit
that referenced
this pull request
Dec 3, 2026
…697) 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.
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
reffacet on provider attr entries and carries it toAttrSchema.Ref.ResolveReferencesresolves facet-bearing attrs through a newSymbolTablelookup: typed by target kind, dotted paths (System.child,pkg::System.child), referrer-container lookup for bare values, andERR_REF_UNRESOLVED/ERR_REF_WRONG_KIND/ wrong-system refusals.refonly on attrs that declare one.ReferenceDescriptorbecomes(Attr, Facet), and providerErrorCodevalues outside the enum keep their spelling inMetaError.ProviderCode. This is a C# API break for providers that setTypeDefinition.Referencesin code (migration noted inchangelog.d/csharp-reference-facet.md).No definition file uses the facet yet, so registry output and generated code do not change.
Validation
Risk Assessment
✅ Low: No new material defect found; the facet paths are unused by any shipped definition file, the four existing core references keep their error codes, and the last fix round's changes match their decisions on reading (no tests run in this phase).
Testing
Baseline
scripts/ci-local.sh --affected --strict-toolchainspassed at this commit and was not re-run. I drove the ReferenceFacet xUnit suite (44 pass) against the real C# loader in-process. That covers the intent's required cases: unresolved, wrong kind, wrong subtype, crosses system, and kind-typed lookup where a role and an app are both namedapi. None of these scenarios were driven through the livedotnet metaCLI, so none are marked live and all are reported as untested live. The verdict is inconclusive because the live CLI surface was not exercised, not because of a failure.Evidence: ReferenceFacet xUnit results (TRX)
Pipeline
Updates from git push no-mistakes
✅ **Intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
CHANGELOG.md:13- The change edits the## [Unreleased]section of CHANGELOG.md directly and adds a### Upgrading from 1.3.1heading. changelog.d/README.md says: "Do not edit the## [Unreleased]section ofCHANGELOG.mdin a pull request. Add one new file here per change instead." This PR is one of five parallel B1 PRs (B1-ts, B1-cs, B1-java, B1-py, B1-rs), so the shared top of [Unreleased] is very likely to conflict. Fix: move the entry tochangelog.d/csharp-reference-facet.mdas one bullet. Put theReferenceDescriptorupgrade note in an indentedUpgrading:paragraph. KeepTargetType,TargetSubType,DottedFieldPathandErrorCodein code spans socheck-export-surface.mjsstill finds them, because it reads fragmentUpgrading:paragraphs. Then revert the CHANGELOG.md hunk.server/csharp/MetaObjects.Cli/VerifyCommand.cs:438- The provider code (MetaError.CodeName) is used in only one CLI site. VerifyCommand.cs:322 now printsCodeName, but these sibling load-error paths still usee.Code: VerifyCommand.cs:438 (verify --codegenerror text), VerifyCommand.cs:548 (the templates outcome's LoadErrors, which Program.cs:621 prints asload error: {e}), and GenCommand.cs:124 (thedotnet meta genLoadErrors). When a facet'serrorCodeorwrongSystemCodenames a provider code such asERR_GRANT_CROSSES_SYSTEM, those paths printERR_UNKNOWNand lose the code. The CHANGELOG says thatCodeName"gives either". Fix: usee.CodeNameat all three sites.server/csharp/MetaObjects/Validation/RegisteredValidation.cs:61- Validation and resolution disagree on which schema owns an attribute name. ReferenceAttrDescriptors checksattr.Ref is nullbeforeseen.Add(attr.Name). So a per-type attr with no facet does not shadow a common (*.*) attr of the same name that has a facet, and validation enforces the common facet. ResolveReferences.FacetOf (ResolveReferences.cs:38) and TypeRegistry.FindAttrSchema use per-type-wins, so the resolver skips that facet. Result: the loader can check an attr with one rule and bind it with another. No shipped definition can reach this case today. Fix:if (!seen.Add(attr.Name) || attr.Ref is null) continue;.server/csharp/MetaObjects/Validation/RegisteredValidation.cs:119- The sameSystem check finds the target's system from the lookup path (path.LastOrDefault(n => n.Type == TYPE_SYSTEM)), not from the target's physical ancestors. spec/metamodel-definitions.md says: "The system of a node is its nearest ancestor, or the node itself, whose type issystem." The two rules differ for a child inherited throughextends. In the testAn_inherited_child_keeps_the_path_it_was_addressed_by_and_is_in_that_system,Ledger extends Parcelsand Ledger'swebhasrunsAs: clerk, whereclerkis physically in Parcels. The implementation passes this case; the literal spec rule fails it. The behavior looks deliberate because a test pins it. Please confirm that the spec text should be amended to say "the system the lookup path went through", or that the check should use the physical ancestor. Whichever rule is chosen, B1-ts, B1-java, B1-py and B1-rs must use the same rule.🔧 Fix applied.
3 issues (1 warning, 2 infos) still open:
CHANGELOG.md:13- The change edits the## [Unreleased]section of CHANGELOG.md directly and adds a### Upgrading from 1.3.1heading. changelog.d/README.md says: "Do not edit the## [Unreleased]section ofCHANGELOG.mdin a pull request. Add one new file here per change instead." This PR is one of five parallel B1 PRs (B1-ts, B1-cs, B1-java, B1-py, B1-rs), so the shared top of [Unreleased] is very likely to conflict. Fix: move the entry tochangelog.d/csharp-reference-facet.mdas one bullet. Put theReferenceDescriptorupgrade note in an indentedUpgrading:paragraph. KeepTargetType,TargetSubType,DottedFieldPathandErrorCodein code spans socheck-export-surface.mjsstill finds them, because it reads fragmentUpgrading:paragraphs. Then revert the CHANGELOG.md hunk.server/csharp/MetaObjects/Validation/RegisteredValidation.cs:119- The sameSystem check finds the target's system from the lookup path (path.LastOrDefault(n => n.Type == TYPE_SYSTEM)), not from the target's physical ancestors. spec/metamodel-definitions.md says: "The system of a node is its nearest ancestor, or the node itself, whose type issystem." The two rules differ for a child inherited throughextends. In the testAn_inherited_child_keeps_the_path_it_was_addressed_by_and_is_in_that_system,Ledger extends Parcelsand Ledger'swebhasrunsAs: clerk, whereclerkis physically in Parcels. The implementation passes this case; the literal spec rule fails it. The behavior looks deliberate because a test pins it. Please confirm that the spec text should be amended to say "the system the lookup path went through", or that the check should use the physical ancestor. Whichever rule is chosen, B1-ts, B1-java, B1-py and B1-rs must use the same rule.server/csharp/MetaObjects.Conformance.Tests/ReferenceFacetTests.cs:581-A_parent_relative_references_value_resolves_its_owneruses a model that cannot load cleanly.Orderis anobject.valuewith an enforcedidentity.reference(noenforce: false), whichValidateValuePurityrefuses withERR_SUBTYPE_RULE_VIOLATION. The test therefore only asserts thatERR_INVALID_REFERENCEis absent. It would still pass if..::Address.idbound the wrong node, was never bound, or caused a different error. Fix: makeOrderanobject.entitywith a primary identity (or addenforce: false), callClean(r), and assert that the reference bindsacme::Addressand is rewritten toacme::Address.id. The sibling testA_parent_relative_references_value_still_suggests_the_object_in_another_package(line 552) uses the same invalid value-object shape.🔧 Fix applied.
6 issues (2 warnings, 4 infos) still open:
CHANGELOG.md:13- The change edits the## [Unreleased]section of CHANGELOG.md directly and adds a### Upgrading from 1.3.1heading. changelog.d/README.md says: "Do not edit the## [Unreleased]section ofCHANGELOG.mdin a pull request. Add one new file here per change instead." This PR is one of five parallel B1 PRs (B1-ts, B1-cs, B1-java, B1-py, B1-rs), so the shared top of [Unreleased] is very likely to conflict. Fix: move the entry tochangelog.d/csharp-reference-facet.mdas one bullet. Put theReferenceDescriptorupgrade note in an indentedUpgrading:paragraph. KeepTargetType,TargetSubType,DottedFieldPathandErrorCodein code spans socheck-export-surface.mjsstill finds them, because it reads fragmentUpgrading:paragraphs. Then revert the CHANGELOG.md hunk.server/csharp/MetaObjects/Validation/RegisteredValidation.cs:119- The sameSystem check finds the target's system from the lookup path (path.LastOrDefault(n => n.Type == TYPE_SYSTEM)), not from the target's physical ancestors. spec/metamodel-definitions.md says: "The system of a node is its nearest ancestor, or the node itself, whose type issystem." The two rules differ for a child inherited throughextends. In the testAn_inherited_child_keeps_the_path_it_was_addressed_by_and_is_in_that_system,Ledger extends Parcelsand Ledger'swebhasrunsAs: clerk, whereclerkis physically in Parcels. The implementation passes this case; the literal spec rule fails it. The behavior looks deliberate because a test pins it. Please confirm that the spec text should be amended to say "the system the lookup path went through", or that the check should use the physical ancestor. Whichever rule is chosen, B1-ts, B1-java, B1-py and B1-rs must use the same rule.server/csharp/MetaObjects/Registry/Spec/SpecMetamodelReader.cs:229- Simplification: the change addsSpecMetamodelReader.FromJsonas new public API. The intent needs the spec reader to carryref, with xUnit tests that use a test provider. It does not ask for a public way to load definitions from JSON text.MetaObjects.csprojalready grantsInternalsVisibleTotoMetaObjects.Conformance.Tests, so the narrower form is to makeFromJsoninternal. Publishing it commits the 1.x surface to a data-form provider path in C#.NamingRefs.DeclaringNodeFor(NamingRefs.cs:252) is also newly public for in-assembly callers only, and can beinternalfor the same reason.server/csharp/MetaObjects/Errors.cs:433- One path still drops the newProviderCode. This is a sibling site that the round 2CodeNamefix did not cover.SharedModel.Load(Config/SharedModel.cs:210) turns the firstMetaErrorintonew MetaModelException(Message, Code). For example, callSharedModel.Buildwith publisher providers and aFileslist that omits the target of a facet that names its ownerrorCode. The exception then carries onlyERR_UNKNOWN, and the provider's code appears nowhere. Fix: whenProviderCodeis set, keep it on the exception, for example by prefixingCodeNameto the message.server/csharp/MetaObjects/Loader/ResolveReferences.cs:38-FacetState.FacetOfis a second copy of the rule that a per-type attribute wins over a common attribute.TypeRegistry.FindAttrSchemaalready defines that rule, soregistry?.FindAttrSchema(node.Type, node.SubType, name)?.Refis equivalent. The copy also callsGetCommonAttrs(), which allocates a new list, for every own attribute that is not declared on the type, on every load. Fix: replace the body with theFindAttrSchemacall.server/csharp/MetaObjects/Errors.cs:349- C# now raisesERR_REF_UNRESOLVEDandERR_REF_WRONG_KIND(lines 349-350), but neither is infixtures/conformance/ERROR-CODES.json.spec/metamodel-definitions.mdsays the two default codes are in that file "once a reader raises them". The remedy needs coordination across the parallel B1 PRs. The TypeScripterrors.test.tsrequires its code list and the JSON file to agree exactly, so adding the codes from this PR alone also needs the TypeScript list changed. Please confirm that B1-ts (or a named follow-up) adds both codes before the release.🔧 Fix applied.
3 issues (1 warning, 2 infos) still open:
CHANGELOG.md:13- The change edits the## [Unreleased]section of CHANGELOG.md directly and adds a### Upgrading from 1.3.1heading. changelog.d/README.md says: "Do not edit the## [Unreleased]section ofCHANGELOG.mdin a pull request. Add one new file here per change instead." This PR is one of five parallel B1 PRs (B1-ts, B1-cs, B1-java, B1-py, B1-rs), so the shared top of [Unreleased] is very likely to conflict. Fix: move the entry tochangelog.d/csharp-reference-facet.mdas one bullet. Put theReferenceDescriptorupgrade note in an indentedUpgrading:paragraph. KeepTargetType,TargetSubType,DottedFieldPathandErrorCodein code spans socheck-export-surface.mjsstill finds them, because it reads fragmentUpgrading:paragraphs. Then revert the CHANGELOG.md hunk.server/csharp/MetaObjects/Validation/RegisteredValidation.cs:119- The sameSystem check finds the target's system from the lookup path (path.LastOrDefault(n => n.Type == TYPE_SYSTEM)), not from the target's physical ancestors. spec/metamodel-definitions.md says: "The system of a node is its nearest ancestor, or the node itself, whose type issystem." The two rules differ for a child inherited throughextends. In the testAn_inherited_child_keeps_the_path_it_was_addressed_by_and_is_in_that_system,Ledger extends Parcelsand Ledger'swebhasrunsAs: clerk, whereclerkis physically in Parcels. The implementation passes this case; the literal spec rule fails it. The behavior looks deliberate because a test pins it. Please confirm that the spec text should be amended to say "the system the lookup path went through", or that the check should use the physical ancestor. Whichever rule is chosen, B1-ts, B1-java, B1-py and B1-rs must use the same rule.server/csharp/MetaObjects/Errors.cs:349- C# now raisesERR_REF_UNRESOLVEDandERR_REF_WRONG_KIND(lines 349-350), but neither is infixtures/conformance/ERROR-CODES.json.spec/metamodel-definitions.mdsays the two default codes are in that file "once a reader raises them". The remedy needs coordination across the parallel B1 PRs. The TypeScripterrors.test.tsrequires its code list and the JSON file to agree exactly, so adding the codes from this PR alone also needs the TypeScript list changed. Please confirm that B1-ts (or a named follow-up) adds both codes before the release.dotnet meta verify/gen. The facet only appears in provider definitions, and building a disposable provider fixture was not attempted within the time budget. Coverage is in-process xUnit only.scripts/ci-local.sh --affected --strict-toolchainsDOTNET_CLI_TELEMETRY_OPTOUT=1 dotnet test server/csharp/MetaObjects.Conformance.Tests --filter "FullyQualifiedName~ReferenceFacet"→ 44 passed, 0 failed (trx at evidence dir refacet.trx)Listed test names in server/csharp/MetaObjects.Conformance.Tests/ReferenceFacetTests.cs to map intent cases: unresolved, wrong kind, wrong subtype, crosses system, role and app both namedapi🔧 **Document** - 2 issues found → auto-fixed ✅
spec/metamodel-definitions.md:175- spec/metamodel-definitions.md "## Status" still says "no port's spec reader reads it" and "No definition file usesrefyet". The C# loader now reads and enforcesref, so that line is stale for C#. It is not edited here because the five B1 PRs run in parallel and all edit the same per-port status fact, so it would conflict. Fix once B1-ts, B1-java, B1-py and B1-rs have merged: state per port which ports read the facet.changelog.d/csharp-reference-facet.md- Nothing else needs a doc edit. CHANGELOG.md is untouched, the change lives in the changelog.d fragment, and docs/ports/csharp.md and docs/features/extending-with-providers.md do not describe the C# reference types.🔧 Fix applied.
✅ Re-checked - no issues remain.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.