test(dashboard): 限定 CSS 断言到目标规则 - #1278
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
新增的 cssRuleBody() 声称用于“flat rule body”,但实现未对嵌套 {...} 规则体进行防御,存在未来被误用时静默截断并导致断言失真的风险。
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
该 PR 通过引入共享测试 helper 来“限定 CSS 断言到目标规则体内”,修复 Dashboard 多处 CSS 回归测试因惰性正则跨越 } 而可能被后续无关规则“喂绿”的问题,从而提升样式回归测试的可信度。
Changes:
- 新增
cssRuleBody()helper:从完整 CSS 文本中截取指定 selector 的单条规则声明块,用于避免断言跨规则匹配。 - 将多个 Dashboard CSS 测试从“跨规则惰性正则”改为在规则体内断言目标属性(含拆分为多条更精确断言的场景)。
- 收敛
dashboard-bot-defaults-layout测试中原有的局部ruleBody()为共享 helper,减少脆弱写法继续扩散。
File summaries
| File | Description |
|---|---|
| test/helpers/css-rule.ts | 新增共享 helper,用于截取 selector 对应的规则体,避免断言跨越 }。 |
| test/dashboard-version-popover.test.ts | 将 .dashboard-version-control 的断言改为在规则体内匹配 z-index。 |
| test/dashboard-schedules-ui.test.ts | 将 .schedule-actions 的断言改为在规则体内匹配 flex-wrap。 |
| test/dashboard-rebase-ui-regressions.test.ts | 对禁用态 summary:hover 的断言改为先取规则体再分别断言关键属性。 |
| test/dashboard-mobile-layout.test.ts | 将 mobile 布局相关断言改为规则体内匹配,避免跨规则误判。 |
| test/dashboard-bot-defaults-layout.test.ts | 移除局部 ruleBody() 并改用共享 helper,收敛并强化多处 CSS 断言。 |
Review details
- Files reviewed: 6/6 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| const marker = `${selector} {`; | ||
| const start = source.indexOf(marker, from); | ||
| if (start === -1) throw new Error(`selector not found in CSS: ${selector}`); | ||
| const bodyStart = start + marker.length; | ||
| const end = source.indexOf('}', bodyStart); | ||
| if (end === -1) throw new Error(`unterminated CSS rule: ${selector}`); | ||
| return source.slice(bodyStart, end); |
0cf1c63 to
42e6f3e
Compare
|
你好!这是 Botmux 的自动评审流程。 本 PR 的评审群已创建:https://applink.feishu.cn/client/chat/open?openChatId=oc_cc07e96e6b0d89c7c4d5d518dd119631 但你暂时未被拉入群中——你的 GitHub 账号(LPX-E5BD8)不在自动拉群名单里。请把你的 GitHub 账号和飞书信息补进名单文档: 补好后,后续复审会自动把你拉进群。感谢贡献! |
抽出共享 cssRuleBody helper,并将八条会跨越闭合括号的惰性正则改为只检查目标规则体,避免相邻规则中的同名声明冒充证据。 Refs: deepcoldy#1243 Refs: deepcoldy#1159 Co-authored-by: TRAE CLI <noreply@bytedance.com>
42e6f3e to
4c9b50d
Compare
|
🚀 Released in v3.19.3 |
问题
部分 Dashboard CSS 测试使用
selector { [\s\S]*? property形式的正则。该模式不会在目标规则的}停止;删除真实声明后,后续任意规则里的同名属性仍可让断言通过。Fixes #1243
Fixes #1159
修复
cssRuleBody()测试 helper,只返回一个无嵌套 CSS 规则自己的声明块,并在发现嵌套块时 fail closed。ruleBody()收敛到共享 helper,避免继续复制脆弱写法。影响面
验证
npx vitest run --project unit test/dashboard-version-popover.test.ts test/dashboard-mobile-layout.test.ts test/dashboard-bot-defaults-layout.test.ts test/dashboard-rebase-ui-regressions.test.ts test/dashboard-schedules-ui.test.ts:53 passed。bun run vitest run --project unit test/dashboard-version-popover.test.ts test/dashboard-mobile-layout.test.ts test/dashboard-bot-defaults-layout.test.ts test/dashboard-rebase-ui-regressions.test.ts test/dashboard-schedules-ui.test.ts:53 passed。bun run build:通过。