From 88db62ecc1887f62e08ae27fb3b6d5706f9dd256 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 01:28:20 +0000 Subject: [PATCH 1/7] fix(lint): i18n extract/check fold the .custom related-list arrangement the way os validate does Claude-Session: https://claude.ai/code/session_01L9qibw44Q7BwdAY1RmfR73 Co-authored-by: Claude --- ...8n-related-lists-arrangement-36595.test.ts | 74 ++++++++- packages/lint/src/i18n-walk.ts | 59 ++++--- packages/lint/src/object-graph.ts | 121 ++++++++++++++- .../src/validate-translation-references.ts | 146 ++++++------------ 4 files changed, 279 insertions(+), 121 deletions(-) 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 1bf426517c1..d4c88acf8b8 100644 --- a/packages/lint/src/i18n-related-lists-arrangement-36595.test.ts +++ b/packages/lint/src/i18n-related-lists-arrangement-36595.test.ts @@ -11,6 +11,7 @@ import { describe, it, expect } from 'vitest'; import { validateTranslationReferences, TRANSLATION_TARGET_UNKNOWN } from './validate-translation-references.js'; +import { collectExpectedEntries } from './i18n-walk.js'; const ACCOUNT = { name: 'account', @@ -50,7 +51,7 @@ describe('validateTranslationReferences — _relatedLists under a `.custom` arra 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` in the `.custom` arrangement'); - expect(findings[0].hint, JSON.stringify(restated)).toContain("owner's `label`"); + expect(findings[0].hint, JSON.stringify(restated)).toContain("{ list: 'contact', label }"); expect(findings[0].message.length).toBeLessThanOrEqual(200); expect(findings[0].hint.length).toBeLessThanOrEqual(200); } @@ -75,9 +76,22 @@ describe('validateTranslationReferences — _relatedLists under a `.custom` arra 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('a dotted list one entry hides stays hidden beside the bare child a sibling entry names (#37622)', () => { + // The object schema refuses a cancelling sibling only when both entries + // name the SAME list (`refuseContradictoryRelatedListEntries`), so this + // shape parses: the bare child drops the dotted list's label in the first + // pass, and the hidden entry hides it in the second, in either order. + for (const arrangement of [ + [{ list: 'event.related_to', hidden: true }, 'event'], + ['event', { list: 'event.related_to', hidden: true }], + ]) { + const findings = judge([{ extend: 'account', relatedLists: arrangement }], { 'event.related_to': { label: '会议' } }); + expect(findings.map((f) => [f.severity, f.path]), JSON.stringify(arrangement)).toEqual([['error', KEY('event.related_to')]]); + expect(findings[0].message, JSON.stringify(arrangement)).toContain('hidden'); + expect(findings[0].hint, JSON.stringify(arrangement)).toContain("{ list: 'event.related_to', label }"); + } }); it('applies the arrangement after every placement, whatever the extensions\' order', () => { @@ -115,3 +129,55 @@ describe('validateTranslationReferences — _relatedLists under a `.custom` arra )).toEqual([]); }); }); + +// [#37622] `os i18n extract` and `os i18n check` read the expected keys from +// `collectExpectedEntries`, which folds the owner's tab list with the same +// arrangement the rule above folds: every key the extractor scaffolds is one +// `os validate` accepts, and a list the arrangement labels is scaffolded. +describe('collectExpectedEntries — _relatedLists agree with the rule under a `.custom` arrangement (#37622)', () => { + const expected = (objectExtensions: unknown[]) => + collectExpectedEntries({ objects: [ACCOUNT], objectExtensions } as never) + .filter((entry) => entry.path[2] === '_relatedLists') + .map((entry) => [entry.path[3], entry.sourceValue]); + + /** The keys the extractor scaffolds, translated, judged by the rule. */ + const scaffoldedJudged = (objectExtensions: unknown[]) => { + const keys = Object.fromEntries(expected(objectExtensions).map(([list]) => [list, { label: '译文' }])); + return judge(objectExtensions, keys); + }; + + const ARRANGEMENTS: Array<[string, unknown[]]> = [ + ['none', []], + ['hides contact', [{ extend: 'account', relatedLists: [{ list: 'contact', hidden: true }] }]], + ['names contact bare', [{ extend: 'account', relatedLists: ['contact'] }]], + ['re-states contact with no label', [{ extend: 'account', relatedLists: [{ list: 'contact' }] }]], + ['relabels contact', [{ extend: 'account', relatedLists: [{ list: 'contact', label: 'Clients' }] }]], + ['labels a list the owner names bare', [{ extend: 'account', relatedLists: [{ list: 'case', label: 'Tickets' }] }]], + ['hides every event list through the bare child', [{ extend: 'account', relatedLists: [{ list: 'event', hidden: true }] }]], + ['labels the bare child', [{ extend: 'account', relatedLists: [{ list: 'event', label: 'Activity' }] }]], + ['keeps the dotted label beside the bare child', [{ extend: 'account', relatedLists: ['event', { list: 'event.related_to', label: 'Meetings' }] }]], + ]; + + it('every scaffolded key is accepted by `os validate`, for every arrangement', () => { + for (const [name, objectExtensions] of ARRANGEMENTS) { + expect(scaffoldedJudged(objectExtensions), name).toEqual([]); + } + }); + + it('scaffolds the tab titles the served object carries, with the text it serves', () => { + expect(expected([])).toEqual([['contact', 'People'], ['event.related_to', 'Meetings']]); + expect(expected(ARRANGEMENTS[1][1])).toEqual([['event.related_to', 'Meetings']]); + expect(expected(ARRANGEMENTS[2][1])).toEqual([['event.related_to', 'Meetings']]); + expect(expected(ARRANGEMENTS[4][1])).toEqual([['event.related_to', 'Meetings'], ['contact', 'Clients']]); + expect(expected(ARRANGEMENTS[5][1])).toEqual([['contact', 'People'], ['event.related_to', 'Meetings'], ['case', 'Tickets']]); + expect(expected(ARRANGEMENTS[6][1])).toEqual([['contact', 'People']]); + expect(expected(ARRANGEMENTS[7][1])).toEqual([['contact', 'People'], ['event', 'Activity']]); + expect(expected(ARRANGEMENTS[8][1])).toEqual([['contact', 'People'], ['event.related_to', 'Meetings']]); + }); + + it('asks for no title a code extender\'s placement alone gives, which the rule still accepts', () => { + const placed = [{ extend: 'account', place: [{ list: 'quote', after: 'contact', label: 'Quotes' }] }]; + expect(expected(placed)).toEqual([['contact', 'People'], ['event.related_to', 'Meetings']]); + expect(judge(placed, { quote: { label: '报价' } })).toEqual([]); + }); +}); diff --git a/packages/lint/src/i18n-walk.ts b/packages/lint/src/i18n-walk.ts index a2607c28043..cf0f603f6e5 100644 --- a/packages/lint/src/i18n-walk.ts +++ b/packages/lint/src/i18n-walk.ts @@ -87,8 +87,12 @@ * objects.._validations..message * objects.._milestones...summary (an `activityMilestones` * entry's summary template) - * objects.._relatedLists..label (an object-form `relatedLists` - * entry that authors a `label`) + * objects.._relatedLists..label (a record-page tab the served + * object titles: an owner entry + * that authors a `label`, as the + * `.custom` arrangement leaves + * it, or an arrangement entry + * that authors one) * objects.._actions..label * objects.._actions..description * objects.._actions..confirmText @@ -202,6 +206,7 @@ import { APPROVAL_NODE_TYPE, flowDecisionEdgeBranch, isFlowTechnicalNodeType } f import { expandViewContainer, InlineLocaleMapSchema } from '@objectstack/spec/ui'; import { authorWarnedProperties } from './lint-liveness-properties.js'; import { walkPageComponents } from './page-walk.js'; +import { addOwnerRelatedLists, emptyRelatedListTitles, foldRelatedListExtensions, objectExtensionsByTarget } from './object-graph.js'; // ─── Public types ────────────────────────────────────────────────────── @@ -1047,23 +1052,34 @@ function pushMilestoneSummaries(out: ExpectedEntry[], objectName: string, milest } /** - * Emit `objects.._relatedLists..label` for every object-form - * `relatedLists` entry of an object that authors a `label` (the record page's - * tab title and table heading for that list, which wins over the child FK's - * `relatedListTitle`). The key is the entry's literal `list`, a dotted - * `object.field` included, indexed as is. Only an AUTHORED label is emitted: - * `translateObject` translates that label and swaps nothing in for an entry - * that has none, so a key for one would ask a translator for a string no - * screen shows. + * Emit `objects.._relatedLists..label` for every record-page + * tab the SERVED object titles with a `label` (the tab title and table heading + * for that list, which wins over the child FK's `relatedListTitle`). The key + * is the entry's literal `list`, a dotted `object.field` included, indexed as + * is. Only an AUTHORED label is emitted: `translateObject` translates that + * label and swaps nothing in for an entry that has none, so a key for one + * would ask a translator for a string no screen shows. + * + * [#37622] The owner's entries are folded with the extensions of this stack + * that target the object ({@link foldRelatedListExtensions}, the fold the + * `translation-target-unknown` rule of `os validate` reads), so a list the + * paired `.custom` arrangement hides, names bare or re-states without a + * `label` gets no key, and a list the arrangement labels gets one, carrying + * the arrangement's text. A label only a code extender's `place` entry gives + * is not emitted: the rule accepts its key, but the registry may not apply the + * placement, so asking for it could ask for a string no screen shows. */ -function pushRelatedListLabels(out: ExpectedEntry[], objectName: string, entries: unknown): void { - if (!Array.isArray(entries)) return; - for (const entry of entries) { - if (!entry || typeof entry !== 'object' || Array.isArray(entry)) continue; - const list = (entry as any).list; - if (typeof list !== 'string' || list.length === 0) continue; - const label = (entry as any).label; - if (typeof label !== 'string' || label.length === 0) continue; +function pushRelatedListLabels( + out: ExpectedEntry[], + objectName: string, + entries: unknown, + extensions: Parameters[1], +): void { + const titles = emptyRelatedListTitles(); + addOwnerRelatedLists(titles, entries); + foldRelatedListExtensions(titles, extensions); + for (const [list, { label, layer }] of titles.labels) { + if (layer === 'place') continue; pushEntry(out, ['objects', objectName, '_relatedLists', list, 'label'], label, 'object', { objectName }); } } @@ -1580,6 +1596,8 @@ export function collectExpectedEntries( // ── Objects ─────────────────────────────────────────────────────── const objects: any[] = Array.isArray(config?.objects) ? config.objects : []; + // [#37622] The extensions each object's served tab list folds in, read once. + const extensionsByTarget = objectExtensionsByTarget(config); for (const obj of objects) { if (!obj?.name) continue; const objectName = obj.name as string; @@ -1710,11 +1728,12 @@ export function collectExpectedEntries( // Record-page related-list titles (`_relatedLists..label`): the // `label` an object-form `relatedLists` entry authors on this parent, - // keyed by the entry's literal `list` (`object.field` is one key). + // keyed by the entry's literal `list` (`object.field` is one key), after + // the paired `.custom` arrangement this stack carries is folded in. // `translateObject` overlays only an authored label, so an entry without // one — and a bare-string entry or built-in tab — gets no key: its title // is the child FK's `relatedListTitle`, keyed on the child above. - pushRelatedListLabels(out, objectName, obj.relatedLists); + pushRelatedListLabels(out, objectName, obj.relatedLists, extensionsByTarget.get(objectName) ?? []); } // ── Top-level views ────────────────────────────────────────────── diff --git a/packages/lint/src/object-graph.ts b/packages/lint/src/object-graph.ts index 985cdbfe70f..7ad1f50993e 100644 --- a/packages/lint/src/object-graph.ts +++ b/packages/lint/src/object-graph.ts @@ -68,7 +68,7 @@ * second question about it is still unanswered — truthfully, and only there. */ -import { referenceTargetOf } from '@objectstack/spec/data'; +import { referenceTargetOf, relatedListEntryHidden, relatedListEntryName, relatedListNameCovers } from '@objectstack/spec/data'; import { injectedColumnDefsFor, injectedColumnsFor } from './system-fields.js'; @@ -550,6 +550,125 @@ export function objectExtensionsByTarget( return byTarget; } +/** + * [#37622] The record-page tab titles of one object, as the registry serves + * them: which `_relatedLists.LIST.label` keys a translation can address. + * + * - `labels`: each list that is served with a `label`, the label it is served + * with, and the layer that wrote it — the owner's `relatedLists`, a code + * extender's `place` entry, or the paired `.custom` arrangement + * (`objectExtensions[].relatedLists`, ADR-0146 D10). + * - `names`: every list any layer names, labelled or not. + * - `hidden`: the lists an arrangement hides (`{ list, hidden: true }`). + * - `stripped`: the lists whose label (the owner's or a placement's) an + * arrangement entry replaced with none. + * + * Built by {@link addOwnerRelatedLists} and then + * {@link foldRelatedListExtensions}: the ONE fold both readers of a + * `_relatedLists` key use, so the key `os i18n extract` / `os i18n check` + * expect is the key `os validate` accepts (`i18n-walk.ts`, + * `validate-translation-references.ts`). + */ +export interface RelatedListTitles { + labels: Map; + names: Set; + hidden: Set; + stripped: Set; +} + +/** An empty {@link RelatedListTitles}. */ +export function emptyRelatedListTitles(): RelatedListTitles { + return { labels: new Map(), names: new Set(), hidden: new Set(), stripped: new Set() }; +} + +/** A non-empty `label` string of a record entry, or `undefined`. */ +function entryLabel(entry: unknown): string | undefined { + if (!isRec(entry)) return undefined; + return typeof entry.label === 'string' && entry.label.length > 0 ? entry.label : undefined; +} + +/** + * Fold an owner declaration's `relatedLists` into `titles`: every list it + * names (a bare string, an object entry, a built-in tab), and the label of + * each object-form entry that authors one — the only entries + * `translateObject` overlays a `_relatedLists` key onto. A later declaration + * of the same list replaces an earlier one's label. + */ +export function addOwnerRelatedLists(titles: RelatedListTitles, entries: unknown): void { + for (const entry of Array.isArray(entries) ? entries : []) { + const list = typeof entry === 'string' ? entry : isRec(entry) ? strName(entry.list) : undefined; + if (!list) continue; + titles.names.add(list); + const label = entryLabel(entry); + if (label !== undefined) titles.labels.set(list, { label, layer: 'owner' }); + } +} + +/** + * Fold the extensions of one target ({@link objectExtensionsByTarget}, in fold + * order) into `titles`, after its owner's lists, as the registry folds them. + * + * 1. Every extension's list placements (`place` entries naming a `list`), in + * fold order; a list already labelled keeps that label. A placement on a + * target that declares no `relatedLists`, or on a list the owner already + * names, is not applied by the registry; this fold takes its label all the + * same, the accepting direction (`layer: 'place'` marks it for a reader + * that must not ask for it). + * 2. Then every extension's `.custom` arrangement (`registry-custom-arrangement.ts` + * in `@objectstack/objectql`): each entry REPLACES every entry it covers + * (`relatedListNameCovers`: the same list, or a bare child for each list of + * that child). A labelled entry titles the tab; a bare name or an unlabelled + * entry leaves it the child FK's `relatedListTitle`; `{ list, hidden: true }` + * leaves no tab. Two passes per arrangement, as the registry reads one: its + * entries first drop what they cover, then add their own labels and hidden + * lists, so one entry never strips what a sibling entry of the SAME + * arrangement wrote, in either order. + */ +export function foldRelatedListExtensions( + titles: RelatedListTitles, + extensions: readonly VisibleObjectExtension[], +): void { + for (const extension of extensions) { + 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; + titles.names.add(list); + const label = entryLabel(entry); + // The registry splices a placement in only where the list is not there + // yet, so a label the owner (or an earlier placement) gives is kept. + if (label !== undefined && !titles.labels.has(list)) titles.labels.set(list, { label, layer: 'place' }); + } + } + for (const extension of extensions) { + 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) { + titles.names.add(list); + for (const labelled of [...titles.labels.keys()]) { + if (!relatedListNameCovers(list, labelled)) continue; + titles.labels.delete(labelled); + titles.stripped.add(labelled); + } + for (const hidden of [...titles.hidden]) { + if (relatedListNameCovers(list, hidden)) titles.hidden.delete(hidden); + } + } + for (const { entry, list } of arrangement) { + if (relatedListEntryHidden(entry)) { + titles.hidden.add(list); + continue; + } + const label = entryLabel(entry); + if (label === undefined) continue; + titles.labels.set(list, { label, layer: 'arrangement' }); + titles.stripped.delete(list); + } + } +} + /** * [#30303] A stack's `objects` as the registry SERVES them: each with every * {@link objectExtensionsByTarget} entry that extends it folded in, the way diff --git a/packages/lint/src/validate-translation-references.ts b/packages/lint/src/validate-translation-references.ts index 1193c70b242..df7f8879123 100644 --- a/packages/lint/src/validate-translation-references.ts +++ b/packages/lint/src/validate-translation-references.ts @@ -276,9 +276,18 @@ import { pageTabItemKey, walkAddressedPageComponents, } from '@objectstack/spec/system'; -import { isRecordPageBuiltinTab, relatedListEntryHidden, relatedListEntryName, relatedListNameCovers } from '@objectstack/spec/data'; +import { isRecordPageBuiltinTab, relatedListNameCovers } from '@objectstack/spec/data'; import { walkFlowNodes } from './flow-walk.js'; -import { objectExtensionsByTarget, packagesOf, recordsOf, suggestName } from './object-graph.js'; +import { + addOwnerRelatedLists, + emptyRelatedListTitles, + foldRelatedListExtensions, + objectExtensionsByTarget, + packagesOf, + recordsOf, + suggestName, + type RelatedListTitles, +} from './object-graph.js'; import { walkPageComponents } from './page-walk.js'; import { SYSTEM_FIELDS } from './system-fields.js'; import { viewObjectName } from './view-walk.js'; @@ -490,29 +499,16 @@ interface ObjectFacts { */ tabs: Set; /** - * `_relatedLists` names — the `list` of every object-form `relatedLists` - * entry this object declares WITH a `label`, the only entries - * `translateObject` overlays `objects.._relatedLists..label` onto. - */ - relatedListLabels: Set; - /** - * Every list this object's `relatedLists` names, labelled or not (a bare - * string, an object entry, a built-in tab) — read only to say WHY a - * `_relatedLists` key over a named but unlabelled entry resolves nothing. - */ - relatedListNames: Set; - /** - * The lists a paired `.custom` arrangement hides (`{ list, hidden: true }`, - * ADR-0146 D10): no tab shows them, so their title is read nowhere — read - * 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. + * `_relatedLists` — the object's record-page tab titles as the registry + * serves them: the owner's `relatedLists`, then every list placement, then + * the paired `.custom` arrangement (ADR-0146 D10), folded by the ONE fold + * `os i18n extract` also reads ({@link foldRelatedListExtensions}). A key + * resolves only over a list in its `labels`, the only entries + * `translateObject` overlays `objects.._relatedLists..label` + * onto; `names`, `hidden` and `stripped` are read only to say WHY a key + * over any other list resolves nothing. */ - relatedListStripped: Set; + relatedListTitles: RelatedListTitles; } /** Everything a `flows..screens.` key may legally name. */ @@ -687,10 +683,7 @@ function emptyFacts(): ObjectFacts { validations: new Set(), milestones: new Map(), tabs: new Set(), - relatedListLabels: new Set(), - relatedListNames: new Set(), - relatedListHidden: new Set(), - relatedListStripped: new Set(), + relatedListTitles: emptyRelatedListTitles(), }; } @@ -1377,12 +1370,7 @@ function buildUniverse(stack: AnyRec): Universe { // literal `list` (`object.field` is one key), and resolves only over an // entry that authors a `label`: `translateObject` overlays that label and // swaps nothing in for an entry without one. - for (const entry of Array.isArray(obj.relatedLists) ? obj.relatedLists : []) { - const list = typeof entry === 'string' ? entry : isRec(entry) ? strName(entry.list) : undefined; - if (!list) continue; - facts.relatedListNames.add(list); - if (isRec(entry) && typeof entry.label === 'string' && entry.label.length > 0) facts.relatedListLabels.add(list); - } + addOwnerRelatedLists(facts.relatedListTitles, obj.relatedLists); }; for (const obj of recordsOf(stack.objects)) { @@ -1459,61 +1447,20 @@ 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 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. - // - // 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) { - 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)) continue; - facts.relatedListLabels.delete(labelled); - facts.relatedListStripped.add(labelled); - } - for (const hidden of [...facts.relatedListHidden]) { - if (relatedListNameCovers(list, hidden)) facts.relatedListHidden.delete(hidden); - } - } - 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); - } - } } + // `_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. [#36595] The + // `.custom` arrangement (ADR-0146 D10) is applied after every placement, + // as the registry applies it (`registry-custom-arrangement.ts`), each of + // its entries replacing every entry it covers. [#37622] One fold for this + // rule and for `os i18n extract` / `os i18n check` (`i18n-walk.ts`). + foldRelatedListExtensions(facts.relatedListTitles, extensions); } // ── Stack-level views: `_views` names + form-section names ── @@ -2239,8 +2186,9 @@ export function validateTranslationReferences(stack: AnyRec): TranslationRefFind // object-form `relatedLists` entry. A key over a list the object names // without a `label` translates nothing: that tab's title is the child // FK's `relatedListTitle`, keyed on the child. + const titles = facts.relatedListTitles; for (const listName of Object.keys(asRecord(rawNode._relatedLists))) { - if (facts.relatedListLabels.has(listName)) continue; + if (titles.labels.has(listName)) continue; const listWhere = `${inLocale} · object "${objectName}" · related list "${listName}"`; const listPath = `${objPath}._relatedLists${memberPath(listName)}`; if (isRecordPageBuiltinTab(listName)) { @@ -2250,21 +2198,27 @@ export function validateTranslationReferences(stack: AnyRec): TranslationRefFind `Drop this key: a built-in tab takes no \`label\` here.`); continue; } - if ([...facts.relatedListHidden].some((hidden) => relatedListNameCovers(hidden, listName))) { + // [#37622] The remedy names the list the key addresses: where a bare + // child (`event`) hides or strips a dotted list (`event.related_to`), + // the entry to write is the dotted list's own, and the label it + // carries is whichever the arrangement should serve — the owner's, + // a placement's or a new one. + if ([...titles.hidden].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.`, - `Drop this key, or show the tab (drop \`hidden\`) with the owner's \`label\` on the entry.`); + `Drop this key, or show the tab: drop \`hidden\` and give the arrangement a ` + + `{ list: '${listName}', label } entry.`); continue; } - if (facts.relatedListStripped.has(listName)) { + if (titles.stripped.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 }).`); + `arrangement, which replaces the entry that labelled it, so no title reads this key.`, + `Drop this key, or give the arrangement a { list: '${listName}', label } entry to title the tab.`); continue; } - const named = facts.relatedListNames.has(listName); + const named = titles.names.has(listName); orphan( listWhere, listPath, @@ -2273,7 +2227,7 @@ export function validateTranslationReferences(stack: AnyRec): TranslationRefFind `\`relatedLists\`, so no title reads this key.` : `Translations are keyed to related list "${listName}", which no \`relatedLists\` entry ` + `of object "${objectName}" names, so nothing reads this key.` + - suggest(listName, facts.relatedListLabels), + suggest(listName, titles.labels.keys()), named ? `Give the entry a \`label\` ({ list, label }) to title it here, or translate the ` + `child lookup field's \`relatedListTitle\` instead, and drop this key.` From e3915ef5bad19b776ae037a9b1b6b88b5384bdef Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 01:30:07 +0000 Subject: [PATCH 2/7] fix(rest): the object read hands the pair's related-list translations to the translator Claude-Session: https://claude.ai/code/session_01L9qibw44Q7BwdAY1RmfR73 Co-authored-by: Claude --- packages/rest/src/meta-item-read-gate.ts | 54 ++++- ...meta-object-related-list-pair-i18n.test.ts | 226 ++++++++++++++++++ 2 files changed, 277 insertions(+), 3 deletions(-) create mode 100644 packages/rest/src/meta-object-related-list-pair-i18n.test.ts diff --git a/packages/rest/src/meta-item-read-gate.ts b/packages/rest/src/meta-item-read-gate.ts index 0a7c846dc0d..8e3a0103ff3 100644 --- a/packages/rest/src/meta-item-read-gate.ts +++ b/packages/rest/src/meta-item-read-gate.ts @@ -3660,6 +3660,46 @@ export async function patchTranslationBundlesOf( return out.length > 0 ? out : undefined; } +/** + * [#37622, ADR-0146 D10] The record-page tab titles the paired `.custom` + * package translates for object `name`, for `translateMetadataDocument`'s + * `pairBundle` — or `undefined`. + * + * An object is extended, never replaced, so {@link pairTranslationBundleOf} + * answers none for it (`servedOverrideBaseOf`, D10), and a tab title the pair's + * arrangement (`objectExtensions[].relatedLists`) sets or changes diverges from + * the packaged base it is judged against: without the pair's catalog such a + * title read nothing and kept its own text, though `os validate` accepts the + * key that translates it. The pair is the one the object's packaged base + * ships in (`packagedBase._packageId`, the base + * {@link withoutStaleObjectPlural} reads it for), its translations are read + * through the same `memo`, and only their + * `objects.._relatedLists` subtree is handed on, per locale: every other + * string of the object keeps the ranking it has without a pair (D10), and an + * empty answer is `undefined`, never a catalog that answers nothing. + */ +async function objectPairRelatedListsBundleOf( + protocol: unknown, + type: string, + name: unknown, + packagedBase: unknown, + memo?: Map>, +): Promise { + if (type !== 'object' || typeof name !== 'string' || name === '') return undefined; + const base = packagedBase && typeof packagedBase === 'object' + ? (packagedBase as Record)._packageId + : undefined; + const pair = await pairTranslationBundleOfBase(protocol, base, memo); + if (!pair || typeof pair !== 'object') return undefined; + const slice: Record = {}; + for (const [locale, data] of Object.entries(pair as Record)) { + const lists = (data as any)?.objects?.[name]?._relatedLists; + if (!lists || typeof lists !== 'object' || Array.isArray(lists) || Object.keys(lists).length === 0) continue; + slice[locale] = { objects: { [name]: { _relatedLists: lists } } }; + } + return Object.keys(slice).length > 0 ? slice : undefined; +} + /** A non-empty string, or `undefined`. */ function nonEmptyText(value: unknown): string | undefined { return typeof value === 'string' && value.length > 0 ? value : undefined; @@ -3838,9 +3878,13 @@ export async function translateMetaList( // `getMetaItems` elements are metadata documents (the list envelope is the // OUTER `{ type, items }`), so every element translates directly (#5563). const translated = await Promise.all(arr.map(async (item) => { - const pairBundle = p === undefined ? undefined : await pairTranslationBundleOf(p, metaType, item, pairBundles); - const patchBundles = p === undefined ? undefined : await patchTranslationBundlesOf(p, metaType, item?.name, packageBundles); const packagedBase = packagedObjectBaseOf(p, metaType, item?.name); + // [#37622] An object has no declared override; its pair's tab-title translations instead. + const pairBundle = p === undefined + ? undefined + : (await pairTranslationBundleOf(p, metaType, item, pairBundles)) + ?? (await objectPairRelatedListsBundleOf(p, metaType, item?.name, packagedBase, pairBundles)); + const patchBundles = p === undefined ? undefined : await patchTranslationBundlesOf(p, metaType, item?.name, packageBundles); const out = translateMetadataDocument(metaType, item, bundle, { ...metaTranslateOptions(i18n, locale), packagedBase, @@ -3915,7 +3959,11 @@ export async function translateMetaDocument( const p = PACKAGED_BASE_ACCESSORS.has(metaType) ? await sources.resolveProtocol() : undefined; const packagedBase = packagedObjectBaseOf(p, metaType, (document as any)?.name); // [#30062] A declared override's pair translations: the ruled order's first rank. - const pairBundle = p === undefined ? undefined : await pairTranslationBundleOf(p, metaType, document); + // [#37622] An object has no declared override; its pair's tab-title translations instead. + const pairBundle = p === undefined + ? undefined + : (await pairTranslationBundleOf(p, metaType, document)) + ?? (await objectPairRelatedListsBundleOf(p, metaType, (document as any)?.name, packagedBase)); // [#33952] Each patching package's own translations: a patched field slot's second rank. const patchBundles = p === undefined ? undefined : await patchTranslationBundlesOf(p, metaType, (document as any)?.name); const translated = translateMetadataDocument(metaType, document as any, bundle, { diff --git a/packages/rest/src/meta-object-related-list-pair-i18n.test.ts b/packages/rest/src/meta-object-related-list-pair-i18n.test.ts new file mode 100644 index 00000000000..1f3a78b707e --- /dev/null +++ b/packages/rest/src/meta-object-related-list-pair-i18n.test.ts @@ -0,0 +1,226 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * #37622 — a record-page tab title the paired `.custom` package's arrangement + * (`objectExtensions[].relatedLists`, ADR-0146 D10) sets or changes is + * translated by the pair's own `objects.._relatedLists..label` + * on both `/meta/object` reads. Before it, the object read handed the + * translator no pair catalog (an object is extended, never replaced, so it + * answers no `servedOverrideBaseOf`), and a title that diverges from the + * packaged base read nothing, though `os validate` accepts the key. + * + * Only the pair's tab titles are handed on: every other string of the object + * keeps the ranking it had (D10), which the scope pin below holds. + * + * Real `SchemaRegistry`, real protocol, real `RestServer`, an i18n service + * whose catalog is the deployment's (every package's translations merged, the + * pair's authored rows included) — the harness of + * `meta-object-extension-plural-label.test.ts`. + */ + +import { describe, it, expect, vi } from 'vitest'; +import { SchemaRegistry, assertEngineFindOnePredicate } from '@objectstack/objectql'; +import { ObjectStackProtocolImplementation } from '@objectstack/metadata-protocol'; +import { RestServer } from './rest-server.js'; + +const BASE = 'com.acme.crm'; +const PAIR = 'com.acme.crm.custom'; + +/** The base package's parent: one labelled tab, one bare. */ +const ACCOUNT = { + name: 'crm_account', + label: 'Account', + fields: { name: { name: 'name', type: 'text', label: 'Name' } }, + relatedLists: [{ list: 'crm_contact', label: 'Contacts' }, 'crm_case'], +}; + +const child = (name: string, label: string) => ({ + name, + label, + fields: { account_id: { name: 'account_id', type: 'lookup', label: 'Account', reference: 'crm_account' } }, +}); + +/** The base package's catalog: `en` repeats the source, `zh-CN` translates it. */ +const BASE_CATALOG: Record = { + en: { objects: { crm_account: { label: 'Account', _relatedLists: { crm_contact: { label: 'Contacts' } } } } }, + 'zh-CN': { objects: { crm_account: { label: '客户', _relatedLists: { crm_contact: { label: '联系人' } } } } }, +}; + +const clone = (v: T): T => JSON.parse(JSON.stringify(v)) as T; + +type Row = Record; + +/** + * Plain equality and `$in` (the by-name read asks `type` in both spellings); + * any other operator or combinator is refused, so a matcher that ignored one + * proves nothing. + */ +function matches(row: Row, where: Record = {}): boolean { + for (const [key, want] of Object.entries(where)) { + if (want === undefined) continue; + if (key.startsWith('$')) throw new Error(`fake engine: unsupported combinator ${key}`); + if (want !== null && typeof want === 'object') { + const ops = Object.keys(want); + const list = (want as { $in?: unknown }).$in; + if (ops.length !== 1 || !Array.isArray(list)) throw new Error(`fake engine: unsupported operator on ${key}`); + if (!list.includes(row[key] ?? null)) return false; + continue; + } + if ((row[key] ?? null) !== want) return false; + } + return true; +} + +/** A pair's saved `translation` row, as `getPairTranslationBundle` reads it. */ +function pairTranslationRow(locale: string, objects: Record): Row { + const name = `pair_${locale}`; + return { + id: name, type: 'translation', name, package_id: PAIR, organization_id: null, state: 'active', + metadata: JSON.stringify({ name, locale, objects }), + }; +} + +/** Deep-merge `top` over `under`, one locale's data: the deployment catalog's shape. */ +function overlay(under: any, top: any): any { + if (!top) return under; + const out: any = { ...under }; + for (const [k, v] of Object.entries(top)) { + out[k] = v && typeof v === 'object' && under?.[k] && typeof under[k] === 'object' ? overlay(under[k], v) : v; + } + return out; +} + +function mockServer() { + return { + get: vi.fn(), post: vi.fn(), put: vi.fn(), delete: vi.fn(), patch: vi.fn(), + use: vi.fn(), listen: vi.fn().mockResolvedValue(undefined), close: vi.fn().mockResolvedValue(undefined), + }; +} + +interface Boot { + /** The `.custom` extension of `crm_account`, or none. */ + extension?: Record; + /** The pair's own translations, locale → `objects` data; they also reach the deployment catalog. */ + pairObjects?: Record>; +} + +/** Boot one host and answer `read(locale)` → `crm_account` as both reads serve it. */ +function boot(opts: Boot = {}) { + const registry = new SchemaRegistry(); + registry.registerObject(clone(ACCOUNT) as never, BASE, undefined, 'own'); + for (const [name, label] of [['crm_contact', 'Contact'], ['crm_case', 'Case']]) { + registry.registerObject(child(name, label) as never, BASE, undefined, 'own'); + } + if (opts.extension) registry.registerObjectExtension({ extend: 'crm_account', ...clone(opts.extension) }, PAIR); + + const rows: Row[] = Object.entries(opts.pairObjects ?? {}).map(([locale, objects]) => pairTranslationRow(locale, objects)); + const read = async (table: string, q?: { where?: Record; limit?: number }) => { + const found = table === 'sys_metadata' ? rows.filter((r) => matches(r, q?.where)) : []; + return typeof q?.limit === 'number' ? found.slice(0, q.limit) : found; + }; + const engine = { + registry, + find: read, + findOne: async (table: string, q: { where: Record }) => { + assertEngineFindOnePredicate(table, q); + return (await read(table, q))[0] ?? null; + }, + }; + const protocol = new ObjectStackProtocolImplementation(engine as never, undefined, 'env_test'); + + const catalog = (locale: string) => overlay(BASE_CATALOG[locale], opts.pairObjects?.[locale] && { objects: opts.pairObjects[locale] }); + const i18nService = { + getLocales: () => ['en', 'zh-CN'], + getTranslations: (locale: string) => catalog(locale), + getDefaultLocale: () => 'en', + }; + + const rest = new RestServer( + mockServer() as never, protocol as never, { api: { requireAuth: false } } as never, + undefined, undefined, undefined, undefined, undefined, + undefined, undefined, undefined, undefined, undefined, + // i18nServiceProvider — the 14th constructor argument. + async () => i18nService as never, + ); + (rest as unknown as { resolveExecCtx: () => Promise }).resolveExecCtx = async () => ({ userId: 'u1', systemPermissions: [] }); + rest.registerRoutes(); + const routes = rest.getRouteManager(); + + const run = async (path: string, params: Record, locale: string) => { + const entry = routes.get('GET', path); + if (!entry) throw new Error(`route not registered: ${path}`); + let body: any; + const res = { + status: () => res, header: () => res, + json: (b: unknown) => { body = b; }, send: (b: unknown) => { body = b; }, + } as unknown as Parameters[1]; + await entry.handler( + { params, query: {}, headers: { 'accept-language': locale }, method: 'GET', path } as unknown as Parameters[0], + res, + ); + return body; + }; + + const titles = (doc: any) => (Array.isArray(doc?.relatedLists) ? doc.relatedLists : []) + .map((entry: any) => (typeof entry === 'string' ? entry : entry?.label ?? entry?.list)); + + /** `crm_account` on the by-name read and on the list read: its label and its tab titles. */ + return async (locale: string) => { + const byName = (await run('/api/v1/meta/:type/:name', { type: 'object', name: 'crm_account' }, locale))?.item; + const listBody = await run('/api/v1/meta/:type', { type: 'object' }, locale); + const listed = (Array.isArray(listBody) ? listBody : listBody?.items ?? []).find((o: any) => o?.name === 'crm_account'); + return [byName, listed].map((doc) => ({ label: doc?.label, tabs: titles(doc) })); + }; +} + +/** The arrangement: relabels the owner's labelled tab and titles its bare one. */ +const ARRANGEMENT = { relatedLists: [{ list: 'crm_contact', label: 'People' }, { list: 'crm_case', label: 'Tickets' }] }; + +describe('#37622 — the pair translates the tab titles its arrangement sets', () => { + it('serves the pair\'s translation of a relabelled tab and of a newly titled one, on both reads', async () => { + const read = boot({ + extension: ARRANGEMENT, + pairObjects: { 'zh-CN': { crm_account: { _relatedLists: { crm_contact: { label: '人员' }, crm_case: { label: '工单' } } } } }, + }); + for (const served of await read('zh-CN')) expect(served.tabs).toEqual(['人员', '工单']); + // A locale the pair does not translate keeps the arrangement's own text. + for (const served of await read('en')) expect(served.tabs).toEqual(['People', 'Tickets']); + }); + + it('a title the pair does not translate keeps its own text, never the base\'s translation of another', async () => { + const read = boot({ + extension: ARRANGEMENT, + pairObjects: { 'zh-CN': { crm_account: { _relatedLists: { crm_case: { label: '工单' } } } } }, + }); + // `联系人` translates the base's `Contacts`, not the arrangement's `People`. + for (const served of await read('zh-CN')) expect(served.tabs).toEqual(['People', '工单']); + }); + + it('hands on the pair\'s tab titles only: a label the extension renames keeps its ranking (D10)', async () => { + const read = boot({ + extension: { ...ARRANGEMENT, label: 'Client' }, + pairObjects: { 'zh-CN': { crm_account: { label: '顾客', _relatedLists: { crm_contact: { label: '人员' } } } } }, + }); + for (const served of await read('zh-CN')) { + expect(served.label).toBe('Client'); + expect(served.tabs).toEqual(['人员', 'Tickets']); + } + }); +}); + +describe('#37622 — controls', () => { + it('with no arrangement, the owner\'s tab title reads the deployment catalog as before', async () => { + const read = boot(); + for (const served of await read('zh-CN')) expect(served.tabs).toEqual(['联系人', 'crm_case']); + }); + + it('an arrangement that keeps the owner\'s title reads the deployment catalog, and the pair first where it ships one', async () => { + const kept = { relatedLists: [{ list: 'crm_contact', label: 'Contacts' }, 'crm_case'] }; + for (const served of await boot({ extension: kept })('zh-CN')) expect(served.tabs).toEqual(['联系人', 'crm_case']); + const pairFirst = boot({ + extension: kept, + pairObjects: { 'zh-CN': { crm_account: { _relatedLists: { crm_contact: { label: '人员' } } } } }, + }); + for (const served of await pairFirst('zh-CN')) expect(served.tabs).toEqual(['人员', 'crm_case']); + }); +}); From 0a3c5d62a14c2bd9bc65a8a0c48b912170a11ad6 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 01:30:47 +0000 Subject: [PATCH 3/7] refactor(lint): the related-list title fold lives in its own module Claude-Session: https://claude.ai/code/session_01L9qibw44Q7BwdAY1RmfR73 Co-authored-by: Claude --- packages/lint/src/i18n-walk.ts | 3 +- packages/lint/src/object-graph.ts | 121 +--------------- packages/lint/src/related-list-titles.ts | 136 ++++++++++++++++++ .../src/validate-translation-references.ts | 7 +- 4 files changed, 141 insertions(+), 126 deletions(-) create mode 100644 packages/lint/src/related-list-titles.ts diff --git a/packages/lint/src/i18n-walk.ts b/packages/lint/src/i18n-walk.ts index cf0f603f6e5..0413dc9a81e 100644 --- a/packages/lint/src/i18n-walk.ts +++ b/packages/lint/src/i18n-walk.ts @@ -206,7 +206,8 @@ import { APPROVAL_NODE_TYPE, flowDecisionEdgeBranch, isFlowTechnicalNodeType } f import { expandViewContainer, InlineLocaleMapSchema } from '@objectstack/spec/ui'; import { authorWarnedProperties } from './lint-liveness-properties.js'; import { walkPageComponents } from './page-walk.js'; -import { addOwnerRelatedLists, emptyRelatedListTitles, foldRelatedListExtensions, objectExtensionsByTarget } from './object-graph.js'; +import { objectExtensionsByTarget } from './object-graph.js'; +import { addOwnerRelatedLists, emptyRelatedListTitles, foldRelatedListExtensions } from './related-list-titles.js'; // ─── Public types ────────────────────────────────────────────────────── diff --git a/packages/lint/src/object-graph.ts b/packages/lint/src/object-graph.ts index 7ad1f50993e..985cdbfe70f 100644 --- a/packages/lint/src/object-graph.ts +++ b/packages/lint/src/object-graph.ts @@ -68,7 +68,7 @@ * second question about it is still unanswered — truthfully, and only there. */ -import { referenceTargetOf, relatedListEntryHidden, relatedListEntryName, relatedListNameCovers } from '@objectstack/spec/data'; +import { referenceTargetOf } from '@objectstack/spec/data'; import { injectedColumnDefsFor, injectedColumnsFor } from './system-fields.js'; @@ -550,125 +550,6 @@ export function objectExtensionsByTarget( return byTarget; } -/** - * [#37622] The record-page tab titles of one object, as the registry serves - * them: which `_relatedLists.LIST.label` keys a translation can address. - * - * - `labels`: each list that is served with a `label`, the label it is served - * with, and the layer that wrote it — the owner's `relatedLists`, a code - * extender's `place` entry, or the paired `.custom` arrangement - * (`objectExtensions[].relatedLists`, ADR-0146 D10). - * - `names`: every list any layer names, labelled or not. - * - `hidden`: the lists an arrangement hides (`{ list, hidden: true }`). - * - `stripped`: the lists whose label (the owner's or a placement's) an - * arrangement entry replaced with none. - * - * Built by {@link addOwnerRelatedLists} and then - * {@link foldRelatedListExtensions}: the ONE fold both readers of a - * `_relatedLists` key use, so the key `os i18n extract` / `os i18n check` - * expect is the key `os validate` accepts (`i18n-walk.ts`, - * `validate-translation-references.ts`). - */ -export interface RelatedListTitles { - labels: Map; - names: Set; - hidden: Set; - stripped: Set; -} - -/** An empty {@link RelatedListTitles}. */ -export function emptyRelatedListTitles(): RelatedListTitles { - return { labels: new Map(), names: new Set(), hidden: new Set(), stripped: new Set() }; -} - -/** A non-empty `label` string of a record entry, or `undefined`. */ -function entryLabel(entry: unknown): string | undefined { - if (!isRec(entry)) return undefined; - return typeof entry.label === 'string' && entry.label.length > 0 ? entry.label : undefined; -} - -/** - * Fold an owner declaration's `relatedLists` into `titles`: every list it - * names (a bare string, an object entry, a built-in tab), and the label of - * each object-form entry that authors one — the only entries - * `translateObject` overlays a `_relatedLists` key onto. A later declaration - * of the same list replaces an earlier one's label. - */ -export function addOwnerRelatedLists(titles: RelatedListTitles, entries: unknown): void { - for (const entry of Array.isArray(entries) ? entries : []) { - const list = typeof entry === 'string' ? entry : isRec(entry) ? strName(entry.list) : undefined; - if (!list) continue; - titles.names.add(list); - const label = entryLabel(entry); - if (label !== undefined) titles.labels.set(list, { label, layer: 'owner' }); - } -} - -/** - * Fold the extensions of one target ({@link objectExtensionsByTarget}, in fold - * order) into `titles`, after its owner's lists, as the registry folds them. - * - * 1. Every extension's list placements (`place` entries naming a `list`), in - * fold order; a list already labelled keeps that label. A placement on a - * target that declares no `relatedLists`, or on a list the owner already - * names, is not applied by the registry; this fold takes its label all the - * same, the accepting direction (`layer: 'place'` marks it for a reader - * that must not ask for it). - * 2. Then every extension's `.custom` arrangement (`registry-custom-arrangement.ts` - * in `@objectstack/objectql`): each entry REPLACES every entry it covers - * (`relatedListNameCovers`: the same list, or a bare child for each list of - * that child). A labelled entry titles the tab; a bare name or an unlabelled - * entry leaves it the child FK's `relatedListTitle`; `{ list, hidden: true }` - * leaves no tab. Two passes per arrangement, as the registry reads one: its - * entries first drop what they cover, then add their own labels and hidden - * lists, so one entry never strips what a sibling entry of the SAME - * arrangement wrote, in either order. - */ -export function foldRelatedListExtensions( - titles: RelatedListTitles, - extensions: readonly VisibleObjectExtension[], -): void { - for (const extension of extensions) { - 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; - titles.names.add(list); - const label = entryLabel(entry); - // The registry splices a placement in only where the list is not there - // yet, so a label the owner (or an earlier placement) gives is kept. - if (label !== undefined && !titles.labels.has(list)) titles.labels.set(list, { label, layer: 'place' }); - } - } - for (const extension of extensions) { - 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) { - titles.names.add(list); - for (const labelled of [...titles.labels.keys()]) { - if (!relatedListNameCovers(list, labelled)) continue; - titles.labels.delete(labelled); - titles.stripped.add(labelled); - } - for (const hidden of [...titles.hidden]) { - if (relatedListNameCovers(list, hidden)) titles.hidden.delete(hidden); - } - } - for (const { entry, list } of arrangement) { - if (relatedListEntryHidden(entry)) { - titles.hidden.add(list); - continue; - } - const label = entryLabel(entry); - if (label === undefined) continue; - titles.labels.set(list, { label, layer: 'arrangement' }); - titles.stripped.delete(list); - } - } -} - /** * [#30303] A stack's `objects` as the registry SERVES them: each with every * {@link objectExtensionsByTarget} entry that extends it folded in, the way diff --git a/packages/lint/src/related-list-titles.ts b/packages/lint/src/related-list-titles.ts new file mode 100644 index 00000000000..f92e2c09951 --- /dev/null +++ b/packages/lint/src/related-list-titles.ts @@ -0,0 +1,136 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +import { relatedListEntryHidden, relatedListEntryName, relatedListNameCovers } from '@objectstack/spec/data'; + +import type { VisibleObjectExtension } from './object-graph.js'; + +type AnyRec = Record; + +function isRec(v: unknown): v is AnyRec { + return typeof v === 'object' && v !== null && !Array.isArray(v); +} + +function strName(v: unknown): string | undefined { + return typeof v === 'string' && v.length > 0 ? v : undefined; +} + +/** + * [#37622] The record-page tab titles of one object, as the registry serves + * them: which `_relatedLists.LIST.label` keys a translation can address. + * + * - `labels`: each list that is served with a `label`, the label it is served + * with, and the layer that wrote it — the owner's `relatedLists`, a code + * extender's `place` entry, or the paired `.custom` arrangement + * (`objectExtensions[].relatedLists`, ADR-0146 D10). + * - `names`: every list any layer names, labelled or not. + * - `hidden`: the lists an arrangement hides (`{ list, hidden: true }`). + * - `stripped`: the lists whose label (the owner's or a placement's) an + * arrangement entry replaced with none. + * + * Built by {@link addOwnerRelatedLists} and then + * {@link foldRelatedListExtensions}: the ONE fold both readers of a + * `_relatedLists` key use, so the key `os i18n extract` / `os i18n check` + * expect is the key `os validate` accepts (`i18n-walk.ts`, + * `validate-translation-references.ts`). It lives in its own module, beside + * `object-graph.ts` rather than in it: that file's receivers are tabled by + * the security-posture rule's key-read meta-test, which this fold is no part of. + */ +export interface RelatedListTitles { + labels: Map; + names: Set; + hidden: Set; + stripped: Set; +} + +/** An empty {@link RelatedListTitles}. */ +export function emptyRelatedListTitles(): RelatedListTitles { + return { labels: new Map(), names: new Set(), hidden: new Set(), stripped: new Set() }; +} + +/** A non-empty `label` string of a record entry, or `undefined`. */ +function entryLabel(entry: unknown): string | undefined { + if (!isRec(entry)) return undefined; + return typeof entry.label === 'string' && entry.label.length > 0 ? entry.label : undefined; +} + +/** + * Fold an owner declaration's `relatedLists` into `titles`: every list it + * names (a bare string, an object entry, a built-in tab), and the label of + * each object-form entry that authors one — the only entries + * `translateObject` overlays a `_relatedLists` key onto. A later declaration + * of the same list replaces an earlier one's label. + */ +export function addOwnerRelatedLists(titles: RelatedListTitles, entries: unknown): void { + for (const entry of Array.isArray(entries) ? entries : []) { + const list = typeof entry === 'string' ? entry : isRec(entry) ? strName(entry.list) : undefined; + if (!list) continue; + titles.names.add(list); + const label = entryLabel(entry); + if (label !== undefined) titles.labels.set(list, { label, layer: 'owner' }); + } +} + +/** + * Fold the extensions of one target ({@link objectExtensionsByTarget}, in fold + * order) into `titles`, after its owner's lists, as the registry folds them. + * + * 1. Every extension's list placements (`place` entries naming a `list`), in + * fold order; a list already labelled keeps that label. A placement on a + * target that declares no `relatedLists`, or on a list the owner already + * names, is not applied by the registry; this fold takes its label all the + * same, the accepting direction (`layer: 'place'` marks it for a reader + * that must not ask for it). + * 2. Then every extension's `.custom` arrangement (`registry-custom-arrangement.ts` + * in `@objectstack/objectql`): each entry REPLACES every entry it covers + * (`relatedListNameCovers`: the same list, or a bare child for each list of + * that child). A labelled entry titles the tab; a bare name or an unlabelled + * entry leaves it the child FK's `relatedListTitle`; `{ list, hidden: true }` + * leaves no tab. Two passes per arrangement, as the registry reads one: its + * entries first drop what they cover, then add their own labels and hidden + * lists, so one entry never strips what a sibling entry of the SAME + * arrangement wrote, in either order. + */ +export function foldRelatedListExtensions( + titles: RelatedListTitles, + extensions: readonly VisibleObjectExtension[], +): void { + for (const extension of extensions) { + 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; + titles.names.add(list); + const label = entryLabel(entry); + // The registry splices a placement in only where the list is not there + // yet, so a label the owner (or an earlier placement) gives is kept. + if (label !== undefined && !titles.labels.has(list)) titles.labels.set(list, { label, layer: 'place' }); + } + } + for (const extension of extensions) { + 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) { + titles.names.add(list); + for (const labelled of [...titles.labels.keys()]) { + if (!relatedListNameCovers(list, labelled)) continue; + titles.labels.delete(labelled); + titles.stripped.add(labelled); + } + for (const hidden of [...titles.hidden]) { + if (relatedListNameCovers(list, hidden)) titles.hidden.delete(hidden); + } + } + for (const { entry, list } of arrangement) { + if (relatedListEntryHidden(entry)) { + titles.hidden.add(list); + continue; + } + const label = entryLabel(entry); + if (label === undefined) continue; + titles.labels.set(list, { label, layer: 'arrangement' }); + titles.stripped.delete(list); + } + } +} diff --git a/packages/lint/src/validate-translation-references.ts b/packages/lint/src/validate-translation-references.ts index df7f8879123..b1538552acd 100644 --- a/packages/lint/src/validate-translation-references.ts +++ b/packages/lint/src/validate-translation-references.ts @@ -278,16 +278,13 @@ import { } from '@objectstack/spec/system'; import { isRecordPageBuiltinTab, relatedListNameCovers } from '@objectstack/spec/data'; import { walkFlowNodes } from './flow-walk.js'; +import { objectExtensionsByTarget, packagesOf, recordsOf, suggestName } from './object-graph.js'; import { addOwnerRelatedLists, emptyRelatedListTitles, foldRelatedListExtensions, - objectExtensionsByTarget, - packagesOf, - recordsOf, - suggestName, type RelatedListTitles, -} from './object-graph.js'; +} from './related-list-titles.js'; import { walkPageComponents } from './page-walk.js'; import { SYSTEM_FIELDS } from './system-fields.js'; import { viewObjectName } from './view-walk.js'; From ce31b694a507b7194fea6f6bafbd359aa05e0305 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 01:32:14 +0000 Subject: [PATCH 4/7] fix(lint,rest): changeset, ledger wording, docs row and the 36528 pin header Claude-Session: https://claude.ai/code/session_01L9qibw44Q7BwdAY1RmfR73 Co-authored-by: Claude --- ...lated-list-keys-agree-under-arrangement.md | 23 +++++++++++++++++++ .../docs/protocol/kernel/i18n-standard.mdx | 2 +- ...ated-lists-label-translation-36528.test.ts | 6 +++++ ...ated-list-key-under-arrangement-refused.ts | 13 ++++++----- 4 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 .changeset/37622-related-list-keys-agree-under-arrangement.md diff --git a/.changeset/37622-related-list-keys-agree-under-arrangement.md b/.changeset/37622-related-list-keys-agree-under-arrangement.md new file mode 100644 index 00000000000..4d0ce28001d --- /dev/null +++ b/.changeset/37622-related-list-keys-agree-under-arrangement.md @@ -0,0 +1,23 @@ +--- +'@objectstack/lint': patch +'@objectstack/rest': patch +'@objectstack/spec': patch +--- + +fix(lint,rest)!: `os i18n extract` / `os i18n check` expect the `_relatedLists` keys `os validate` accepts under a `.custom` arrangement, and the object read translates a tab title the arrangement sets + +Clause-②: yes (narrowing) +Metadata-protocol: none + + + +**BREAKING** for a stack that runs `os i18n check --strict` (or `--threshold`) and carries a paired `.custom` package's `relatedLists` arrangement (ADR-0146 D10) that labels a record-page tab. The coverage gate now expects `objects.._relatedLists..label` for each list the arrangement labels, with the arrangement's text, so a stack that passed in 19.0.0-next.1 without that translation now reports it missing. Add the translation, or drop the arrangement entry's `label`. Keys over a list the arrangement hides, names bare or re-states without a `label` are no longer expected, so a gate that demanded a key `os validate` refuses stops demanding it. + +**What changes in `@objectstack/lint`.** + +- `collectExpectedEntries`, which `os i18n extract` and `os i18n check` read, folds the owner's `relatedLists` with the stack's `objectExtensions` the way `translation-target-unknown` folds them: every placement first, then the arrangement, whose entries replace every entry they cover (`relatedListNameCovers`). It is one fold, `related-list-titles.ts`, read by both. `os i18n extract` scaffolds no key over a list the arrangement hides, names bare or re-states without a `label`, and scaffolds one, carrying the arrangement's text, over a list it labels. A label only a code extender's `place` entry gives is still not scaffolded: the rule accepts its key, but the registry may not apply the placement. +- The two `translation-target-unknown` hints for such a key name the list it addresses, `{ list: 'LIST', label }`, instead of "the owner's `label`". The stripped label may be a placement's, and where a bare child name covers a dotted list, the entry to write is the dotted list's own. + +**What changes in `@objectstack/rest`.** The `/meta/object` reads (by name and list) hand the translator the paired `.custom` package's own `objects.._relatedLists` translations, read for the pair of the base the object's packaged base ships in. A tab title the arrangement sets or changes now reads the pair's translation, then keeps its own text. Before, it read nothing, because an object answers no `servedOverrideBaseOf` (ADR-0146 D10, unchanged). Only that subtree is handed on: every other string of an object keeps the ranking it had. + +**What changes in `@objectstack/spec`.** The wording of the `translation-related-list-key-under-arrangement-refused` ledger entry: the label the arrangement strips may be a placement's, and the remedy no longer says that a translated title needs the owner's label. diff --git a/content/docs/protocol/kernel/i18n-standard.mdx b/content/docs/protocol/kernel/i18n-standard.mdx index 18e14e5f1e1..6bc1adf2bd5 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. 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}._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 or a placement gave it, and a list it labels resolves. `os i18n extract` and `os i18n check` expect exactly the keys over the owner's and the arrangement's labelled lists, and the object read translates a title the arrangement sets from the `.custom` package's own translations | | `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}._milestones.{field}.{value}` | an `activityMilestones[]` entry of that object watching `field` and firing on `value` | | `objects.{object}._actions.{action}` | an action bound to that object: one in its `actions`, or a stack-level action whose `objectName` is that object | diff --git a/packages/objectql/src/registry-related-lists-label-translation-36528.test.ts b/packages/objectql/src/registry-related-lists-label-translation-36528.test.ts index 52f047c7572..3394f1a929d 100644 --- a/packages/objectql/src/registry-related-lists-label-translation-36528.test.ts +++ b/packages/objectql/src/registry-related-lists-label-translation-36528.test.ts @@ -11,6 +11,12 @@ * asks the engine's registry). A code extender's placed entry is part of that * base (#36528), so its title reads the deployment catalog; a `.custom` title * diverges from the base and reads the pair's translations (`pairBundle`). + * An object answers no `servedOverrideBaseOf` (ADR-0146 D10), so the REST + * read hands the pair's `objects.._relatedLists` translations alone, + * read for the pair of the base `packagedObjectBaseOf` names + * (`objectPairRelatedListsBundleOf`, #37622); this file passes that bundle by + * hand, and `meta-object-related-list-pair-i18n.test.ts` in `@objectstack/rest` + * pins the read that builds it. */ import { describe, it, expect } from 'vitest'; diff --git a/packages/spec/src/migrations/entries/semantic/19.translation-related-list-key-under-arrangement-refused.ts b/packages/spec/src/migrations/entries/semantic/19.translation-related-list-key-under-arrangement-refused.ts index a89a72f365f..bb0fc0f1c43 100644 --- a/packages/spec/src/migrations/entries/semantic/19.translation-related-list-key-under-arrangement-refused.ts +++ b/packages/spec/src/migrations/entries/semantic/19.translation-related-list-key-under-arrangement-refused.ts @@ -12,15 +12,16 @@ 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 ' + + 'translations, over a list the object\'s owner or a list placement 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, so a labelled { list: event, ' - + 'label } also leaves the owner\'s event.related_to with no label)', + + 'label } also leaves a labelled 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 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.', + + 'Where the tab should keep a translated title, give the .custom arrangement an entry for that list itself ' + + '({ list, label }; the dotted list where a bare child name covers it) and keep the key: a label equal to the ' + + 'owner\'s reads the deployment\'s translation, and any other label reads the .custom package\'s own ' + + 'translation of the key.', 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 ' @@ -32,5 +33,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 the owner\'s label and the record page shows the translated title in that locale.', + + 'carries a label and the record page shows the translated title in that locale.', }; From 48c654cce2b60d526f47ae9a94113d7749b4215e Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 01:47:07 +0000 Subject: [PATCH 5/7] test(cli): os i18n check expects the related-list keys the .custom arrangement leaves titled Claude-Session: https://claude.ai/code/session_01L9qibw44Q7BwdAY1RmfR73 Co-authored-by: Claude --- packages/cli/test/i18n-coverage.test.ts | 33 +++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/packages/cli/test/i18n-coverage.test.ts b/packages/cli/test/i18n-coverage.test.ts index 8ae5130c2f2..689bb37c724 100644 --- a/packages/cli/test/i18n-coverage.test.ts +++ b/packages/cli/test/i18n-coverage.test.ts @@ -518,3 +518,36 @@ describe('computeI18nCoverage — the users\' defaultLocale stays gated beside s expect(report).toEqual(run(undeclared, [ES], { defaultLocale: 'zh-CN' })); }); }); + +// [#37622] `os i18n check` reads its expected keys from `collectExpectedEntries`, +// which folds the owner's tab list with the stack's `.custom` arrangement the +// way `os validate` does: no key over a tab the arrangement hides, and one +// over a tab it titles. +describe('computeI18nCoverage — _relatedLists under a `.custom` arrangement (#37622)', () => { + const arranged: any = { + objects: [{ + name: 'account', + label: 'Account', + fields: { name: { label: 'Name' } }, + relatedLists: [{ list: 'contact', label: 'People' }, 'case'], + }], + objectExtensions: [{ extend: 'account', relatedLists: [{ list: 'contact', hidden: true }, { list: 'case', label: 'Tickets' }] }], + translations: [{ en: { objects: { account: { label: 'Account' } } }, 'zh-CN': { objects: { account: { label: '客户' } } } }], + }; + + it('expects the tab the arrangement titles and not the one it hides', () => { + const zhKeys = new Set( + computeI18nCoverage(arranged, { defaultLocale: 'en' }).issues + .filter((i) => i.locale === 'zh-CN' && i.key.includes('._relatedLists.')) + .map((i) => i.key), + ); + expect([...zhKeys]).toEqual(['objects.account._relatedLists.case.label']); + }); + + it('control: with no arrangement, the owner\'s labelled tab is expected', () => { + const zhKeys = computeI18nCoverage({ ...arranged, objectExtensions: [] }, { defaultLocale: 'en' }).issues + .filter((i) => i.locale === 'zh-CN' && i.key.includes('._relatedLists.')) + .map((i) => i.key); + expect(zhKeys).toEqual(['objects.account._relatedLists.contact.label']); + }); +}); From fe0f53eb69cb064eb323ff9dc9576372f049ef8c Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 02:00:32 +0000 Subject: [PATCH 6/7] chore(scripts): the engine-double ledger records the new related-list pair pin Claude-Session: https://claude.ai/code/session_01L9qibw44Q7BwdAY1RmfR73 Co-authored-by: Claude --- scripts/engine-double-contract.pinned.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/engine-double-contract.pinned.json b/scripts/engine-double-contract.pinned.json index 5ffa3642ad8..26ec3022c81 100644 --- a/scripts/engine-double-contract.pinned.json +++ b/scripts/engine-double-contract.pinned.json @@ -5171,6 +5171,11 @@ "verb": "findOne", "pinned": 1 }, + { + "file": "packages/rest/src/meta-object-related-list-pair-i18n.test.ts", + "verb": "findOne", + "pinned": 1 + }, { "file": "packages/rest/src/meta-object-search-companion-agreement.test.ts", "verb": "findOne", From 7ddcc64690282bb66f2c8baf5d8ea0aacf080884 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 02:40:00 +0000 Subject: [PATCH 7/7] fix(rest): ask the pair's catalog only for an object whose tab titles diverge from the packaged base The object reads asked getPairTranslationBundle for every listed object, so an MCP list_objects paid one more translation read than the ADR-0090 D10 budget in mcp-list-objects-statements.pin.test.ts allows. A tab title equal to the base's reads the deployment catalog, which already holds the pair's share, so the pair is now asked only when the served object carries a title off the base. A new pin counts the asks. Claude-Session: https://claude.ai/code/session_01L9qibw44Q7BwdAY1RmfR73 Co-authored-by: Claude --- packages/rest/src/meta-item-read-gate.ts | 43 ++++++++++++++++--- ...meta-object-related-list-pair-i18n.test.ts | 18 +++++++- 2 files changed, 54 insertions(+), 7 deletions(-) diff --git a/packages/rest/src/meta-item-read-gate.ts b/packages/rest/src/meta-item-read-gate.ts index 8e3a0103ff3..946fd74f68d 100644 --- a/packages/rest/src/meta-item-read-gate.ts +++ b/packages/rest/src/meta-item-read-gate.ts @@ -3677,18 +3677,26 @@ export async function patchTranslationBundlesOf( * `objects.._relatedLists` subtree is handed on, per locale: every other * string of the object keeps the ranking it has without a pair (D10), and an * empty answer is `undefined`, never a catalog that answers nothing. + * + * The pair is asked only when `served` carries a tab title that diverges from + * the packaged base ({@link hasRelatedListTitleOffBase}), the one case its + * catalog decides: a title equal to the base's reads the deployment catalog, + * which already holds the pair's share. So an object list whose tab titles no + * arrangement changed pays no translation read (ADR-0090 D10's statement + * budget, `mcp-list-objects-statements.pin.test.ts` in `@objectstack/runtime`). */ async function objectPairRelatedListsBundleOf( protocol: unknown, type: string, - name: unknown, + served: unknown, packagedBase: unknown, memo?: Map>, ): Promise { + const name = (served as Record | null | undefined)?.name; if (type !== 'object' || typeof name !== 'string' || name === '') return undefined; - const base = packagedBase && typeof packagedBase === 'object' - ? (packagedBase as Record)._packageId - : undefined; + if (!packagedBase || typeof packagedBase !== 'object') return undefined; + if (!hasRelatedListTitleOffBase(served, packagedBase as Record)) return undefined; + const base = (packagedBase as Record)._packageId; const pair = await pairTranslationBundleOfBase(protocol, base, memo); if (!pair || typeof pair !== 'object') return undefined; const slice: Record = {}; @@ -3700,6 +3708,29 @@ async function objectPairRelatedListsBundleOf( return Object.keys(slice).length > 0 ? slice : undefined; } +/** + * Whether `served` carries an object-form `relatedLists` entry whose non-empty + * `label` the packaged base's entry for the same `list` does not carry — the + * divergence `translateObjectRelatedLists` (`@objectstack/spec/system`) judges + * a title by, where an entry the base does not name counts as diverged. + */ +function hasRelatedListTitleOffBase(served: unknown, packagedBase: Record): boolean { + const lists = (served as Record | null | undefined)?.relatedLists; + if (!Array.isArray(lists)) return false; + const baseLabels = new Map(); + for (const raw of Array.isArray(packagedBase.relatedLists) ? packagedBase.relatedLists : []) { + if (raw && typeof raw === 'object' && typeof (raw as any).list === 'string' && !baseLabels.has((raw as any).list)) { + baseLabels.set((raw as any).list, (raw as any).label); + } + } + return lists.some((raw) => { + if (!raw || typeof raw !== 'object') return false; + const { list, label } = raw as Record; + return typeof list === 'string' && list !== '' && typeof label === 'string' && label !== '' + && baseLabels.get(list) !== label; + }); +} + /** A non-empty string, or `undefined`. */ function nonEmptyText(value: unknown): string | undefined { return typeof value === 'string' && value.length > 0 ? value : undefined; @@ -3883,7 +3914,7 @@ export async function translateMetaList( const pairBundle = p === undefined ? undefined : (await pairTranslationBundleOf(p, metaType, item, pairBundles)) - ?? (await objectPairRelatedListsBundleOf(p, metaType, item?.name, packagedBase, pairBundles)); + ?? (await objectPairRelatedListsBundleOf(p, metaType, item, packagedBase, pairBundles)); const patchBundles = p === undefined ? undefined : await patchTranslationBundlesOf(p, metaType, item?.name, packageBundles); const out = translateMetadataDocument(metaType, item, bundle, { ...metaTranslateOptions(i18n, locale), @@ -3963,7 +3994,7 @@ export async function translateMetaDocument( const pairBundle = p === undefined ? undefined : (await pairTranslationBundleOf(p, metaType, document)) - ?? (await objectPairRelatedListsBundleOf(p, metaType, (document as any)?.name, packagedBase)); + ?? (await objectPairRelatedListsBundleOf(p, metaType, document, packagedBase)); // [#33952] Each patching package's own translations: a patched field slot's second rank. const patchBundles = p === undefined ? undefined : await patchTranslationBundlesOf(p, metaType, (document as any)?.name); const translated = translateMetadataDocument(metaType, document as any, bundle, { diff --git a/packages/rest/src/meta-object-related-list-pair-i18n.test.ts b/packages/rest/src/meta-object-related-list-pair-i18n.test.ts index 1f3a78b707e..faca260992d 100644 --- a/packages/rest/src/meta-object-related-list-pair-i18n.test.ts +++ b/packages/rest/src/meta-object-related-list-pair-i18n.test.ts @@ -127,6 +127,10 @@ function boot(opts: Boot = {}) { }, }; const protocol = new ObjectStackProtocolImplementation(engine as never, undefined, 'env_test'); + // Every question the reads put to the pair's catalog, for the statement-budget pin. + let pairAsks = 0; + const askPair = protocol.getPairTranslationBundle.bind(protocol); + (protocol as unknown as { getPairTranslationBundle: typeof askPair }).getPairTranslationBundle = (base) => { pairAsks++; return askPair(base); }; const catalog = (locale: string) => overlay(BASE_CATALOG[locale], opts.pairObjects?.[locale] && { objects: opts.pairObjects[locale] }); const i18nService = { @@ -165,12 +169,13 @@ function boot(opts: Boot = {}) { .map((entry: any) => (typeof entry === 'string' ? entry : entry?.label ?? entry?.list)); /** `crm_account` on the by-name read and on the list read: its label and its tab titles. */ - return async (locale: string) => { + const readAt = async (locale: string) => { const byName = (await run('/api/v1/meta/:type/:name', { type: 'object', name: 'crm_account' }, locale))?.item; const listBody = await run('/api/v1/meta/:type', { type: 'object' }, locale); const listed = (Array.isArray(listBody) ? listBody : listBody?.items ?? []).find((o: any) => o?.name === 'crm_account'); return [byName, listed].map((doc) => ({ label: doc?.label, tabs: titles(doc) })); }; + return Object.assign(readAt, { pairAsks: () => pairAsks }); } /** The arrangement: relabels the owner's labelled tab and titles its bare one. */ @@ -223,4 +228,15 @@ describe('#37622 — controls', () => { }); for (const served of await pairFirst('zh-CN')) expect(served.tabs).toEqual(['人员', 'crm_case']); }); + + it('asks the pair\'s catalog only for an object whose tab titles an arrangement changed (ADR-0090 D10 budget)', async () => { + for (const extension of [undefined, { relatedLists: [{ list: 'crm_contact', label: 'Contacts' }, 'crm_case'] }]) { + const read = boot({ extension, pairObjects: { 'zh-CN': { crm_account: { _relatedLists: { crm_contact: { label: '人员' } } } } } }); + await read('zh-CN'); + expect(read.pairAsks()).toBe(0); + } + const changed = boot({ extension: ARRANGEMENT }); + await changed('zh-CN'); + expect(changed.pairAsks()).toBeGreaterThan(0); + }); });