Skip to content

test(dashboard): 限定 CSS 断言到目标规则 - #1278

Merged
deepcoldy merged 1 commit into
deepcoldy:masterfrom
LPX-E5BD8:test/css-rule-boundaries
Sep 7, 2026
Merged

test(dashboard): 限定 CSS 断言到目标规则#1278
deepcoldy merged 1 commit into
deepcoldy:masterfrom
LPX-E5BD8:test/css-rule-boundaries

Conversation

@LPX-E5BD8

@LPX-E5BD8 LPX-E5BD8 commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

问题

部分 Dashboard CSS 测试使用 selector { [\s\S]*? property 形式的正则。该模式不会在目标规则的 } 停止;删除真实声明后,后续任意规则里的同名属性仍可让断言通过。

Fixes #1243
Fixes #1159

修复

  • 新增共享 cssRuleBody() 测试 helper,只返回一个无嵌套 CSS 规则自己的声明块,并在发现嵌套块时 fail closed。
  • 将 Issue 列出的 8 条弱断言改为规则体内匹配:
    • version control 层级
    • mobile bulk action 按钮
    • mobile topic view
    • bot defaults wide tile
    • description preview
    • grant actions
    • disabled sort menu
    • schedule actions
  • 将 bot defaults 文件中已有的局部 ruleBody() 收敛到共享 helper,避免继续复制脆弱写法。

影响面

  • 只修改测试,不改变生产 CSS 或运行时代码。
  • helper 适用于无嵌套块的普通规则;需要指定 at-rule 范围的测试仍应先定位对应上下文。

验证

  • Issue 已记录逐条删除真实属性时旧断言仍通过的反变异证据。
  • 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:通过。

Copilot AI lite review requested due to automatic review settings September 6, 2026 10:41
@LPX-E5BD8
LPX-E5BD8 requested a review from deepcoldy as a code owner September 6, 2026 10:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

Comment thread test/helpers/css-rule.ts
Comment on lines +3 to +9
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);
@LPX-E5BD8
LPX-E5BD8 force-pushed the test/css-rule-boundaries branch from 0cf1c63 to 42e6f3e Compare September 6, 2026 10:51
@deepcoldy

Copy link
Copy Markdown
Owner

你好!这是 Botmux 的自动评审流程。

本 PR 的评审群已创建:https://applink.feishu.cn/client/chat/open?openChatId=oc_cc07e96e6b0d89c7c4d5d518dd119631

但你暂时未被拉入群中——你的 GitHub 账号(LPX-E5BD8)不在自动拉群名单里。请把你的 GitHub 账号和飞书信息补进名单文档:
https://bytedance.larkoffice.com/wiki/WJ1nwWbtxi89erkNGNbcgkt9nUe

补好后,后续复审会自动把你拉进群。感谢贡献!

抽出共享 cssRuleBody helper,并将八条会跨越闭合括号的惰性正则改为只检查目标规则体,避免相邻规则中的同名声明冒充证据。

Refs: deepcoldy#1243
Refs: deepcoldy#1159

Co-authored-by: TRAE CLI <noreply@bytedance.com>
@deepcoldy
deepcoldy force-pushed the test/css-rule-boundaries branch from 42e6f3e to 4c9b50d Compare September 7, 2026 07:52
@deepcoldy
deepcoldy merged commit 46cc783 into deepcoldy:master Sep 7, 2026
4 checks passed
@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown

🚀 Released in v3.19.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants