Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .changeset/36595-related-list-key-under-arrangement.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
'@objectstack/lint': minor
'@objectstack/spec': patch
---

fix(lint)!: a `_relatedLists` translation key over a list the `.custom` arrangement hides or re-states without a label is refused, as nothing reads it

Clause-②: no (narrowing)
Metadata-protocol: narrowed
Skills-docs: follow-up #37620

<!-- adr-0087: registered translation-related-list-key-under-arrangement-refused -->

**BREAKING** for a translation bundle that carries `objects.<object>._relatedLists.<list>` over a list the object's owner labels but the paired `.custom` package's `relatedLists` (ADR-0146 D10) re-states. `objectstack validate` and the other doors that run `translation-target-unknown` now report such a key as an error, where 18.x accepted it. Drop the key, or re-state the arrangement's entry with the owner's own `label` (`{ list, label }`) and keep it: an object read translates a label only while it still equals the packaged one.

**Why.** The registry applies the `.custom` arrangement after the owner's tab list and every `place` entry, and each arrangement entry replaces every entry it covers: the same list, or, for a bare child name, every list of that child (`relatedListNameCovers`). An entry `{ list, hidden: true }` leaves no tab, and a bare name or an entry with no `label` leaves the tab titled by the child lookup field's `relatedListTitle`. In both cases the served object has no `label` on that list for the key to translate. The rule judged the owner's label first and accepted the key before it looked at the arrangement, and it never saw the arrangement's bare names.

**What changes in `@objectstack/lint`.**

- The rule folds the arrangement's entries after the owner's entries and every placement, as the registry does. A list the arrangement labels resolves. A list it hides, names bare or names without a label does not resolve, whatever label the owner or a placement gave it; a labelled bare child such as `{ list: 'event', label }` covers the owner's `event.related_to` too. Lists the arrangement does not cover keep what they had. Each arrangement is read in two passes, as the registry reads it, so one entry never strips the label a sibling entry of the same arrangement gives (`[{ list: 'event.related_to', label }, 'event']` resolves in either order).
- A key over a list the arrangement hides gets the "hidden by the `.custom` arrangement" message, now also when a bare child name such as `{ list: 'event', hidden: true }` hides a dotted list such as `event.related_to`. A key over an owner-labelled list the arrangement re-states without a label names the arrangement too, and its hint points at the owner's `label`.
- `VisibleObjectExtension` (`object-graph.ts`, internal) carries the extension's `relatedLists` as written, bare names included, as `relatedListArrangement`.

Measured first-party exposure: none. No example or first-party package ships a `.custom` arrangement that re-states an owner-labelled list together with a key for it.
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 |
| `objects.{object}._relatedLists.{list}` | the `list` of an object-form `relatedLists` entry on that object that authors a `label` — a dotted `object.field` is one key; a key over an entry with no `label`, a bare-string entry or a built-in tab is an orphan, because that tab's title is the child lookup field's `relatedListTitle`, translated on the child. The paired `.custom` arrangement's `relatedLists` is applied after the owner's list and every placement: a list it hides, names bare or names without a `label` is an orphan whatever label the owner gave it, and a list it labels resolves |
| `objects.{object}._validations.{rule}` | a validation rule's `name` in that object's `validations[]` or in an `objectExtensions[]` entry aimed at it — a `conditional` rule's `then` / `otherwise` branch included |
| `objects.{object}._actions.{action}` | an action bound to that object: one in its `actions`, or a stack-level action whose `objectName` is that object |
| `globalActions.{action}` | an action with **no** `objectName` — a key naming a bound action is an error whose message names the `objects.{owner}._actions.{action}` key to write instead, `{owner}` being the action's own `objectName` |
Expand Down
117 changes: 117 additions & 0 deletions packages/lint/src/i18n-related-lists-arrangement-36595.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
//
// [#36595] `objects.<object>._relatedLists.<list>` against the paired `.custom`
// arrangement (ADR-0146 D10). The registry applies the arrangement after the
// owner's list and every placement, and each of its entries REPLACES every
// entry it covers (`registry-custom-arrangement.ts`): a bare name or an
// unlabelled entry leaves the tab no `label` to translate, and
// `{ list, hidden: true }` leaves no tab at all. A key over a list the owner
// labelled but the arrangement re-states that way is read by nothing, and the
// translation-reference rule says so.

import { describe, it, expect } from 'vitest';
import { validateTranslationReferences, TRANSLATION_TARGET_UNKNOWN } from './validate-translation-references.js';

const ACCOUNT = {
name: 'account',
label: 'Account',
fields: { name: { name: 'name', type: 'text', label: 'Name' } },
relatedLists: [
{ list: 'contact', label: 'People' },
{ list: 'event.related_to', label: 'Meetings' },
'case',
],
};

const KEY = (list: string) =>
`translations[0]["zh-CN"].objects.account._relatedLists${list.includes('.') ? `["${list}"]` : `.${list}`}`;

