Skip to content

Commit 5c7e448

Browse files
fix(lint): the object_extension publish door refuses an extension field under a label its target already shows, or another field of the same extension shows (field-label-duplicate) (#34132)
<!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9X2XkBPz2k7zHhv5J4C6j7e)_ Fixes #33644 Clause-②: no (narrowing) 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. ## 维护者速读 - 改了什么:运行时发布扩展对象(Studio 加字段、`/meta` 写入、MCP/AI 作者)时,也检查"同一对象出现两个同名标签的可见字段";扩展新加的字段若和目标对象已有字段(含平台的 `owner_id`)同名标签,或同一扩展里两个字段同名标签,发布被拒(422)。 - 为什么改:这条规则原来只拦 `object` 写入,扩展写入不拦,于是扩展可以在别人的对象上加出第二个"负责人"列,列表、卡片、表单里两列同名分不清。 - 风险与回滚:只收紧扩展发布门;只追究这次扩展新造成的冲突,目标对象原有冲突不算它的,扩展把原有冲突变小(拿走其中一个字段)也不算;一方示例(showcase、plugin-auth 各一条扩展)实测零命中。回滚 = revert 本 PR。 - 先看:`packages/lint/src/lint-duplicate-field-labels.ts`(`duplicateFieldLabelFindings` 的两项门输入);`packages/lint/src/authoring-rules.ts`(`lintDuplicateFieldLabels` 条目加 `object_extension`);`packages/lint/src/runtime-gate.object-writes.test.ts`(新 describe 的十一条用例)。 - 两分钟验证:`pnpm --filter @objectstack/lint exec vitest run src/runtime-gate.object-writes.test.ts -t "object_extension door refuses"`,预期 11 条全绿。 - 需要你做的:无,席位落地。 ## What changes - `lintDuplicateFieldLabels` (`field-label-duplicate`) joins the `object_extension` publish door (`runtimeTypes: ['object', 'object_extension']`). - On that door the rule judges the target as it will be served after the write: the door already hands the target as served without the written package's own stored extension; the rule folds the written entry among the target's other packages' extensions by priority (`ctx.storedObjectExtensions`, the build's fold, so a field two packages tie on is left out as at the build), and reads the served objects back to their authored shape (`stripInjectedSystemColumns`, keyed on `ctx.runtimeWriteType === 'object_extension'`, the argument `validateStackExpressions` gives for the same input), so `owner_id` is named as the platform's column exactly as the build names it. - The published signature of `lintDuplicateFieldLabels(stack)` is unchanged; the door inputs go through the module-internal `duplicateFieldLabelFindings(stack, options)`, which is not on any package entry. - The gate's existing differential charges the write only with a clash its entry creates; no gate code changed (one comment in `runtime-gate.ts`). On this door the rule also drops a candidate clash whose fields are a subset of a clash the target already serves before the write: an entry that takes a member out of a three-member clash (relabel, hide, or a priority tie) changes the group's message, so the fingerprint differential alone would charge it for what is left. - An entry whose own two fields share a label is refused the same way, whether or not the target shows that label (the build already refuses it; the semantic entry, changeset and docs now name this arm). - The door reads no translation bundle, so the refusal's remedy (semantic entry `replacement`, changeset Migration line, docs) is to give the field a label of its own or reuse the platform column, and on this door the finding's hint drops the build's "(in the translation bundle too …)" clause; `os build` / `os validate` judge a bundle that translates the label apart. - The before-write snapshot that the shrink rule reads is computed only for the objects the written entry extends (verdicts unchanged). - `os explain field-label-duplicate` and `content/docs/deployment/validating-metadata.mdx` name the door. - ADR-0087 semantic entry `object-extension-door-field-label-duplicate-refused` (registered), changeset `.changeset/33644-object-extension-door-label-duplicate.md` (lint + spec minor). Premise reading: the card's "the TARGET's next `object` save is refused for a clash the extension created" holds at `os build` (the stack's extensions fold onto a declared target), not at the publish door: an `object` write judges the body it sends, which carries no extension fields. The door pin below reads it. ## Tests New top-level describe in `runtime-gate.object-writes.test.ts` (the rule's door harness), each a real reading through `runRuntimeAuthoringRules`: 1. ⭐ an extension field labelled 负责人 beside the injected `owner_id` is REFUSED: `where` `object "xl_ticket"`, wire path `objects.xl_ticket.fields`, message names both fields, the label and locale zh-CN, and is byte-identical to the build's finding over the same entry; an extension field labelled like a target field (`Subject`) is refused in the authored pass. 2. unrelated extension writes (`Escalation Level`; `assignee` labelled 处理人; `assignee` labelled 负责人 with `hidden: true`) are not charged. 3. the target's own `object` save after a refused extension write is clean (`lintDuplicateFieldLabels` ran, zero errors). 4. a target that already carries a clash (`phone`/`mobile` both `Phone`, the build reports it) is not charged to an unrelated extension write; an entry that joins the clash is charged (`'fax', 'mobile' and 'phone'`). 5. priority fold: a tie with another package's extension is left out at the build and at the door (with `storedObjectExtensions`); without the stated extensions the door would refuse it; a higher priority (210) is refused. 6. the rule is on both doors. 7. an entry that shrinks a three-member clash the target already serves (`phone`/`mobile`/`fax` all `Phone`; the entry relabels or hides `fax` at priority 210, or ties it at 200) is not charged; a swap that takes `fax` out and puts `headline` under `Phone` is charged. 8. a clashing extension already stored is folded onto the served target by the host; the target's own `object` save then has zero errors, and the build reports the clash on `object "xl_ticket"`. 9. ⭐ an entry whose own `a__c` and `b__c` are both labelled `Region`, on a target that shows no `Region`, is refused; the message names both fields and equals the build's; the same fields under labels of their own publish. 10. the door's hint for a clash only zh-CN shows does not mention a translation bundle; the build's hint over the same entry still does. Forced test edits (each because the rule now runs on this door): - `runtime-gate.object-formula-writes.test.ts` (2 exact roster pins) and `validate-security-posture.runtime-surface.test.ts` (3 exact roster pins): `lintDuplicateFieldLabels` inserted in registry order. - `lint-duplicate-field-labels.test.ts`: the entry's `runtimeTypes` pin reads `['object', 'object_extension']`. - `runtime-gate.object-formula-cycle.test.ts` "the target's own stored cycle…": the extension field took the helper's shared label `F`, joining the target's `f_x`/`f_y` group (a clash this door now charges); it gets its own label `E`, so the test still asserts zero errors and still means what it meant. - `packages/runtime/src/domains/meta-object-extension-item.test.ts` ([#33153] / [#33494] formula-door describes): the `formula()` helper labelled every field `F`, so the CONTROL entry (`a__c`, `b__c`) served two visible fields under one label and the door refused it (CI Test Core 3/8 on `c51fcc1d`). The helper takes a label; the fields that share an entry or a target get their own (`A`, `B`, `S`). Assertions unchanged. Restoring the old fixture reds the CONTROL case only (1 of 50). ## Acceptance notes - HotCRM extensions: not measured (outside this session's repository scope). - The CLI judges an extension's clash only when the stack declares the target; an app extending another package's object is judged at the door only. Unchanged by this PR. ## Verification All readings at head `4fa9c1cd` (branch point `f81e4b6c`). <details><summary>Package tests</summary> - `pnpm --filter @objectstack/lint test`: Test Files 212 passed (212), Tests 9037 passed (9037). `pnpm --filter @objectstack/lint typecheck`: exit 0. - `pnpm --filter @objectstack/spec exec vitest run src/migrations`: Test Files 5 passed, Tests 198 passed. - Consumer `pnpm --filter @objectstack/metadata-protocol test` (the door's host): Test Files 342 passed, 9 skipped (351); Tests 22926 passed, 45 skipped. - Extension-door fixture sweep (every test file outside `packages/lint` that publishes or folds an `objectExtensions` entry): runtime 6 files / 135 tests, rest 5 / 55, objectql 8 / 343, cloud-connection 1 / 5, cli `package-export` 1 / 6, all passed. The dogfood files of that kind run in the battery below. - Consumer `pnpm --filter @objectstack/cli exec vitest run --project unit` (at `315696ed`; round 2 touches no cli input): 421/423 files on the first run; the two reds were `published-subpath-console.pin` and `published-subpath-hook-body.pin` refusing an unbuilt `packages/cli/dist` (prerequisite); after the build both pass (2 files, 29 tests). Integration layer declared to CI. - Full dogfood battery (Clause-② carries the `(narrowing)` arm), `pnpm --filter @objectstack/dogfood test` under the lock: VERDICT command-exit 0, Test Files 467 passed, 3 skipped (470); Tests 3962 passed, 42 skipped (4004). </details> <details><summary>Ablations (one-off, through scripts/ablation-replace.mjs, restored to the HEAD blob each time)</summary> - Rule's `runtimeTypes` back to `['object']`: all 7 round-1 cases of the new describe red. - The stored-extension fold (`objectsAsServed(stack, [])`): only the priority-fold case reds. - The served-object read-back (`servedObjects` branch disabled): only the owner_id case reds (the finding stops naming `owner_id` as the platform's column, so it no longer equals the build's message). - The subset drop (`continue` removed): only the shrink case (7) reds. - The door's hint clause (`authored || extensionWrite` back to `authored`): only the hint case (10) reds, 1 of 55 in the file. </details> <details><summary>First-party exposure</summary> - `examples/app-showcase` entry on `showcase_account` (three fields): build over object + entry + the showcase translation bundle 0 findings; door 0; a planted 负责人 `user` field on the same target is refused (1). - `packages/plugins/plugin-auth` entry on `sys_sso_provider` (`oidc_client_secret`): build 0, door 0; a planted field under the target's `ID` label is refused (1). - No other `objectExtensions` entry under `examples/**` or `packages/**` (tooling and tests aside). HotCRM: not measured. </details> <details><summary>Gates</summary> - `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack`: 114 commands. All 114 exit 0. - `dispatch-gates --ran`: 114 derived, 114 run, 0 NOT-MEASURED, 0 UNRUN. - `check-changeset-no-major --base origin/main --event` over this body: exit 0 (level axis: `no (narrowing)` + `narrowed`, no package graded patch). </details> ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` passes. (No formatter ran; `eslint --no-inline-config` over the ten changed `.ts` files exits 0; the repo-wide run is CI's.) - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. - [x] 6. `packages/spec` touched: its generated artifacts are regenerated and committed. (One migration entry; `check:spec-changes`, `check:upgrade-guide` and the generated-artifact gates exit 0, nothing to commit.) - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English. --- 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01ADHkmTKdZ14pCk23CyRWjE <!-- signed: domain:spec#2 · os-steve · session_01ADHkmQjrEpxMVxEiDUJHqC --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 74e99c2 commit 5c7e448

