Skip to content

Commit 1950f07

Browse files
fix(rest): GET /forms/:slug reads a .custom pair's own translation of its form view override (#35290)
<!-- claude-projects-attribution: {"github_login":"os-bill"} --> _Requested by **Bill** · [project thread](https://claude.ai/code/project/chan_016iMXWSZDzqWRWvWzdNo8wg?thread=cmsg_016iMXWSZDzqWRWvWzdNo8wgRuogP8Tp8XyFXLc92Bxvo6)_ repo:objectstack#5 · os-bill · session_01Utp6CZiaBg6rk7dpy1s9Me Fixes #34806 Clause-②: no Metadata-protocol: none ## 维护者速读 - 改了什么:公开表单 `GET /forms/:slug` 翻译表单视图时,补上 `.custom` 配对包自带的译文这一档,与 `/meta/view` 读取同一套标签顺序。 - 为什么改:配对包覆盖了表单的标题或分区标题并自带中文译文时,匿名访客看到的仍是覆盖原文(英文),登录用户在 `/meta` 却看到中文;同一份文档两处答案不同。 - 风险与回滚:只影响「表单视图被配对包覆盖、且配对包为该文案提供了请求语种译文」的公开表单;其余表单输出逐字不变。字段标签(对象那一半)不动。回滚即还原 `form-routes.ts` 一处调用。 - 先看:`packages/rest/src/form-routes.ts`(视图翻译调用处新增的 `pairTranslationBundleOf`);`packages/rest/src/public-form-pair-translation.test.ts`(含 `/meta` 对照腿)。 - 两分钟验证:`pnpm --filter @objectstack/rest exec vitest run src/public-form-pair-translation.test.ts`,预期 5 个用例全绿;其中 zh-CN 用例的表单标题与分区标题为配对包译文。 - 需要你做的:无,席位落地。 ## What changes `GET /forms/:slug` now hands the public form's view translator the `.custom` pair's own translations (`pairBundle`), asked with `pairTranslationBundleOf(p, 'view', match.view)`, the same question the `/meta/view` list and item reads ask (ruling 6995998752: the read half only). The label order is the one already ruled (6631250894 on #30062, restated 6942920667 on #33952) and owned by `@objectstack/spec/system`'s `labelCatalogs`: a translation the pair ships, then the override's own text, then the base's translation. With no pair, or a pair that ships no row for the request's locale, the helper answers `undefined` and the call is exactly what it was. - Scope per the ruling: the object translate call is unchanged and no pair source is invented for objects. An object is extended, never replaced (ADR-0146 D10), so it never answers `servedOverrideBaseOf`. - One comment in the object block said "this route passes no `pairBundle`". This change makes that false for the route, so the comment now states the object-specific reason. The code there is untouched. - `packages/metadata-protocol/**` is not touched. The write-door half is split off by the ruling. ## Tests New `packages/rest/src/public-form-pair-translation.test.ts`. It uses the real `ObjectStackProtocolImplementation` over a real `SchemaRegistry`. The fixture seeds a container form under the base package, the pair's declared override row (`package_id: BASE.custom`, `overrides.package: BASE`) and the pair's zh-CN `translation` row. Every cell reads both `/forms/:slug` and `GET /meta/view/:name` (the control leg) on the same fixture: - the matched view carries the envelope (`_packageId` = base, `overrides.package` = base, `servedOverrideBaseOf` answers the base); - zh-CN with pair translation: the title and the about heading come from the pair on both surfaces. The unchanged description keeps the base's zh-CN translation; - en (the pair ships none): the override's own text on both surfaces; - zh-CN, override but no pair translation: the override's own text beats the base translation on both surfaces; - zh-CN, no override: the base's translation on both surfaces. Code was last changed at `f62c05f8a0`, and the package runs below are on that tree. The later commits `8a81c3c7dd` (changeset wording) and `8d14c223ba` (one add-only row in `scripts/engine-double-contract.pinned.json`) change no code. The gates that read those files were re-run at `8d14c223ba`. <details><summary>Red leg (test committed before the fix, route unchanged)</summary> ``` × zh-CN: a translation the pair ships beats the override's own text, as /meta serves it AssertionError: /forms zh-CN: expected { …(3) } to deeply equal { title: '联系服务台(配对包译文)', …(2) } - "about": "关于你(配对包译文)", + "about": "About you (pair override)", - "title": "联系服务台(配对包译文)", + "title": "Contact the helpdesk (pair override)", Tests 1 failed | 4 passed (5) ``` The `/meta/view` control assertion in the same cell passed before the `/forms` one failed. </details> <details><summary>Ablation on the committed fix (scripts/ablation-replace.mjs, --delete of the pairBundle spread)</summary> ``` ablation-replace: ok mutation landed: anchor 1 -> 0, blob 8e7901c -> b16cb626e1da × zh-CN: a translation the pair ships beats the override's own text, as /meta serves it Tests 1 failed | 4 passed (5) ablation-replace: ok restored: blob == HEAD (8e7901c) and `git diff HEAD` is empty ``` The test imports `./rest-server.js` from source, so no `dist/` rebuild is involved. </details> <details><summary>Package runs</summary> ``` pnpm --filter @objectstack/rest exec vitest run --maxWorkers=2 src/public-form-pair-translation.test.ts src/public-form-section-i18n.test.ts Test Files 2 passed (2) Tests 24 passed (24) pnpm --filter @objectstack/rest test (VERDICT command-exit 0) Test Files 420 passed (420) Tests 8621 passed | 350 skipped (8971) pnpm --filter @objectstack/rest typecheck (VERDICT command-exit 0) check:test-typecheck: OK, the test layer compiles under packages/rest/tsconfig.test.json ``` </details> ## Acceptance notes - The claim placed the pin in a new file beside `public-form-section-i18n.test.ts`. The fixture here is the `/meta` precedence host, not that file's protocol double, so the two do not share a harness. - Not covered: whether the same pair rank reaches the form's thank-you panel text (`submitBehavior`). The translator reads the same catalogs there, but no test here seeds it. ## Verification Local subset only. `node scripts/pm/dispatch-gates.mjs --ran` reports 74 derived, 72 run, 2 NOT-MEASURED, 0 UNRUN. CI runs every family, and its check-runs on this PR are the verdict. - The 72 run families all exited 0. `check:engine-double-contract` first answered exit 1, `RETAINED [findOne]` for the new test's `findOne` double: that is new pinned coverage. The fix was `--write`, which added one row to the ledger, and the re-run exited 0. - NOT MEASURED: `check:dual-build-cjs-loads`, exit 3, PREREQUISITE NOT MET (only the rest dependency closure was built, not the whole repo). - NOT MEASURED: `check:type-check-debt`, timed out at 300 s (a repo-wide re-measure on a shared box). - `overlap-check --branch=claude/issue-34806-public-form-pair-bundle`: VERDICT clean. It merges cleanly with origin/main and with #34999, which shares the ledger file. --- _Generated by [Claude Code](https://claude.ai/code/session_01Utp6CZiaBg6rk7dpy1s9Me)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01Utp6CZiaBg6rk7dpy1s9Me --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent c809deb commit 1950f07

4 files changed

Lines changed: 340 additions & 4 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@objectstack/rest': patch
3+
---
4+
5+
fix(rest): a public form whose view a `.custom` pair overrides reads the pair's own translation, as `/meta` does
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
`GET /forms/:slug` now translates the public form's view in the same label order the `/meta/view` reads already use for a `.custom` pair's declared override (ADR-0146 D2): a translation the pair ships, then the override's own text, then the base's translation. Before, an anonymous visitor read the override's text as written in every locale (the form's `title` and its section headings), while a signed-in reader of the same view got the pair's translation. A form view no pair overrides, or whose pair ships no translation for the request's locale, is served exactly as before. The form's field labels (the object half) do not change: an object is extended, never replaced, so it has no pair rank on any read. No metadata key, value or default changes.