function judge(objectExtensions: unknown[], keys: Record<string, unknown>) {
return validateTranslationReferences({
objects: [ACCOUNT],
objectExtensions,
translations: [{ 'zh-CN': { objects: { account: { _relatedLists: keys } } } }],
});
}

describe('validateTranslationReferences — _relatedLists under a `.custom` arrangement (#36595)', () => {
it('flags a key over an owner-labelled list the arrangement hides, saying it is hidden', () => {
const findings = judge(
[{ extend: 'account', relatedLists: [{ list: 'contact', hidden: true }] }],
{ contact: { label: '联系人' } },
);
expect(findings.map((f) => [f.rule, f.severity, f.path])).toEqual([[TRANSLATION_TARGET_UNKNOWN, 'error', KEY('contact')]]);
expect(findings[0].message).toContain('hidden');
expect(findings[0].message.length).toBeLessThanOrEqual(200);
});

it('flags a key over an owner-labelled list the arrangement names bare, or as an entry with no label', () => {
for (const restated of ['contact', { list: 'contact' }, { list: 'contact', hidden: false }]) {
const findings = judge([{ extend: 'account', relatedLists: [restated] }], { contact: { label: '联系人' } });
expect(findings.map((f) => f.path), JSON.stringify(restated)).toEqual([KEY('contact')]);
expect(findings[0].message, JSON.stringify(restated)).toContain('carries no `label` in the `.custom` arrangement');
expect(findings[0].hint, JSON.stringify(restated)).toContain("owner's `label`");
expect(findings[0].message.length).toBeLessThanOrEqual(200);
expect(findings[0].hint.length).toBeLessThanOrEqual(200);
}
});

it('a bare child hides or strips every list of that child: the dotted owner entry included', () => {
const hidden = judge(
[{ extend: 'account', relatedLists: [{ list: 'event', hidden: true }] }],
{ 'event.related_to': { label: '会议' } },
);
expect(hidden.map((f) => f.path)).toEqual([KEY('event.related_to')]);
expect(hidden[0].message).toContain('hidden');
const bare = judge([{ extend: 'account', relatedLists: ['event'] }], { 'event.related_to': { label: '会议' } });
expect(bare.map((f) => f.path)).toEqual([KEY('event.related_to')]);
});

it('one arrangement entry never strips what a sibling entry of the same arrangement wrote, in either order', () => {
// The registry collects the arrangement's entries first, then drops what
// they cover from the owner's list: a bare child beside its labelled
// dotted list leaves that label served.
for (const arrangement of [[{ list: 'event.related_to', label: 'Meetings' }, 'event'], ['event', { list: 'event.related_to', label: 'Meetings' }]]) {
expect(judge([{ extend: 'account', relatedLists: arrangement }], { 'event.related_to': { label: '会议' } }), JSON.stringify(arrangement))
.toEqual([]);
}
// A sibling that would cancel a `hidden` entry is a list both shown and
// hidden in one arrangement, which the object schema refuses at save
// (`refuseContradictoryRelatedListEntries`), so it has no pin here.
});

it('applies the arrangement after every placement, whatever the extensions\' order', () => {
// Two packages: the placing one folds AFTER the arrangement's (higher
// priority, later in the artifact), and the arrangement still replaces
// the placed entry, as the registry applies it.
const findings = validateTranslationReferences({
packages: [
{ manifest: { id: 'com.example.crm.custom', objectExtensions: [{ extend: 'account', priority: 100, relatedLists: ['quote'] }] } },
{ manifest: { id: 'com.example.quotes', objectExtensions: [{ extend: 'account', priority: 300, place: [{ list: 'quote', after: 'contact', label: 'Quotes' }] }] } },
],
objects: [ACCOUNT],
translations: [{ 'zh-CN': { objects: { account: { _relatedLists: { quote: { label: '报价' } } } } } }],
});
expect(findings.map((f) => f.path)).toEqual([KEY('quote')]);
});

it('accepts a key over a list the arrangement labels, and over owner lists it does not cover', () => {
expect(judge(
[{ extend: 'account', relatedLists: [{ list: 'contact', label: 'Clients' }, { list: 'event.owner_id', hidden: true }] }],
{ contact: { label: '客户' }, 'event.related_to': { label: '会议' } },
)).toEqual([]);
// One relationship does not cover its sibling or its bare child.
expect(judge(
[{ extend: 'account', relatedLists: ['event.owner_id', 'case'] }],
{ contact: { label: '联系人' }, 'event.related_to': { label: '会议' } },
)).toEqual([]);
});

it('control: with no arrangement, the owner\'s labels resolve as before', () => {
expect(judge([], { contact: { label: '联系人' }, 'event.related_to': { label: '会议' } })).toEqual([]);
expect(judge(
[{ extend: 'account', place: [{ list: 'quote', after: 'contact', label: 'Quotes' }] }],
{ contact: { label: '联系人' }, quote: { label: '报价' } },
)).toEqual([]);
});
});
12 changes: 12 additions & 0 deletions packages/lint/src/object-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,17 @@ export interface VisibleObjectExtension {
* `validations`, carrying them changes nothing about which entries survive.
*/
relatedListEntries: AnyRec[];
/**
* [#36595] Its `relatedLists` as written, bare names included (`undefined`
* when it writes none): the `.custom` arrangement (ADR-0146 D10). Where the
* key is written, each entry REPLACES every entry of the owner and of the
* placements that it covers (`relatedListNameCovers`), so a bare name or an
* unlabelled entry takes a title away and `{ list, hidden: true }` takes the
* tab away (`registry-custom-arrangement.ts`, `@objectstack/objectql`). The
* one reader that needs the bare names is the `_relatedLists.LIST` check of
* `validate-translation-references.ts`.
*/
relatedListArrangement?: unknown[];
/**
* [#33494] Set on an entry the host's registry already holds
* ({@link StoredObjectExtension}), folded in at its priority but never
Expand Down Expand Up @@ -510,6 +521,7 @@ export function objectExtensionsByTarget(
...(Array.isArray(ext.relatedLists) ? ext.relatedLists : []),
...(Array.isArray(ext.place) ? ext.place : []),
].filter(isRec),
...(Array.isArray(ext.relatedLists) ? { relatedListArrangement: ext.relatedLists } : {}),
label: ext.label,
fieldPatches: isRec(ext.fieldPatches)
? Object.fromEntries(
Expand Down
82 changes: 65 additions & 17 deletions packages/lint/src/validate-translation-references.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ import {
pageTabItemKey,
walkAddressedPageComponents,
} from '@objectstack/spec/system';
import { isRecordPageBuiltinTab, relatedListEntryHidden } from '@objectstack/spec/data';
import { isRecordPageBuiltinTab, relatedListEntryHidden, relatedListEntryName, relatedListNameCovers } from '@objectstack/spec/data';
import { walkFlowNodes } from './flow-walk.js';
import { objectExtensionsByTarget, packagesOf, recordsOf, suggestName } from './object-graph.js';
import { walkPageComponents } from './page-walk.js';
Expand Down Expand Up @@ -501,6 +501,12 @@ interface ObjectFacts {
* only to say so.
*/
relatedListHidden: Set<string>;
/**
* The lists whose label (from the owner or a placement) a `.custom`
* arrangement entry replaced with none: the tab shows, untitled by any
* `label` — read only to name the arrangement in the finding.
*/
relatedListStripped: Set<string>;
}

