Skip to content

Commit a79e5bc

Browse files
committed
wip(objectql,rest): pin getPackagedReportBase against a real registry; review nits
Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BUeRMD4VYCYUfzxTKcZFAF
1 parent 118a82d commit a79e5bc

3 files changed

Lines changed: 104 additions & 5 deletions

File tree

‎.changeset/25788-translation-reports.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Metadata-protocol: added
1313

1414
An app authored in one language listed its reports (`reports[].label`, `reports[].description`) in that language on the app's report index and the report page heading. Before this change the translation bundle had no key for them: `reports` was a retired object-first dialect key, so a bundle carrying it was refused by `os validate`, and `os i18n check` could not report the gap.
1515

16-
- **`@objectstack/spec`:** `TranslationData` (and the registered `translation` item and the platform bundle, which share its groups) gains `reports`, keyed by the report's `name`, carrying `label` and `description` (strict: any other key is refused — `name` or `title` with a message pointing at `label`, and the singular spelling `report` with a message pointing at `reports`). `reports` leaves `LEGACY_OBJECT_FIRST_KEYS`, so a stored translation row carrying it now loads through the authored-row sync instead of being skipped as a retired dialect; the legacy dialect never used the key. A new translator, `translateReport`, overlays the two strings and is registered in the metadata-document dispatch, so `GET /meta/report` (list and item) is served in the request's locale. A key the bundle does not carry keeps the authored string. A report is overlay-editable (ADR-0126 Regime O), so the translator honours the packaged base: a label or description an org re-authored is served as written (ADR-0029 D9.2a), and the strings it did not touch are still translated.
16+
- **`@objectstack/spec`:** `TranslationData` (and the registered `translation` item and the platform bundle, which share its groups) gains `reports`, keyed by the report's `name`, carrying `label` and `description` (strict: any other key is refused — `name` or `title` with a message pointing at `label`, and the singular spelling `report` with a message pointing at `reports`). `reports` leaves `LEGACY_OBJECT_FIRST_KEYS`, so a stored translation row carrying it now loads through the authored-row sync instead of being skipped as a retired dialect; the key's measured footprint in the legacy dialect was zero (#3778). A new translator, `translateReport`, overlays the two strings and is registered in the metadata-document dispatch, so `GET /meta/report` (list and item) is served in the request's locale. A key the bundle does not carry keeps the authored string. A report is overlay-editable (ADR-0126 Regime O), so the translator honours the packaged base: a label or description an org re-authored is served as written (ADR-0029 D9.2a), and the strings it did not touch are still translated.
1717
- **`@objectstack/metadata-protocol`:** `getPackagedReportBase(name)` returns the shipped report document beneath any overlay, the base the REST read path hands the translator.
1818
- **`@objectstack/rest`:** the meta read path supplies that base for `report`, as it does for `dashboard` and `view`.
1919
- **`@objectstack/lint`:** `translation-target-unknown` reports a `reports.<name>` key that names no report a package of the stack declares, as an error with the nearest declared name.
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* #25788 — `ObjectStackProtocolImplementation.getPackagedReportBase`, against a
5+
* REAL `SchemaRegistry`: the twin of `protocol-packaged-dashboard-base.test.ts`.
6+
*
7+
* A report is overlay-editable (ADR-0126 Regime O), and the translation bundle
8+
* now carries `reports.<name>.label` / `.description`, so `translateReport`
9+
* must lose to a string an org re-authored (ADR-0029 D9.2a). It decides that by
10+
* comparing against the PACKAGED declaration, and that comparison is only as
11+
* good as the body this accessor returns: the one the code package shipped,
12+
* never an overlay hydrated under the plain registry key.
13+
*/
14+
15+
import { describe, it, expect } from 'vitest';
16+
import { ObjectStackProtocolImplementation } from '@objectstack/metadata-protocol';
17+
import { translateReport, type TranslationBundle } from '@objectstack/spec/system';
18+
import { SchemaRegistry } from './registry.js';
19+
20+
const PKG = 'com.example.showcase';
21+
const REPORT = 'opps_by_stage';
22+
23+
const SHIPPED_LABEL = 'Opportunities by Stage';
24+
const EDITED_LABEL = 'Pipeline by stage (ours)';
25+
26+
/** The report as the code package ships it. */
27+
const packagedBody = () => ({
28+
name: REPORT,
29+
label: SHIPPED_LABEL,
30+
description: 'Summary of opportunities grouped by stage',
31+
type: 'summary',
32+
dataset: 'pipeline',
33+
rows: ['stage'],
34+
values: ['amount'],
35+
});
36+
37+
/** The same report as an org's published overlay stores it — the label edited. */
38+
const overlayBody = () => ({ ...packagedBody(), label: EDITED_LABEL });
39+
40+
const BUNDLE: TranslationBundle = {
41+
'zh-CN': { reports: { [REPORT]: { label: '各阶段商机', description: '按阶段汇总的商机' } } },
42+
};
43+
44+
function makeSession() {
45+
const registry = new SchemaRegistry({ multiTenant: false });
46+
registry.logLevel = 'silent';
47+
const protocol: any = new ObjectStackProtocolImplementation({ registry } as any, undefined, 'env_test');
48+
return { protocol, registry };
49+
}
50+
51+
describe('#25788 getPackagedReportBase — the packaged declaration, never an overlay', () => {
52+
it('answers the body the code package shipped', () => {
53+
const s = makeSession();
54+
s.registry.registerItem('report', packagedBody(), 'name', PKG);
55+
const base = s.protocol.getPackagedReportBase(REPORT);
56+
expect(base?.label).toBe(SHIPPED_LABEL);
57+
expect(base?._packageId).toBe(PKG);
58+
});
59+
60+
it('is immune to an overlay hydrated under the plain registry key', () => {
61+
const s = makeSession();
62+
s.registry.registerItem('report', packagedBody(), 'name', PKG);
63+
s.registry.registerItem('report', overlayBody(), 'name');
64+
65+
// The trap is live: the plain registry read answers the overlay…
66+
expect((s.registry.getItem('report', REPORT) as any)?.label).toBe(EDITED_LABEL);
67+
// …and the packaged base does not move.
68+
expect(s.protocol.getPackagedReportBase(REPORT)?.label).toBe(SHIPPED_LABEL);
69+
});
70+
71+
it('is undefined for a report no code package ships, an unknown name, and an empty name', () => {
72+
const s = makeSession();
73+
s.registry.registerItem('report', { ...packagedBody(), name: 'tenant_report' }, 'name');
74+
expect(s.protocol.getPackagedReportBase('tenant_report')).toBeUndefined();
75+
expect(s.protocol.getPackagedReportBase('no_such_report')).toBeUndefined();
76+
expect(s.protocol.getPackagedReportBase('')).toBeUndefined();
77+
});
78+
79+
it('is undefined when the host registry cannot answer', () => {
80+
const partial: any = new ObjectStackProtocolImplementation({ registry: {} } as any, undefined, 'env_test');
81+
expect(partial.getPackagedReportBase(REPORT)).toBeUndefined();
82+
const none: any = new ObjectStackProtocolImplementation({} as any, undefined, 'env_test');
83+
expect(none.getPackagedReportBase(REPORT)).toBeUndefined();
84+
});
85+
86+
it('hands `translateReport` the base it needs: the edit is kept, the untouched description translated', () => {
87+
const s = makeSession();
88+
s.registry.registerItem('report', packagedBody(), 'name', PKG);
89+
s.registry.registerItem('report', overlayBody(), 'name');
90+
const packagedBase = s.protocol.getPackagedReportBase(REPORT);
91+
92+
const served = translateReport(overlayBody(), BUNDLE, { locale: 'zh-CN', packagedBase }) as any;
93+
expect(served.label).toBe(EDITED_LABEL);
94+
expect(served.description).toBe('按阶段汇总的商机');
95+
96+
const shipped = translateReport(packagedBody(), BUNDLE, { locale: 'zh-CN', packagedBase }) as any;
97+
expect(shipped.label).toBe('各阶段商机');
98+
});
99+
});

‎packages/rest/src/meta-item-read-gate.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2902,9 +2902,9 @@ export async function translateMetaList(
29022902
if (!locale) return items;
29032903
const { translateMetadataDocument } = await import('@objectstack/spec/system');
29042904
// [#8284 · #20730] One protocol resolution for the whole page, for every
2905-
// type with a packaged base (object, dashboard, view); the lookup itself is
2906-
// a synchronous in-memory registry read per element, by that element's own
2907-
// registry name — a view's qualified `<object>.<viewKey>`.
2905+
// type with a packaged base (object, dashboard, view, report); the lookup
2906+
// itself is a synchronous in-memory registry read per element, by that
2907+
// element's own registry name — a view's qualified `<object>.<viewKey>`.
29082908
const p = PACKAGED_BASE_ACCESSORS.has(metaType) ? await sources.resolveProtocol() : undefined;
29092909
// `getMetaItems` elements are metadata documents (the list envelope is the
29102910
// OUTER `{ type, items }`), so every element translates directly (#5563).
@@ -2929,7 +2929,7 @@ export async function translateMetaList(
29292929
* labels live on the document. A missing bundle is not a bail-out (the
29302930
* built-in fallbacks still apply); no locale is. The i18n service is resolved
29312931
* only for a translatable type, and the protocol only for a type with a
2932-
* packaged base — an object, a dashboard or a view (#8284, #20730:
2932+
* packaged base — an object, a dashboard, a view or a report (#8284, #20730, #25788:
29332933
* {@link packagedObjectBaseOf}).
29342934
*
29352935
* Moved here, unchanged, from `RestServer.translateMetaItem` (which now

0 commit comments

Comments
 (0)