‎packages/rest/src/form-routes.ts‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ import { FILE_REFERENCE_TYPES, RUNTIME_OWNED_FIELD_TYPES } from '@objectstack/sp
8282
import type { ServerScopedDataRequest } from './data-action-routes.js';
8383
import { isExpectedRouteError, mapDataError } from './error-response.js';
8484
import { logError } from './log.js';
85-
import { patchTranslationBundlesOf } from './meta-item-read-gate.js';
85+
import { pairTranslationBundleOf, patchTranslationBundlesOf } from './meta-item-read-gate.js';
8686
import type { TransportScopedMetaRequest } from './meta-collection-routes.js';
8787
import type { RestServer } from './rest-server.js';
8888
import { earnedAnswerLogged } from './stale-summary-answer.js';
@@ -383,9 +383,11 @@ export function registerFormEndpoints(this: FormRouteHost, basePath: string): vo
383383
// string back at a tenant who renamed it.
384384
// [#33952] …and a field slot a code package's
385385
// `fieldPatches` wrote reads that package's own
386-
// translations, then its text. Unlike those
387-
// reads, no pair `.custom` rank sits above it
388-
// here: this route passes no `pairBundle`.
386+
// translations, then its text. No pair `.custom`
387+
// rank sits above it: an object is extended,
388+
// never replaced (ADR-0146 D10), so it never
389+
// answers `servedOverrideBaseOf` and this call
390+
// passes no `pairBundle` (the view call below does).
389391
const patchBundles = await patchTranslationBundlesOf(p, 'object', objectSchema?.name);
390392
objectSchema = translateMetadataDocument('object', objectSchema, bundle, {
391393
...this.translateOptionsFor(i18n, locale),
@@ -424,9 +426,20 @@ export function registerFormEndpoints(this: FormRouteHost, basePath: string): vo
424426
// falls back to the view's machine name, which must
425427
// never shadow the form's title in the console's
426428
// `label ?? form.title ?? objectSchema.label`.
429+
//
430+
// A form view a `.custom` pair overrides (ADR-0146
431+
// D2) is also handed the pair's own translations,
432+
// the first rank of a string the override changed
433+
// (ruling record 6631250894): the same
434+
// `pairTranslationBundleOf` question the `/meta/view`
435+
// reads ask, of the view as the protocol served it
436+
// (its envelope names the base). `undefined` keeps
437+
// the override's own text, as before.
438+
const pairBundle = await pairTranslationBundleOf(p, 'view', match.view);
427439
const view = translateMetadataDocument('view', match.view, bundle, {
428440
...this.translateOptionsFor(i18n, locale),
429441
packagedBase: this.packagedObjectBase(p, 'view', match.view?.name),
442+
...(pairBundle !== undefined ? { pairBundle: pairBundle as any } : {}),
430443
});
431444
if (match.form === match.view?.config) servedForm = view?.config;
432445
if (match.view?.label !== undefined && view?.label !== undefined) {
Lines changed: 308 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,308 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
//
3+
// `GET /forms/:slug` translates a public form view that a `.custom` pair
4+
// overrides (ADR-0146 D2) in the same label order the `/meta/view` reads serve
5+
// it in (ruling record 6631250894, restated by 6942920667): a translation the
6+
// pair ships, then the override's own text, then the base's translation.
7+
//
8+
// The ORDER is `@objectstack/spec/system`'s (`labelCatalogs`), and the pair's
9+
// translations are the protocol's to answer (`servedOverrideBaseOf` +
10+
// `getPairTranslationBundle`, asked through `pairTranslationBundleOf`). What is
11+
// pinned here is the ROUTE's half: that the view it serves is handed the
12+
// pair's translations beside its packaged base, so the anonymous visitor reads
13+
// the text the authenticated `/meta` reader reads.
14+
//
15+
// Every cell carries a CONTROL leg through `GET /meta/view/:name` on the same
16+
// fixture. The pair rank needs the override envelope the read stamped on the
17+
// served document (`_packageId` = the base, `overrides.package` = the base); a
18+
// fixture that lost it would leave both surfaces on the override's own text,
19+
// and the form pin would pass with the wiring absent. The control fails first.
20+
//
21+
// The object half of the form (its field labels) is out of this file: an
22+
// `object` is extended, never replaced (ADR-0146 D10), so it never answers
23+
// `servedOverrideBaseOf` and has no pair rank on `/meta` either.
24+
25+
import { describe, it, expect, vi } from 'vitest';
26+
import { SchemaRegistry, assertEngineFindOnePredicate } from '@objectstack/objectql';
27+
import { ObjectStackProtocolImplementation } from '@objectstack/metadata-protocol';
28+
import { expandViewContainer } from '@objectstack/spec/ui';
29+
import { RestServer } from './rest-server.js';
30+
31+
// Pay the first transform of the dist-resolved workspace dep the handlers reach
32+
// through a dynamic `import()` at MODULE LOAD, not inside a clocked `it()` body
33+
// (`scripts/check-test-source-alias.mjs`).
34+
import '@objectstack/spec/system';
35+
36+
const OBJ = 'ticket';
37+
const BASE_PKG = 'com.example.helpdesk';
38+
const PAIR_PKG = `${BASE_PKG}.custom`;
39+
const VIEW = `${OBJ}.contact`;
40+
const SLUG = 'ticket-contact';
41+
42+
const TITLE_EN = 'Contact us';
43+
const TITLE_ZH = '联系我们';
44+
const ABOUT_EN = 'Tell us about yourself';
45+
const ABOUT_ZH = '介绍一下你自己';
46+
const ABOUT_DESC_EN = 'We will get back to you within a day.';
47+
const ABOUT_DESC_ZH = '我们会在一天内回复你。';
48+
49+
/** The override's own text: what the pair's declared override wrote over the base. */
50+
const TITLE_OV = 'Contact the helpdesk (pair override)';
51+
const ABOUT_OV = 'About you (pair override)';
52+
/** The pair's own zh-CN translation of the text its override wrote. */
53+
const TITLE_PAIR_ZH = '联系服务台(配对包译文)';
54+
const ABOUT_PAIR_ZH = '关于你(配对包译文)';
55+
56+
const ticketObject = {
57+
name: OBJ,
58+
label: 'Ticket',
59+
fields: {
60+
subject: { type: 'text', label: 'Subject' },
61+
email: { type: 'text', label: 'Email' },
62+
},
63+
};
64+
65+
/** The `defineView` container as the code package ships it: one public form under `formViews.contact`. */
66+
const ticketContainer = () => ({
67+
object: OBJ,
68+
formViews: {
69+
contact: {
70+
type: 'simple',
71+
title: TITLE_EN,
72+
data: { provider: 'object', object: OBJ },
73+
sharing: { enabled: true, allowAnonymous: true, publicLink: `/forms/${SLUG}` },
74+
sections: [
75+
{ name: 'about', label: ABOUT_EN, description: ABOUT_DESC_EN, fields: ['subject'] },
76+
{ name: 'details', label: 'Details', fields: ['email'] },
77+
],
78+
},
79+
},
80+
});
81+
82+
/** The packaged form item as the boot registers it (`expandViewContainer`). */
83+
const shippedFormItem = (): any => {
84+
const item = expandViewContainer(OBJ, ticketContainer()).find((v) => v.name === VIEW);
85+
if (!item) throw new Error(`fixture missing ${VIEW}`);
86+
return item;
87+
};
88+
89+
/** The deployment's code catalog: `en` repeats the shipped strings, `zh-CN` translates them. */
90+
const CODE_CATALOG: Record<string, Record<string, any>> = {
91+
en: {
92+
objects: {
93+
[OBJ]: {
94+
_views: { contact: { title: TITLE_EN } },
95+
_sections: { about: { label: ABOUT_EN, description: ABOUT_DESC_EN } },
96+
},
97+
},
98+
},
99+
'zh-CN': {
100+
objects: {
101+
[OBJ]: {
102+
_views: { contact: { title: TITLE_ZH } },
103+
_sections: { about: { label: ABOUT_ZH, description: ABOUT_DESC_ZH } },
104+
},
105+
},
106+
},
107+
};
108+
109+
/** The pair's own zh-CN rows for the two strings its override changed. */
110+
const PAIR_ZH_DATA = {
111+
objects: {
112+
[OBJ]: {
113+
_views: { contact: { title: TITLE_PAIR_ZH } },
114+
_sections: { about: { label: ABOUT_PAIR_ZH } },
115+
},
116+
},
117+
};
118+
119+
/** Deep merge, `top` over `under`, of two translation-data groups. */
120+
const mergeData = (under: Record<string, any>, top: Record<string, any>): Record<string, any> => {
121+
const out: Record<string, any> = { ...under };
122+
for (const [k, v] of Object.entries(top)) {
123+
out[k] = v && typeof v === 'object' && !Array.isArray(v) && out[k] && typeof out[k] === 'object'
124+
? mergeData(out[k], v)
125+
: v;
126+
}
127+
return out;
128+
};
129+
130+
/** One `where` value as the store reads it: `{ $in: [...] }` or equality. */
131+
const whereValueMatches = (actual: unknown, want: unknown): boolean =>
132+
want !== null && typeof want === 'object' && Array.isArray((want as { $in?: unknown }).$in)
133+
? (want as { $in: unknown[] }).$in.includes(actual)
134+
: actual === want;
135+
136+
function createMockServer() {
137+
return {
138+
get: vi.fn(), post: vi.fn(), put: vi.fn(), delete: vi.fn(), patch: vi.fn(),
139+
use: vi.fn(),
140+
listen: vi.fn().mockResolvedValue(undefined),
141+
close: vi.fn().mockResolvedValue(undefined),
142+
};
143+
}
144+
145+
interface Seed {
146+
/** Seed the pair's declared override of the form view. */
147+
readonly override: boolean;
148+
/** Seed the pair's own zh-CN translation of the text its override wrote. */
149+
readonly pairZh: boolean;
150+
}
151+
152+
/**
153+
* The REAL protocol over a real `SchemaRegistry`, the container registered the
154+
* way the boot registers a `defineView` container, and the `.custom` pair's
155+
* rows seeded the way Studio's Customize publishes them: the override row bound
156+
* to the pair (`package_id: <base>.custom`) declaring
157+
* `overrides: { package: <base> }`, and the pair's translation an active
158+
* `translation` row bound to the pair. The i18n service serves the deployment
159+
* catalog: the code catalog with every authored row merged over it, the pair's
160+
* row included, its package dropped.
161+
*/
162+
function makeHost(seed: Seed) {
163+
const registry = new SchemaRegistry({ multiTenant: false });
164+
registry.logLevel = 'silent';
165+
registry.registerObject(ticketObject as any, BASE_PKG);
166+
const container = ticketContainer();
167+
registry.registerItem('view', { name: OBJ, ...container }, 'name', BASE_PKG);
168+
for (const item of expandViewContainer(OBJ, container)) registry.registerItem('view', item, 'name', BASE_PKG);
169+
170+
const rows: Record<string, unknown>[] = [];
171+
if (seed.override) {
172+
const shipped = shippedFormItem();
173+
const overridden = {
174+
...shipped,
175+
config: {
176+
...shipped.config,
177+
title: TITLE_OV,
178+
sections: shipped.config.sections.map((s: any) => (s.name === 'about' ? { ...s, label: ABOUT_OV } : s)),
179+
},
180+
overrides: { package: BASE_PKG, basedOn: '1.0.0' },
181+
};
182+
rows.push({
183+
id: 'ov_form', type: 'view', name: VIEW, package_id: PAIR_PKG, organization_id: null, state: 'active',
184+
metadata: JSON.stringify(overridden),
185+
});
186+
}
187+
if (seed.pairZh) {
188+
rows.push({
189+
id: 'tr_pair_zh', type: 'translation', name: 'helpdesk_custom_zh', package_id: PAIR_PKG, organization_id: null,
190+
state: 'active', metadata: JSON.stringify({ name: 'helpdesk_custom_zh', locale: 'zh-CN', ...PAIR_ZH_DATA }),
191+
});
192+
}
193+
194+
const merged: Record<string, any> = {
195+
en: CODE_CATALOG.en,
196+
'zh-CN': seed.pairZh ? mergeData(CODE_CATALOG['zh-CN'], PAIR_ZH_DATA) : CODE_CATALOG['zh-CN'],
197+
};
198+
const i18n = {
199+
getLocales: () => ['en', 'zh-CN'],
200+
getTranslations: (locale: string) => merged[locale],
201+
getDefaultLocale: () => 'en',
202+
};
203+
204+
const matches = (r: Record<string, unknown>, w: Record<string, unknown>) =>
205+
Object.entries(w ?? {}).every(([k, v]) => {
206+
if (k.startsWith('$')) throw new Error(`fake driver: unsupported operator ${k}`);
207+
return whereValueMatches(r[k] ?? null, v ?? null);
208+
});
209+
const engine = {
210+
registry,
211+
find: async (table: string, q: { where: Record<string, unknown>; limit?: number }) => {
212+
if (table !== 'sys_metadata') return [];
213+
const matched = rows.filter((r) => matches(r, q.where));
214+
return typeof q?.limit === 'number' ? matched.slice(0, q.limit) : matched;
215+
},
216+
findOne: async (table: string, q: { where: Record<string, unknown> }) => {
217+
assertEngineFindOnePredicate(table, q);
218+
return table === 'sys_metadata' ? rows.find((r) => matches(r, q.where)) ?? null : null;
219+
},
220+
};
221+
const protocol = new ObjectStackProtocolImplementation(engine as never, undefined, 'env_test');
222+
const rest = new RestServer(
223+
createMockServer() as never, protocol as never, { api: { requireAuth: false } } as never,
224+
undefined, undefined, undefined, undefined, undefined,
225+
undefined, undefined, undefined, undefined, undefined,
226+
// i18nServiceProvider — the 14th constructor argument.
227+
async () => i18n as never,
228+
);
229+
(rest as unknown as { resolveExecCtx: () => Promise<unknown> }).resolveExecCtx = async () => ({
230+
userId: 'u_admin', systemPermissions: ['manage_metadata', 'studio.access', 'setup.access'],
231+
});
232+
rest.registerRoutes();
233+
const routes = rest.getRouteManager();
234+
const run = async (path: string, params: Record<string, string>, locale: string) => {
235+
const entry = routes.get('GET', path);
236+
if (!entry) throw new Error(`route not registered: GET ${path}`);
237+
let body: any;
238+
let status = 200;
239+
const res = {
240+
status: (s: number) => { status = s; return res; },
241+
header: () => res,
242+
setHeader: () => res,
243+
json: (b: unknown) => { body = b; },
244+
send: (b: unknown) => { body = b; },
245+
} as unknown as Parameters<typeof entry.handler>[1];
246+
await entry.handler(
247+
{ params, query: {}, body: {}, headers: { 'accept-language': locale }, method: 'GET', path } as unknown as Parameters<typeof entry.handler>[0],
248+
res,
249+
);
250+
expect(status, `GET ${path} ${JSON.stringify(params)}: ${JSON.stringify(body)}`).toBe(200);
251+
return body;
252+
};
253+
/** The two strings a reader sees, plus the about section's description (a string the override left alone). */
254+
const strings = (config: any) => ({
255+
title: config?.title,
256+
about: config?.sections?.find((s: any) => s?.name === 'about')?.label,
257+
aboutDescription: config?.sections?.find((s: any) => s?.name === 'about')?.description,
258+
});
259+
return {
260+
protocol,
261+
/** `GET /forms/:slug` — the anonymous visitor's read. */
262+
form: async (locale: string) => strings((await run('/api/v1/forms/:slug', { slug: SLUG }, locale))?.form),
263+
/** `GET /meta/view/:name` — the CONTROL leg: the authenticated read of the same document. */
264+
meta: async (locale: string) => strings((await run('/api/v1/meta/:type/:name', { type: 'view', name: VIEW }, locale))?.item?.config),
265+
};
266+
}
267+
268+
describe('GET /forms/:slug serves a .custom pair override of the form view in the ruled label order', () => {
269+
it('the view the route matches carries the override envelope the pair rank reads', async () => {
270+
// The route matches its form in `getMetaItems({ type: 'view' })`; the pair
271+
// rank reads `servedOverrideBaseOf` off that served document.
272+
const { protocol } = makeHost({ override: true, pairZh: true });
273+
const views: any[] = ((await protocol.getMetaItems({ type: 'view' } as never)) as any).items;
274+
const served = views.find((v) => v?.name === VIEW);
275+
expect(served?._packageId).toBe(BASE_PKG);
276+
expect(served?.overrides?.package).toBe(BASE_PKG);
277+
expect(protocol.servedOverrideBaseOf('view', served)).toBe(BASE_PKG);
278+
});
279+
280+
it('zh-CN: a translation the pair ships beats the override\'s own text, as /meta serves it', async () => {
281+
const host = makeHost({ override: true, pairZh: true });
282+
const expected = { title: TITLE_PAIR_ZH, about: ABOUT_PAIR_ZH, aboutDescription: ABOUT_DESC_ZH };
283+
// CONTROL: the authenticated read of the same document reads the pair's rank.
284+
expect(await host.meta('zh-CN'), '/meta/view zh-CN').toEqual(expected);
285+
expect(await host.form('zh-CN'), '/forms zh-CN').toEqual(expected);
286+
});
287+
288+
it('en: the pair ships no en row, so both surfaces serve the override\'s own text', async () => {
289+
const host = makeHost({ override: true, pairZh: true });
290+
const expected = { title: TITLE_OV, about: ABOUT_OV, aboutDescription: ABOUT_DESC_EN };
291+
expect(await host.meta('en'), '/meta/view en').toEqual(expected);
292+
expect(await host.form('en'), '/forms en').toEqual(expected);
293+
});
294+
295+
it('zh-CN with no pair translation: the override\'s own text beats the base\'s translation on both surfaces', async () => {
296+
const host = makeHost({ override: true, pairZh: false });
297+
const expected = { title: TITLE_OV, about: ABOUT_OV, aboutDescription: ABOUT_DESC_ZH };
298+
expect(await host.meta('zh-CN'), '/meta/view zh-CN').toEqual(expected);
299+
expect(await host.form('zh-CN'), '/forms zh-CN').toEqual(expected);
300+
});
301+
302+
it('zh-CN with no override: the base\'s form reads the base\'s translation on both surfaces', async () => {
303+
const host = makeHost({ override: false, pairZh: false });
304+
const expected = { title: TITLE_ZH, about: ABOUT_ZH, aboutDescription: ABOUT_DESC_ZH };
305+
expect(await host.meta('zh-CN'), '/meta/view zh-CN').toEqual(expected);
306+
expect(await host.form('zh-CN'), '/forms zh-CN').toEqual(expected);
307+
});
308+
});

‎scripts/engine-double-contract.pinned.json‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5086,6 +5086,11 @@
50865086
"verb": "findOne",
50875087
"pinned": 1
50885088
},
5089+
{
5090+
"file": "packages/rest/src/public-form-pair-translation.test.ts",
5091+
"verb": "findOne",
5092+
"pinned": 1
5093+
},
50895094
{
50905095
"file": "packages/rest/src/public-form-routes.stored-row.test.ts",
50915096
"verb": "delete",

0 commit comments

Comments
 (0)