feat(home): 首屏改拼贴构图 + 外壳三修收口(Batch 1)

ADR-0009 的首屏读数取自对标 `opacity:0` 的视频轮播层(只在 ~13s 淡入 0.8s),
据此做出的「居中巨型声明」复刻的是一段过渡帧。本轮按静止态拼贴重做,并把
同批发现的四处结构缺陷收口。

首屏(拼贴)
- 黑底半透明文字块(左 7/12)+ 右手错位副图(右 5/12,lg 起)+ 副图角上双 V
  + 深色影像上的斜线纹;素材复用既有 hero-architecture / industry-manufacturing,
  禁人物入镜,题材换建筑/工业、语法不变
- title 字阶 90px → 桌面 44px(对标 100/700 是过渡帧字号,静止态短句是 40/700)
- 诚实信号前置为 eyebrow:`2026 年 1 月成立 · 首批客户共创中`(均取常量单一真源)

令牌与面积纪律
- `--spacer-band` 7.5rem → 6.6667rem:原值注释称「16px 根字号下 120px」,
  但 ≥1024px 根字号是 18px ⇒ 实测 135px,比对标的 120px 大 12.5%
- 斜线纹加面积封顶(收束段原 h-full w-[38%] 实测 606×569,越过 ≤640×520)

新门禁 R20(check:grammar)
- 裸 alpha 必须在 Tailwind opacity scale 内。`bg-[#0B0A08]/92` 与审计抓到的
  `bg-bg-primary/98` 同根因:scale 外的值被编译器静默丢弃,computed 退化为
  rgba(0,0,0,0)。type-check / lint / build / 单测四道全绿也拦不住