/** Everything a `flows.<name>.screens.<node_id>` key may legally name. */
Expand Down Expand Up @@ -671,6 +677,7 @@ function emptyFacts(): ObjectFacts {
relatedListLabels: new Set(),
relatedListNames: new Set(),
relatedListHidden: new Set(),
relatedListStripped: new Set(),
};
}

Expand Down Expand Up @@ -1424,27 +1431,61 @@ function buildUniverse(stack: AnyRec): Universe {
const key = strName(group.key);
if (key) facts.sections.add(key);
}
// `_relatedLists.<list>` is keyed by a labelled entry's `list`: a
// `.custom` arrangement's `relatedLists` entry (ADR-0146 D10) and a
// list placement's `place` entry each title a tab of the target, and
// where the target declares `relatedLists` the served target carries
// that entry, which `translateObject` translates as it does the
// target's own (a placed entry is part of the packaged base it is
// compared with, `getPackagedObjectBase`). A placement on a target
// that declares none is not applied, and its key is accepted here all
// the same: this fold does not read whether the target declares the
// list. An arrangement entry with `hidden: true` titles no tab.
// `_relatedLists.<list>` 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<unknown>(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 (relatedListEntryHidden(entry)) {
facts.relatedListHidden.add(list);
continue;
}
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);
}
}
}
}

// ── Stack-level views: `_views` names + form-section names ──
Expand Down Expand Up @@ -2156,11 +2197,18 @@ export function validateTranslationReferences(stack: AnyRec): TranslationRefFind
`Drop this key: a built-in tab takes no \`label\` here.`);
continue;
}
if (facts.relatedListHidden.has(listName)) {
if ([...facts.relatedListHidden].some((hidden) => relatedListNameCovers(hidden, listName))) {
orphan(listWhere, listPath,
`Related list "${listName}" of object "${objectName}" is hidden by the \`.custom\` ` +
`arrangement (\`hidden: true\`), so no tab shows a title from this key.`,
`Drop this key, or show the tab (drop \`hidden\`) and give the entry a \`label\`.`);
`Drop this key, or show the tab (drop \`hidden\`) with the owner's \`label\` on the entry.`);
continue;
}
if (facts.relatedListStripped.has(listName)) {
orphan(listWhere, listPath,
`Related list "${listName}" of object "${objectName}" carries no \`label\` in the \`.custom\` ` +
`arrangement, which replaces the owner's entry, so no title reads this key.`,
`Drop this key, or re-state the arrangement's entry with the owner's \`label\` ({ list, label }).`);
continue;
}
const named = facts.relatedListNames.has(listName);
Expand Down
Loading
Loading