Skip to content

Commit 37238cc

Browse files
committed
test(i18n): give the studio zh-only key families one home
The studio namespace pin and the app-shell ZH_ONLY_REASONS pin each held their own copy of the three zh-only prefixes. The list now lives in an i18n test-support module that the namespace pin reads, and the app-shell pin asserts its reason prefixes equal it, so neither list can widen alone. Claude-Session: https://claude.ai/code/session_01JQwxban7wCJnPiiSY4ULYz Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 1e8e529 commit 37238cc

3 files changed

Lines changed: 26 additions & 8 deletions

File tree

‎ui/packages/app-shell/src/views/metadata-admin/inspectors/inspectorStrings.studioNamespace-25922.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import path from 'node:path';
2929
import { fileURLToPath } from 'node:url';
3030
import { loadStudioCatalogue } from '@object-ui/i18n/namespaces/studio';
3131
import { t, tOptional } from '../i18n';
32+
// The i18n pin's own family list (a test-support module, not a package export).
33+
import { STUDIO_ZH_ONLY_FAMILIES } from '../../../../../i18n/src/__tests__/studio-zh-only-families';
3234

3335
const EN = await loadStudioCatalogue('en');
3436
// Resident before any case, so the zh lookups below read synchronously.
@@ -152,6 +154,8 @@ const ZH_ONLY_FLOOR: Readonly<Record<string, number>> = Object.freeze({
152154
* here from the retired `check:i18n-designer-parity` gate with slice S7. A
153155
* citation is `{ file, anchor }`, the anchor is TEXT and never a line number,
154156
* and it must occur exactly once in its file or it stops locating anything.
157+
* Its prefixes are held equal to `STUDIO_ZH_ONLY_FAMILIES`, the list the i18n
158+
* pin `studio-namespace.test.ts` allows, so neither can widen alone.
155159
*/
156160
const ZH_ONLY_REASONS = Object.freeze([
157161
{
@@ -248,6 +252,10 @@ describe('the namespace is the only home (objectstack#25922 slice S7)', () => {
248252
expect(wrong).toEqual([]);
249253
});
250254

255+
it('a reason is given for exactly the families the i18n pin allows', () => {
256+
expect(ZH_ONLY_REASONS.map((f) => f.prefix).sort()).toEqual([...STUDIO_ZH_ONLY_FAMILIES].sort());
257+
});
258+
251259
it.each(ZH_ONLY_REASONS.map((f) => [f.prefix, f] as const))('%s: its citation anchor occurs exactly once', (_prefix, family) => {
252260
const text = readFileSync(path.join(here, family.file), 'utf8');
253261
expect(text.split(family.anchor).length - 1).toBe(1);

‎ui/packages/i18n/src/__tests__/studio-namespace.test.ts‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,13 @@ import {
3030
resolveStudioLanguage,
3131
studioString,
3232
} from '../namespaces/studio/index.js';
33+
// The `zh`-only families, each one-sided on purpose; the list's one home.
34+
import { STUDIO_ZH_ONLY_FAMILIES } from './studio-zh-only-families.js';
3335

3436
/** `tFormat()`'s own placeholder pattern (app-shell `views/metadata-admin/i18n.ts`). */
3537
const PLACEHOLDER = /\{(\w+)\}/g;
3638
const placeholders = (value: string) => [...new Set(Array.from(value.matchAll(PLACEHOLDER), (m) => m[1]))].sort();
3739

38-
/**
39-
* The `zh`-only families, each one-sided on purpose. `ZH_ONLY_REASONS` in
40-
* app-shell's `inspectorStrings.studioNamespace-25922.test.ts` carries the
41-
* reason and the consumer for each, and checks that its citation still locates it.
42-
*/
43-
const ZH_ONLY_FAMILIES = ['engine.flowNode.', 'engine.enum.type.', 'engine.packages.form.help.'];
44-
4540
function flatKeys(node: unknown, prefix = ''): string[] {
4641
if (typeof node !== 'object' || node === null) return [prefix];
4742
return Object.entries(node).flatMap(([k, v]) => flatKeys(v, prefix ? `${prefix}.${k}` : k));
@@ -69,7 +64,7 @@ describe('studio namespace — scoped parity', () => {
6964

7065
it('a zh-only key belongs to a documented family', () => {
7166
const stray = zhKeys.filter(
72-
(key) => !(key in STUDIO_EN) && !ZH_ONLY_FAMILIES.some((family) => key.startsWith(family)),
67+
(key) => !(key in STUDIO_EN) && !STUDIO_ZH_ONLY_FAMILIES.some((family) => key.startsWith(family)),
7368
);
7469
expect(stray).toEqual([]);
7570
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* The `studio` namespace's `zh`-only key families, the one list.
3+
*
4+
* Two pins read it: `studio-namespace.test.ts` here, which reds on a `zh`-only
5+
* key outside these prefixes, and app-shell's
6+
* `inspectorStrings.studioNamespace-25922.test.ts`, whose `ZH_ONLY_REASONS`
7+
* carries the reason and consumer for each family and asserts its prefixes
8+
* equal this list. A test-support module, not an export of the package entry:
9+
* `__tests__/` is excluded from the build, so nothing here ships.
10+
*/
11+
export const STUDIO_ZH_ONLY_FAMILIES: readonly string[] = Object.freeze([
12+
'engine.flowNode.',
13+
'engine.enum.type.',
14+
'engine.packages.form.help.',
15+
]);

0 commit comments

Comments
 (0)