chore(gates): DEC-N6 让 e2e 进类型口径,并修 pre-commit 位与证据路径覆盖历史

- 新增 e2e/tsconfig.json + `npm run type-check:e2e`(并入 test:all)。
  本轮实测证据:teardown 补丁里第二个 `const revalidateSecret` 与既有声明重名,
  `npm run type-check` 全程 EXIT=0,只有 `playwright test --list` 才报重复声明 ——
  现在静态期就能抓。读数:type-check:e2e EXIT=0。
- .husky/pre-commit 的索引模式改回 100755(本轮每次提交都在打
  "was ignored because it's not set as executable",即 lint-staged 在任何克隆里都不执行)。
  验证看 `git ls-files -s .husky` 的 mode,不是看文件系统权限。
- axe 证据落盘改为按运行轮次分目录(原写死 docs/acceptance/2026-09-21-axe/axe-evidence.json,
  于是每跑一次就覆盖一次历史:0157b1c9 里那 409 行 diff 就是这么产生的),
  并补 check:axe:selftest;判定逻辑与退出码三档语义未动。
- 顺带修一处仪器级缺陷:package.json 里 `type-check:e2e` 被写了两遍 ——
  JSON 重复键是后者静默覆盖前者,不会报错也不会判红,正是本仓反复吃的"重复声明"类。
  现取键数与值由 node 回读校验。
This commit is contained in:
zhangxiang committed 2026-10-17 07:54:21 +08:00
1 parent 2e0099426f
commit 1c0ce5f458
12 files changed
+199 -27

No files matched your search