13 files changed

Lines changed: 474 additions & 50 deletions
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
'@objectstack/lint': minor
3+
'@objectstack/spec': minor
4+
---
5+
6+
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`)
7+
8+
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.
9+
Metadata-protocol: narrowed
10+
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.
11+
12+
<!-- adr-0087: registered object-extension-door-field-label-duplicate-refused -->
13+
14+
**BREAKING** accept-set narrowing of the runtime `object_extension` publish door (`lintDuplicateFieldLabels` joins its `runtimeTypes`).
15+
16+
`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.
17+
18+
- 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.
19+
- 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.
20+
- 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.
21+
- 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.
22+
23+
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`.

‎content/docs/deployment/validating-metadata.mdx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,11 @@ every package's entry (#33494), so both judge the same definition of each
629629
field: the written entry's where its priority decides the field (a name the
630630
target already serves included), another package's where that one outranks it.
631631
On a declared object neither judges a field two packages add at the priority
632-
that decides it.
632+
that decides it. A field the entry adds under a label the target already shows,
633+
the platform's `owner_id` included, or under the label of another field of the
634+
same entry, is refused as `field-label-duplicate` (#33644), judged on the target as it will be served after the write, so only a
635+
clash the entry creates is charged: not one the target already carried, nor
636+
what is left of one after the entry took a field out of it.
633637

634638
**Declared enforcement that cannot run** is two rows for the mirror-image
635639
reason, and #4716 is where it split. That heading covers four rule ids, and

‎packages/lint/src/authoring-rules.ts‎

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ import { lintConnectorCredentialLiterals } from './lint-connector-credential-lit
157157
import { lintLivenessProperties } from './lint-liveness-properties.js';
158158
import { lintAutonumberFormats } from './lint-autonumber-formats.js';
159159
import { lintViewRefs } from './lint-view-refs.js';
160-
import { lintDuplicateFieldLabels } from './lint-duplicate-field-labels.js';
160+
import { duplicateFieldLabelFindings } from './lint-duplicate-field-labels.js';
161161
import { validateRetiredPermissionResidue } from './validate-retired-permission-residue.js';
162162
import { validateEmailTemplateHolePlacements } from './validate-email-template-hole-placements.js';
163163
import { validateEmailTemplateHoleGrammar } from './validate-email-template-hole-grammar.js';
@@ -356,15 +356,26 @@ export interface AuthoringRuleContext {
356356
* so a name it does not carry is refused there; on the CLI commands they are
357357
* one app's declaration, and the object-reference ladder (sibling packages,
358358
* platform names, a platform-prefixed name advised at `warning`) applies.
359+
*
360+
* [#33644] `lintDuplicateFieldLabels` reads `object_extension` only, on the
361+
* argument `validateStackExpressions` gives for the same write: there the
362+
* snapshot's objects are the registry's served definitions, carrying the
363+
* injected columns as declared fields, so the rule reads them back to the
364+
* authored shape the build judges (`stripInjectedSystemColumns`); and it
365+
* leaves out a label group every member of which already shared the label on
366+
* the target without the written entry, a clash the entry did not create.
359367
*/
360368
runtimeWriteType?: string;
361369
/**
362370
* [#33494] Set by the runtime gate on an `object_extension` write only: the
363371
* written entry's target's other packages' published extensions, as the
364-
* host's registry holds them. Read by one rule, `validateStackExpressions`,
365-
* whose extension walk folds the written entry among them by priority (the
366-
* build's own fold, `objectsAsServed`), so the door judges the definition
367-
* the build judges (`StackExpressionOptions.storedObjectExtensions`).
372+
* host's registry holds them. Read by two rules, each folding the written
373+
* entry among them by priority (the build's own fold, `objectsAsServed`), so
374+
* the door judges the definition the build judges:
375+
* `validateStackExpressions`' extension walk
376+
* (`StackExpressionOptions.storedObjectExtensions`) and (#33644)
377+
* `lintDuplicateFieldLabels` (`DuplicateFieldLabelOptions`, read by the
378+
* module-internal `duplicateFieldLabelFindings`).
368379
*/
369380
storedObjectExtensions?: readonly StoredObjectExtension[];
370381
/**
@@ -2370,16 +2381,36 @@ export const AUTHORING_RULES: readonly AuthoringRule[] = [
23702381
// another object; a re-save of that object is judged on its own body, as
23712382
// for every gating rule at this door. No boot or registration path runs
23722383
// this table, so an app already installed keeps loading.
2384+
//
2385+
// [#33644] `object_extension` joins: an extension adds fields to an object
2386+
// it does not own, and the registry folds them onto it, so one can add a
2387+
// field under a label the target already shows (`owner_id` included). The
2388+
// door hands the written entry and the target as served without the written
2389+
// package's own extension; the rule folds the entry among the target's other
2390+
// packages' extensions by priority (`storedObjectExtensions`, the build's
2391+
// fold) and reads the served objects back to their authored shape
2392+
// (`runtimeWriteType`, the expression rule's argument for the same input).
2393+
// The write is charged with the clash its entry creates and nothing the
2394+
// target already carried: the gate's differential cancels an unchanged
2395+
// group, and the rule itself drops a group every member of which already
2396+
// shared the label on the target (one the entry shrank by taking a member
2397+
// out), whose message the baseline cannot hold. MEASURED first: the two
2398+
// first-party `objectExtensions` entries (app-showcase's `showcase_account`
2399+
// overlay, plugin-auth's `sys_sso_provider` secret) add no clash, as
2400+
// written or in any locale.
23732401
{
23742402
name: 'lintDuplicateFieldLabels',
23752403
tier: 'gating',
23762404
input: 'parsed',
23772405
commands: ALL,
23782406
source: 'packages/lint/src/lint-duplicate-field-labels.ts',
23792407
surfaces: CLI_AND_RUNTIME,
2380-
runtimeTypes: ['object'],
2381-
run: (stack) =>
2382-
lintDuplicateFieldLabels(stack).map((f) => ({
2408+
runtimeTypes: ['object', 'object_extension'],
2409+
run: (stack, ctx) =>
2410+
duplicateFieldLabelFindings(stack, {
2411+
...(ctx.storedObjectExtensions !== undefined ? { storedObjectExtensions: ctx.storedObjectExtensions } : {}),
2412+
...(ctx.runtimeWriteType === 'object_extension' ? { extensionWrite: true } : {}),
2413+
}).map((f) => ({
23832414
severity: f.severity,
23842415
rule: f.rule,
23852416
where: f.where,

‎packages/lint/src/lint-duplicate-field-labels.test.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,12 @@ describe('lintDuplicateFieldLabels', () => {
8282
expect(lintDuplicateFieldLabels({ objects: [obj] })).toEqual([]);
8383
});
8484

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

0 commit comments

Comments
 (0)