Files
novalon-website/scripts/landing/verify-landing-layout.py
T
zhangxiang 99eaa8c66a feat(landing): 睿视 landing 由本仓统一管理——源码子目录化 + 四道门禁移植 + 契约路由
承接 ADR-0014 §4「第二等产品镜像起必须子目录化 + rewrites 前缀映射并回溯睿视」。
上一轮(2026-12-02)只搬了字节,源码落在 public/ 根命名空间;本轮把源码、门禁、
发布职责一并收进本仓,authority 侧退役对应产物。

源码与 URL 契约:
- public/novavis/{index.html,css,js,assets,images/logos} 一棵树自成一体
- index.html 引用保持站点级绝对路径(/css /js /assets /images/logos)不变。
  因为同一份字节要服务两个落点:官网镜像 novalon.cn/novavis/,以及独立子域
  novavis.p.novalon.cn/(页面在根路径)。改绝对路径会把子域首页变成 /novavis/
- 故用 4 条 prefix rewrite 把根命名空间映射进子目录,而非改写 HTML

四道门禁(从 authority 的四个 python 脚本移植为 Playwright,已并入 test:all):
- e2e/landing/{layout,motion,demo,a11y}.spec.ts + 独立 config(单引擎单 project 串行)
- layout:几何与焦点 / motion:js-grow 渐进生长与 reduced-motion 直达终态
- demo:首屏剧本四步 + 徽标一一对应 + 无 JS 降级四层真实可见性
- a11y:结构与全量对比度(同色无条件阻断)+ axe critical/serious=0
- 实测 13 passed / EXIT=0(1.4m)

补一个映射期暴露的真缺陷:landing 的 main.js 固定 POST /api/v1/contact 且只认
code===200,而本仓只有 /api/contact(formData + 必填 subject),镜像侧转化路径
一直 404。新增 src/app/api/v1/contact/route.ts 按 authority 契约响应(JSON +
{code:200}),而非改前端去适配本仓——改前端等于把适配成本转嫁给子域,且会让
两个落点的成功判据不一致。9 个单测覆盖校验、限流、上游失败不透传 5xx。

文档与配置同步:CLAUDE.md → AGENTS.md(单文档真源)、docs/landing.md、
docs/deployment.md §八、ADR-0014、qa-tracker §32、README 与 quality-gates 脚本表、
Jenkinsfile 落地「♿ 可访问性门禁」阶段的 landing 四道门禁、eslint 忽略
.next-dev-live 构建产物目录(未忽略时 eslint . 会扫出 21195 errors)。

门禁:tsc 0 / eslint 0 / jest app/api/v1 9/9 / test:landing 13 passed。
2026-12-03 22:56:17 +08:00

