Skip to content
Merged
23 changes: 23 additions & 0 deletions .changeset/37622-related-list-keys-agree-under-arrangement.md
Original file line number Diff line number Diff line change
@@ -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

<!-- adr-0087: not-required (no-migration-prescription) no schema key, accepted value, stored shape or export moves; the moved answers are the coverage gate's expected key set and the translation an object read serves, and the remedy is a translation the author adds or drops in a bundle, which no conversion can write -->

**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.<object>._relatedLists.<list>.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.<object>._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.
2 changes: 1 addition & 1 deletion content/docs/protocol/kernel/i18n-standard.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
33 changes: 33 additions & 0 deletions packages/cli/test/i18n-coverage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
});
});
74 changes: 70 additions & 4 deletions packages/lint/src/i18n-related-lists-arrangement-36595.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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);
}
Expand All @@ -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', () => {
Expand Down Expand Up @@ -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([]);
});
});
60 changes: 40 additions & 20 deletions packages/lint/src/i18n-walk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,12 @@
* objects.<name>._validations.<rule>.message
* objects.<name>._milestones.<field>.<value>.summary (an `activityMilestones`
* entry's summary template)
* objects.<name>._relatedLists.<list>.label (an object-form `relatedLists`
* entry that authors a `label`)
* objects.<name>._relatedLists.<list>.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.<name>._actions.<action>.label
* objects.<name>._actions.<action>.description
* objects.<name>._actions.<action>.confirmText
Expand Down Expand Up @@ -202,6 +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 { objectExtensionsByTarget } from './object-graph.js';
import { addOwnerRelatedLists, emptyRelatedListTitles, foldRelatedListExtensions } from './related-list-titles.js';

// ─── Public types ──────────────────────────────────────────────────────

Expand Down Expand Up @@ -1047,23 +1053,34 @@ function pushMilestoneSummaries(out: ExpectedEntry[], objectName: string, milest
}

/**
* Emit `objects.<object>._relatedLists.<list>.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.<object>._relatedLists.<list>.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<typeof foldRelatedListExtensions>[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 });
}
}
Expand Down Expand Up @@ -1580,6 +1597,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;
Expand Down Expand Up @@ -1710,11 +1729,12 @@ export function collectExpectedEntries(

// Record-page related-list titles (`_relatedLists.<list>.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 ──────────────────────────────────────────────
Expand Down
Loading
Loading