From 5dae65b14bde6532caa297a4bba6f8acb93674e6 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 13 Nov 2026 14:16:10 +0000 Subject: [PATCH 1/9] test(lint): pin the object_extension door's field-formula judgment (reproduction) Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01L9qibwwiSN1TXWjohzCZN9 --- ...runtime-gate.object-formula-writes.test.ts | 116 ++++++++++++++++++ 1 file changed, 116 insertions(+) diff --git a/packages/lint/src/runtime-gate.object-formula-writes.test.ts b/packages/lint/src/runtime-gate.object-formula-writes.test.ts index 0f83a19c07b..540f9e85090 100644 --- a/packages/lint/src/runtime-gate.object-formula-writes.test.ts +++ b/packages/lint/src/runtime-gate.object-formula-writes.test.ts @@ -336,3 +336,119 @@ describe('#32529 / #32554 — the object door judges a stored expression\'s inpu expect(atDoor).toEqual(atBuild); }); }); + +describe('#33072 — the object_extension door judges an extension field\'s formula as the build does', () => { + /** The extended object, as the door's live universe carries it. */ + const target = { + name: 'fx_ticket', + label: 'Ticket', + sharingModel: 'private', + fields: { + employee: { type: 'lookup', label: 'Employee', reference: 'fx_staff' }, + amount: { type: 'number', label: 'Amount' }, + }, + }; + const staff = { + name: 'fx_staff', label: 'Staff', sharingModel: 'private', + fields: { daily_hours: { type: 'number', label: 'Daily Hours' } }, + }; + /** One extension of `fx_ticket` adding the given fields. */ + const extension = (fields: Record) => ({ extend: 'fx_ticket', fields }); + const scoreOf = (expression: string) => extension({ score: { type: 'formula', label: 'Score', expression } }); + const EXT_WHERE = (field: string) => `object 'fx_ticket' · objectExtensions[0] · field '${field}' expression`; + const gateExtension = (item: unknown, objects: unknown[] = [target, staff]) => + runRuntimeAuthoringRules({ type: 'object_extension', item, context: { objects } }); + const ofRule = (rule: string, fs: readonly T[]): T[] => fs.filter((f) => f.rule === rule); + + it('`validateStackExpressions` is on the object_extension door, beside the vocabulary freeze', () => { + expect(runtimeAuthoringRulesFor('object_extension').map((r) => r.name)) + .toEqual(['validateStackExpressions', 'validateSecurityRoleWord']); + }); + + it('⭐ LIT — an extension formula calling an unregistered function (`sqrt`) is REFUSED, at the entry the build names', () => { + const result = gateExtension(scoreOf('sqrt(record.amount)')); + + expect(result.rulesRun).toContain('validateStackExpressions'); + const errs = expressionFindings(result.errors); + expect(errs, dump(result)).toHaveLength(1); + expect(errs[0]).toMatchObject({ severity: 'error', where: EXT_WHERE('score'), path: EXT_WHERE('score') }); + }); + + it('⭐ LIT — an extension formula reading a field the extended object does not serve is REFUSED', () => { + const result = gateExtension(scoreOf('record.amont * 2')); + + const errs = expressionFindings(result.errors); + expect(errs, dump(result)).toHaveLength(1); + expect(errs[0]!.where).toBe(EXT_WHERE('score')); + expect(errs[0]!.message).toContain('amont'); + }); + + it('⭐ LIT — a stored extension field reading another record is an ADVISORY, never a 422', () => { + const result = gateExtension(extension({ + hours: { type: 'number', label: 'Hours', expression: 'record.amount * record.employee.daily_hours' }, + })); + + const advised = ofRule(STORED_EXPRESSION_CROSS_RECORD_INPUT, result.advisories); + expect(advised, dump(result)).toHaveLength(1); + expect(advised[0]).toMatchObject({ severity: 'warning', where: EXT_WHERE('hours') }); + expect(result.errors, dump(result)).toEqual([]); + }); + + it('⭐ PARITY — on one shared input, the door finding IS the build finding', () => { + for (const item of [ + scoreOf('sqrt(record.amount)'), + extension({ hours: { type: 'number', label: 'Hours', expression: 'record.amount * record.employee.daily_hours' } }), + ]) { + const atDoor = gateExtension(item); + const stack = { objects: [target, staff], objectExtensions: [item] }; + const atBuild = runAuthoringRules('build', { normalized: stack, parsed: stack }) + .filter((f) => f.where.includes('objectExtensions')); + + expect(atBuild.length, dump(atBuild)).toBe(1); + expect([...atDoor.errors, ...atDoor.advisories]).toEqual(atBuild); + } + }); + + it('⭐ CONTROL — a valid extension formula, and one reading a field the same extension adds, publish clean', () => { + for (const item of [ + scoreOf('floor(record.amount)'), + extension({ + bonus: { type: 'number', label: 'Bonus' }, + total: { type: 'formula', label: 'Total', expression: 'record.amount + record.bonus' }, + }), + ]) { + const result = gateExtension(item); + expect(result.errors, dump(result)).toEqual([]); + expect(result.advisories, dump(result)).toEqual([]); + expect(result.rulesRun).toEqual(['validateStackExpressions', 'validateSecurityRoleWord']); + } + }); + + it('an extension of an object the door does not carry is judged on what does not depend on its fields', () => { + expect(expressionFindings(gateExtension(scoreOf('sqrt(record.amount)'), []).errors)).toHaveLength(1); + const read = gateExtension(scoreOf('record.amount * 2'), []); + expect(read.errors, dump(read)).toEqual([]); + }); + + it('a stored object\'s own broken formula is not the extension write\'s to answer for (the differential)', () => { + const broken = { ...target, fields: { ...target.fields, bad: { type: 'formula', label: 'Bad', expression: 'sqrt(record.amount)' } } }; + const result = gateExtension(scoreOf('floor(record.amount)'), [broken, staff]); + + expect(result.errors, dump(result)).toEqual([]); + }); + + it('on an extension write only the extension walk judges: no pass over the objects the door carries', () => { + const broken = { ...target, fields: { ...target.fields, bad: { type: 'formula', label: 'Bad', expression: 'sqrt(record.amount)' } } }; + const stack = { objects: [broken, staff], objectExtensions: [scoreOf('floor(record.amount)')] }; + // The build judges the declared formula… + expect(validateStackExpressions(stack).map((i) => i.where)).toEqual(["object 'fx_ticket' · field 'bad' expression"]); + // …the extension door's pass reads only the written entry. + expect(runStackExpressionPasses(stack, { runtimeWriteType: 'object_extension' })).toEqual([]); + }); + + it('CONTROL — the object save door is unchanged: it judges the object\'s own formula and no extension field', () => { + const result = gateObject(fxSqrt('sqrt(record.amount)')); + expect(expressionFindings(result.errors).map((f) => f.where)).toEqual([WHERE]); + expect(runtimeAuthoringRulesFor('object').map((r) => r.name)).toContain('validateStackExpressions'); + }); +}); From c2d22bac8d27d5762a6176cae9ba811cfd6d9801 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 13 Nov 2026 14:19:47 +0000 Subject: [PATCH 2/9] fix(lint): the object_extension publish door judges an extension field's formula as the build does Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01L9qibwwiSN1TXWjohzCZN9 --- packages/lint/src/authoring-rules.ts | 15 ++++++- packages/lint/src/validate-expressions.ts | 31 +++++++++++++- ...e-security-posture.runtime-surface.test.ts | 6 +-- .../meta-object-extension-item.test.ts | 42 +++++++++++++++++++ 4 files changed, 88 insertions(+), 6 deletions(-) diff --git a/packages/lint/src/authoring-rules.ts b/packages/lint/src/authoring-rules.ts index c3e485679c4..b9b7af4a497 100644 --- a/packages/lint/src/authoring-rules.ts +++ b/packages/lint/src/authoring-rules.ts @@ -821,8 +821,21 @@ export const AUTHORING_RULES: readonly AuthoringRule[] = [ // shipped corpus at `6021b5e837`: 0 findings across examples/**, // platform-objects and plugin-approvals, against one for a planted unbound // hole; #25709 re-measured 0 sentences of the holeless `${…}` shape there. + // + // [#33072] `object_extension` joins, for ONE pass: the field-formula pass + // over each field the written extension adds — the extension walk #32875 + // gave `os build` / `os validate`, which refuses a computed field there + // that this door published with a 200 (Studio's add-field on a `.custom` + // pair and the `/meta` doors write the item). On an extension write + // `runStackExpressionPasses` runs that walk alone, by construction, over + // the written entry (the sole member of `objectExtensions`) against the + // door's live objects as served, so a refusal carries the build's rule id + // and location (`object 'TARGET' · objectExtensions[0] · field 'F' + // expression`). MEASURED first: 0 first-party `objectExtensions` entries + // carry a computed field (examples/**, packages/**, HotCRM), so the + // crossing refuses nothing the repository ships. surfaces: CLI_AND_RUNTIME, - runtimeTypes: ['flow', 'action', 'hook', 'object', 'view', 'page'], + runtimeTypes: ['flow', 'action', 'hook', 'object', 'view', 'page', 'object_extension'], run: (stack, ctx) => runStackExpressionPasses(stack, { runtimeWriteType: ctx.runtimeWriteType }).map((i) => ({ severity: i.severity ?? 'error', diff --git a/packages/lint/src/validate-expressions.ts b/packages/lint/src/validate-expressions.ts index e93ed39d308..7a89c84985d 100644 --- a/packages/lint/src/validate-expressions.ts +++ b/packages/lint/src/validate-expressions.ts @@ -2261,6 +2261,15 @@ export interface StackExpressionOptions { * write. None of them is the object's own body, the object write's snapshot * does not carry them, and each is judged at its own type's door; the claim * holds by construction rather than by the snapshot's shape. + * + * [#33072] On an `object_extension` write exactly ONE pass judges: the + * field-formula pass over each field the written entry adds (#32875's + * extension walk, `judgeFieldFormula`), against the extended object as + * served — the door's live objects with the entry folded in by + * `objectsAsServed`, the build's own fold — and located at the entry, as the + * build locates it. The object walk reads an empty list (the carried + * objects are the universe the field resolves in, not the subject) and so + * does every other pass; the function returns after the extension walk. */ runtimeWriteType?: string; } @@ -2299,6 +2308,13 @@ export function runStackExpressionPasses(stack: AnyRec, options: StackExpression // an empty list under it, so the claim holds by construction rather than by // the shape of the snapshot the gate happens to build today. const objectWrite = options.runtimeWriteType === 'object'; + // [#33072] On an `object_extension` write exactly ONE pass judges: the + // extension-field walk below (#32875), over the written entry, against the + // extended object as served. Every other loop reads an empty list under it + // (the object walk and the flows included), and the function returns right + // after that walk, so the claim holds by construction. See + // {@link StackExpressionOptions.runtimeWriteType}. + const extensionWrite = options.runtimeWriteType === 'object_extension'; // [#24798] On a `view` write exactly ONE pass judges — the bulk `confirmText` // pass over the written view's own list containers ({@link bulkConfirmTextIssues}); // every other pass reads a collection a view write does not carry, so it @@ -2803,7 +2819,7 @@ export function runStackExpressionPasses(stack: AnyRec, options: StackExpression const runtimeGateWrite = options.runtimeWriteType !== undefined; const flowEntrances: ReadonlyMap = objectWrite || runtimeGateWrite ? new Map() : flowCelEntrances(stack, fieldIndex); - for (const flow of objectWrite ? [] : recordsOf(stack.flows)) { + for (const flow of objectWrite || extensionWrite ? [] : recordsOf(stack.flows)) { const flowName = typeof flow.name === 'string' ? flow.name : '(unnamed flow)'; // [#26858] The flow's index in the authored list, for a finding's key path // (`recordsOf` hands an array's own members back). A map-form `flows` has @@ -3503,7 +3519,9 @@ export function runStackExpressionPasses(stack: AnyRec, options: StackExpression // [#32529] The object's position in `objects`, which is its position in // `typedObjects` too (the served body the stored-expression member reads). let objectPosition = -1; - for (const obj of objects) { + // [#33072] Fenced on an extension write: the objects the door carries are + // the universe the extension field is judged against, not its subject. + for (const obj of extensionWrite ? [] : objects) { objectPosition += 1; const objectName = typeof obj.name === 'string' ? obj.name : undefined; // [#27643] The object's index in the authored list, for a validation-rule @@ -3974,6 +3992,12 @@ export function runStackExpressionPasses(stack: AnyRec, options: StackExpression // // Fenced on an object write: an extension is not the written object's // body, and an object write's snapshot carries none. + // + // [#33072] The `object_extension` publish door runs this walk and nothing + // else: its snapshot carries the written entry as the sole member of + // `objectExtensions` and the door's live objects as `objects`, so the field + // is judged against its target as served and located where the build + // locates it (`objectExtensions[0]` for a one-entry stack). for (const [target, entries] of objectWrite ? [] : objectExtensionsByTarget(stack)) { // The target's position in `objects`, which is its position in // `typedObjects` too (see `objectPosition` above); -1 when undeclared. @@ -4015,6 +4039,9 @@ export function runStackExpressionPasses(stack: AnyRec, options: StackExpression } } + // [#33072] An extension write's one pass ends here. + if (extensionWrite) return issues; + // ── Action `visible` / `disabled` / `pressed` predicates ──────────── // Record-scoped, same as validation rules: a record-header / row action's // `visible` is evaluated by ActionEngine against `{ record, recordId, diff --git a/packages/lint/src/validate-security-posture.runtime-surface.test.ts b/packages/lint/src/validate-security-posture.runtime-surface.test.ts index 7b562565440..48d0dfbe6cd 100644 --- a/packages/lint/src/validate-security-posture.runtime-surface.test.ts +++ b/packages/lint/src/validate-security-posture.runtime-surface.test.ts @@ -566,7 +566,7 @@ describe('validateSecurityPosture at the runtime publish surface (#7576 → #830 const entry = DEFAULT_METADATA_TYPE_REGISTRY.find((e) => e.type === 'object_extension'); expect(entry?.allowRuntimeCreate, "'object_extension' is runtime-creatable").toBe(true); expect(stackKeyForType('object_extension')).toBe('objectExtensions'); - expect(runtimeAuthoringRulesFor('object_extension').map((r) => r.name)).toEqual(['validateSecurityRoleWord']); + expect(runtimeAuthoringRulesFor('object_extension').map((r) => r.name)).toEqual(['validateStackExpressions', 'validateSecurityRoleWord']); const roleSelect = { type: 'select', label: 'Group Function', options: [{ value: 'l1', label: 'Tier 1' }] }; const refused = runRuntimeAuthoringRules({ @@ -581,7 +581,7 @@ describe('validateSecurityPosture at the runtime publish surface (#7576 → #830 // positional and names it. expect(refused.errors[0].path).toBe('objectExtensions[0].fields.role.name'); expect(refused.errors[0].where).toBe('field "sd_agent.role"'); - expect(refused.rulesRun).toEqual(['validateSecurityRoleWord']); + expect(refused.rulesRun).toEqual(['validateStackExpressions', 'validateSecurityRoleWord']); // The two labels the entry serves, at the same door. const labelled = runRuntimeAuthoringRules({ @@ -601,7 +601,7 @@ describe('validateSecurityPosture at the runtime publish surface (#7576 → #830 }); expect(clean.errors).toEqual([]); expect(clean.advisories).toEqual([]); - expect(clean.rulesRun).toEqual(['validateSecurityRoleWord']); + expect(clean.rulesRun).toEqual(['validateStackExpressions', 'validateSecurityRoleWord']); // Not a context row: the baseline carries no `objectExtensions`, and the // candidate holds exactly the written item. diff --git a/packages/runtime/src/domains/meta-object-extension-item.test.ts b/packages/runtime/src/domains/meta-object-extension-item.test.ts index 77b6e553d51..741165802c7 100644 --- a/packages/runtime/src/domains/meta-object-extension-item.test.ts +++ b/packages/runtime/src/domains/meta-object-extension-item.test.ts @@ -353,6 +353,48 @@ describe('[#28574] refused at the door, leaving no row', () => { }, 60_000); }); +describe('[#33072] the publish door judges an extension field\'s formula as `os build` does', () => { + /** Studio's add-field body for a computed field on the account. */ + const scoreBody = (expression: string) => ({ + extend: TARGET, + fields: { score__c: { type: 'formula', label: 'Score', expression } }, + }); + const WHERE = "object 'crm_account' · objectExtensions[0] · field 'score__c' expression"; + + it('⭐ LIT — a formula calling an unregistered function is refused with the build\'s rule id and location; the field is not served', async () => { + const rig = await boot(); + await rig.protocol.saveMetaItem({ type: TYPE, name: TARGET, item: scoreBody('sqrt(record.name)'), mode: 'draft', packageId: PAIR }); + const err: any = await rig.protocol.publishMetaItem({ type: TYPE, name: TARGET, packageId: PAIR }).catch((e: any) => e); + + expect(err, 'the publish was admitted').toBeInstanceOf(Error); + expect({ code: err.code, status: err.status }).toEqual({ code: 'INVALID_METADATA', status: 422 }); + const issue = (err.issues ?? []).find((i: any) => i.rule === 'expression-invalid'); + expect(issue, JSON.stringify(err.issues)).toBeDefined(); + expect({ where: issue.where, path: issue.path }).toEqual({ where: WHERE, path: WHERE }); + expect((await rig.fieldsOn()).registry).not.toContain('score__c'); + expect(await rig.rows()).toEqual([{ name: TARGET, package_id: PAIR, state: 'draft' }]); + }, 60_000); + + it('⭐ LIT — a formula reading a field the account does not serve is refused, judged against the extended object', async () => { + const rig = await boot(); + await rig.protocol.saveMetaItem({ type: TYPE, name: TARGET, item: scoreBody("record.nmae + '!'"), mode: 'draft', packageId: PAIR }); + const err: any = await rig.protocol.publishMetaItem({ type: TYPE, name: TARGET, packageId: PAIR }).catch((e: any) => e); + + expect({ code: err?.code, status: err?.status }).toEqual({ code: 'INVALID_METADATA', status: 422 }); + const issue = (err.issues ?? []).find((i: any) => i.rule === 'expression-invalid'); + expect(issue?.where, JSON.stringify(err.issues)).toBe(WHERE); + expect(issue.message).toContain('nmae'); + }, 60_000); + + it('⭐ CONTROL — a valid formula over the account\'s own field publishes and is served', async () => { + const rig = await boot(); + await rig.saveAndPublish(PAIR, scoreBody("record.name + '!'")); + + expect((await rig.fieldsOn()).registry).toContain('score__c'); + expect(await rig.rows()).toEqual([{ name: TARGET, package_id: PAIR, state: 'active' }]); + }, 60_000); +}); + describe('[ADR-0146 D10] a module\'s extension that re-declares the base\'s field beyond its display properties', () => { /** A writable module package that depends on the base: the account is inside its closure. */ const MODULE = 'com.acme.module'; From c237a74ac3edebc928bc9dd0e172a47de092293b Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 13 Nov 2026 14:28:07 +0000 Subject: [PATCH 3/9] fix(lint): changeset and semantic entry for the object_extension door's formula judgment Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01L9qibwwiSN1TXWjohzCZN9 --- .../33072-object-extension-door-formula.md | 22 +++++++++++ packages/lint/src/runtime-gate.ts | 5 +++ ...n-door-computed-field-expression-judged.ts | 37 +++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 .changeset/33072-object-extension-door-formula.md create mode 100644 packages/spec/src/migrations/entries/semantic/18.object-extension-door-computed-field-expression-judged.ts diff --git a/.changeset/33072-object-extension-door-formula.md b/.changeset/33072-object-extension-door-formula.md new file mode 100644 index 00000000000..dd5d74fe158 --- /dev/null +++ b/.changeset/33072-object-extension-door-formula.md @@ -0,0 +1,22 @@ +--- +'@objectstack/lint': minor +'@objectstack/spec': minor +--- + +fix(lint): the runtime `object_extension` publish door judges a computed field an extension adds by the build's field-formula pass, against the extended object as served + +Clause-②: no (narrowing) — the `object_extension` publish door (Studio's add-field on a `.custom` pair, `PUT /api/v1/meta/object_extension/TARGET`, the MCP and AI authoring doors) now refuses an extension whose computed field carries an `expression` `os build` refuses. No exported type or signature changes. Measured first-party: 0 extension entries with a computed field (`examples/app-showcase` one entry, three plain fields; `packages/plugins/plugin-auth` one, a `secret` field; HotCRM none), so nothing first-party is newly refused. +Metadata-protocol: narrowed +Skills-docs: none — `skills/objectstack-data` teaches `defineObjectExtension({ extend, fields })` and the computed-field rules without saying the runtime door is exempt; the door now gives the verdict the build already gives. + + + +**BREAKING** accept-set narrowing of the runtime `object_extension` publish door (`validateStackExpressions` joins its `runtimeTypes`). + +`os build` and `os validate` judge each field an `objectExtensions` entry adds with the field-formula pass, but the publish door that writes an extension at runtime ran only the vocabulary freeze, so a computed field the build refuses published with a 200 and then read null, or failed, on every row. + +- On an `object_extension` write the expression rule runs exactly one pass: the extension walk over each field the written entry adds, against the door's live objects with the entry folded in (the build's own fold), located where the build locates it: `object 'crm_account' · objectExtensions[0] · field 'score__c' expression`. A refusal is the gate's `422 INVALID_METADATA` with issue rule `expression-invalid`; a stored field that reads another record, the clock or the acting user is an advisory (`stored-expression-cross-record-input`, `stored-expression-volatile-input`), never a refusal. +- An extension of an object the door does not carry is judged on what does not depend on that object's fields (grammar, registered functions, bare and unbound references). +- Unchanged: the object save door, `os build`, `os validate`, a draft save (never gated), and a stored row, which is judged only when it is published again. + +Migration: before publishing an extension again, fix each refused `expression` the way you would on a declared field of the same object: read `record.FIELD` for a field the object serves, call only registered functions, and make a stored field that reads another record, the clock or the acting user a `formula` field. diff --git a/packages/lint/src/runtime-gate.ts b/packages/lint/src/runtime-gate.ts index 88b4ace5b10..effba98294f 100644 --- a/packages/lint/src/runtime-gate.ts +++ b/packages/lint/src/runtime-gate.ts @@ -289,6 +289,11 @@ const TYPE_TO_STACK_KEY: Readonly> = { // written word on its own, and a write's own collection holds exactly one // member — its own item (an extension carries `extend` and no `name`, so it is // never name-keyed). + // + // [#33072] `validateStackExpressions` crosses with this row too, for one + // pass: the extension walk over the written entry's fields. It resolves + // `record.FIELD` into `objects`, which every snapshot already carries, so the + // row still needs no context collection of its own. object_extension: 'objectExtensions', }; diff --git a/packages/spec/src/migrations/entries/semantic/18.object-extension-door-computed-field-expression-judged.ts b/packages/spec/src/migrations/entries/semantic/18.object-extension-door-computed-field-expression-judged.ts new file mode 100644 index 00000000000..f5e68191a05 --- /dev/null +++ b/packages/spec/src/migrations/entries/semantic/18.object-extension-door-computed-field-expression-judged.ts @@ -0,0 +1,37 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +import type { SemanticMigration } from '../../types.js'; + +// #33072: an accept-set narrowing of the runtime `object_extension` publish +// door. `os build` and `os validate` judge the computed fields an +// `objectExtensions` entry adds (`object-extension-computed-field-expression-judged`); +// the door that publishes an extension at runtime (Studio's add-field on a +// `.custom` pair, `PUT /api/v1/meta/object_extension/TARGET`, an MCP or AI +// author) ran no field-formula judgment, so it published a field the build +// refuses. It now asks the same pass. No D2 conversion: how a refused +// expression is repaired is a fact only the author holds, and a stored row is +// not re-judged until it is published again. +export const entry: SemanticMigration = { + id: 'object-extension-door-computed-field-expression-judged', + surface: + 'an `object_extension` item published at runtime (Studio\'s add-field on a `.custom` pair, ' + + '`PUT /api/v1/meta/object_extension/TARGET`, the MCP and AI authoring doors) whose `fields` carry an ' + + '`expression`, a `formula` field or a stored computed field, e.g. ' + + '`{ extend: \'crm_account\', fields: { score__c: { type: \'formula\', expression: \'sqrt(record.amount)\' } } }`.', + replacement: + 'An `expression` `os build` accepts on the same extension field: CEL that reads `record.FIELD` for a field ' + + 'the extended object serves (its own fields and every field an extension adds), calls only registered ' + + 'functions, and reads at most one hop through a reference field. A stored field that reads another record, ' + + 'the clock or the acting user is advised, never refused, as on a declared field.', + reason: + 'The publish door ran only the vocabulary freeze on an extension, so a computed field `os build` refuses ' + + 'published with a 200 and then read null, or failed, on every row. The door now runs the build\'s ' + + 'field-formula pass on each field the written extension adds, against the extended object as the door ' + + 'serves it, and refuses with the build\'s rule id and location ' + + '(`422 INVALID_METADATA`, issue `expression-invalid` at `object \'TARGET\' · objectExtensions[0] · field ' + + '\'FIELD\' expression`).', + acceptanceCriteria: + 'Publish each extension that adds a computed field again (or run `os validate` on the package that ships ' + + 'it): the publish answers 200 with no `expression-invalid` issue located at an `objectExtensions[0] · field` ' + + 'site, and a record of the extended object holds a value in every computed field the extension adds.', +}; From e86250fbc7b3c8faae634a0a1bfc7b4faff9babd Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 13 Nov 2026 16:39:39 +0000 Subject: [PATCH 4/9] fix(metadata-protocol): judge an object_extension republish without the package's stored extension The runtime authoring gate gathered the extension's target as served before the write, so the package's stored extension (which the write replaces) still lent its fields to the judgment. Dropping a field the extension's own formula reads was admitted, and re-targeting the extension's own lookup was judged over the old target. The gate now takes the target from the registry fold that leaves the written package's `extend` contributions out (`withoutExtensionsOf`, applied to the target by name only), and passes the same narrowing through the stored-row fold for a target with its own stored object row. Every other caller of both folds reaches the call it made before. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01L9qibwwiSN1TXWjohzCZN9 --- ...uthoring-gate.extension-write-fold.test.ts | 52 ++++++++++++ .../src/protocol-authoring-gate.ts | 74 ++++++++++++++++- .../src/protocol-object-extender-fold.ts | 10 +++ .../src/protocol-stored-collection-fold.ts | 28 +++++-- packages/metadata-protocol/src/protocol.ts | 9 ++- .../meta-object-extension-item.test.ts | 79 +++++++++++++++++-- 6 files changed, 235 insertions(+), 17 deletions(-) create mode 100644 packages/metadata-protocol/src/protocol-authoring-gate.extension-write-fold.test.ts diff --git a/packages/metadata-protocol/src/protocol-authoring-gate.extension-write-fold.test.ts b/packages/metadata-protocol/src/protocol-authoring-gate.extension-write-fold.test.ts new file mode 100644 index 00000000000..1d750c53c10 --- /dev/null +++ b/packages/metadata-protocol/src/protocol-authoring-gate.extension-write-fold.test.ts @@ -0,0 +1,52 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * [#33072 r1] The runtime authoring gate's view of an `object_extension` + * write's target: without the written package's own stored extension, which + * the write replaces. These pin the two helpers' contracts; the real-door + * pins (republish in both directions, and a target with a stored object row) + * are in `packages/runtime/src/domains/meta-object-extension-item.test.ts`. + */ + +import { describe, expect, it } from 'vitest'; +import { objectExtensionWriteFold, withTargetFoldedWithout } from './protocol-authoring-gate.js'; + +describe('[#33072] objectExtensionWriteFold — which writes narrow the target, and to what', () => { + it('an object_extension write in a package narrows its `extend` target without that package', () => { + expect(objectExtensionWriteFold('object_extension', 'crm_account', { extend: 'crm_account' }, 'com.acme.crm.custom')) + .toEqual({ options: { withoutExtensionsOf: 'com.acme.crm.custom' }, target: 'crm_account' }); + }); + + it('a body with no `extend` falls back to the item name', () => { + expect(objectExtensionWriteFold('object_extension', 'crm_account', { fields: {} }, 'p')?.target).toBe('crm_account'); + }); + + it('every other type, and a write naming no package, changes nothing', () => { + expect(objectExtensionWriteFold('object', 'crm_account', { extend: 'crm_account' }, 'p')).toBeUndefined(); + expect(objectExtensionWriteFold('object_extension', 'crm_account', { extend: 'crm_account' }, undefined)).toBeUndefined(); + expect(objectExtensionWriteFold('object_extension', 'crm_account', { extend: 'crm_account' }, '')).toBeUndefined(); + }); +}); + +describe('[#33072] withTargetFoldedWithout — only the target entry is replaced', () => { + const served = [ + { name: 'crm_account', fields: { name: {}, bonus__c: {} } }, + { name: 'crm_region', fields: { code: {}, other__c: {} } }, + ]; + const without = [ + { name: 'crm_account', fields: { name: {} } }, + { name: 'crm_region', fields: { code: {} } }, + ]; + + it('the target comes from the narrowed list; every other object keeps its served fold', () => { + const out = withTargetFoldedWithout(served, without, 'crm_account'); + expect(out[0]).toBe(without[0]); + // The package's extension of ANOTHER object is still served: the + // narrowing is package-wide in the registry, so it is applied by name. + expect(out[1]).toBe(served[1]); + }); + + it('a target the narrowed list lacks leaves the served list as it was', () => { + expect(withTargetFoldedWithout(served, [], 'crm_account')).toEqual(served); + }); +}); diff --git a/packages/metadata-protocol/src/protocol-authoring-gate.ts b/packages/metadata-protocol/src/protocol-authoring-gate.ts index 8e19d254703..ebb06ce97ae 100644 --- a/packages/metadata-protocol/src/protocol-authoring-gate.ts +++ b/packages/metadata-protocol/src/protocol-authoring-gate.ts @@ -206,6 +206,50 @@ export async function runAuthoringGate( }); } +/** + * [#33072] What an `object_extension` write's object universe leaves out: the + * WRITTEN package's own extensions of the extended target (`options`, the + * registry's existing `withoutExtensionsOf` fold option), on that target only + * (`target`, the body's `extend`, else the row's name, which the item gate + * holds equal to it). A package holds one extension per target, so the written + * entry replaces the stored one; the gate folds the written entry in itself + * (`objectsAsServed` in `@objectstack/lint`), so the candidate is the target as + * it will be served after the write. The package's extensions of OTHER objects + * are not being written and stay served. `undefined` (the ordinary fold) for + * every other write type, and for a write naming no package or no target. + */ +export function objectExtensionWriteFold( + singularType: string, + name: string, + body: unknown, + packageId: string | null | undefined, +): { options: { withoutExtensionsOf: string }; target: string } | undefined { + if (singularType !== 'object_extension') return undefined; + if (typeof packageId !== 'string' || packageId === '') return undefined; + const extend = body !== null && typeof body === 'object' ? (body as { extend?: unknown }).extend : undefined; + const target = typeof extend === 'string' && extend !== '' ? extend : name; + if (typeof target !== 'string' || target === '') return undefined; + return { options: { withoutExtensionsOf: packageId }, target }; +} + +/** + * [#33072] `served` with the entry named `target` taken from `withoutWritten` + * (the same registry list, folded without the written package's extensions): + * two answers of the registry's own fold, composed by name, no fold of its + * own. Positions are kept, so every other entry is the served one, unchanged. + * A target absent from `withoutWritten` keeps its served entry. + */ +export function withTargetFoldedWithout( + served: readonly unknown[], + withoutWritten: readonly unknown[], + target: string, +): unknown[] { + const nameOf = (o: unknown): unknown => (o !== null && typeof o === 'object' ? (o as { name?: unknown }).name : undefined); + const replacement = withoutWritten.find((o) => nameOf(o) === target); + if (replacement === undefined) return [...served]; + return served.map((o) => (nameOf(o) === target ? replacement : o)); +} + /** * The members {@link judgeRuntimeAuthoringRules} reads: the host facts and * collections every judgement of the shared rules is made against. @@ -375,11 +419,31 @@ export async function judgeRuntimeAuthoringRules( // prevent). It is still bounded by the number of TENANT-AUTHORED rows // of one type — code-package metadata lives in the registry and never // reaches this read — and it never runs on a draft. + // + // [#33072] On an `object_extension` write the extended TARGET is listed + // without the written package's own extensions (the registry's + // `withoutExtensionsOf` fold option, which the disable door reads too): + // the written entry REPLACES that package's stored extension of its + // target, so the stored one must not stay folded beneath it. Left in, a + // republish was judged against the target as served BEFORE the write: a + // field the write drops still resolved, and a reference the write + // re-targets still resolved to its old target. Every other object, and + // every other package's extensions of the target, stay as served. + const extensionWrite = objectExtensionWriteFold(singular, evt.name, evt.body, evt.packageId); const listRegisteredCollection = (singularType: string, pluralType: string): unknown[] => { try { if (typeof this.engine.registry?.listItems !== 'function') return []; - const items = [...this.engine.registry.listItems(singularType)]; - return items.length > 0 ? items : [...this.engine.registry.listItems(pluralType)]; + const list = (type: string): unknown[] => { + const items = [...this.engine.registry.listItems(type)]; + if (extensionWrite === undefined || (type !== 'object' && type !== 'objects')) return items; + return withTargetFoldedWithout( + items, + [...this.engine.registry.listItems(type, undefined, extensionWrite.options)], + extensionWrite.target, + ); + }; + const items = list(singularType); + return items.length > 0 ? items : list(pluralType); } catch { return []; } @@ -394,6 +458,12 @@ export async function judgeRuntimeAuthoringRules( listRegisteredCollection(singularType, pluralType), singularType, pluralType, + // [#33072] The stored half of the same narrowing: a target that + // has its own stored `object` row is folded without the written + // package's extension too. Objects only; undefined otherwise. + extensionWrite !== undefined && singularType === 'object' + ? { target: extensionWrite.target, withoutExtensionsOf: extensionWrite.options.withoutExtensionsOf } + : undefined, ); // Resolved together rather than in sequence: each is one indexed // `sys_metadata` read and they do not depend on one another, so the diff --git a/packages/metadata-protocol/src/protocol-object-extender-fold.ts b/packages/metadata-protocol/src/protocol-object-extender-fold.ts index ef514f65373..f774e55b8e8 100644 --- a/packages/metadata-protocol/src/protocol-object-extender-fold.ts +++ b/packages/metadata-protocol/src/protocol-object-extender-fold.ts @@ -47,6 +47,7 @@ export function foldObjectExtendersFromRegistry( name: unknown, body: unknown, onlyExtensionsOf?: string, + withoutExtensionsOf?: string, ): unknown { const singular = PLURAL_TO_SINGULAR[type] ?? type; if (singular !== 'object') return body; @@ -63,6 +64,15 @@ export function foldObjectExtendersFromRegistry( // [#29903, #29872] `onlyExtensionsOf`: every other package's `extend` // contributions are left out of the fold (the per-package layer names // the listed package). + // + // [#33072] `withoutExtensionsOf`: that one package's `extend` + // contributions are left out — the runtime authoring gate's view of an + // `object_extension` write's target as it stands WITHOUT the written + // package's stored self, which the write replaces. Undefined for every + // other caller, which reaches the same call as before. + if (withoutExtensionsOf !== undefined) { + return registry.foldObjectExtendersOnto(name, body, { withoutExtensionsOf }); + } return onlyExtensionsOf === undefined ? registry.foldObjectExtendersOnto(name, body) : registry.foldObjectExtendersOnto(name, body, { onlyExtensionsOf }); diff --git a/packages/metadata-protocol/src/protocol-stored-collection-fold.ts b/packages/metadata-protocol/src/protocol-stored-collection-fold.ts index 01e384a2ca2..7eaaa63899f 100644 --- a/packages/metadata-protocol/src/protocol-stored-collection-fold.ts +++ b/packages/metadata-protocol/src/protocol-stored-collection-fold.ts @@ -48,12 +48,24 @@ export interface StoredCollectionFoldHost { readonly foldObjectExtendersFromRegistry: ObjectStackProtocolImplementation['foldObjectExtendersFromRegistry']; } +/** + * [#33072] One stored row's fold narrowed for the runtime authoring gate's + * `object_extension` write: the row named `target` is folded without + * `withoutExtensionsOf`'s `extend` contributions (the written package's + * stored self, which the write replaces). Nothing else moves. + */ +export interface StoredCollectionTargetFold { + readonly target: string; + readonly withoutExtensionsOf: string; +} + /** The body of `ObjectStackProtocolImplementation#foldStoredCollection`; the method's docblock there is its contract. */ export async function foldStoredCollection( this: Pick, registered: unknown[], singularType: string, pluralType: string, + targetFold?: StoredCollectionTargetFold, ): Promise { if (typeof this.engine?.find !== 'function') return registered; let rows: Record[]; @@ -134,11 +146,17 @@ export async function foldStoredCollection( // the point: the gate's universe is now the same universe the platform // answers `GET /meta/:type` from, by construction rather than by // agreement. - const merged = mergePackageAwareOverlay(singularType, registered, overlays, (data) => - this.foldObjectExtendersFromRegistry( - singularType, (data as { name?: unknown } | null)?.name, data, - ), - ); + // + // [#33072] `targetFold`, when given, changes the fold of ONE row: the one + // named `targetFold.target` is folded without `withoutExtensionsOf`'s + // contributions. Every other row, and every call without it, reaches + // exactly the call above. + const merged = mergePackageAwareOverlay(singularType, registered, overlays, (data) => { + const name = (data as { name?: unknown } | null)?.name; + return targetFold !== undefined && name === targetFold.target + ? this.foldObjectExtendersFromRegistry(singularType, name, data, undefined, targetFold.withoutExtensionsOf) + : this.foldObjectExtendersFromRegistry(singularType, name, data); + }); // A registry entry with no `name` is not addressable by any reference, // so the merge above has no slot for it and drops it. It is carried diff --git a/packages/metadata-protocol/src/protocol.ts b/packages/metadata-protocol/src/protocol.ts index f690e344cce..b28c170db37 100644 --- a/packages/metadata-protocol/src/protocol.ts +++ b/packages/metadata-protocol/src/protocol.ts @@ -380,7 +380,7 @@ import { reportPageRequiresAbsentAtLoad, resolveSduiManifest } from './protocol- // [#25467 cut 35] The environment's own `sys_metadata` rows: the family read, the one-row read, the served row and the package-less address. import { findEnvironmentRow, findEnvironmentRows, findServedOverlayRow, packagelessAddress, packagelessContentPackage } from './protocol-environment-rows.js'; // [#25467 cut 35] The stored rows of a collection, folded over the registered ones. -import { foldStoredCollection } from './protocol-stored-collection-fold.js'; +import { foldStoredCollection, type StoredCollectionTargetFold } from './protocol-stored-collection-fold.js'; // [#25467 cut 35] The environment-wide package uninstall verb. import { deletePackage, recordPackageUninstall, runUninstallGuards } from './protocol-package-uninstall.js'; // ADR-0146 D3 — the ensure door of a base's paired `.custom` package, and the @@ -2028,6 +2028,7 @@ export class ObjectStackProtocolImplementation implements registered: unknown[], singularType: string, pluralType: string, + targetFold?: StoredCollectionTargetFold, ): Promise { // [#25467 cut 35] The body moved to `protocol-stored-collection-fold.ts` (see `StoredCollectionFoldHost`). const readEngine = () => this.engine; @@ -2037,7 +2038,7 @@ export class ObjectStackProtocolImplementation implements findEnvironmentRows: (...a) => this.findEnvironmentRows(...a), foldObjectExtendersFromRegistry: (...a) => this.foldObjectExtendersFromRegistry(...a), }; - return foldStoredCollection.call(host, registered, singularType, pluralType); + return foldStoredCollection.call(host, registered, singularType, pluralType, targetFold); } /** @@ -2779,13 +2780,13 @@ export class ObjectStackProtocolImplementation implements * (see {@link SchemaRegistry.foldObjectExtendersOnto}), so applying it twice * would duplicate both. */ - private foldObjectExtendersFromRegistry(type: string, name: unknown, body: unknown, onlyExtensionsOf?: string): unknown { + private foldObjectExtendersFromRegistry(type: string, name: unknown, body: unknown, onlyExtensionsOf?: string, withoutExtensionsOf?: string): unknown { // [#25467 cut 30] The body moved to `protocol-object-extender-fold.ts` (see `ObjectExtenderFoldHost`). const readEngine = () => this.engine; const host: ThisParameterType = { get engine() { return readEngine(); }, }; - return foldObjectExtendersFromRegistry.call(host, type, name, body, onlyExtensionsOf); + return foldObjectExtendersFromRegistry.call(host, type, name, body, onlyExtensionsOf, withoutExtensionsOf); } /** diff --git a/packages/runtime/src/domains/meta-object-extension-item.test.ts b/packages/runtime/src/domains/meta-object-extension-item.test.ts index 741165802c7..33dc0b8af36 100644 --- a/packages/runtime/src/domains/meta-object-extension-item.test.ts +++ b/packages/runtime/src/domains/meta-object-extension-item.test.ts @@ -62,7 +62,7 @@ const OTHER = 'com.acme.other'; const TARGET = 'crm_account'; const TYPE = 'object_extension'; -const baseManifest = () => ({ +const baseManifest = (extraObjects: readonly Record[] = []) => ({ id: BASE, name: 'crm', version: '3.4.1', @@ -72,7 +72,7 @@ const baseManifest = () => ({ name: TARGET, label: 'Account', fields: { name: { name: 'name', label: 'Name', type: 'text' } }, - }], + }, ...extraObjects], }); /** Studio's add-field body: an extension in the pair, its field suffixed. */ @@ -89,7 +89,7 @@ afterEach(async () => { } }); -async function freshEngine(): Promise { +async function freshEngine(extraObjects: readonly Record[] = []): Promise { const engine = new ObjectQL(); liveEngines.push(engine); engine.registerDriver(new SqlDriver({ @@ -102,13 +102,13 @@ async function freshEngine(): Promise { engine.registry.registerObject(SysMetadataHistoryObject as any, TEST_PACKAGE_ID); engine.registry.registerObject(SysMetadataAuditObject as any, TEST_PACKAGE_ID); (engine.registry as unknown as { logLevel: string }).logLevel = 'silent'; - engine.registerApp(baseManifest()); + engine.registerApp(baseManifest(extraObjects)); await engine.syncSchemas(); return engine; } -async function boot() { - const engine = await freshEngine(); +async function boot(extraObjects: readonly Record[] = []) { + const engine = await freshEngine(extraObjects); const protocol = new ObjectStackProtocolImplementation(engine as any, () => new Map()); const p = protocol as any; await p.installPackage({ @@ -393,6 +393,73 @@ describe('[#33072] the publish door judges an extension field\'s formula as `os expect((await rig.fieldsOn()).registry).toContain('score__c'); expect(await rig.rows()).toEqual([{ name: TARGET, package_id: PAIR, state: 'active' }]); }, 60_000); + + // [#33072 r1] A REPUBLISH replaces the package's stored extension, so the + // target is judged without it: the written body is the package's whole + // extension, exactly as `os build` sees its one `objectExtensions` entry. + // Judging against the target as served BEFORE the write read the stored + // self as well, which erred both ways — the two pins below. + const totalBody = (fields: Record = {}, extend = TARGET) => ({ + extend, + fields: { ...fields, total__c: { type: 'formula', label: 'Total', expression: 'record.bonus__c + 1' } }, + }); + const BONUS = { bonus__c: { type: 'number', label: 'Bonus' } }; + + it('⭐ LIT (republish, lenient direction) — dropping a field the extension\'s own formula still reads is refused', async () => { + const rig = await boot(); + await rig.saveAndPublish(PAIR, totalBody(BONUS)); + expect((await rig.fieldsOn()).registry).toEqual(expect.arrayContaining(['bonus__c', 'total__c'])); + + await rig.protocol.saveMetaItem({ type: TYPE, name: TARGET, item: totalBody(), mode: 'draft', packageId: PAIR }); + const err: any = await rig.protocol.publishMetaItem({ type: TYPE, name: TARGET, packageId: PAIR }).catch((e: any) => e); + + expect({ code: err?.code, status: err?.status }, 'the stored self still lent bonus__c').toEqual({ code: 'INVALID_METADATA', status: 422 }); + const issue = (err.issues ?? []).find((i: any) => i.rule === 'expression-invalid'); + expect(issue?.where, JSON.stringify(err.issues)) + .toBe("object 'crm_account' · objectExtensions[0] · field 'total__c' expression"); + expect(issue.message).toContain('bonus__c'); + // The served extension is the one published before, untouched. + expect((await rig.fieldsOn()).registry).toContain('bonus__c'); + }, 60_000); + + it('⭐ LIT (republish, strict direction) — re-targeting the extension\'s own lookup is judged over its new target', async () => { + const region = { name: 'crm_region', label: 'Region', fields: { code: { name: 'code', label: 'Code', type: 'text' } } }; + const rig = await boot([region]); + await rig.saveAndPublish(PAIR, { + extend: TARGET, + fields: { ref__c: { type: 'lookup', label: 'Ref', reference: 'crm_region' } }, + }); + + const out = await rig.saveAndPublish(PAIR, { + extend: TARGET, + fields: { + ref__c: { type: 'lookup', label: 'Ref', reference: TARGET }, + via__c: { type: 'formula', label: 'Via', expression: 'record.ref__c.name' }, + }, + }).catch((e: any) => e); + + expect(out, JSON.stringify((out as any)?.issues ?? out?.message)).not.toBeInstanceOf(Error); + expect((await rig.fieldsOn()).registry).toContain('via__c'); + }, 60_000); + + it('⭐ LIT (republish, target with a stored object row) — the stored fold leaves the written package\'s extension out too', async () => { + const rig = await boot(); + const LEAD = 'crm_custom_lead'; + await rig.protocol.saveMetaItem({ + type: 'object', name: LEAD, mode: 'draft', packageId: PAIR, + item: { name: LEAD, label: 'Lead', sharingModel: 'private', fields: { title: { name: 'title', label: 'Title', type: 'text' } } }, + }); + await rig.protocol.publishMetaItem({ type: 'object', name: LEAD, packageId: PAIR }); + await rig.saveAndPublish(PAIR, totalBody(BONUS, LEAD), LEAD); + + await rig.protocol.saveMetaItem({ type: TYPE, name: LEAD, item: totalBody({}, LEAD), mode: 'draft', packageId: PAIR }); + const err: any = await rig.protocol.publishMetaItem({ type: TYPE, name: LEAD, packageId: PAIR }).catch((e: any) => e); + + expect({ code: err?.code, status: err?.status }, 'the stored row\'s fold still lent bonus__c').toEqual({ code: 'INVALID_METADATA', status: 422 }); + const issue = (err.issues ?? []).find((i: any) => i.rule === 'expression-invalid'); + expect(issue?.where, JSON.stringify(err.issues)) + .toBe(`object '${LEAD}' · objectExtensions[0] · field 'total__c' expression`); + }, 60_000); }); describe('[ADR-0146 D10] a module\'s extension that re-declares the base\'s field beyond its display properties', () => { From 74ef8eafafc13f81d655a61dd4cc20b804ead367 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 13 Nov 2026 16:41:45 +0000 Subject: [PATCH 5/9] docs(lint): the object_extension door's formula pass in validating-metadata, and its location parity stated exactly The CEL row's runtime column gains the object_extension marker and the door paragraph names the formula pass. The changeset and semantic entry say that location parity with the build is index-exact for a package with one extension entry, state the republish semantics, and drop the weaker `os validate` acceptance alternative. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01L9qibwwiSN1TXWjohzCZN9 --- .changeset/33072-object-extension-door-formula.md | 5 +++-- content/docs/deployment/validating-metadata.mdx | 7 +++++-- ...tension-door-computed-field-expression-judged.ts | 13 +++++++------ 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/.changeset/33072-object-extension-door-formula.md b/.changeset/33072-object-extension-door-formula.md index dd5d74fe158..2790996037a 100644 --- a/.changeset/33072-object-extension-door-formula.md +++ b/.changeset/33072-object-extension-door-formula.md @@ -7,7 +7,7 @@ fix(lint): the runtime `object_extension` publish door judges a computed field a Clause-②: no (narrowing) — the `object_extension` publish door (Studio's add-field on a `.custom` pair, `PUT /api/v1/meta/object_extension/TARGET`, the MCP and AI authoring doors) now refuses an extension whose computed field carries an `expression` `os build` refuses. No exported type or signature changes. Measured first-party: 0 extension entries with a computed field (`examples/app-showcase` one entry, three plain fields; `packages/plugins/plugin-auth` one, a `secret` field; HotCRM none), so nothing first-party is newly refused. Metadata-protocol: narrowed -Skills-docs: none — `skills/objectstack-data` teaches `defineObjectExtension({ extend, fields })` and the computed-field rules without saying the runtime door is exempt; the door now gives the verdict the build already gives. +Skills-docs: none owed — this PR edits `content/docs/deployment/validating-metadata.mdx` (the CEL row's runtime column gains `ᵒˣ`, and the object extension door paragraph names the formula pass); `skills/objectstack-data` teaches `defineObjectExtension({ extend, fields })` and the computed-field rules without saying the runtime door is exempt, so the door now gives the verdict the build already gives. @@ -15,7 +15,8 @@ Skills-docs: none — `skills/objectstack-data` teaches `defineObjectExtension({ `os build` and `os validate` judge each field an `objectExtensions` entry adds with the field-formula pass, but the publish door that writes an extension at runtime ran only the vocabulary freeze, so a computed field the build refuses published with a 200 and then read null, or failed, on every row. -- On an `object_extension` write the expression rule runs exactly one pass: the extension walk over each field the written entry adds, against the door's live objects with the entry folded in (the build's own fold), located where the build locates it: `object 'crm_account' · objectExtensions[0] · field 'score__c' expression`. A refusal is the gate's `422 INVALID_METADATA` with issue rule `expression-invalid`; a stored field that reads another record, the clock or the acting user is an advisory (`stored-expression-cross-record-input`, `stored-expression-volatile-input`), never a refusal. +- On an `object_extension` write the expression rule runs exactly one pass: the extension walk over each field the written entry adds, against the door's live objects with the entry folded in (the build's own fold), located as the build locates it for a package with one extension entry: `object 'crm_account' · objectExtensions[0] · field 'score__c' expression` (the door judges the written entry alone, so its index is always `[0]`; a build of a package with several entries names the entry's own index). A refusal is the gate's `422 INVALID_METADATA` with issue rule `expression-invalid`; a stored field that reads another record, the clock or the acting user is an advisory (`stored-expression-cross-record-input`, `stored-expression-volatile-input`), never a refusal. +- A republish is judged against the target without the package's own stored extension, which the write replaces, as the build sees the package's one entry: dropping a field the extension's own formula still reads is refused, and a formula over a lookup the same write re-targets is judged over the new target. - An extension of an object the door does not carry is judged on what does not depend on that object's fields (grammar, registered functions, bare and unbound references). - Unchanged: the object save door, `os build`, `os validate`, a draft save (never gated), and a stored row, which is judged only when it is published again. diff --git a/content/docs/deployment/validating-metadata.mdx b/content/docs/deployment/validating-metadata.mdx index 9b6440358bf..241b54313dc 100644 --- a/content/docs/deployment/validating-metadata.mdx +++ b/content/docs/deployment/validating-metadata.mdx @@ -494,7 +494,7 @@ orthogonal to both, and no cell here can carry it; it is written out in | | `os validate` | `os build` | `os lint` | runtime publish | |---|---|---|---|---| | Protocol schema (Zod) | ✓ | ✓ | — | ✓ | -| CEL / predicate validation (ADR-0032) | ✓ | ✓ | ✓ | ✓ᶠᵃᶜʰᵒᵛᵖ | +| CEL / predicate validation (ADR-0032) | ✓ | ✓ | ✓ | ✓ᶠᵃᶜʰᵒˣᵒᵛᵖ | | List-view navigation modes (ADR-0053) | ✓ | ✓ | ✓ | — | | Zod-valid but functionally inert declarations — a `summary` with no operations (ADR-0078), a managed object advertising an API method its affordances refuse (#7521) | ✓ | ✓ | ✓ | ✓ᵒ | | Retired object title template — an object that declares `titleFormat`, retired by ADR-0079 for `nameField` (`title-format-retired`, #29007) | ✓ | ✓ | ✓ | ✓ᵒ | @@ -606,7 +606,10 @@ located at the entry (`objectExtensions[0].fields.FIELD.name`). The `object_extension` publish door (Studio's add-field on a customization package, `/api/v1/meta`) runs the same rule. A field an extension adds to a `sys_*` object is judged too: the system-object exemption covers the platform's own -declarations, not words an app adds. +declarations, not words an app adds. The same door runs the build's +field-formula pass on each computed field the written entry adds (#33072), +against the target as served without the package's own stored extension, which +the write replaces, and refuses with the build's rule id (`expression-invalid`). **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 diff --git a/packages/spec/src/migrations/entries/semantic/18.object-extension-door-computed-field-expression-judged.ts b/packages/spec/src/migrations/entries/semantic/18.object-extension-door-computed-field-expression-judged.ts index f5e68191a05..daab6f7f8d6 100644 --- a/packages/spec/src/migrations/entries/semantic/18.object-extension-door-computed-field-expression-judged.ts +++ b/packages/spec/src/migrations/entries/semantic/18.object-extension-door-computed-field-expression-judged.ts @@ -27,11 +27,12 @@ export const entry: SemanticMigration = { 'The publish door ran only the vocabulary freeze on an extension, so a computed field `os build` refuses ' + 'published with a 200 and then read null, or failed, on every row. The door now runs the build\'s ' + 'field-formula pass on each field the written extension adds, against the extended object as the door ' - + 'serves it, and refuses with the build\'s rule id and location ' - + '(`422 INVALID_METADATA`, issue `expression-invalid` at `object \'TARGET\' · objectExtensions[0] · field ' - + '\'FIELD\' expression`).', + + 'serves it without the package\'s own stored extension (which the write replaces), and refuses with ' + + 'the build\'s rule id (`422 INVALID_METADATA`, issue `expression-invalid` at `object \'TARGET\' · ' + + 'objectExtensions[0] · field \'FIELD\' expression`; the door judges the written entry alone, so the index ' + + 'matches the build\'s exactly for a package with one extension entry).', acceptanceCriteria: - 'Publish each extension that adds a computed field again (or run `os validate` on the package that ships ' - + 'it): the publish answers 200 with no `expression-invalid` issue located at an `objectExtensions[0] · field` ' - + 'site, and a record of the extended object holds a value in every computed field the extension adds.', + 'Publish each extension that adds a computed field again: the publish answers 200 with no ' + + '`expression-invalid` issue located at an `objectExtensions[0] · field` site, and a record of the extended ' + + 'object holds a value in every computed field the extension adds.', }; From 765f003f7450b25619c72b46c9ff8653ea652345 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 13 Nov 2026 18:00:31 +0000 Subject: [PATCH 6/9] fix(metadata-protocol): key the extension-write narrowing on the singular type The registry list narrowed the target by comparing the listed type with both spellings, which brought back an executable `'objects'` literal the #8862 census forbids. The narrowing is now decided once from the collection's singular type, so the plural retry narrows the same way. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01L9qibwwiSN1TXWjohzCZN9 --- packages/metadata-protocol/src/protocol-authoring-gate.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/metadata-protocol/src/protocol-authoring-gate.ts b/packages/metadata-protocol/src/protocol-authoring-gate.ts index ebb06ce97ae..3085610f668 100644 --- a/packages/metadata-protocol/src/protocol-authoring-gate.ts +++ b/packages/metadata-protocol/src/protocol-authoring-gate.ts @@ -433,13 +433,15 @@ export async function judgeRuntimeAuthoringRules( const listRegisteredCollection = (singularType: string, pluralType: string): unknown[] => { try { if (typeof this.engine.registry?.listItems !== 'function') return []; + // Keyed on the singular, so the plural retry below narrows too. + const narrow = extensionWrite !== undefined && singularType === 'object' ? extensionWrite : undefined; const list = (type: string): unknown[] => { const items = [...this.engine.registry.listItems(type)]; - if (extensionWrite === undefined || (type !== 'object' && type !== 'objects')) return items; + if (narrow === undefined) return items; return withTargetFoldedWithout( items, - [...this.engine.registry.listItems(type, undefined, extensionWrite.options)], - extensionWrite.target, + [...this.engine.registry.listItems(type, undefined, narrow.options)], + narrow.target, ); }; const items = list(singularType); From 5af0d88ed46ef2c7c2b9c69b63fe652ecc12d11d Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 13 Nov 2026 18:48:28 +0000 Subject: [PATCH 7/9] test(metadata-protocol): pay the lint load at collection in the extension-write fold pins Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01L9qibwwiSN1TXWjohzCZN9 --- .../src/protocol-authoring-gate.extension-write-fold.test.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/metadata-protocol/src/protocol-authoring-gate.extension-write-fold.test.ts b/packages/metadata-protocol/src/protocol-authoring-gate.extension-write-fold.test.ts index 1d750c53c10..b6608f39841 100644 --- a/packages/metadata-protocol/src/protocol-authoring-gate.extension-write-fold.test.ts +++ b/packages/metadata-protocol/src/protocol-authoring-gate.extension-write-fold.test.ts @@ -9,6 +9,10 @@ */ import { describe, expect, it } from 'vitest'; +// The module under test reaches `@objectstack/lint` through `protocol.ts`; its +// first load is paid at collection, never inside a case's clock +// (`scripts/check-test-source-alias.mjs`). +import '@objectstack/lint'; import { objectExtensionWriteFold, withTargetFoldedWithout } from './protocol-authoring-gate.js'; describe('[#33072] objectExtensionWriteFold — which writes narrow the target, and to what', () => { From f57cc2739f882bff944335a116fc250b33e94295 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 13 Nov 2026 21:12:11 +0000 Subject: [PATCH 8/9] docs(metadata-protocol): state the batch-publish limit and the folds' optional package arguments The changeset, the semantic entry and the docblocks now say that a package-wide draft publish whose drafts depend on a sibling extension draft is refused (#33152), and that publishing the extension first through the per-item door works. The changeset names the metadata-protocol package, which carries the host half. The two folds' docblocks describe their optional arguments, and the extender fold hands both package options to the registry when both are given rather than dropping one; no caller passes both today. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01L9qibwwiSN1TXWjohzCZN9 --- .../33072-object-extension-door-formula.md | 2 ++ packages/lint/src/authoring-rules.ts | 6 ++++- packages/lint/src/validate-expressions.ts | 4 ++++ ...uthoring-gate.extension-write-fold.test.ts | 23 ++++++++++++++++++ .../src/protocol-authoring-gate.ts | 5 ++++ .../src/protocol-object-extender-fold.ts | 18 ++++++++------ packages/metadata-protocol/src/protocol.ts | 24 +++++++++++++++++++ ...n-door-computed-field-expression-judged.ts | 5 +++- 8 files changed, 78 insertions(+), 9 deletions(-) diff --git a/.changeset/33072-object-extension-door-formula.md b/.changeset/33072-object-extension-door-formula.md index 2790996037a..5065fcc5dbc 100644 --- a/.changeset/33072-object-extension-door-formula.md +++ b/.changeset/33072-object-extension-door-formula.md @@ -1,6 +1,7 @@ --- '@objectstack/lint': minor '@objectstack/spec': minor +'@objectstack/metadata-protocol': patch --- fix(lint): the runtime `object_extension` publish door judges a computed field an extension adds by the build's field-formula pass, against the extended object as served @@ -18,6 +19,7 @@ Skills-docs: none owed — this PR edits `content/docs/deployment/validating-met - On an `object_extension` write the expression rule runs exactly one pass: the extension walk over each field the written entry adds, against the door's live objects with the entry folded in (the build's own fold), located as the build locates it for a package with one extension entry: `object 'crm_account' · objectExtensions[0] · field 'score__c' expression` (the door judges the written entry alone, so its index is always `[0]`; a build of a package with several entries names the entry's own index). A refusal is the gate's `422 INVALID_METADATA` with issue rule `expression-invalid`; a stored field that reads another record, the clock or the acting user is an advisory (`stored-expression-cross-record-input`, `stored-expression-volatile-input`), never a refusal. - A republish is judged against the target without the package's own stored extension, which the write replaces, as the build sees the package's one entry: dropping a field the extension's own formula still reads is refused, and a formula over a lookup the same write re-targets is judged over the new target. - An extension of an object the door does not carry is judged on what does not depend on that object's fields (grammar, registered functions, bare and unbound references). +- A package-wide draft publish (`publishPackageDrafts`) whose drafts depend on a sibling extension draft is refused, because that batch's pending set carries no extension drafts (#33152); publishing the extension first through the per-item door works. - Unchanged: the object save door, `os build`, `os validate`, a draft save (never gated), and a stored row, which is judged only when it is published again. Migration: before publishing an extension again, fix each refused `expression` the way you would on a declared field of the same object: read `record.FIELD` for a field the object serves, call only registered functions, and make a stored field that reads another record, the clock or the acting user a `formula` field. diff --git a/packages/lint/src/authoring-rules.ts b/packages/lint/src/authoring-rules.ts index 08aa2b4fa46..3227849b70d 100644 --- a/packages/lint/src/authoring-rules.ts +++ b/packages/lint/src/authoring-rules.ts @@ -833,7 +833,11 @@ export const AUTHORING_RULES: readonly AuthoringRule[] = [ // and location (`object 'TARGET' · objectExtensions[0] · field 'F' // expression`). MEASURED first: 0 first-party `objectExtensions` entries // carry a computed field (examples/**, packages/**, HotCRM), so the - // crossing refuses nothing the repository ships. + // crossing refuses nothing the repository ships. A package-wide draft + // publish (`publishPackageDrafts`) whose drafts depend on a sibling + // extension draft is refused, because that batch's pending set carries no + // extension drafts (#33152); publishing the extension first through the + // per-item door works. surfaces: CLI_AND_RUNTIME, runtimeTypes: ['flow', 'action', 'hook', 'object', 'view', 'page', 'object_extension'], run: (stack, ctx) => diff --git a/packages/lint/src/validate-expressions.ts b/packages/lint/src/validate-expressions.ts index 52b2b936bd2..96ecbbbbfe0 100644 --- a/packages/lint/src/validate-expressions.ts +++ b/packages/lint/src/validate-expressions.ts @@ -2271,6 +2271,10 @@ export interface StackExpressionOptions { * build locates it. The object walk reads an empty list (the carried * objects are the universe the field resolves in, not the subject) and so * does every other pass; the function returns after the extension walk. + * A package-wide draft publish (`publishPackageDrafts`) whose drafts depend + * on a sibling extension draft is refused, because that batch's pending set + * carries no extension drafts (#33152); publishing the extension first + * through the per-item door works. */ runtimeWriteType?: string; } diff --git a/packages/metadata-protocol/src/protocol-authoring-gate.extension-write-fold.test.ts b/packages/metadata-protocol/src/protocol-authoring-gate.extension-write-fold.test.ts index b6608f39841..3f128e5da36 100644 --- a/packages/metadata-protocol/src/protocol-authoring-gate.extension-write-fold.test.ts +++ b/packages/metadata-protocol/src/protocol-authoring-gate.extension-write-fold.test.ts @@ -14,6 +14,7 @@ import { describe, expect, it } from 'vitest'; // (`scripts/check-test-source-alias.mjs`). import '@objectstack/lint'; import { objectExtensionWriteFold, withTargetFoldedWithout } from './protocol-authoring-gate.js'; +import { foldObjectExtendersFromRegistry } from './protocol-object-extender-fold.js'; describe('[#33072] objectExtensionWriteFold — which writes narrow the target, and to what', () => { it('an object_extension write in a package narrows its `extend` target without that package', () => { @@ -54,3 +55,25 @@ describe('[#33072] withTargetFoldedWithout — only the target entry is replaced expect(withTargetFoldedWithout(served, [], 'crm_account')).toEqual(served); }); }); + +describe('[#33072] foldObjectExtendersFromRegistry — what each package argument hands the registry', () => { + const calls: unknown[][] = []; + const host = { + engine: { registry: { foldObjectExtendersOnto: (...a: unknown[]) => { calls.push(a.slice(2)); return a[1]; } } }, + } as never; + const fold = (only?: string, without?: string) => { + calls.length = 0; + foldObjectExtendersFromRegistry.call(host, 'object', 'crm_account', { name: 'crm_account' }, only, without); + return calls[0]; + }; + + it('neither argument is the ordinary call, and `onlyExtensionsOf` alone is the call it always was', () => { + expect(fold()).toEqual([]); + expect(fold('p1')).toEqual([{ onlyExtensionsOf: 'p1' }]); + }); + + it('`withoutExtensionsOf` alone, and both together, are each handed over', () => { + expect(fold(undefined, 'p2')).toEqual([{ withoutExtensionsOf: 'p2' }]); + expect(fold('p1', 'p2')).toEqual([{ onlyExtensionsOf: 'p1', withoutExtensionsOf: 'p2' }]); + }); +}); diff --git a/packages/metadata-protocol/src/protocol-authoring-gate.ts b/packages/metadata-protocol/src/protocol-authoring-gate.ts index 3085610f668..aabfb76cca0 100644 --- a/packages/metadata-protocol/src/protocol-authoring-gate.ts +++ b/packages/metadata-protocol/src/protocol-authoring-gate.ts @@ -217,6 +217,11 @@ export async function runAuthoringGate( * it will be served after the write. The package's extensions of OTHER objects * are not being written and stay served. `undefined` (the ordinary fold) for * every other write type, and for a write naming no package or no target. + * + * A package-wide draft publish (`publishPackageDrafts`) whose drafts depend on + * a sibling extension draft is refused, because that batch's pending set + * carries no extension drafts (#33152); publishing the extension first through + * the per-item door works. */ export function objectExtensionWriteFold( singularType: string, diff --git a/packages/metadata-protocol/src/protocol-object-extender-fold.ts b/packages/metadata-protocol/src/protocol-object-extender-fold.ts index f774e55b8e8..09e1e47a4e0 100644 --- a/packages/metadata-protocol/src/protocol-object-extender-fold.ts +++ b/packages/metadata-protocol/src/protocol-object-extender-fold.ts @@ -68,14 +68,18 @@ export function foldObjectExtendersFromRegistry( // [#33072] `withoutExtensionsOf`: that one package's `extend` // contributions are left out — the runtime authoring gate's view of an // `object_extension` write's target as it stands WITHOUT the written - // package's stored self, which the write replaces. Undefined for every - // other caller, which reaches the same call as before. - if (withoutExtensionsOf !== undefined) { - return registry.foldObjectExtendersOnto(name, body, { withoutExtensionsOf }); + // package's stored self, which the write replaces. + // + // Neither given is the ordinary call, and `onlyExtensionsOf` alone is + // the call it always was. Both given are both handed to the registry, + // which leaves out a contribution either one leaves out. + if (onlyExtensionsOf === undefined && withoutExtensionsOf === undefined) { + return registry.foldObjectExtendersOnto(name, body); } - return onlyExtensionsOf === undefined - ? registry.foldObjectExtendersOnto(name, body) - : registry.foldObjectExtendersOnto(name, body, { onlyExtensionsOf }); + return registry.foldObjectExtendersOnto(name, body, { + ...(onlyExtensionsOf !== undefined ? { onlyExtensionsOf } : {}), + ...(withoutExtensionsOf !== undefined ? { withoutExtensionsOf } : {}), + }); } catch { // The fold is a read over in-memory contributors; a failure here // must not turn a served schema into a 5xx. diff --git a/packages/metadata-protocol/src/protocol.ts b/packages/metadata-protocol/src/protocol.ts index f154a31120d..7e665b891be 100644 --- a/packages/metadata-protocol/src/protocol.ts +++ b/packages/metadata-protocol/src/protocol.ts @@ -2023,6 +2023,15 @@ export class ObjectStackProtocolImplementation implements * `warn`, not `error`, per this repo's degradation rule: no write claims to * have persisted anything it did not. The consequence is a possible wrong * verdict on the NEXT reference, and the message says so. + * + * ## `targetFold` (#33072) + * + * Optional; every caller but one passes nothing and gets the fold above. + * The runtime authoring gate passes it on an `object_extension` write: the + * stored row named `targetFold.target` is folded without + * `targetFold.withoutExtensionsOf`'s `extend` contributions (the written + * package's own stored extension of the target, which the write + * replaces), and every other row is folded exactly as without it. */ private async foldStoredCollection( registered: unknown[], @@ -2779,6 +2788,21 @@ export class ObjectStackProtocolImplementation implements * already been folded, and the fold concatenates `validations`/`indexes` * (see {@link SchemaRegistry.foldObjectExtendersOnto}), so applying it twice * would duplicate both. + * + * ## The two optional package arguments + * + * Each is handed to the registry's fold as the option of the same name + * (`ObjectExtensionFoldOptions`), and both are optional: + * + * - `onlyExtensionsOf` (#29903, #29872) — every OTHER package's `extend` + * contributions are left out; the per-package layer passes it. + * - `withoutExtensionsOf` (#33072) — that one package's `extend` + * contributions are left out; the runtime authoring gate passes it for + * an `object_extension` write's target. + * + * Neither given is the ordinary fold. Both given are both handed over, and + * the registry leaves out a contribution either one leaves out; no caller + * passes both today. */ private foldObjectExtendersFromRegistry(type: string, name: unknown, body: unknown, onlyExtensionsOf?: string, withoutExtensionsOf?: string): unknown { // [#25467 cut 30] The body moved to `protocol-object-extender-fold.ts` (see `ObjectExtenderFoldHost`). diff --git a/packages/spec/src/migrations/entries/semantic/18.object-extension-door-computed-field-expression-judged.ts b/packages/spec/src/migrations/entries/semantic/18.object-extension-door-computed-field-expression-judged.ts index daab6f7f8d6..b1aba4b3c5a 100644 --- a/packages/spec/src/migrations/entries/semantic/18.object-extension-door-computed-field-expression-judged.ts +++ b/packages/spec/src/migrations/entries/semantic/18.object-extension-door-computed-field-expression-judged.ts @@ -34,5 +34,8 @@ export const entry: SemanticMigration = { acceptanceCriteria: 'Publish each extension that adds a computed field again: the publish answers 200 with no ' + '`expression-invalid` issue located at an `objectExtensions[0] · field` site, and a record of the extended ' - + 'object holds a value in every computed field the extension adds.', + + 'object holds a value in every computed field the extension adds. A package-wide draft publish ' + + '(`publishPackageDrafts`) whose drafts depend on a sibling extension draft is refused, because that ' + + 'batch\'s pending set carries no extension drafts (#33152); publish the extension first through the ' + + 'per-item door.', }; From bb8a46225eb8eef07f93863a1adba76b3976e0e1 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 13 Nov 2026 23:29:47 +0000 Subject: [PATCH 9/9] fix(spec): the object_extension door entry's guidance cites no tracker id The printed migration guidance of a semantic entry carries no tracker number. The batch-publish sentence keeps its substance; the changeset and the docblocks still cite the follow-up card. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01L9qibwwiSN1TXWjohzCZN9 --- ...18.object-extension-door-computed-field-expression-judged.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/spec/src/migrations/entries/semantic/18.object-extension-door-computed-field-expression-judged.ts b/packages/spec/src/migrations/entries/semantic/18.object-extension-door-computed-field-expression-judged.ts index b1aba4b3c5a..76def782fa5 100644 --- a/packages/spec/src/migrations/entries/semantic/18.object-extension-door-computed-field-expression-judged.ts +++ b/packages/spec/src/migrations/entries/semantic/18.object-extension-door-computed-field-expression-judged.ts @@ -36,6 +36,6 @@ export const entry: SemanticMigration = { + '`expression-invalid` issue located at an `objectExtensions[0] · field` site, and a record of the extended ' + 'object holds a value in every computed field the extension adds. A package-wide draft publish ' + '(`publishPackageDrafts`) whose drafts depend on a sibling extension draft is refused, because that ' - + 'batch\'s pending set carries no extension drafts (#33152); publish the extension first through the ' + + 'batch\'s pending set carries no extension drafts; publish the extension first through the ' + 'per-item door.', };