306 lines
13 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
"""landing 布局几何与焦点管理验证(复评 P2-7 / P2-8 / P2-9 的判别性门禁)。
前置:先起本地静态服务
python3 -m http.server 8088 --bind 127.0.0.1 --directory landing
用法:
NO_PROXY=localhost,127.0.0.1 no_proxy=localhost,127.0.0.1 \
python3 scripts/verify-landing-layout.py [--url http://127.0.0.1:8088/] [--only tabs,focus,cta] [--shots /tmp/landing-shots]
检查项:
1. tabs:各视口下 .showcase-tabs 的每个 tab 中心不被 #showcasePause 覆盖
(窄视口下绝对定位的暂停按钮压在 tab 行之上),且无横向溢出
2. focus:showcase 轮播的焦点管理(WCAG 2.2.2 精神)
a. 焦点进入卡片后自动轮播让位(持焦期间 active tab 不变)
b. 持焦 tab 不被摘掉 tabindex(摘掉即被移出 tab 序列,键盘焦点无处可回)
c. 失焦后轮播恢复(证明 a 不是「轮播整体坏了」的假通过)
3. roving:方向键切换后整组只留一只 tab 可被 Tab 键到达,且该只即 active 那只
(roving tabindex 单点不变量;焦点须跟随 active)
4. cta:nav 转化入口与信息链接有可视分层(描边/底色至少一项不同)
5. --shots:把上述几处截成图片,供人工看几何与视觉权重(像素层面的重叠、
留白、按钮挤行无法靠数值断言穷尽)
注意:悬停会冻结轮播(既有设计),故 focus 项全程把鼠标移到 (0,0) 并显式核对
卡片已滚入视口——否则测的是 hover 冻结而非 focusin 暂停(本仓踩过)。
2b 与 3 分工:2b 只在「持焦期间不切」的暂停语义下观察,真正判别 tabindex 时序
缺陷的是 3(方向键切换 → syncRovingTabindex 与 focus() 的先后决定旧 tab 是否残留
tabindex="0")。二者都不覆盖 2b 所防的那个竞态窗口(轮播回调已在 focusin 之前入队),
该分支须驱动闭包内部函数才能命中,不为其暴露生产 API,仅由代码注释交代。
Last updated: 2026-09-20
maintainer: novavis-authority
"""
import argparse
import sys
import time
from pathlib import Path
from playwright.sync_api import sync_playwright
VIEWPORTS = [
("桌面 1440", 1440, 900),
("笔记本 1024", 1024, 768),
("平板竖屏 768", 768, 1024),
("手机 480", 480, 900),
("手机 375", 375, 812),
]
CYCLE_MS = 5500
# 轮播间隔 + 余量:等待窗口内若未暂停,active tab 必定已切换
WAIT_S = (CYCLE_MS / 1000) + 2.0
TAB_INFO = """() => {
const pause = document.querySelector('#showcasePause');
const pr = pause && getComputedStyle(pause).display !== 'none'
? pause.getBoundingClientRect() : null;
const covers = (r) => {
if (!pr) return false;
const cx = r.left + r.width / 2, cy = r.top + r.height / 2;
return pr.left <= cx && cx <= pr.right && pr.top <= cy && cy <= pr.bottom;
};
return [...document.querySelectorAll('.showcase-tab')].map((t) => {
const r = t.getBoundingClientRect();
return {
id: t.id,
covered: covers(r),
centerInViewport: (() => {
const cx = r.left + r.width / 2, cy = r.top + r.height / 2;
return cx >= 0 && cy >= 0 && cx <= innerWidth && cy <= innerHeight;
})(),
};
});
}"""
def check_tabs(page, failures):
"""1. tab 行与暂停按钮不重叠、无横向溢出"""
for name, w, h in VIEWPORTS:
page.set_viewport_size({"width": w, "height": h})
page.evaluate("() => window.scrollTo(0, 0)")
page.mouse.move(0, 0)
page.locator(".showcase-tabs").scroll_into_view_if_needed()
time.sleep(0.3)
tabs = page.evaluate(TAB_INFO)
covered = [t["id"] for t in tabs if t["covered"]]
offscreen = [t["id"] for t in tabs if not t["centerInViewport"]]
overflow = page.evaluate(
"() => document.documentElement.scrollWidth - document.documentElement.clientWidth"
)
print(f" {name:>12} 被暂停按钮覆盖={covered or '无'} 出视口={offscreen or '无'} 横向溢出={overflow}px")
if covered:
failures.append(f"{name}: tab 被 #showcasePause 覆盖 {covered}")
if offscreen:
failures.append(f"{name}: tab 中心不在视口内 {offscreen}")
if overflow > 1:
failures.append(f"{name}: 页面横向溢出 {overflow}px")
def active_tab(page):
return page.evaluate("() => document.querySelector('.showcase-tab.active')?.id ?? null")
def focused_tab_state(page):
return page.evaluate(
"""() => {
const el = document.activeElement;
if (!el || !el.classList || !el.classList.contains('showcase-tab')) return null;
return { id: el.id, tabindex: el.getAttribute('tabindex') };
}"""
)
def check_focus(page, failures):
"""2. 焦点进入卡片期间轮播让位;持焦 tab 不被摘 tabindex;失焦后轮播恢复"""
page.set_viewport_size({"width": 1440, "height": 900})
page.reload(wait_until="load")
page.mouse.move(0, 0)
page.locator(".showcase-tabs").scroll_into_view_if_needed()
time.sleep(0.6)
page.mouse.move(0, 0)
before = active_tab(page)
page.evaluate(
"""() => { const t = document.querySelector('.showcase-tab.active'); t && t.focus(); }"""
)
state = focused_tab_state(page)
print(f" 持焦 tab = {state}")
if not state:
failures.append("未能把焦点放进 tablist(用例前提不成立)")
return
time.sleep(WAIT_S)
after = active_tab(page)
print(f" 持焦 {WAIT_S:.1f}s 后 active = {after}(持焦前 {before},期望不变)")
if after != before:
failures.append(f"焦点在卡片内时轮播未让位:active {before} → {after}")
held = focused_tab_state(page)
print(f" 持焦元素 tabindex = {held}")
if held and held.get("tabindex") == "-1":
failures.append(f"持焦 tab {held['id']} 的 tabindex 被摘成 -1(键盘焦点会被移出序列)")
# 失焦后须恢复轮播:否则上一条「不变」可能只是轮播整体失效
page.evaluate("() => document.activeElement && document.activeElement.blur()")
page.evaluate("() => window.scrollTo(0, 0)")
page.mouse.move(0, 0)
page.locator("#nav").scroll_into_view_if_needed()
page.locator(".showcase-tabs").scroll_into_view_if_needed()
deadline = time.time() + WAIT_S + 1.0
resumed = None
while time.time() < deadline:
current = active_tab(page)
if current != before:
resumed = current
break
time.sleep(0.5)
print(f" 失焦后轮播恢复 = {resumed}(期望 ≠ {before})")
if not resumed:
failures.append("失焦后轮播未恢复:前一条「持焦不变」可能是轮播整体失效的假通过")
def check_roving(page, failures):
"""3. 方向键切换后 roving tabindex 单点不变量"""
page.set_viewport_size({"width": 1440, "height": 900})
page.reload(wait_until="load")
page.mouse.move(0, 0)
page.locator(".showcase-tabs").scroll_into_view_if_needed()
time.sleep(0.4)
page.evaluate(
"""() => { const t = document.querySelector('.showcase-tab.active'); t && t.focus(); }"""
)
if focused_tab_state(page) is None:
failures.append("未能把焦点放进 tablist(roving 不变量前提不成立)")
return
page.keyboard.press("ArrowRight")
time.sleep(0.3)
state = page.evaluate(
"""() => {
const tabs = [...document.querySelectorAll('.showcase-tab')];
const isTab = (el) => !!el && el.classList && el.classList.contains('showcase-tab');
return {
zero: tabs.filter((t) => t.getAttribute('tabindex') === '0').map((t) => t.id),
active: tabs.filter((t) => t.classList.contains('active')).map((t) => t.id),
focused: isTab(document.activeElement) ? document.activeElement.id : null,
};
}"""
)
print(f" 方向键后 tabindex=0 = {state['zero']},active = {state['active']},持焦 = {state['focused']}")
if len(state["zero"]) != 1:
failures.append(
f"方向键切换后整组有 {len(state['zero'])} 只 tab 可被 Tab 键到达({state['zero']}),"
"违反 roving tabindex 单点(旧 tab 仍留在序列里)"
)
elif not state["active"] or state["zero"][0] != state["active"][0]:
failures.append(
f"可被 Tab 键到达的 tab({state['zero']})不是 active tab({state['active']})"
)
if not state["active"]:
failures.append("方向键切换后无 active tab")
elif state["focused"] != state["active"][0]:
failures.append(f"方向键切换后焦点未跟随 active tab(持焦 {state['focused']})")
def check_cta(page, failures):
"""3. nav 转化入口与信息链接分层"""
page.set_viewport_size({"width": 1440, "height": 900})
page.evaluate("() => window.scrollTo(0, 0)")
styles = page.evaluate(
"""() => {
const links = [...document.querySelectorAll('.nav-links a')];
const info = links.find((a) => a.getAttribute('href') === '#features');
const cta = links.find((a) => a.getAttribute('href') === '#contact');
const pick = (el) => {
if (!el) return null;
const s = getComputedStyle(el);
return {
cls: el.className,
border: `${s.borderTopWidth} ${s.borderTopStyle} ${s.borderTopColor}`,
bg: s.backgroundColor,
color: s.color,
};
};
return { info: pick(info), cta: pick(cta) };
}"""
)
print(f" 信息链接 = {styles['info']}")
print(f" 转化入口 = {styles['cta']}")
if not styles["info"] or not styles["cta"]:
failures.append("nav 信息链接或 #contact 转化入口不存在")
return
if styles["info"] == styles["cta"]:
failures.append("nav 转化入口与信息链接样式完全相同(无分层)")
# 转化入口须比信息链接更醒目:文字更亮(白色)
print(" 判据:转化入口须与信息链接在描边/底色/文字色上至少一项不同")
def take_shots(page, out):
"""4. 人工评审截图:nav 分层(宽/窄)、窄视口 showcase tab 行"""
page.set_viewport_size({"width": 1440, "height": 900})
page.reload(wait_until="load")
page.mouse.move(0, 0)
time.sleep(1.0)
page.locator("#nav").screenshot(path=str(out / "nav-1440.png"))
page.set_viewport_size({"width": 375, "height": 812})
page.evaluate("() => window.scrollTo(0, 0)")
page.click("#navToggle")
time.sleep(0.5)
# 展开面板是 #nav 的绝对定位子元素,元素截图会裁到导航条自身高度,故截整个视口
page.screenshot(path=str(out / "nav-375-open.png"))
page.click("#navToggle")
for w in (480, 375):
page.set_viewport_size({"width": w, "height": 900})
page.locator(".showcase-tabs").scroll_into_view_if_needed()
page.mouse.move(0, 0)
time.sleep(0.5)
page.locator(".showcase-card").screenshot(path=str(out / f"showcase-{w}.png"))
print(f" 截图已写入 {out}:nav-1440 / nav-375-open / showcase-480 / showcase-375")
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--url", default="http://127.0.0.1:8088/")
ap.add_argument("--only", default="tabs,focus,roving,cta")
ap.add_argument("--shots", default="", help="传入目录则产出人工评审用截图")
args = ap.parse_args()
only = {s.strip() for s in args.only.split(",") if s.strip()}
failures = []
with sync_playwright() as p:
browser = p.chromium.launch(channel="chrome", headless=True)
page = browser.new_page(viewport={"width": 1440, "height": 900})
page.goto(args.url, wait_until="load")
time.sleep(1.2)
if "tabs" in only:
print("== 1. showcase tab 行与暂停按钮几何 ==")
check_tabs(page, failures)
if "focus" in only:
print("\n== 2. showcase 轮播焦点管理 ==")
check_focus(page, failures)
if "roving" in only:
print("\n== 3. 键盘 roving tabindex 单点 ==")
check_roving(page, failures)
if "cta" in only:
print("\n== 4. nav 转化入口分层 ==")
check_cta(page, failures)
if args.shots:
print("\n== 5. 人工评审截图 ==")
out = Path(args.shots)
out.mkdir(parents=True, exist_ok=True)
take_shots(page, out)
browser.close()
print("\n" + "=" * 46)
if failures:
print("RESULT: FAIL")
for f in failures:
print(" -", f)
sys.exit(1)
print("RESULT: PASS")
if __name__ == "__main__":
main()