Skip to content

Commit c22d2bd

Browse files
committed
fix(ui): 棘轮守卫同前缀目录漏判与白名单措辞
两处均为评审者实测抓出、由控制方直接修(非实施者),并自证有效。 1) 棘轮守卫:!f.startsWith(ICONS_DIR) 是裸字符串前缀比较,任何以 icons 开头的同级目录被静默豁免。 评审者双针实测:ui/icons-legacy/Probe.tsx -> exit 0 放行(漏判)。改为比较 ICONS_DIR + sep。 修复后用同一探针复现:exit 1 并点名 ui/icons-legacy/Probe.tsx;移除探针后图标层 21/21 全绿 (证明 ui/icons/ 自身的正常排除未被破坏)。该写法逐字来自计划,属计划缺陷。 2) types.ts 两处注释与 paths.test.ts 用例名称「四种」标签,而 ICON_ELEMENT_TAGS 实为 3 种 (path/circle/rect)。该 Minor 在 T1 任务评审已登记,但当时只修了计划、代码里的措辞留了下来。 零行为变更(守卫判定范围修正除外):tsc exit 0 · 图标层 21/21 · 全量 809/809。
1 parent 1da830f commit c22d2bd

3 files changed

Lines changed: 6 additions & 4 deletions

File tree

‎app/src/ui/icons/no-inline-svg.test.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ function collectFiles(dir: string, out: string[] = []): string[] {
3838

3939
function filesWithInlineSvg(): string[] {
4040
return collectFiles(SRC)
41-
.filter((f) => !f.startsWith(ICONS_DIR))
41+
// 排除图标层自身(它当然要能写 svg)。比较**必须带上分隔符**:裸的 `startsWith(ICONS_DIR)`
42+
// 会把 `ui/icons-legacy/` 这类同前缀的兄弟目录一并静默豁免 —— 守卫会悄悄失效(实测已复现)。
43+
.filter((f) => !f.startsWith(ICONS_DIR + sep))
4244
.filter((f) => readFileSync(f, "utf8").includes("<svg"))
4345
.map((f) => relative(SRC, f).split(sep).join("/"))
4446
.sort();

‎app/src/ui/icons/paths.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe("图标几何契约", () => {
3131
}
3232
});
3333

34-
it("元素只用白名单内的四种标签", () => {
34+
it("元素只用白名单内的三种标签", () => {
3535
for (const name of ICON_NAMES) {
3636
for (const el of ICON_PATHS[name].elements) {
3737
expect(ICON_ELEMENT_TAGS, `${name} 含越界标签 ${el.tag}`).toContain(el.tag);

‎app/src/ui/icons/types.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
* 组件只有一个。
88
*
99
* 副作用:无(纯类型 + 常量)。
10-
* 边界:几何只允许四种 SVG 元素(见 `ICON_ELEMENT_TAGS`)——**不含任何颜色字段**,
10+
* 边界:几何只允许三种 SVG 元素(见 `ICON_ELEMENT_TAGS`)——**不含任何颜色字段**,
1111
* 颜色一律由 `currentColor` 决定。新增元素类型必须先在此登记并同步契约测试。
1212
*/
1313

14-
/** 几何白名单:只用这四种,足够表达全部图标且便于穷举校验 */
14+
/** 几何白名单:只用这三种,足够表达全部图标且便于穷举校验 */
1515
export const ICON_ELEMENT_TAGS = ["path", "circle", "rect"] as const;
1616

1717
export type IconElementTag = (typeof ICON_ELEMENT_TAGS)[number];

0 commit comments

Comments
 (0)