Skip to content

Commit 641ef85

Browse files
committed
test: lock literal i18n usage and icon names against silent vanish
The exact-twice dictionary lock cannot see a key with zero dictionary lines (it vanishes from the count), and Icon returns null on unregistered names. Add a reverse lock: every literal t() usage (templates expanded over FEATURE_GROUPS) must have a dictionary line, and every icon name passed to Icon/feedRow must be registered (73->74). Discrimination verified by temporarily removing both dict lines of one key: old lock stays green, new lock names the key.
1 parent 0e41cc8 commit 641ef85

1 file changed

Lines changed: 53 additions & 3 deletions

File tree

‎dsh-mneme/test/client.test.js‎

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,10 +1020,14 @@ test("scope isolation ships panel switches and provenance surfaces (A4)", () =>
10201020
// 默认值),面板自判、不加后端字段;④分组与折叠键中英成对。验收口径:首屏
10211021
// 可点项 = 3 总开关 + autoInject 的 2 个子开关 + scope 2 开关 + 「全部设置」
10221022
// 按钮 = 8(≤ 8),由 ①② 的组成正则共同钉死,不另数 DOM。
1023+
// v0.9.0 复验修订:首屏加 group.mo(M.O. 独立组),可点项预算 8→9。这不是
1024+
// 悄悄放宽——是产品主人点名「别藏在里面」:M.O. 独立成组却仍折在「全部
1025+
// 设置」后等于换个地方继续藏。≤8 原为 #427 自设软预算,owner 豁免一项。
10231026
test("settings card folds everything beyond the first screen behind All settings (issue #427)", () => {
1024-
// ① 首屏层组成:两组都要在,且 basic 的成员是从 core/dream 移走的。
1025-
assert.ok(/const FEATURE_FIRST_SCREEN = \["group\.basic", "group\.scope"\];/.test(clientSource),
1026-
"the first screen must be exactly the basic and scope groups");
1027+
// ① 首屏层组成:三组都要在(basic 总开关 / mo 座位闸门 / scope 必答题),
1028+
// 且 basic 的成员是从 core/dream 移走的。
1029+
assert.ok(/const FEATURE_FIRST_SCREEN = \["group\.basic", "group\.mo", "group\.scope"\];/.test(clientSource),
1030+
"the first screen must be exactly the basic, mo and scope groups");
10271031
assert.ok(/key: "group\.basic", items: \["autoInject", "autoSummarize", "autoDream"\]/.test(clientSource),
10281032
"group.basic must carry exactly the three master switches");
10291033
assert.ok(!/key: "group\.core", items: \["autoInject/.test(clientSource) && !/key: "group\.dream", items: \["autoDream/.test(clientSource),
@@ -1939,3 +1943,49 @@ test("M.O. class names do not collide in the stylesheet", () => {
19391943
// 扫描量也得钉:正则一旦匹配不到东西,上面那条会静默变绿(例如样式表被整块挪走)。
19401944
assert.ok(declared.size >= 20, `the scan must actually see the pipeline stylesheet (saw ${declared.size})`);
19411945
});
1946+
1947+
// 回归锁(v0.9.0 复验轮沉淀):面板的两种「静默消失」假绿形状一起钉住。
1948+
// ① i18n 缺定义:既有的「每键恰好两次」锁只统计**字典里存在**的键,一个只有
1949+
// 用法、零字典行的键在计数里整个消失——本轮就查出 4 个这种键(zoom.value 自
1950+
// 基线即断)。所以这里反向查:每一处用法都必须能找到定义行。三种用法形状:
1951+
// 字面量 t("k")、模板 t(`memory.features.${g.key}`) 按 FEATURE_GROUPS 的组键
1952+
// 展开、模板 t(`memory.features.${k}`) 按各 items 旗标键展开(boolRow 的
1953+
// name/hint 各一路)。不做全量动态键解析——拼接形态的键在此设防范围外。
1954+
// ② 图标名未注册:Icon 对查不到的名字 return null(无回退、无告警),闸门照绿
1955+
// 而屏幕上图标没了。本轮 star 入口就是这么哑掉的。这里钉「每个用到的名字都在
1956+
// ICON_PATHS 注册表里」+ 提取与注册表的最低数量(防正则空转的静默绿)。
1957+
test("panel copy and icons must not silently vanish (missing dict lines, unregistered icon names)", () => {
1958+
const defined = (key) => clientSource.includes('"' + key + '":');
1959+
1960+
// ①-a 字面量用法(右括号紧贴字符串,排除 "前缀" + 变量 拼接形态)
1961+
const usedKeys = new Set();
1962+
for (const m of clientSource.matchAll(/\bt\("([a-zA-Z0-9_.]+)"\)/g)) usedKeys.add(m[1]);
1963+
assert.ok(usedKeys.size >= 300, `the literal scan must actually see the panel's t() calls (saw ${usedKeys.size})`);
1964+
// ①-b 模板展开:组键 与 旗标键(label + .hint 两路)
1965+
const groupKeys = [...clientSource.matchAll(/key: "(group\.[a-z]+)"/g)].map((m) => m[1]);
1966+
assert.ok(groupKeys.length >= 5, `FEATURE_GROUPS must be parseable (saw ${groupKeys.length} groups)`);
1967+
for (const g of groupKeys) usedKeys.add("memory.features." + g);
1968+
const flagKeys = [...new Set([...clientSource.matchAll(/items: \[((?:[^\]]|\n)*)\]/g)]
1969+
.flatMap((m) => [...m[1].matchAll(/"([a-zA-Z0-9_.]+)"/g)].map((x) => x[1])))];
1970+
assert.ok(flagKeys.length >= 20, `group items must be parseable (saw ${flagKeys.length})`);
1971+
for (const k of flagKeys) { usedKeys.add("memory.features." + k); usedKeys.add("memory.features." + k + ".hint"); }
1972+
1973+
const missing = [...usedKeys].filter((k) => !defined(k)).sort();
1974+
assert.deepEqual(missing, [], `用而无典的 i18n 键(界面会裸奔出键名):${missing.join(", ")}`);
1975+
1976+
// ② 图标名:注册表形状(顶层对象、六空格缩进)+ Icon 表达式与 feedRow 首参的提取
1977+
const registered = new Set([...clientSource.matchAll(/^\s{6}([a-zA-Z]+): \[\[/gm)].map((m) => m[1]));
1978+
assert.ok(registered.size >= 10, `the ICON_PATHS registry must be parseable (saw ${registered.size})`);
1979+
const iconNames = new Set();
1980+
for (const m of clientSource.matchAll(/h\(Icon, \{ name: ([^}]+?) [,}]/g)) {
1981+
const expr = m[1];
1982+
const direct = expr.match(/^"([a-zA-Z]+)"$/);
1983+
if (direct) { iconNames.add(direct[1]); continue; }
1984+
// 只取三元分支的纯字母串;"===" 比较对象前面是运算符不是 ? : ,不会误伤
1985+
for (const b of expr.matchAll(/[?:]\s*"([a-zA-Z]+)"/g)) iconNames.add(b[1]);
1986+
}
1987+
for (const m of clientSource.matchAll(/feedRow\(\s*"([a-zA-Z]+)"/g)) iconNames.add(m[1]);
1988+
assert.ok(iconNames.size >= 8, `icon usage must be parseable (saw ${iconNames.size})`);
1989+
const noIcon = [...iconNames].filter((n) => !registered.has(n)).sort();
1990+
assert.deepEqual(noIcon, [], `Icon 静默 return null 的未注册名:${noIcon.join(", ")}`);
1991+
});

0 commit comments

Comments
 (0)