Skip to content

Commit aff34ba

Browse files
fix(approvals,audit): flow and position labels, and a renamed object's label, read as the metadata translators serve them (#36598)
<!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi91tYCagMT6JaQ6YA5YqnWwi)_ Part of #35384 Clause-②: no Metadata-protocol: none ## 维护者速读 - 应用以英文编写、默认给用户中文的部署里,英文读者在审批收件箱、审批详情和时间线上看到的流程名与岗位名,从中文改回作者写的英文;被代码扩展改过名的对象,在审批和动态摘要里也显示新名字,与元数据接口一致。 - 属于「标签按读者语言显示」的收尾工作,替英文读者和改过对象名的应用解决「看到默认语言或旧名字」的问题。 - 出错时读者看到的是改动前的标签(中文或旧对象名),不影响数据,可直接撤回本改动。 - 请决定审批步骤名是否另开一张卡:它暂时仍走旧的查词方式,需要规范包新增一个读取函数。 ## What changes This is stage 2 of #35384: items 2 and 3 of the remainder in release comment 7082136476. Item 1 (the approval notification subject param in service-messaging) is not in this PR, and neither is the approval STEP label (see Acceptance notes). That is why this PR says `Part of`. - **Item 2: flow and position labels in the approvals door** (`plugin-approvals/src/reader-locale-labels.ts`). `readerLabelsFor().flowLabel` and `.positionLabel` no longer go through `t()`, which falls back to the `defaultLocale` row. Each now uses the spec translator for its type, over every locale the i18n service holds, with the resolve options the metadata route builds (the reader's negotiated locale, the declared fallback chain, and the authored language: `sourceLocale`, else `defaultLocale`): - position: `translatePosition`, which `GET /meta/position` serves through `translateMetadataDocument`; - flow: `translateFlow`. `/meta` serves a flow document untranslated: `translateFlow` is deliberately not in the dispatch table, and the flow runner applies it on the client. So `translateFlow` is the spec's one reading of `flows.FLOW.label`. - Callers that pick these up with no change: the inbox, the request page, the generic data door's request rows (`reader-locale-labels-middleware.ts`), and timeline position notes. - **Item 3: a renamed packaged object.** `objectLabel` (approvals) and `translatedObjectDef` (audit) now give `translateObject` the object's served definition and its packaged base as `packagedBase`. The base comes from the engine's registry (`registry.getPackagedObjectBase(name)`). That is the same body the metadata protocol's `getPackagedObjectBase` reads (`engine.registry`), and the protocol accessor is how `/meta` and #36460's share-link label get `packagedBase`. - approvals: `readerLabelsFor` takes an optional third argument, `ReaderObjectSource` (`getSchema`, `registry`). `ApprovalService.readerLabels` and the two lock-refusal sentences in `lifecycle-hooks.ts` pass the engine they already hold. - audit: `installActivitySummaryLocale` reads the base off the engine it is installed on, and `readerSummaryLocale` takes an optional `getPackagedObjectBase`. - No public surface moves. The changed functions and types are internal modules, not exported from either package's index. `ApprovalServiceOptions` and `ApprovalEngine` are unchanged. Nothing under `packages/spec/src/**` or `packages/services/service-messaging/**` is edited. ## Tests - `reader-locale-labels.test.ts` (the shared harness), two new top-level describes: - Flow and position labels in a `sourceLocale: 'en'` / `defaultLocale: 'zh-CN'` deployment with an `en` pack. First the precondition: `t()` gives an `en` reader the zh-CN rows. Then `en` and `en-US` readers pick nothing, so the authored snapshot stands. A pin measures that `en-US` is negotiated to `en`. Controls: a zh-CN reader, an `en` pack entry, no `sourceLocale` declared, a `t()`-only service, and one bundle per read. - A renamed packaged object over a real `SchemaRegistry` (a packaged `Opportunity` that an extension renames `Deal`). `en`, `en-US` and `zh-CN` readers read `Deal`, and so does the oracle `translateMetadataDocument('object', served, bundle, {...options, packagedBase})`. Controls: an unrenamed object, a registry that throws, and a `getSchema` that throws. - Fixture triage (change of spelling): two older `#24863` cases that used a `t()`-only double for `flowLabel` now ask `stepLabel`, the one label still on `t()`. - `activity-summary-message.test.ts`: a new top-level describe drives the installed `sys_activity` middleware over a real `SchemaRegistry`. `en`, `en-US` and `zh-CN` readers get `Deal`, and the zh-CN field label still translates. Controls: an unrenamed object, and a registry whose base read throws. <details><summary>Readings at head 0e31535</summary> - `pnpm --filter @objectstack/plugin-approvals test`: Test Files 127 passed (127), Tests 1880 passed (1880). - `pnpm --filter @objectstack/plugin-audit test`: Test Files 109 passed (109), Tests 1821 passed (1821). - `pnpm --filter @objectstack/plugin-approvals --filter @objectstack/plugin-audit typecheck` (tsc, scripts tsconfig, `check:test-typecheck`): lock VERDICT command-exit 0. - Ablation. One lock call, `scripts/ablation-replace.mjs` per leg, plus a trap restore. The subject resolves from `src/` (relative import), so there is no dist leg. - leg 1, approvals `objectLabel` without `packagedBase`: 3 failed / 37 (the `en`, `en-US` and `zh-CN` rename cases). - leg 2, `flowLabel` back on `t()`: 3 failed / 37 (the `en` and `en-US` authored cases, and the `t()`-only case). - leg 3, `positionLabel` back on `t()`: 3 failed / 37 (the same three). - leg 4, audit `translatedObjectDef` without `packagedBase`: 3 failed / 24 (the `en`, `en-US` and `zh-CN` rename cases). - Each leg: anchor x1 to x0 on disk, then restored with blob equal to HEAD. Final hashes match HEAD, and `git diff HEAD` is empty. - `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` @0e315358fa: 72 families. 70 exit 0. 2 NOT MEASURED (exit 3, PREREQUISITE NOT MET): `check:dual-build-cjs-loads` (needs a full build) and `check:i18n` (needs the built CLI closure); CI runs both. `--ran`: 72 derived, 70 run, 2 NOT-MEASURED, 0 UNRUN. - `node scripts/pm/overlap-check.mjs --branch=HEAD` @0e315358fa: VERDICT clean exit 0. </details> ## Acceptance notes - **The approval step label (`flows.FLOW.approvals.NODE.label`) is still read through `t()`.** No spec translator reads that key: `translateFlow` overlays the flow label, the toasts and screen copy only. Reading the bundle along the locale chain inside plugin-approvals would be a second resolver beside `localeChain`. A spec export would widen `@objectstack/spec`, which this slice may not do. So an `en` reader in such a deployment still sees the zh-CN step label next to the authored flow label. The fork goes to the seat as an open question in the report. - PM mechanism assumption, measured: `/meta` does not translate flows. `GET /meta/flow` serves the authored document, so the flow side uses `translateFlow` (the same translator, with the same resolve options), not a `/meta` read. - The packaged base comes from the engine's registry, not from the `protocol` service. It is the same body, the engine is already in hand at every caller, and `ApprovalServiceOptions` stays unchanged. - File surface: `approval-service.ts` (one argument) and `lifecycle-hooks.ts` (two arguments) are beyond the claim's listed files. They are the callers that hand `objectLabel` its engine. ## Verification Read first, by risk: 1. `packages/plugins/plugin-approvals/src/reader-locale-labels.ts`: the `readerLabelsFor` body (`translated`, `flowLabel`, `positionLabel`, `objectLabel`). 2. `packages/plugins/plugin-audit/src/activity-summary-message.ts`: `translatedObjectDef` and `packagedObjectBaseReader`. 3. `packages/plugins/plugin-approvals/src/lifecycle-hooks.ts`: the two `readerLabelsFor(service, locale, engine)` calls. Two-minute check: `pnpm --filter @objectstack/plugin-approvals exec vitest run src/reader-locale-labels.test.ts` should report 37 passed. The `[#35384]` describes cover `en` and `en-US` readers with authored flow and position labels, and the rename `Deal` in every locale. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01ADHkmPTDM2MxHR8cvoMVUX <!-- signed: repo:objectstack#2 · os-steve · session_01ADHkmPTDM2MxHR8cvoMVUX --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 7501d0c commit aff34ba

