Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions GOVERNANCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ MetaObjects, in the way the [`library/`](library/) entries do (see
- **An attribute promoted from a pack into core keeps its name and meaning.** Promotion moves
which provider registers the attribute. It does not rename it or change what it does, so a
model that used the attribute under the pack loads and behaves the same once core owns it.
- **Recorded exception: the systems vocabulary in 1.4.0.**
[ADR-0070](spec/decisions/ADR-0070-systems-estates-and-apis.md) (call 12) moves the `systems`
pack's vocabulary into core and renames part of it (`resource.database` to `resource.rdb`,
`system.internal` and `.external` to `system.software`, and the rest listed there), without a
second independent consumer. The two rules above are waived for that vocabulary only: the
pack was never published, so no adopter's model loads under the old names, and an entity file
names its resource, so the resource must load in every port. Any other promotion follows the
two rules above.

A pack in this repository is one of two kinds
([ADR-0069](spec/decisions/ADR-0069-independent-packs.md)). A **bundled pack** (`db`, `rules`,
Expand Down
1 change: 1 addition & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions changelog.d/adr-0070-systems-and-reference-facet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
- **Spec: ADR-0070 records the 1.4.0 design for systems, estates and APIs, and the provider
definition format gains a reference facet.** ADR-0070 records the seventeen accepted calls
(one `system.software` kind with an owner, organizations, locations, `environment.stage`,
deployment and provision nodes with no platform, product or size, grants that stay inside
their system, the eventing and batch API vocabulary, and core versus pack placement), and
GOVERNANCE.md records the exception for promoting the systems vocabulary into core.
`spec/metamodel-definitions.md` specifies the `ref` facet a reference attribute carries
(`targetType`, `targetSubTypes`, `fieldPath`, `sameSystem`, `errorCode`, `wrongSystemCode`)
and the kind-typed `Parent.child` lookup, and `spec/metamodel-definition.schema.json` is the
format's JSON Schema, which every core definition file validates against unchanged.
Specification only: no port reads the facet yet, and `metamodelVersion` does not move.
1 change: 1 addition & 0 deletions server/typescript/packages/metadata/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"devDependencies": {
"@metaobjectsdev/conformance": "workspace:*",
"@stryker-mutator/core": "^9.6.1",
"ajv": "^8.20.0",
"bun-types": "latest",
"typescript": "^5.6.0"
}
Expand Down
176 changes: 176 additions & 0 deletions server/typescript/packages/metadata/test/definition-schema.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
// definition-schema — spec/metamodel-definition.schema.json describes the provider
// definition format, including the reference facet (`ref` on an attr child) that
// spec/metamodel-definitions.md specifies.
//
// Two guarantees:
// 1. Every definition file in spec/metamodel/ validates against the schema
// unchanged, so the schema is the format the files are written in and not a
// looser or stricter one.
// 2. The reference facet's shape rules hold: where `ref` may appear, which keys
// it takes, and the sameSystem/wrongSystemCode and fieldPath pairings.
//
// No reader reads `ref` yet; each port's spec reader learns it in its own change.

import { describe, test, expect } from "bun:test";
import { readFileSync, readdirSync, existsSync } from "node:fs";
import { join, dirname } from "node:path";
import Ajv2020 from "ajv/dist/2020";

function repoRoot(): string {
let dir = import.meta.dir;
for (let i = 0; i < 12; i++) {
if (existsSync(join(dir, "spec")) && existsSync(join(dir, "server"))) return dir;
dir = dirname(dir);
}
throw new Error("repo root not found");
}
const root = repoRoot();
const schema = JSON.parse(readFileSync(join(root, "spec", "metamodel-definition.schema.json"), "utf-8"));
const validate = new Ajv2020({ allErrors: true, strict: true }).compile(schema);

const specDir = join(root, "spec", "metamodel");
const definitionFiles = readdirSync(specDir).filter((f) => f.endsWith(".json")).sort();

function errorsOf(doc: unknown): string {
return validate(doc) ? "" : JSON.stringify(validate.errors, null, 2);
}

/** A one-type definition whose single attr child is `attr`. */
function withAttr(attr: Record<string, unknown>): unknown {
return {
provider: "test",
types: [
{
type: "grant",
subType: "rdb",
description: "test",
children: [{ type: "attr", subType: "string", name: "resource", min: 1, max: 1, ...attr }],
},
],
};
}

describe("definition schema — the existing definition files", () => {
test("spec/metamodel holds the 22 core definition files", () => {
expect(definitionFiles.length).toBe(22);
});

for (const file of definitionFiles) {
test(`${file} validates unchanged`, () => {
const doc = JSON.parse(readFileSync(join(specDir, file), "utf-8"));
expect(errorsOf(doc)).toBe("");
});
}

test("no existing definition file uses the reference facet yet", () => {
for (const file of definitionFiles) {
const doc = JSON.parse(readFileSync(join(specDir, file), "utf-8")) as {
types?: { children?: object[] }[];
extends?: { children?: object[] }[];
};
const children = [...(doc.types ?? []), ...(doc.extends ?? [])].flatMap((t) => t.children ?? []);
expect(children.filter((c) => "ref" in c)).toEqual([]);
}
});
});

describe("definition schema — the reference facet", () => {
test("a full facet on a string attr is accepted", () => {
const doc = withAttr({
ref: {
targetType: "resource",
targetSubTypes: ["rdb"],
sameSystem: true,
errorCode: "ERR_REF_UNRESOLVED",
wrongSystemCode: "ERR_GRANT_CROSSES_SYSTEM",
},
});
expect(errorsOf(doc)).toBe("");
});

test("the minimal facet is targetType alone", () => {
expect(errorsOf(withAttr({ ref: { targetType: "role" } }))).toBe("");
});

test("a list-valued string attr may carry the facet", () => {
expect(errorsOf(withAttr({ isArray: true, ref: { targetType: "location" } }))).toBe("");
});

test("a fieldPath facet (an existing descriptor's shape) is accepted", () => {
const doc = withAttr({ ref: { targetType: "object", fieldPath: true, errorCode: "ERR_INVALID_REFERENCE" } });
expect(errorsOf(doc)).toBe("");
});

test("targetType is required", () => {
expect(errorsOf(withAttr({ ref: { targetSubTypes: ["rdb"] } }))).not.toBe("");
});

test("targetType may not be the wildcard", () => {
expect(errorsOf(withAttr({ ref: { targetType: "*" } }))).not.toBe("");
});

test("targetSubTypes may not be empty, repeat, or hold the wildcard", () => {
expect(errorsOf(withAttr({ ref: { targetType: "resource", targetSubTypes: [] } }))).not.toBe("");
expect(errorsOf(withAttr({ ref: { targetType: "resource", targetSubTypes: ["rdb", "rdb"] } }))).not.toBe("");
expect(errorsOf(withAttr({ ref: { targetType: "resource", targetSubTypes: ["*"] } }))).not.toBe("");
});

test("an unknown facet key is refused", () => {
expect(errorsOf(withAttr({ ref: { targetType: "resource", targetSubType: "rdb" } }))).not.toBe("");
});

test("sameSystem requires wrongSystemCode", () => {
expect(errorsOf(withAttr({ ref: { targetType: "role", sameSystem: true } }))).not.toBe("");
});

test("wrongSystemCode without sameSystem is refused", () => {
expect(errorsOf(withAttr({ ref: { targetType: "role", wrongSystemCode: "ERR_X" } }))).not.toBe("");
expect(
errorsOf(withAttr({ ref: { targetType: "role", sameSystem: false, wrongSystemCode: "ERR_X" } })),
).not.toBe("");
});

test("fieldPath and sameSystem do not combine", () => {
const doc = withAttr({
ref: { targetType: "object", fieldPath: true, sameSystem: true, wrongSystemCode: "ERR_X" },
});
expect(errorsOf(doc)).not.toBe("");
});

test("error codes must look like loader codes", () => {
expect(errorsOf(withAttr({ ref: { targetType: "role", errorCode: "not a code" } }))).not.toBe("");
});

test("the facet is refused on a non-string attr", () => {
expect(errorsOf(withAttr({ subType: "boolean", ref: { targetType: "role" } }))).not.toBe("");
});

test("the facet is refused on a structural child", () => {
const doc = {
provider: "test",
types: [
{
type: "role",
subType: "service",
description: "test",
children: [{ type: "grant", subType: "*", name: "*", min: 0, max: null, ref: { targetType: "resource" } }],
},
],
};
expect(errorsOf(doc)).not.toBe("");
});

test("the facet is accepted in an extends entry", () => {
const doc = {
provider: "test",
extends: [
{
type: "source",
subType: "rdb",
children: [{ type: "attr", subType: "string", name: "resource", min: 0, max: 1, ref: { targetType: "resource", targetSubTypes: ["rdb"] } }],
},
],
};
expect(errorsOf(doc)).toBe("");
});
});
1 change: 1 addition & 0 deletions spec/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Each implementation passes the same conformance fixtures under [`fixtures/confor
|---|---|
| [`metamodel.md`](metamodel.md) | The 11-type vocabulary, structural keys, subtypes, fused-key node encoding. The normative type system. |
| [`wire-format.md`](wire-format.md) | JSON shape, body-key order, package resolution, overlay merging, attribute value rules. The normative serialization contract. |
| [`metamodel-definitions.md`](metamodel-definitions.md) | The provider definition file format every port reads (`metamodel/*.json`), the reference facet and how a reference is looked up. Its JSON Schema is [`metamodel-definition.schema.json`](metamodel-definition.schema.json). |
| [`conformance-tests.md`](conformance-tests.md) | How to run cross-language conformance fixtures. The contract every implementation passes. |
| [`roadmap.md`](roadmap.md) | Release direction, the FR → issue → spec index, and roadmap history. Status and target releases live in GitHub issues labelled `FR`. |
| [`design-docs/`](design-docs/) | Project design documents -- historical context and current in-flight design decisions. |
Expand Down
Loading
Loading