From dbad3faa19c3250975822fc331953c9a58a2bbeb Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 14:39:26 +0000 Subject: [PATCH 1/4] fix(lint)!: refuse a _relatedLists key over a list the .custom arrangement hides or re-states without a label Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01L6bhgUpnvPnJ1hR74pUrVj --- ...6595-related-list-key-under-arrangement.md | 22 ++++ .../docs/protocol/kernel/i18n-standard.mdx | 2 +- ...8n-related-lists-arrangement-36595.test.ts | 101 ++++++++++++++++++ packages/lint/src/object-graph.ts | 12 +++ .../src/validate-translation-references.ts | 50 ++++++--- 5 files changed, 173 insertions(+), 14 deletions(-) create mode 100644 .changeset/36595-related-list-key-under-arrangement.md create mode 100644 packages/lint/src/i18n-related-lists-arrangement-36595.test.ts diff --git a/.changeset/36595-related-list-key-under-arrangement.md b/.changeset/36595-related-list-key-under-arrangement.md new file mode 100644 index 00000000000..cff64e0e772 --- /dev/null +++ b/.changeset/36595-related-list-key-under-arrangement.md @@ -0,0 +1,22 @@ +--- +'@objectstack/lint': minor +--- + +fix(lint)!: a `_relatedLists` translation key over a list the `.custom` arrangement hides or re-states without a label is refused, as nothing reads it + +Clause-②: no (narrowing) +Metadata-protocol: narrowed + + + +**BREAKING** for a translation bundle that carries `objects.._relatedLists.` over a list the object's owner labels but the paired `.custom` package's `relatedLists` (ADR-0146 D10) re-states. `objectstack validate` and the other doors that run `translation-target-unknown` now report such a key as an error, where 18.x accepted it. Drop the key, or give the arrangement's entry a `label` (`{ list, label }`) and keep it. + +**Why.** The registry applies the `.custom` arrangement after the owner's tab list and every `place` entry, and each arrangement entry replaces every entry it covers: the same list, or, for a bare child name, every list of that child (`relatedListNameCovers`). An entry `{ list, hidden: true }` leaves no tab, and a bare name or an entry with no `label` leaves the tab titled by the child lookup field's `relatedListTitle`. In both cases the served object has no `label` on that list for the key to translate. The rule judged the owner's label first and accepted the key before it looked at the arrangement, and it never saw the arrangement's bare names. + +**What changes in `@objectstack/lint`.** + +- The rule folds the arrangement's entries after the owner's entries and every placement, as the registry does. A list the arrangement labels resolves. A list it hides, names bare or names without a label does not resolve, whatever label the owner or a placement gave it. Lists the arrangement does not cover keep what they had. +- A key over a list the arrangement hides gets the "hidden by the `.custom` arrangement" message, now also when a bare child name such as `{ list: 'event', hidden: true }` hides a dotted list such as `event.related_to`. +- `VisibleObjectExtension` (`object-graph.ts`, internal) carries the extension's `relatedLists` as written, bare names included, as `relatedListArrangement`. + +Measured first-party exposure: none. No example or first-party package ships a `.custom` arrangement that re-states an owner-labelled list together with a key for it. diff --git a/content/docs/protocol/kernel/i18n-standard.mdx b/content/docs/protocol/kernel/i18n-standard.mdx index ba8b38db68f..b2a1b339cd9 100644 --- a/content/docs/protocol/kernel/i18n-standard.mdx +++ b/content/docs/protocol/kernel/i18n-standard.mdx @@ -1174,7 +1174,7 @@ beneath an action entry are judged the same way under either. | `objects.{object}._views.{view}` | the key the view registry assigns a view over that object: a `listViews` / `formViews` map key, or the default `list`'s `name` — `default` when it has none (see [ObjectUI Integration](#objectui-integration)) | | `objects.{object}._sections.{section}` | a `fieldGroups[].key`, a named section of a form view over that object (a `formViews` entry or the default `form`), or a named section of a `record:details` component on a page bound to it | | `objects.{object}._tabs.{tab}` | a filter-preset tab's `name` in `interfaceConfig.userFilters.tabs` on a page over that object (`interfaceConfig.source`, else the page's `object`) — a list view's own `tabs` has no renderer and is not resolvable | -| `objects.{object}._relatedLists.{list}` | the `list` of an object-form `relatedLists` entry on that object that authors a `label` — a dotted `object.field` is one key; a key over an entry with no `label`, a bare-string entry or a built-in tab is an orphan, because that tab's title is the child lookup field's `relatedListTitle`, translated on the child | +| `objects.{object}._relatedLists.{list}` | the `list` of an object-form `relatedLists` entry on that object that authors a `label` — a dotted `object.field` is one key; a key over an entry with no `label`, a bare-string entry or a built-in tab is an orphan, because that tab's title is the child lookup field's `relatedListTitle`, translated on the child. The paired `.custom` arrangement's `relatedLists` is applied after the owner's list and every placement: a list it hides, names bare or names without a `label` is an orphan whatever label the owner gave it, and a list it labels resolves | | `objects.{object}._validations.{rule}` | a validation rule's `name` in that object's `validations[]` or in an `objectExtensions[]` entry aimed at it — a `conditional` rule's `then` / `otherwise` branch included | | `objects.{object}._actions.{action}` | an action bound to that object: one in its `actions`, or a stack-level action whose `objectName` is that object | | `globalActions.{action}` | an action with **no** `objectName` — a key naming a bound action is an error whose message names the `objects.{owner}._actions.{action}` key to write instead, `{owner}` being the action's own `objectName` | diff --git a/packages/lint/src/i18n-related-lists-arrangement-36595.test.ts b/packages/lint/src/i18n-related-lists-arrangement-36595.test.ts new file mode 100644 index 00000000000..e67fde1dbb8 --- /dev/null +++ b/packages/lint/src/i18n-related-lists-arrangement-36595.test.ts @@ -0,0 +1,101 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. +// +// [#36595] `objects.._relatedLists.` against the paired `.custom` +// arrangement (ADR-0146 D10). The registry applies the arrangement after the +// owner's list and every placement, and each of its entries REPLACES every +// entry it covers (`registry-custom-arrangement.ts`): a bare name or an +// unlabelled entry leaves the tab no `label` to translate, and +// `{ list, hidden: true }` leaves no tab at all. A key over a list the owner +// labelled but the arrangement re-states that way is read by nothing, and the +// translation-reference rule says so. + +import { describe, it, expect } from 'vitest'; +import { validateTranslationReferences, TRANSLATION_TARGET_UNKNOWN } from './validate-translation-references.js'; + +const ACCOUNT = { + name: 'account', + label: 'Account', + fields: { name: { name: 'name', type: 'text', label: 'Name' } }, + relatedLists: [ + { list: 'contact', label: 'People' }, + { list: 'event.related_to', label: 'Meetings' }, + 'case', + ], +}; + +const KEY = (list: string) => + `translations[0]["zh-CN"].objects.account._relatedLists${list.includes('.') ? `["${list}"]` : `.${list}`}`; + +function judge(objectExtensions: unknown[], keys: Record) { + return validateTranslationReferences({ + objects: [ACCOUNT], + objectExtensions, + translations: [{ 'zh-CN': { objects: { account: { _relatedLists: keys } } } }], + }); +} + +describe('validateTranslationReferences — _relatedLists under a `.custom` arrangement (#36595)', () => { + it('flags a key over an owner-labelled list the arrangement hides, saying it is hidden', () => { + const findings = judge( + [{ extend: 'account', relatedLists: [{ list: 'contact', hidden: true }] }], + { contact: { label: '联系人' } }, + ); + expect(findings.map((f) => [f.rule, f.severity, f.path])).toEqual([[TRANSLATION_TARGET_UNKNOWN, 'error', KEY('contact')]]); + expect(findings[0].message).toContain('hidden'); + expect(findings[0].message.length).toBeLessThanOrEqual(200); + }); + + it('flags a key over an owner-labelled list the arrangement names bare, or as an entry with no label', () => { + for (const restated of ['contact', { list: 'contact' }, { list: 'contact', hidden: false }]) { + const findings = judge([{ extend: 'account', relatedLists: [restated] }], { contact: { label: '联系人' } }); + expect(findings.map((f) => f.path), JSON.stringify(restated)).toEqual([KEY('contact')]); + expect(findings[0].message, JSON.stringify(restated)).toContain('carries no `label`'); + } + }); + + it('a bare child hides or strips every list of that child: the dotted owner entry included', () => { + const hidden = judge( + [{ extend: 'account', relatedLists: [{ list: 'event', hidden: true }] }], + { 'event.related_to': { label: '会议' } }, + ); + expect(hidden.map((f) => f.path)).toEqual([KEY('event.related_to')]); + expect(hidden[0].message).toContain('hidden'); + const bare = judge([{ extend: 'account', relatedLists: ['event'] }], { 'event.related_to': { label: '会议' } }); + expect(bare.map((f) => f.path)).toEqual([KEY('event.related_to')]); + }); + + it('applies the arrangement after every placement, whatever the extensions\' order', () => { + // Two packages: the placing one folds AFTER the arrangement's (higher + // priority, later in the artifact), and the arrangement still replaces + // the placed entry, as the registry applies it. + const findings = validateTranslationReferences({ + packages: [ + { manifest: { id: 'com.example.crm.custom', objectExtensions: [{ extend: 'account', priority: 100, relatedLists: ['quote'] }] } }, + { manifest: { id: 'com.example.quotes', objectExtensions: [{ extend: 'account', priority: 300, place: [{ list: 'quote', after: 'contact', label: 'Quotes' }] }] } }, + ], + objects: [ACCOUNT], + translations: [{ 'zh-CN': { objects: { account: { _relatedLists: { quote: { label: '报价' } } } } } }], + }); + expect(findings.map((f) => f.path)).toEqual([KEY('quote')]); + }); + + it('accepts a key over a list the arrangement labels, and over owner lists it does not cover', () => { + expect(judge( + [{ extend: 'account', relatedLists: [{ list: 'contact', label: 'Clients' }, { list: 'event.owner_id', hidden: true }] }], + { contact: { label: '客户' }, 'event.related_to': { label: '会议' } }, + )).toEqual([]); + // One relationship does not cover its sibling or its bare child. + expect(judge( + [{ extend: 'account', relatedLists: ['event.owner_id', 'case'] }], + { contact: { label: '联系人' }, 'event.related_to': { label: '会议' } }, + )).toEqual([]); + }); + + it('control: with no arrangement, the owner\'s labels resolve as before', () => { + expect(judge([], { contact: { label: '联系人' }, 'event.related_to': { label: '会议' } })).toEqual([]); + expect(judge( + [{ extend: 'account', place: [{ list: 'quote', after: 'contact', label: 'Quotes' }] }], + { contact: { label: '联系人' }, quote: { label: '报价' } }, + )).toEqual([]); + }); +}); diff --git a/packages/lint/src/object-graph.ts b/packages/lint/src/object-graph.ts index 58b26d5577b..985cdbfe70f 100644 --- a/packages/lint/src/object-graph.ts +++ b/packages/lint/src/object-graph.ts @@ -418,6 +418,17 @@ export interface VisibleObjectExtension { * `validations`, carrying them changes nothing about which entries survive. */ relatedListEntries: AnyRec[]; + /** + * [#36595] Its `relatedLists` as written, bare names included (`undefined` + * when it writes none): the `.custom` arrangement (ADR-0146 D10). Where the + * key is written, each entry REPLACES every entry of the owner and of the + * placements that it covers (`relatedListNameCovers`), so a bare name or an + * unlabelled entry takes a title away and `{ list, hidden: true }` takes the + * tab away (`registry-custom-arrangement.ts`, `@objectstack/objectql`). The + * one reader that needs the bare names is the `_relatedLists.LIST` check of + * `validate-translation-references.ts`. + */ + relatedListArrangement?: unknown[]; /** * [#33494] Set on an entry the host's registry already holds * ({@link StoredObjectExtension}), folded in at its priority but never @@ -510,6 +521,7 @@ export function objectExtensionsByTarget( ...(Array.isArray(ext.relatedLists) ? ext.relatedLists : []), ...(Array.isArray(ext.place) ? ext.place : []), ].filter(isRec), + ...(Array.isArray(ext.relatedLists) ? { relatedListArrangement: ext.relatedLists } : {}), label: ext.label, fieldPatches: isRec(ext.fieldPatches) ? Object.fromEntries( diff --git a/packages/lint/src/validate-translation-references.ts b/packages/lint/src/validate-translation-references.ts index fb0fb0c3d6a..bcc4339f935 100644 --- a/packages/lint/src/validate-translation-references.ts +++ b/packages/lint/src/validate-translation-references.ts @@ -276,7 +276,7 @@ import { pageTabItemKey, walkAddressedPageComponents, } from '@objectstack/spec/system'; -import { isRecordPageBuiltinTab, relatedListEntryHidden } from '@objectstack/spec/data'; +import { isRecordPageBuiltinTab, relatedListEntryHidden, relatedListEntryName, relatedListNameCovers } from '@objectstack/spec/data'; import { walkFlowNodes } from './flow-walk.js'; import { objectExtensionsByTarget, packagesOf, recordsOf, suggestName } from './object-graph.js'; import { walkPageComponents } from './page-walk.js'; @@ -1424,25 +1424,49 @@ function buildUniverse(stack: AnyRec): Universe { const key = strName(group.key); if (key) facts.sections.add(key); } - // `_relatedLists.` is keyed by a labelled entry's `list`: a - // `.custom` arrangement's `relatedLists` entry (ADR-0146 D10) and a - // list placement's `place` entry each title a tab of the target, and - // where the target declares `relatedLists` the served target carries - // that entry, which `translateObject` translates as it does the - // target's own (a placed entry is part of the packaged base it is - // compared with, `getPackagedObjectBase`). A placement on a target - // that declares none is not applied, and its key is accepted here all - // the same: this fold does not read whether the target declares the - // list. An arrangement entry with `hidden: true` titles no tab. + // `_relatedLists.` is keyed by a labelled entry's `list`: a list + // placement's `place` entry titles a tab of the target, and where the + // target declares `relatedLists` the served target carries that entry, + // which `translateObject` translates as it does the target's own (a + // placed entry is part of the packaged base it is compared with, + // `getPackagedObjectBase`). A placement on a target that declares none + // is not applied, and its key is accepted here all the same: this fold + // does not read whether the target declares the list. The `.custom` + // arrangement's entries are folded after every placement, below. + const arranged = new Set(extension.relatedListArrangement ?? []); for (const entry of extension.relatedListEntries) { + if (arranged.has(entry)) continue; const list = strName(entry.list); if (!list) continue; facts.relatedListNames.add(list); + if (typeof entry.label === 'string' && entry.label.length > 0) facts.relatedListLabels.add(list); + } + } + // [#36595] The `.custom` arrangement (ADR-0146 D10) is applied after the + // owner's list and every placement, as the registry applies it + // (`registry-custom-arrangement.ts`): each of its entries REPLACES every + // entry it covers (`relatedListNameCovers`: the same list, or a bare child + // for each list of that child). So a labelled entry titles the tab, a + // bare name or an unlabelled entry leaves it the child FK's + // `relatedListTitle`, and `{ list, hidden: true }` leaves no tab, whatever + // label the owner or a placement gave the lists it covers. Lists it does + // not cover keep what they had. + for (const extension of extensions) { + for (const entry of extension.relatedListArrangement ?? []) { + const list = relatedListEntryName(entry); + if (!list) continue; + facts.relatedListNames.add(list); + for (const labelled of [...facts.relatedListLabels]) { + if (relatedListNameCovers(list, labelled)) facts.relatedListLabels.delete(labelled); + } if (relatedListEntryHidden(entry)) { facts.relatedListHidden.add(list); continue; } - if (typeof entry.label === 'string' && entry.label.length > 0) facts.relatedListLabels.add(list); + for (const hidden of [...facts.relatedListHidden]) { + if (relatedListNameCovers(list, hidden)) facts.relatedListHidden.delete(hidden); + } + if (isRec(entry) && typeof entry.label === 'string' && entry.label.length > 0) facts.relatedListLabels.add(list); } } } @@ -2156,7 +2180,7 @@ export function validateTranslationReferences(stack: AnyRec): TranslationRefFind `Drop this key: a built-in tab takes no \`label\` here.`); continue; } - if (facts.relatedListHidden.has(listName)) { + if ([...facts.relatedListHidden].some((hidden) => relatedListNameCovers(hidden, listName))) { orphan(listWhere, listPath, `Related list "${listName}" of object "${objectName}" is hidden by the \`.custom\` ` + `arrangement (\`hidden: true\`), so no tab shows a title from this key.`, From e978009608e0c8fecba7596f0d10ae08645a1357 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 14:43:24 +0000 Subject: [PATCH 2/4] chore(spec): register the ADR-0087 semantic entry for the _relatedLists key refusal Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01L6bhgUpnvPnJ1hR74pUrVj --- ...6595-related-list-key-under-arrangement.md | 2 +- ...ated-list-key-under-arrangement-refused.ts | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 packages/spec/src/migrations/entries/semantic/18.translation-related-list-key-under-arrangement-refused.ts diff --git a/.changeset/36595-related-list-key-under-arrangement.md b/.changeset/36595-related-list-key-under-arrangement.md index cff64e0e772..acba6598391 100644 --- a/.changeset/36595-related-list-key-under-arrangement.md +++ b/.changeset/36595-related-list-key-under-arrangement.md @@ -7,7 +7,7 @@ fix(lint)!: a `_relatedLists` translation key over a list the `.custom` arrangem Clause-②: no (narrowing) Metadata-protocol: narrowed - + **BREAKING** for a translation bundle that carries `objects.._relatedLists.` over a list the object's owner labels but the paired `.custom` package's `relatedLists` (ADR-0146 D10) re-states. `objectstack validate` and the other doors that run `translation-target-unknown` now report such a key as an error, where 18.x accepted it. Drop the key, or give the arrangement's entry a `label` (`{ list, label }`) and keep it. diff --git a/packages/spec/src/migrations/entries/semantic/18.translation-related-list-key-under-arrangement-refused.ts b/packages/spec/src/migrations/entries/semantic/18.translation-related-list-key-under-arrangement-refused.ts new file mode 100644 index 00000000000..14664e630e2 --- /dev/null +++ b/packages/spec/src/migrations/entries/semantic/18.translation-related-list-key-under-arrangement-refused.ts @@ -0,0 +1,34 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +import type { SemanticMigration } from '../../types.js'; + +// A translated record-page tab title is judged against the tab list as the +// registry serves it: the paired `.custom` arrangement replaces every entry it +// covers, after the owner's list and every placement. Semantic-only — whether +// a key the arrangement left with no label to translate should be dropped, or +// the arrangement's entry given a label, is the author's call, so no D2 +// conversion rewrites it. +export const entry: SemanticMigration = { + id: 'translation-related-list-key-under-arrangement-refused', + surface: + 'translation.objects.._relatedLists. — a translated record-page tab title, in a stack\'s ' + + 'translations, over a list the object\'s owner labels but the paired .custom package\'s relatedLists ' + + 're-states as { list, hidden: true }, as a bare name, or as an entry with no label (a bare child name ' + + 'such as event covers every list of that child, event.related_to included)', + replacement: + 'nothing, where the tab should stay hidden or keep the child lookup field\'s relatedListTitle: drop the key. ' + + 'Where the tab should keep a title of its own, give the .custom arrangement\'s entry a label ' + + '({ list, label }) and keep the key, which then translates that label.', + reason: + 'The registry applies the .custom arrangement (ADR-0146 D10) after the owner\'s tab list and every place ' + + 'entry, and each of its entries replaces every entry it covers. A hidden entry leaves no tab, and a bare or ' + + 'unlabelled one leaves the tab titled by the child\'s relatedListTitle, so the served object carries no ' + + 'label on that list and nothing reads the key. translation-target-unknown judged the owner\'s label first ' + + 'and accepted the key before it looked at the arrangement, and never saw the arrangement\'s bare names. It ' + + 'now folds the arrangement as the registry does and reports such a key as an error. No D2 conversion ' + + 'exists: only the author can say whether the tab was meant to lose its title or the arrangement to keep one.', + acceptanceCriteria: + 'Run objectstack validate: no translation-target-unknown finding names an objects._relatedLists key. For ' + + 'each key the finding named, either the key is gone, or the .custom arrangement\'s entry for that list ' + + 'carries a label and the record page shows the translated title in that locale.', +}; From 61beb993c3a932e9df8af98a079b415fc5a03c10 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 14:44:02 +0000 Subject: [PATCH 3/4] chore(changeset): bump spec for the ledger entry Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01L6bhgUpnvPnJ1hR74pUrVj --- .changeset/36595-related-list-key-under-arrangement.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.changeset/36595-related-list-key-under-arrangement.md b/.changeset/36595-related-list-key-under-arrangement.md index acba6598391..1a083d33cb5 100644 --- a/.changeset/36595-related-list-key-under-arrangement.md +++ b/.changeset/36595-related-list-key-under-arrangement.md @@ -1,5 +1,6 @@ --- '@objectstack/lint': minor +'@objectstack/spec': patch --- fix(lint)!: a `_relatedLists` translation key over a list the `.custom` arrangement hides or re-states without a label is refused, as nothing reads it From b18f2ca55b4d35252852aaf90aa2751dc32d5f06 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 15:53:11 +0000 Subject: [PATCH 4/4] fix(lint): read a .custom arrangement in two passes; register the narrowing at step 19 Contract review on the #36595 change: - The migration entry moves to step 19 (PROTOCOL_VERSION is 19.0.0), so `migrate meta --from 18` lists it. - Each arrangement strips what it covers from the owner's list and the placements first, then adds its own labels and hidden entries, as the registry reads it: one entry never strips a sibling's label. - A key over an owner-labelled list the arrangement re-states without a label names the arrangement, and its hint points at the owner's label. - The remedy text names the owner's own label: an object read translates a label only while it equals the packaged one. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01L6bhgUpnvPnJ1hR74pUrVj --- ...6595-related-list-key-under-arrangement.md | 7 +-- ...8n-related-lists-arrangement-36595.test.ts | 18 +++++++- .../src/validate-translation-references.ts | 44 ++++++++++++++----- ...ted-list-key-under-arrangement-refused.ts} | 10 +++-- 4 files changed, 61 insertions(+), 18 deletions(-) rename packages/spec/src/migrations/entries/semantic/{18.translation-related-list-key-under-arrangement-refused.ts => 19.translation-related-list-key-under-arrangement-refused.ts} (82%) diff --git a/.changeset/36595-related-list-key-under-arrangement.md b/.changeset/36595-related-list-key-under-arrangement.md index 1a083d33cb5..e301b25fc9c 100644 --- a/.changeset/36595-related-list-key-under-arrangement.md +++ b/.changeset/36595-related-list-key-under-arrangement.md @@ -7,17 +7,18 @@ fix(lint)!: a `_relatedLists` translation key over a list the `.custom` arrangem Clause-②: no (narrowing) Metadata-protocol: narrowed +Skills-docs: follow-up #37620 -**BREAKING** for a translation bundle that carries `objects.._relatedLists.` over a list the object's owner labels but the paired `.custom` package's `relatedLists` (ADR-0146 D10) re-states. `objectstack validate` and the other doors that run `translation-target-unknown` now report such a key as an error, where 18.x accepted it. Drop the key, or give the arrangement's entry a `label` (`{ list, label }`) and keep it. +**BREAKING** for a translation bundle that carries `objects.._relatedLists.` over a list the object's owner labels but the paired `.custom` package's `relatedLists` (ADR-0146 D10) re-states. `objectstack validate` and the other doors that run `translation-target-unknown` now report such a key as an error, where 18.x accepted it. Drop the key, or re-state the arrangement's entry with the owner's own `label` (`{ list, label }`) and keep it: an object read translates a label only while it still equals the packaged one. **Why.** The registry applies the `.custom` arrangement after the owner's tab list and every `place` entry, and each arrangement entry replaces every entry it covers: the same list, or, for a bare child name, every list of that child (`relatedListNameCovers`). An entry `{ list, hidden: true }` leaves no tab, and a bare name or an entry with no `label` leaves the tab titled by the child lookup field's `relatedListTitle`. In both cases the served object has no `label` on that list for the key to translate. The rule judged the owner's label first and accepted the key before it looked at the arrangement, and it never saw the arrangement's bare names. **What changes in `@objectstack/lint`.** -- The rule folds the arrangement's entries after the owner's entries and every placement, as the registry does. A list the arrangement labels resolves. A list it hides, names bare or names without a label does not resolve, whatever label the owner or a placement gave it. Lists the arrangement does not cover keep what they had. -- A key over a list the arrangement hides gets the "hidden by the `.custom` arrangement" message, now also when a bare child name such as `{ list: 'event', hidden: true }` hides a dotted list such as `event.related_to`. +- The rule folds the arrangement's entries after the owner's entries and every placement, as the registry does. A list the arrangement labels resolves. A list it hides, names bare or names without a label does not resolve, whatever label the owner or a placement gave it; a labelled bare child such as `{ list: 'event', label }` covers the owner's `event.related_to` too. Lists the arrangement does not cover keep what they had. Each arrangement is read in two passes, as the registry reads it, so one entry never strips the label a sibling entry of the same arrangement gives (`[{ list: 'event.related_to', label }, 'event']` resolves in either order). +- A key over a list the arrangement hides gets the "hidden by the `.custom` arrangement" message, now also when a bare child name such as `{ list: 'event', hidden: true }` hides a dotted list such as `event.related_to`. A key over an owner-labelled list the arrangement re-states without a label names the arrangement too, and its hint points at the owner's `label`. - `VisibleObjectExtension` (`object-graph.ts`, internal) carries the extension's `relatedLists` as written, bare names included, as `relatedListArrangement`. Measured first-party exposure: none. No example or first-party package ships a `.custom` arrangement that re-states an owner-labelled list together with a key for it. diff --git a/packages/lint/src/i18n-related-lists-arrangement-36595.test.ts b/packages/lint/src/i18n-related-lists-arrangement-36595.test.ts index e67fde1dbb8..1bf426517c1 100644 --- a/packages/lint/src/i18n-related-lists-arrangement-36595.test.ts +++ b/packages/lint/src/i18n-related-lists-arrangement-36595.test.ts @@ -49,7 +49,10 @@ describe('validateTranslationReferences — _relatedLists under a `.custom` arra for (const restated of ['contact', { list: 'contact' }, { list: 'contact', hidden: false }]) { const findings = judge([{ extend: 'account', relatedLists: [restated] }], { contact: { label: '联系人' } }); expect(findings.map((f) => f.path), JSON.stringify(restated)).toEqual([KEY('contact')]); - expect(findings[0].message, JSON.stringify(restated)).toContain('carries no `label`'); + expect(findings[0].message, JSON.stringify(restated)).toContain('carries no `label` in the `.custom` arrangement'); + expect(findings[0].hint, JSON.stringify(restated)).toContain("owner's `label`"); + expect(findings[0].message.length).toBeLessThanOrEqual(200); + expect(findings[0].hint.length).toBeLessThanOrEqual(200); } }); @@ -64,6 +67,19 @@ describe('validateTranslationReferences — _relatedLists under a `.custom` arra expect(bare.map((f) => f.path)).toEqual([KEY('event.related_to')]); }); + it('one arrangement entry never strips what a sibling entry of the same arrangement wrote, in either order', () => { + // The registry collects the arrangement's entries first, then drops what + // they cover from the owner's list: a bare child beside its labelled + // dotted list leaves that label served. + for (const arrangement of [[{ list: 'event.related_to', label: 'Meetings' }, 'event'], ['event', { list: 'event.related_to', label: 'Meetings' }]]) { + expect(judge([{ extend: 'account', relatedLists: arrangement }], { 'event.related_to': { label: '会议' } }), JSON.stringify(arrangement)) + .toEqual([]); + } + // A sibling that would cancel a `hidden` entry is a list both shown and + // hidden in one arrangement, which the object schema refuses at save + // (`refuseContradictoryRelatedListEntries`), so it has no pin here. + }); + it('applies the arrangement after every placement, whatever the extensions\' order', () => { // Two packages: the placing one folds AFTER the arrangement's (higher // priority, later in the artifact), and the arrangement still replaces diff --git a/packages/lint/src/validate-translation-references.ts b/packages/lint/src/validate-translation-references.ts index bcc4339f935..7f041b70cbd 100644 --- a/packages/lint/src/validate-translation-references.ts +++ b/packages/lint/src/validate-translation-references.ts @@ -501,6 +501,12 @@ interface ObjectFacts { * only to say so. */ relatedListHidden: Set; + /** + * The lists whose label (from the owner or a placement) a `.custom` + * arrangement entry replaced with none: the tab shows, untitled by any + * `label` — read only to name the arrangement in the finding. + */ + relatedListStripped: Set; } /** Everything a `flows..screens.` key may legally name. */ @@ -671,6 +677,7 @@ function emptyFacts(): ObjectFacts { relatedListLabels: new Set(), relatedListNames: new Set(), relatedListHidden: new Set(), + relatedListStripped: new Set(), }; } @@ -1451,22 +1458,32 @@ function buildUniverse(stack: AnyRec): Universe { // `relatedListTitle`, and `{ list, hidden: true }` leaves no tab, whatever // label the owner or a placement gave the lists it covers. Lists it does // not cover keep what they had. + // + // Two passes per arrangement, as the registry reads one: it collects the + // arrangement's entries first and only then drops what they cover from the + // tab list steps 1–2 gave, so one entry never strips a label or a `hidden` + // a sibling entry of the SAME arrangement wrote, in either order. for (const extension of extensions) { - for (const entry of extension.relatedListArrangement ?? []) { - const list = relatedListEntryName(entry); - if (!list) continue; + const arrangement = (extension.relatedListArrangement ?? []) + .map((entry) => ({ entry, list: relatedListEntryName(entry) })) + .filter((e): e is { entry: unknown; list: string } => typeof e.list === 'string' && e.list !== ''); + for (const { list } of arrangement) { facts.relatedListNames.add(list); for (const labelled of [...facts.relatedListLabels]) { - if (relatedListNameCovers(list, labelled)) facts.relatedListLabels.delete(labelled); - } - if (relatedListEntryHidden(entry)) { - facts.relatedListHidden.add(list); - continue; + if (!relatedListNameCovers(list, labelled)) continue; + facts.relatedListLabels.delete(labelled); + facts.relatedListStripped.add(labelled); } for (const hidden of [...facts.relatedListHidden]) { if (relatedListNameCovers(list, hidden)) facts.relatedListHidden.delete(hidden); } - if (isRec(entry) && typeof entry.label === 'string' && entry.label.length > 0) facts.relatedListLabels.add(list); + } + for (const { entry, list } of arrangement) { + if (relatedListEntryHidden(entry)) facts.relatedListHidden.add(list); + else if (isRec(entry) && typeof entry.label === 'string' && entry.label.length > 0) { + facts.relatedListLabels.add(list); + facts.relatedListStripped.delete(list); + } } } } @@ -2184,7 +2201,14 @@ export function validateTranslationReferences(stack: AnyRec): TranslationRefFind orphan(listWhere, listPath, `Related list "${listName}" of object "${objectName}" is hidden by the \`.custom\` ` + `arrangement (\`hidden: true\`), so no tab shows a title from this key.`, - `Drop this key, or show the tab (drop \`hidden\`) and give the entry a \`label\`.`); + `Drop this key, or show the tab (drop \`hidden\`) with the owner's \`label\` on the entry.`); + continue; + } + if (facts.relatedListStripped.has(listName)) { + orphan(listWhere, listPath, + `Related list "${listName}" of object "${objectName}" carries no \`label\` in the \`.custom\` ` + + `arrangement, which replaces the owner's entry, so no title reads this key.`, + `Drop this key, or re-state the arrangement's entry with the owner's \`label\` ({ list, label }).`); continue; } const named = facts.relatedListNames.has(listName); diff --git a/packages/spec/src/migrations/entries/semantic/18.translation-related-list-key-under-arrangement-refused.ts b/packages/spec/src/migrations/entries/semantic/19.translation-related-list-key-under-arrangement-refused.ts similarity index 82% rename from packages/spec/src/migrations/entries/semantic/18.translation-related-list-key-under-arrangement-refused.ts rename to packages/spec/src/migrations/entries/semantic/19.translation-related-list-key-under-arrangement-refused.ts index 14664e630e2..a89a72f365f 100644 --- a/packages/spec/src/migrations/entries/semantic/18.translation-related-list-key-under-arrangement-refused.ts +++ b/packages/spec/src/migrations/entries/semantic/19.translation-related-list-key-under-arrangement-refused.ts @@ -14,11 +14,13 @@ export const entry: SemanticMigration = { 'translation.objects.._relatedLists. — a translated record-page tab title, in a stack\'s ' + 'translations, over a list the object\'s owner labels but the paired .custom package\'s relatedLists ' + 're-states as { list, hidden: true }, as a bare name, or as an entry with no label (a bare child name ' - + 'such as event covers every list of that child, event.related_to included)', + + 'such as event covers every list of that child, event.related_to included, so a labelled { list: event, ' + + 'label } also leaves the owner\'s event.related_to with no label)', replacement: 'nothing, where the tab should stay hidden or keep the child lookup field\'s relatedListTitle: drop the key. ' - + 'Where the tab should keep a title of its own, give the .custom arrangement\'s entry a label ' - + '({ list, label }) and keep the key, which then translates that label.', + + 'Where the tab should keep the owner\'s translated title, re-state the .custom arrangement\'s entry with the ' + + 'owner\'s own label ({ list, label }) and keep the key: an object read translates a label only while it still ' + + 'equals the packaged one.', reason: 'The registry applies the .custom arrangement (ADR-0146 D10) after the owner\'s tab list and every place ' + 'entry, and each of its entries replaces every entry it covers. A hidden entry leaves no tab, and a bare or ' @@ -30,5 +32,5 @@ export const entry: SemanticMigration = { acceptanceCriteria: 'Run objectstack validate: no translation-target-unknown finding names an objects._relatedLists key. For ' + 'each key the finding named, either the key is gone, or the .custom arrangement\'s entry for that list ' - + 'carries a label and the record page shows the translated title in that locale.', + + 'carries the owner\'s label and the record page shows the translated title in that locale.', };