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。
This commit was merged in pull request #70.
This commit is contained in:
zhangxiang committed 2026-12-03 22:56:17 +08:00
1 parent f20fc92dc3
commit 99eaa8c66a
38 files changed
+3904 -48

No files matched your search

+193
View File
@@ -0,0 +1,193 @@
import { test, expect, type Page } from '@playwright/test';
/**
* Landing 门禁 ②:渐进生长动效(移植自 `novavis-authority/scripts/verify-landing-motion.py`)
*
* ## 判据(与迁移前逐条对应,一条不放宽)
*
* 1. `html.js-grow` 已挂载 —— CSS 初始隐藏态生效的前提(没挂上时所有元素本来就是可见的,
* 后面的「生长」判据会退化成恒真)。
* 2. Hero 首屏演示推进:`demo-step-1..4` 按序出现且单向(不回头)。
* hero 在 2026-11-07 改画 `/home` 任务工作台后不再有 `data-grow` 元素,
* 「动画在跑」这件事改由步骤类推进来证明(原脚本的等价迁移)。
* 3. Showcase 四个 panel 切 tab 后各自重播到**峰值 = 目标总数**(不锁死具体数字)。
* 4. 离开视口后 `is-grown` 复位为 0(否则「重播」可能是残留态)。
* 5. `prefers-reduced-motion` 下直达终态(`is-grown == 总数`)。
* 6. 装饰性图形对 AT 隐藏(`aria-hidden="true"`),且其子树内**无可聚焦元素**
* (axe `aria-hidden-focus` 的静态等价物);暂停控件存在且带 `aria-pressed`。
* 7. 无 JS 运行时错误。
*
* ## 为什么用「密集采样取峰值」而不是末次快照
*
* 剧本播完会循环复位,固定短窗口采样会读到复位后的 0 而假失败。原脚本的 `watch_growth`
* 就是为此写的,这里保持同口径:峰值须等于总数。
*/
const LANDING_URL = '/novavis';
const PANELS = [
{ tab: '#showcase-tab-graph', panel: '#showcase-panel-graph', name: '账户综合关联' },
{ tab: '#showcase-tab-flow', panel: '#showcase-panel-flow', name: '进出统计分析' },
{ tab: '#showcase-tab-ai', panel: '#showcase-panel-ai', name: '智能问答' },
{ tab: '#showcase-tab-process', panel: '#showcase-panel-process', name: '生成分析报告' },
] as const;
/** 待点亮目标总数(与 `main.js` 的 targetsOf 同规则:`<g>` 按子元素数计,其余算 1)。 */
async function totalTargets(page: Page, selector: string): Promise<number> {
return page.evaluate((sel) => {
const root = document.querySelector(sel);
if (!root) return 0;
let n = 0;
root.querySelectorAll('[data-grow]').forEach((el) => {
n += el.tagName.toLowerCase() === 'g' ? el.children.length : 1;
});
return n;
}, selector);
}
async function grown(page: Page, selector: string): Promise<number> {
return page.locator(`${selector} .is-grown`).count();
}
/** 密集采样到峰值(剧本会循环复位,故以「是否曾到达终态」判定)。 */
async function watchGrowth(
page: Page,
selector: string,
total: number,
windowMs = 12000,
intervalMs = 400,
): Promise<{ peak: number; samples: number[] }> {
const samples: number[] = [];
let peak = 0;
const deadline = Date.now() + windowMs;
while (Date.now() < deadline) {
const cur = await grown(page, selector);
peak = Math.max(peak, cur);
samples.push(cur);
if (peak === total) break;
await page.waitForTimeout(intervalMs);
}
return { peak, samples };
}
/** 采样 `demo-step-*` 的推进序列(去重、保序)。 */
async function watchDemoSteps(page: Page, selector: string, windowMs = 14000): Promise<string[]> {
const seen: string[] = [];
const deadline = Date.now() + windowMs;
while (Date.now() < deadline) {
const cls = await page.evaluate(
(sel) => document.querySelector<HTMLElement>(sel)?.className ?? '',
selector,
);
const cur = ['demo-step-1', 'demo-step-2', 'demo-step-3', 'demo-step-4'].find((s) => cls.includes(s));
if (cur && !seen.includes(cur)) seen.push(cur);
await page.waitForTimeout(250);
}
return seen;
}
test.describe('landing ② 动效与生长', () => {
test('js-grow 挂载 + hero 剧本单向推进 + 四屏重播 + 离开复位', async ({ page }) => {
const pageErrors: string[] = [];
page.on('pageerror', (e) => pageErrors.push(String(e)));
await page.goto(LANDING_URL, { waitUntil: 'load' });
await page.waitForTimeout(1500);
// 1. js-grow 挂载
const jsGrow = await page.evaluate(() => document.documentElement.classList.contains('js-grow'));
expect(jsGrow, 'html.js-grow 未挂载(CSS 初始隐藏态不生效 ⇒ 后续「生长」判据会退化成恒真)').toBe(true);
// 2. hero 剧本推进
const heroTotal = await totalTargets(page, '.hero-visual');
const stepsSeen = await watchDemoSteps(page, '#heroDemo');
expect(
stepsSeen.length,
`Hero 剧本未推进:只观察到 ${JSON.stringify(stepsSeen)}`,
).toBeGreaterThanOrEqual(3);
expect(stepsSeen[0], `Hero 剧本未从第 1 步开始:${JSON.stringify(stepsSeen)}`).toBe('demo-step-1');
expect(
stepsSeen.some((s) => s === 'demo-step-3' || s === 'demo-step-4'),
`Hero 剧本未走完前半程:${JSON.stringify(stepsSeen)}`,
).toBe(true);
// hero 上出现 data-grow 目标说明 DOM 又画回了图窗形态,此时期望值需重钉(原脚本同样打印该提示)
expect(heroTotal, `hero 上出现 ${heroTotal} 个 data-grow 目标,与「/home 剧本无生长目标」的口径不符`).toBe(0);
// 3. 四屏重播
await page.locator('#showcase').scrollIntoViewIfNeeded();
await page.waitForTimeout(500);
for (const { tab, panel, name } of PANELS) {
await page.click(tab);
await page.waitForTimeout(200);
const total = await totalTargets(page, panel);
expect(total, `${name}: data-grow 目标总数为 0(判据分母为空)`).toBeGreaterThan(0);
const before = await grown(page, panel);
const { peak } = await watchGrowth(page, panel, total);
expect(
peak === total || before < peak,
`${name} 切换后未重播:峰值 ${peak}(切换后 ${before},总数 ${total})`,
).toBe(true);
expect(peak, `${name} 未跑完:峰值 ${peak}/${total}`).toBe(total);
}
// 4. 离开视口复位
await page.evaluate(() => window.scrollTo(0, document.body.scrollHeight));
await page.waitForTimeout(1000);
const afterLeave = await grown(page, '#showcase-panel-process');
expect(afterLeave, `离开视口未复位: ${afterLeave}(期望 0)`).toBe(0);
// 7. 无 JS 运行时错误
expect(pageErrors, `landing 页有 JS 运行时错误:${pageErrors.join(' | ')}`).toEqual([]);
});
test('reduced-motion 直达终态 + 装饰图形对 AT 隐藏', async ({ page }) => {
await page.emulateMedia({ reducedMotion: 'reduce' });
await page.goto(LANDING_URL, { waitUntil: 'load' });
await page.waitForTimeout(1200);
await page.locator('#showcase').scrollIntoViewIfNeeded();
await page.waitForTimeout(400);
const rTotal = await totalTargets(page, '#showcase-panel-graph');
const rGrown = await grown(page, '#showcase-panel-graph');
expect(rTotal, 'reduced-motion 下 showcase 目标总数为 0(判据分母为空)').toBeGreaterThan(0);
expect(rGrown, `reduced-motion 未直达终态: ${rGrown}/${rTotal}`).toBe(rTotal);
// 6. 装饰性图形无障碍属性
const a11y = await page.evaluate(() => {
const FOCUSABLE = 'a[href], button, input, select, textarea, [tabindex]';
const heroDemo = document.querySelector('#heroDemo')?.getAttribute('aria-hidden') ?? null;
const showcaseVisuals = [...document.querySelectorAll('.showcase-visual')].map((e) =>
e.getAttribute('aria-hidden'),
);
const heroVisual = document.querySelector('.hero-visual')?.getAttribute('aria-hidden') ?? null;
const focusableInHidden = [...document.querySelectorAll('[aria-hidden="true"]')]
.flatMap((root) => [...root.querySelectorAll(FOCUSABLE)])
.filter((e) => !e.hasAttribute('disabled') && (e as HTMLElement).tabIndex >= 0)
.map((e) => `${e.tagName.toLowerCase()}#${e.id}`);
const btn = document.querySelector('#demoPause');
const demoPause = btn
? {
exists: true,
label: btn.getAttribute('aria-label'),
pressed: btn.getAttribute('aria-pressed'),
}
: { exists: false, label: null, pressed: null };
return { heroDemo, showcaseVisuals, heroVisual, focusableInHidden, demoPause };
});
expect(a11y.heroDemo, `演示层未对 AT 隐藏: ${a11y.heroDemo}`).toBe('true');
expect(a11y.showcaseVisuals.length, '.showcase-visual 一个都没选中(判据分母为空)').toBeGreaterThan(0);
expect(
new Set(a11y.showcaseVisuals),
`.showcase-visual aria-hidden 应全为 true,实测 ${JSON.stringify(a11y.showcaseVisuals)}`,
).toEqual(new Set(['true']));
// .hero-visual 承载暂停按钮,隐藏会连带隐藏控件 ⇒ 必须为 null
expect(a11y.heroVisual, '.hero-visual 不应 aria-hidden(它承载暂停控件)').toBeNull();
expect(a11y.focusableInHidden, `aria-hidden 子树内有可聚焦元素: ${a11y.focusableInHidden.join(',')}`).toEqual(
[],
);
expect(a11y.demoPause.exists, '暂停控件 #demoPause 不存在(WCAG 2.2.2 要求自动播放内容可暂停)').toBe(true);
expect(a11y.demoPause.label, '暂停控件缺 aria-label').toBeTruthy();
expect(a11y.demoPause.pressed, '暂停控件缺 aria-pressed 状态').not.toBeNull();
});
});