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
23 changes: 23 additions & 0 deletions .changeset/33494-extension-door-priority-fold.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
'@objectstack/lint': minor
'@objectstack/metadata-protocol': minor
'@objectstack/spec': minor
---

fix(lint, metadata-protocol): the `object_extension` publish door folds the written entry among the other packages' extensions of its target by priority, so it judges the field definition `os build` judges

Clause-②: no (narrowing) — at the runtime `object_extension` publish door (Studio, `PUT /api/v1/meta/object_extension/TARGET`, the MCP and AI authoring doors) the expression rule now reads each field of the target as `os build` serves it when another package's published extension adds the same field: one write it accepted is now refused (a higher-priority package's definition of a field the written entry also adds closes a formula cycle through another field of the entry), and two it refused now publish (the written entry ties with another package on that field, or another package outranks it there). `os build` is unchanged. The new gate input (`storedObjectExtensions` on `runRuntimeAuthoringRules` and `evaluateRuntimeAuthoringGate`, the `StoredObjectExtension` type from `@objectstack/lint/runtime`) is optional. Measured first-party exposure: no two first-party packages extend the same object (`examples/app-showcase` one entry on `showcase_account`, `packages/plugins/plugin-auth` one on `sys_sso_provider`, HotCRM `origin/main` 2492ac6 one module, o2c, extending `crm_contract` and `crm_account`), so no first-party write changes verdict.
Metadata-protocol: narrowed
Skills-docs: none owed — this PR edits `content/docs/deployment/validating-metadata.mdx` (the object extension paragraph states the door's fold); the skills teach `defineObjectExtension({ extend, fields, priority })` and formula fields, and say nothing of how the door read a field two packages add.

<!-- adr-0087: not-required (already-registered object-extension-formula-cycle-refused) the unreleased entry this PR updates states the door's fold and covers each changed shape -->

**BREAKING** accept-set change of the runtime `object_extension` publish door (narrowing in one shape, widening in two).

**Before:** the door's target carried every other package's extension field as a plain field with no package and no priority, and the gate folded the written entry over it, so the door judged the written entry's own definition of every field it adds. A self-reading formula the written entry adds under a field another package adds at the same priority, or at a higher one, was refused although `os build` accepts it; and a higher-priority package's formula closing a cycle through another field of the written entry was not seen, although `os build` refuses it.

**Now:** the host states the target's other packages' published extensions (each with its package, priority and fields; a disabled package's left out), and the gate folds the written entry among them by priority through the build's own fold (`objectsAsServed`). The door judges the definition `os build` judges: the written entry's where its priority decides the field, another package's where that one outranks it, and none where two packages add it at the priority that decides it. This corrects the `@objectstack/lint` 33153 note's **Now** clause "(at the door, a name the target already serves included: the written definition is the one served)" and its **Unchanged** sentence "The publish door judges the written entry's own definition of every field it adds, whatever priority another package's extension adds the same field at, so it can refuse a tie, or an entry another package outranks, that `os build` lets through": the written definition is the one judged where the written entry's priority decides the field, and the door no longer refuses a tie or an outranked entry that `os build` accepts. Where that note says "at the same priority", read "at the priority that decides it".

**Unchanged:** `os build`, `os validate` and `os lint`; a write the door judges with no other package extending the same field; a host that states no extensions (the written entry is folded over the target as served); a draft save (never gated).

**Fix:** a write refused for the new shape: break the cycle, so the formula the entry adds does not read a field that another package's higher-priority formula computes from it, or rename the entry's field so it is not outranked.
12 changes: 7 additions & 5 deletions content/docs/deployment/validating-metadata.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -623,11 +623,13 @@ through another formula, is refused as one the object declares is (#33153):
the cycle is found on the target as served, each member the entry adds is
located at the entry (`object 'TARGET' · objectExtensions[0] · field 'FIELD'
expression`), and in `os build` a member the target declares keeps its
location at the object. The door judges the written entry's own definition of
every field it adds, so a name the target already serves is refused at the
entry too, whatever priority another package's extension adds it at; `os build`
judges the definition the registry serves, and on a declared object leaves out
a field two packages add at the same priority.
location at the object. The door folds the written entry among the other
packages' published extensions of the target by priority, as `os build` folds
every package's entry (#33494), so both judge the same definition of each
field: the written entry's where its priority decides the field (a name the
target already serves included), another package's where that one outranks it.
On a declared object neither judges a field two packages add at the priority
that decides it.

**Declared enforcement that cannot run** is two rows for the mirror-image
reason, and #4716 is where it split. That heading covers four rule ids, and
Expand Down
15 changes: 14 additions & 1 deletion packages/lint/src/authoring-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ import {

import type { IObjectQLEngine } from '@objectstack/spec/contracts';
import type { UserTextParams } from './finding-user-text.js';
import type { StoredObjectExtension } from './object-graph.js';

type AnyRec = Record<string, unknown>;

Expand Down Expand Up @@ -356,6 +357,15 @@ export interface AuthoringRuleContext {
* platform names, a platform-prefixed name advised at `warning`) applies.
*/
runtimeWriteType?: string;
/**
* [#33494] Set by the runtime gate on an `object_extension` write only: the
* written entry's target's other packages' published extensions, as the
* host's registry holds them. Read by one rule, `validateStackExpressions`,
* whose extension walk folds the written entry among them by priority (the
* build's own fold, `objectsAsServed`), so the door judges the definition
* the build judges (`StackExpressionOptions.storedObjectExtensions`).
*/
storedObjectExtensions?: readonly StoredObjectExtension[];
/**
* [#32666] Set by the runtime gate on its SUBJECT pass only, which judges
* the subject collections it withholds from every other pass
Expand Down Expand Up @@ -850,7 +860,10 @@ export const AUTHORING_RULES: readonly AuthoringRule[] = [
surfaces: CLI_AND_RUNTIME,
runtimeTypes: ['flow', 'action', 'hook', 'object', 'view', 'page', 'object_extension'],
run: (stack, ctx) =>
runStackExpressionPasses(stack, { runtimeWriteType: ctx.runtimeWriteType }).map((i) => ({
runStackExpressionPasses(stack, {
runtimeWriteType: ctx.runtimeWriteType,
...(ctx.storedObjectExtensions !== undefined ? { storedObjectExtensions: ctx.storedObjectExtensions } : {}),
}).map((i) => ({
severity: i.severity ?? 'error',
// [#32529, #32554] The stored-expression input member names its own
// two ids; every other finding of the pass is `expression-invalid`.
Expand Down
16 changes: 12 additions & 4 deletions packages/lint/src/formula-cycle-issues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,28 @@ export function formulaCycleIssues(
* elsewhere. The build passes the names the authored target declares (the
* object walk locates those at the object, so a cycle closing through a
* declared formula keeps that location); the `object_extension` door passes
* none, since it judges the written entry's own definition of every name the
* entry adds, over everything the target served before the write.
* none, since its target is served before the write and the object walk does
* not run there.
*
* [#33494] A `stored` entry (another package's published extension, which the
* door folds in among the written one by priority) locates nothing: a name it
* adds later in fold order than the written entry is the stored entry's
* definition, served over the written one, so no locus is left for it, and a
* cycle it closes through another field of the written entry is named on
* that field alone.
*/
export function extensionFormulaLoci(
target: string,
entries: ReadonlyArray<{ path: string; fields: readonly AnyRec[] }>,
entries: ReadonlyArray<{ path: string; fields: readonly AnyRec[]; stored?: true }>,
left: ReadonlySet<string>,
): Map<string, string> {
const loci = new Map<string, string>();
for (const entry of entries) {
for (const field of entry.fields) {
const name = field.name;
if (typeof name !== 'string' || left.has(name)) continue;
loci.set(name, `object '${target}' · ${entry.path} · field '${name}' expression`);
if (entry.stored) loci.delete(name);
else loci.set(name, `object '${target}' · ${entry.path} · field '${name}' expression`);
}
}
return loci;
Expand Down
52 changes: 48 additions & 4 deletions packages/lint/src/object-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,32 @@ export interface VisibleObjectExtension {
*/
label: unknown;
fieldPatches: Record<string, AnyRec>;
/**
* [#33494] Set on an entry the host's registry already holds
* ({@link StoredObjectExtension}), folded in at its priority but never
* located: its fields are no field of the stack, so no walk names one.
*/
stored?: true;
}

/**
* [#33494] Another package's published extension of an object, as the host's
* registry holds it (each `extend` contribution of the object: its package,
* its merge priority, its fields). The `object_extension` publish door states
* them for the written entry's target, so {@link objectExtensionsByTarget}
* folds the written entry among them by priority, as the build folds every
* package's entry, instead of over their fields carried as plain fields with
* no priority. Never stated by the build, whose stack carries every entry.
*/
export interface StoredObjectExtension {
/** The object it extends. */
extend: string;
/** Its merge priority; absent reads as the registry's default, 200. */
priority?: number;
/** Its field records (a record keyed by name, or an array). */
fields?: unknown;
/** The package it belongs to, for the record; the fold reads only the order. */
packageId?: string;
}

/**
Expand Down Expand Up @@ -428,17 +454,25 @@ export interface VisibleObjectExtension {
* earlier one whole, its fields included.
* - Fold order: ascending `priority` (default 200), equal priorities in
* package order. Each list is returned in that order.
* - [#33494] `stored`: the entries the host's registry already holds for
* another package (the `object_extension` door states them, the build never
* does), each its own package, registered before every entry of the stack
* and marked `stored`. They fold as any entry does, so the stack's entry
* that one outranks is not the one served and a tie between them is a tie.
*
* Which targets to judge is the caller's question: an entry is listed here
* whether or not the stack declares its target.
*/
export function objectExtensionsByTarget(stack: unknown): Map<string, VisibleObjectExtension[]> {
export function objectExtensionsByTarget(
stack: unknown,
stored: readonly StoredObjectExtension[] = [],
): Map<string, VisibleObjectExtension[]> {
const byTarget = new Map<string, VisibleObjectExtension[]>();
if (!isRec(stack)) return byTarget;
// The receivers are named as `validate-security-posture.test.ts`'s key-read
// meta-test tables them (`stack`, `entry`, `body`, `ext`, `obj`, `f`): that
// scan reads this fold as part of the rules that read through it.
const collect = (entries: unknown, carrier: number, at: string) => {
const collect = (entries: unknown, carrier: number, at: string, held = false) => {
if (!Array.isArray(entries)) return;
entries.forEach((ext: unknown, i: number) => {
if (!isRec(ext) || typeof ext.extend !== 'string') return;
Expand All @@ -455,10 +489,14 @@ export function objectExtensionsByTarget(stack: unknown): Map<string, VisibleObj
Object.entries(ext.fieldPatches).filter((pair): pair is [string, AnyRec] => isRec(pair[1])),
)
: {},
...(held ? { stored: true as const } : {}),
});
byTarget.set(ext.extend, kept);
});
};
// [#33494] Registered before the stack's own entries: carriers below 0, one
// per stored entry, in the order the host states them.
stored.forEach((entry, k) => collect([entry], k - stored.length, `stored[${k}].`, true));
if (Array.isArray(stack.packages)) {
stack.packages.forEach((entry: unknown, j: number) => {
const body = isRec(entry) ? entry.manifest : undefined;
Expand Down Expand Up @@ -492,17 +530,23 @@ export function objectExtensionsByTarget(stack: unknown): Map<string, VisibleObj
* verdict depends on which definition wins: registration order decides that,
* and a stack does not state it.
*
* [#33494] `stored` ({@link objectExtensionsByTarget}): the host's registered
* entries of other packages, folded in among the stack's own by priority.
*
* Contract, which `indexObjectFields` (validate-hook-body-writes.ts) joins on
* by position: `objects` is one to one and in order with
* `recordsOf(stack.objects)`. `objectsAsServed(stack).objects[i]` is the
* served form of `recordsOf(stack.objects)[i]`, on the early return (nothing
* extends anything: the declared array itself) as on the fold. No object is
* dropped, added or reordered.
*/
export function objectsAsServed(stack: unknown): { objects: AnyRec[]; tied: Map<string, Set<string>> } {
export function objectsAsServed(
stack: unknown,
stored: readonly StoredObjectExtension[] = [],
): { objects: AnyRec[]; tied: Map<string, Set<string>> } {
const objects = isRec(stack) ? recordsOf(stack.objects) : [];
const tied = new Map<string, Set<string>>();
const extensions = objectExtensionsByTarget(stack);
const extensions = objectExtensionsByTarget(stack, stored);
if (extensions.size === 0) return { objects, tied };

const served = objects.map((obj) => {
Expand Down
Loading
Loading