From cb5615a5811f87b07f488ad751593f57aa1cd9a7 Mon Sep 17 00:00:00 2001 From: Doug Mealing Date: Thu, 3 Dec 2026 03:32:26 -0500 Subject: [PATCH 1/6] feat(metadata): accept parent-relative origin @from/@of/@via in the TypeScript loader MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Split origin paths at the first dot after the last :: (ADR-0059 §2) so ..::Entity.field resolves exactly as its pkg:: twin. Adds the shared conformance fixtures origin-parent-relative-refs and two negatives. --- .../expected-errors.json | 17 +++ .../input/meta.acme.json | 83 +++++++++++ .../input/meta.shop.json | 58 ++++++++ .../providers.json | 1 + .../expected-errors.json | 17 +++ .../input/meta.acme.json | 83 +++++++++++ .../input/meta.shop.json | 58 ++++++++ .../providers.json | 1 + .../expected-effective.json | 139 ++++++++++++++++++ .../origin-parent-relative-refs/expected.json | 136 +++++++++++++++++ .../input/meta.acme.json | 83 +++++++++++ .../input/meta.shop.json | 58 ++++++++ .../providers.json | 1 + .../packages/cli/src/lib/deprecation-lint.ts | 10 +- .../cli/test/unit/deprecation-lint.test.ts | 49 ++++++ .../metadata/src/loader/validation-passes.ts | 24 ++- 16 files changed, 807 insertions(+), 11 deletions(-) create mode 100644 fixtures/conformance/error-origin-parent-relative-unresolved/expected-errors.json create mode 100644 fixtures/conformance/error-origin-parent-relative-unresolved/input/meta.acme.json create mode 100644 fixtures/conformance/error-origin-parent-relative-unresolved/input/meta.shop.json create mode 100644 fixtures/conformance/error-origin-parent-relative-unresolved/providers.json create mode 100644 fixtures/conformance/error-origin-parent-relative-wrong-kind/expected-errors.json create mode 100644 fixtures/conformance/error-origin-parent-relative-wrong-kind/input/meta.acme.json create mode 100644 fixtures/conformance/error-origin-parent-relative-wrong-kind/input/meta.shop.json create mode 100644 fixtures/conformance/error-origin-parent-relative-wrong-kind/providers.json create mode 100644 fixtures/conformance/origin-parent-relative-refs/expected-effective.json create mode 100644 fixtures/conformance/origin-parent-relative-refs/expected.json create mode 100644 fixtures/conformance/origin-parent-relative-refs/input/meta.acme.json create mode 100644 fixtures/conformance/origin-parent-relative-refs/input/meta.shop.json create mode 100644 fixtures/conformance/origin-parent-relative-refs/providers.json diff --git a/fixtures/conformance/error-origin-parent-relative-unresolved/expected-errors.json b/fixtures/conformance/error-origin-parent-relative-unresolved/expected-errors.json new file mode 100644 index 0000000000..4f57fadfc9 --- /dev/null +++ b/fixtures/conformance/error-origin-parent-relative-unresolved/expected-errors.json @@ -0,0 +1,17 @@ +{ + "errors": [ + { + "code": "ERR_INVALID_ORIGIN", + "source": { + "format": "resolved", + "files": [ + "meta.shop.json" + ], + "jsonPath": "$['metadata.root'].children[0]['object.projection'].children[3]['field.string'].children[0]['origin.passthrough']", + "referrer": "ProgramSummary::title", + "target": "..::Course.title" + } + } + ], + "warnings": [] +} diff --git a/fixtures/conformance/error-origin-parent-relative-unresolved/input/meta.acme.json b/fixtures/conformance/error-origin-parent-relative-unresolved/input/meta.acme.json new file mode 100644 index 0000000000..47c142c48d --- /dev/null +++ b/fixtures/conformance/error-origin-parent-relative-unresolved/input/meta.acme.json @@ -0,0 +1,83 @@ +{ + "metadata.root": { + "package": "acme", + "children": [ + { + "object.entity": { + "name": "Program", + "children": [ + { + "source.rdb": { + "@table": "programs" + } + }, + { + "field.long": { + "name": "id" + } + }, + { + "field.string": { + "name": "title" + } + }, + { + "identity.primary": { + "name": "pk", + "@fields": [ + "id" + ] + } + }, + { + "relationship.composition": { + "name": "weeks", + "@objectRef": "Week", + "@cardinality": "many" + } + } + ] + } + }, + { + "object.entity": { + "name": "Week", + "children": [ + { + "source.rdb": { + "@table": "weeks" + } + }, + { + "field.long": { + "name": "id" + } + }, + { + "field.long": { + "name": "programId" + } + }, + { + "identity.primary": { + "name": "pk", + "@fields": [ + "id" + ] + } + }, + { + "identity.reference": { + "name": "program", + "@fields": [ + "programId" + ], + "@references": "Program.id" + } + } + ] + } + } + ] + } +} diff --git a/fixtures/conformance/error-origin-parent-relative-unresolved/input/meta.shop.json b/fixtures/conformance/error-origin-parent-relative-unresolved/input/meta.shop.json new file mode 100644 index 0000000000..dbfdf6af91 --- /dev/null +++ b/fixtures/conformance/error-origin-parent-relative-unresolved/input/meta.shop.json @@ -0,0 +1,58 @@ +{ + "metadata.root": { + "package": "acme::shop", + "children": [ + { + "object.projection": { + "name": "ProgramSummary", + "children": [ + { + "source.rdb": { + "@kind": "view", + "@view": "v_program_summary" + } + }, + { + "field.long": { + "name": "id", + "extends": "acme::Program.id" + } + }, + { + "identity.primary": { + "name": "pk", + "extends": "acme::Program.pk" + } + }, + { + "field.string": { + "name": "title", + "children": [ + { + "origin.passthrough": { + "@from": "..::Course.title" + } + } + ] + } + }, + { + "field.long": { + "name": "weekCount", + "children": [ + { + "origin.aggregate": { + "@agg": "count", + "@of": "..::Week.id", + "@via": "..::Program.weeks" + } + } + ] + } + } + ] + } + } + ] + } +} diff --git a/fixtures/conformance/error-origin-parent-relative-unresolved/providers.json b/fixtures/conformance/error-origin-parent-relative-unresolved/providers.json new file mode 100644 index 0000000000..f9bb435a37 --- /dev/null +++ b/fixtures/conformance/error-origin-parent-relative-unresolved/providers.json @@ -0,0 +1 @@ +["metaobjects-core-types","metaobjects-db"] diff --git a/fixtures/conformance/error-origin-parent-relative-wrong-kind/expected-errors.json b/fixtures/conformance/error-origin-parent-relative-wrong-kind/expected-errors.json new file mode 100644 index 0000000000..a81dbe7449 --- /dev/null +++ b/fixtures/conformance/error-origin-parent-relative-wrong-kind/expected-errors.json @@ -0,0 +1,17 @@ +{ + "errors": [ + { + "code": "ERR_INVALID_ORIGIN", + "source": { + "format": "resolved", + "files": [ + "meta.shop.json" + ], + "jsonPath": "$['metadata.root'].children[0]['object.projection'].children[4]['field.long'].children[0]['origin.aggregate']", + "referrer": "ProgramSummary::weekCount", + "target": "..::Program.title" + } + } + ], + "warnings": [] +} diff --git a/fixtures/conformance/error-origin-parent-relative-wrong-kind/input/meta.acme.json b/fixtures/conformance/error-origin-parent-relative-wrong-kind/input/meta.acme.json new file mode 100644 index 0000000000..47c142c48d --- /dev/null +++ b/fixtures/conformance/error-origin-parent-relative-wrong-kind/input/meta.acme.json @@ -0,0 +1,83 @@ +{ + "metadata.root": { + "package": "acme", + "children": [ + { + "object.entity": { + "name": "Program", + "children": [ + { + "source.rdb": { + "@table": "programs" + } + }, + { + "field.long": { + "name": "id" + } + }, + { + "field.string": { + "name": "title" + } + }, + { + "identity.primary": { + "name": "pk", + "@fields": [ + "id" + ] + } + }, + { + "relationship.composition": { + "name": "weeks", + "@objectRef": "Week", + "@cardinality": "many" + } + } + ] + } + }, + { + "object.entity": { + "name": "Week", + "children": [ + { + "source.rdb": { + "@table": "weeks" + } + }, + { + "field.long": { + "name": "id" + } + }, + { + "field.long": { + "name": "programId" + } + }, + { + "identity.primary": { + "name": "pk", + "@fields": [ + "id" + ] + } + }, + { + "identity.reference": { + "name": "program", + "@fields": [ + "programId" + ], + "@references": "Program.id" + } + } + ] + } + } + ] + } +} diff --git a/fixtures/conformance/error-origin-parent-relative-wrong-kind/input/meta.shop.json b/fixtures/conformance/error-origin-parent-relative-wrong-kind/input/meta.shop.json new file mode 100644 index 0000000000..4de8f70c30 --- /dev/null +++ b/fixtures/conformance/error-origin-parent-relative-wrong-kind/input/meta.shop.json @@ -0,0 +1,58 @@ +{ + "metadata.root": { + "package": "acme::shop", + "children": [ + { + "object.projection": { + "name": "ProgramSummary", + "children": [ + { + "source.rdb": { + "@kind": "view", + "@view": "v_program_summary" + } + }, + { + "field.long": { + "name": "id", + "extends": "acme::Program.id" + } + }, + { + "identity.primary": { + "name": "pk", + "extends": "acme::Program.pk" + } + }, + { + "field.string": { + "name": "title", + "children": [ + { + "origin.passthrough": { + "@from": "..::Program.title" + } + } + ] + } + }, + { + "field.long": { + "name": "weekCount", + "children": [ + { + "origin.aggregate": { + "@agg": "count", + "@of": "..::Week.id", + "@via": "..::Program.title" + } + } + ] + } + } + ] + } + } + ] + } +} diff --git a/fixtures/conformance/error-origin-parent-relative-wrong-kind/providers.json b/fixtures/conformance/error-origin-parent-relative-wrong-kind/providers.json new file mode 100644 index 0000000000..f9bb435a37 --- /dev/null +++ b/fixtures/conformance/error-origin-parent-relative-wrong-kind/providers.json @@ -0,0 +1 @@ +["metaobjects-core-types","metaobjects-db"] diff --git a/fixtures/conformance/origin-parent-relative-refs/expected-effective.json b/fixtures/conformance/origin-parent-relative-refs/expected-effective.json new file mode 100644 index 0000000000..24aefef645 --- /dev/null +++ b/fixtures/conformance/origin-parent-relative-refs/expected-effective.json @@ -0,0 +1,139 @@ +{ + "metadata.root": { + "children": [ + { + "object.entity": { + "name": "Program", + "package": "acme", + "children": [ + { + "source.rdb": { + "@table": "programs" + } + }, + { + "field.long": { + "name": "id" + } + }, + { + "field.string": { + "name": "title" + } + }, + { + "identity.primary": { + "name": "pk", + "@fields": [ + "id" + ] + } + }, + { + "relationship.composition": { + "name": "weeks", + "@cardinality": "many", + "@objectRef": "acme::Week" + } + } + ] + } + }, + { + "object.entity": { + "name": "Week", + "package": "acme", + "children": [ + { + "source.rdb": { + "@table": "weeks" + } + }, + { + "field.long": { + "name": "id" + } + }, + { + "field.long": { + "name": "programId" + } + }, + { + "identity.primary": { + "name": "pk", + "@fields": [ + "id" + ] + } + }, + { + "identity.reference": { + "name": "program", + "@fields": [ + "programId" + ], + "@references": "acme::Program.id" + } + } + ] + } + }, + { + "object.projection": { + "name": "ProgramSummary", + "package": "acme::shop", + "children": [ + { + "source.rdb": { + "@kind": "view", + "@view": "v_program_summary" + } + }, + { + "field.long": { + "name": "id", + "extends": "acme::Program.id" + } + }, + { + "identity.primary": { + "name": "pk", + "extends": "acme::Program.pk", + "@fields": [ + "id" + ] + } + }, + { + "field.string": { + "name": "title", + "children": [ + { + "origin.passthrough": { + "@from": "acme::Program.title" + } + } + ] + } + }, + { + "field.long": { + "name": "weekCount", + "children": [ + { + "origin.aggregate": { + "@agg": "count", + "@of": "acme::Week.id", + "@via": "acme::Program.weeks" + } + } + ] + } + } + ] + } + } + ] + } +} diff --git a/fixtures/conformance/origin-parent-relative-refs/expected.json b/fixtures/conformance/origin-parent-relative-refs/expected.json new file mode 100644 index 0000000000..5a158f6097 --- /dev/null +++ b/fixtures/conformance/origin-parent-relative-refs/expected.json @@ -0,0 +1,136 @@ +{ + "metadata.root": { + "children": [ + { + "object.entity": { + "name": "Program", + "package": "acme", + "children": [ + { + "source.rdb": { + "@table": "programs" + } + }, + { + "field.long": { + "name": "id" + } + }, + { + "field.string": { + "name": "title" + } + }, + { + "identity.primary": { + "name": "pk", + "@fields": [ + "id" + ] + } + }, + { + "relationship.composition": { + "name": "weeks", + "@cardinality": "many", + "@objectRef": "acme::Week" + } + } + ] + } + }, + { + "object.entity": { + "name": "Week", + "package": "acme", + "children": [ + { + "source.rdb": { + "@table": "weeks" + } + }, + { + "field.long": { + "name": "id" + } + }, + { + "field.long": { + "name": "programId" + } + }, + { + "identity.primary": { + "name": "pk", + "@fields": [ + "id" + ] + } + }, + { + "identity.reference": { + "name": "program", + "@fields": [ + "programId" + ], + "@references": "acme::Program.id" + } + } + ] + } + }, + { + "object.projection": { + "name": "ProgramSummary", + "package": "acme::shop", + "children": [ + { + "source.rdb": { + "@kind": "view", + "@view": "v_program_summary" + } + }, + { + "field.long": { + "name": "id", + "extends": "acme::Program.id" + } + }, + { + "identity.primary": { + "name": "pk", + "extends": "acme::Program.pk" + } + }, + { + "field.string": { + "name": "title", + "children": [ + { + "origin.passthrough": { + "@from": "acme::Program.title" + } + } + ] + } + }, + { + "field.long": { + "name": "weekCount", + "children": [ + { + "origin.aggregate": { + "@agg": "count", + "@of": "acme::Week.id", + "@via": "acme::Program.weeks" + } + } + ] + } + } + ] + } + } + ] + } +} diff --git a/fixtures/conformance/origin-parent-relative-refs/input/meta.acme.json b/fixtures/conformance/origin-parent-relative-refs/input/meta.acme.json new file mode 100644 index 0000000000..47c142c48d --- /dev/null +++ b/fixtures/conformance/origin-parent-relative-refs/input/meta.acme.json @@ -0,0 +1,83 @@ +{ + "metadata.root": { + "package": "acme", + "children": [ + { + "object.entity": { + "name": "Program", + "children": [ + { + "source.rdb": { + "@table": "programs" + } + }, + { + "field.long": { + "name": "id" + } + }, + { + "field.string": { + "name": "title" + } + }, + { + "identity.primary": { + "name": "pk", + "@fields": [ + "id" + ] + } + }, + { + "relationship.composition": { + "name": "weeks", + "@objectRef": "Week", + "@cardinality": "many" + } + } + ] + } + }, + { + "object.entity": { + "name": "Week", + "children": [ + { + "source.rdb": { + "@table": "weeks" + } + }, + { + "field.long": { + "name": "id" + } + }, + { + "field.long": { + "name": "programId" + } + }, + { + "identity.primary": { + "name": "pk", + "@fields": [ + "id" + ] + } + }, + { + "identity.reference": { + "name": "program", + "@fields": [ + "programId" + ], + "@references": "Program.id" + } + } + ] + } + } + ] + } +} diff --git a/fixtures/conformance/origin-parent-relative-refs/input/meta.shop.json b/fixtures/conformance/origin-parent-relative-refs/input/meta.shop.json new file mode 100644 index 0000000000..d34fec504c --- /dev/null +++ b/fixtures/conformance/origin-parent-relative-refs/input/meta.shop.json @@ -0,0 +1,58 @@ +{ + "metadata.root": { + "package": "acme::shop", + "children": [ + { + "object.projection": { + "name": "ProgramSummary", + "children": [ + { + "source.rdb": { + "@kind": "view", + "@view": "v_program_summary" + } + }, + { + "field.long": { + "name": "id", + "extends": "acme::Program.id" + } + }, + { + "identity.primary": { + "name": "pk", + "extends": "acme::Program.pk" + } + }, + { + "field.string": { + "name": "title", + "children": [ + { + "origin.passthrough": { + "@from": "..::Program.title" + } + } + ] + } + }, + { + "field.long": { + "name": "weekCount", + "children": [ + { + "origin.aggregate": { + "@agg": "count", + "@of": "..::Week.id", + "@via": "..::Program.weeks" + } + } + ] + } + } + ] + } + } + ] + } +} diff --git a/fixtures/conformance/origin-parent-relative-refs/providers.json b/fixtures/conformance/origin-parent-relative-refs/providers.json new file mode 100644 index 0000000000..f9bb435a37 --- /dev/null +++ b/fixtures/conformance/origin-parent-relative-refs/providers.json @@ -0,0 +1 @@ +["metaobjects-core-types","metaobjects-db"] diff --git a/server/typescript/packages/cli/src/lib/deprecation-lint.ts b/server/typescript/packages/cli/src/lib/deprecation-lint.ts index 115ee48222..366f57852b 100644 --- a/server/typescript/packages/cli/src/lib/deprecation-lint.ts +++ b/server/typescript/packages/cli/src/lib/deprecation-lint.ts @@ -51,6 +51,7 @@ import { isMetaObject, resolveObjectRef, refTarget, + splitChildTail, type MetaData, type MetaObject, } from "@metaobjectsdev/metadata"; @@ -146,10 +147,10 @@ function considerTarget(referrer: MetaData, referrerPath: string, verb: string, /** Split a dotted reference into its entity HEAD and member tail ("Entity.field" -> * "Entity" / "field"). `@objectRef` carries no tail (a pure object ref) and is - * resolved whole by the caller; `@references`/`@from`/`@of`/`@via` do. */ + * resolved whole by the caller; `@references`/`@from`/`@of`/`@via` do. The head + * ends at the first `.` after the last `::` (ADR-0059 §2), so `..::Entity` stays whole. */ function headOf(raw: string): string { - const dot = raw.indexOf("."); - return dot === -1 ? raw : raw.slice(0, dot); + return splitChildTail(raw).owner; } function resolveEntityRef(root: MetaData, ref: string, referrerPkg: string): MetaObject | undefined { @@ -220,7 +221,8 @@ function checkViaPath( referrerPkg: string, out: Diagnostic[], ): void { - const segments = via.split("."); + const head = headOf(via); + const segments = [head, ...(via.length > head.length ? via.slice(head.length + 1).split(".") : [])]; const headSegment = segments[0]; if (headSegment === undefined || headSegment === "") return; let current = resolveEntityRef(root, headSegment, referrerPkg); diff --git a/server/typescript/packages/cli/test/unit/deprecation-lint.test.ts b/server/typescript/packages/cli/test/unit/deprecation-lint.test.ts index de59a9d406..2d4c636f83 100644 --- a/server/typescript/packages/cli/test/unit/deprecation-lint.test.ts +++ b/server/typescript/packages/cli/test/unit/deprecation-lint.test.ts @@ -453,6 +453,55 @@ describe("deprecated-reference lint — origin @of / @via (aggregate)", () => { }); }); +describe("deprecated-reference lint — parent-relative origin paths (ADR-0059 §2)", () => { + test("`..::` @of and @via resolve as their `pkg::` twins and warn on the deprecated targets", async () => { + const findings = await lint([ + { + "object.entity": { + name: "Week", + children: [ + { "source.rdb": { "@table": "weeks" } }, + { "field.long": { name: "id" } }, + { "field.long": { name: "programId" } }, + { "field.int": { name: "minutes", "@deprecated": "use durationMinutes" } }, + { "identity.reference": { name: "programRef", "@fields": ["programId"], "@references": "acme::app::Program" } }, + { "identity.primary": { name: "pk", "@fields": ["id"] } }, + ], + }, + }, + { + "object.entity": { + name: "Program", + package: "acme::app", + children: [ + { "source.rdb": { "@table": "programs" } }, + { "source.rdb": { "@kind": "view", "@view": "v_program", "@role": "replica" } }, + { "field.long": { name: "id" } }, + { + "field.int": { + name: "totalMinutes", + children: [{ "origin.aggregate": { "@agg": "sum", "@of": "..::Week.minutes", "@via": "..::app::Program.weeks" } }], + }, + }, + { + "relationship.composition": { + name: "weeks", + "@objectRef": "..::Week", + "@cardinality": "many", + "@deprecated": "replaced by the weeklySchedule relationship", + }, + }, + { "identity.primary": { name: "pk", "@fields": ["id"] } }, + ], + }, + }, + ]); + const messages = findings.map((d) => d.message); + expect(messages.some((m) => m.includes("origin.aggregate @of references deprecated field.int acme::Week.minutes"))).toBe(true); + expect(messages.some((m) => m.includes("origin.aggregate @via references deprecated relationship.composition acme::app::Program.weeks"))).toBe(true); + }); +}); + describe("deprecated-reference lint — inherited deprecated counts (ADR-0039 resolving)", () => { test("a target that INHERITS @deprecated from its own abstract base still warns, naming the concrete target", async () => { const findings = await lint([ diff --git a/server/typescript/packages/metadata/src/loader/validation-passes.ts b/server/typescript/packages/metadata/src/loader/validation-passes.ts index 170e549848..cba679ef04 100644 --- a/server/typescript/packages/metadata/src/loader/validation-passes.ts +++ b/server/typescript/packages/metadata/src/loader/validation-passes.ts @@ -39,7 +39,7 @@ import { effectiveProjectionFilter } from "../core/object/effective-projection-f import type { MetaReferenceIdentity } from "../core/identity/meta-identity.js"; import { contradictionHint, contradictionsFor } from "../attr-contradictions.js"; import { ParseError, type ErrorCode } from "../errors.js"; -import { resolveObjectRef, didYouMeanHint, refTarget } from "../naming-refs.js"; +import { resolveObjectRef, didYouMeanHint, refTarget, splitChildTail } from "../naming-refs.js"; import { PACKAGE_SEPARATOR, CHILD_REF_SEPARATOR } from "../shared/structural.js"; import { resolvedSource, type ErrorSource } from "../source.js"; import { @@ -644,6 +644,15 @@ function _hopTargetName(hop: MetaData): unknown { : hop.attr(RELATIONSHIP_ATTR_OBJECT_REF); } +/** + * Split a `@via` path into its owner and hops. The owner ends at the first `.` + * after the last `::` (ADR-0059 §2), so `..::Entity.rel` keeps `..::Entity`. + */ +function _splitViaPath(via: string): string[] { + const { owner, tail } = splitChildTail(via); + return tail === "" ? [owner] : [owner, ...tail.slice(CHILD_REF_SEPARATOR.length).split(CHILD_REF_SEPARATOR)]; +} + /** Resolved `Entity.field` reference target: the entity AND the field node. * FR-024 B5 inference needs the entity; the B6 extends/origin agreement * check compares against the field node identity. */ @@ -674,8 +683,11 @@ function _validateFromPath( const referrer = `${projection.fqn()}::${fieldName}`; // ADR-0042 — a bare @from/@of head resolves in the projection's package. const referrerPkg = projection.package ?? projection.fileDefaultPackage ?? ""; - const dotIdx = fromAttr.indexOf("."); - if (dotIdx < 1 || dotIdx === fromAttr.length - 1) { + // ADR-0059 §2: the owner ends at the first `.` after the last `::`, so a + // parent-relative `..::Entity.field` keeps its owner whole. + const { owner: entityName, tail } = splitChildTail(fromAttr); + const targetFieldName = tail.slice(CHILD_REF_SEPARATOR.length); + if (entityName === "" || targetFieldName === "") { // Malformed shape (not "Entity.field") — not a reference resolution // failure per se, but emit format=resolved with target=the bad string // so consumers see the same envelope shape across all FR5d sites. @@ -690,8 +702,6 @@ function _validateFromPath( ); return undefined; } - const entityName = fromAttr.slice(0, dotIdx); - const targetFieldName = fromAttr.slice(dotIdx + 1); const sourceObj = _findObject(root, entityName, referrerPkg); if (!sourceObj) { // FR5d — entity half of the ref didn't resolve. target = full ref. @@ -776,7 +786,7 @@ function _validateViaPath( const referrer = `${projection.fqn()}::${fieldName}`; // ADR-0042 — a bare @via HEAD resolves in the projection's package. const referrerPkg = projection.package ?? projection.fileDefaultPackage ?? ""; - const segments = viaAttr.split("."); + const segments = _splitViaPath(viaAttr); if (segments.length < 2) { errors.push( new ParseError( @@ -2241,7 +2251,7 @@ function originRelatedEntity(origin: MetaData, obj: MetaData, root: MetaData): M const referrerPkg = obj.package ?? obj.fileDefaultPackage ?? ""; const via = origin.ownAttr(ORIGIN_AGGREGATE_ATTR_VIA); if (typeof via !== "string") return undefined; - const [head, ...hops] = via.split("."); + const [head, ...hops] = _splitViaPath(via); let current = resolveObjectRef(root, head ?? "", referrerPkg).node; for (const hop of hops) { if (current === undefined) return undefined; From 6f96ac2e3bed89c5b29871982a422a43fd42f507 Mon Sep 17 00:00:00 2001 From: Doug Mealing Date: Thu, 3 Dec 2026 03:37:12 -0500 Subject: [PATCH 2/6] feat(metadata): accept parent-relative origin @from/@of/@via in C#, Java, Python and Rust MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Each loader now splits an origin path at the first dot after the last :: (ADR-0059 §2) through its existing splitChildTail equivalent, so ..::Entity.field resolves exactly as the pkg:: form. The C# deprecation lint had the same first-dot split and is fixed with a test. Rust's minPassing and the corpus counts move to 587; one changelog fragment. --- AGENTS.md | 2 +- README.md | 2 +- changelog.d/origin-parent-relative-paths.md | 10 ++++ docs/CONFORMANCE.md | 8 +-- docs/features/templates-and-payloads.md | 3 ++ docs/ports/rust.md | 2 +- examples/showcase/site-payload.json | 2 +- .../DeprecationLintParentRelativeTests.cs | 49 +++++++++++++++++++ .../csharp/MetaObjects.Cli/DeprecationLint.cs | 6 +-- .../MetaObjects/Loader/ValidationPasses.cs | 14 +++--- server/csharp/MetaObjects/NamingRefs.cs | 12 +++++ .../metaobjects/loader/ValidationPhase.java | 26 +++++++--- .../metaobjects/loader/validation_passes.py | 14 ++++-- .../rust/metaobjects/src/validate/origin.rs | 20 +++++--- .../tests/conformance-expected-failures.json | 2 +- 15 files changed, 134 insertions(+), 38 deletions(-) create mode 100644 changelog.d/origin-parent-relative-paths.md create mode 100644 server/csharp/MetaObjects.Cli.Tests/DeprecationLintParentRelativeTests.cs diff --git a/AGENTS.md b/AGENTS.md index fa64da40ea..aa45aab115 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -74,7 +74,7 @@ PyPI has had no product change since `0.25.0` — nothing is broken. - **Kotlin** — `codegen-kotlin` (laid out by `KotlinWriter`, ADR-0063, on the JVM): entity + Exposed table + Spring controller + payload + relations + filter allowlist + validator + stored-proc + output-parser generators. `integration-tests-kotlin` runs the persistence-conformance corpus through Exposed against Testcontainers Postgres. **Cross-port conformance corpora** (every port runs the shared corpus): -- Metamodel: `fixtures/conformance/` (584 fixtures; 49 shared corpora in total — per-corpus counts + the corpus x port matrix live in `docs/CONFORMANCE.md`). TS / C# / Java / Python all green. +- Metamodel: `fixtures/conformance/` (587 fixtures; 49 shared corpora in total — per-corpus counts + the corpus x port matrix live in `docs/CONFORMANCE.md`). TS / C# / Java / Python all green. - Render: `fixtures/render-conformance/`. TS / Java / Kotlin / Python / C# / Rust byte-identical; the C# and Rust drift ledgers are empty (`docs/CONFORMANCE.md`). - Persistence: `fixtures/persistence-conformance/`. **Query** scenarios run on every port (TS / C# / Java / Kotlin / Python; `op: guardedUpdate` is TS-only until each port's 1.3.0 guarded update lands), each provisioning its test DB by executing the committed, TS-produced `canonical/schema.postgres.sql` (Postgres only — Derby dropped for the cross-port query corpus, ADR-0015; the FR-044 `report-*` scenarios also run on SQLite, MySQL and D1 where a port has the engine, see [docs/CONFORMANCE.md](docs/CONFORMANCE.md)). The **migration** scenarios are exercised by **TS only** (the Node reference helper writes them; a native tool is equally first-class, ADR-0015 Amendment 2). **The corpus now gates WRITES, not just reads (SP-H):** an `op: roundtrip` scenario type INSERTs through each port's runtime/ORM write codec (NOT raw SQL), reads the row back, and asserts the wire-normalized value. The `AllTypes` entity (`roundtrip-all-types.yaml`) carries one field of **every** persistable `field.*` subtype — string/int/long/double/float/decimal/boolean/date/time/timestamp(+tz)/currency/enum/uuid/object — plus an **array-of-VO** `field.object @isArray @storage:jsonb` column (`labels`, written as 2-element / empty-`[]` / single-element arrays across the three rows) — so every subtype write+read (incl. the array-of-value-object jsonb codec) round-trips through every port against Testcontainers PG. (`field.byte`/`field.short`/`field.class` were cut as non-functional registration-only stubs — the matrix tracks only genuinely-supported subtypes; see `fixtures/registry-conformance/README.md` → "Per-subtype write-round-trip matrix".) - API-contract: `fixtures/api-contract-conformance/`. TS / C# / Java / Kotlin / Python all green — each port runs **two lanes**: a hand-rolled reference server AND its **generated** API artifact booted over HTTP (the deployed controller/routes; TS+C# full-stack vs Testcontainers PG, Java/Kotlin/Python generated controller + in-memory repo behind the consumer seam). The generated fan-out found 10 real deployment bugs golden snapshots missed. Three sub-corpora run the **generated lane only, on all five ports** — `write-through/`, `projection/` (F22: a view-only `object.projection` serves GET list + GET by id and answers every write verb with `405 {"error": "method_not_allowed"}`) and `report/` (FR-044: a view-backed `object.report` serves GET list, answers `POST` with that same `405`, and mounts no `/{id}` route). That is deliberate, not a gap: what is under test is whether a port's GENERATOR emits those routes, and a hand-rolled reference server would answer every scenario by construction. The `m2m/` sub-corpus also gates **TPH x M:N together** (base-declared, subtype-declared, abstract-mid-declared, a non-subtype source onto a subtype TARGET, and the cross-subtype source id answering `200 []`) — the two corpora were originally built disjoint (`tph/` had no relationships, `m2m/` no discriminators), which is precisely how that defect class survived. diff --git a/README.md b/README.md index afa1a484cf..fe1bf2ec94 100644 --- a/README.md +++ b/README.md @@ -172,7 +172,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 in your own tool or the Node `meta migrate` reference helper (ADR-0015) | [`docs/ports/python.md`](docs/ports/python.md) | [`server/python/`](server/python/) | -| Rust | **Crates ready to publish, not yet published** — loader (JSON + YAML), project and source resolution, naming and all 41 validation passes; 584 / 584 metamodel conformance; prompt render and the reply parser (`metaobjects-render`); `cargo meta init` / `gen` / `verify` / `eject` with eleven generators — the model crate through the sqlx store, the service and its opt-in axum routes (`service-routes`) to a typed client and its commands (ADR-0065). Schema migrations stay with the Node `meta` tool | [`docs/ports/rust.md`](docs/ports/rust.md) | [`server/rust/`](server/rust/) | +| Rust | **Crates ready to publish, not yet published** — loader (JSON + YAML), project and source resolution, naming and all 41 validation passes; 587 / 587 metamodel conformance; prompt render and the reply parser (`metaobjects-render`); `cargo meta init` / `gen` / `verify` / `eject` with eleven generators — the model crate through the sqlx store, the service and its opt-in axum routes (`service-routes`) to a typed client and its commands (ADR-0065). Schema migrations stay with the Node `meta` tool | [`docs/ports/rust.md`](docs/ports/rust.md) | [`server/rust/`](server/rust/) | ## Capability matrix diff --git a/changelog.d/origin-parent-relative-paths.md b/changelog.d/origin-parent-relative-paths.md new file mode 100644 index 0000000000..1393f0d2f6 --- /dev/null +++ b/changelog.d/origin-parent-relative-paths.md @@ -0,0 +1,10 @@ +- **Origin paths accept parent-relative references in every port.** An origin's `@from`, `@of` + or `@via` written `..::Entity.field` (ADR-0059 sections 2 and 4) was refused with + `ERR_INVALID_ORIGIN` because the loaders cut the value at its first `.`, inside the `..::` + prefix. The TypeScript, C#, Java (and so Kotlin), Python and Rust loaders now split it where + ADR-0059 says, at the first `.` after the last `::`, and resolve it exactly as the qualified + `pkg::Entity.field` form. The TypeScript and C# deprecated-reference lints split the same way. The new + conformance fixture `origin-parent-relative-refs` loads to the same model as its `pkg::` twin, + and `error-origin-parent-relative-unresolved` and `error-origin-parent-relative-wrong-kind` + keep the existing `ERR_INVALID_ORIGIN` refusals. No registry, manifest or generated output + changes. diff --git a/docs/CONFORMANCE.md b/docs/CONFORMANCE.md index e620400f89..f78451bee6 100644 --- a/docs/CONFORMANCE.md +++ b/docs/CONFORMANCE.md @@ -26,7 +26,7 @@ regenerate with `ls -d fixtures//*/ | wc -l` for directory-shaped corpor | Corpus | Fixtures | TS | Java | Kotlin | C# | Python | Rust | |---|---|---|---|---|---|---|---| -| [`fixtures/conformance/`](../fixtures/conformance/) (metamodel) | 584 | ✓ | ✓ | inherits via `metadata-ktx` | ✓ | ✓ | ✓ (584 / 584, empty ledger) | +| [`fixtures/conformance/`](../fixtures/conformance/) (metamodel) | 587 | ✓ | ✓ | inherits via `metadata-ktx` | ✓ | ✓ | ✓ (587 / 587, empty ledger) | | [`fixtures/yaml-conformance/`](../fixtures/yaml-conformance/) | 19 | 19 / 19 | 19 / 19 | inherits via Java | 18 / 19 (1 ledgered: `error-yaml-coerced-hex-in-string` — YamlDotNet doesn't coerce `0xFF`) | 19 / 19 | 19 / 19 | | [`fixtures/verify-conformance/`](../fixtures/verify-conformance/) | 45 | ✓ | ✓ | inherits via Java | ✓ | ✓ | ✓ | | [`fixtures/verify-strict-conformance/`](../fixtures/verify-strict-conformance/) | 1 | ✓ | — | — | — | ✓ | — | @@ -82,7 +82,7 @@ and render ledgers; the api-contract runner's list of sub-corpora not built yet) shrink, and the corpora without one assert each case outright. 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 ADR-0065 turns the warning off. A regression still fails: the ledger's -`minPassing` (584) is the number of fixtures known to pass, and the run fails when fewer do. +`minPassing` (587) is the number of fixtures known to pass, and the run fails when fewer do. Beside the corpora it runs the codegen-compile gate (below) with every shipped generator, a scale gate over twenty copies of the fitness model, and `examples/rust-service/`'s HTTP test. [The Rust port page](ports/rust.md#conformance) has the detail. @@ -445,7 +445,7 @@ carry it, and a model that uses it fails there by name. There is no row per pack ## Fixture-to-doc mapping -### `fixtures/conformance/` — metamodel loader + canonical serializer (584) +### `fixtures/conformance/` — metamodel loader + canonical serializer (587) | Fixture prefix | Feature doc | |---|---| @@ -951,7 +951,7 @@ shared input. ## Orphaned fixtures (tested but not yet documented) -The fixtures in the nine corpora mapped above (metamodel 584 + yaml 19 + verify 45 +The fixtures in the nine corpora mapped above (metamodel 587 + yaml 19 + verify 45 + render 26 + persistence 68 + api-contract 191 + source-resolution 30 + scope 10 + dependency 47) each map to a feature doc, and so do the two requirement corpora, `rules-check-conformance`, `shared-model-conformance`, the `cube-model` corpus, `explorer-conformance` and `list-query-conformance`, whose case lists live in their own READMEs. None are orphaned today. The remaining diff --git a/docs/features/templates-and-payloads.md b/docs/features/templates-and-payloads.md index 528576717d..8b77353d78 100644 --- a/docs/features/templates-and-payloads.md +++ b/docs/features/templates-and-payloads.md @@ -797,6 +797,9 @@ for payload typing per #270) - [`fixtures/conformance/origin-aggregate-sum/`](../../fixtures/conformance/origin-aggregate-sum/) — `origin.aggregate @agg=sum` - [`fixtures/conformance/origin-multi-level-via/`](../../fixtures/conformance/origin-multi-level-via/) — dotted-path `@via` traversal across hops - [`fixtures/conformance/error-origin-bad-via-path/`](../../fixtures/conformance/error-origin-bad-via-path/) — unresolvable `@via` rejected +- [`fixtures/conformance/origin-parent-relative-refs/`](../../fixtures/conformance/origin-parent-relative-refs/) — `@from`, `@of` and `@via` written `..::Entity.member` (ADR-0059 §2) load to the same model as their `pkg::` twin +- [`fixtures/conformance/error-origin-parent-relative-unresolved/`](../../fixtures/conformance/error-origin-parent-relative-unresolved/) — a `..::` `@from` naming no entity is `ERR_INVALID_ORIGIN` +- [`fixtures/conformance/error-origin-parent-relative-wrong-kind/`](../../fixtures/conformance/error-origin-parent-relative-wrong-kind/) — a `..::` `@via` whose hop names a field, not a relationship or reference, is `ERR_INVALID_ORIGIN` - [`fixtures/conformance/error-origin-bad-aggregate-fn/`](../../fixtures/conformance/error-origin-bad-aggregate-fn/) — unknown `@agg` rejected - [`fixtures/conformance/error-origin-passthrough-type-mismatch/`](../../fixtures/conformance/error-origin-passthrough-type-mismatch/) — a `passthrough` field whose `field.` differs from its `@from` source fails with `ERR_PASSTHROUGH_TYPE_MISMATCH` - [`fixtures/conformance/error-origin-passthrough-array-mismatch/`](../../fixtures/conformance/error-origin-passthrough-array-mismatch/) — a `passthrough` field whose array-ness differs from its `@from` source fails with `ERR_PASSTHROUGH_TYPE_MISMATCH` diff --git a/docs/ports/rust.md b/docs/ports/rust.md index 71ae4b32d2..02687f538b 100644 --- a/docs/ports/rust.md +++ b/docs/ports/rust.md @@ -617,7 +617,7 @@ outright. | Corpus | Rust today | |---|---| | `registry-conformance` | byte-identical manifest | -| `conformance` (the metamodel corpus) | **584 of 584**, and the ledger is empty | +| `conformance` (the metamodel corpus) | **587 of 587**, and the ledger is empty | | `yaml-conformance` | all 19, and the ledger is empty | | `source-resolution-conformance` | all 30 cases | | `reference-source-conformance` | all 6 cases: a `reference: true` source loads so references resolve against it, a node declared only in reference files is a reference node no generator emits, and a `template.*` declared only there is refused (`ERR_REFERENCE_SOURCE_TEMPLATE`) | diff --git a/examples/showcase/site-payload.json b/examples/showcase/site-payload.json index 6fd9a6b48e..b98f0a101b 100644 --- a/examples/showcase/site-payload.json +++ b/examples/showcase/site-payload.json @@ -7,7 +7,7 @@ "metamodel": "1.3" }, "counts": { - "fixtures": 584, + "fixtures": 587, "corpora": 49, "baseTypes": 21 }, diff --git a/server/csharp/MetaObjects.Cli.Tests/DeprecationLintParentRelativeTests.cs b/server/csharp/MetaObjects.Cli.Tests/DeprecationLintParentRelativeTests.cs new file mode 100644 index 0000000000..b6f5a6583c --- /dev/null +++ b/server/csharp/MetaObjects.Cli.Tests/DeprecationLintParentRelativeTests.cs @@ -0,0 +1,49 @@ +using MetaObjects.Loader; +using Xunit; + +namespace MetaObjects.Cli.Tests; + +/// ADR-0059 §2: origin @of / @via split at the first '.' after the last '::', so `..::` forms lint as their `pkg::` twins. +public class DeprecationLintParentRelativeTests +{ + private const string Week = """ + { "metadata.root": { "package": "acme", "children": [ + { "object.entity": { "name": "Week", "children": [ + { "source.rdb": { "@table": "weeks" } }, + { "field.long": { "name": "id" } }, + { "field.int": { "name": "minutes", "@deprecated": "use durationMinutes" } }, + { "identity.primary": { "name": "pk", "@fields": ["id"] } } ] } } ] } } + """; + + private const string Program = """ + { "metadata.root": { "package": "acme::app", "children": [ + { "object.entity": { "name": "Program", "children": [ + { "source.rdb": { "@table": "programs" } }, + { "source.rdb": { "@kind": "view", "@view": "v_program", "@role": "replica" } }, + { "field.long": { "name": "id" } }, + { "field.int": { "name": "totalMinutes", "children": [ + { "origin.aggregate": { "@agg": "sum", "@of": "..::Week.minutes", "@via": "..::app::Program.weeks" } } ] } }, + { "relationship.composition": { "name": "weeks", "@objectRef": "..::Week", "@cardinality": "many", + "@deprecated": "replaced by the weeklySchedule relationship" } }, + { "identity.primary": { "name": "pk", "@fields": ["id"] } } ] } } ] } } + """; + + [Fact] + public void Parent_relative_of_and_via_warn_on_the_deprecated_targets() + { + var scratch = Environment.GetEnvironmentVariable("DEV_SCRATCH") ?? Path.GetTempPath(); + var dir = Path.Combine(scratch, "mo-dep-lint-" + Guid.NewGuid().ToString("N")); + Directory.CreateDirectory(dir); + try + { + File.WriteAllText(Path.Combine(dir, "meta.week.json"), Week); + File.WriteAllText(Path.Combine(dir, "meta.program.json"), Program); + var load = MetaDataLoader.FromDirectory(dir, strict: true); + Assert.Empty(load.Errors.Select(e => e.Code + ": " + e.Message)); + var messages = DeprecationLint.Lint(load.Root).Select(f => f.Message).ToList(); + Assert.Contains(messages, m => m.Contains("origin.aggregate @of references deprecated field.int acme::Week.minutes")); + Assert.Contains(messages, m => m.Contains("origin.aggregate @via references deprecated relationship.composition acme::app::Program.weeks")); + } + finally { Directory.Delete(dir, true); } + } +} diff --git a/server/csharp/MetaObjects.Cli/DeprecationLint.cs b/server/csharp/MetaObjects.Cli/DeprecationLint.cs index 51308be0d0..6ad4ce2f3d 100644 --- a/server/csharp/MetaObjects.Cli/DeprecationLint.cs +++ b/server/csharp/MetaObjects.Cli/DeprecationLint.cs @@ -104,8 +104,8 @@ private static bool Consider(MetaData referrer, string path, string verb, MetaDa private static string HeadOf(string raw) { - var dot = raw.IndexOf('.'); - return dot < 0 ? raw : raw[..dot]; + // ADR-0059 §2: the head ends at the first '.' after the last '::', so `..::Entity` stays whole. + return NamingRefs.SplitChildTail(raw).Owner; } private static MetaObject? ResolveEntity(MetaData root, string reference, string referrerPkg) => @@ -137,7 +137,7 @@ private static void CheckEntityFieldPath( /// Walk an @via path, checking the head entity and every hop; stop at the first segment that does not resolve. private static void CheckVia(MetaData root, MetaData origin, string path, string verb, string via, string pkg, List findings) { - var segments = via.Split('.'); + var segments = NamingRefs.SplitViaPath(via); if (segments[0] == "") return; var current = ResolveEntity(root, segments[0], pkg); if (current is null) return; diff --git a/server/csharp/MetaObjects/Loader/ValidationPasses.cs b/server/csharp/MetaObjects/Loader/ValidationPasses.cs index ee4ca7dc7f..3b686316b4 100644 --- a/server/csharp/MetaObjects/Loader/ValidationPasses.cs +++ b/server/csharp/MetaObjects/Loader/ValidationPasses.cs @@ -1144,8 +1144,11 @@ private static bool IsReferenceHop(MetaData hop) // "where the broken reference lives" identifier). string referrer = $"{projection.Fqn()}::{fieldName}"; - int dotIdx = fromAttr.IndexOf('.', StringComparison.Ordinal); - if (dotIdx < 1 || dotIdx == fromAttr.Length - 1) + // ADR-0059 §2: the owner ends at the first '.' after the last '::', so a + // parent-relative `..::Entity.field` keeps its owner whole. + var (entityName, fieldTail) = NamingRefs.SplitChildTail(fromAttr); + string targetFieldName = fieldTail.Length == 0 ? "" : fieldTail[CHILD_REF_SEPARATOR.Length..]; + if (entityName.Length == 0 || targetFieldName.Length == 0) { // Malformed shape (not "Entity.field") — not a reference resolution // failure per se, but emit format=resolved with target=the bad string @@ -1158,9 +1161,6 @@ private static bool IsReferenceHop(MetaData hop) return null; } - string entityName = fromAttr[..dotIdx]; - string targetFieldName = fromAttr[(dotIdx + 1)..]; - // ADR-0042 — a bare @from/@of head resolves in the projection's package. var sourceObj = FindObject(root, entityName, NamingRefs.EffectivePackage(projection)); if (sourceObj is null) @@ -1230,7 +1230,7 @@ private static bool IsReferenceHop(MetaData hop) // FR5d — referrer is `::`. string referrer = $"{projection.Fqn()}::{fieldName}"; - var segments = viaAttr.Split('.'); + var segments = NamingRefs.SplitViaPath(viaAttr); if (segments.Length < 2) { errors.Add(new MetaError( @@ -2133,7 +2133,7 @@ static string Describe(MetaData f) return ValidateFromPath(of, root, obj, origin.Parent?.Name ?? "", [], "", origin.Source)?.Entity; if (origin.OwnAttr(ORIGIN_AGGREGATE_ATTR_VIA) is not string via) return null; var pkg = NamingRefs.EffectivePackage(obj); - var segments = via.Split('.'); + var segments = NamingRefs.SplitViaPath(via); var current = NamingRefs.ResolveObjectRef(root, segments[0], pkg); foreach (var hop in segments.Skip(1)) { diff --git a/server/csharp/MetaObjects/NamingRefs.cs b/server/csharp/MetaObjects/NamingRefs.cs index a4cb5c526c..4955e1c075 100644 --- a/server/csharp/MetaObjects/NamingRefs.cs +++ b/server/csharp/MetaObjects/NamingRefs.cs @@ -71,6 +71,18 @@ public static (string Owner, string Tail) SplitChildTail(string raw) return dot == -1 ? (raw, "") : (raw[..dot], raw[dot..]); } + /// + /// Split an origin @via path into its owner and hop names (ADR-0059 §2): the owner ends + /// at the first . after the last ::, so ..::Entity.rel keeps ..::Entity whole. + /// + public static string[] SplitViaPath(string via) + { + var (owner, tail) = SplitChildTail(via); + return tail.Length == 0 + ? [owner] + : [owner, .. tail[CHILD_REF_SEPARATOR.Length..].Split(CHILD_REF_SEPARATOR)]; + } + /// Expand the two relative forms against a package; throws on over-drop. private static string ExpandOwner(string owner, string packageContext) { diff --git a/server/java/metadata/src/main/java/com/metaobjects/loader/ValidationPhase.java b/server/java/metadata/src/main/java/com/metaobjects/loader/ValidationPhase.java index 90064b9542..0b445ba893 100644 --- a/server/java/metadata/src/main/java/com/metaobjects/loader/ValidationPhase.java +++ b/server/java/metadata/src/main/java/com/metaobjects/loader/ValidationPhase.java @@ -4489,7 +4489,7 @@ private static MetaObject originRelatedEntity(MetaOrigin origin, MetaObject obj, String via = origin.hasMetaAttr(MetaOrigin.ATTR_VIA, false) ? origin.getMetaAttr(MetaOrigin.ATTR_VIA, false).getValueAsString() : null; if (via == null) return null; - String[] parts = via.split("\\."); + String[] parts = splitViaPath(via); MetaObject current = resolveRootObject(root, parts[0], referrerPkg); for (int i = 1; i < parts.length && current != null; i++) { MetaRelationship rel = findRelationship(current, parts[i]); @@ -5203,6 +5203,18 @@ private static final class OriginTarget { OriginTarget(MetaObject entity, MetaField field) { this.entity = entity; this.field = field; } } + /** Split a {@code @via} path into its owner and hops; the owner ends at the first '.' after + * the last "::" (ADR-0059 section 2), so {@code ..::Entity.rel} keeps {@code ..::Entity}. */ + private static String[] splitViaPath(String via) { + References.Split s = References.splitChildTail(via); + if (s.tail().isEmpty()) return new String[] { s.owner() }; + String[] hops = s.tail().substring(1).split("\\."); + String[] out = new String[hops.length + 1]; + out[0] = s.owner(); + System.arraycopy(hops, 0, out, 1, hops.length); + return out; + } + private static OriginTarget validateFromOrOfPath(String pathAttr, MetaRoot root, MetaObject projection, String fieldName, String label, @@ -5213,8 +5225,12 @@ private static OriginTarget validateFromOrOfPath(String pathAttr, MetaRoot root, // root-level objects, so the bare entity name is used. String projectionName = projection.getName(); String referrer = projection.getShortName() + "::" + fieldName; - int dotIdx = pathAttr.indexOf('.'); - if (dotIdx < 1 || dotIdx == pathAttr.length() - 1) { + // ADR-0059 section 2: the owner ends at the first '.' after the last "::", so a + // parent-relative "..::Entity.field" keeps its owner whole. + References.Split pathSplit = References.splitChildTail(pathAttr); + String entityName = pathSplit.owner(); + String targetFieldName = pathSplit.tail().isEmpty() ? "" : pathSplit.tail().substring(1); + if (entityName.isEmpty() || targetFieldName.isEmpty()) { // Malformed shape (not "Entity.field") — not a reference resolution // failure per se, but emit format=resolved with target=the bad string // so consumers see the same envelope shape across all FR5d sites. @@ -5226,8 +5242,6 @@ private static OriginTarget validateFromOrOfPath(String pathAttr, MetaRoot root, ErrorCode.ERR_INVALID_ORIGIN, ResolvedSource.from(envelope, referrer, pathAttr)); } - String entityName = pathAttr.substring(0, dotIdx); - String targetFieldName = pathAttr.substring(dotIdx + 1); // ADR-0042 — a bare @from/@of head resolves in the projection's package. String referrerPkg = projection.getPackage() == null ? "" : projection.getPackage(); @@ -5297,7 +5311,7 @@ private static WalkedViaPath validateViaPath(String viaAttr, MetaRoot root, String projectionName = projection.getName(); String referrer = projection.getShortName() + "::" + fieldName; java.util.List hops = new java.util.ArrayList<>(); - String[] segments = viaAttr.split("\\."); + String[] segments = splitViaPath(viaAttr); if (segments.length < 2) { throw new MetaDataException( ErrorMessageConstants.ERR_INVALID_ORIGIN diff --git a/server/python/src/metaobjects/loader/validation_passes.py b/server/python/src/metaobjects/loader/validation_passes.py index 6959297553..f3fd8e3b66 100644 --- a/server/python/src/metaobjects/loader/validation_passes.py +++ b/server/python/src/metaobjects/loader/validation_passes.py @@ -179,7 +179,7 @@ IDENTITY_SECONDARY_ATTR_EXPR as IDENTITY_ATTR_EXPR, ) from ..source import resolved_source -from ..naming_refs import did_you_mean_hint, resolve_object_ref, referrer_package_of +from ..naming_refs import did_you_mean_hint, resolve_object_ref, referrer_package_of, split_child_tail from ..naming_refs import ref_target as bound_ref_target from ..meta.core.field.flattened_member import resolve_flattened_member from ..meta.core.object.effective_projection_filter import effective_projection_filter @@ -2297,8 +2297,11 @@ def _validate_entity_field_ref( (``::``) attached to the FR5d ResolvedSource envelope so consumers know which node declared the broken reference. """ - parts = ref.split(".", 1) - if len(parts) != 2: + # ADR-0059 §2: the owner ends at the first '.' AFTER the last '::', so a + # parent-relative '..::Entity.field' owner keeps its dots. + _owner, _tail = split_child_tail(ref) + parts = (_owner, _tail[1:]) + if not _owner or not _tail[1:]: # Malformed shape — not a reference-resolution failure per se, but TS # emits format=resolved here too (with target=the bad string) so every # FR5d site is shape-consistent across the four ports. @@ -2402,8 +2405,9 @@ def _validate_via_path( message on a hop failure (mirrors TS reference at validation-passes.ts L304-L325). """ - segments = via.split(".") - if len(segments) < 2: + _owner, _tail = split_child_tail(via) + segments = [_owner, *_tail[1:].split(".")] if _tail else [_owner] + if not _owner or len(segments) < 2: errors.append( MetaError( f"{context} @via='{via}' must be in 'EntityName.relName[.relName...]' format", diff --git a/server/rust/metaobjects/src/validate/origin.rs b/server/rust/metaobjects/src/validate/origin.rs index c7a617cf8e..03b56f2163 100644 --- a/server/rust/metaobjects/src/validate/origin.rs +++ b/server/rust/metaobjects/src/validate/origin.rs @@ -308,8 +308,9 @@ fn validate_from_path( let referrer = format!("{}::{field_name}", h.fqn()); let pkg = m.pkg(host); let rs = || resolved_src(src, referrer.clone(), from); - let dot = from.find('.'); - let Some(dot) = dot.filter(|&d| d >= 1 && d != from.len() - 1) else { + let (entity_name, field_tail) = split_child_tail(from); + let field_part = field_tail.strip_prefix('.').unwrap_or(""); + if entity_name.is_empty() || field_part.is_empty() { push( errs, ERR_INVALID_ORIGIN, @@ -320,8 +321,7 @@ fn validate_from_path( &rs(), ); return None; - }; - let (entity_name, field_part) = (&from[..dot], &from[dot + 1..]); + } let Some(entity) = m.find_object(entity_name, pkg) else { push( errs, @@ -381,8 +381,11 @@ fn validate_via_path( let referrer = format!("{}::{field_name}", h.fqn()); let rs = |t: &str| resolved_src(src, referrer.clone(), t); let at = format!("origin.@via \"{via}\" on {}.{field_name}", h.name); - let segments: Vec<&str> = via.split('.').collect(); - if segments.len() < 2 { + let (via_owner, via_tail) = split_child_tail(via); + let segments: Vec<&str> = std::iter::once(via_owner) + .chain(via_tail.split('.').skip(1)) + .collect(); + if via_owner.is_empty() || segments.len() < 2 { push( errs, ERR_INVALID_ORIGIN, @@ -1939,8 +1942,9 @@ fn origin_related_entity(m: &M<'_>, origin: NodeId, obj: NodeId) -> Option Date: Thu, 3 Dec 2026 03:42:56 -0500 Subject: [PATCH 3/6] feat(metadata): report an over-dropping origin path as ERR_BAD_ATTR_VALUE in every port MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A ..:: origin @from/@of/@via with more parent steps than the referrer's package has segments now reports ERR_BAD_ATTR_VALUE (ADR-0059 §2), the code the reference readers use for over-drop, through each port's existing owner-candidate check. Shared fixture error-origin-parent-relative-over-drop; corpus counts move to 588. --- AGENTS.md | 2 +- README.md | 2 +- changelog.d/origin-parent-relative-paths.md | 5 +- docs/CONFORMANCE.md | 8 +- docs/features/templates-and-payloads.md | 1 + docs/ports/rust.md | 2 +- examples/showcase/site-payload.json | 2 +- .../expected-errors.json | 17 ++++ .../input/meta.acme.json | 83 +++++++++++++++++++ .../input/meta.shop.json | 58 +++++++++++++ .../providers.json | 1 + .../MetaObjects/Loader/ValidationPasses.cs | 24 ++++++ .../metaobjects/loader/ValidationPhase.java | 20 +++++ .../metaobjects/loader/validation_passes.py | 25 +++++- .../rust/metaobjects/src/validate/origin.rs | 26 +++++- .../tests/conformance-expected-failures.json | 2 +- .../metadata/src/loader/validation-passes.ts | 33 +++++++- 17 files changed, 297 insertions(+), 14 deletions(-) create mode 100644 fixtures/conformance/error-origin-parent-relative-over-drop/expected-errors.json create mode 100644 fixtures/conformance/error-origin-parent-relative-over-drop/input/meta.acme.json create mode 100644 fixtures/conformance/error-origin-parent-relative-over-drop/input/meta.shop.json create mode 100644 fixtures/conformance/error-origin-parent-relative-over-drop/providers.json diff --git a/AGENTS.md b/AGENTS.md index aa45aab115..d0c2578c71 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -74,7 +74,7 @@ PyPI has had no product change since `0.25.0` — nothing is broken. - **Kotlin** — `codegen-kotlin` (laid out by `KotlinWriter`, ADR-0063, on the JVM): entity + Exposed table + Spring controller + payload + relations + filter allowlist + validator + stored-proc + output-parser generators. `integration-tests-kotlin` runs the persistence-conformance corpus through Exposed against Testcontainers Postgres. **Cross-port conformance corpora** (every port runs the shared corpus): -- Metamodel: `fixtures/conformance/` (587 fixtures; 49 shared corpora in total — per-corpus counts + the corpus x port matrix live in `docs/CONFORMANCE.md`). TS / C# / Java / Python all green. +- Metamodel: `fixtures/conformance/` (588 fixtures; 49 shared corpora in total — per-corpus counts + the corpus x port matrix live in `docs/CONFORMANCE.md`). TS / C# / Java / Python all green. - Render: `fixtures/render-conformance/`. TS / Java / Kotlin / Python / C# / Rust byte-identical; the C# and Rust drift ledgers are empty (`docs/CONFORMANCE.md`). - Persistence: `fixtures/persistence-conformance/`. **Query** scenarios run on every port (TS / C# / Java / Kotlin / Python; `op: guardedUpdate` is TS-only until each port's 1.3.0 guarded update lands), each provisioning its test DB by executing the committed, TS-produced `canonical/schema.postgres.sql` (Postgres only — Derby dropped for the cross-port query corpus, ADR-0015; the FR-044 `report-*` scenarios also run on SQLite, MySQL and D1 where a port has the engine, see [docs/CONFORMANCE.md](docs/CONFORMANCE.md)). The **migration** scenarios are exercised by **TS only** (the Node reference helper writes them; a native tool is equally first-class, ADR-0015 Amendment 2). **The corpus now gates WRITES, not just reads (SP-H):** an `op: roundtrip` scenario type INSERTs through each port's runtime/ORM write codec (NOT raw SQL), reads the row back, and asserts the wire-normalized value. The `AllTypes` entity (`roundtrip-all-types.yaml`) carries one field of **every** persistable `field.*` subtype — string/int/long/double/float/decimal/boolean/date/time/timestamp(+tz)/currency/enum/uuid/object — plus an **array-of-VO** `field.object @isArray @storage:jsonb` column (`labels`, written as 2-element / empty-`[]` / single-element arrays across the three rows) — so every subtype write+read (incl. the array-of-value-object jsonb codec) round-trips through every port against Testcontainers PG. (`field.byte`/`field.short`/`field.class` were cut as non-functional registration-only stubs — the matrix tracks only genuinely-supported subtypes; see `fixtures/registry-conformance/README.md` → "Per-subtype write-round-trip matrix".) - API-contract: `fixtures/api-contract-conformance/`. TS / C# / Java / Kotlin / Python all green — each port runs **two lanes**: a hand-rolled reference server AND its **generated** API artifact booted over HTTP (the deployed controller/routes; TS+C# full-stack vs Testcontainers PG, Java/Kotlin/Python generated controller + in-memory repo behind the consumer seam). The generated fan-out found 10 real deployment bugs golden snapshots missed. Three sub-corpora run the **generated lane only, on all five ports** — `write-through/`, `projection/` (F22: a view-only `object.projection` serves GET list + GET by id and answers every write verb with `405 {"error": "method_not_allowed"}`) and `report/` (FR-044: a view-backed `object.report` serves GET list, answers `POST` with that same `405`, and mounts no `/{id}` route). That is deliberate, not a gap: what is under test is whether a port's GENERATOR emits those routes, and a hand-rolled reference server would answer every scenario by construction. The `m2m/` sub-corpus also gates **TPH x M:N together** (base-declared, subtype-declared, abstract-mid-declared, a non-subtype source onto a subtype TARGET, and the cross-subtype source id answering `200 []`) — the two corpora were originally built disjoint (`tph/` had no relationships, `m2m/` no discriminators), which is precisely how that defect class survived. diff --git a/README.md b/README.md index fe1bf2ec94..6b4da766ad 100644 --- a/README.md +++ b/README.md @@ -172,7 +172,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 in your own tool or the Node `meta migrate` reference helper (ADR-0015) | [`docs/ports/python.md`](docs/ports/python.md) | [`server/python/`](server/python/) | -| Rust | **Crates ready to publish, not yet published** — loader (JSON + YAML), project and source resolution, naming and all 41 validation passes; 587 / 587 metamodel conformance; prompt render and the reply parser (`metaobjects-render`); `cargo meta init` / `gen` / `verify` / `eject` with eleven generators — the model crate through the sqlx store, the service and its opt-in axum routes (`service-routes`) to a typed client and its commands (ADR-0065). Schema migrations stay with the Node `meta` tool | [`docs/ports/rust.md`](docs/ports/rust.md) | [`server/rust/`](server/rust/) | +| Rust | **Crates ready to publish, not yet published** — loader (JSON + YAML), project and source resolution, naming and all 41 validation passes; 588 / 588 metamodel conformance; prompt render and the reply parser (`metaobjects-render`); `cargo meta init` / `gen` / `verify` / `eject` with eleven generators — the model crate through the sqlx store, the service and its opt-in axum routes (`service-routes`) to a typed client and its commands (ADR-0065). Schema migrations stay with the Node `meta` tool | [`docs/ports/rust.md`](docs/ports/rust.md) | [`server/rust/`](server/rust/) | ## Capability matrix diff --git a/changelog.d/origin-parent-relative-paths.md b/changelog.d/origin-parent-relative-paths.md index 1393f0d2f6..4e946d6b95 100644 --- a/changelog.d/origin-parent-relative-paths.md +++ b/changelog.d/origin-parent-relative-paths.md @@ -6,5 +6,6 @@ `pkg::Entity.field` form. The TypeScript and C# deprecated-reference lints split the same way. The new conformance fixture `origin-parent-relative-refs` loads to the same model as its `pkg::` twin, and `error-origin-parent-relative-unresolved` and `error-origin-parent-relative-wrong-kind` - keep the existing `ERR_INVALID_ORIGIN` refusals. No registry, manifest or generated output - changes. + keep the existing `ERR_INVALID_ORIGIN` refusals. A `..::` origin path that climbs above the + root package is `ERR_BAD_ATTR_VALUE`, the code every other reference uses for that case + (`error-origin-parent-relative-over-drop`). No registry, manifest or generated output changes. diff --git a/docs/CONFORMANCE.md b/docs/CONFORMANCE.md index f78451bee6..dabb0b095e 100644 --- a/docs/CONFORMANCE.md +++ b/docs/CONFORMANCE.md @@ -26,7 +26,7 @@ regenerate with `ls -d fixtures//*/ | wc -l` for directory-shaped corpor | Corpus | Fixtures | TS | Java | Kotlin | C# | Python | Rust | |---|---|---|---|---|---|---|---| -| [`fixtures/conformance/`](../fixtures/conformance/) (metamodel) | 587 | ✓ | ✓ | inherits via `metadata-ktx` | ✓ | ✓ | ✓ (587 / 587, empty ledger) | +| [`fixtures/conformance/`](../fixtures/conformance/) (metamodel) | 588 | ✓ | ✓ | inherits via `metadata-ktx` | ✓ | ✓ | ✓ (588 / 588, empty ledger) | | [`fixtures/yaml-conformance/`](../fixtures/yaml-conformance/) | 19 | 19 / 19 | 19 / 19 | inherits via Java | 18 / 19 (1 ledgered: `error-yaml-coerced-hex-in-string` — YamlDotNet doesn't coerce `0xFF`) | 19 / 19 | 19 / 19 | | [`fixtures/verify-conformance/`](../fixtures/verify-conformance/) | 45 | ✓ | ✓ | inherits via Java | ✓ | ✓ | ✓ | | [`fixtures/verify-strict-conformance/`](../fixtures/verify-strict-conformance/) | 1 | ✓ | — | — | — | ✓ | — | @@ -82,7 +82,7 @@ and render ledgers; the api-contract runner's list of sub-corpora not built yet) shrink, and the corpora without one assert each case outright. 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 ADR-0065 turns the warning off. A regression still fails: the ledger's -`minPassing` (587) is the number of fixtures known to pass, and the run fails when fewer do. +`minPassing` (588) is the number of fixtures known to pass, and the run fails when fewer do. Beside the corpora it runs the codegen-compile gate (below) with every shipped generator, a scale gate over twenty copies of the fitness model, and `examples/rust-service/`'s HTTP test. [The Rust port page](ports/rust.md#conformance) has the detail. @@ -445,7 +445,7 @@ carry it, and a model that uses it fails there by name. There is no row per pack ## Fixture-to-doc mapping -### `fixtures/conformance/` — metamodel loader + canonical serializer (587) +### `fixtures/conformance/` — metamodel loader + canonical serializer (588) | Fixture prefix | Feature doc | |---|---| @@ -951,7 +951,7 @@ shared input. ## Orphaned fixtures (tested but not yet documented) -The fixtures in the nine corpora mapped above (metamodel 587 + yaml 19 + verify 45 +The fixtures in the nine corpora mapped above (metamodel 588 + yaml 19 + verify 45 + render 26 + persistence 68 + api-contract 191 + source-resolution 30 + scope 10 + dependency 47) each map to a feature doc, and so do the two requirement corpora, `rules-check-conformance`, `shared-model-conformance`, the `cube-model` corpus, `explorer-conformance` and `list-query-conformance`, whose case lists live in their own READMEs. None are orphaned today. The remaining diff --git a/docs/features/templates-and-payloads.md b/docs/features/templates-and-payloads.md index 8b77353d78..6c321586f7 100644 --- a/docs/features/templates-and-payloads.md +++ b/docs/features/templates-and-payloads.md @@ -800,6 +800,7 @@ for payload typing per #270) - [`fixtures/conformance/origin-parent-relative-refs/`](../../fixtures/conformance/origin-parent-relative-refs/) — `@from`, `@of` and `@via` written `..::Entity.member` (ADR-0059 §2) load to the same model as their `pkg::` twin - [`fixtures/conformance/error-origin-parent-relative-unresolved/`](../../fixtures/conformance/error-origin-parent-relative-unresolved/) — a `..::` `@from` naming no entity is `ERR_INVALID_ORIGIN` - [`fixtures/conformance/error-origin-parent-relative-wrong-kind/`](../../fixtures/conformance/error-origin-parent-relative-wrong-kind/) — a `..::` `@via` whose hop names a field, not a relationship or reference, is `ERR_INVALID_ORIGIN` +- [`fixtures/conformance/error-origin-parent-relative-over-drop/`](../../fixtures/conformance/error-origin-parent-relative-over-drop/) — a `..::` path with more parent steps than the referrer's package has segments is `ERR_BAD_ATTR_VALUE` (ADR-0059 §2) - [`fixtures/conformance/error-origin-bad-aggregate-fn/`](../../fixtures/conformance/error-origin-bad-aggregate-fn/) — unknown `@agg` rejected - [`fixtures/conformance/error-origin-passthrough-type-mismatch/`](../../fixtures/conformance/error-origin-passthrough-type-mismatch/) — a `passthrough` field whose `field.` differs from its `@from` source fails with `ERR_PASSTHROUGH_TYPE_MISMATCH` - [`fixtures/conformance/error-origin-passthrough-array-mismatch/`](../../fixtures/conformance/error-origin-passthrough-array-mismatch/) — a `passthrough` field whose array-ness differs from its `@from` source fails with `ERR_PASSTHROUGH_TYPE_MISMATCH` diff --git a/docs/ports/rust.md b/docs/ports/rust.md index 02687f538b..3693e99d42 100644 --- a/docs/ports/rust.md +++ b/docs/ports/rust.md @@ -617,7 +617,7 @@ outright. | Corpus | Rust today | |---|---| | `registry-conformance` | byte-identical manifest | -| `conformance` (the metamodel corpus) | **587 of 587**, and the ledger is empty | +| `conformance` (the metamodel corpus) | **588 of 588**, and the ledger is empty | | `yaml-conformance` | all 19, and the ledger is empty | | `source-resolution-conformance` | all 30 cases | | `reference-source-conformance` | all 6 cases: a `reference: true` source loads so references resolve against it, a node declared only in reference files is a reference node no generator emits, and a `template.*` declared only there is refused (`ERR_REFERENCE_SOURCE_TEMPLATE`) | diff --git a/examples/showcase/site-payload.json b/examples/showcase/site-payload.json index b98f0a101b..1feb6eb8ae 100644 --- a/examples/showcase/site-payload.json +++ b/examples/showcase/site-payload.json @@ -7,7 +7,7 @@ "metamodel": "1.3" }, "counts": { - "fixtures": 587, + "fixtures": 588, "corpora": 49, "baseTypes": 21 }, diff --git a/fixtures/conformance/error-origin-parent-relative-over-drop/expected-errors.json b/fixtures/conformance/error-origin-parent-relative-over-drop/expected-errors.json new file mode 100644 index 0000000000..fc657a6f24 --- /dev/null +++ b/fixtures/conformance/error-origin-parent-relative-over-drop/expected-errors.json @@ -0,0 +1,17 @@ +{ + "errors": [ + { + "code": "ERR_BAD_ATTR_VALUE", + "source": { + "format": "resolved", + "files": [ + "meta.shop.json" + ], + "jsonPath": "$['metadata.root'].children[0]['object.projection'].children[3]['field.string'].children[0]['origin.passthrough']", + "referrer": "ProgramSummary::title", + "target": "..::..::..::Program.title" + } + } + ], + "warnings": [] +} diff --git a/fixtures/conformance/error-origin-parent-relative-over-drop/input/meta.acme.json b/fixtures/conformance/error-origin-parent-relative-over-drop/input/meta.acme.json new file mode 100644 index 0000000000..47c142c48d --- /dev/null +++ b/fixtures/conformance/error-origin-parent-relative-over-drop/input/meta.acme.json @@ -0,0 +1,83 @@ +{ + "metadata.root": { + "package": "acme", + "children": [ + { + "object.entity": { + "name": "Program", + "children": [ + { + "source.rdb": { + "@table": "programs" + } + }, + { + "field.long": { + "name": "id" + } + }, + { + "field.string": { + "name": "title" + } + }, + { + "identity.primary": { + "name": "pk", + "@fields": [ + "id" + ] + } + }, + { + "relationship.composition": { + "name": "weeks", + "@objectRef": "Week", + "@cardinality": "many" + } + } + ] + } + }, + { + "object.entity": { + "name": "Week", + "children": [ + { + "source.rdb": { + "@table": "weeks" + } + }, + { + "field.long": { + "name": "id" + } + }, + { + "field.long": { + "name": "programId" + } + }, + { + "identity.primary": { + "name": "pk", + "@fields": [ + "id" + ] + } + }, + { + "identity.reference": { + "name": "program", + "@fields": [ + "programId" + ], + "@references": "Program.id" + } + } + ] + } + } + ] + } +} diff --git a/fixtures/conformance/error-origin-parent-relative-over-drop/input/meta.shop.json b/fixtures/conformance/error-origin-parent-relative-over-drop/input/meta.shop.json new file mode 100644 index 0000000000..55241f5333 --- /dev/null +++ b/fixtures/conformance/error-origin-parent-relative-over-drop/input/meta.shop.json @@ -0,0 +1,58 @@ +{ + "metadata.root": { + "package": "acme::shop", + "children": [ + { + "object.projection": { + "name": "ProgramSummary", + "children": [ + { + "source.rdb": { + "@kind": "view", + "@view": "v_program_summary" + } + }, + { + "field.long": { + "name": "id", + "extends": "acme::Program.id" + } + }, + { + "identity.primary": { + "name": "pk", + "extends": "acme::Program.pk" + } + }, + { + "field.string": { + "name": "title", + "children": [ + { + "origin.passthrough": { + "@from": "..::..::..::Program.title" + } + } + ] + } + }, + { + "field.long": { + "name": "weekCount", + "children": [ + { + "origin.aggregate": { + "@agg": "count", + "@of": "..::Week.id", + "@via": "..::Program.weeks" + } + } + ] + } + } + ] + } + } + ] + } +} diff --git a/fixtures/conformance/error-origin-parent-relative-over-drop/providers.json b/fixtures/conformance/error-origin-parent-relative-over-drop/providers.json new file mode 100644 index 0000000000..f9bb435a37 --- /dev/null +++ b/fixtures/conformance/error-origin-parent-relative-over-drop/providers.json @@ -0,0 +1 @@ +["metaobjects-core-types","metaobjects-db"] diff --git a/server/csharp/MetaObjects/Loader/ValidationPasses.cs b/server/csharp/MetaObjects/Loader/ValidationPasses.cs index 3b686316b4..75f2beafcf 100644 --- a/server/csharp/MetaObjects/Loader/ValidationPasses.cs +++ b/server/csharp/MetaObjects/Loader/ValidationPasses.cs @@ -1130,6 +1130,22 @@ private static bool IsReferenceHop(MetaData hop) /// Validate a passthrough `@from` / aggregate `@of` "Entity.field" reference. /// Returns the resolved (entity, field) on full success, or null when any /// error was pushed (malformed shape / unknown entity / unknown field). + /// ADR-0059 §2: a `..::` owner with more parent steps than the referrer's package has segments + /// is ERR_BAD_ATTR_VALUE, the code every reference reader uses for an over-drop. Pushes the + /// error and returns true when the owner over-drops. + private static bool ReportOverDrop(string owner, string referrerPkg, string where, ErrorSource source, List errors) + { + try { NamingRefs.OwnerCandidateKeys(owner, referrerPkg); return false; } + catch (RefOverDropException) + { + errors.Add(new MetaError( + $"{where}: \"{owner}\" climbs above the root package — each \"..::\" drops one segment of the package \"{referrerPkg}\".", + ErrorCode.ERR_BAD_ATTR_VALUE, + Envelope: source)); + return true; + } + } + private static ResolvedFromTarget? ValidateFromPath( string fromAttr, MetaData root, @@ -1161,6 +1177,10 @@ private static bool IsReferenceHop(MetaData hop) return null; } + if (ReportOverDrop(entityName, NamingRefs.EffectivePackage(projection), + $"{label} \"{fromAttr}\" on {projectionName}.{fieldName}", ResolvedSource.From(originSource, referrer, fromAttr), errors)) + return null; + // ADR-0042 — a bare @from/@of head resolves in the projection's package. var sourceObj = FindObject(root, entityName, NamingRefs.EffectivePackage(projection)); if (sourceObj is null) @@ -1244,6 +1264,10 @@ private static bool IsReferenceHop(MetaData hop) string entityName = segments[0]; var relSegments = segments.Skip(1).ToArray(); + if (ReportOverDrop(entityName, NamingRefs.EffectivePackage(projection), + $"origin.@via \"{viaAttr}\" on {projectionName}.{fieldName}", ResolvedSource.From(originSource, referrer, viaAttr), errors)) + return null; + // ADR-0042 — a bare @via HEAD resolves in the projection's package. var currentObj = FindObject(root, entityName, NamingRefs.EffectivePackage(projection)); if (currentObj is null) diff --git a/server/java/metadata/src/main/java/com/metaobjects/loader/ValidationPhase.java b/server/java/metadata/src/main/java/com/metaobjects/loader/ValidationPhase.java index 0b445ba893..0def42134e 100644 --- a/server/java/metadata/src/main/java/com/metaobjects/loader/ValidationPhase.java +++ b/server/java/metadata/src/main/java/com/metaobjects/loader/ValidationPhase.java @@ -5215,6 +5215,22 @@ private static String[] splitViaPath(String via) { return out; } + /** ADR-0059 section 2: an owner with more "..::" than the referrer's package has segments + * is ERR_BAD_ATTR_VALUE, the code every reference reader uses for an over-drop. */ + private static void rejectOverDrop(String owner, String referrerPkg, String where, + com.metaobjects.source.ErrorSource envelope, + String referrer, String authored) { + try { + References.ownerCandidateKeys(owner, referrerPkg); + } catch (References.OverDropException e) { + throw new MetaDataException( + where + ": \"" + owner + "\" climbs above the root package - each \"..::\" drops one segment of the package \"" + + referrerPkg + "\".", + ErrorCode.ERR_BAD_ATTR_VALUE, + ResolvedSource.from(envelope, referrer, authored)); + } + } + private static OriginTarget validateFromOrOfPath(String pathAttr, MetaRoot root, MetaObject projection, String fieldName, String label, @@ -5245,6 +5261,8 @@ private static OriginTarget validateFromOrOfPath(String pathAttr, MetaRoot root, // ADR-0042 — a bare @from/@of head resolves in the projection's package. String referrerPkg = projection.getPackage() == null ? "" : projection.getPackage(); + rejectOverDrop(entityName, referrerPkg, label + " \"" + pathAttr + "\" on " + + projectionName + "." + fieldName, envelope, referrer, pathAttr); MetaObject sourceObj = resolveRootObject(root, entityName, referrerPkg); if (sourceObj == null) { // FR5d — entity half of the ref didn't resolve. target = full ref. @@ -5324,6 +5342,8 @@ private static WalkedViaPath validateViaPath(String viaAttr, MetaRoot root, // ADR-0042 — a bare @via HEAD resolves in the projection's package. String referrerPkg = projection.getPackage() == null ? "" : projection.getPackage(); String entityName = segments[0]; + rejectOverDrop(entityName, referrerPkg, "origin.@via \"" + viaAttr + "\" on " + + projectionName + "." + fieldName, envelope, referrer, viaAttr); MetaObject currentObj = resolveRootObject(root, entityName, referrerPkg); if (currentObj == null) { throw new MetaDataException( diff --git a/server/python/src/metaobjects/loader/validation_passes.py b/server/python/src/metaobjects/loader/validation_passes.py index f3fd8e3b66..84db1150ad 100644 --- a/server/python/src/metaobjects/loader/validation_passes.py +++ b/server/python/src/metaobjects/loader/validation_passes.py @@ -179,7 +179,7 @@ IDENTITY_SECONDARY_ATTR_EXPR as IDENTITY_ATTR_EXPR, ) from ..source import resolved_source -from ..naming_refs import did_you_mean_hint, resolve_object_ref, referrer_package_of, split_child_tail +from ..naming_refs import did_you_mean_hint, resolve_object_ref, referrer_package_of, split_child_tail, owner_candidate_keys, RefOverDropError from ..naming_refs import ref_target as bound_ref_target from ..meta.core.field.flattened_member import resolve_flattened_member from ..meta.core.object.effective_projection_filter import effective_projection_filter @@ -2314,6 +2314,8 @@ def _validate_entity_field_ref( ) return None entity_name, field_name = parts + if _report_over_drop(entity_name, referrer_pkg, context, attr_name, ref, origin_node, referrer, errors): + return None # ADR-0042 — a bare @from/@of entity head resolves in the host/projection's package. entity = resolve_object_ref(root, entity_name, referrer_pkg) if entity is None: @@ -2379,6 +2381,25 @@ class WalkedViaPath(NamedTuple): reverse: Mapping[int, str] | None = None +def _report_over_drop(owner: str, referrer_pkg: str, where: str, attr_name: str, ref: str, + origin_node: MetaData, referrer: str, errors: list[MetaError]) -> bool: + """ADR-0059 §2: a ``..::`` owner climbing above the root package is + ERR_BAD_ATTR_VALUE. Appends the error and returns True on over-drop.""" + try: + owner_candidate_keys(owner, referrer_pkg) + return False + except RefOverDropError: + errors.append( + MetaError( + f"{where} @{attr_name}='{ref}': \"{owner}\" climbs above the root package — " + f"each \"..::\" drops one segment of the package \"{referrer_pkg}\".", + ErrorCode.ERR_BAD_ATTR_VALUE, + envelope=resolved_source(origin_node.source, referrer, ref), + ) + ) + return True + + def _validate_via_path( via: str, context: str, @@ -2420,6 +2441,8 @@ def _validate_via_path( # First segment: starting entity. ADR-0042 — a bare @via HEAD resolves in the # host/projection's package. current_name = segments[0] + if _report_over_drop(current_name, referrer_pkg, context, "via", via, origin_node, referrer, errors): + return None current_entity = resolve_object_ref(root, current_name, referrer_pkg) if current_entity is None: errors.append( diff --git a/server/rust/metaobjects/src/validate/origin.rs b/server/rust/metaobjects/src/validate/origin.rs index 03b56f2163..aee561ba44 100644 --- a/server/rust/metaobjects/src/validate/origin.rs +++ b/server/rust/metaobjects/src/validate/origin.rs @@ -12,7 +12,7 @@ use std::collections::{HashMap, HashSet}; use serde_json::Value; use crate::errors::{MetaError, WARN_LEGACY}; -use crate::loader::split_child_tail; +use crate::loader::{owner_candidate_keys, split_child_tail}; use crate::naming::{NamingCtx, collection_name_of}; use crate::node::{NodeId, Tree}; use crate::source::ErrorSource; @@ -93,6 +93,23 @@ fn push(errs: &mut Errs, code: &'static str, msg: String, src: &ErrorSource) { errs.push(MetaError::at(code, msg, src.clone())); } +/// ADR-0059 §2: a `..::` owner climbing above the root package is `ERR_BAD_ATTR_VALUE`. +/// Pushes the error and returns true when `owner` over-drops. +fn report_over_drop(errs: &mut Errs, owner: &str, pkg: &str, at: &str, src: &ErrorSource) -> bool { + if owner_candidate_keys(owner, pkg).is_ok() { + return false; + } + push( + errs, + ERR_BAD_ATTR_VALUE, + format!( + "{at}: \"{owner}\" climbs above the root package; each \"..::\" drops one segment of the package \"{pkg}\"." + ), + src, + ); + true +} + /// `resolvedSource(src, referrer, target)`. fn resolved_src(src: &ErrorSource, referrer: String, target: &str) -> ErrorSource { ErrorSource::Resolved { @@ -322,6 +339,10 @@ fn validate_from_path( ); return None; } + let at = format!("{label} \"{from}\" on {}.{field_name}", h.name); + if report_over_drop(errs, entity_name, pkg, &at, &rs()) { + return None; + } let Some(entity) = m.find_object(entity_name, pkg) else { push( errs, @@ -394,6 +415,9 @@ fn validate_via_path( ); return None; } + if report_over_drop(errs, segments[0], m.pkg(host), &at, &rs(via)) { + return None; + } let Some(mut cur) = m.find_object(segments[0], m.pkg(host)) else { push( errs, diff --git a/server/rust/metaobjects/tests/conformance-expected-failures.json b/server/rust/metaobjects/tests/conformance-expected-failures.json index 658631be5c..027a365b2d 100644 --- a/server/rust/metaobjects/tests/conformance-expected-failures.json +++ b/server/rust/metaobjects/tests/conformance-expected-failures.json @@ -1,6 +1,6 @@ { "language": "rust", "notes": "The Rust port passes every fixture of the shared metamodel corpus, so the ledger is empty. The ledger may only shrink and is kept for the day a new fixture lands that Rust does not pass yet: list it here with the reason, and it leaves when the work that covers it lands. minPassing is the number of fixtures known to pass; the run fails when fewer do, and it may only rise.", - "minPassing": 587, + "minPassing": 588, "fixtures": [] } diff --git a/server/typescript/packages/metadata/src/loader/validation-passes.ts b/server/typescript/packages/metadata/src/loader/validation-passes.ts index cba679ef04..c86001d3fe 100644 --- a/server/typescript/packages/metadata/src/loader/validation-passes.ts +++ b/server/typescript/packages/metadata/src/loader/validation-passes.ts @@ -39,7 +39,7 @@ import { effectiveProjectionFilter } from "../core/object/effective-projection-f import type { MetaReferenceIdentity } from "../core/identity/meta-identity.js"; import { contradictionHint, contradictionsFor } from "../attr-contradictions.js"; import { ParseError, type ErrorCode } from "../errors.js"; -import { resolveObjectRef, didYouMeanHint, refTarget, splitChildTail } from "../naming-refs.js"; +import { resolveObjectRef, didYouMeanHint, refTarget, splitChildTail, ownerCandidateKeys, RefOverDropError } from "../naming-refs.js"; import { PACKAGE_SEPARATOR, CHILD_REF_SEPARATOR } from "../shared/structural.js"; import { resolvedSource, type ErrorSource } from "../source.js"; import { @@ -644,6 +644,31 @@ function _hopTargetName(hop: MetaData): unknown { : hop.attr(RELATIONSHIP_ATTR_OBJECT_REF); } +/** + * ADR-0059 §2: a parent-relative owner with more `..::` than the referrer's package has + * segments is ERR_BAD_ATTR_VALUE, the code every reference reader uses for an over-drop. + * Pushes the error and returns true when `owner` over-drops. + */ +function _reportOverDrop( + owner: string, + referrerPkg: string, + where: string, + source: ErrorSource, + errors: ParseError[], +): boolean { + try { + ownerCandidateKeys(owner, referrerPkg); + return false; + } catch (err) { + if (!(err instanceof RefOverDropError)) throw err; + errors.push(new ParseError( + `${where}: "${owner}" climbs above the root package — each "..::" drops one segment of the package "${referrerPkg}".`, + { code: "ERR_BAD_ATTR_VALUE", source }, + )); + return true; + } +} + /** * Split a `@via` path into its owner and hops. The owner ends at the first `.` * after the last `::` (ADR-0059 §2), so `..::Entity.rel` keeps `..::Entity`. @@ -702,6 +727,9 @@ function _validateFromPath( ); return undefined; } + if (_reportOverDrop(entityName, referrerPkg, `${label} "${fromAttr}" on ${projectionName}.${fieldName}`, resolvedSource(originSource, referrer, fromAttr), errors)) { + return undefined; + } const sourceObj = _findObject(root, entityName, referrerPkg); if (!sourceObj) { // FR5d — entity half of the ref didn't resolve. target = full ref. @@ -800,6 +828,9 @@ function _validateViaPath( return undefined; } const [entityName, ...relSegments] = segments as [string, ...string[]]; + if (_reportOverDrop(entityName, referrerPkg, `origin.@via "${viaAttr}" on ${projectionName}.${fieldName}`, resolvedSource(originSource, referrer, viaAttr), errors)) { + return undefined; + } let currentObj = _findObject(root, entityName, referrerPkg); if (!currentObj) { errors.push( From ba7a53dbcf49265835e58cb4fda21b0a16e26655 Mon Sep 17 00:00:00 2001 From: Doug Mealing Date: Thu, 3 Dec 2026 03:46:24 -0500 Subject: [PATCH 4/6] no-mistakes(review): apply reviewer inline fixes --- server/csharp/MetaObjects/Loader/ValidationPasses.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/csharp/MetaObjects/Loader/ValidationPasses.cs b/server/csharp/MetaObjects/Loader/ValidationPasses.cs index 75f2beafcf..a306e6d50a 100644 --- a/server/csharp/MetaObjects/Loader/ValidationPasses.cs +++ b/server/csharp/MetaObjects/Loader/ValidationPasses.cs @@ -1127,9 +1127,6 @@ private static bool IsReferenceHop(MetaData hop) /// against the field node identity. private readonly record struct ResolvedFromTarget(MetaData Entity, MetaData Field); - /// Validate a passthrough `@from` / aggregate `@of` "Entity.field" reference. - /// Returns the resolved (entity, field) on full success, or null when any - /// error was pushed (malformed shape / unknown entity / unknown field). /// ADR-0059 §2: a `..::` owner with more parent steps than the referrer's package has segments /// is ERR_BAD_ATTR_VALUE, the code every reference reader uses for an over-drop. Pushes the /// error and returns true when the owner over-drops. @@ -1146,6 +1143,9 @@ private static bool ReportOverDrop(string owner, string referrerPkg, string wher } } + /// Validate a passthrough `@from` / aggregate `@of` "Entity.field" reference. + /// Returns the resolved (entity, field) on full success, or null when any + /// error was pushed (malformed shape / unknown entity / unknown field). private static ResolvedFromTarget? ValidateFromPath( string fromAttr, MetaData root, From b3cb7a1add941539c2812fcac97fd1396afd1f01 Mon Sep 17 00:00:00 2001 From: Doug Mealing Date: Thu, 3 Dec 2026 03:48:31 -0500 Subject: [PATCH 5/6] no-mistakes(review): revert unneeded deprecation-lint split edits --- changelog.d/origin-parent-relative-paths.md | 12 ++++++------ ...tiveTests.cs => ParentRelativeOriginLoadTests.cs} | 6 +++--- server/csharp/MetaObjects.Cli/DeprecationLint.cs | 6 +++--- .../packages/cli/src/lib/deprecation-lint.ts | 10 ++++------ .../packages/cli/test/unit/deprecation-lint.test.ts | 4 ++-- 5 files changed, 18 insertions(+), 20 deletions(-) rename server/csharp/MetaObjects.Cli.Tests/{DeprecationLintParentRelativeTests.cs => ParentRelativeOriginLoadTests.cs} (88%) diff --git a/changelog.d/origin-parent-relative-paths.md b/changelog.d/origin-parent-relative-paths.md index 4e946d6b95..f7f49ae89b 100644 --- a/changelog.d/origin-parent-relative-paths.md +++ b/changelog.d/origin-parent-relative-paths.md @@ -3,9 +3,9 @@ `ERR_INVALID_ORIGIN` because the loaders cut the value at its first `.`, inside the `..::` prefix. The TypeScript, C#, Java (and so Kotlin), Python and Rust loaders now split it where ADR-0059 says, at the first `.` after the last `::`, and resolve it exactly as the qualified - `pkg::Entity.field` form. The TypeScript and C# deprecated-reference lints split the same way. The new - conformance fixture `origin-parent-relative-refs` loads to the same model as its `pkg::` twin, - and `error-origin-parent-relative-unresolved` and `error-origin-parent-relative-wrong-kind` - keep the existing `ERR_INVALID_ORIGIN` refusals. A `..::` origin path that climbs above the - root package is `ERR_BAD_ATTR_VALUE`, the code every other reference uses for that case - (`error-origin-parent-relative-over-drop`). No registry, manifest or generated output changes. + `pkg::Entity.field` form. The new conformance fixture `origin-parent-relative-refs` loads to the + same model as its `pkg::` twin, and `error-origin-parent-relative-unresolved` and + `error-origin-parent-relative-wrong-kind` keep the existing `ERR_INVALID_ORIGIN` refusals. A + `..::` origin path that climbs above the root package is `ERR_BAD_ATTR_VALUE`, the code every + other reference uses for that case (`error-origin-parent-relative-over-drop`). No registry, + manifest or generated output changes. diff --git a/server/csharp/MetaObjects.Cli.Tests/DeprecationLintParentRelativeTests.cs b/server/csharp/MetaObjects.Cli.Tests/ParentRelativeOriginLoadTests.cs similarity index 88% rename from server/csharp/MetaObjects.Cli.Tests/DeprecationLintParentRelativeTests.cs rename to server/csharp/MetaObjects.Cli.Tests/ParentRelativeOriginLoadTests.cs index b6f5a6583c..107a528b51 100644 --- a/server/csharp/MetaObjects.Cli.Tests/DeprecationLintParentRelativeTests.cs +++ b/server/csharp/MetaObjects.Cli.Tests/ParentRelativeOriginLoadTests.cs @@ -3,8 +3,8 @@ namespace MetaObjects.Cli.Tests; -/// ADR-0059 §2: origin @of / @via split at the first '.' after the last '::', so `..::` forms lint as their `pkg::` twins. -public class DeprecationLintParentRelativeTests +/// End-to-end loader coverage (ADR-0059 §2): `..::` origin @of / @via load, and are resolved before the lint reads them. +public class ParentRelativeOriginLoadTests { private const string Week = """ { "metadata.root": { "package": "acme", "children": [ @@ -29,7 +29,7 @@ public class DeprecationLintParentRelativeTests """; [Fact] - public void Parent_relative_of_and_via_warn_on_the_deprecated_targets() + public void Parent_relative_of_and_via_load_and_the_lint_reports_the_deprecated_targets_after_resolution() { var scratch = Environment.GetEnvironmentVariable("DEV_SCRATCH") ?? Path.GetTempPath(); var dir = Path.Combine(scratch, "mo-dep-lint-" + Guid.NewGuid().ToString("N")); diff --git a/server/csharp/MetaObjects.Cli/DeprecationLint.cs b/server/csharp/MetaObjects.Cli/DeprecationLint.cs index 6ad4ce2f3d..51308be0d0 100644 --- a/server/csharp/MetaObjects.Cli/DeprecationLint.cs +++ b/server/csharp/MetaObjects.Cli/DeprecationLint.cs @@ -104,8 +104,8 @@ private static bool Consider(MetaData referrer, string path, string verb, MetaDa private static string HeadOf(string raw) { - // ADR-0059 §2: the head ends at the first '.' after the last '::', so `..::Entity` stays whole. - return NamingRefs.SplitChildTail(raw).Owner; + var dot = raw.IndexOf('.'); + return dot < 0 ? raw : raw[..dot]; } private static MetaObject? ResolveEntity(MetaData root, string reference, string referrerPkg) => @@ -137,7 +137,7 @@ private static void CheckEntityFieldPath( /// Walk an @via path, checking the head entity and every hop; stop at the first segment that does not resolve. private static void CheckVia(MetaData root, MetaData origin, string path, string verb, string via, string pkg, List findings) { - var segments = NamingRefs.SplitViaPath(via); + var segments = via.Split('.'); if (segments[0] == "") return; var current = ResolveEntity(root, segments[0], pkg); if (current is null) return; diff --git a/server/typescript/packages/cli/src/lib/deprecation-lint.ts b/server/typescript/packages/cli/src/lib/deprecation-lint.ts index 366f57852b..115ee48222 100644 --- a/server/typescript/packages/cli/src/lib/deprecation-lint.ts +++ b/server/typescript/packages/cli/src/lib/deprecation-lint.ts @@ -51,7 +51,6 @@ import { isMetaObject, resolveObjectRef, refTarget, - splitChildTail, type MetaData, type MetaObject, } from "@metaobjectsdev/metadata"; @@ -147,10 +146,10 @@ function considerTarget(referrer: MetaData, referrerPath: string, verb: string, /** Split a dotted reference into its entity HEAD and member tail ("Entity.field" -> * "Entity" / "field"). `@objectRef` carries no tail (a pure object ref) and is - * resolved whole by the caller; `@references`/`@from`/`@of`/`@via` do. The head - * ends at the first `.` after the last `::` (ADR-0059 §2), so `..::Entity` stays whole. */ + * resolved whole by the caller; `@references`/`@from`/`@of`/`@via` do. */ function headOf(raw: string): string { - return splitChildTail(raw).owner; + const dot = raw.indexOf("."); + return dot === -1 ? raw : raw.slice(0, dot); } function resolveEntityRef(root: MetaData, ref: string, referrerPkg: string): MetaObject | undefined { @@ -221,8 +220,7 @@ function checkViaPath( referrerPkg: string, out: Diagnostic[], ): void { - const head = headOf(via); - const segments = [head, ...(via.length > head.length ? via.slice(head.length + 1).split(".") : [])]; + const segments = via.split("."); const headSegment = segments[0]; if (headSegment === undefined || headSegment === "") return; let current = resolveEntityRef(root, headSegment, referrerPkg); diff --git a/server/typescript/packages/cli/test/unit/deprecation-lint.test.ts b/server/typescript/packages/cli/test/unit/deprecation-lint.test.ts index 2d4c636f83..85aa7dfd46 100644 --- a/server/typescript/packages/cli/test/unit/deprecation-lint.test.ts +++ b/server/typescript/packages/cli/test/unit/deprecation-lint.test.ts @@ -453,8 +453,8 @@ describe("deprecated-reference lint — origin @of / @via (aggregate)", () => { }); }); -describe("deprecated-reference lint — parent-relative origin paths (ADR-0059 §2)", () => { - test("`..::` @of and @via resolve as their `pkg::` twins and warn on the deprecated targets", async () => { +describe("end-to-end loader coverage — parent-relative origin paths (ADR-0059 §2)", () => { + test("`..::` @of and @via load, and the lint still reports the deprecated targets after resolution", async () => { const findings = await lint([ { "object.entity": { From 3691fe22815b187452b1e964b298325582725f0a Mon Sep 17 00:00:00 2001 From: Doug Mealing Date: Thu, 3 Dec 2026 04:04:59 -0500 Subject: [PATCH 6/6] no-mistakes(test): refuse trailing-dot origin @via in Java and Kotlin --- AGENTS.md | 2 +- README.md | 2 +- changelog.d/origin-parent-relative-paths.md | 4 +- docs/CONFORMANCE.md | 8 +- docs/features/templates-and-payloads.md | 1 + docs/ports/rust.md | 2 +- examples/showcase/site-payload.json | 2 +- .../expected-errors.json | 29 +++++++ .../input/meta.acme.json | 83 +++++++++++++++++++ .../input/meta.shop.json | 72 ++++++++++++++++ .../providers.json | 1 + .../metaobjects/loader/ValidationPhase.java | 17 ++-- .../tests/conformance-expected-failures.json | 2 +- 13 files changed, 208 insertions(+), 17 deletions(-) create mode 100644 fixtures/conformance/error-origin-via-trailing-dot/expected-errors.json create mode 100644 fixtures/conformance/error-origin-via-trailing-dot/input/meta.acme.json create mode 100644 fixtures/conformance/error-origin-via-trailing-dot/input/meta.shop.json create mode 100644 fixtures/conformance/error-origin-via-trailing-dot/providers.json diff --git a/AGENTS.md b/AGENTS.md index d0c2578c71..2e9e6d140a 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -74,7 +74,7 @@ PyPI has had no product change since `0.25.0` — nothing is broken. - **Kotlin** — `codegen-kotlin` (laid out by `KotlinWriter`, ADR-0063, on the JVM): entity + Exposed table + Spring controller + payload + relations + filter allowlist + validator + stored-proc + output-parser generators. `integration-tests-kotlin` runs the persistence-conformance corpus through Exposed against Testcontainers Postgres. **Cross-port conformance corpora** (every port runs the shared corpus): -- Metamodel: `fixtures/conformance/` (588 fixtures; 49 shared corpora in total — per-corpus counts + the corpus x port matrix live in `docs/CONFORMANCE.md`). TS / C# / Java / Python all green. +- Metamodel: `fixtures/conformance/` (589 fixtures; 49 shared corpora in total — per-corpus counts + the corpus x port matrix live in `docs/CONFORMANCE.md`). TS / C# / Java / Python all green. - Render: `fixtures/render-conformance/`. TS / Java / Kotlin / Python / C# / Rust byte-identical; the C# and Rust drift ledgers are empty (`docs/CONFORMANCE.md`). - Persistence: `fixtures/persistence-conformance/`. **Query** scenarios run on every port (TS / C# / Java / Kotlin / Python; `op: guardedUpdate` is TS-only until each port's 1.3.0 guarded update lands), each provisioning its test DB by executing the committed, TS-produced `canonical/schema.postgres.sql` (Postgres only — Derby dropped for the cross-port query corpus, ADR-0015; the FR-044 `report-*` scenarios also run on SQLite, MySQL and D1 where a port has the engine, see [docs/CONFORMANCE.md](docs/CONFORMANCE.md)). The **migration** scenarios are exercised by **TS only** (the Node reference helper writes them; a native tool is equally first-class, ADR-0015 Amendment 2). **The corpus now gates WRITES, not just reads (SP-H):** an `op: roundtrip` scenario type INSERTs through each port's runtime/ORM write codec (NOT raw SQL), reads the row back, and asserts the wire-normalized value. The `AllTypes` entity (`roundtrip-all-types.yaml`) carries one field of **every** persistable `field.*` subtype — string/int/long/double/float/decimal/boolean/date/time/timestamp(+tz)/currency/enum/uuid/object — plus an **array-of-VO** `field.object @isArray @storage:jsonb` column (`labels`, written as 2-element / empty-`[]` / single-element arrays across the three rows) — so every subtype write+read (incl. the array-of-value-object jsonb codec) round-trips through every port against Testcontainers PG. (`field.byte`/`field.short`/`field.class` were cut as non-functional registration-only stubs — the matrix tracks only genuinely-supported subtypes; see `fixtures/registry-conformance/README.md` → "Per-subtype write-round-trip matrix".) - API-contract: `fixtures/api-contract-conformance/`. TS / C# / Java / Kotlin / Python all green — each port runs **two lanes**: a hand-rolled reference server AND its **generated** API artifact booted over HTTP (the deployed controller/routes; TS+C# full-stack vs Testcontainers PG, Java/Kotlin/Python generated controller + in-memory repo behind the consumer seam). The generated fan-out found 10 real deployment bugs golden snapshots missed. Three sub-corpora run the **generated lane only, on all five ports** — `write-through/`, `projection/` (F22: a view-only `object.projection` serves GET list + GET by id and answers every write verb with `405 {"error": "method_not_allowed"}`) and `report/` (FR-044: a view-backed `object.report` serves GET list, answers `POST` with that same `405`, and mounts no `/{id}` route). That is deliberate, not a gap: what is under test is whether a port's GENERATOR emits those routes, and a hand-rolled reference server would answer every scenario by construction. The `m2m/` sub-corpus also gates **TPH x M:N together** (base-declared, subtype-declared, abstract-mid-declared, a non-subtype source onto a subtype TARGET, and the cross-subtype source id answering `200 []`) — the two corpora were originally built disjoint (`tph/` had no relationships, `m2m/` no discriminators), which is precisely how that defect class survived. diff --git a/README.md b/README.md index 6b4da766ad..4f6b86098a 100644 --- a/README.md +++ b/README.md @@ -172,7 +172,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 in your own tool or the Node `meta migrate` reference helper (ADR-0015) | [`docs/ports/python.md`](docs/ports/python.md) | [`server/python/`](server/python/) | -| Rust | **Crates ready to publish, not yet published** — loader (JSON + YAML), project and source resolution, naming and all 41 validation passes; 588 / 588 metamodel conformance; prompt render and the reply parser (`metaobjects-render`); `cargo meta init` / `gen` / `verify` / `eject` with eleven generators — the model crate through the sqlx store, the service and its opt-in axum routes (`service-routes`) to a typed client and its commands (ADR-0065). Schema migrations stay with the Node `meta` tool | [`docs/ports/rust.md`](docs/ports/rust.md) | [`server/rust/`](server/rust/) | +| Rust | **Crates ready to publish, not yet published** — loader (JSON + YAML), project and source resolution, naming and all 41 validation passes; 589 / 589 metamodel conformance; prompt render and the reply parser (`metaobjects-render`); `cargo meta init` / `gen` / `verify` / `eject` with eleven generators — the model crate through the sqlx store, the service and its opt-in axum routes (`service-routes`) to a typed client and its commands (ADR-0065). Schema migrations stay with the Node `meta` tool | [`docs/ports/rust.md`](docs/ports/rust.md) | [`server/rust/`](server/rust/) | ## Capability matrix diff --git a/changelog.d/origin-parent-relative-paths.md b/changelog.d/origin-parent-relative-paths.md index f7f49ae89b..173c233732 100644 --- a/changelog.d/origin-parent-relative-paths.md +++ b/changelog.d/origin-parent-relative-paths.md @@ -8,4 +8,6 @@ `error-origin-parent-relative-wrong-kind` keep the existing `ERR_INVALID_ORIGIN` refusals. A `..::` origin path that climbs above the root package is `ERR_BAD_ATTR_VALUE`, the code every other reference uses for that case (`error-origin-parent-relative-over-drop`). No registry, - manifest or generated output changes. + manifest or generated output changes. Java (and so Kotlin) now refuses a trailing-dot `@via` + (such as `acme::Week.days.`) with `ERR_INVALID_ORIGIN`, like the other ports, and reports one + error per broken origin instead of only the first (`error-origin-via-trailing-dot`). diff --git a/docs/CONFORMANCE.md b/docs/CONFORMANCE.md index dabb0b095e..2bc016b3b4 100644 --- a/docs/CONFORMANCE.md +++ b/docs/CONFORMANCE.md @@ -26,7 +26,7 @@ regenerate with `ls -d fixtures//*/ | wc -l` for directory-shaped corpor | Corpus | Fixtures | TS | Java | Kotlin | C# | Python | Rust | |---|---|---|---|---|---|---|---| -| [`fixtures/conformance/`](../fixtures/conformance/) (metamodel) | 588 | ✓ | ✓ | inherits via `metadata-ktx` | ✓ | ✓ | ✓ (588 / 588, empty ledger) | +| [`fixtures/conformance/`](../fixtures/conformance/) (metamodel) | 589 | ✓ | ✓ | inherits via `metadata-ktx` | ✓ | ✓ | ✓ (589 / 589, empty ledger) | | [`fixtures/yaml-conformance/`](../fixtures/yaml-conformance/) | 19 | 19 / 19 | 19 / 19 | inherits via Java | 18 / 19 (1 ledgered: `error-yaml-coerced-hex-in-string` — YamlDotNet doesn't coerce `0xFF`) | 19 / 19 | 19 / 19 | | [`fixtures/verify-conformance/`](../fixtures/verify-conformance/) | 45 | ✓ | ✓ | inherits via Java | ✓ | ✓ | ✓ | | [`fixtures/verify-strict-conformance/`](../fixtures/verify-strict-conformance/) | 1 | ✓ | — | — | — | ✓ | — | @@ -82,7 +82,7 @@ and render ledgers; the api-contract runner's list of sub-corpora not built yet) shrink, and the corpora without one assert each case outright. 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 ADR-0065 turns the warning off. A regression still fails: the ledger's -`minPassing` (588) is the number of fixtures known to pass, and the run fails when fewer do. +`minPassing` (589) is the number of fixtures known to pass, and the run fails when fewer do. Beside the corpora it runs the codegen-compile gate (below) with every shipped generator, a scale gate over twenty copies of the fitness model, and `examples/rust-service/`'s HTTP test. [The Rust port page](ports/rust.md#conformance) has the detail. @@ -445,7 +445,7 @@ carry it, and a model that uses it fails there by name. There is no row per pack ## Fixture-to-doc mapping -### `fixtures/conformance/` — metamodel loader + canonical serializer (588) +### `fixtures/conformance/` — metamodel loader + canonical serializer (589) | Fixture prefix | Feature doc | |---|---| @@ -951,7 +951,7 @@ shared input. ## Orphaned fixtures (tested but not yet documented) -The fixtures in the nine corpora mapped above (metamodel 588 + yaml 19 + verify 45 +The fixtures in the nine corpora mapped above (metamodel 589 + yaml 19 + verify 45 + render 26 + persistence 68 + api-contract 191 + source-resolution 30 + scope 10 + dependency 47) each map to a feature doc, and so do the two requirement corpora, `rules-check-conformance`, `shared-model-conformance`, the `cube-model` corpus, `explorer-conformance` and `list-query-conformance`, whose case lists live in their own READMEs. None are orphaned today. The remaining diff --git a/docs/features/templates-and-payloads.md b/docs/features/templates-and-payloads.md index 6c321586f7..f0d2e8764e 100644 --- a/docs/features/templates-and-payloads.md +++ b/docs/features/templates-and-payloads.md @@ -801,6 +801,7 @@ for payload typing per #270) - [`fixtures/conformance/error-origin-parent-relative-unresolved/`](../../fixtures/conformance/error-origin-parent-relative-unresolved/) — a `..::` `@from` naming no entity is `ERR_INVALID_ORIGIN` - [`fixtures/conformance/error-origin-parent-relative-wrong-kind/`](../../fixtures/conformance/error-origin-parent-relative-wrong-kind/) — a `..::` `@via` whose hop names a field, not a relationship or reference, is `ERR_INVALID_ORIGIN` - [`fixtures/conformance/error-origin-parent-relative-over-drop/`](../../fixtures/conformance/error-origin-parent-relative-over-drop/) — a `..::` path with more parent steps than the referrer's package has segments is `ERR_BAD_ATTR_VALUE` (ADR-0059 §2) +- [`fixtures/conformance/error-origin-via-trailing-dot/`](../../fixtures/conformance/error-origin-via-trailing-dot/) — a `@via` ending in `.`, written `..::` or `pkg::`, is `ERR_INVALID_ORIGIN`, one error per origin - [`fixtures/conformance/error-origin-bad-aggregate-fn/`](../../fixtures/conformance/error-origin-bad-aggregate-fn/) — unknown `@agg` rejected - [`fixtures/conformance/error-origin-passthrough-type-mismatch/`](../../fixtures/conformance/error-origin-passthrough-type-mismatch/) — a `passthrough` field whose `field.` differs from its `@from` source fails with `ERR_PASSTHROUGH_TYPE_MISMATCH` - [`fixtures/conformance/error-origin-passthrough-array-mismatch/`](../../fixtures/conformance/error-origin-passthrough-array-mismatch/) — a `passthrough` field whose array-ness differs from its `@from` source fails with `ERR_PASSTHROUGH_TYPE_MISMATCH` diff --git a/docs/ports/rust.md b/docs/ports/rust.md index 3693e99d42..a6cb72b000 100644 --- a/docs/ports/rust.md +++ b/docs/ports/rust.md @@ -617,7 +617,7 @@ outright. | Corpus | Rust today | |---|---| | `registry-conformance` | byte-identical manifest | -| `conformance` (the metamodel corpus) | **588 of 588**, and the ledger is empty | +| `conformance` (the metamodel corpus) | **589 of 589**, and the ledger is empty | | `yaml-conformance` | all 19, and the ledger is empty | | `source-resolution-conformance` | all 30 cases | | `reference-source-conformance` | all 6 cases: a `reference: true` source loads so references resolve against it, a node declared only in reference files is a reference node no generator emits, and a `template.*` declared only there is refused (`ERR_REFERENCE_SOURCE_TEMPLATE`) | diff --git a/examples/showcase/site-payload.json b/examples/showcase/site-payload.json index 1feb6eb8ae..61e5899853 100644 --- a/examples/showcase/site-payload.json +++ b/examples/showcase/site-payload.json @@ -7,7 +7,7 @@ "metamodel": "1.3" }, "counts": { - "fixtures": 588, + "fixtures": 589, "corpora": 49, "baseTypes": 21 }, diff --git a/fixtures/conformance/error-origin-via-trailing-dot/expected-errors.json b/fixtures/conformance/error-origin-via-trailing-dot/expected-errors.json new file mode 100644 index 0000000000..b6a3927e8c --- /dev/null +++ b/fixtures/conformance/error-origin-via-trailing-dot/expected-errors.json @@ -0,0 +1,29 @@ +{ + "errors": [ + { + "code": "ERR_INVALID_ORIGIN", + "source": { + "format": "resolved", + "files": [ + "meta.shop.json" + ], + "jsonPath": "$['metadata.root'].children[0]['object.projection'].children[4]['field.long'].children[0]['origin.aggregate']", + "referrer": "ProgramSummary::weekCount", + "target": "..::Program.weeks." + } + }, + { + "code": "ERR_INVALID_ORIGIN", + "source": { + "format": "resolved", + "files": [ + "meta.shop.json" + ], + "jsonPath": "$['metadata.root'].children[0]['object.projection'].children[5]['field.long'].children[0]['origin.aggregate']", + "referrer": "ProgramSummary::qualifiedWeekCount", + "target": "acme::Program.weeks." + } + } + ], + "warnings": [] +} diff --git a/fixtures/conformance/error-origin-via-trailing-dot/input/meta.acme.json b/fixtures/conformance/error-origin-via-trailing-dot/input/meta.acme.json new file mode 100644 index 0000000000..47c142c48d --- /dev/null +++ b/fixtures/conformance/error-origin-via-trailing-dot/input/meta.acme.json @@ -0,0 +1,83 @@ +{ + "metadata.root": { + "package": "acme", + "children": [ + { + "object.entity": { + "name": "Program", + "children": [ + { + "source.rdb": { + "@table": "programs" + } + }, + { + "field.long": { + "name": "id" + } + }, + { + "field.string": { + "name": "title" + } + }, + { + "identity.primary": { + "name": "pk", + "@fields": [ + "id" + ] + } + }, + { + "relationship.composition": { + "name": "weeks", + "@objectRef": "Week", + "@cardinality": "many" + } + } + ] + } + }, + { + "object.entity": { + "name": "Week", + "children": [ + { + "source.rdb": { + "@table": "weeks" + } + }, + { + "field.long": { + "name": "id" + } + }, + { + "field.long": { + "name": "programId" + } + }, + { + "identity.primary": { + "name": "pk", + "@fields": [ + "id" + ] + } + }, + { + "identity.reference": { + "name": "program", + "@fields": [ + "programId" + ], + "@references": "Program.id" + } + } + ] + } + } + ] + } +} diff --git a/fixtures/conformance/error-origin-via-trailing-dot/input/meta.shop.json b/fixtures/conformance/error-origin-via-trailing-dot/input/meta.shop.json new file mode 100644 index 0000000000..fe0a6f5517 --- /dev/null +++ b/fixtures/conformance/error-origin-via-trailing-dot/input/meta.shop.json @@ -0,0 +1,72 @@ +{ + "metadata.root": { + "package": "acme::shop", + "children": [ + { + "object.projection": { + "name": "ProgramSummary", + "children": [ + { + "source.rdb": { + "@kind": "view", + "@view": "v_program_summary" + } + }, + { + "field.long": { + "name": "id", + "extends": "acme::Program.id" + } + }, + { + "identity.primary": { + "name": "pk", + "extends": "acme::Program.pk" + } + }, + { + "field.string": { + "name": "title", + "children": [ + { + "origin.passthrough": { + "@from": "..::Program.title" + } + } + ] + } + }, + { + "field.long": { + "name": "weekCount", + "children": [ + { + "origin.aggregate": { + "@agg": "count", + "@of": "..::Week.id", + "@via": "..::Program.weeks." + } + } + ] + } + }, + { + "field.long": { + "name": "qualifiedWeekCount", + "children": [ + { + "origin.aggregate": { + "@agg": "count", + "@of": "acme::Week.id", + "@via": "acme::Program.weeks." + } + } + ] + } + } + ] + } + } + ] + } +} diff --git a/fixtures/conformance/error-origin-via-trailing-dot/providers.json b/fixtures/conformance/error-origin-via-trailing-dot/providers.json new file mode 100644 index 0000000000..f9bb435a37 --- /dev/null +++ b/fixtures/conformance/error-origin-via-trailing-dot/providers.json @@ -0,0 +1 @@ +["metaobjects-core-types","metaobjects-db"] diff --git a/server/java/metadata/src/main/java/com/metaobjects/loader/ValidationPhase.java b/server/java/metadata/src/main/java/com/metaobjects/loader/ValidationPhase.java index 0def42134e..de3b206457 100644 --- a/server/java/metadata/src/main/java/com/metaobjects/loader/ValidationPhase.java +++ b/server/java/metadata/src/main/java/com/metaobjects/loader/ValidationPhase.java @@ -267,7 +267,7 @@ public static void run(MetaRoot root, MetaDataLoader loader) { collected.add(MetaDataException.ofCodeName(e.message(), e.code(), e.source())); } } - pass(collected, () -> validateOrigins(root)); + validateOrigins(root, collected); // FR-024 B6 — derived-field providability (entity origin fields need a read source). pass(collected, () -> validateDerivedFieldProvidability(root)); pass(collected, () -> validateObjectFieldStorage(root)); @@ -3313,13 +3313,14 @@ private static String attrStringOrNull(MetaData node, String attrName) { * @param root the root node to walk * @throws MetaDataException on the first error found (eager-throw) */ - static void validateOrigins(MetaRoot root) { + static void validateOrigins(MetaRoot root, java.util.List collected) { for (MetaData rootChild : root.getChildren(MetaData.class, false)) { - walkOriginsOnObject(root, rootChild); + walkOriginsOnObject(root, rootChild, collected); } } - private static void walkOriginsOnObject(MetaRoot root, MetaData node) { + private static void walkOriginsOnObject(MetaRoot root, MetaData node, + java.util.List collected) { if (!(node instanceof MetaObject)) return; // only objects carry origins (via their fields) MetaObject obj = (MetaObject) node; for (MetaData child : obj.getChildren(MetaData.class, false)) { @@ -3327,11 +3328,12 @@ private static void walkOriginsOnObject(MetaRoot root, MetaData node) { MetaField field = (MetaField) child; for (MetaData originChild : field.getChildren(MetaData.class, false)) { if (originChild instanceof MetaOrigin) { - validateOriginNode(root, obj, field, (MetaOrigin) originChild); + // One finding per origin, so a broken origin does not hide the next one. + pass(collected, () -> validateOriginNode(root, obj, field, (MetaOrigin) originChild)); } } } else if (child instanceof MetaObject) { - walkOriginsOnObject(root, child); // nested object (composition) + walkOriginsOnObject(root, child, collected); // nested object (composition) } // identity/source/attr/etc. children are skipped — they don't carry origins } @@ -5208,7 +5210,8 @@ private static final class OriginTarget { private static String[] splitViaPath(String via) { References.Split s = References.splitChildTail(via); if (s.tail().isEmpty()) return new String[] { s.owner() }; - String[] hops = s.tail().substring(1).split("\\."); + // Limit -1 keeps a trailing empty hop, so "Entity.rel." is refused as in the other ports. + String[] hops = s.tail().substring(1).split("\\.", -1); String[] out = new String[hops.length + 1]; out[0] = s.owner(); System.arraycopy(hops, 0, out, 1, hops.length); diff --git a/server/rust/metaobjects/tests/conformance-expected-failures.json b/server/rust/metaobjects/tests/conformance-expected-failures.json index 027a365b2d..ab0870a23f 100644 --- a/server/rust/metaobjects/tests/conformance-expected-failures.json +++ b/server/rust/metaobjects/tests/conformance-expected-failures.json @@ -1,6 +1,6 @@ { "language": "rust", "notes": "The Rust port passes every fixture of the shared metamodel corpus, so the ledger is empty. The ledger may only shrink and is kept for the day a new fixture lands that Rust does not pass yet: list it here with the reason, and it leaves when the work that covers it lands. minPassing is the number of fixtures known to pass; the run fails when fewer do, and it may only rise.", - "minPassing": 588, + "minPassing": 589, "fixtures": [] }