- 三向自证 + 真实树负对照(/95→/92 判红,改回即绿);上线当天即抓到本人
  第二处同类失误(to-[#0B0A08]/88)

守卫与基线
- e2e/chrome-persistence.spec.ts:页头吸顶(1500/3000)、抽屉背景不透明、
  mega 不被裁切。两处装配缺陷已修(`data-content-ready` 门控替代猜毫秒数;
  mega 必须 hover 打开,click 面板根本不挂载);注回缺陷 8/8 全红做负对照
- 视觉基线按授权重采 55 张(归因:同一棵树全量回滚后旧基线 26/26 全绿 ⇒
  失败全由本轮改动引起;只回滚外壳修复则 mobile 从 20 降到 4)
  独立只读复跑 129 passed / 1 failed,那 1 条为并发抖动(单跑绿、连跑两轮 26/26)

文档
- ADR-0009 增「更正一」(首屏校准);签名件「逐字移植」改「同构再造」
- lessons §5.53–5.58;CONTEXT 决策表 4 行;quality-gates 记 R20

门禁:type-check / type-check:e2e / lint(0 error) / 158 套件 1854 例 /
check:grammar 20-20 + selftest / check:motion / check:accents / check:brand-token /
check:a11y / test:e2e:prod 80 passed / 视觉 129+ passed
This commit is contained in:
zhangxiang committed 2026-11-24 21:53:16 +08:00
1 parent 8c64064181
commit 198d6a0303
70 files changed
+911 -54

No files matched your search

+204
View File
@@ -0,0 +1,204 @@
import { test, expect } from './fixtures';
import { expectHydrated } from './hydrated';
/**
* 站点外壳(header / 移动抽屉 / mega 面板)的**持久性**回归。
*
* 三个缺陷同源于 2026-11-24 的对标审计,每一个都有「文档级验收看不见」的共同特征:
*
* 1. **页头不吸顶**(P0-1)。`<header>` 写的是 `position: fixed`,但 `PageTransition` 的
* `motion.div` 常驻内联 `will-change: transform, opacity` —— `will-change: transform`
* 会让该元素成为 `position: fixed` 后代的**包含块**(CSS Containment / transform 语义),
* 于是 header 相对「文档高度」的那个祖先定位,而不是相对视口。实测 `scrollY=1500` 时
* `header.top === -1500`,computed `position` 仍是 `fixed`。
* 这里断言的是**行为**(滚动了它还在视口顶部),不是 computed style —— 后者在缺陷态下
* 依然是 `fixed`,拿它当判据等于什么都没测。
*
* 2. **移动抽屉透明白底**(P0-2)。`bg-bg-primary/98` 的 `/98` 不在 Tailwind 的 opacity
* scale 里,编译器**静默不生成**该规则(同族 `/95` 正常生成)。抽屉文字因此直接压在
* 首页深色建筑照与朱砂 CTA 上。断言 `backgroundColor` 不能是 `rgba(0, 0, 0, 0)`:
* 「class 写在源码里」和「CSS 真的存在」是两件事,只有前者能被 grep 验到。
*
* 3. **能力 mega 面板超视口**(P1-2)。面板 946px 高、`overflow-y: visible`,1280×720
* 下把最后一个入口裁掉 289px 且无处可滚。断言面板底部不超过视口,或面板自身可滚。
*
* 敏感性(改回即转红):
* - 恢复 `page-transition.tsx` 的常驻 `willChange` ⇒ 用例 1 红;
* - 把 `bg-bg-primary/95` 改回 `/98` ⇒ 用例 2 红;
* - 去掉 mega 面板的 `max-h`/`overflow-y-auto` ⇒ 用例 3 在 1280×720 下红。
*/
/** 页头在滚动后必须仍贴在视口顶部(容差 2px,吸收亚像素与高度过渡抖动)。 */
const HEADER_STICK_TOLERANCE = 2;
for (const scrollY of [1500, 3000]) {
test(`页头在滚动 ${scrollY}px 后仍吸附视口顶部`, async ({ page }) => {
await page.goto('/', { waitUntil: 'domcontentloaded' });
const header = page.locator('header').first();
await expect(header).toBeVisible({ timeout: 15000 });
// ⚠ 必须等 hydration 再滚。PageTransition 在 mounted=false 时直接 `return <>{children}</>`,
// 那层 motion.div **此时还不存在**(实测:`domcontentloaded` 就滚,读到「正确」的 top=0 ——
// 那是在测一个还没有缺陷的 DOM,本用例在本缺陷下会假绿,首轮实测就是绿的)。
//
// 判据用项目既定的 `expectHydrated`(React 写在宿主元素上的 `__reactProps$` 内部键):
// 不往 DOM 塞属性(那会触发 React 对多余属性的 hydration warning,用例自己制造噪声),
// 也不锚 `will-change`(缺陷修好后它已被删除,锚它 = 自证失效)。
await expectHydrated(header);
// ⚠ 再等**入场动画走完**。这是一条独立于 hydration 的前置条件,实测必须有:
// framer-motion 在 280ms 入场期间会给 PageTransition 的包裹层写 `transform: matrix(...)`,
// 而 transform 与 will-change 一样会创建 fixed 的包含块。实测(scrollY → header.top):
// 500 → -483(matrix 在)、1000 → -1000(matrix 在)、1500 → 0(transform: none)。
// 也就是说「动画进行中页头不吸顶」是**瞬时且固有**的,不是缺陷 —— 缺陷是 will-change 让它
// **永久**如此。用例必须测稳态,否则会把动画帧当成回归。
//
// 门控分两步,两步都不能省:
//
// ① **等 `data-content-ready` 置位**(`(marketing)/template.tsx` 在水合后 800ms 写入,
// 800ms > 最长入场 280ms,成立的唯一理由就是「入场动画已结束、控制权交还 framer」)。
// 这一条同时堵住两个坑:
// · 直接 `expect.poll(transform === 'none')` 会在动画**尚未开始**那刻命中(framer 还没写
// matrix),然后放行 —— 那是假绿;
// · 固定 `waitForTimeout(600)` 在**慢机器 / 移动 project 上不够**。实测 chromium-mobile
// 首轮就死在这里:600ms 时仍读到 `matrix(0.999928, 0, 0, 0.999928, 0, 0.028695)`,
// 而同一台机器等 3s 后 transform 链为空、`headerTop=0`(产品是好的,是本用例等短了)。
// `data-content-ready` 是项目既有判据,不是为本用例新造的锚点:它表达的正是
// 「动画该结束了」,比任何猜出来的毫秒数都可复算。
await expect
.poll(() => page.evaluate(() => document.documentElement.getAttribute('data-content-ready')), {
timeout: 15000,
message: '入场动画交接标记 data-content-ready 未置位 —— 页面可能停在动画中,此时测的是动画帧不是稳态',
})
.toBe('1');
// ② 交接之后再硬断言一次 transform 已归零:不轮询、不等待,只用它抓「交接了但仍在动」的真缺陷。
await expect(
await page.evaluate(() => {
let n: Element | null = document.querySelector('header');
while (n && n !== document.documentElement) {
if (getComputedStyle(n).transform !== 'none') return getComputedStyle(n).transform;
n = n.parentElement;
}
return null;
}),
'祖先链上仍有 transform,入场动画未结束(此时测量会读到动画帧,不是稳态)',
).toBeNull();
await page.evaluate((y) => {
// scroll-behavior: smooth 会让 scrollTo 与随后的读数竞态 —— 先显式关掉。
document.documentElement.style.scrollBehavior = 'auto';
window.scrollTo(0, y);
}, scrollY);
await expect
.poll(() => page.evaluate(() => Math.round(window.scrollY)), { timeout: 5000 })
.toBe(scrollY);
// 缺陷态:top 恒等于 -scrollY 且不随轮询改善(fixed 被包含块劫持,随文档一起滚走)。
// 正确态:top 收敛到 0±容差。用 poll 吸收 header 高度 80→64 过渡期的亚像素抖动;
// 缺陷态下它不会「恰好」收敛,只会超时并打印末次读数。
await expect
.poll(() => page.evaluate(() => document.querySelector('header')!.getBoundingClientRect().top), {
timeout: 5000,
message:
`页头在 scrollY=${scrollY} 时应贴在视口顶部(top≈0)。` +
`若收敛到 -${scrollY},说明祖先有 transform / will-change 劫持了 fixed 的包含块`,
})
.toBeGreaterThanOrEqual(-HEADER_STICK_TOLERANCE);
});
}
test('移动抽屉的面板背景不得是透明的', async ({ page }) => {
await page.setViewportSize({ width: 390, height: 844 });
await page.goto('/', { waitUntil: 'domcontentloaded' });
const button = page.getByTestId('mobile-menu-button');
await expect(button).toBeVisible({ timeout: 15000 });
const drawer = page.getByTestId('mobile-navigation');
await expect(async () => {
if (!(await drawer.isVisible())) await button.click();
await expect(drawer).toBeVisible({ timeout: 1000 });
}).toPass({ timeout: 15000 });
// 抽屉的滚动容器(面板本体)。取第一个带 overflow-y 的子节点,退化为抽屉自身。
const panel = drawer.locator('div[class*="overflow-y-auto"]').first();
const target = (await panel.count()) > 0 ? panel : drawer;
const bg = await target.evaluate((el) => getComputedStyle(el).backgroundColor);
expect(
bg,
`抽屉面板背景为 ${bg}。rgba(0, 0, 0, 0) 表示 class 存在但 CSS 未生成` +
`(Tailwind opacity scale 之外的值如 /98 会静默失效,同族 /95 正常)`,
).not.toBe('rgba(0, 0, 0, 0)');
// 同时断言它真的是「不透明到能承载正文」:alpha 至少 0.9。
const alpha = await target.evaluate((el) => {
const m = /rgba?\(([^)]+)\)/.exec(getComputedStyle(el).backgroundColor);
if (!m || !m[1]) return null;
const parts = m[1].split(/[,/]/).map((s) => parseFloat(s.trim()));
return parts.length >= 4 ? parts[3] : 1;
});
expect(alpha, `抽屉面板背景 alpha=${alpha},正文会与页面内容叠印`).toBeGreaterThanOrEqual(0.9);
});
test('能力 mega 面板在 1280x720 下不被裁切,或自身可滚', async ({ page }) => {
// 1280×720 是本仓实测最容易翻车的桌面尺寸(修复前面板 946px、overflow-y: visible)。
await page.setViewportSize({ width: 1280, height: 720 });
await page.goto('/', { waitUntil: 'domcontentloaded' });
const nav = page.locator('nav[aria-label="主导航"]');
await expect(nav).toBeVisible({ timeout: 15000 });
const trigger = nav.locator('button:has-text("能力")').first();
await expect(trigger).toBeVisible();
await expect(trigger).toHaveAttribute('aria-expanded', 'false');
// ⚠ **必须 hover 打开,不能 click**。本仓 mega 是 hover 驱动的(`onMouseEnter`),
// `click()` 只切 `aria-expanded` 所依赖的另一条路径、面板根本不挂载 ——
// 首轮实测:click 之后 `[class*="top-full"]` 在整页命中 **0** 个,用例死在
// 「locator 等不到元素」而不是死在裁切判据上(假红,且指向错误方向)。
// 独立验证读数(同机、同产物、hover 打开):面板 rect h=612、`max-h: 612px`、
// `overflow-y: auto`、`scrollHeight 935 > clientHeight 610` ⇒ 自身可滚,`/products` 入口在视口内。
// 与 `e2e/nav-dropdown.spec.ts` 的 openAxis 同一姿势(那里也是 hover + toPass 重试):
// 入场动画期间的指针可能落在按钮尚未覆盖的帧上,mouseenter 不会补发,故要重试。
await expectHydrated(trigger);
await expect(async () => {
await page.mouse.move(0, 0);
await trigger.hover();
await expect(trigger).toHaveAttribute('aria-expanded', 'true', { timeout: 1000 });
}).toPass({ timeout: 20000 });
// 面板 = 导航地标里 `top-full` 容器内的第一层 div(把选择器收进 nav,避免命中别处的 absolute)。
const panel = nav.locator('[class*="top-full"] > div').first();
await expect(panel).toBeVisible({ timeout: 5000 });
const { bottom, overflowY, scrollable } = await panel.evaluate((el) => {
const cs = getComputedStyle(el);
return {
bottom: el.getBoundingClientRect().bottom,
overflowY: cs.overflowY,
scrollable: el.scrollHeight > el.clientHeight + 1,
};
});
const vh = 720;
const clipped = Math.round(bottom - vh);
const fits = clipped <= 0;
const usable = fits || scrollable || overflowY === 'auto' || overflowY === 'scroll';
expect(
usable,
`mega 面板底部 ${Math.round(bottom)}px,超出视口 ${clipped}px,` +
`overflowY=${overflowY}、内部可滚=${scrollable} ⇒ 最后几个入口既不可见也点不到`,
).toBe(true);
// 最后一组入口必须真的可达(scrollIntoView 后可见并可点)。
const lastLink = panel.getByRole('link', { name: /查看全部能力|产品矩阵总览/ }).last();
if ((await lastLink.count()) > 0) {
await lastLink.scrollIntoViewIfNeeded();
await expect(lastLink).toBeVisible({ timeout: 3000 });
}
});