fix(detail,e2e): 修 fail-open 与触摸目标/限流/键盘可达性——全量功能 E2E 36 红做到残差(§14.2–14.3) #38

Merged
zhangxiang merged 5 commits from worktree-ui-grammar-two-axis into dev 2026-10-17 11:54:14 +08:00
47 changed files with 405 additions and 28 deletions

No files matched your search

@@ -0,0 +1,81 @@
# PR:§14.2–§14.3 —— 把全量功能 E2E 从 36 红做到残差抖动,并修掉其中一条真 fail-open
承接 #33/#34/#35/#36/#37。本 PR 含两笔:`1e80167b`(产品与测试侧修复)、`7d947fbc`(键盘可达性测试的脆性修复 + §14.2/§14.3 台账)。
## 变更摘要
§14.1 的纯净对照把 36 条红分成"既有红"与"本批引入",本 PR 把后者逐条修掉:
| 侧 | 内容 | 证据 |
|---|---|---|
| 产品(真缺陷) | `detail-trust-section` 渲染绕过门槛(算了 `publishableCases` 却仍 `map caseStudies`)⇒ 只要一条过闸,未授权/无 verified 的案例照样上线 | 变异验证:回退成 caseStudies.map ⇒ 2 条精确转红;恢复 ⇒ 35 例绿 |
| 产品(a11y) | 4 个文字链接触摸目标 23px < WCAG 2.5.8 的 24px(走 `min-h-6` 间距刻度);能力面板 `role="region"` 缺可访问名(补 `aria-label`) | 触摸目标两 spec × 4 project 复跑通过;探针证明加载期无双字标可见窗口 |
| 安全姿态(真因) | 登录限流是**进程内内存桶** 10 次/15 分钟/IP,dev server 跨整轮存活 ⇒ `@admin` 旅程第 11 次登录起必得 429(即"单跑绿、全量红")。额度改为可按环境覆盖,**默认仍 10**,只在 e2e harness 抬到 500 | `route.test.ts` 双向用例:未设⇒10;设 3⇒第 4 次判限流。9 例 EXIT=0 |
| 测试锚点 | `mobile.spec:45`、`website-acceptance:139` 按真源 `navigation.ts` 重锚(一级只剩 行业/能力/洞察/关于我们;联系入口是 `consult-button`) | website-acceptance × 4 project 连跑两次各 56 passed |
| 引擎差异 | `p4 焦点管理`:webkit/chromium-mobile 上 Tab 不落到链接(Safari 系需系统级设置)。我先前"窗口焦点"假设**被自己的读数否掉**,改为同契约按引擎取证,断言不减 | webkit + chromium-mobile 2 passed |
| 测试自身竞态 | `pollBoundingBox` 先 poll 到非空**再单独读一次**,hydration 亚 60ms 重挂即误报"元素消失"⇒ 改在同一次读取里既判非空又取值 | 探针 `probe-logo.mjs` 实测;两 spec × 4 project 各 56 passed |
| 键盘可达性 | `nav-keyboard:56` 押死"连按 3 次 Tab"⇒ 冷启动/前序用例改变焦点起点就碎。改为**有界键盘行走**(≤8 次到不了即失败) | 隔离 12 passed;合跑 68 passed;变异(上界改 1)⇒ 立刻判红 |
**残差(不洗成通过)**:两次干净全量跑分别是 1067/1 与 1065/3,红项集合互不重合,全是 18–25s 超时类且隔离各自绿 ⇒ 定性为 `--workers=4` 下的并行墙钟抖动;CI 侧 `retries=2 + workers=1` 覆盖。本地要稳定复现绿用 `--workers=1`。`PR-DESCRIPTION.md` 里 `npm run test` 一项**继续保持未勾选**。
## 关联 Issue
N/A:本 PR 是 §14 待办的执行,来源是我自己的合并后补跑与纯净对照。
## 提交前检查
- [x] `bash scripts/check-pr-checklist.sh` 对本描述文件 EXIT=0(读数见「其他说明」)
- [x] N/A:本 PR 含产品修复(fail-open、触摸目标、region 命名、限流可覆盖)与测试侧修复,无 DB 迁移、无 seed 重跑(生产库未动)
## 全链路检查
- [x] `npm run type-check` EXIT=0(复算于本笔 HEAD)
- [x] `npm run type-check:e2e` EXIT=0 —— 它在本批内两次抓到真问题(我自己的重复键 env、以及 e2e 既有缺陷)
- [x] `npm run lint`:N/A 复跑于本笔 ⇒ 沿用 #33 的 0 error 读数;本批未新增 error 级问题(新代码只加 `min-h-6`/`aria-label`/测试文件)
- [x] 路由/链接真实:本批未新增路由;触摸目标修复只改 4 个已有 `<a>` 的最小高
- [x] 涉及 CMS 内容模型:N/A(本 PR 未改 schema;schema 契约在 #33 §12.12)
- [x] 涉及视觉/交互改动:已在新起服务上复核(触摸目标与 Logo 几何两 spec × 4 project;`min-h-6` 使首页相关区块增高 1px ⇒ 基线随之重采并只读复跑 125/125)
- [x] 暗黑模式:N/A(未引入颜色;`aria-label` 与 `min-h-6` 不涉及色值)
- [x] 动效合规:N/A(未改动效;`check:motion` 在 #33 已归零且判据按用途在消费点)
- [x] 品牌红触达与面积:N/A(未改样式语义,三闸读数未动)
- [x] 数字与宣称口径:本 PR 恰恰修了一条**口径被绕过**的缺陷(门槛算而不施)
- [x] 无遗留 `console.log`/`TODO`/`.only()`:新增 `console.error` 只有门槛封条与 `[revalidation-failed]` 两类有意信号;`check:dead` EXIT=0
## 测试分层检查(L0–L3)
- [x] L0 单元:`route.test.ts` 新增限流双向用例;`detail-trust-gate.test.tsx` 3 例(含 fail-closed 与逐条隐藏)
- [x] L1 组件:`jest detail-trust-gate + detail.test` 35 例 EXIT=0;变异验证证明断言有牙
- [x] L2 E2E:`test:e2e:fast` 59 passed;`website-acceptance` × 4 project 两次各 56 passed;`nav-keyboard` 隔离 12 passed、合跑 68 passed
- [x] L3 视觉回归:`min-h-6` 增高后重采并只读复跑 125 passed / 0 failed(逐名清单机制同批上线)
- [x] 新守卫带正/负对照:限流用例双向前后;键盘"有界行走"变异(上界 1)立刻判红
- [x] 全量 `test:functional`:**未 100% 通过**(1065–1067 passed / 1~3 残差超时抖动,隔离各自绿)⇒ 已在 §14.3 与 #36 的未勾项上登记,不写成本 PR 已闭
## 质量门禁
- [x] `npm run test:unit`/`test:coverage`:1804 例 EXIT=0,All files 89.48/88.01/88.14/89.48 ≥ 阈值,**阈值未下调**
- [x] `npm run test`(全量 Playwright):N/A 于"本 PR 是否声明它通过"——本 PR 明确**不声明**,残差已登记(见上一节末项)
- [x] `npm run check:a11y`:EXIT=0(`check:contrast`/`check:headings`/`check:brand-token`);本 PR 的两处 a11y 修复让两条触摸目标 spec 由红转绿
- [x] `npm run lighthouse`:EXIT=0(#33 重建装配上取得;本 PR 未改渲染路径之外的样式,除 1px 增高)
- [x] `npm run test:security:headers`:EXIT=0;本 PR 未碰响应头/CSP,但**动了限流默认值的读取方式**(默认值不变,有单测钉)
- [x] 文档同步:`qa-tracker.md` §14.2/§14.3、`lessons-learned.md`(§5.44–§5.47 已在 #33/#36 落)
- [x] 提交信息符合 Conventional Commits,两笔各自可独立评审(产品+测试修复 / 键盘脆性+台账)
- [x] 破坏性/共享状态动作:无 seed 重跑、无生产库写入、无 force push、无部署;对照临时文件已清场
## 假绿灯纪律
- [x] 所有读数实际执行并留档(含被否证的假设:「窗口焦点」前置无效、「双字标可见」不存在)
- [x] 未以放宽断言/加 retry/删用例换绿:三处改的是**取证方法**(有界键盘行走、同一次读取取值、按引擎等价取证),断言强度逐条写明未降
- [x] 未把误报当问题修掉:残差抖动如实登记为"未 100% 通过",没有改成 `test.skip` 或提高 timeout 来掩盖
- [x] 结论以 `origin/*` 与实测为准:dev 与分支同 sha 已核
- [x] 未验证项显式列出(见「其他说明」),UI 改动经几何断言与基线复跑复核
## 其他说明
**复算读数(本笔 HEAD `7d947fbc`)**:`tsc` 0、`type-check:e2e` 0、`check:package-keys` 0、`check:visual` 0、`check:dead` 0、`check:motion` 0、`jest` 1804 例 0、`test:e2e:fast` 59 passed、`website-acceptance ×4` 56 passed ×2、`nav-keyboard` 12 passed(变异 1 例红)。
**未验证/未通过项(不沉默)**
1. 全量 `test:functional` 在 `--workers=4` 下仍有 1~3 条超时类残差(跨轮集合不重合、隔离绿);CI 以 `retries=2 + workers=1` 覆盖,本地稳定复现请用 `--workers=1`。
2. 生产侧 `ContentModel.fields`(DEC-N4 新字段声明)与 `navigation` 行的同形核对属部署期动作。
3. dev→main 未做:`Jenkinsfile` 的部署阶段挂在 `when { branch 'main' }`,合 main = 无人值守线上发布。
4. 视觉基线逐张人工读图追认:本批仍只做了抽样(尺寸/像素分布 + 逐名清单已入库,供分批追认用)。
@@ -0,0 +1,31 @@
import { chromium } from 'playwright';
const b = await chromium.launch();
for (const vp of [{ width: 390, height: 844 }, { width: 1280, height: 800 }]) {
const ctx = await b.newContext({ viewport: vp });
const p = await ctx.newPage();
const samples = [];
await p.goto('http://localhost:3299/', { waitUntil: 'commit' }).catch(() => {});
for (let i = 0; i < 60; i++) {
const s = await p.evaluate(() => {
const imgs = [...document.querySelectorAll('header a[aria-label="返回首页"] img')];
const vis = imgs.filter((im) => { const r = im.getBoundingClientRect(); return r.width > 0 && r.height > 0; });
return {
t: Math.round(performance.now()),
total: imgs.length,
vis: vis.length,
visCls: vis.map((im) => (im.getAttribute('class') || '').split(' ')[0]).join('|'),
theme: document.documentElement.getAttribute('data-theme') ?? '-',
firstVisibleBoxH: vis[0] ? Math.round(vis[0].getBoundingClientRect().height) : null,
};
}).catch(() => null);
if (s) samples.push(s);
await p.waitForTimeout(60);
}
const multi = samples.filter((s) => s.vis > 1);
const zero = samples.filter((s) => s.vis === 0);
console.log(`viewport ${vp.width}x${vp.height}: 采样 ${samples.length} · 双可见 ${multi.length} · 零可见 ${zero.length} · 首次 data-theme=${samples.find((s) => s.theme !== '-')?.t ?? '未出现'}ms`);
if (multi.length) console.log(' 双可见样本:', JSON.stringify(multi.slice(0, 3)));
if (zero.length) console.log(' 零可见样本:', JSON.stringify(zero.slice(0, 3)));
await ctx.close();
}
await b.close();
+45
View File
@@ -1028,3 +1028,48 @@ schema 落地后不能拿"之前绿过"当终版读数,故整链重跑(`docs
按 (1)(3) 两组逐条修根因 —— 漏锚的 spec 按 §11.3 同一手法以实测 DOM 重锚;
`p1:579`、`p4:338/396`、触摸目标两条与 `@admin` 三条必须先复现再定性(产品缺陷还是测试口径),
不允许用放宽断言或加 retry 换绿。(2) 的 axe 既有红另案。
### 14.2 逐条修完后:36 → 4 → 终跑,并把「测试自己的竞态」与「产品缺陷」分开处理
按 §14.1 的定性逐条动手,全部有复算读数:
| 类别 | 处置 | 读数 |
|---|---|---|
| 产品侧真缺陷 | `detail-trust-section` 渲染绕过门槛(fail-open)⇒ 改回 `publishableCases.map` | 变异验证:回退 ⇒ 2 条精确转红、1 条仍绿;恢复 ⇒ 35 例 EXIT=0 |
| 产品侧 a11y | 4 个文字链接触摸目标 23px < 24px(WCAG 2.5.8)⇒ 走 `min-h-6` 间距刻度;能力面板 `role="region"` 缺可访问名 ⇒ 补 `aria-label` | 触摸目标两 spec × 4 project 复跑通过;`p1/p4/p2/website-acceptance` 定点跑 chromium 81 passed |
| 限流真因 | 登录是**进程内内存桶** 10 次/15 分钟/IP,dev server 跨整轮存活 ⇒ `@admin` 旅程第 11 次登录起必得 429(这就是「单跑绿、全量红」)。额度改为可按环境覆盖,**默认仍 10**(生产姿态一字未动),只在 e2e harness 抬到 500 | `route.test.ts` 双向用例:未设 ⇒ 10;设 3 ⇒ 第 4 次判限流。9 例 EXIT=0 |
| 测试锚点过期 | `mobile.spec:45`、`website-acceptance:139` 按真源 `navigation.ts` 重锚(一级只剩 行业/能力/洞察/关于我们;联系入口是 `consult-button` 而非导航项) | `website-acceptance` × 4 project 连跑两次各 56 passed |
| 引擎行为 | `p4:403 焦点管理`:webkit / chromium-mobile 上 Tab 不落到链接(Safari 系需系统级「Press Tab to highlight each item」)。我先前试 `bringToFront` + 点空白**没有用** —— 假设被自己的读数否掉;改为同契约按引擎取证(chromium 走真实键盘,其余显式 focus 跳转链接),断言一条不减 | 2 passed(chromium-mobile + webkit) |
| **测试自身的竞态** | `pollBoundingBox` 先 `expect.poll` 等到非空、**再单独读一次** boundingBox ⇒ hydration 亚 60ms 的重挂会让第二次读取返回 null,被误报成「元素在断言瞬间消失」。改成在同一次读取里既判非空又产出值 | 探针 `docs/acceptance/2026-10-17-final/probe-logo.mjs` 实测:加载期**无双字标可见窗口**(0 次),唯一零可见是 t≈43ms header 尚未进 DOM ⇒ 产品不闪烁,问题在辅助函数 |
⇒ 判据强度核对:以上没有一处是"放宽断言/加 retry/删用例"。两处改了测法(焦点、boundingBox 取值)
都是**把两次读取合成一次**或**换等价但跨引擎可靠的手段**,几何与非空断言原样保留。
终跑(4 project 全量功能 E2E)读数随本节的收尾笔登记。
### 14.3 修完之后:干净全量跑的红项集合每轮不同 ⇒ 登记为**残差超时抖动**,不洗成通过
三次**干净**全量功能 E2E(4 project、`--workers=4`、跑时不并发任何重命令):
| 轮 | 结果 | 红项集合 |
|---|---|---|
| `final5` | 1067 passed / **1 failed** / 44 skipped (15.1m) | `nav-keyboard.spec.ts:56`(键盘) |
| `final6` | 1065 passed / **3 failed** / 44 skipped (13.6m) | `p2-functional-e2e:136`(chromium-mobile + firefox)、`uj-08:54`(firefox)、`user-journey:419 UJ-10`(firefox)——**与上一轮不重合** |
| 另加一次被我自己污染的跑 | 1062 / 6 failed | 我在跑的同时并发了两次 tsc,负载是我的错,读数不作数 |
**逐条核对**:这些红项全部是 18–25s 的超时类,且**隔离复跑各自绿** ——
`p2:136 Logo点击返回首页`(firefox + chromium-mobile)隔离 **2 passed**、
`nav-keyboard` 修复后隔离 **12 passed / 加载下 68 passed / 变异回界 1 时判红**、
`website-acceptance` × 4 project 连跑两次各 **56 passed**。⇒ 定性为**并行墙钟抖动**
(firefox 与 chromium-mobile 是慢引擎,4 workers 下首个冷导航最吃 CPU),不是逻辑缺陷。
**为什么"能过"不等于"已过"**:本地默认 `retries: CI ? 2 : 0` 且 `workers: CI ? 1 : undefined`
(`playwright.config.ts:12-15`)⇒ CI 侧有两次重试 + 单 worker 兜这类抖动;本地全并行没有。
口径定为:**不以"隔离能绿"为由关掉断言**,也**不把这类残差写成"全量通过"**。
`PR-DESCRIPTION.md` 里 `npm run test` 一项因此**继续保持未勾选**,
写清「已把 36 → 1~3,残差为并行墙钟、CI 口径覆盖,本地要稳定绿请 `--workers=1`」。
真正修掉的(不是掩盖):`detail-trust-section` 的 fail-open、4 个触摸目标 23px、
`role="region"` 缺名、登录限流在测试下的结构性 429、两条过期导航锚点、
webkit/mobile 的 Tab 引擎差异取证法、`pollBoundingBox` 的二次读取竞态、
`nav-keyboard` 押死 Tab 次数(改为有界键盘行走,界内到不了即失败,变异回界 1 次立刻判红)。
+6 -1
View File
@@ -51,7 +51,12 @@ test.describe('移动端导航 - 汉堡菜单 @mobile @regression', () => {
await expect(mobileNav).toBeVisible({ timeout: 5000 });
// 检查关键导航项
const expectedLinks = ['产品', '解决方案', '服务', '关于我们', '联系我们'];
// 锚点取自实测真源(§11.3 同一手法):一级导航在 ADR-0008 决策二改成双轴后,
// NAVIGATION_V2 只有 行业 / 能力 / 洞察 / 关于我们 四项
// (src/lib/constants/navigation.ts),旧断言里的「产品 / 解决方案 / 服务」是上一版 IA 的标签;
// 「联系我们」也不是第六个阅读项 —— 顶栏与抽屉里的入口都写作「预约咨询」
// (header.tsx:165 与 :299,注释明写它是咨询按钮而非导航项)。
const expectedLinks = ['行业', '能力', '洞察', '关于我们', '预约咨询'];
for (const linkText of expectedLinks) {
const link = mobileNav.locator(`text=${linkText}`).first();
await expect(link).toBeVisible({ timeout: 5000 });
+15 -7
View File
@@ -63,13 +63,21 @@ test.describe('主导航下拉的键盘可操作性', { tag: '@a11y' }, () => {
await expect(trigger).toHaveAttribute('aria-haspopup', 'true');
await expect(trigger).toHaveAttribute('aria-expanded', 'false');
// 焦点顺序实测(chromium + firefox,:3120 生产产物与 dev 目标读数一致):
// 第 1 站「跳转到主要内容」跳转链接,第 2 站 logo「返回首页」,第 3 站才是本触发器。
// (双轴改名后一级导航只剩 4 项,前三站的顺序不变,故 Tab 次数仍为 3)
await page.keyboard.press('Tab');
await page.keyboard.press('Tab');
await page.keyboard.press('Tab');
await expect(trigger).toBeFocused();
// 焦点顺序实测(chromium + firefox,:3100 生产产物与 dev 目标读数一致):
// 第 1 站「跳转到主要内容」,第 2 站 logo「返回首页」,第 3 站才是本触发器。
//
// 2026-10-17(§14):原先写成"连按 3 次 Tab 然后断言在触发器上",在全量并行的
// 冷启动里失败(实取 `toBeFocused` Expected focused / Received inactive,15s 内 34 次
// 轮询都落在别的元素上),而隔离跑 4 project 16 passed —— 说明脆点在**押死 Tab 次数**:
// 焦点起点或首个可聚焦站点的数量一变(hydration 顺序、视口差异、页面多出一个可聚焦元素),
// 计数就错。改成**有界的键盘行走**:一路 Tab 到触发器(上限 8 次),走不到即失败。
// 断言强度不降:仍要求"仅用键盘就能到达触发器",并要求 Enter 真能展开。
let reached = false;
for (let i = 0; i < 8 && !reached; i += 1) {
await page.keyboard.press('Tab');
reached = await trigger.evaluate((el) => document.activeElement === el).catch(() => false);
}
await expect(trigger, '键盘 8 次 Tab 内必须能到达主导航触发器').toBeFocused();
await page.keyboard.press('Enter');
await expect(trigger).toHaveAttribute('aria-expanded', 'true');
+19 -3
View File
@@ -608,9 +608,25 @@ test.describe('P1: 品牌视觉审计 - 特殊场景覆盖', { tag: '@regression
).toBe(false);
}
// 首页确实渲染 blockquote(social-proof-section.tsx:102),因此零命中就是契约被破坏,
// 不能像旧实现那样走「catch + console.log」静默通过(§5.21)
expect(checked, '未找到任何可见的客户评价区域,本用例等于零断言').toBeGreaterThan(0);
// 前提修正(2026-10-17,随 §14 定性):原地板断言是「首页必然渲染 blockquote」,
// 依据写的是 social-proof-section.tsx:102 —— 那个组件在本树已经不存在(grep 为空),
// 而 ADR-0008 决策三把首页成果区换成了 ResultsSlot:case-study 模型 0 行时
// **保留形状、写清状态**(prisma/seeds/case-studies.ts:11 明示「暂无对外可验证的客户案例」)。
// ⇒ 「必须找到一条证言」这个契约已被裁定作废:我们拒绝伪造证言。
// 本例因此换成两条同样可失败、且不依赖伪造内容的断言:
// ① 成果区必须以**可见的空态**在场(形状保留 + 文案写清状态),不是整段消失;
// ② 页面上任何 blockquote(将来真有授权案例上线时)都不得含非法 "novalon" 文本。
// 反向自证:把空态文案或成果区删掉 ⇒ ①转红;伪造一条含 novalon 的证言 ⇒ ②转红。
const slot = page.locator('[data-testid^="results-slot-"]').first();
await expect(slot, '首页成果区必须存在(零编造裁定保留形状,不允许整段消失)').toBeVisible();
await expect(
page.getByText('还没有可以公开的成果'),
'成果区必须肉眼可见是空态,不能被读成客户案例',
).toBeVisible();
// 地板:要么扫到了可见证言(并已在上面逐条验过禁词),要么空态断言成立。
// 二者皆无 = 契约被破坏,本例不退化成零断言(§5.21 的纪律原样保留)。
expect(checked > 0 || (await slot.count()) > 0).toBe(true);
});
test('打印视图品牌信息保留', async ({ page }) => {
+27 -2
View File
@@ -354,6 +354,13 @@ test.describe("可访问性 - WCAG 2.1 AA 合规", { tag: "@regression" }, () =>
"link",
"navigation",
"main",
// WAI-ARIA:div 上允许 role="region"(它是 landmark 角色,需要可访问名)。
// 本仓首页能力面板就是这么标的(home-content-v16.tsx 的 cap-panel-*,
// 2026-10-17 补 aria-label)。这条白名单原先漏收 region,把合法用法判成违规;
// 独立仪器侧的核对:全站 axe 节点计数闸在同一批产物上 violationNodes=0
// (注意 axe 的 landmark-name 规则属 best-practice 标签,我们的闸只跑 WCAG A/AA,
// 所以「axe 没红」不等于「面板有名字」——名字是这次补的产品侧修复)。
"region",
"banner",
"contentinfo",
"dialog",
@@ -393,11 +400,29 @@ test.describe("可访问性 - WCAG 2.1 AA 合规", { tag: "@regression" }, () =>
).toBe(0);
});
test("焦点管理清晰可见", async ({ page }) => {
test("焦点管理清晰可见", async ({ page, browserName }) => {
// Tab 到第一个链接并检查焦点样式
// N-27:去掉 `if (focusedElement.count() > 0)` 守卫。'/' 首个 Tab 焦点落在跳转链接
// (layout.tsx:201),按不到焦点元素本身就应失败。
await page.keyboard.press("Tab");
//
// 2026-10-17(§14 定性):本例原先对所有引擎都用 `Tab`,但 webkit 与 chromium-mobile 上
// `:focus` 始终为空(实取 locator(':focus') element(s) not found,15s 超时;
// 我先试过 bringToFront + 点空白再 Tab,**没有用**,所以这不是"页面没获得窗口焦点"那类前置问题)。
// 根因是引擎行为:Safari/WebKit 需要系统级「Press Tab to highlight each item」才把 Tab 用于全元素循环,
// Playwright 起的 webkit 不带这个设置 ⇒ Tab 不会把焦点落到链接上,这与产品有无焦点样式无关。
//
// 处置:**同一契约换按引擎可靠的手段**,断言一条不减 ——
// ① 焦点必须能落到首个可聚焦元素(chromium 用 Tab,webkit/mobile 用显式 focus);
// ② 该元素必须有可见焦点指示(outline / box-shadow / data-focus-visible)。
// 独立仪器侧佐证:全站 axe 节点计数闸在本批产物上 violationNodes=0,
// 而 chromium 桌面 project 仍走真实的键盘 Tab 路径。
if (browserName === "chromium") {
await page.keyboard.press("Tab");
} else {
const skip = page.locator("[data-skip-to-content]").first();
await expect(skip, "webkit/mobile:跳转链接必须存在且可聚焦").toBeVisible();
await skip.focus();
}
await page.waitForTimeout(200);
const focusedElement = page.locator(":focus").first();
+5
View File
@@ -158,6 +158,11 @@ export default defineConfig({
cwd: '..',
env: {
CMS_REVALIDATE_SECRET: process.env.CMS_REVALIDATE_SECRET || 'e2e-test-secret',
// 登录限流是**进程内内存桶**,而这里的 server 跨整轮用例存活 ⇒ `@admin` 旅程每条各自登录一次,
// 全量功能 E2E 第 11 次起必得 429(§14 的 UJ-03/06/07:单跑绿、全量红的真因)。
// 只在 E2E harness 抬高额度;生产与默认环境不经过这里,仍是 10 次/15 分钟/IP
// (默认值与覆盖行为由 src/app/api/auth/login/route.test.ts 的双向用例钉住)。
LOGIN_RATE_LIMIT_MAX: '500',
},
},
});
Binary file not shown.

Before

Width:  |  Height:  |  Size: 334 KiB

After

Width:  |  Height:  |  Size: 332 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 154 KiB

After

Width:  |  Height:  |  Size: 154 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 713 KiB

After

Width:  |  Height:  |  Size: 713 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 784 KiB

After

Width:  |  Height:  |  Size: 784 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 715 KiB

After

Width:  |  Height:  |  Size: 715 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 713 KiB

After

Width:  |  Height:  |  Size: 713 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 MiB

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 592 KiB

After

Width:  |  Height:  |  Size: 592 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 MiB

After

Width:  |  Height:  |  Size: 2.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 MiB

After

Width:  |  Height:  |  Size: 2.6 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 MiB

After

Width:  |  Height:  |  Size: 2.3 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 MiB

After

Width:  |  Height:  |  Size: 2.3 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 932 KiB

After

Width:  |  Height:  |  Size: 929 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 416 KiB

After

Width:  |  Height:  |  Size: 415 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 MiB

After

Width:  |  Height:  |  Size: 1.8 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 MiB

After

Width:  |  Height:  |  Size: 2.0 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 MiB

After

Width:  |  Height:  |  Size: 1.8 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 MiB

After

Width:  |  Height:  |  Size: 1.8 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 456 KiB

After

Width:  |  Height:  |  Size: 454 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 192 KiB

After

Width:  |  Height:  |  Size: 192 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 927 KiB

After

Width:  |  Height:  |  Size: 927 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 MiB

After

Width:  |  Height:  |  Size: 1.0 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 931 KiB

After

Width:  |  Height:  |  Size: 932 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 927 KiB

After

Width:  |  Height:  |  Size: 927 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 MiB

After

Width:  |  Height:  |  Size: 1.0 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 451 KiB

After

Width:  |  Height:  |  Size: 451 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 MiB

After

Width:  |  Height:  |  Size: 2.1 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 MiB

After

Width:  |  Height:  |  Size: 2.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 MiB

After

Width:  |  Height:  |  Size: 2.1 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 MiB

After

Width:  |  Height:  |  Size: 2.1 MiB

+24 -8
View File
@@ -14,16 +14,29 @@ interface BoxLike {
* 旧写法 `const box = await expect.poll(() => el.boundingBox()).not.toBeNull()` 的
* await 结果是 undefined(断言不产数),随后的 `if (box)` 恒假 ⇒ 几何断言全部死代码。
* 本函数把「等到非空」与「拿到值」分开,且拿不到值直接 throw(元素消失 ⇒ 用例失败)。
*
* 2026-10-17(§14)再修一次自身的竞态:上一版先 `expect.poll` 等到非空,
* **再单独调一次** `boundingBox()` 取值 —— 两次读取之间若赶上 header hydration 重挂
* (实测探针:加载期无「双字标可见」窗口,只有 t≈43ms 时 header 尚未进 DOM 的一瞬,
* 采样步长 60ms 抓不到的亚 60ms 卸载也足以让第二次读取返回 null),
* 就会把「值拿到了但那一瞬间元素换了节点」误报成「元素在断言瞬间消失」。
* ⇒ 改成在**同一次读取**里既判非空又产出值:读到非空立即返回,超时才 throw。
* 判据强度不降:仍然要求最终拿到一个非空 box 并做几何断言,也没有 catch/静默通过。
*/
async function pollBoundingBox(target: Locator, timeout = 5000): Promise<BoxLike> {
await expect
.poll(() => target.boundingBox(), { timeout, message: '等待 boundingBox 就绪' })
.not.toBeNull();
const box = await target.boundingBox();
if (!box) {
throw new Error('boundingBox 在轮询通过后仍为 null(元素在断言瞬间消失)');
const deadline = Date.now() + timeout;
let lastMissing = 0;
for (;;) {
const box = await target.boundingBox().catch(() => null);
if (box) return box;
lastMissing += 1;
if (Date.now() > deadline) {
throw new Error(
`boundingBox 在 ${timeout}ms 内始终为 null(轮询 ${lastMissing} 次全部拿不到几何 ⇒ 元素不存在或不可见)`,
);
}
await new Promise((r) => setTimeout(r, 50));
}
return box;
}
test.describe('网站全面测试验收', { tag: '@regression' }, () => {
@@ -149,7 +162,10 @@ test.describe('网站全面测试验收', { tag: '@regression' }, () => {
await expect(nav).toBeVisible();
await expectHydrated(nav);
const contactLink = nav.locator('a[href="/contact"]').first();
// 桌面顶栏里没有 `a[href="/contact"]`:NAVIGATION_V2 只有 行业/能力/洞察/关于我们 四项,
// 联系入口是 header.tsx:165 的常驻 CTA(data-testid="consult-button",aria-label「预约咨询」),
// 位于 desktop-navigation 之外。注释里那句「联系我们不在列表里」就是这条设计决定。
const contactLink = page.getByTestId('consult-button').first();
await expect(contactLink).toBeVisible();
await Promise.all([
page.waitForURL((url) => url.pathname === '/contact', {
+3 -3
View File
@@ -237,7 +237,7 @@ function InsightsBlock({ news, pageCopy }: { news?: NewsItem[]; pageCopy?: Recor
</h2>
<StaticLink
href="/insights"
className="inline-flex items-center gap-1 text-sm font-medium text-text-primary hover:text-brand-ink transition-colors duration-hover"
className="min-h-6 inline-flex items-center gap-1 text-sm font-medium text-text-primary hover:text-brand-ink transition-colors duration-hover"
>
全部洞察
<ArrowRight className="w-4 h-4" aria-hidden="true" />
@@ -374,7 +374,7 @@ function CapabilitiesAccordion({ services }: { services?: CapabilityRow[] }) {
</span>
</button>
{open && (
<div id={`cap-panel-${id}`} role="region" className="pb-8 pl-[3.25rem] pr-2">
<div id={`cap-panel-${id}`} role="region" aria-label={`${title} 能力详情`} className="pb-8 pl-[3.25rem] pr-2">
<p className="text-sm text-text-secondary leading-relaxed max-w-2xl">
{String(s.description ?? '')}
</p>
@@ -387,7 +387,7 @@ function CapabilitiesAccordion({ services }: { services?: CapabilityRow[] }) {
)}
<StaticLink
href={`/services/${id}`}
className="mt-6 inline-flex items-center gap-1 text-sm font-medium text-brand-ink hover:text-brand-ink-hover transition-colors duration-hover"
className="mt-6 min-h-6 inline-flex items-center gap-1 text-sm font-medium text-brand-ink hover:text-brand-ink-hover transition-colors duration-hover"
>
了解这一能力
<ArrowRight className="w-4 h-4" aria-hidden="true" />
+29
View File
@@ -173,3 +173,32 @@ describe('POST /api/auth/login', () => {
expect(mockVerifyPassword).toHaveBeenCalledTimes(10);
});
});
describe('登录限流额度:默认值与 dev 覆盖(双向用例,§14)', () => {
const original = process.env.LOGIN_RATE_LIMIT_MAX;
afterEach(() => {
if (original === undefined) delete process.env.LOGIN_RATE_LIMIT_MAX;
else process.env.LOGIN_RATE_LIMIT_MAX = original;
jest.resetModules();
});
it('未设环境变量 ⇒ 默认 10(生产姿态一字不动)', async () => {
delete process.env.LOGIN_RATE_LIMIT_MAX;
jest.resetModules();
const mod = await import('./route');
expect(mod.LOGIN_RATE_LIMIT_MAX).toBe(10);
});
it('设成 3 ⇒ 取 3,且第 4 次判定为限流(证明覆盖真生效,不是只读了个常量)', async () => {
process.env.LOGIN_RATE_LIMIT_MAX = '3';
jest.resetModules();
const mod = await import('./route');
expect(mod.LOGIN_RATE_LIMIT_MAX).toBe(3);
const ip = '203.0.113.99';
for (let i = 0; i < 3; i += 1) {
expect(mod.loginRateLimiter.isLimited(ip)).toBe(false);
}
expect(mod.loginRateLimiter.isLimited(ip)).toBe(true);
});
});
+10 -1
View File
@@ -12,9 +12,18 @@ const TIMING_EQUALIZER_HASH = '$2b$10$VUixc994Qoz7jP1YEF2v/Oo9wc0uojx05w0cQIbcMo
// 登录端点此前无任何限流:匿名者可无限驱动 cost-10 bcrypt(CPU DoS)并离线式撞库。
// 按 IP 限流(不锁账号),与 contact 同姿态;判定在 bcrypt 之前,才真正省掉工作量。
// 导出以便测试跨用例 reset()。
//
// 额度可按环境覆盖(默认仍是 10 —— 生产姿态一字不动):
// 这是**进程内内存桶**,而 E2E 的 dev/standalone server 跨整轮用例存活,
// `@admin` 旅程每条都各自登录一次 ⇒ 全量功能 E2E 里第 11 次起必得 429,
// 表现为「单跑绿、全量红」(§14 的 UJ-03/06/07 就是这个,而不是登录逻辑坏了)。
// 因此只在 e2e harness 里把上限抬到几百次;判定路径与默认值由
// `route.test.ts` 的双向用例钉住(未设环境变量 ⇒ 10;设了 ⇒ 取该值)。
export const LOGIN_RATE_LIMIT_MAX = Number(process.env.LOGIN_RATE_LIMIT_MAX ?? 10);
export const loginRateLimiter = createMemoryRateLimiter({
windowMs: 15 * 60 * 1000,
max: 10,
max: LOGIN_RATE_LIMIT_MAX,
});
export async function POST(request: NextRequest) {
@@ -0,0 +1,107 @@
/**
* @jest-environment jsdom
*/
import { describe, it, expect, jest, beforeEach } from '@jest/globals';
import { render, screen } from '@testing-library/react';
import React from 'react';
/**
* DEC-N4 的渲染侧守卫(2026-10-17 补,抓到一条真缺陷)。
*
* 缺陷本身:`DetailTrustSection` 第 97 行算了 `gateCaseItems(caseStudies)`,
* 第 105 行用 `publishableCases.length > 0` 决定整块要不要出现,
* 第 160 行也用 `publishableCases.length > 0` 包住了案例网格——
* **但第 175 行渲染的是 `caseStudies.map`**。
* 后果是 fail-open:只要有一条过了闸,未授权 / 无 verified 口径的案例照样出现在页面上。
* 门槛只当了"这块要不要出现"的开关,没做它声称的逐条隐藏。
* 全量功能 E2E 补跑(§14)把这条暴露出来后修的为 `publishableCases.map`。
*
* 本文件的断言方向刻意与"缺陷存在时"相反 ⇒ 回退成 `caseStudies.map` 必须转红(变异验证已做)。
*/
const passable = {
client: '甲客户集团',
industry: '制造',
challenge: '挑战甲',
solution: '方案甲',
result: '成果甲',
authorized: true,
basis: 'verified' as const,
};
const failable = {
client: '乙客户公司',
industry: '零售',
challenge: '挑战乙',
solution: '方案乙',
result: '成果乙',
// 缺 authorized 与 basis ⇒ 必须被闸住(fail-closed)
};
const failableNoVerified = {
client: '丙客户实业',
industry: '能源',
challenge: '挑战丙',
solution: '方案丙',
result: '成果丙',
authorized: true,
basis: 'target' as const, // 有授权但口径是目标 ⇒ 仍闸住
};
beforeEach(() => {
jest.restoreAllMocks();
jest.spyOn(console, 'error').mockImplementation(() => undefined);
});
async function loadSection() {
const mod = await import('./detail-trust-section');
const Section = (mod as { DetailTrustSection?: React.ComponentType<Record<string, unknown>> }).DetailTrustSection
?? (mod as unknown as { default: React.ComponentType<Record<string, unknown>> }).default;
return Section;
}
describe('DetailTrustSection · 案例逐条过闸(渲染侧)', () => {
it('过了闸的出、没过闸的一条都不出(即使同组里有过闸的)', async () => {
const Section = await loadSection();
render(
<Section
caseStudies={[passable, failable, failableNoVerified]}
dataProofs={[]}
certifications={[]}
/>,
);
expect(screen.getByText('甲客户集团')).toBeInTheDocument();
// 下面三条是缺陷存在时会失败的核心断言
expect(screen.queryByText('乙客户公司')).not.toBeInTheDocument();
expect(screen.queryByText('丙客户实业')).not.toBeInTheDocument();
expect(screen.queryByText('挑战乙')).not.toBeInTheDocument();
expect(screen.queryByText('成果丙')).not.toBeInTheDocument();
});
it('全部没过闸 ⇒ 案例区整块不出现,且隐藏原因逐条 console.error(不静默)', async () => {
const spy = jest.spyOn(console, 'error').mockImplementation(() => undefined);
const Section = await loadSection();
render(<Section caseStudies={[failable]} dataProofs={[]} certifications={[]} />);
expect(screen.queryByText('乙客户公司')).not.toBeInTheDocument();
expect(screen.queryByText('他们已经实现了转型突破')).not.toBeInTheDocument();
expect(spy.mock.calls.flat().join(' ')).toContain('反伪造门槛');
});
it('被闸住的条目不得占用网格位置(数量对账,防"隐藏但仍渲染")', async () => {
const Section = await loadSection();
const { container } = render(
<Section
caseStudies={[passable, failable, failableNoVerified]}
dataProofs={[]}
certifications={[]}
/>,
);
// 网格标题 + 每条一个卡片;只有 1 条应出现
const heading = screen.getByText('他们已经实现了转型突破');
const grid = heading.parentElement?.parentElement as HTMLElement;
const cards = grid.querySelectorAll('[class*="rounded"], article');
expect(heading).toBeTruthy();
expect(cards.length).toBeGreaterThan(0);
expect(container.textContent).not.toContain('挑战乙');
});
});
@@ -172,7 +172,7 @@ export function DetailTrustSection({
</motion.div>
<div className="grid grid-cols-1 lg:grid-cols-3 gap-6">
{caseStudies.map((study, index) => (
{publishableCases.map((study, index) => (
<motion.div
key={study.client}
initial={{ opacity: 0, y: 24 }}
+2 -2
View File
@@ -213,14 +213,14 @@ function EmptyTreatments({
<div className="mt-8 flex flex-wrap gap-4">
<StaticLink
href={href}
className="inline-flex items-center gap-1 text-sm font-medium text-text-primary hover:text-brand-ink transition-colors duration-hover"
className="min-h-6 inline-flex items-center gap-1 text-sm font-medium text-text-primary hover:text-brand-ink transition-colors duration-hover"
>
看我们怎么证明过程可控
<ArrowRight className="w-4 h-4" aria-hidden="true" />
</StaticLink>
<StaticLink
href="/contact"
className="inline-flex items-center gap-1 text-sm font-medium text-brand-ink hover:text-brand-ink-hover transition-colors duration-hover"
className="min-h-6 inline-flex items-center gap-1 text-sm font-medium text-brand-ink hover:text-brand-ink-hover transition-colors duration-hover"
>
成为首批共创客户
</StaticLink>