7 files changed

Lines changed: 484 additions & 43 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
'@objectstack/plugin-approvals': patch
3+
'@objectstack/plugin-audit': patch
4+
---
5+
6+
fix(approvals,audit): an approval's flow and position labels, and a renamed object's label in approvals and activity summaries, read as the metadata translators serve them
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
In a deployment whose `i18n.sourceLocale` differs from its `i18n.defaultLocale` (an app authored in English that defaults its users to Chinese, say), the approvals door still looked up a request's flow label (`flows.<flow>.label`) and a position's label (`positions.<name>.label`) through `II18nService.t()`, which falls back to the `defaultLocale` row when the reader's locale has no entry. So an `en` or `en-US` reader saw the Chinese flow name on the inbox, the request page and the generic data door's request rows, and the Chinese position name in a timeline note, where the authored text was expected. Both labels now resolve through the spec translators of their types (`translateFlow`, `translatePosition` from `@objectstack/spec/system`) over every locale the i18n service holds. They use the resolve options the metadata route builds: the reader's locale, the declared fallback chain, and the authored language (the declared `sourceLocale`, else `defaultLocale`). A reader in the authored language now reads the label as written, and every other reader reads the same row as before.
12+
13+
A packaged object renamed by a code extension was named in the reader's language by the bundle's translation of its OLD label. This hit the approvals inbox, request page and object-naming refusals, and the object label inside an activity summary, where `GET /meta/object` serves the rename. Both readers now hand `translateObject` the object's served definition and its packaged base (`packagedBase`, read off the engine's registry through `getPackagedObjectBase`, the base `/meta` reads). So the rename stands in every locale, as on `/meta`, and an unrenamed object reads its translation as before.
14+
15+
An approval step's label (`flows.<flow>.approvals.<node_id>.label`) is still read through `t()`: no spec translator reads that key yet.

‎packages/plugins/plugin-approvals/src/approval-service.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10937,6 +10937,10 @@ export class ApprovalService implements IApprovalService, ObjectSchemaReadDelega
1093710937
* a reader: the list ({@link listRequests}: the inbox and the record's
1093810938
* approval panel), and the get and a decision's echo ({@link loadRequest}),
1093910939
* whose step progress ({@link attachFlowSteps}) names its steps the same way.
10940+
*
10941+
* [#35384] The engine is where an object's label is served from: its served
10942+
* definition and its packaged base, so a renamed object is named by its
10943+
* rename, as `/meta` names it.
1094010944
*/
1094110945
private readerLabels(context: ExecutionContext): ReaderLabels | undefined {
1094210946
let service: ReaderLabelI18n | undefined;
@@ -10946,7 +10950,7 @@ export class ApprovalService implements IApprovalService, ObjectSchemaReadDelega
1094610950
// The i18n service is optional and late-bound: the stored labels stand.
1094710951
return undefined;
1094810952
}
10949-
return readerLabelsFor(service, context?.locale);
10953+
return readerLabelsFor(service, context?.locale, this.engine);
1095010954
}
1095110955

1095210956
async countRequests(

‎packages/plugins/plugin-approvals/src/lifecycle-hooks.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -768,9 +768,10 @@ export function bindApprovalLockHook(
768768
: undefined;
769769
// The sentence is in the writer's locale, and so is the label it names:
770770
// the translated `objects.<object>.label` when the pack carries one, else
771-
// the declared label. ⛔ Never the API name.
771+
// the declared label. ⛔ Never the API name. [#35384] The engine hands
772+
// the label its served definition and packaged base, as `/meta` reads them.
772773
const { locale, service, translate } = refusalLocalization(ctx, i18nService);
773-
const objectLabel = readerLabelsFor(service, locale)?.objectLabel(object) ?? declaredLabel;
774+
const objectLabel = readerLabelsFor(service, locale, engine)?.objectLabel(object) ?? declaredLabel;
774775
// `previous` is the pre-image the engine already read for THIS row; it is
775776
// used only when it really is the row this pending request names, so a
776777
// dispatch that ever carried a different row cannot title the wrong
@@ -1065,7 +1066,7 @@ export function bindDetailRowLockHook(
10651066
? String((schema as any).label)
10661067
: undefined;
10671068
const { locale, service, translate } = refusalLocalization(ctx, i18nService);
1068-
const masterLabel = readerLabelsFor(service, locale)?.objectLabel(master) ?? declaredLabel;
1069+
const masterLabel = readerLabelsFor(service, locale, engine)?.objectLabel(master) ?? declaredLabel;
10691070
return recordLockRefusal(masterLabel, undefined, locale, translate);
10701071
};
10711072

‎packages/plugins/plugin-approvals/src/reader-locale-labels.test.ts‎

Lines changed: 187 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@
2121

2222
import { describe, it, expect } from 'vitest';
2323
import { createMemoryI18n } from '@objectstack/core';
24-
import { TranslationDataSchema, objectLabelKey } from '@objectstack/spec/system';
24+
import { SchemaRegistry } from '@objectstack/objectql';
25+
import { TranslationDataSchema, objectLabelKey, translateMetadataDocument } from '@objectstack/spec/system';
2526

2627
import {
2728
approvalStepLabelKey,
2829
flowLabelKey,
2930
flowNameOfProcess,
3031
localizeRequestLabels,
32+
negotiatedReaderLocale,
3133
positionLabelKey,
3234
readerLabelsFor,
3335
type ReaderLabelI18n,
@@ -108,11 +110,12 @@ describe('[#24863] the pick', () => {
108110

109111
it('negotiates through `resolveBundleLocale` even for a service that resolves exactly', () => {
110112
// A service that answers only the exact tag it holds, as `FileI18nAdapter` does.
113+
// [#35384] Asked of the step's label, the one label still read through `t()`.
111114
const exact: ReaderLabelI18n = {
112-
t: (key, locale) => (locale === 'zh-CN' && key === flowLabelKey('f') ? '流程' : key),
115+
t: (key, locale) => (locale === 'zh-CN' && key === approvalStepLabelKey('f', 'n') ? '步骤' : key),
113116
getLocales: () => ['en', 'zh-CN'],
114117
};
115-
expect(readerLabelsFor(exact, 'zh')!.flowLabel('f')).toBe('流程');
118+
expect(readerLabelsFor(exact, 'zh')!.stepLabel('f', 'n')).toBe('步骤');
116119
});
117120

118121
it('picks nothing on a miss: no entry, an empty entry, a blank entry', () => {
@@ -145,9 +148,9 @@ describe('[#24863] the pick', () => {
145148
const asked: string[] = [];
146149
const counting: ReaderLabelI18n = { t: (key) => { asked.push(key); return key; } };
147150
const labels = readerLabelsFor(counting, 'zh-CN')!;
148-
labels.flowLabel('f');
149-
labels.flowLabel('f');
150-
expect(asked).toEqual([flowLabelKey('f')]);
151+
labels.stepLabel('f', 'n');
152+
labels.stepLabel('f', 'n');
153+
expect(asked).toEqual([approvalStepLabelKey('f', 'n')]);
151154
});
152155
});
153156

@@ -280,3 +283,181 @@ describe('[#35384] the object label in the declared sourceLocale reads as author
280283
expect(readerLabelsFor(throwing, 'zh-CN')!.objectLabel('account')).toBeUndefined();
281284
});
282285
});
286+
287+
/**
288+
* [#35384] The flow's and the position's labels are metadata too, so they are
289+
* resolved by the spec translators of their types — `translateFlow` (the
290+
* flow runner's reading of `flows.<flow>.label`; `/meta` serves a flow
291+
* document untranslated) and `translatePosition` (what `GET /meta/position`
292+
* serves) — with `/meta`'s `ResolveOptions`, and never through `t()`.
293+
*
294+
* The scenario: an app authored in English (`sourceLocale: 'en'`) that
295+
* defaults its users to Chinese (`defaultLocale: 'zh-CN'`, declared fallback
296+
* `zh-CN`) and ships an `en` pack beside the `zh-CN` one, which holds neither
297+
* label. `t('flows.<flow>.label', 'en')` falls to the `zh-CN` row; an `en` and
298+
* an `en-US` reader must read the authored label (the stored snapshot). An
299+
* `en-US` reader is negotiated to the `en` pack first, the authored language.
300+
* CONTROLS: a `zh-CN` reader reads the `zh-CN` rows, an `en` pack entry is
301+
* read by an `en` reader, and with no `sourceLocale` declared an `en` reader
302+
* walks the declared fallback to the `zh-CN` rows.
303+
*/
304+
describe('[#35384] the flow and position labels in the declared sourceLocale read as authored', () => {
305+
const EN = { [flowLabelKey('other_flow')]: 'Other flow' };
306+
const declared = (sourceLocale: string | undefined, en: Record<string, string> = EN) => {
307+
const i18n = i18nWith({ 'zh-CN': ZH, en });
308+
i18n.setDefaultLocale('zh-CN');
309+
i18n.setFallbackLocale('zh-CN');
310+
if (sourceLocale) i18n.setSourceLocale(sourceLocale);
311+
// The served adapter's shape (`FileI18nAdapter`): the declared fallback, read back by `getFallbackLocale()`.
312+
return Object.assign(i18n, { getFallbackLocale: () => 'zh-CN' });
313+
};
314+
const served = () => ({
315+
process_name: 'flow:account_approval', current_step: 'manager_review', object_name: 'account',
316+
process_label: 'Account Approval', step_label: 'Manager Review', current_step_label: 'Manager Review',
317+
object_label: 'Account',
318+
});
319+
320+
it('the defect\'s precondition: t() answers an en reader with the zh-CN rows', () => {
321+
const i18n = declared('en');
322+
expect(i18n.t(flowLabelKey('account_approval'), 'en')).toBe('客户审批');
323+
expect(i18n.t(positionLabelKey('crm_sales_manager'), 'en')).toBe('销售经理');
324+
});
325+
326+
it('an en-US reader is negotiated to the en pack, the authored language', () => {
327+
expect(negotiatedReaderLocale(declared('en'), 'en-US')).toBe('en');
328+
});
329+
330+
for (const locale of ['en', 'en-US']) {
331+
it(`an ${locale} reader picks no defaultLocale row: the flow and position labels stand as authored`, () => {
332+
const labels = readerLabelsFor(declared('en'), locale)!;
333+
expect(labels.flowLabel('account_approval')).toBeUndefined();
334+
expect(labels.positionLabel('crm_sales_manager')).toBeUndefined();
335+
const row = served();
336+
localizeRequestLabels(row, labels);
337+
expect(row.process_label).toBe('Account Approval');
338+
});
339+
}
340+
341+
it('CONTROL: a zh-CN reader still reads the zh-CN rows', () => {
342+
const labels = readerLabelsFor(declared('en'), 'zh-CN')!;
343+
expect(labels.flowLabel('account_approval')).toBe('客户审批');
344+
expect(labels.positionLabel('crm_sales_manager')).toBe('销售经理');
345+
});
346+
347+
it('CONTROL: an en pack entry is what an en and an en-US reader read', () => {
348+
const en = { [flowLabelKey('account_approval')]: 'Account sign-off', [positionLabelKey('crm_sales_manager')]: 'Sales lead' };
349+
for (const locale of ['en', 'en-US']) {
350+
const labels = readerLabelsFor(declared('en', en), locale)!;
351+
expect(labels.flowLabel('account_approval')).toBe('Account sign-off');
352+
expect(labels.positionLabel('crm_sales_manager')).toBe('Sales lead');
353+
}
354+
});
355+
356+
it('CONTROL: with no sourceLocale declared, an en reader walks the declared fallback to the zh-CN rows', () => {
357+
const labels = readerLabelsFor(declared(undefined), 'en')!;
358+
expect(labels.flowLabel('account_approval')).toBe('客户审批');
359+
expect(labels.positionLabel('crm_sales_manager')).toBe('销售经理');
360+
});
361+
362+
it('reads neither label through t(): a service that cannot hand its translations over picks none', () => {
363+
const tOnly: ReaderLabelI18n = { t: (key) => (key === flowLabelKey('f') ? '流程' : key === positionLabelKey('p') ? '岗位' : key) };
364+
const labels = readerLabelsFor(tOnly, 'zh-CN')!;
365+
expect(labels.flowLabel('f')).toBeUndefined();
366+
expect(labels.positionLabel('p')).toBeUndefined();
367+
});
368+
369+
it('reads each label once per read', () => {
370+
let reads = 0;
371+
const i18n = declared('en');
372+
const counting: ReaderLabelI18n = {
373+
t: (key) => key,
374+
getLocales: () => i18n.getLocales(),
375+
getTranslations: (code) => { reads += 1; return i18n.getTranslations(code); },
376+
};
377+
const labels = readerLabelsFor(counting, 'zh-CN')!;
378+
labels.flowLabel('account_approval');
379+
labels.flowLabel('account_approval');
380+
labels.positionLabel('crm_sales_manager');
381+
// One bundle for the read, built once: a read of each locale the service holds.
382+
expect(reads).toBe(2);
383+
});
384+
});
385+
386+
/**
387+
* [#35384] A renamed packaged object is named by its rename, as `/meta` names
388+
* it: the object's served definition is translated with its packaged base as
389+
* `packagedBase` (ADR-0029 D9.2a), the base read off the engine's registry
390+
* (`getPackagedObjectBase`, the body the metadata protocol's accessor reads).
391+
* The bundle's `objects.crm_deal.label` translates the PACKAGED label, so it
392+
* says nothing about the rename, in any locale.
393+
*
394+
* The registry is the real `SchemaRegistry`: a packaged `Opportunity` that a
395+
* code extension renames `Deal`. The oracle is the call `/meta` makes,
396+
* `translateMetadataDocument('object', served, bundle, { …resolveOptions,
397+
* packagedBase })`. CONTROLS: the unrenamed object reads the bundle in every
398+
* locale, and a registry that cannot answer translates the name alone.
399+
*/
400+
describe('[#35384] a renamed packaged object is named by its rename, as /meta names it', () => {
401+
const PKG = 'com.acme.crm';
402+
const PAIR = 'com.acme.crm.custom';
403+
const engineWith = (renamed: boolean) => {
404+
const registry = new SchemaRegistry({ multiTenant: false });
405+
registry.logLevel = 'silent';
406+
registry.registerObject({ name: 'crm_deal', label: 'Opportunity', fields: {} } as never, PKG, undefined, 'own');
407+
if (renamed) registry.registerObjectExtension({ extend: 'crm_deal', label: 'Deal' } as never, PAIR);
408+
return { getSchema: (name: string) => registry.getObject(name), registry };
409+
};
410+
const i18n = () => {
411+
const service = i18nWith({
412+
'zh-CN': { [objectLabelKey('crm_deal')]: '商机' },
413+
en: { [objectLabelKey('crm_deal')]: 'Opportunity' },
414+
});
415+
service.setDefaultLocale('zh-CN');
416+
service.setFallbackLocale('zh-CN');
417+
service.setSourceLocale('en');
418+
return Object.assign(service, { getFallbackLocale: () => 'zh-CN' });
419+
};
420+
/** What `GET /meta/object/crm_deal` serves as the label for a request in `locale`. */
421+
const metaLabel = (engine: ReturnType<typeof engineWith>, locale: string): unknown => {
422+
const service = i18n();
423+
const bundle = Object.fromEntries(service.getLocales().map((code) => [code, service.getTranslations(code)]));
424+
return translateMetadataDocument('object', engine.getSchema('crm_deal'), bundle as never, {
425+
locale: negotiatedReaderLocale(service, locale),
426+
fallbackChain: ['zh-CN'],
427+
defaultLocale: 'en',
428+
packagedBase: engine.registry.getPackagedObjectBase('crm_deal'),
429+
}).label;
430+
};
431+
432+
it('the fixture: the served label is the rename, the packaged base keeps the old one', () => {
433+
const engine = engineWith(true);
434+
expect((engine.getSchema('crm_deal') as { label?: string }).label).toBe('Deal');
435+
expect((engine.registry.getPackagedObjectBase('crm_deal') as { label?: string }).label).toBe('Opportunity');
436+
});
437+
438+
for (const locale of ['en', 'en-US', 'zh-CN']) {
439+
it(`a ${locale} reader reads the rename, as /meta serves it`, () => {
440+
const engine = engineWith(true);
441+
expect(metaLabel(engine, locale)).toBe('Deal');
442+
expect(readerLabelsFor(i18n(), locale, engine)!.objectLabel('crm_deal')).toBe('Deal');
443+
const row = { object_name: 'crm_deal', object_label: 'Deal' };
444+
localizeRequestLabels(row, readerLabelsFor(i18n(), locale, engine)!);
445+
expect(row.object_label).toBe('Deal');
446+
});
447+
}
448+
449+
it('CONTROL: the unrenamed object reads the bundle, as /meta serves it', () => {
450+
const engine = engineWith(false);
451+
expect(readerLabelsFor(i18n(), 'zh-CN', engine)!.objectLabel('crm_deal')).toBe('商机');
452+
expect(metaLabel(engine, 'zh-CN')).toBe('商机');
453+
expect(readerLabelsFor(i18n(), 'en', engine)!.objectLabel('crm_deal')).toBe('Opportunity');
454+
});
455+
456+
it('CONTROL: a registry that throws is no baseline known, and the read does not throw', () => {
457+
const engine = engineWith(true);
458+
const failing = { getSchema: engine.getSchema, registry: { getPackagedObjectBase: () => { throw new Error('registry exploded'); } } };
459+
expect(readerLabelsFor(i18n(), 'zh-CN', failing)!.objectLabel('crm_deal')).toBe('商机');
460+
const blind = { getSchema: () => { throw new Error('schema exploded'); } };
461+
expect(readerLabelsFor(i18n(), 'zh-CN', blind)!.objectLabel('crm_deal')).toBe('商机');
462+
});
463+
});

0 commit comments

Comments
 (0)