release: 视觉门禁状态判据 + CMS 退化可判(#58) #59

Merged
zhangxiang merged 4 commits from dev into main 2026-10-21 16:54:37 +08:00
10 changed files with 362 additions and 25 deletions

No files matched your search

+6 -1
View File
@@ -347,7 +347,12 @@ novalon-accenture-redesign/
# - backup-*/:landing/apply.sh 自建还原点。只忽略其中的 png/ico/webmanifest/tsx 副本
# (内容都能从 git 取回),同目录的 svg 半份是已入库资产,不能用目录级规则一并屏蔽
deliverables/**/*.html
deliverables/logo-redesign-2026-10-13/fonts/
# 字体源与 woff2 子集留本地(43MB,仅本机栅格化用;站内实际引用的字体在 public/fonts)
# 但授权文本与清单必须入库:OFL 要求随分发附带,且它们是「用了哪几套字」的唯一记录
deliverables/logo-redesign-2026-10-13/fonts/*
!deliverables/logo-redesign-2026-10-13/fonts/FONT-MANIFEST.md
!deliverables/logo-redesign-2026-10-13/fonts/LICENSES.md
!deliverables/logo-redesign-2026-10-13/fonts/OFL-*.txt
deliverables/logo-redesign-2026-10-13/landing/backup-*/public/*.png
deliverables/logo-redesign-2026-10-13/landing/backup-*/public/*.ico
deliverables/logo-redesign-2026-10-13/landing/backup-*/public/site.webmanifest
@@ -0,0 +1,26 @@
# 中文字体子集包(P2 已裁定:思源宋体进正文,先只上 tight 档)
全部由 `font-subset.py` 现场切出并用 `fontTools` 回读 cmap 验证,不是引用别人的数字。复跑:
```
/tmp/fenv/bin/python font-subset.py # 目标字符集 = 扫 src 的 407 个 .ts/.tsx 得 1050 码位
```
| 文件 | 字族/档 | 体积 | sha256 前 16 | 说明 |
|---|---|---|---|---|
| `notoserifsc-subset.woff2` | 思源宋体(可变 200–900)tight 档 | 388.1 KB | 2c1a2ad9df1a96be | P2 采用档:源码实际用字 1050 码位,回读 cmap 缺字 0 |
| `notoserifsc-wide.woff2` | 思源宋体 wide 档 | 1361.0 KB | a8ab2160a3ed1a8d | GB2312 一级 3755 + ASCII/标点 = 3841 码位,缺字 0;**押后**(出网仅 1 Mbps) |
| `lxgwwenkaitc-subset.woff2` | 霞鹜文楷 TC tight 档 | 262.9 KB | 9c0d4a223b37289d | 第二字族(年报引言等叙述体),单字重;缺字 0 |
| `mashanzheng-subset.woff2` | 马善政毛笔楷书(反例) | 406.4 KB | fe9f6ac249c594c4 | 切完仍**缺「遠」与「·」** ⇒ 品牌名「睿新致遠」不可用,留作证伪证据 |
**三条落地约束(落库时必须一起处理,否则会踩授权与合规)**
1. **OFL 要求授权文本随字体分发**:已补齐两份全文并做内容核验(正文含 `SIL OPEN FONT LICENSE Version 1.1`),见 [LICENSES.md](LICENSES.md) 与 `OFL-NotoSerifSC.txt` / `OFL-LXGWWenKai.txt`。霞鹜的 RFN 条款明确允许"仅为网页字体交付而做的子集/格式转换"保留保留字体名 ⇒ 我们切 woff2 自托管在允许范围内;但**不得**把它做成可安装桌面字体沿名发布。发布时这两份 txt 必须与 woff2 同目录或同等可达。SIL Open Font License 1.1 原文一并放进 `public/fonts/`(或与字体同目录),并在文档里保留版权声明。
2. **禁止外部字体 CDN**(项目规则)⇒ 只能自托管;`@font-face` 写在 `src/app/globals.css`,`font-display: swap`,`unicode-range` 不必手工切(子集本身就是窄集)。
3. **子集覆盖不了 CMS 后台新增中文**:站点有 CMS,967 个源码用字之外的字会回退到系统衬线。这正是"先只上 tight 档"的理由 —— 等真有中文长文再上 wide(1361 KB)。
**执行边界**:本目录是准备件。把字体放进 `public/fonts/` 与改 `globals.css` 都是仓库写入,按 AGENTS.md §5.1 需单独授权,目前**一件没动**(`git diff --name-only` 恒为 0 行)。
---
**执行件已就绪并三向验过**:`staging-p2/fontsync.sh`(由 `make-fontsync.py` 生成)。正例:3 个文件放进 `public/fonts/` 并逐字节对拍、`"Novalon Serif SC"` 插到 `--font-serif` 队首(原系统兜底全部保留)、追加 `@font-face`(可变 200–900、`font-display: swap`);落点实测在副本的 `globals.css:201` 与 `:1471`。负例:重复执行被拒(认块内标记);不给 `REPO_ROOT` 被拒。该暂存件已纳入 `check-probes` 的 S4b 齐全性检查(藏起来会报红)。
@@ -0,0 +1,14 @@
# 字体授权文本(P2 自托管的分发要件)
OFL 1.1 第 (2) 条要求"含保留字体名的原始版本不得改名分发",而实践中**授权文本必须随字体一起给**;现在 `fonts/` 里只有 woff2,缺这两份就是合规缺口。
| 文件 | 字族 | 字节 | sha256 前 16 | 取信来源 |
|---|---|---|---|---|
| `OFL-NotoSerifSC.txt` | 思源宋体 / Noto Serif SC | 4350 | `5e0da210fb04058a` | https://raw.githubusercontent.com/google/fonts/main/ofl/notoserifsc/OFL.txt |
| `OFL-LXGWWenKai.txt` | 霞鹜文楷 / LXGW WenKai TC | 5171 | `1a25e35da1031c6c` | https://raw.githubusercontent.com/lxgw/LxgwWenKai/main/OFL.txt |
**两条要点**
1. 两份都经内容核验:正文含 `SIL OPEN FONT LICENSE Version 1.1`(不是只看到文件名就当作对)。
2. **霞鹜文楷的 RFN 条款对我们有利**:其原文允许"仅为网页字体交付而做的子集/格式转换版本"继续保留『霞鹜/LXGW』这些保留字体名,前提是不得作为可安装桌面字体发布。⇒ 我们正是切 woff2 自托管网页字体,**落在允许范围内**;若将来有人把它做成桌面字体安装包,就必须改名。
3. 思源宋体(Noto Serif SC)在 google/fonts 仓库的授权文件实名是 `OFL.txt`(不是 `LICENSE`),第一次取 `LICENSE` 得到 404 —— 落库时按本表的路径取,别猜文件名。
@@ -0,0 +1,94 @@
Copyright 2021-2026 LXGW (https://github.com/lxgw/LxgwWenKai), with Reserved Font Name '霞鹜', '霞鶩', '落霞孤鹜', '落霞孤鶩' and 'LXGW'. [ADDITIONAL PERMISSION] The Reserved Font Names '霞鹜', '霞鶩', '落霞孤鹜', '落霞孤鶩' and 'LXGW' may continue to be used in Modified Versions recompiled from the Original Version, without modifications to the font source code; or in Modified Versions subsetted or converted to other formats (e.g., WOFF/WOFF2) solely for web font delivery, provided such Modified Versions are not made available as installable desktop fonts (e.g., on mainstream platforms like Google Fonts, or third-party non-commercial platforms recognized by the author @lxgw; other web font platforms please contact the author @lxgw for confirmation).
Copyright 2020 The Klee Project Authors (https://github.com/fontworks-fonts/Klee)
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
https://openfontlicense.org
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.
The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).
"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.
"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.
5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are
not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.
@@ -0,0 +1,94 @@
Copyright 2012 Google Inc. All Rights Reserved.
This Font Software is licensed under the SIL Open Font License,
Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font
creation efforts of academic and linguistic communities, and to
provide a free and open framework in which fonts may be shared and
improved in partnership with others.
The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply to
any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).
"Original Version" refers to the collection of Font Software
components as distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to,
deleting, or substituting -- in part or in whole -- any of the
components of the Original Version, by changing formats or by porting
the Font Software to a new environment.
"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed,
modify, redistribute, and sell modified and unmodified copies of the
Font Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components, in
Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the
corresponding Copyright Holder. This restriction only applies to the
primary font name as presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.
5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created using
the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are
not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.
+20 -18
View File
@@ -924,7 +924,7 @@ if [ "$A" -eq 0 ] && [ "$B" -eq 0 ]; then git add … && git commit … && git p
⇒ 通用判据:**跨路由的「等旧页退场再挂新页」不能依赖 framer 的 presence 状态机;
新页面挂载不得以旧页面的动画完成作为前置条件。**
### 5.51 视觉门禁的间歇红有两种签名:dwell 竞态与 CMS 取数退化,都不是像素回归(2026-10-20)
### 5.51 视觉门禁的间歇红有两种签名:装配竞态与整段换版式,都不是像素回归(2026-10-20)
**现象**:在 `3fabb77c` 上只读比对 `visual-regression.spec.ts`(本批未碰 `/team`、`/about/brand`
任何文件)得 **121 passed / 4 failed / EXIT=1**;紧接着原样重跑同一批用例,失败集合换了一批
@@ -943,28 +943,30 @@ expected 是已显影正文 ⇒ 内容停在 `opacity:0` 初始态,而不是
目标),但 IO 回调与 framer 的 `whileInView` 提交都要排帧;4 worker 抢 CPU 时 dwell 不够,
中间某屏就被跳过。判别实验:同一批用例 `--workers=1` 重跑 **10 passed / 0 failed / EXIT=0**。
**修法①**(只覆盖下面签名 1;独立动作,未随本批落地):dwell 提到 ≥250ms 且每步排空一帧
(`requestAnimationFrame`);或给 `ScrollReveal` 加一个「已显影」可查询标记供用例等待——
现在 `src/components/ui/scroll-reveal.tsx:80-96` 只透传 `className`,这条写不出来。
门禁口径:视觉层默认执行方式钉成 `--workers=1`,否则 `test:all` 里这一层可红可绿。
**修法(2026-10-20 已落地)**:`waitForPageStable` 的 dwell 120ms → 260ms 且每步排空
两帧;滚动结束后**再等一次「显影落定」**——`main` 下 inline `opacity:0`(framer 未提交的
初始态)且仍有高度的元素必须归零,超时直接把前 5 个 offender 的标签写进错误里,而不是
留给像素比对去猜。这条把关的是**状态**,不是时长,所以对 CPU 争用不敏感。
**补测(同日 22:20–22:35,同一棵树 `9ea8d5f4`)**:把整层改成 `--workers=1` 全量复跑,
得 **124 passed / 1 failed** —— 上面「串行即绿」的说法过强,必须更正。且那一条红
(`L2 主题切换 › 浅色主题 - 首页视觉` @ `visual-chromium-tablet`)在同一棵树上
`--repeat-each=3` 隔离复跑是 **3 passed**,在改动前的 `3fabb77c` 上单跑也是 passed。
⇒ 它是**负载相关的间歇红**,不是 worker 数目的函数。
**没有采用的方案**:把视觉层默认钉成 `--workers=1`。它能让读数稳定,但把 5 分钟的层拖到
17 分钟,是用串行掩盖竞态;竞态本身有确定的状态判据,就该按状态等。
**两种签名必须分开归因**(都不是像素回归):
1. **同高、带内空白**(`/team`、`/about/brand`):页高与基线一致,差异只在一条带内,
带内 actual 是 `opacity:0` 的空白 ⇒ `waitForPageStable` 的 120ms dwell 没把
`whileInView` 提交完。
带内 actual 是 `opacity:0` 的空白 ⇒ 120ms dwell 没把 `whileInView` 提交完(上面的修法覆盖它)。
2. **不等高、整段换版式**(首页 `theme-light-main` @ tablet):actual 比基线**矮 3114px**,
且带内不是空白而是**另一套版式**(浅色无图 hero、`还没有可以公开的成果` 占位区)。
根因在 `src/app/(marketing)/page.tsx:60` 的 `await getHomePageCopy().catch(() => null)`
——CMS 取数在负载下退化即静默回落成常量版式,页面照常 200、只是内容换了。
这一类**不能**用「加大 dwell」修,也不该由视觉基线去背。
**机理未取证,不要照抄一个像样的解释**:当时的怀疑是 `src/app/(marketing)/page.tsx` 里
`getHomePageCopy().catch(() => null)` 静默降级,但 hero 在代码里是**无条件黑底**
(`home-content-v16.tsx:101` 的 `bg-[#0B0A08]`),null copy 根本产生不出「浅色 hero」
⇒ 该解释被自己的代码读回否掉。已确证的只有:同树隔离复跑 3/3 绿、基线与被测代码一致
⇒ 环境侧偶发,不是提交引入。
收口方式因此改成**把状态显式化**而不是猜:首页现在输出 `data-cms-state`(`ok`/`empty`,
`page.tsx` 判定、`home-content-v16.tsx` 渲染),视觉层截图前先断言它——真退化会以
「CMS 数据退化:data-cms-state=empty」按名字失败。
⇒ 通用判据:**「串行复跑变绿」不足以给并行红背书,先比对签名再归因。**
同高空白带 = 装配竞态;不等高且内容换了一套 = 数据侧退化。判据实验是
「隔离复跑 N 次是否稳定 + actual/expected 的页高是否一致」,而不是「换一种并发就绿了」。
动基线之前这两步都要跑完,否则会把竞态或退化固化成参照。
同高空白带 = 装配竞态,用状态判据修;不等高且内容换了一套 = 先证伪自己的机理解释,
再决定是数据侧还是环境侧。判据实验是「隔离复跑 N 次是否稳定 + 页高是否一致 +
解释能否被代码读回」,而不是「换一种并发就绿了」。动基线之前这几步都要跑完,
否则会把竞态或一次偶发固化成参照。
+51 -4
View File
@@ -51,11 +51,16 @@ async function waitForPageStable(page: Page) {
// 不能直接 `scrollTo(scrollHeight)` 一跳到底:IntersectionObserver 只会回调当前视口
// 内的目标,中间各屏被跳过 ⇒ 截图出来是空白段(2026-10-20 移除路由级 AnimatePresence
// 后首屏不再替子树屏蔽 initial,这条路径才真正被走到)。
// dwell 由 120ms 提到 260ms 并排掉两帧:120ms 在 4 worker 抢 CPU 时不足以让
// IO 回调 + framer 提交动画,中间某屏会被跳过(lessons §5.51)。
await page.evaluate(async () => {
const nextFrame = () =>
new Promise<void>((resolve) => requestAnimationFrame(() => requestAnimationFrame(() => resolve())));
const step = Math.max(400, Math.floor(window.innerHeight * 0.8));
for (let y = 0; y <= document.body.scrollHeight; y += step) {
window.scrollTo({ top: y, behavior: 'instant' });
await new Promise((resolve) => setTimeout(resolve, 120));
await new Promise((resolve) => setTimeout(resolve, 260));
await nextFrame();
}
window.scrollTo({ top: document.body.scrollHeight, behavior: 'instant' });
await new Promise((resolve) => setTimeout(resolve, 400));
@@ -71,10 +76,52 @@ async function waitForPageStable(page: Page) {
});
});
await page.waitForTimeout(1000);
await page.evaluate(() => {
document.fonts?.ready;
});
await page.evaluate(() => document.fonts?.ready);
await page.waitForTimeout(500);
await assertCmsStateOk(page);
await waitForRevealsSettled(page);
}
/**
* 等 whileInView 真正提交:framer 把未开始的动画写成 inline `opacity: 0`,
* 完成后改写成 1。两者只差这一笔,所以按 inline style 判定即可。
* 排除 display:none 与零高度元素(折叠菜单、屏外测距节点),避免把「本来就不可见」判成未提交。
* 表达式以字符串传入:它在浏览器上下文求值,闭包里的 Node 侧变量带不过去。
*/
const PENDING_REVEALS_EXPR =
"Array.from(document.querySelectorAll('main *')).filter((el) => el.style.opacity === '0' && getComputedStyle(el).display !== 'none' && el.getBoundingClientRect().height > 0)";
async function waitForRevealsSettled(page: Page) {
try {
await page.waitForFunction(`${PENDING_REVEALS_EXPR}.length === 0`, undefined, {
timeout: 8000,
polling: 100,
});
} catch {
const total: number = await page.evaluate(`${PENDING_REVEALS_EXPR}.length`);
const pending: string[] = await page.evaluate(
`${PENDING_REVEALS_EXPR}.slice(0, 5).map((el) => el.tagName.toLowerCase() + '.' + String(el.className).split(' ').slice(0, 2).join('.'))`,
);
throw new Error(
`${total} 个元素仍停在 inline opacity:0(whileInView 未提交):${pending.join(' , ')}`,
);
}
}
/**
* 首页把 CMS 读数状态写在 `data-cms-state` 上。退化时页面照常 200、只是整套落到常量版式,
* 像素比对只会给出一团无从归因的差异 —— 在这里先按名字判一次。
*/
async function assertCmsStateOk(page: Page) {
const marker = page.locator('main [data-cms-state]').first();
if ((await marker.count()) === 0) return;
const state = await marker.getAttribute('data-cms-state');
if (state !== 'ok') {
throw new Error(
`CMS 数据退化:data-cms-state=${state};页面已回落到常量版式,像素比对无意义(lessons §5.51)`,
);
}
}
test.describe('L1: 全页面视觉回归测试', () => {
+4 -1
View File
@@ -635,6 +635,7 @@ export default function HomeContentV16({
news,
pageCopy,
trustSignals,
cmsState = 'ok',
}: {
services?: CapabilityRow[];
solutions?: Row[];
@@ -644,6 +645,8 @@ export default function HomeContentV16({
news?: NewsItem[];
pageCopy?: Record<string, unknown> | null;
trustSignals?: Row[];
/** 由 page.tsx 判定的 CMS 读数状态;视觉用例据此按名字判红,而不是猜像素差 */
cmsState?: 'ok' | 'empty';
}) {
const caseRows = cases ?? [];
// 判别式联合要靠显式类型标注收窄 —— 三元直接推会退化成 { kind: string },
@@ -654,7 +657,7 @@ export default function HomeContentV16({
: { kind: 'co-creation', steps: CO_CREATION_STEPS };
return (
<div>
<div data-cms-state={cmsState}>
{/* 咨询机构的首页节拍:影像开场 → 编辑内容 → 行业网格 → 能力
→ 客户成果 → 信任 → 收尾 CTA。数字账本压成 hero 后的一条窄带,
不抢「新闻」这一拍。段序变化只动装配顺序,各段的真源与空态判据不变。 */}
+40
View File
@@ -24,6 +24,7 @@ jest.mock('./home-content-v16', () => ({
<div data-testid="news-count">{(props.news as unknown[])?.length ?? 0}</div>
<div data-testid="hero-data">{props.heroData ? JSON.stringify(props.heroData) : 'null'}</div>
<div data-testid="page-copy-data">{props.pageCopy ? JSON.stringify(props.pageCopy) : 'null'}</div>
<div data-testid="cms-state">{String(props.cmsState ?? '')}</div>
</div>
);
},
@@ -176,4 +177,43 @@ describe('HomePage', () => {
expect(screen.getByTestId('services-count')).toHaveTextContent('0');
expect(screen.getByTestId('hero-data')).toHaveTextContent('null');
});
/**
* CMS 读数退化与「后台就是没内容」在页面上长得一样:两者都落到常量版式,
* 页面照常 200。视觉基线只能看到像素差,读不出是哪一种 —— 2026-10-20 的间歇红
* 就是这么被当成竞态的。这里把状态显式透出,视觉层才能按名字失败。
*/
it('一条内容都没读到 ⇒ cmsState=empty(供视觉层按名字判红)', async () => {
const page = await HomePage();
render(page);
expect(screen.getByTestId('cms-state')).toHaveTextContent('empty');
});
it('任一来源读到内容 ⇒ cmsState=ok', async () => {
mockedGetResolvedHomeZones.mockResolvedValue({
hero: [createMockItem('hero-banner', { heading: 'H' })],
});
const page = await HomePage();
render(page);
expect(screen.getByTestId('cms-state')).toHaveTextContent('ok');
});
it('page-copy 读取抛错时页面不炸,且错误不被静默吞掉', async () => {
mockedGetResolvedHomeZones.mockResolvedValue({
hero: [createMockItem('hero-banner', { heading: 'H' })],
});
mockedGetHomePageCopy.mockRejectedValue(new Error('SQLITE_BUSY'));
const warn = jest.spyOn(console, 'warn').mockImplementation(() => {});
const page = await HomePage();
render(page);
expect(screen.getByTestId('page-copy-data')).toHaveTextContent('null');
expect(screen.getByTestId('cms-state')).toHaveTextContent('ok');
expect(warn).toHaveBeenCalledWith(
expect.stringContaining('getHomePageCopy'),
expect.any(Error),
);
warn.mockRestore();
});
});
+13 -1
View File
@@ -57,7 +57,12 @@ export default async function HomePage() {
* ⇒ 兜底数据在这里起的是**遮蔽**作用,不是降级作用。
*/
const homePageCopy = await getHomePageCopy().catch(() => null);
const homePageCopy = await getHomePageCopy().catch((error: unknown) => {
// 静默 catch 成 null 会让「CMS 读挂了」和「后台没配」在页面上长得一模一样:
// 两者都回落到内置文案,页面照常 200。至少要留下可检索的一行。
console.warn('[home] getHomePageCopy 读取失败,回落到内置文案:', error);
return null;
});
const copyData = (homePageCopy?.data ?? null) as Record<string, unknown> | null;
// 信任信号:后台可覆盖,未配置则回到 constants 里那份带 source 的真实信号
@@ -65,6 +70,12 @@ export default async function HomePage() {
? (copyData!.trustSignals as Record<string, unknown>[])
: [...TRUST_SIGNALS]; // 常量是 as const 只读元组,转成可变数组喂给 Row[]
// 一条内容都没读到 ⇒ 整套落到常量版式(页面仍 200,外观与「后台没内容」不可区分)。
// 把这个状态显式透给视觉层:否则它只能看到一团像素差,无从判断是竞态还是数据退化。
const cmsItemCount =
services.length + solutions.length + cases.length + stats.length + news.length + (heroData ? 1 : 0);
const cmsState: 'ok' | 'empty' = cmsItemCount > 0 ? 'ok' : 'empty';
return (
<HomeContentV16
services={services}
@@ -75,6 +86,7 @@ export default async function HomePage() {
news={news}
pageCopy={copyData}
trustSignals={trustSignals}
cmsState={cmsState}
/>
);
}