Files
novalon-website/scripts/landing/landing-demo-verify.py
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

248 lines
12 KiB
Python
Raw Permalink 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
"""Hero Live Demo 演示动画验证脚本(landing/index.html #heroDemo)。
用法:
NO_PROXY=localhost,127.0.0.1 no_proxy=localhost,127.0.0.1 \
python3 scripts/landing-demo-verify.py [--url http://127.0.0.1:8088/] [--out /tmp/demo-verify]
验证内容:
1. 四步剧本各阶段截图(导入 → 图谱 → 检测 → AI 结论)
2. 循环重播(第二轮 demo-step-1 回归)
3. 无 JS 降级:演示层不可见、静态 mockup 完整、指标为终值
4. prefers-reduced-motion:demo-final 终态一次呈现
5. console error / pageerror 收集
"""
import argparse
import json
import sys
import time
from pathlib import Path
from playwright.sync_api import sync_playwright
# 剧本阶段与采样时刻(秒)。2026-11-07 hero 主图由图窗改为 /home 任务工作台后,
# 四步语义随之重写(新建任务 → 打开任务 → 导入数据 → 就绪),阶段名同步改掉;
# DUR = {s1:2.6, s2:3.4, s3:3.2, s4:3.8, hold:1.6},故 1.4 / 4.4 / 7.6 / 11.6 / 16.4 的
# 采样点相对于新剧本仍然落在各自的步内——**时刻未改,只改了阶段名**,因为改动时刻会让
# 「脚本采样点」与「动画真实时间轴」脱钩,那是判据自伤而不是适配。
STEPS = [
("step1-create", 1.4),
("step2-open", 4.4),
("step3-import", 7.6),
("step4-ready", 11.6),
("loop-restart", 16.4),
]
def cls_of(page):
return page.evaluate("document.getElementById('heroDemo').className")
# 步号 → 该步应当显示的徽标文案(与 index.html 的 data-badge 一一对应)
BADGE_OF_STEP = {
"demo-step-1": "新建任务",
"demo-step-2": "打开任务",
"demo-step-3": "导入数据",
"demo-step-4": "就绪",
}
def badges_now(page):
"""当前**真实可见**的徽标文案列表(三层可见性,与 nojs 判定同口径)。"""
return page.evaluate("""
() => [...document.querySelectorAll('.demo-chrome-badge-item')]
.filter((el) => {
const r = el.getBoundingClientRect();
if (!el.checkVisibility({checkOpacity: true, checkVisibilityCSS: true})) return false;
if (r.width <= 0 || r.height <= 0) return false;
let op = 1, n = el;
while (n && n.nodeType === 1) {
const o = parseFloat(getComputedStyle(n).opacity);
if (!Number.isNaN(o)) op *= o;
if (op <= 0.05) return false;
n = n.parentElement;
}
return true;
})
.map((el) => el.textContent.trim())
""")
def check_badge_matches_step(cls_samples, badge_samples):
"""【SHOULD-FIX-2 / 2026-11-07 复审】
徽标是 BLOCKING-1 修完后的核心资产(「徽标与步号同义」),但此前**只靠人眼守**:
复审的 PROBE-E 把 style.css 里整块徽标显示规则删掉,四道门禁仍然全绿。
这里补正向断言:四个采样点上,当前步必须**恰好显示 1 个**徽标,且文案与该步同义。
为什么是"恰好 1 个"而不是">= 1":同时显示两个徽标说明映射有重叠(正是首轮
「错位一整步」的伴生症状),那会让观众同时看到两个互斥的进度。
"""
problems = []
for name, cls in cls_samples.items():
step = next((st for st in BADGE_OF_STEP if st in cls), None)
if step is None:
continue # loop-restart 采样点落在复位瞬间,不判
want = BADGE_OF_STEP[step]
got = badge_samples.get(name, [])
if len(got) != 1:
problems.append(f"{name}: {step} 应恰好显示 1 个徽标,实测 {len(got)} 个 {got}")
elif got[0] != want:
problems.append(f"{name}: {step} 应显示「{want}」,实测「{got[0]}」")
return {"ok": not problems, "problems": problems}
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--url", default="http://127.0.0.1:8088/")
ap.add_argument("--out", default="/tmp/demo-verify")
args = ap.parse_args()
out = Path(args.out)
out.mkdir(parents=True, exist_ok=True)
report = {"console_errors": [], "page_errors": []}
with sync_playwright() as p:
browser = p.chromium.launch(channel="chrome", headless=True)
# ---- 场景 1:正常播放,分阶段截图 + 类名采样 ----
pg = browser.new_page(viewport={"width": 1440, "height": 900})
pg.on("console", lambda m: report["console_errors"].append(m.text) if m.type == "error" else None)
pg.on("pageerror", lambda e: report["page_errors"].append(str(e)))
pg.goto(args.url, wait_until="load", timeout=60000)
samples = {}
badges = {}
start = time.time()
for name, at in STEPS:
delta = at - (time.time() - start)
if delta > 0:
pg.wait_for_timeout(delta * 1000)
samples[name] = cls_of(pg)
badges[name] = badges_now(pg)
pg.screenshot(path=str(out / f"{name}.png"), clip={"x": 620, "y": 120, "width": 800, "height": 620})
report["class_samples"] = samples
report["badge_samples"] = badges
report["badge_step_check"] = check_badge_matches_step(samples, badges)
# ---- 场景 2:无 JS 降级 ----
ctx2 = browser.new_context(java_script_enabled=False, viewport={"width": 1440, "height": 900})
pg2 = ctx2.new_page()
pg2.goto(args.url, wait_until="load", timeout=60000)
pg2.wait_for_timeout(500)
# 无 JS 降级(2026-11-07 口径迁移):原断言挂在图窗的 .demo-import / .demo-ai /
# [data-count-to=2046](= 关系数)/ .app-mockup-alert 上,那四样随 hero 改画 /home 已不存在。
# 新口径问的是同一个问题——"没有 JS 时,首屏该看见的数是不是已经看得见":
# · 任务总数读数 = 6(而不是被脚本归零的 0)
# · 当前打开行仍在(is-current 是静态类,不靠 JS 加)
# · 列头可见(视口锁定后列头只渲染一次,它是纯静态结构)
# 【2026-11-07 §28.2 评审 BLOCKING-2 修法:判据收紧,不是放宽】
# 上一版只读 textContent + computed display,对「内容在、但看不见」零判别力:
# 评审用 `html:not(.js-demo) .nv-home-rows{opacity:0!important;visibility:hidden!important}`
# 注入后本门禁仍然 PASS,截图是空白台账。那与 2026-11-04 的 Blocking① 是同一失效模式
# (那一轮也是"内容在、看不见、门禁全绿")。
# 现改为**真实可见性**判定,四层缺一不可:
# ① checkVisibility({checkOpacity, checkVisibilityCSS}) —— 浏览器自己的口径
# ② 祖先链上 opacity 有效值 > 0.05(checkVisibility 对 opacity 的处理在旧内核不一致)
# ③ 元素矩形有面积(width/height > 0,排除被 layout 折叠)
# ④ 文字非空
report["nojs"] = {
# 台账读数是**静态数据**(6 个任务),不是动画指标——它旁边列着 4 行真实任务,
# 若写成 0 就与内容自相矛盾。故这里断言它无 JS 时就等于 6。
"task_total": pg2.evaluate(
"document.querySelector('.nv-home-pager b').textContent"),
"current_row": pg2.evaluate(
"document.querySelectorAll('.nv-home-row.is-current').length"),
# 列头 + 第一行任务:不仅看 display,还要真的**看得见**
"cols_visible": pg2.evaluate(
"document.querySelector('.nv-home-cols').checkVisibility("
"{checkOpacity:true, checkVisibilityCSS:true})"),
"rows_visible": pg2.evaluate("""
() => {
const rows = [...document.querySelectorAll('.nv-home-row')];
if (rows.length === 0) return 0;
return rows.filter((el) => {
const st = getComputedStyle(el);
const r = el.getBoundingClientRect();
// ② 祖先链有效 opacity
let op = 1, n = el;
while (n && n.nodeType === 1) {
const o = parseFloat(getComputedStyle(n).opacity);
if (!Number.isNaN(o)) op *= o;
if (op <= 0.05) return false;
n = n.parentElement;
}
// ① + ③ + ④
const visible = el.checkVisibility({checkOpacity: true, checkVisibilityCSS: true});
return visible && r.width > 0 && r.height > 0
&& (el.textContent || '').trim().length > 0;
}).length;
}
"""),
"demo_rows_seen": pg2.evaluate(
"document.querySelectorAll('.nv-home-row').length"),
# 反向断言:**仅动画层**的徽标在无 JS 时必须不可见。
# 它只在演示推进时有意义("现在走到哪一步"),无 JS 时没有步骤可指,
# 显示出来就是一条没有指涉的标签。评审用
# `.demo-chrome-badge{display:flex!important}` 注入出一条,上一版断言放过了它。
"badge_visible": pg2.evaluate("""
() => [...document.querySelectorAll('.demo-chrome-badge-item')]
.filter((el) => {
const r = el.getBoundingClientRect();
return el.checkVisibility({checkOpacity: true, checkVisibilityCSS: true})
&& r.width > 0 && r.height > 0;
}).length
"""),
# 正向金丝雀:选择器必须真的命中元素。
# 否则 `badge_visible == 0` 会因为"一个徽标都没选中"而恒真——恒真的断言等于没有断言
# (本仓反复踩过这个形状:判据通过态是 0 或空集时,"0"本身不是证据)。
"badge_count": pg2.evaluate(
"document.querySelectorAll('.demo-chrome-badge-item').length"),
}
pg2.screenshot(path=str(out / "nojs-static.png"), clip={"x": 620, "y": 120, "width": 800, "height": 620})
ctx2.close()
# ---- 场景 3:prefers-reduced-motion ----
ctx3 = browser.new_context(reduced_motion="reduce", viewport={"width": 1440, "height": 900})
pg3 = ctx3.new_page()
pg3.on("pageerror", lambda e: report["page_errors"].append("reduced: " + str(e)))
pg3.goto(args.url, wait_until="load", timeout=60000)
pg3.wait_for_timeout(1200)
report["reduced"] = {
"hero_class": pg3.evaluate("document.getElementById('heroDemo').className"),
"task_total": pg3.evaluate(
"document.querySelector('.nv-home-pager b').textContent"),
"current_row": pg3.evaluate(
"document.querySelectorAll('.nv-home-row.is-current').length"),
}
pg3.screenshot(path=str(out / "reduced-final.png"), clip={"x": 620, "y": 120, "width": 800, "height": 620})
ctx3.close()
browser.close()
print(json.dumps(report, ensure_ascii=False, indent=2))
# 判定:无 pageerror + 循环回归 demo-step-1 + 无 JS 降级成立
ok = (
not report["page_errors"]
and "demo-step-1" in report["class_samples"].get("loop-restart", "")
# 无 JS 时必须直接看到终值 6(脚本未接管就不该出现 0)
and report["nojs"]["task_total"] == "6"
and report["nojs"]["current_row"] == 1
# 列头与**全部**任务行必须真的可见(不是"存在但被 opacity/visibility 藏起来")
and report["nojs"]["cols_visible"] is True
and report["nojs"]["demo_rows_seen"] > 0
and report["nojs"]["rows_visible"] == report["nojs"]["demo_rows_seen"]
# 仅动画层在无 JS 时不得可见;且选择器必须非空(否则上一条恒真)
and report["nojs"]["badge_count"] > 0
and report["nojs"]["badge_visible"] == 0
and "demo-final" in report["reduced"]["hero_class"]
# 徽标正向:每步恰好 1 个且与步号同义(SHOULD-FIX-2)
and report["badge_step_check"]["ok"]
)
print("VERIFY_RESULT:", "PASS" if ok else "FAIL")
return ok
if __name__ == "__main__":
# 判据必须同时体现在 stdout 和退出码上:只打印 FAIL 而恒 exit 0,
# 会让 §19/§21 引用的「门禁 exit 0」失去证明力(自检见 scripts/selfcheck-gates.sh)
sys.exit(0 if main() else 1)