+5 -1
View File
@@ -37,7 +37,11 @@ test.describe('Footer ICP/Police BeiAn Visibility', { tag: '@regression' }, () =
const icpBox = await icp.boundingBox();
const policeBox = await police.boundingBox();
const viewport = page.viewportSize();
// DEC-N6 补口带出的类型口径修正:Page.viewportSize() 的返回类型是 `{width,height} | null`。
// 本项目在 playwright.config.ts 里显式设了 viewport,取不到只会是装配异常;旧代码在此处
// 直接 `viewport.height`,null 分支本来就是 TypeError 崩溃 ⇒ 改成显式抛错,消息可读、行为等价。
if (!viewport) throw new Error('viewportSize() 返回 null:chromium-mobile 项目应有显式 viewport');
console.log('移动端 ICP位置:', icpBox);
console.log('移动端 公安备案位置:', policeBox);
console.log('移动端 视口高度:', viewport.height);
+4 -2
View File
@@ -75,8 +75,10 @@ test.describe(
const observer = new PerformanceObserver((list) => {
const entries = list.getEntries();
if (entries.length > 0) {
const lastEntry = entries[entries.length - 1];
resolve(lastEntry.startTime);
// 用 .at(-1) 取末条:在 `length > 0` 守卫下与原 `entries[length-1]` 等价,
// 同时满足 noUncheckedIndexedAccess(原写法在 e2e 纳入类型检查后报 TS18048)。
const lastEntry = entries.at(-1);
if (lastEntry) resolve(lastEntry.startTime);
}
});
observer.observe({
+5 -3
View File
@@ -364,7 +364,7 @@ test.describe('P1: 品牌视觉审计 - SVG Logo 详细检查', { tag: '@regress
const res = await page.request.get(asset);
expect(res.status(), `${asset} 应可取回`).toBe(200);
const svg = await res.text();
const textNodes = [...svg.matchAll(/<text[^>]*>([^<]*)<\/text>/g)].map((m) => m[1].trim());
const textNodes = [...svg.matchAll(/<text[^>]*>([^<]*)<\/text>/g)].map((m) => m[1]?.trim() ?? '');
if (textNodes.length === 0) {
expect(asset, `${asset} 是几何字标却带 <text>`).toBeTruthy();
continue;
@@ -663,13 +663,15 @@ test.describe('P1: 品牌视觉审计 - 性能与截图基线', { tag: '@regress
// 旧实现三处 `.catch(e => console.log(...))` + 结尾 expect(true),一张都没截到也算通过(§5.21)。
const header = page.locator('header');
await expect(header, 'Header 区域不可见').toBeVisible({ timeout: 10000 });
const headerPng = await header.screenshot({ fullPage: false });
// `fullPage` 不是 Locator.screenshot() 的选项(类型里没有,运行时也不读):元素截图恒为元素框。
// 旧代码写 `{ fullPage: false }` 等于没写,删掉它不改变任何字节 ⇒ 只保留类型口径正确的一侧。
const headerPng = await header.screenshot();
expect(headerPng.byteLength, 'Header 截图为空').toBeGreaterThan(1000);
await testInfo.attach('p1-brand-audit-header', { body: headerPng, contentType: 'image/png' });
const footer = page.locator('[data-testid="footer"], footer').first();
await expect(footer, 'Footer 区域不可见').toBeVisible({ timeout: 10000 });
const footerPng = await footer.screenshot({ fullPage: false });
const footerPng = await footer.screenshot();
expect(footerPng.byteLength, 'Footer 截图为空').toBeGreaterThan(1000);
await testInfo.attach('p1-brand-audit-footer', { body: footerPng, contentType: 'image/png' });
+3 -1
View File
@@ -721,7 +721,9 @@ test.describe("无障碍性 - A11y 基础检查", { tag: "@regression" }, () =>
// 基本检查:不应该有太多级别跳跃
let maxJump = 0;
for (let i = 1; i < headings.length; i++) {
const jump = headings[i] - headings[i - 1];
// 循环上界保证两个下标都在界内;`?? 0` 只为满足 noUncheckedIndexedAccess
// (e2e 纳入类型检查后原写法报 TS2532),运行时取不到 undefined。
const jump = (headings[i] ?? 0) - (headings[i - 1] ?? 0);
if (jump > maxJump) maxJump = jump;
}
// 允许最多跳跃2级(如 h1 -> h3)
+9 -5
View File
@@ -76,7 +76,7 @@ test.describe("性能 - 页面加载指标", { tag: "@regression" }, () => {
const paintEntries = performance
.getEntriesByType("paint")
.filter((entry) => entry.name === "first-contentful-paint");
return paintEntries.length > 0 ? paintEntries[0].startTime : null;
return paintEntries.length > 0 ? (paintEntries[0]?.startTime ?? null) : null;
});
await expect
@@ -199,13 +199,17 @@ test.describe("性能 - 资源优化", { tag: "@regression" }, () => {
await page.waitForTimeout(2000);
const fontInfo = await page.evaluate(() => {
const fonts = performance
.getEntriesByType("resource")
.filter((e: PerformanceResourceTiming) => e.initiatorType === "font");
// 沿用同文件 :164 的既有写法:getEntriesByType("resource") 的返回类型在 lib.dom 里是
// PerformanceEntry[],按规范这些条目就是 PerformanceResourceTiming ⇒ 在数组上收窄一次,
// 不再把回调形参伪标成 PerformanceResourceTiming(那会让 filter 的重载匹配失败,TS2769)。
const entries = performance.getEntriesByType(
"resource",
) as PerformanceResourceTiming[];
const fonts = entries.filter((e) => e.initiatorType === "font");
return {
fontCount: fonts.length,
fonts: fonts.map((f: PerformanceResourceTiming) => ({
fonts: fonts.map((f) => ({
name: f.name.split("/").pop(),
duration: Math.round(f.duration),
})),
+12 -3
View File
@@ -30,7 +30,10 @@ test.describe('滚动进度条 - 全局组件行为', { tag: '@regression' }, ()
const scale = await progressFill.evaluate((el) => {
const transform = (el as HTMLElement).style.transform;
const match = transform.match(/scaleX\(([\d.]+)\)/);
return match ? parseFloat(match[1]) : 0;
// 先落到局部变量再判空:`match[1]` 在 noUncheckedIndexedAccess 下类型是
// string | undefined,直接 parseFloat 报 TS2532;捕获组必然存在,运行时与旧写法等价。
const ratio = match?.[1];
return ratio ? parseFloat(ratio) : 0;
});
expect(scale).toBe(0);
});
@@ -45,7 +48,10 @@ test.describe('滚动进度条 - 全局组件行为', { tag: '@regression' }, ()
const getScale = () => progressFill.evaluate((el) => {
const transform = (el as HTMLElement).style.transform;
const match = transform.match(/scaleX\(([\d.]+)\)/);
return match ? parseFloat(match[1]) : 0;
// 先落到局部变量再判空:`match[1]` 在 noUncheckedIndexedAccess 下类型是
// string | undefined,直接 parseFloat 报 TS2532;捕获组必然存在,运行时与旧写法等价。
const ratio = match?.[1];
return ratio ? parseFloat(ratio) : 0;
});
// 先获取顶部缩放
@@ -279,7 +285,10 @@ test.describe('服务详情页 - 滚动进度条', { tag: '@regression' }, () =>
const scale = await progressFill.evaluate((el) => {
const transform = (el as HTMLElement).style.transform;
const match = transform.match(/scaleX\(([\d.]+)\)/);
return match ? parseFloat(match[1]) : 0;
// 先落到局部变量再判空:`match[1]` 在 noUncheckedIndexedAccess 下类型是
// string | undefined,直接 parseFloat 报 TS2532;捕获组必然存在,运行时与旧写法等价。
const ratio = match?.[1];
return ratio ? parseFloat(ratio) : 0;
});
expect(scale).toBeGreaterThan(0);
});
+17
View File
@@ -41,6 +41,11 @@ export default defineConfig({
animations: 'disabled',
caret: 'hide',
scale: 'device',
// @ts-expect-error 类型口径缺口(不是运行时缺口):@playwright/test 的
// expect.toHaveScreenshot 选项类型里没有 `timeout`,但实现确实读它 ——
// node_modules/playwright/lib/matchers/expect.js:12182 `helper.options.timeout ?? this.timeout`。
// 删掉这行会让截图断言超时从 20s 回落到下面的 expect.timeout=15000,属行为变更 ⇒ 保留并标记。
// 若日后 Playwright 把 timeout 补进类型,本指令会因「未使用」而报错,届时直接摘掉标记。
timeout: 20000,
},
timeout: 15000,
@@ -54,6 +59,14 @@ export default defineConfig({
// 视觉回归确定性:reducedMotion 让 ScrollReveal/StaggerReveal 走 initial={} 分支
// 默认可见(不残留 opacity:0),避免全页截图时 below-the-fold 模块因 whileInView
// 未触发而空白。同时使 Hero 粒子场走固定种子的静态降级帧,快照零漂移。
//
// ⚠ 残留 R-1(DEC-N6 补口带出,本批未修,需视觉 owner 拍板):这条意图**当前并没有生效**。
// `reducedMotion` 是 browser.newContext() 的上下文选项,不是 `use` 层选项:
// node_modules/playwright/lib/index.js:241-266 的 fixture 白名单里没有它,
// `_combinedContextOptions` 只从 `contextOptions` 取值 ⇒ 写在 use 里被直接忽略。
// 生效写法是 `contextOptions: { reducedMotion: 'reduce' }`,但那会真的关掉动效、
// 改变截图字节 ⇒ 与正在重采的 132 张基线冲突,本批只标注不改行为。
// @ts-expect-error 残留 R-1:见上,use 层无 reducedMotion 选项
reducedMotion: 'reduce',
},
testMatch: 'visual-regression.spec.ts',
@@ -63,6 +76,7 @@ export default defineConfig({
use: {
...devices['iPad Pro 11'],
viewport: { width: 834, height: 1194 },
// @ts-expect-error 残留 R-1:use 层无 reducedMotion 选项,运行时被忽略(见 visual-chromium-desktop 处说明)
reducedMotion: 'reduce',
},
testMatch: 'visual-regression.spec.ts',
@@ -74,6 +88,7 @@ export default defineConfig({
viewport: { width: 390, height: 844 },
isMobile: true,
hasTouch: true,
// @ts-expect-error 残留 R-1:use 层无 reducedMotion 选项,运行时被忽略(见 visual-chromium-desktop 处说明)
reducedMotion: 'reduce',
},
testMatch: 'visual-regression.spec.ts',
@@ -84,6 +99,7 @@ export default defineConfig({
...devices['Desktop Firefox'],
viewport: { width: 1280, height: 800 },
storageState: './storageState.firefox.json',
// @ts-expect-error 残留 R-1:use 层无 reducedMotion 选项,运行时被忽略(见 visual-chromium-desktop 处说明)
reducedMotion: 'reduce',
},
testMatch: 'visual-regression.spec.ts',
@@ -94,6 +110,7 @@ export default defineConfig({
...devices['Desktop Safari'],
viewport: { width: 1280, height: 800 },
storageState: './storageState.firefox.json',
// @ts-expect-error 残留 R-1:use 层无 reducedMotion 选项,运行时被忽略(见 visual-chromium-desktop 处说明)
reducedMotion: 'reduce',
},
testMatch: 'visual-regression.spec.ts',
+4 -1
View File
@@ -364,7 +364,10 @@ test.describe('安全传输 - 资源加载', { tag: '@security' }, () => {
return Array.from(elements)
.map((el) => {
const htmlEl = el as HTMLLinkElement | HTMLScriptElement | HTMLImageElement | HTMLSourceElement | HTMLVideoElement;
return htmlEl.src || (htmlEl as HTMLLinkElement).href;
// 联合类型里 HTMLLinkElement 没有 `src`(它只有 href),旧写法直接 `htmlEl.src`
// 在 e2e 纳入类型检查后报 TS2339。运行时语义不变:link 元素取不到 src 仍回落 href。
const src = (htmlEl as { src?: string }).src;
return src || (htmlEl as HTMLLinkElement).href;
})
.filter(Boolean);
});
+5 -2
View File
@@ -29,7 +29,10 @@ const AA_MIN_PX = 24;
const AAA_MIN_PX = 44;
export async function scanTouchTargets(page: Page): Promise<TouchTargetReport> {
return page.evaluate(([aaMin, aaaMin]) => {
// 传对象而不是数组:数组解构的下标在 noUncheckedIndexedAccess 下类型是 number | undefined
// (下面 :62/:64 的 `aaMin`/`aaaMin` 比较各报两条 TS18048),对象解构能直接推出 number。
// evaluate 的参数走结构化克隆,数组改对象不改变运行时行为,两个阈值仍是 24/44。
return page.evaluate(({ aaMin, aaaMin }) => {
const nodes = document.querySelectorAll<HTMLElement>(
'a, button, input, select, textarea, [role="button"], [tabindex]:not([tabindex="-1"])'
);
@@ -67,7 +70,7 @@ export async function scanTouchTargets(page: Page): Promise<TouchTargetReport> {
});
return { aaViolations, aaaShortlist };
}, [AA_MIN_PX, AAA_MIN_PX]);
}, { aaMin: AA_MIN_PX, aaaMin: AAA_MIN_PX });
}
export function formatTargets(targets: TouchTarget[]): string {
+27
View File
@@ -0,0 +1,27 @@
{
"//": [
"DEC-N6 补口:根 tsconfig.json 的 exclude 里显式列了 e2e,因此 `npm run type-check` 全程抓不到",
"e2e/** 里的类型错误与重复声明(历史实例:teardown 补丁里第二个 `const revalidateSecret` 与既有声明",
"重名,type-check EXIT=0,只有 `cd e2e && npx playwright test --list` 才报)。本文件让 `tsc --noEmit -p e2e`",
"能在静态阶段抓到同一类错误,由 `npm run type-check:e2e` 承载。",
"口径:继承根配置的 strict / noUncheckedIndexedAccess 等全部严格度开关,只替换文件集合与 types。",
"不引入 skipLibCheck / any 之类的降噪手段(根配置本就 skipLibCheck: true,此处保持一致,未额外放宽)。"
],
"extends": "../tsconfig.json",
"compilerOptions": {
"types": ["node"],
"noEmit": true,
"incremental": false,
"paths": {
"@/*": ["../src/*"]
}
},
"include": ["**/*.ts"],
"exclude": [
"node_modules",
"test-results",
"allure-results",
"playwright-report",
"visual-snapshots"
]
}