From 30c3cf1d1fb5f87383feb901e650f9325b51326a Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 01:58:25 +0000 Subject: [PATCH 1/5] feat(lint): refuse two visible fields an object serves under one label New gating rule field-label-duplicate (lintDuplicateFieldLabels): compares each object's visible fields, the platform-injected columns included, as translateObject serves them in the authored pass and in every bundle or built-in system-label locale. Runs on validate, build, lint and the object publish door. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01FEkQ5mdmzDcF58D1JdRH4y --- content/docs/deployment/cli.mdx | 2 +- .../docs/deployment/validating-metadata.mdx | 2 +- .../build-with-claude-code.mdx | 2 +- content/docs/ui/react-pages.mdx | 2 +- packages/lint/src/authoring-rules.ts | 30 +++ packages/lint/src/index.ts | 3 + .../src/lint-duplicate-field-labels.test.ts | 92 +++++++ .../lint/src/lint-duplicate-field-labels.ts | 236 ++++++++++++++++++ 8 files changed, 365 insertions(+), 4 deletions(-) create mode 100644 packages/lint/src/lint-duplicate-field-labels.test.ts create mode 100644 packages/lint/src/lint-duplicate-field-labels.ts diff --git a/content/docs/deployment/cli.mdx b/content/docs/deployment/cli.mdx index a1cbb3b6c42..653eb1ed427 100644 --- a/content/docs/deployment/cli.mdx +++ b/content/docs/deployment/cli.mdx @@ -880,7 +880,7 @@ os compile --json # JSON output for CI pipelines → Normalizing stack definition... → Lowering inline handlers... → Validating protocol compliance... - → Running author-time rules (67)... + → Running author-time rules (68)... → Checking that every required capability has a provider installable in this edition... → Collecting package docs (ADR-0046)... 0 collected → Writing artifact... diff --git a/content/docs/deployment/validating-metadata.mdx b/content/docs/deployment/validating-metadata.mdx index c0f8161f8e7..2b9c1c4479b 100644 --- a/content/docs/deployment/validating-metadata.mdx +++ b/content/docs/deployment/validating-metadata.mdx @@ -837,7 +837,7 @@ A clean run walks the registry and reports timing: Config: /path/to/support-desk/objectstack.config.ts Load time: 21ms → Validating against ObjectStack Protocol... - → Running author-time rules (67)... + → Running author-time rules (68)... → Checking that every required capability has a provider installable in this edition... → Checking package docs (ADR-0046)... diff --git a/content/docs/getting-started/build-with-claude-code.mdx b/content/docs/getting-started/build-with-claude-code.mdx index 5f8f38827c8..0afbb85a249 100644 --- a/content/docs/getting-started/build-with-claude-code.mdx +++ b/content/docs/getting-started/build-with-claude-code.mdx @@ -311,7 +311,7 @@ visible: 'status != "resolved"' ◆ Validate ──────────────────────────────────────── → Validating against ObjectStack Protocol... - → Running author-time rules (67)... + → Running author-time rules (68)... ✗ Author-time rules failed (1 issue) • stack · action 'resolve_ticket' visible: bare reference `status` — a diff --git a/content/docs/ui/react-pages.mdx b/content/docs/ui/react-pages.mdx index a2b6e12e644..a2c91e9cff5 100644 --- a/content/docs/ui/react-pages.mdx +++ b/content/docs/ui/react-pages.mdx @@ -404,7 +404,7 @@ objectstack validate ──────────────────────────────────────── → Loading configuration... → Validating against ObjectStack Protocol... - → Running author-time rules (67)... + → Running author-time rules (68)... → Checking that every required capability has a provider installable in this edition... → Checking package docs (ADR-0046)... diff --git a/packages/lint/src/authoring-rules.ts b/packages/lint/src/authoring-rules.ts index 0e9f012f541..2c1b6bbfbbf 100644 --- a/packages/lint/src/authoring-rules.ts +++ b/packages/lint/src/authoring-rules.ts @@ -157,6 +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 { 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'; @@ -2345,6 +2346,35 @@ export const AUTHORING_RULES: readonly AuthoringRule[] = [ hint: f.fix ?? '', })), }, + // Two visible fields of one object served under one label + // (`field-label-duplicate`): the platform's `owner_id` and an author's + // `assignee`, both read as "负责人" by a zh-CN reader, are two columns of one + // name in every grid, card and form, and editing one reads as editing the + // other. GATING on all three commands and on the runtime publish gate's + // `object` writes, the door an AI or Studio author has. The labels compared + // are the ones `translateObject` serves (see the rule's module note), and + // the gate's differential charges a stored object's clash only to the write + // that creates it, so an object already stored with one keeps saving + // unrelated edits. No boot or registration path runs this table, so an app + // already installed keeps loading. + { + 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) => ({ + severity: f.severity, + rule: f.rule, + where: f.where, + path: f.path, + message: f.message, + hint: f.hint, + })), + }, // #3991 / ADR-0120 D5b — a column carrying BOTH a field-level `unique` and a // single-column declared unique index states two scopes of which at most one // takes effect (`unique/double-declaration`, the four-quadrant matrix). diff --git a/packages/lint/src/index.ts b/packages/lint/src/index.ts index 0ef6a49d8c0..b2f70e67f69 100644 --- a/packages/lint/src/index.ts +++ b/packages/lint/src/index.ts @@ -1185,6 +1185,9 @@ export { AUTONUMBER_LITERAL_TOKEN, } from './lint-autonumber-formats.js'; +export { lintDuplicateFieldLabels, FIELD_LABEL_DUPLICATE } from './lint-duplicate-field-labels.js'; +export type { DuplicateFieldLabelFinding } from './lint-duplicate-field-labels.js'; + export { lintViewRefs } from './lint-view-refs.js'; export type { ViewRefFinding } from './lint-view-refs.js'; export { diff --git a/packages/lint/src/lint-duplicate-field-labels.test.ts b/packages/lint/src/lint-duplicate-field-labels.test.ts new file mode 100644 index 00000000000..0f2b93555e3 --- /dev/null +++ b/packages/lint/src/lint-duplicate-field-labels.test.ts @@ -0,0 +1,92 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +import { describe, expect, it } from 'vitest'; + +import { AUTHORING_RULES, runAuthoringRules } from './authoring-rules.js'; +import { FIELD_LABEL_DUPLICATE, lintDuplicateFieldLabels } from './lint-duplicate-field-labels.js'; + +/** The staging object: an AI-added `user` field labelled like the platform's `owner_id` in zh-CN. */ +function ticketObject(assignee: Record = {}): Record { + return { + name: 'e9gv_ticket', + label: '工单', + fields: { + title: { type: 'text', label: '标题' }, + assignee: { type: 'user', label: '负责人', ...assignee }, + }, + }; +} + +describe('lintDuplicateFieldLabels', () => { + it('reports the injected owner_id and an authored field the zh-CN reader sees under one label', () => { + const findings = lintDuplicateFieldLabels({ objects: [ticketObject()] }); + expect(findings).toHaveLength(1); + const [f] = findings; + expect(f.rule).toBe(FIELD_LABEL_DUPLICATE); + expect(f.severity).toBe('error'); + expect(f.where).toBe('object "e9gv_ticket"'); + expect(f.path).toBe('objects[0].fields'); + expect(f.message).toContain("'assignee' and 'owner_id'"); + expect(f.message).toContain('"负责人"'); + expect(f.message).toContain('locale zh-CN'); + expect(f.hint).toContain("'owner_id'"); + }); + + it('does not compare a hidden field', () => { + expect(lintDuplicateFieldLabels({ objects: [ticketObject({ hidden: true })] })).toEqual([]); + }); + + it('passes fields whose labels differ in every locale', () => { + expect(lintDuplicateFieldLabels({ objects: [ticketObject({ label: '处理人' })] })).toEqual([]); + }); + + it('does not compare owner_id where the platform injects none', () => { + const obj = { ...ticketObject(), ownership: 'none' }; + expect(lintDuplicateFieldLabels({ objects: [obj] })).toEqual([]); + }); + + it('reports a clash only a translation bundle creates, naming that locale alone', () => { + const stack = { + objects: [ + { name: 'deal', fields: { amount: { type: 'currency', label: 'Amount' }, total: { type: 'currency', label: 'Total' } } }, + ], + translations: [ + { 'ja-JP': { objects: { deal: { fields: { amount: { label: '金額' }, total: { label: '金額' } } } } } }, + ], + }; + const findings = lintDuplicateFieldLabels(stack); + expect(findings).toHaveLength(1); + expect(findings[0].message).toContain("'amount' and 'total'"); + expect(findings[0].message).toContain('"金額" when read in locale ja-JP,'); + }); + + it('reports an authored clash once, naming no locale', () => { + const stack = { + objects: [ + { name: 'deal', fields: { stage: { type: 'text', label: 'Status' }, status: { type: 'select', label: ' Status ' } } }, + ], + }; + const findings = lintDuplicateFieldLabels(stack); + expect(findings).toHaveLength(1); + expect(findings[0].message).toContain("'stage' and 'status' under one label \"Status\", so"); + }); + + it('reads an authored owner_id with its own label in place of the injected column', () => { + const obj = { + name: 'e9gv_ticket', + fields: { owner_id: { type: 'lookup', reference: 'sys_user', label: '所有者' }, assignee: { type: 'user', label: '负责人' } }, + }; + expect(lintDuplicateFieldLabels({ objects: [obj] })).toEqual([]); + }); + + it('is a gating entry the three commands and the object publish door run', () => { + const entry = AUTHORING_RULES.find((r) => r.name === 'lintDuplicateFieldLabels'); + expect(entry?.tier).toBe('gating'); + expect(entry?.runtimeTypes).toEqual(['object']); + 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); + expect(rules.map((f) => f.severity), command).toEqual(['error']); + } + }); +}); diff --git a/packages/lint/src/lint-duplicate-field-labels.ts b/packages/lint/src/lint-duplicate-field-labels.ts new file mode 100644 index 00000000000..df051586883 --- /dev/null +++ b/packages/lint/src/lint-duplicate-field-labels.ts @@ -0,0 +1,236 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * Two visible fields of one object that a reader sees under the same label + * (`field-label-duplicate`). + * + * Every surface that draws an object's fields names a column by its label: the + * list grid's header, the kanban card's field line, the form's caption, the + * export file's header, the import template's column. Two visible fields with + * one label are two columns a person cannot tell apart, and a person who edits + * one of them believes they changed the other. The common case is a field the + * author adds beside a platform field it duplicates: a `user` field `assignee` + * labelled "负责人" on an object that already carries the injected `owner_id`, + * which a zh-CN reader is served as "负责人" too. The two are not the same + * thing (`owner_id` drives record ownership and visibility, the author's field + * drives nothing), so the reader cannot even pick the right one by meaning. + * + * ## What is compared + * + * The fields an object SERVES: its own fields with every `objectExtensions` + * field of the same stack folded in (`objectsAsServed`, the package's one + * fold; a field two packages tie on is left out, since which definition wins + * is registration order), plus the platform columns the registry injects on it + * (`injectedColumnDefsFor`, the spec tables `applySystemFields` spreads; an + * authored field of the same name replaces the injected one). A field declared + * `hidden: true` is drawn on no default surface and is not compared; the + * injected tenant, business-unit and queue columns are hidden by their own + * definitions, so the comparison sees `owner_id` and the four audit columns. + * + * Labels are compared as the reader is served them, in each locale this stack + * can be read in, through the spec's own read-exit translator + * (`translateObject`, the function the `/meta` read applies), never a second + * copy of its ladder: + * + * - the AUTHORED pass: each field's label as written, with the injected + * columns under their definition's label; + * - one pass per locale: every locale a `translations` bundle of this stack + * carries, plus every locale the platform's built-in system-field labels + * carry (`BUILTIN_SYSTEM_FIELD_LABEL_LOCALES`). The second set matters + * without any bundle: a `/meta` read in one of those locales serves the + * injected columns translated while an author's untranslated field keeps + * the label it was written with, which is exactly the "负责人" pair above. + * + * Labels are compared after trimming surrounding white space, otherwise + * exactly. A field with no label is drawn under its name, which is unique on + * the object, and is not compared. + * + * ## What is reported + * + * One finding per group of fields that share a label: in the authored pass + * (then the label clashes for every reader the stack does not translate, and + * the finding names no locale), or else only in some locales (the finding + * names them). Each finding names every field of the group, so the message is + * the same on every run and the publish door's differential charges a stored + * object's clash only to the write that creates it. + * + * `error`: the build, `os validate`, `os lint` and the publish door refuse it. + * Nothing on the boot or registration path runs the author-time rules, so an + * app that is already installed keeps loading. + */ + +import { + BUILTIN_SYSTEM_FIELD_LABEL_LOCALES, + translateObject, + type ObjectLike, + type TranslationBundle, +} from '@objectstack/spec/system'; +import { objectsAsServed, objectsWithoutTiedFields, recordsOf } from './object-graph.js'; +import { injectedColumnDefsFor } from './system-fields.js'; + +type AnyRec = Record; + +export const FIELD_LABEL_DUPLICATE = 'field-label-duplicate'; + +export interface DuplicateFieldLabelFinding { + severity: 'error'; + rule: typeof FIELD_LABEL_DUPLICATE; + /** `object "e9gv_ticket"`. */ + where: string; + /** `objects[N].fields` — positional in the stack's own `objects`. */ + path: string; + message: string; + hint: string; +} + +/** The authored pass's key in a group's pass set; no locale tag is spelled like this. */ +const AUTHORED = ''; + +function isRec(v: unknown): v is AnyRec { + return !!v && typeof v === 'object' && !Array.isArray(v); +} + +/** + * The stack's translation bundles narrowed to ONE object's field entries and + * merged per locale key, a later bundle's entry overriding an earlier one's key + * by key (the order the app plugin loads them into the i18n service). + */ +function fieldBundleFor(stack: AnyRec, objectName: string): TranslationBundle { + const merged: Record }> }> = {}; + const bundles = Array.isArray(stack.translations) ? stack.translations : []; + for (const bundle of bundles) { + if (!isRec(bundle)) continue; + for (const [locale, data] of Object.entries(bundle)) { + if (!isRec(data) || !isRec(data.objects)) continue; + const node = data.objects[objectName]; + if (!isRec(node) || !isRec(node.fields)) continue; + const slot = (merged[locale] ??= { objects: { [objectName]: { fields: {} } } }).objects[objectName].fields; + for (const [fieldName, entry] of Object.entries(node.fields)) { + if (isRec(entry)) slot[fieldName] = { ...(slot[fieldName] ?? {}), ...entry }; + } + } + } + return merged as unknown as TranslationBundle; +} + +/** The locales this object's labels are compared in: the bundle's, then the built-in table's. */ +function localesOf(bundle: TranslationBundle): string[] { + const out: string[] = []; + const seen = new Set(); + for (const code of [...Object.keys(bundle), ...BUILTIN_SYSTEM_FIELD_LABEL_LOCALES]) { + const key = code.toLowerCase(); + if (seen.has(key)) continue; + seen.add(key); + out.push(code); + } + return out; +} + +/** field name → the label a reader sees, for the visible fields of `fields`. */ +function visibleLabels(fields: Readonly>): Map { + const out = new Map(); + for (const [name, def] of Object.entries(fields)) { + if (def.hidden === true) continue; + if (typeof def.label !== 'string') continue; + const label = def.label.trim(); + if (label.length > 0) out.set(name, label); + } + return out; +} + +/** Fields grouped by the label they share, groups of two or more only. */ +function clashes(labels: ReadonlyMap): Map { + const byLabel = new Map(); + for (const [name, label] of labels) { + const group = byLabel.get(label); + if (group) group.push(name); + else byLabel.set(label, [name]); + } + for (const [label, names] of byLabel) if (names.length < 2) byLabel.delete(label); + return byLabel; +} + +function quoteList(names: readonly string[]): string { + const quoted = names.map((n) => `'${n}'`); + if (quoted.length <= 2) return quoted.join(' and '); + return `${quoted.slice(0, -1).join(', ')} and ${quoted[quoted.length - 1]}`; +} + +/** + * Report every object that serves two or more visible fields under one label. + * Returns a (possibly empty) list of findings; never throws. + */ +export function lintDuplicateFieldLabels(stack: AnyRec): DuplicateFieldLabelFinding[] { + const findings: DuplicateFieldLabelFinding[] = []; + if (!isRec(stack)) return findings; + const declared = recordsOf(stack.objects); + const served = objectsWithoutTiedFields(objectsAsServed(stack)); + + declared.forEach((obj, i) => { + const objectName = typeof obj.name === 'string' ? obj.name : undefined; + if (!objectName) return; + + // The injected columns first, so an authored field of the same name + // replaces the platform's definition, as it does at registration. + const fields: Record = {}; + const injectedNames = new Set(); + for (const [name, def] of injectedColumnDefsFor(obj)) { + fields[name] = { ...def }; + injectedNames.add(name); + } + for (const f of recordsOf(served[i]?.fields)) { + if (typeof f.name !== 'string') continue; + fields[f.name] = f; + injectedNames.delete(f.name); + } + + const bundle = fieldBundleFor(stack, objectName); + // group key (sorted field names + label) → the passes it clashes in. + const groups = new Map(); + const record = (pass: string, labels: ReadonlyMap): void => { + for (const [label, names] of clashes(labels)) { + const sorted = [...names].sort(); + const key = `${sorted.join('\u0000')}\u0001${label}`; + const group = groups.get(key) ?? { names: sorted, label, passes: [] }; + group.passes.push(pass); + groups.set(key, group); + } + }; + + record(AUTHORED, visibleLabels(fields)); + for (const locale of localesOf(bundle)) { + const doc = translateObject({ name: objectName, fields } as ObjectLike, bundle, { locale }); + record(locale, visibleLabels((doc.fields ?? {}) as Record)); + } + + for (const { names, label, passes } of groups.values()) { + const authored = passes.includes(AUTHORED); + const locales = passes.filter((p) => p !== AUTHORED); + // A clash in the authored pass names no locale: every reader the stack + // does not translate sees it, and the locale passes that repeat it + // under the same label are the same group. + const injected = names.filter((n) => injectedNames.has(n)); + const scope = authored ? '' : ` when read in ${locales.length === 1 ? 'locale' : 'locales'} ${locales.join(', ')}`; + findings.push({ + severity: 'error', + rule: FIELD_LABEL_DUPLICATE, + where: `object "${objectName}"`, + path: `objects[${i}].fields`, + message: + `object "${objectName}" shows fields ${quoteList(names)} under one label "${label}"${scope}, so ` + + 'a person sees more than one column of that name in lists, cards and forms and cannot tell which one they edit.' + + (injected.length > 0 + ? ` ${quoteList(injected)} ${injected.length === 1 ? 'is a column' : 'are columns'} the platform adds to the object.` + : ''), + hint: + 'Give each visible field its own label' + + (authored ? '' : ' (in the translation bundle too, for a locale only a translation clashes in)') + + ', or set `hidden: true` on the one readers should not see, or drop the duplicate field' + + (injected.length > 0 + ? ` and use the platform's ${quoteList(injected)} instead of declaring a second field for the same thing.` + : '.'), + }); + } + }); + return findings; +} From 63ddbdc3c4d390ab1fa8303ee61789b91e2db52b Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 02:00:19 +0000 Subject: [PATCH 2/5] test(lint): pin field-label-duplicate at the object publish door and in os explain Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01FEkQ5mdmzDcF58D1JdRH4y --- packages/lint/src/authoring-rules.ts | 10 ++--- .../src/lint-duplicate-field-labels.test.ts | 9 +++++ .../lint/src/lint-duplicate-field-labels.ts | 14 ++++--- packages/lint/src/rule-explanations.ts | 31 +++++++++++++++ .../src/runtime-gate.object-writes.test.ts | 39 +++++++++++++++++++ 5 files changed, 93 insertions(+), 10 deletions(-) diff --git a/packages/lint/src/authoring-rules.ts b/packages/lint/src/authoring-rules.ts index 2c1b6bbfbbf..fce0076eb06 100644 --- a/packages/lint/src/authoring-rules.ts +++ b/packages/lint/src/authoring-rules.ts @@ -2352,11 +2352,11 @@ export const AUTHORING_RULES: readonly AuthoringRule[] = [ // name in every grid, card and form, and editing one reads as editing the // other. GATING on all three commands and on the runtime publish gate's // `object` writes, the door an AI or Studio author has. The labels compared - // are the ones `translateObject` serves (see the rule's module note), and - // the gate's differential charges a stored object's clash only to the write - // that creates it, so an object already stored with one keeps saving - // unrelated edits. No boot or registration path runs this table, so an app - // already installed keeps loading. + // are the ones `translateObject` serves (see the rule's module note). The + // gate's differential never charges a stored object's clash to a write of + // 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. { name: 'lintDuplicateFieldLabels', tier: 'gating', diff --git a/packages/lint/src/lint-duplicate-field-labels.test.ts b/packages/lint/src/lint-duplicate-field-labels.test.ts index 0f2b93555e3..f825c345370 100644 --- a/packages/lint/src/lint-duplicate-field-labels.test.ts +++ b/packages/lint/src/lint-duplicate-field-labels.test.ts @@ -2,7 +2,10 @@ import { describe, expect, it } from 'vitest'; +import { BUILTIN_SYSTEM_FIELD_LABEL_LOCALES } from '@objectstack/spec/system'; + import { AUTHORING_RULES, runAuthoringRules } from './authoring-rules.js'; +import { explainRule } from './rule-explanations.js'; import { FIELD_LABEL_DUPLICATE, lintDuplicateFieldLabels } from './lint-duplicate-field-labels.js'; /** The staging object: an AI-added `user` field labelled like the platform's `owner_id` in zh-CN. */ @@ -89,4 +92,10 @@ describe('lintDuplicateFieldLabels', () => { expect(rules.map((f) => f.severity), command).toEqual(['error']); } }); + + it('the explanation names exactly the locales the platform translates the injected columns into', () => { + const text = explainRule(FIELD_LABEL_DUPLICATE)!.paragraphs.join(' '); + const named = new Set([...text.matchAll(/`([a-z]{2}(?:-[A-Z]{2})?)`/g)].map((m) => m[1])); + expect([...named].sort()).toEqual([...BUILTIN_SYSTEM_FIELD_LABEL_LOCALES].sort()); + }); }); diff --git a/packages/lint/src/lint-duplicate-field-labels.ts b/packages/lint/src/lint-duplicate-field-labels.ts index df051586883..0d904837d0c 100644 --- a/packages/lint/src/lint-duplicate-field-labels.ts +++ b/packages/lint/src/lint-duplicate-field-labels.ts @@ -50,13 +50,17 @@ * One finding per group of fields that share a label: in the authored pass * (then the label clashes for every reader the stack does not translate, and * the finding names no locale), or else only in some locales (the finding - * names them). Each finding names every field of the group, so the message is - * the same on every run and the publish door's differential charges a stored - * object's clash only to the write that creates it. + * names them). Each finding names every field of the group and nothing + * positional beyond the object, so the message is the same on every run, which + * is what the publish door's differential compares. * * `error`: the build, `os validate`, `os lint` and the publish door refuse it. - * Nothing on the boot or registration path runs the author-time rules, so an - * app that is already installed keeps loading. + * At the door, as for every gating rule there, a write of ANOTHER object is + * never charged with a stored object's clash, while a write of the object + * itself is judged on the body it sends, so re-saving an object that still + * carries a clash is refused until the clash is fixed. Nothing on the boot or + * registration path runs the author-time rules, so an app that is already + * installed keeps loading and serving. */ import { diff --git a/packages/lint/src/rule-explanations.ts b/packages/lint/src/rule-explanations.ts index 8e9573f7b71..d688b994c5c 100644 --- a/packages/lint/src/rule-explanations.ts +++ b/packages/lint/src/rule-explanations.ts @@ -6138,6 +6138,36 @@ const STORED_EXPRESSION_VOLATILE_INPUT_EXPLANATION: RuleExplanation = { ], }; +const FIELD_LABEL_DUPLICATE_EXPLANATION: RuleExplanation = { + rule: 'field-label-duplicate', + covers: 'which fields and which labels are compared', + paragraphs: [ + 'Every surface that draws an object\'s fields names a column by its label: the list grid\'s header, the ' + + 'kanban card\'s field line, the form\'s caption, the export and import columns. Two visible fields with one ' + + 'label are two columns a person cannot tell apart, and editing one reads as editing the other. The common ' + + 'case is a field added beside a platform field it duplicates, such as a `user` field labelled like the ' + + '`owner_id` column the platform adds to every user-owned object (served as "Owner" in English and under ' + + 'its translated label in other languages).', + 'Compared: the fields the object serves, that is its own fields plus every `objectExtensions` field of the ' + + 'same stack, and the columns the platform injects on it (`owner_id` and the `created_*` / `updated_*` ' + + 'audit columns; the organization, business-unit and queue columns are hidden). A field you declare under ' + + 'one of those names replaces the injected column. A field with `hidden: true` is not compared, and a field ' + + 'with no label is drawn under its unique name and is not compared either.', + 'Labels are compared as a reader is served them, trimmed, otherwise exactly: once as written, and once per ' + + 'locale, for every locale a `translations` bundle of the stack carries and every locale the platform ' + + 'translates the injected columns into (`en`, `zh-CN`, `ja-JP`, `es-ES`). The second set needs no bundle: ' + + 'a reader in one of those languages sees the injected columns translated while your untranslated field ' + + 'keeps the label you wrote, so a field labelled "负责人" clashes with `owner_id` for a `zh-CN` reader only, ' + + 'and the finding names that locale.', + 'An error at `os build`, `os validate`, `os lint` and the metadata publish door. At the door a write of ' + + 'another object is never refused for a clash a stored object carries, while saving the object itself is ' + + 'refused until its clash is fixed; nothing on the boot path runs the rule, so an installed app keeps ' + + 'loading. To fix it, give each ' + + 'visible field its own label (in the translation bundle too, when only a translation clashes), set ' + + '`hidden: true` on the field readers should not see, or drop the duplicate and use the platform\'s column.', + ], +}; + export const RULE_EXPLANATIONS: Readonly> = Object.freeze({ [FIELD_NO_CONSUMERS_EXPLANATION.rule]: FIELD_NO_CONSUMERS_EXPLANATION, [SECURITY_OWD_UNSET_EXPLANATION.rule]: SECURITY_OWD_UNSET_EXPLANATION, @@ -6371,6 +6401,7 @@ export const RULE_EXPLANATIONS: Readonly> = Obje [FLOW_REGION_SHAPE_INVALID_EXPLANATION.rule]: FLOW_REGION_SHAPE_INVALID_EXPLANATION, [STORED_EXPRESSION_CROSS_RECORD_INPUT_EXPLANATION.rule]: STORED_EXPRESSION_CROSS_RECORD_INPUT_EXPLANATION, [STORED_EXPRESSION_VOLATILE_INPUT_EXPLANATION.rule]: STORED_EXPRESSION_VOLATILE_INPUT_EXPLANATION, + [FIELD_LABEL_DUPLICATE_EXPLANATION.rule]: FIELD_LABEL_DUPLICATE_EXPLANATION, }); /** The explanation for `rule`, or `undefined` when the rule has none. Exact id match. */ diff --git a/packages/lint/src/runtime-gate.object-writes.test.ts b/packages/lint/src/runtime-gate.object-writes.test.ts index 9bb234c8eaf..a028f460d59 100644 --- a/packages/lint/src/runtime-gate.object-writes.test.ts +++ b/packages/lint/src/runtime-gate.object-writes.test.ts @@ -166,6 +166,10 @@ describe('the object write door dispatches at the adjudicated scope (#4716)', () // and its child object against the deployment's names; the door // controls are in the roll-up describe below. 'lintSummaryRollups', + // Joins as the card's ruling names it (error at the author door): two + // visible fields an object serves under one label. The door cases are + // in the duplicate-label describe below. + 'lintDuplicateFieldLabels', 'validateSecurityPosture', // #8310 — at this door before #4716 // [#19370] `security-role-word` joins this door, and NOT silently — // which is the distinction this pin exists to draw. The maintainer @@ -554,6 +558,7 @@ describe('the object write door dispatches at the adjudicated scope (#4716)', () 'validateTitleFormatRetired', // [#29007] — see the roster pin above 'lintAutonumberFormats', 'lintSummaryRollups', // see the roster pin above + 'lintDuplicateFieldLabels', // see the roster pin above 'validateSecurityPosture', 'validateSecurityRoleWord', // [#19370] — see the roster pin above 'validateRlsPredicateEnforceability', // [#25234] — see the roster pin above @@ -602,6 +607,40 @@ describe('the object write door dispatches at the adjudicated scope (#4716)', () }); }); +describe('the object write door refuses a write that serves two visible fields under one label', () => { + /** The staging pair: an author's `user` field labelled like the injected `owner_id` in zh-CN. */ + const withAssignee = (assignee: Record = {}) => + cleanObject({ fields: { owner: { type: 'text' }, assignee: { type: 'user', label: '负责人', ...assignee } } }); + + it('refuses the write that adds the clash', () => { + const result = expectSingleRefusal(withAssignee(), 'field-label-duplicate'); + const f = result.errors.find((e) => e.rule === 'field-label-duplicate')!; + expect(f.path).toBe('objects.leave_request.fields'); + expect(f.message).toContain("'assignee' and 'owner_id'"); + }); + + it('publishes the same write with the field hidden or labelled apart (the controls)', () => { + for (const item of [withAssignee({ hidden: true }), withAssignee({ label: '处理人' })]) { + const result = gateObject(item); + expect(result.errors, JSON.stringify(result.errors)).toEqual([]); + } + }); + + it('does not charge a stored clash to a sibling write; a re-save of the object itself is judged on its body', () => { + const stored = [withAssignee()]; + // Every gating rule at this door judges a re-save on the body it sends. + const resave = gateObject(withAssignee({ description: 'edited' }), { objects: stored }); + expect(resave.errors.map((e) => e.rule)).toEqual(['field-label-duplicate']); + const healed = gateObject(withAssignee({ label: '处理人' }), { objects: stored }); + expect(healed.errors, JSON.stringify(healed.errors)).toEqual([]); + const sibling = gateObject( + { name: 'leave_type', label: 'Leave Type', sharingModel: 'private', fields: { code: { type: 'text' } } }, + { objects: stored }, + ); + expect(sibling.errors, JSON.stringify(sibling.errors)).toEqual([]); + }); +}); + /** * #10064 — the WIRE spelling of a collection-resident finding's path. * From 2b0925270ca816f8df8c1ca00bf5f03108edc4af Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 02:05:06 +0000 Subject: [PATCH 3/5] fix(example-showcase): label the task assignee and team lead apart from the zh-CN owner column Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01FEkQ5mdmzDcF58D1JdRH4y --- .../app-showcase/src/system/translations/index.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/examples/app-showcase/src/system/translations/index.ts b/examples/app-showcase/src/system/translations/index.ts index 9f53c3c3fdb..24cb59700ce 100644 --- a/examples/app-showcase/src/system/translations/index.ts +++ b/examples/app-showcase/src/system/translations/index.ts @@ -467,7 +467,10 @@ export const ShowcaseTranslationBundle = { title: { label: '标题' }, // The project page's Tasks list, titled by this master-detail. project: { label: '项目', relatedListTitle: '任务' }, - assignee: { label: '负责人' }, + // Not 负责人: that is what a zh-CN reader is served for the platform's + // `owner_id` on this object, and two columns of one label cannot be + // told apart (`field-label-duplicate`). + assignee: { label: '处理人' }, status: { label: '状态', options: { backlog: '待规划', todo: '待办', in_progress: '进行中', in_review: '评审中', done: '已完成' }, @@ -859,7 +862,7 @@ export const ShowcaseTranslationBundle = { }, showcase_team: { label: '团队', pluralLabel: '团队', - fields: { name: { label: '团队名称' }, lead: { label: '负责人' }, capacity_hours: { label: '产能(小时)' } }, + fields: { name: { label: '团队名称' }, lead: { label: '组长' }, capacity_hours: { label: '产能(小时)' } }, _sections: { team: { label: '团队' } }, }, showcase_project_membership: { @@ -1002,7 +1005,7 @@ export const ShowcaseTranslationBundle = { // because `check-i18n-coverage` ratchets this example at its current // untranslated count: a newly declared label that skips zh-CN pushes the // count up and fails the gate. (The gallery's older params sit inside - // that baseline; this one is not allowed to widen it.) `负责人` matches + // that baseline; this one is not allowed to widen it.) `处理人` matches // what the bundle already renders for `showcase_task.assignee`, rather // than introducing a second word for the same idea. // 动作显隐矩阵(objectui#3492 / #3501)。同上:本示例被 @@ -1013,7 +1016,7 @@ export const ShowcaseTranslationBundle = { showcase_action_param_gallery: { params: { p_assignee: { - label: '负责人', + label: '处理人', helpText: '指向系统对象的内联查找 —— 可按姓名或邮箱搜索,无需填写 UUID。', }, }, From 6eed9c4e8be0d6ecf3d6b95ba1affd96f5497839 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 02:07:56 +0000 Subject: [PATCH 4/5] fix(example-todo): label the task owner field apart from the zh-CN owner column; register the ADR-0087 entry and changeset Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01FEkQ5mdmzDcF58D1JdRH4y --- .changeset/33545-duplicate-field-labels.md | 24 ++++++++++++ examples/app-todo/src/translations/zh-CN.ts | 6 ++- ...18.object-field-label-duplicate-refused.ts | 37 +++++++++++++++++++ 3 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 .changeset/33545-duplicate-field-labels.md create mode 100644 packages/spec/src/migrations/entries/semantic/18.object-field-label-duplicate-refused.ts diff --git a/.changeset/33545-duplicate-field-labels.md b/.changeset/33545-duplicate-field-labels.md new file mode 100644 index 00000000000..0f16897e3c6 --- /dev/null +++ b/.changeset/33545-duplicate-field-labels.md @@ -0,0 +1,24 @@ +--- +'@objectstack/lint': minor +'@objectstack/spec': minor +--- + +feat(lint)!: refuse an object that shows two visible fields under one label (`field-label-duplicate`) + +Clause-②: no (narrowing) — `os build`, `os validate`, `os lint` and the metadata publish door (an `object` write) now refuse an object whose visible fields, the platform's injected columns included, share one label in the authored text or in any locale a reader is served. Shipped first-party metadata hit: two example apps, relabelled here (`example-showcase`: `showcase_task.assignee` and `showcase_team.lead`, both served 负责人 to a `zh-CN` reader beside `owner_id`; `example-todo`: `todo_task.owner`, likewise); every other example, every first-party app under `packages/apps` and HotCRM build clean. +Metadata-protocol: narrowed +Skills-docs: none — the authoring half (an AI builder reusing `owner_id` instead of adding a second "Owner" field) is the skills lane's on the parent card; `os explain field-label-duplicate` carries the rule's full text, and four CLI transcripts in `content/docs` show the author-time rule count moving from 67 to 68. + + + +**BREAKING** for metadata that builds today: an object that shows two or more visible fields under one label is now an error. Every surface draws a field under its label (list grid headers, kanban card lines, form captions, export and import columns), so two fields of one label are two columns a person cannot tell apart, and editing one reads as editing the other. The common case is a field added beside the platform's own: a `user` field labelled like `owner_id`, which a `zh-CN` reader is served as "负责人". + +What is compared: the fields the object serves (its own plus every `objectExtensions` field of the stack) and the columns the platform injects on it (`owner_id`, `created_at`, `created_by`, `updated_at`, `updated_by`; the organization, business-unit and queue columns are hidden). A field declared under an injected column's name replaces it. `hidden: true` fields are not compared. Labels are compared trimmed, once as authored and once per locale (every locale a `translations` bundle carries, plus `en`, `zh-CN`, `ja-JP` and `es-ES`, the locales the platform translates the injected columns into), through the same `translateObject` the `/meta` read serves them with. + +FROM → TO, and the fix: + +- FROM an object with `assignee: { type: 'user', label: '负责人' }` beside the injected `owner_id` building clean TO `field-label-duplicate` naming `'assignee' and 'owner_id'`, the label and `locale zh-CN`. Fix: use `owner_id` instead of a second owner field, or label the field apart (for example "处理人"), or set `hidden: true` on it. +- FROM two authored fields labelled "Status" building clean TO the same error, naming both fields and no locale. Fix: give each its own label. +- FROM a translation bundle that gives two fields one label in one locale building clean TO the error naming that locale. Fix: translate them apart in that bundle. + +At the publish door a write of another object is never refused for a clash a stored object carries; saving the clashing object itself is refused until the clash is fixed, as for every gating rule at that door. No boot or registration path runs the author-time rules, so an installed app keeps loading and serving its objects as before. diff --git a/examples/app-todo/src/translations/zh-CN.ts b/examples/app-todo/src/translations/zh-CN.ts index 56cf79d053c..4d6f52d8d36 100644 --- a/examples/app-todo/src/translations/zh-CN.ts +++ b/examples/app-todo/src/translations/zh-CN.ts @@ -53,7 +53,9 @@ export const zhCN: TranslationData = { days_overdue: { label: '逾期天数', help: '距截止日期已过的整天数;未逾期或未设置截止日期时为 0' }, reminder_date: { label: '提醒日期/时间' }, completed_date: { label: '完成日期' }, - owner: { label: '负责人' }, + // Not 负责人: a zh-CN reader is served that for the platform's `owner_id` + // on this object too (`field-label-duplicate`). + owner: { label: '处理人' }, tags: { label: '标签', options: { @@ -104,7 +106,7 @@ export const zhCN: TranslationData = { reports: { todo_tasks_by_status: { label: '按状态统计任务', description: '按状态分组的任务汇总' }, todo_tasks_by_priority: { label: '按优先级统计任务', description: '按优先级分组的任务汇总' }, - todo_tasks_by_owner: { label: '按负责人统计任务', description: '按负责人汇总的任务' }, + todo_tasks_by_owner: { label: '按处理人统计任务', description: '按处理人汇总的任务' }, todo_completed_tasks: { label: '已完成任务', description: '所有已完成任务及其工时记录' }, todo_time_tracking: { label: '工时跟踪报表', description: '预计工时与实际工时分析' }, }, diff --git a/packages/spec/src/migrations/entries/semantic/18.object-field-label-duplicate-refused.ts b/packages/spec/src/migrations/entries/semantic/18.object-field-label-duplicate-refused.ts new file mode 100644 index 00000000000..d446b09f40a --- /dev/null +++ b/packages/spec/src/migrations/entries/semantic/18.object-field-label-duplicate-refused.ts @@ -0,0 +1,37 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +import type { SemanticMigration } from '../../types.js'; + +// The author-time rules refuse an object that shows two visible fields under one +// label (`field-label-duplicate`, `@objectstack/lint`). A structured TODO, not a +// D2 conversion: which of the two fields keeps the label, whether the second one +// should be hidden, or whether it duplicates a platform column and should be +// dropped, is the author's choice and is not recorded anywhere. +export const entry: SemanticMigration = { + id: 'object-field-label-duplicate-refused', + surface: + 'objects[].fields[].label, objectExtensions[].fields[].label and translations[].LOCALE.objects.OBJECT.fields.FIELD.label ' + + '— two or more visible fields of one object served under one label, the injected owner_id and created_* / ' + + 'updated_* columns included, as written or in any locale a reader is served', + replacement: + 'Give each visible field its own label, in the translation bundle too when only a translation clashes; or set ' + + '`hidden: true` on the field readers should not see; or, when the field duplicates a platform column (an owner ' + + 'field beside `owner_id`), drop it and use the platform column. `os validate`, `os build`, `os lint` and the ' + + 'metadata publish door (`422 INVALID_METADATA` on an object write) refuse the shape as `field-label-duplicate`, ' + + 'an error that names every field of the group, the shared label and, when only some locales clash, those ' + + 'locales.', + reason: + 'Every surface draws a field under its label: list grid headers, kanban card lines, form captions, export and ' + + 'import columns. Two visible fields of one label are two columns a person cannot tell apart, and editing one ' + + 'reads as editing the other. The common shape is a field added beside a platform column, such as a `user` field ' + + 'a `zh-CN` reader is served as 负责人 next to `owner_id`, which drives record ownership while the added field ' + + 'drives nothing. No mechanical move is lossless: which field keeps the label is not recorded. Measured at the ' + + 'change: two example apps of this repository carried the shape in their `zh-CN` bundle and were relabelled in ' + + 'the same change; HotCRM carried none. ADR-0087.', + acceptanceCriteria: + 'Run `os validate` or `os build` over the stack: no `field-label-duplicate` finding. Every visible field of an ' + + 'object reads under its own label as written and in every locale its bundles or the platform translate. An ' + + 'installed app is not affected at load: no boot or registration path runs the author-time rules, and a stored ' + + 'object in the shape is still served; its next save through the publish door is refused until it is ' + + 'relabelled. Done when no authored or stored object carries the shape.', +}; From 274a4bd5bffdcec618998245f7b2ae4b09653728 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 02:18:20 +0000 Subject: [PATCH 5/5] test(metadata-protocol): relabel fixture fields the duplicate-label rule now refuses Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01FEkQ5mdmzDcF58D1JdRH4y --- .../src/protocol.runtime-authoring-gate.test.ts | 8 ++++---- .../src/protocol.unknown-picklist-binding-refusal.test.ts | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/metadata-protocol/src/protocol.runtime-authoring-gate.test.ts b/packages/metadata-protocol/src/protocol.runtime-authoring-gate.test.ts index 9b4e5eefd63..e14605ae900 100644 --- a/packages/metadata-protocol/src/protocol.runtime-authoring-gate.test.ts +++ b/packages/metadata-protocol/src/protocol.runtime-authoring-gate.test.ts @@ -410,7 +410,7 @@ describe('runtime authoring gate on saveMetaItem (#4463)', () => { name: 'leave_request', label: 'Leave Request', sharingModel: 'private', - fields: { owner: { type: 'text', label: 'Owner' } }, + fields: { owner: { type: 'text', label: 'Owner Name' } }, }, }); expect(result.success).toBe(true); @@ -700,7 +700,7 @@ describe('runtime authoring gate on OBJECT writes (#4716)', () => { label: 'Task', sharingModel: 'private', fields: { - owner: { type: 'text', label: 'Owner' }, + owner: { type: 'text', label: 'Owner Name' }, task_no: { type: 'autonumber', label: 'Task No', autonumberFormat: '{plan_no}{000}' }, }, }); @@ -711,7 +711,7 @@ describe('runtime authoring gate on OBJECT writes (#4716)', () => { label: 'Task', sharingModel: 'private', fields: { - owner: { type: 'text', label: 'Owner' }, + owner: { type: 'text', label: 'Owner Name' }, }, }); @@ -788,7 +788,7 @@ describe('runtime authoring gate on OBJECT writes (#4716)', () => { // rule objects to would pin nothing… const body = { ...cleanTaskObject(), - fields: { owner: { type: 'text', label: 'Owner', group: 'main_info' } }, + fields: { owner: { type: 'text', label: 'Owner Name', group: 'main_info' } }, }; const wouldFire = validateSemanticRoles({ objects: [body] }); expect( diff --git a/packages/metadata-protocol/src/protocol.unknown-picklist-binding-refusal.test.ts b/packages/metadata-protocol/src/protocol.unknown-picklist-binding-refusal.test.ts index 3f7e7664514..f1d3e12c227 100644 --- a/packages/metadata-protocol/src/protocol.unknown-picklist-binding-refusal.test.ts +++ b/packages/metadata-protocol/src/protocol.unknown-picklist-binding-refusal.test.ts @@ -184,7 +184,7 @@ const object = (name: string, bindings: Array<[string, string]>, extra: Record [field, { type: 'select', label: 'Tier', picklist }])), + ...Object.fromEntries(bindings.map(([field, picklist]) => [field, { type: 'select', label: `Tier (${field})`, picklist }])), }, ...extra, });