Skip to content

Commit 143499a

Browse files
committed
test(spec): pin the served translation face against the platform face and the response schema
Claude-Session: https://claude.ai/code/session_01Vy85beHdawtEtqNscYBy7V Co-authored-by: Claude <noreply@anthropic.com>
1 parent 1658c4c commit 143499a

1 file changed

Lines changed: 71 additions & 0 deletions

File tree

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* #25785 — the served translation document is the platform face without the
5+
* groups the server resolves itself.
6+
*
7+
* `GET /i18n/translations/:locale` answers `GetTranslationsResponseSchema`,
8+
* whose `translations` is {@link ServedTranslationDataSchema}. The runtime door
9+
* leaves out {@link SERVER_RESOLVED_TRANSLATION_GROUPS} (`metadataForms`, which
10+
* `/meta/types` resolves into Studio's forms on the server), and these pins keep
11+
* the constant, the served face and the response schema one declaration:
12+
*
13+
* - the served face is exactly the platform face minus the constant, both ways;
14+
* - a server-resolved group stays authorable on both bundle faces (only the
15+
* served document leaves it out);
16+
* - the served face is closed: a body still carrying the group is refused by
17+
* name, which is what lets a response conformance suite catch a door that
18+
* stops leaving it out.
19+
*/
20+
21+
import { describe, it, expect } from 'vitest';
22+
import { GetTranslationsResponseSchema } from '../api/protocol.zod';
23+
import {
24+
PlatformTranslationDataSchema,
25+
SERVER_RESOLVED_TRANSLATION_GROUPS,
26+
ServedTranslationDataSchema,
27+
TranslationDataSchema,
28+
} from './translation.zod';
29+
30+
const keysOf = (schema: { shape: Record<string, unknown> }) => Object.keys(schema.shape).sort();
31+
32+
describe('#25785 — the served translation face', () => {
33+
it('is the platform face without SERVER_RESOLVED_TRANSLATION_GROUPS, in both directions', () => {
34+
const platform = keysOf(PlatformTranslationDataSchema);
35+
const expected = platform.filter((k) => !(SERVER_RESOLVED_TRANSLATION_GROUPS as readonly string[]).includes(k));
36+
// Positive control: the walk read real shapes, and the constant names a platform group.
37+
expect(platform).toEqual(expect.arrayContaining(['objects', 'settings', 'metadataForms']));
38+
expect(expected.length).toBe(platform.length - SERVER_RESOLVED_TRANSLATION_GROUPS.length);
39+
expect(keysOf(ServedTranslationDataSchema)).toEqual(expected);
40+
});
41+
42+
it('is what GetTranslationsResponseSchema serves under `translations`', () => {
43+
expect(keysOf(GetTranslationsResponseSchema.shape.translations)).toEqual(keysOf(ServedTranslationDataSchema));
44+
});
45+
46+
it.each(SERVER_RESOLVED_TRANSLATION_GROUPS)('%s stays authorable on both bundle faces', (group) => {
47+
expect(Object.keys(TranslationDataSchema.shape)).toContain(group);
48+
expect(Object.keys(PlatformTranslationDataSchema.shape)).toContain(group);
49+
});
50+
51+
it('accepts a document carrying the served groups', () => {
52+
const served = {
53+
objects: { lead: { label: '潜在客户', fields: { company: { label: '公司' } } } },
54+
settings: { mail: { title: '邮件投递' } },
55+
messages: { save: '保存' },
56+
};
57+
expect(ServedTranslationDataSchema.safeParse(served).success).toBe(true);
58+
expect(GetTranslationsResponseSchema.safeParse({ locale: 'zh-CN', translations: served }).success).toBe(true);
59+
});
60+
61+
it.each(SERVER_RESOLVED_TRANSLATION_GROUPS)('refuses a document still carrying %s, by name', (group) => {
62+
const result = ServedTranslationDataSchema.safeParse({ messages: { save: '保存' }, [group]: {} });
63+
expect(result.success).toBe(false);
64+
const issue = result.error?.issues.find((i) => i.code === 'unrecognized_keys');
65+
expect(issue).toBeDefined();
66+
expect((issue as { keys?: string[] }).keys).toEqual([group]);
67+
68+
const response = GetTranslationsResponseSchema.safeParse({ locale: 'zh-CN', translations: { [group]: {} } });
69+
expect(response.success).toBe(false);
70+
});
71+
});

0 commit comments

Comments
 (0)