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/33644-object-extension-door-label-duplicate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
'@objectstack/lint': minor
'@objectstack/spec': minor
---

fix(lint): the runtime `object_extension` publish door refuses an extension that adds a field under a label the object it extends already shows, or under the label of another field of the same extension (`field-label-duplicate`)

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 fields create a `field-label-duplicate` clash on the object it extends. No exported type or signature changes. Measured first-party: the two extension entries (`examples/app-showcase` on `showcase_account`, three fields; `packages/plugins/plugin-auth` on `sys_sso_provider`, one `secret` field) add no clash, as written or in any locale, so nothing first-party is newly refused. HotCRM: not measured.
Metadata-protocol: narrowed
Skills-docs: none owed — this PR edits `content/docs/deployment/validating-metadata.mdx` (the object extension door paragraph names the rule); `os explain field-label-duplicate` names the door; `skills/objectstack-data` teaches `defineObjectExtension({ extend, fields })` and reusing `owner_id` instead of a second owner field without saying the runtime door is exempt, so the door now gives the verdict the build already gives.

<!-- adr-0087: registered object-extension-door-field-label-duplicate-refused -->

**BREAKING** accept-set narrowing of the runtime `object_extension` publish door (`lintDuplicateFieldLabels` joins its `runtimeTypes`).

`os build`, `os validate` and `os lint` refuse an object whose visible fields share one label, extension fields of the same stack folded in, and the publish door refused it on an `object` write. An `object_extension` write ran no such judgment, so an extension could add a field under a label its target already shows (a `user` field labelled 负责人 beside the injected `owner_id`, which a `zh-CN` reader is served as 负责人), or two fields of its own under one label, and publish with a 200: two columns of one name in every grid, card and form of the object.

- On an `object_extension` write the rule judges the target as it will be served after the write: the door's live target without the package's own stored extension (which the write replaces), the written entry folded in among the target's other packages' extensions by priority, as `os build` folds every package's entry. A field two packages add at the priority that decides it is left out, as at the build. The injected columns are read as the platform's, so the finding names `owner_id` as the platform's column.
- A refusal is the gate's `422 INVALID_METADATA` with issue rule `field-label-duplicate`, located on the extended object (`objects.TARGET.fields`), naming the object, every field of the group, the shared label and, when only some locales clash, those locales: the message the build gives for the same entry.
- The write is charged only with a clash its entry creates: a clash the target already carries is not the extension's to answer for, nor is what is left of one after the entry took a field out of it (a new label, `hidden: true`, or a tie at the deciding priority); an entry that joins one changes the group and is refused.
- Unchanged: the object save door, `os build`, `os validate`, `os lint`, a draft save (never gated), and a stored extension, which is served and is judged only when it is published again.

Migration: before publishing an extension again, give each field it adds a label the extended object does not already show and no other field of the same extension carries, set `hidden: true` on it, or drop it and use the field the object already has (the platform's `owner_id` for an owner). The door compares labels as written and as the platform translates its own columns; it reads no translation bundle, so a bundle edit neither raises nor clears a refusal there (`os build` and `os validate` judge the bundle). Upgrade-guide entry `object-extension-door-field-label-duplicate-refused`.
6 changes: 5 additions & 1 deletion content/docs/deployment/validating-metadata.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,11 @@ 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.
that decides it. A field the entry adds under a label the target already shows,
the platform's `owner_id` included, or under the label of another field of the
same entry, is refused as `field-label-duplicate` (#33644), judged on the target as it will be served after the write, so only a
clash the entry creates is charged: not one the target already carried, nor
what is left of one after the entry took a field out of 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
47 changes: 39 additions & 8 deletions packages/lint/src/authoring-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ import { lintConnectorCredentialLiterals } from './lint-connector-credential-lit
import { lintLivenessProperties } from './lint-liveness-properties.js';
import { lintAutonumberFormats } from './lint-autonumber-formats.js';
import { lintViewRefs } from './lint-view-refs.js';
import { lintDuplicateFieldLabels } from './lint-duplicate-field-labels.js';
import { duplicateFieldLabelFindings } from './lint-duplicate-field-labels.js';
import { validateRetiredPermissionResidue } from './validate-retired-permission-residue.js';
import { validateEmailTemplateHolePlacements } from './validate-email-template-hole-placements.js';
import { validateEmailTemplateHoleGrammar } from './validate-email-template-hole-grammar.js';
Expand Down Expand Up @@ -356,15 +356,26 @@ export interface AuthoringRuleContext {
* so a name it does not carry is refused there; on the CLI commands they are
* one app's declaration, and the object-reference ladder (sibling packages,
* platform names, a platform-prefixed name advised at `warning`) applies.
*
* [#33644] `lintDuplicateFieldLabels` reads `object_extension` only, on the
* argument `validateStackExpressions` gives for the same write: there the
* snapshot's objects are the registry's served definitions, carrying the
* injected columns as declared fields, so the rule reads them back to the
* authored shape the build judges (`stripInjectedSystemColumns`); and it
* leaves out a label group every member of which already shared the label on
* the target without the written entry, a clash the entry did not create.
*/
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`).
* host's registry holds them. Read by two rules, each folding the written
* entry among them by priority (the build's own fold, `objectsAsServed`), so
* the door judges the definition the build judges:
* `validateStackExpressions`' extension walk
* (`StackExpressionOptions.storedObjectExtensions`) and (#33644)
* `lintDuplicateFieldLabels` (`DuplicateFieldLabelOptions`, read by the
* module-internal `duplicateFieldLabelFindings`).
*/
storedObjectExtensions?: readonly StoredObjectExtension[];
/**
Expand Down Expand Up @@ -2370,16 +2381,36 @@ export const AUTHORING_RULES: readonly AuthoringRule[] = [
// another object; a re-save of that object is judged on its own body, as
// for every gating rule at this door. No boot or registration path runs
// this table, so an app already installed keeps loading.
//
// [#33644] `object_extension` joins: an extension adds fields to an object
// it does not own, and the registry folds them onto it, so one can add a
// field under a label the target already shows (`owner_id` included). The
// door hands the written entry and the target as served without the written
// package's own extension; the rule folds the entry among the target's other
// packages' extensions by priority (`storedObjectExtensions`, the build's
// fold) and reads the served objects back to their authored shape
// (`runtimeWriteType`, the expression rule's argument for the same input).
// The write is charged with the clash its entry creates and nothing the
// target already carried: the gate's differential cancels an unchanged
// group, and the rule itself drops a group every member of which already
// shared the label on the target (one the entry shrank by taking a member
// out), whose message the baseline cannot hold. MEASURED first: the two
// first-party `objectExtensions` entries (app-showcase's `showcase_account`
// overlay, plugin-auth's `sys_sso_provider` secret) add no clash, as
// written or in any locale.
{
name: 'lintDuplicateFieldLabels',
tier: 'gating',
input: 'parsed',
commands: ALL,
source: 'packages/lint/src/lint-duplicate-field-labels.ts',
surfaces: CLI_AND_RUNTIME,
runtimeTypes: ['object'],
run: (stack) =>
lintDuplicateFieldLabels(stack).map((f) => ({
runtimeTypes: ['object', 'object_extension'],
run: (stack, ctx) =>
duplicateFieldLabelFindings(stack, {
...(ctx.storedObjectExtensions !== undefined ? { storedObjectExtensions: ctx.storedObjectExtensions } : {}),
...(ctx.runtimeWriteType === 'object_extension' ? { extensionWrite: true } : {}),
}).map((f) => ({
severity: f.severity,
rule: f.rule,
where: f.where,
Expand Down
6 changes: 4 additions & 2 deletions packages/lint/src/lint-duplicate-field-labels.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,12 @@ describe('lintDuplicateFieldLabels', () => {
expect(lintDuplicateFieldLabels({ objects: [obj] })).toEqual([]);
});

it('is a gating entry the three commands and the object publish door run', () => {
it('is a gating entry the three commands and the object and object_extension publish doors run', () => {
const entry = AUTHORING_RULES.find((r) => r.name === 'lintDuplicateFieldLabels');
expect(entry?.tier).toBe('gating');
expect(entry?.runtimeTypes).toEqual(['object']);
// [#33644] `object_extension` joins; its door pins live in
// `runtime-gate.object-writes.test.ts`.
expect(entry?.runtimeTypes).toEqual(['object', 'object_extension']);
const stack = { objects: [ticketObject()] };
for (const command of ['validate', 'build', 'lint'] as const) {
const rules = runAuthoringRules(command, { normalized: stack, parsed: stack }).filter((f) => f.rule === FIELD_LABEL_DUPLICATE);
Expand Down
Loading
Loading