feat(qa): DEC-N4 把授权与 basis 门槛下沉成共用闸,既有两处转化区块同闸
只有新成果槽有反伪造门槛,CaseStudiesSection 与 detail-trust-section 没有 —— 同一类主张走两套标准,等于门槛只在新增位置有效。 - 新增 src/lib/constants/case-publish-gate.ts:判据(授权 + ≥1 个 basis==='verified' + 禁词扫描)下沉成一处实现,禁词/口径真源仍是 metrics-basis.ts; results-slot 的 casePublishBlockers 改为委托它 ⇒ 三处消费同一闸,无第二套真源。 - detail-case-studies-section / detail-trust-section 逐条过闸,被封条 console.error 喊出原因, 全封或空 ⇒ return null(L3EmptyFallback 契约不变)。 - dataProofs 不套 verified 硬闸:它已在 weakestBasis + MetricsBasisNote 契约下且自述目标口径, 硬清会误伤全站已标注数字(代码注释里写明理由)。 - 实测门槛下会隐藏的既有条目 = 0 条(seeds 里 caseStudies 全是空数组、 CMS dev.db 11 条内容的 caseStudies 长度全为 0)⇒ 线上转化页无可见变化, 这是前瞻性 fail-closed 加固,不是内容清洗。 - 转红的只有两处旧断言("未授权案例照常渲染"),按测试夹具补 authorized/basis 处理, 并新增负例。⚠ CMS content-types 的 caseStudies schema 还没有这两个字段, 业务要真出案例须先扩 schema —— 登记为残留。 仪器自证:把闸改成恒真(return [])⇒ EXIT=1、20 例转红(覆盖 gate 本体、results-slot 原有用例、 两区块负例、solution-detail 消费页);还原后 EXIT=0。 同批登记 §12.3 DEC-N3(判据从令牌声明移到消费点、8 条归零)与 §12.4(build 的 tsc 比 jest 严)。 读数:tsc EXIT=0、全量 jest 145 套件/1795 例 EXIT=0、check:visual EXIT=0、check:dead EXIT=0。
This commit is contained in:
1 parent
20d5cd0943
commit
2e0099426f
12 files changed
+574
-23
No files matched your search
Regular → Executable
File mode changed.
@@ -0,0 +1,65 @@
|
||||
#!/usr/bin/env bash
|
||||
# §12 收尾验证车道(2026-10-17)
|
||||
#
|
||||
# 为什么写成脚本而不是逐条手敲:本仓反复栽在「取退出码的写法把闸吞掉」——
|
||||
# `cmd | tail` 拿的是 tail 的状态,`A && B; echo $?` 会把 A 的红丢掉。
|
||||
# 这里每条命令都单独重定向到文件、紧跟 `echo $?` 记进汇总,汇总就是证据。
|
||||
#
|
||||
# 用法:
|
||||
# nohup bash docs/acceptance/2026-10-17-final/run-lane.sh > /tmp/12-lane.out 2>&1 &
|
||||
# tail -f /tmp/12-lane-summary.txt
|
||||
#
|
||||
# 前提:先 `npm run build`(本脚本不代跑 build;E2E_TARGET=production 打的是
|
||||
# dist/standalone/server.js,postbuild 须已装配 dist/static + public)。
|
||||
# 端口:车道内所有步骤串行,避免与残留 server 抢 3000(本仓有「静默复用旧服务」的历史坑)。
|
||||
|
||||
set -u
|
||||
cd "$(git rev-parse --show-toplevel)" || exit 1
|
||||
LOGDIR=/tmp/12-lane
|
||||
mkdir -p "$LOGDIR"
|
||||
SUM=/tmp/12-lane-summary.txt
|
||||
: > "$SUM"
|
||||
|
||||
step() {
|
||||
local name="$1"; shift
|
||||
local log="$LOGDIR/$name.log"
|
||||
echo ">>> $name" | tee -a "$SUM"
|
||||
"$@" > "$log" 2>&1
|
||||
local code=$?
|
||||
echo " $name EXIT=$code (log: $log)" | tee -a "$SUM"
|
||||
}
|
||||
|
||||
# 装配自检:产物缺 dist/static 时,axe 会 bgMismatch 报红而 Lighthouse 仍错误 exit 0(§5.34)
|
||||
if [ -d dist/standalone/dist/static ] && [ -d dist/standalone/public ]; then
|
||||
echo " assembly OK (dist/static + public present)" | tee -a "$SUM"
|
||||
else
|
||||
echo " assembly MISSING -> 先 npm run build" | tee -a "$SUM"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
step type-check npm run type-check
|
||||
step lint npm run lint
|
||||
step coverage npm run test:coverage
|
||||
step integration-real npm run test:integration:real
|
||||
step a11y npm run check:a11y
|
||||
step visual-grammar npm run check:visual
|
||||
step accents npm run check:accents
|
||||
step dead npm run check:dead
|
||||
step motion npm run check:motion
|
||||
|
||||
# GA4 那 16 例只在 production 目标下真断言:dev 下 GoogleAnalytics.tsx 提前 return null,
|
||||
# 用例内 test.skip 触发 ⇒ 记为 skipped 而不是 passed(§5 表格的口径)。
|
||||
step ga4-prod bash -c 'cd e2e && E2E_TARGET=production npx playwright test ga4-event-tracking.spec.ts --project=chromium --project=chromium-mobile --project=firefox --project=webkit'
|
||||
|
||||
step e2e-fast npm run test:e2e:fast
|
||||
step security-headers npm run test:security:headers
|
||||
step axe-routes npm run check:axe:routes
|
||||
step axe npm run check:axe
|
||||
step lighthouse npm run lighthouse
|
||||
|
||||
# 视觉只读比对(不写基线)。AUTH-VISUAL 的写入是单独动作,不在本车道内。
|
||||
step visual-readonly bash -c 'cd e2e && npx playwright test visual-regression.spec.ts --update-snapshots=none'
|
||||
|
||||
echo "=== DONE ===" | tee -a "$SUM"
|
||||
grep -c 'EXIT=0' "$SUM" | sed 's/^/green_steps=/' | tee -a "$SUM"
|
||||
grep -c 'EXIT=[1-9]' "$SUM" | sed 's/^/nonzero_steps=/' | tee -a "$SUM"
|
||||
@@ -685,3 +685,69 @@ D-2 的回归守卫:`solution-detail-content-v3.test.tsx` 新增断言,且**
|
||||
- 阈值口径未动:`performance ≥ 0.9`、`accessibility/best-practices/seo ≥ 0.9`、
|
||||
`LCP ≤ 3000ms`(`config/test/lighthouserc.json`),本轮实测最低 perf 98(/contact)、
|
||||
最大 LCP 1101ms(/contact),余量分别 8 点与 1899ms。
|
||||
|
||||
---
|
||||
|
||||
## §12 2026-10-17 · §11.4 待拍批的落地轮(DEC-N1…N6 + AUTH-VISUAL)
|
||||
|
||||
用户裁定「需要决策就采用推荐方案」,本批把 §11.4/§11.5 登记的每一条按推荐项执行到位。
|
||||
分支仍是 `worktree-ui-grammar-two-axis`,起点 `0ae765af`。
|
||||
|
||||
### 12.1 DEC-N5 · 后台发布/更新/删除真正让前台 ISR 失效(`f3e66f7d`)
|
||||
|
||||
**根因不是算错,是没有调用方**:`modelCode → paths` 的推导长在 `/api/cms/revalidate` 的路由体里,
|
||||
所以它只能被外部 HTTP 调用触发。8 个页面注释那句「CMS 发布/更新时通过 `/api/cms/revalidate`
|
||||
主动刷新」在没有任何生产调用方的日子里是假的 —— `s-maxage=3600` 下最长 1 小时前台仍端出
|
||||
已删或过期内容,且没有任何门禁会红。
|
||||
|
||||
| 处置 | 内容 |
|
||||
|---|---|
|
||||
| 提纯 | 新增 `src/lib/cms/revalidation.ts`:`pathsForModel` / `tagsForModel` / `planRevalidation` 是**不碰 `next/cache` 的纯函数**,副作用收在 `applyRevalidation`(严格,供路由用)与 `revalidateContent`(尽力而为,供变更链用)。依据 §5.30「安全抽象必须可导入」 |
|
||||
| 接线 | `items` 的 POST/PUT/DELETE、`workflow` 的 submit/approve/reject/archive、`zones` 的写与删,全部走同一份推导。判据按 `status`(草稿不进前台读取路径);**slug 变更时旧地址一并刷** |
|
||||
| 时序 | 失效放在数据与审计**都落库之后**:刷缓存失败不该把一次成功的写入连带变成 500(那比旧快照更糟 —— 操作者以为没保存,其实已改) |
|
||||
| 不静默 | `revalidateContent` 逐条 try,失败以 `[revalidation-failed]` 打日志并在 `failed` 字段回报;`applyRevalidation` 仍冒泡,保持 `/api/cms/revalidate` 的 500 语义 |
|
||||
|
||||
**证据**:`revalidation.test.ts` 18 例(纯映射对账真实 `CONTENT_TYPE_CONFIGS`,不抄字面路径)+
|
||||
`cache-invalidation.test.ts` 7 例(断言的是「调用点存在」本身,正是当初缺的东西)。
|
||||
定向 16 套件 **193 passed / EXIT=0**;
|
||||
**负对照**:把 workflow 的调用点替换成注释 ⇒ `MUTANT_EXIT=1`、4 例转红(approve + submit/reject/archive),
|
||||
还原后 `EXIT=0` 且文件逐字节复原。lint 定向 0 error。
|
||||
|
||||
### 12.2 DEC-N2 · 台账声明被证伪:`staggerDelay` 默认值从来不是 0.15
|
||||
|
||||
ADR-0008 §87-1 与 §11.4 写的是「`StaggerReveal` 默认 `staggerDelay = 0.15`,与 ADR-0004 决策三
|
||||
「子元素 stagger 30–60ms」不符」。实测三条把它推翻:
|
||||
|
||||
1. `src/components/ui/scroll-reveal.tsx:113` 现行默认是 **`0.05`(= 50ms,落在 30–60ms 内)**,且工作树干净(不是我改的)。
|
||||
2. `git log -S'staggerDelay = 0.15' -- src/components/ui/scroll-reveal.tsx` **无任何提交** —— 那串字面量在该文件历史里没存在过。
|
||||
3. 全站 18 个显式传参只有 `staggerDelay={0.05}`(16 处)与 `{0.06}`(2 处),没有任何 0.15。
|
||||
|
||||
⇒ **DEC-N2 无需执行**,它和 §11.6 那条「axe 哨兵抄字面量早已过期」是同一类缺陷:
|
||||
**台账里的数是从前一轮的叙述里抄来的,而不是从当场的仪器里取的**。
|
||||
ADR-0008 §87-1 的同一句话需要一并更正(该文件本轮由 accent 子任务独占改写,故在此登记而非并发改)。
|
||||
|
||||
### 12.3 DEC-N3 · `check:motion` 的 8 条基线红归零,判据从「令牌声明」移到「消费点」(DEC-N3,提交见 `git log`)
|
||||
|
||||
先量再判,没有直接把红线挪低:
|
||||
|
||||
| 子项 | 读数与处置 |
|
||||
|---|---|
|
||||
| 6 处写死 cubic-bezier | 全部收进既有令牌 `--ease-ink` `[0.22,1,0.36,1]`(`template.tsx`、`page-transition.tsx`、`brand-visuals.tsx`),各处注释标 `CONTEXT.md:77` 出处;两曲线原本都落在 280ms 入场档,没有不可替代的物理理由 |
|
||||
| `opacity 0.6s` 裸时长 | 改 `var(--transition-slower)`(globals.css:1486) |
|
||||
| `--transition-gentle = 1000ms` | **实测在 `src/` 零消费**(仅 `tailwind.config.js:220` 的 `duration-gentle` 映射,无一处使用)⇒ 入场/循环/其他 = 0/0/0。原「令牌声明一律 ≤700ms」是把 CONTEXT.md:82 的**入场**红线读成了对调色板的禁令;现口径改为**消费点判红**:非 infinite 的 `transition/animation` 声明(含经 `var()` 解析出的时长)>700ms 必红,`infinite` 循环环境动效维持既有豁免 |
|
||||
|
||||
**仪器自证(负对照,真树注入 → 还原)**:塞回 `[0.16,1,0.3,1]` + `opacity 900ms` 裸字面量 +
|
||||
`opacity var(--transition-gentle)`(非循环消费点)⇒ `npm run check:motion` **EXIT=1**,
|
||||
4 条红分别命中 `easing-palette`×1、`css-transition-token`×1、`entrance-cap`×2;
|
||||
还原后 **EXIT=0**、违规 0。⇒ 改口径没有把闸调瞎:超上限档位一旦接入非循环声明就判红。
|
||||
|
||||
读数:`check:motion` EXIT=0(0 违反)、`check:motion:test` EXIT=0(21/21)、`tsc --noEmit` EXIT=0。
|
||||
|
||||
### 12.4 DEC-N5 的连带教训:`next build` 的 TypeScript 阶段比 jest 严
|
||||
|
||||
新增的 `cache-invalidation.test.ts` 在 jest 里 25 例全绿,却把 `npm run build` 打成
|
||||
`error TS2554: Expected 2 arguments, but got 1` —— 原因是测试夹具 `req(url, body)` 的 `body`
|
||||
写成必填,而 `DELETE`/`PUT` 的调用不带 body。**jest 里少传一个参数只会让 `json()` 抛错、
|
||||
又被路由的 catch 吞成 500 之外的路径**,所以测试毫无症状。已把 `body` 改可选并留下注释。
|
||||
⇒ 口径补充:**改 `src/**` 下的测试后必须让 `npm run build` 过一遍 tsc**,
|
||||
`npm run type-check` 与 build 的 tsc 覆盖同一份 tsconfig,但只有 build 会被 CI 跑到。
|
||||
@@ -122,6 +122,11 @@ describe('SolutionDetailContentV3 - L3 信任层三档策略', () => {
|
||||
challenge: '生产数据孤岛',
|
||||
solution: '部署 MES 与 BI',
|
||||
result: '生产效率提升 40%',
|
||||
// DEC-N4 同闸(2026-10-19):CaseStudiesSection 现与首页成果槽共用
|
||||
// case-publish-gate,条目须带授权 + verified 口径才渲染。
|
||||
// 下面两条负例断言的就是「不补这两维 ⇒ 本节不出」。
|
||||
verified: true,
|
||||
metrics: [{ value: '40%', label: '生产效率提升', basis: 'verified' }],
|
||||
},
|
||||
] as Solution['caseStudies'],
|
||||
};
|
||||
@@ -131,6 +136,27 @@ describe('SolutionDetailContentV3 - L3 信任层三档策略', () => {
|
||||
expect(screen.getByText('某制造集团')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('DEC-N4 同闸:未授权 / 缺已验证口径的案例条目不再渲染为「同行业落地案例」', () => {
|
||||
const withUngatedCases: Solution = {
|
||||
...baseSolution,
|
||||
caseStudies: [
|
||||
{
|
||||
client: '某制造集团',
|
||||
industry: '制造业',
|
||||
challenge: '生产数据孤岛',
|
||||
solution: '部署 MES 与 BI',
|
||||
result: '生产效率提升 40%',
|
||||
},
|
||||
] as Solution['caseStudies'],
|
||||
};
|
||||
const spy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
||||
render(<SolutionDetailContentV3 solution={withUngatedCases} />);
|
||||
|
||||
expect(screen.queryByText('同行业落地案例')).not.toBeInTheDocument();
|
||||
expect(screen.queryByText('某制造集团')).not.toBeInTheDocument();
|
||||
spy.mockRestore();
|
||||
});
|
||||
|
||||
it('renders certifications when data is available', () => {
|
||||
const withCerts: Solution = {
|
||||
...baseSolution,
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
/**
|
||||
* CaseStudiesSection 反伪造门槛用例(DEC-N4 同闸,2026-10-19)。
|
||||
*
|
||||
* 门槛机制真源:lib/constants/case-publish-gate(与首页 ResultsSlot 同一实现)。
|
||||
* 这里验证的是「本区块确实接上了那道闸」:三条判据必须各自可红——
|
||||
* 授权 + verified 口径 → 渲染;缺 basis → 不渲染;未授权 → 不渲染。
|
||||
* 若守卫被改成恒真,"不渲染"两条断言必须转红(变异验证已跑过,见台账口径)。
|
||||
*/
|
||||
import { describe, it, expect, jest } from '@jest/globals';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import '@testing-library/jest-dom';
|
||||
|
||||
jest.mock('@/components/ui/scroll-reveal', () => ({
|
||||
ScrollReveal: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
|
||||
StaggerReveal: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
|
||||
}));
|
||||
jest.mock('@/components/ui/page-decoration', () => ({
|
||||
SectionLabel: ({ children }: { children: React.ReactNode }) => <span>{children}</span>,
|
||||
}));
|
||||
|
||||
import { CaseStudiesSection, type CaseStudyItem } from './detail-case-studies-section';
|
||||
|
||||
/** 一条"够格"的卡片基线 —— 负例都在它身上破坏一项 */
|
||||
const gated: CaseStudyItem = {
|
||||
client: '华辰制造',
|
||||
industry: '制造业',
|
||||
challenge: '库存不透明',
|
||||
solution: '统一库存中台',
|
||||
result: '库存周转下降 38%',
|
||||
authorized: true,
|
||||
basis: 'verified',
|
||||
};
|
||||
|
||||
describe('CaseStudiesSection —— DEC-N4 同闸', () => {
|
||||
it('授权 + verified 口径 ⇒ 渲染卡片与成果主张(正控制)', () => {
|
||||
render(<CaseStudiesSection caseStudies={[gated]} />);
|
||||
expect(screen.getByTestId('case-studies-section')).toBeInTheDocument();
|
||||
expect(screen.getByText('华辰制造')).toBeInTheDocument();
|
||||
expect(screen.getByText('库存周转下降 38%')).toBeInTheDocument();
|
||||
expect(screen.getByText('核心成果')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('缺 basis(只有授权)⇒ 整段不渲染,且原因被 console.error 喊出来', () => {
|
||||
const spy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
||||
const { container } = render(
|
||||
<CaseStudiesSection caseStudies={[{ ...gated, basis: undefined }]} />,
|
||||
);
|
||||
expect(container.innerHTML).toBe('');
|
||||
expect(spy).toHaveBeenCalledWith(expect.stringMatching(/basis === "verified"/));
|
||||
spy.mockRestore();
|
||||
});
|
||||
|
||||
it('未授权(口径已 verified)⇒ 整段不渲染,喊出「未授权公开」', () => {
|
||||
const spy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
||||
const { container } = render(
|
||||
<CaseStudiesSection caseStudies={[{ ...gated, authorized: false }]} />,
|
||||
);
|
||||
expect(container.innerHTML).toBe('');
|
||||
expect(spy).toHaveBeenCalledWith(expect.stringMatching(/未授权公开/));
|
||||
spy.mockRestore();
|
||||
});
|
||||
|
||||
it('basis 非法值(如 "已验证")按最弱口径回落 target ⇒ 照样被闸住', () => {
|
||||
const spy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
||||
const { container } = render(
|
||||
<CaseStudiesSection caseStudies={[{ ...gated, basis: '已验证' as never }]} />,
|
||||
);
|
||||
expect(container.innerHTML).toBe('');
|
||||
expect(spy).toHaveBeenCalledWith(expect.stringMatching(/basis === "verified"/));
|
||||
spy.mockRestore();
|
||||
});
|
||||
|
||||
it('好条目照常渲染、坏条目单独隐藏(混合列表逐条过闸,不整段连坐)', () => {
|
||||
const spy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
||||
render(
|
||||
<CaseStudiesSection
|
||||
caseStudies={[{ ...gated, client: '未授权公司', authorized: false }, gated]}
|
||||
heading="同行业落地案例"
|
||||
/>,
|
||||
);
|
||||
expect(screen.getByText('华辰制造')).toBeInTheDocument();
|
||||
expect(screen.queryByText('未授权公司')).not.toBeInTheDocument();
|
||||
expect(spy).toHaveBeenCalledTimes(1);
|
||||
spy.mockRestore();
|
||||
});
|
||||
|
||||
it('文案命中虚构佐证禁词 ⇒ 即便授权与口径齐 also 被闸住', () => {
|
||||
const spy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
||||
const { container } = render(
|
||||
<CaseStudiesSection
|
||||
caseStudies={[{ ...gated, result: '库存周转下降 38%,源自真实客户案例' }]}
|
||||
/>,
|
||||
);
|
||||
expect(container.innerHTML).toBe('');
|
||||
expect(spy).toHaveBeenCalledWith(expect.stringMatching(/禁词/));
|
||||
spy.mockRestore();
|
||||
});
|
||||
|
||||
it('空入参维持原契约:return null(L3EmptyFallback 接管)', () => {
|
||||
const { container } = render(<CaseStudiesSection caseStudies={[]} />);
|
||||
expect(container.innerHTML).toBe('');
|
||||
});
|
||||
});
|
||||
@@ -16,10 +16,14 @@
|
||||
* 放外层 div 时包装层成为 grid 唯一子项,卡片会堆成单列(commit 3091035 踩坑记录)。
|
||||
*
|
||||
* 数据闸门:caseStudies 为空时 return null(L3EmptyFallback 接管兜底渲染)。
|
||||
* DEC-N4 同闸(2026-10-19):非空条目还须过 lib/constants/case-publish-gate
|
||||
* (授权 + basis=verified + 禁词),与首页 ResultsSlot 同一判据实现。
|
||||
*/
|
||||
|
||||
import { ScrollReveal, StaggerReveal } from '@/components/ui/scroll-reveal';
|
||||
import { SectionLabel } from '@/components/ui/page-decoration';
|
||||
import { gateCaseItems } from '@/lib/constants/case-publish-gate';
|
||||
import type { MetricBasis } from '@/lib/constants/metrics-basis';
|
||||
|
||||
/** 三处数据源(cases.ts / services.ts / products.ts)的结构公共子集 */
|
||||
export interface CaseStudyItem {
|
||||
@@ -28,6 +32,14 @@ export interface CaseStudyItem {
|
||||
challenge: string;
|
||||
solution?: string;
|
||||
result: string;
|
||||
/**
|
||||
* DEC-N4 同闸(2026-10-19):卡片型案例必须声明「客户授权对外展示」+
|
||||
* 「成果口径 verified」才会渲染,判据复用 lib/constants/case-publish-gate
|
||||
* (与首页成果槽同一实现,非第二套真源)。两字段可选 ⇒ 既有未补口径的
|
||||
* 条目一律被闸住,这正是 fail-closed 的应有行为。
|
||||
*/
|
||||
authorized?: boolean;
|
||||
basis?: MetricBasis;
|
||||
}
|
||||
|
||||
interface CaseStudiesSectionProps {
|
||||
@@ -43,10 +55,23 @@ export function CaseStudiesSection({
|
||||
heading = '客户案例',
|
||||
id,
|
||||
}: CaseStudiesSectionProps) {
|
||||
if (!caseStudies || caseStudies.length === 0) return null;
|
||||
/**
|
||||
* 数据闸门分两层(DEC-N4 同闸改造):
|
||||
* 1. 原契约:入参为空 ⇒ return null,由 L3EmptyFallback 兜底;
|
||||
* 2. 新契约:非空条目先过 case-publish-gate,未授权 / 缺 verified 口径 /
|
||||
* 命中虚构佐证禁词的条目**不渲染**,降级原因逐条 console.error 喊出来
|
||||
* (静默吞掉等于掩饰,同 ResultsSlot 的纪律)。全部被闸住 ⇒ 整段 null。
|
||||
*/
|
||||
const { publishable, blocked } = gateCaseItems(caseStudies ?? []);
|
||||
for (const { item, blockers } of blocked) {
|
||||
console.error(
|
||||
`[CaseStudiesSection] 案例「${item.client}」未通过反伪造门槛,已隐藏:${blockers.join(';')}`,
|
||||
);
|
||||
}
|
||||
if (publishable.length === 0) return null;
|
||||
|
||||
return (
|
||||
<section id={id} className="relative py-20 sm:py-28 md:py-32 lg:py-40 overflow-hidden bg-bg-primary">
|
||||
<section id={id} data-testid="case-studies-section" className="relative py-20 sm:py-28 md:py-32 lg:py-40 overflow-hidden bg-bg-primary">
|
||||
<div className="absolute top-0 left-0 right-0 h-px bg-border-primary" />
|
||||
<div className="absolute bottom-0 left-0 right-0 h-px bg-border-primary" />
|
||||
|
||||
@@ -72,7 +97,7 @@ export function CaseStudiesSection({
|
||||
delayChildren={0.05}
|
||||
className="grid md:grid-cols-2 lg:grid-cols-3 gap-px bg-border-primary"
|
||||
>
|
||||
{caseStudies.map((study) => (
|
||||
{publishable.map((study) => (
|
||||
<div
|
||||
key={study.client}
|
||||
className="group relative block h-full overflow-hidden bg-bg-primary transition-all duration-normal hover:bg-bg-secondary"
|
||||
|
||||
@@ -8,6 +8,7 @@ import { CertificationList } from './detail-certification';
|
||||
import type { CaseStudy, DataProof, Certification } from '@/lib/constants/products';
|
||||
import { MetricsBasisNote } from '@/components/ui/metrics-basis-note';
|
||||
import { weakestBasis } from '@/lib/constants/metrics-basis';
|
||||
import { gateCaseItems } from '@/lib/constants/case-publish-gate';
|
||||
|
||||
interface DetailTrustSectionProps {
|
||||
caseStudies?: CaseStudy[];
|
||||
@@ -84,7 +85,24 @@ export function DetailTrustSection({
|
||||
certifications = [],
|
||||
accentColor: _accentColor = '#C41E3A',
|
||||
}: DetailTrustSectionProps) {
|
||||
const hasContent = caseStudies.length > 0 || dataProofs.length > 0 || certifications.length > 0;
|
||||
/**
|
||||
* DEC-N4 同闸(2026-10-19):客户案例块必须过与首页 ResultsSlot **同一实现**的
|
||||
* case-publish-gate(授权 + basis=verified + 虚构佐证禁词),未过闸条目不渲染、
|
||||
* 原因逐条 console.error(不静默)。
|
||||
* 边界说明:dataProofs 块不在本次补闸范围——它早已在 metrics-basis 契约之下
|
||||
* (每条声明 basis、整组取 weakestBasis 挂 MetricsBasisNote,且标题自述「目标口径」),
|
||||
* 缺的只是"授权"维度,而目标值本身不声称客户授权。若对它套 verified 硬闸,
|
||||
* 会把全站已按规标注的目标数字整体清空,那不是 DEC-N4 的裁定内容。
|
||||
*/
|
||||
const { publishable: publishableCases, blocked: blockedCases } = gateCaseItems(caseStudies);
|
||||
for (const { item, blockers } of blockedCases) {
|
||||
console.error(
|
||||
`[DetailTrustSection] 案例「${item.client}」未通过反伪造门槛,已隐藏:${blockers.join(';')}`,
|
||||
);
|
||||
}
|
||||
|
||||
const hasContent =
|
||||
publishableCases.length > 0 || dataProofs.length > 0 || certifications.length > 0;
|
||||
if (!hasContent) return null;
|
||||
|
||||
return (
|
||||
@@ -139,8 +157,8 @@ export function DetailTrustSection({
|
||||
</div>
|
||||
)}
|
||||
|
||||
{caseStudies.length > 0 && (
|
||||
<div className="mb-16">
|
||||
{publishableCases.length > 0 && (
|
||||
<div className="mb-16" data-testid="detail-trust-case-studies">
|
||||
<motion.div
|
||||
initial={{ opacity: 0, y: 24 }}
|
||||
whileInView={{ opacity: 1, y: 0 }}
|
||||
|
||||
@@ -208,7 +208,8 @@ const mockProduct = {
|
||||
heroThemeId: 'erp',
|
||||
bundle: 'enterprise' as const,
|
||||
caseStudies: [
|
||||
{ client: '某制造企业', industry: '制造业', challenge: '库存管理混乱', solution: '实施ERP系统', result: '库存周转率提升200%' },
|
||||
// DEC-N4 同闸:卡片型案例必须带授权 + basis=verified 才渲染(门槛见 case-publish-gate)
|
||||
{ client: '某制造企业', industry: '制造业', challenge: '库存管理混乱', solution: '实施ERP系统', result: '库存周转率提升200%', authorized: true, basis: 'verified' as const },
|
||||
],
|
||||
dataProofs: [
|
||||
{ metric: '效率提升', value: '300%', description: '业务流程效率提升' },
|
||||
@@ -492,6 +493,62 @@ describe('DetailTrustSection', () => {
|
||||
expect(screen.getByTestId('case-client')).toHaveTextContent('某制造企业');
|
||||
});
|
||||
|
||||
// ── DEC-N4 同闸:DetailTrustSection 案例块必须过与首页成果槽同一门槛 ──
|
||||
describe('案例块反伪造门槛(DEC-N4 同闸)', () => {
|
||||
const gated = mockProduct.caseStudies[0]!;
|
||||
|
||||
it('缺 basis(即便已授权)⇒ 成果主张整块不渲染,且原因被喊出来', async () => {
|
||||
const { DetailTrustSection } = await import('./detail-trust-section');
|
||||
const spy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
||||
const { container } = render(
|
||||
<DetailTrustSection
|
||||
caseStudies={[{ ...gated, basis: undefined }]}
|
||||
certifications={mockProduct.certifications}
|
||||
/>
|
||||
);
|
||||
expect(screen.queryByText('他们已经实现了转型突破')).not.toBeInTheDocument();
|
||||
expect(screen.queryByTestId('case-study-card')).not.toBeInTheDocument();
|
||||
expect(container.querySelector('[data-testid="detail-trust-case-studies"]')).not.toBeInTheDocument();
|
||||
expect(spy).toHaveBeenCalledWith(expect.stringMatching(/basis === "verified"/));
|
||||
spy.mockRestore();
|
||||
});
|
||||
|
||||
it('未授权(authorized 不为 true,即便口径已 verified)⇒ 不渲染', async () => {
|
||||
const { DetailTrustSection } = await import('./detail-trust-section');
|
||||
const spy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
||||
render(
|
||||
<DetailTrustSection
|
||||
caseStudies={[{ ...gated, authorized: false }]}
|
||||
certifications={mockProduct.certifications}
|
||||
/>
|
||||
);
|
||||
expect(screen.queryByText('他们已经实现了转型突破')).not.toBeInTheDocument();
|
||||
expect(spy).toHaveBeenCalledWith(expect.stringMatching(/未授权公开/));
|
||||
spy.mockRestore();
|
||||
});
|
||||
|
||||
it('授权 + verified 口径 ⇒ 渲染(正控制,防"闸恒真/恒假"两种假绿)', async () => {
|
||||
const { DetailTrustSection } = await import('./detail-trust-section');
|
||||
render(<DetailTrustSection caseStudies={[gated]} />);
|
||||
expect(screen.getByText('他们已经实现了转型突破')).toBeInTheDocument();
|
||||
expect(screen.getByTestId('detail-trust-case-studies')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('非 verified 口径(target / team-history)同样被闸住——闸要能拒绝"数字真、出处假"', async () => {
|
||||
const { DetailTrustSection } = await import('./detail-trust-section');
|
||||
const spy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
||||
render(
|
||||
<DetailTrustSection
|
||||
caseStudies={[{ ...gated, basis: 'team-history' }, { ...gated, client: '另一企业', basis: 'target' }]}
|
||||
/>
|
||||
);
|
||||
expect(screen.queryByText('他们已经实现了转型突破')).not.toBeInTheDocument();
|
||||
expect(screen.queryByTestId('case-study-card')).not.toBeInTheDocument();
|
||||
expect(spy).toHaveBeenCalledWith(expect.stringMatching(/basis === "verified"/));
|
||||
spy.mockRestore();
|
||||
});
|
||||
});
|
||||
|
||||
it('should render certifications', async () => {
|
||||
const { DetailTrustSection } = await import('./detail-trust-section');
|
||||
render(
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
import { ScrollReveal } from '@/components/ui/scroll-reveal';
|
||||
import { StaticLink } from '@/components/ui/static-link';
|
||||
import { SectionLabel } from '@/components/ui/page-decoration';
|
||||
import { FORBIDDEN_PROOF_PHRASES } from '@/lib/constants/metrics-basis';
|
||||
import { casePublishGateBlockers } from '@/lib/constants/case-publish-gate';
|
||||
import type { CaseStudy } from '@/lib/constants/cases';
|
||||
import { ArrowRight } from 'lucide-react';
|
||||
|
||||
@@ -40,23 +40,19 @@ export type ResultsSlotState =
|
||||
/**
|
||||
* 规则 1 + 2 的判据。导出是为了让单测能直接喂"不该通过"的 fixture —— 判据必须可失败。
|
||||
* 返回原因数组(空 = 可发布),不抛:抛与不抛由调用方决定语义。
|
||||
*
|
||||
* 实现已下沉到 lib/constants/case-publish-gate.ts(DEC-N4 同闸):成果槽、
|
||||
* CaseStudiesSection、DetailTrustSection 消费同一判据,禁词与口径真源仍是 metrics-basis。
|
||||
* 这里保留同名导出,是因为它是本组件的公开契约(单测直接喂 fixture),不是第二套实现。
|
||||
*/
|
||||
export function casePublishBlockers(c: CaseStudy): string[] {
|
||||
const problems: string[] = [];
|
||||
|
||||
if (c.verified !== true) problems.push('verified 不为 true(客户未授权公开)');
|
||||
|
||||
const author = c.testimonial?.author?.trim();
|
||||
if (!author) problems.push('缺少可署名的客户证言作者');
|
||||
|
||||
const hasVerifiedMetric = (c.metrics ?? []).some((m) => m.basis === 'verified');
|
||||
if (!hasVerifiedMetric) problems.push('没有任何一个指标 basis === "verified"');
|
||||
|
||||
const haystack = [c.title, c.subtitle, c.result, c.testimonial?.quote ?? ''].join(' ');
|
||||
const hit = FORBIDDEN_PROOF_PHRASES.find((p) => haystack.includes(p));
|
||||
if (hit) problems.push(`文案命中虚构佐证禁词「${hit}」`);
|
||||
|
||||
return problems;
|
||||
return casePublishGateBlockers({
|
||||
authorized: c.verified,
|
||||
bases: (c.metrics ?? []).map((m) => m.basis),
|
||||
testimonialAuthor: c.testimonial?.author,
|
||||
requireSignableAuthor: true,
|
||||
copy: [c.title, c.subtitle, c.result, c.testimonial?.quote ?? ''],
|
||||
});
|
||||
}
|
||||
|
||||
/** 兼容旧调用名:抛错版本,留给构建期/测试期使用。组件渲染路径**不**用它。 */
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
/**
|
||||
* case-publish-gate 单测 —— DEC-N4 同闸的机制层判据。
|
||||
* 三处消费方(ResultsSlot / CaseStudiesSection / DetailTrustSection)共用的就是这里,
|
||||
* 所以每条判据都必须"可失败":守卫恒真时,本文件的负例与两处区块的负例一起转红。
|
||||
*/
|
||||
import { describe, it, expect } from '@jest/globals';
|
||||
import {
|
||||
casePublishGateBlockers,
|
||||
gateCaseItems,
|
||||
type GateableCaseItem,
|
||||
} from './case-publish-gate';
|
||||
|
||||
const clean = {
|
||||
authorized: true,
|
||||
bases: ['verified'],
|
||||
copy: ['某客户', '库存周转下降 38%'],
|
||||
} as const;
|
||||
|
||||
describe('casePublishGateBlockers', () => {
|
||||
it('正控制:授权 + 已验证口径 + 干净文案 ⇒ 无阻塞项', () => {
|
||||
expect(casePublishGateBlockers({ ...clean })).toEqual([]);
|
||||
});
|
||||
|
||||
it('未授权 ⇒ 报「未授权公开」(undefined / false 同罪)', () => {
|
||||
expect(casePublishGateBlockers({ ...clean, authorized: undefined })).toEqual([
|
||||
expect.stringMatching(/未授权公开/),
|
||||
]);
|
||||
expect(casePublishGateBlockers({ ...clean, authorized: false })).toEqual([
|
||||
expect.stringMatching(/未授权公开/),
|
||||
]);
|
||||
});
|
||||
|
||||
it('无任何 verified 口径 ⇒ 报 basis 阻塞项', () => {
|
||||
expect(casePublishGateBlockers({ ...clean, bases: ['target', 'team-history'] })).toEqual([
|
||||
expect.stringMatching(/basis === "verified"/),
|
||||
]);
|
||||
expect(casePublishGateBlockers({ ...clean, bases: [] })).toEqual([
|
||||
expect.stringMatching(/basis === "verified"/),
|
||||
]);
|
||||
});
|
||||
|
||||
it('requireSignableAuthor 时缺作者 ⇒ 报「署名」;不要求时不报(卡片形状没有证言)', () => {
|
||||
expect(
|
||||
casePublishGateBlockers({ ...clean, requireSignableAuthor: true, testimonialAuthor: ' ' }),
|
||||
).toEqual([expect.stringMatching(/署名/)]);
|
||||
expect(casePublishGateBlockers({ ...clean, requireSignableAuthor: true })).toEqual([
|
||||
expect.stringMatching(/署名/),
|
||||
]);
|
||||
expect(casePublishGateBlockers(clean)).toEqual([]);
|
||||
});
|
||||
|
||||
it('文案命中禁词 ⇒ 报「禁词」,且多问题一次报齐(不玩"修一个撞下一个")', () => {
|
||||
expect(
|
||||
casePublishGateBlockers({ ...clean, copy: ['源自真实客户案例的成效'] }),
|
||||
).toEqual([expect.stringMatching(/禁词/)]);
|
||||
expect(
|
||||
casePublishGateBlockers({
|
||||
authorized: false,
|
||||
bases: ['target'],
|
||||
copy: ['经过实战验证'],
|
||||
}),
|
||||
).toHaveLength(3);
|
||||
});
|
||||
});
|
||||
|
||||
describe('gateCaseItems', () => {
|
||||
const good: GateableCaseItem = { client: 'A', result: 'x', authorized: true, basis: 'verified' };
|
||||
const noBasis: GateableCaseItem = { client: 'B', result: 'y', authorized: true };
|
||||
const noAuth: GateableCaseItem = { client: 'C', result: 'z', basis: 'verified' };
|
||||
|
||||
it('逐条分区:可发布的渲染、被封的带原因返回', () => {
|
||||
const { publishable, blocked } = gateCaseItems([good, noBasis, noAuth]);
|
||||
expect(publishable.map((i) => i.client)).toEqual(['A']);
|
||||
expect(blocked.map((b) => b.item.client)).toEqual(['B', 'C']);
|
||||
expect(blocked[0]!.blockers.join()).toMatch(/basis/);
|
||||
expect(blocked[1]!.blockers.join()).toMatch(/未授权公开/);
|
||||
});
|
||||
|
||||
it('cases.ts 形状(verified + metrics[].basis)与卡片形状走同一条归一判据', () => {
|
||||
const asLegacy: GateableCaseItem = {
|
||||
client: 'D',
|
||||
result: 'w',
|
||||
verified: true,
|
||||
metrics: [{ basis: 'verified' }],
|
||||
};
|
||||
const { publishable, blocked } = gateCaseItems([asLegacy]);
|
||||
expect(publishable).toHaveLength(1);
|
||||
expect(blocked).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,98 @@
|
||||
/**
|
||||
* CasePublishGate —— 「数字/成果类文案」反伪造门槛的唯一机制真源。
|
||||
*
|
||||
* 来源:results-slot.tsx 最早在首页成果槽建立这条门槛(客户授权 + 可署名证言 +
|
||||
* 至少一个 basis === 'verified' 的指标 + 文案不命中虚构佐证禁词)。收尾台账 DEC-N4
|
||||
* 指出既有 CaseStudiesSection / detail-trust-section 没有同闸,用户裁定**同闸**。
|
||||
* 于是把判据从组件里下沉到本模块:三处消费同一实现,禁词与口径枚举的真源仍是
|
||||
* metrics-basis.ts —— 本文件不新增任何枚举或文案口径,只做门槛组合。
|
||||
*
|
||||
* fail-closed 约定:授权字段缺失、basis 缺失/非法(resolveMetricBasis 回落 target)
|
||||
* 一律不通过。老数据没有这两个字段 ⇒ 整条被闸住,这是判据应有的行为,
|
||||
* 不是回归;业务要让某条案例出镜,必须先在数据源补上真实授权与已验证口径。
|
||||
*/
|
||||
import type { MetricBasis } from './metrics-basis';
|
||||
import { FORBIDDEN_PROOF_PHRASES, resolveMetricBasis } from './metrics-basis';
|
||||
|
||||
export interface CasePublishGateInput {
|
||||
/** 客户是否授权对外展示(成果槽的 `verified` 字段映射到这里) */
|
||||
authorized?: boolean | null;
|
||||
/** 本条涉及的数字/成果口径;须至少一个解析为 verified */
|
||||
bases?: readonly (MetricBasis | string | null | undefined)[];
|
||||
/** 可署名证言作者;requireSignableAuthor 为 true 时缺失即拒绝(成果槽规则 1) */
|
||||
testimonialAuthor?: string | null;
|
||||
requireSignableAuthor?: boolean;
|
||||
/** 该条全部用户可见文案,拼接后做禁词扫描(规则 2) */
|
||||
copy?: readonly (string | null | undefined)[];
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回不通过原因列表(空数组 = 可发布)。与 results-slot 原实现逐字同文案,
|
||||
* 因为既有断言匹配「未授权公开 / 署名 / basis === "verified" / 禁词」这些子串——
|
||||
* 门槛下沉不得改变判据语义,只改变它住在哪个文件。
|
||||
*/
|
||||
export function casePublishGateBlockers(input: CasePublishGateInput): string[] {
|
||||
const problems: string[] = [];
|
||||
|
||||
if (input.authorized !== true) problems.push('客户未授权公开(授权字段不为 true)');
|
||||
|
||||
if (input.requireSignableAuthor) {
|
||||
const author = (input.testimonialAuthor ?? '').trim();
|
||||
if (!author) problems.push('缺少可署名的客户证言作者');
|
||||
}
|
||||
|
||||
const bases = input.bases ?? [];
|
||||
if (!bases.some((b) => resolveMetricBasis(b) === 'verified')) {
|
||||
problems.push('没有任何一个指标 basis === "verified"');
|
||||
}
|
||||
|
||||
const haystack = (input.copy ?? []).filter(Boolean).join(' ');
|
||||
const hit = FORBIDDEN_PROOF_PHRASES.find((p) => haystack.includes(p));
|
||||
if (hit) problems.push(`文案命中虚构佐证禁词「${hit}」`);
|
||||
|
||||
return problems;
|
||||
}
|
||||
|
||||
/**
|
||||
* 卡片型案例条目(CaseStudiesSection / DetailTrustSection 的数据形状)
|
||||
* 进闸的最小契约。字段全部可选:既有数据源(seeds / CMS)没有授权与口径字段,
|
||||
* 缺字段按 fail-closed 处理,不为此改动任何既有类型或 seed。
|
||||
*
|
||||
* 兼容说明:cases.ts 的完整 CaseStudy 同时塞得进这个契约——它的授权字段叫
|
||||
* `verified`(历史命名,与成果槽规则 1 同源)、口径散布在 `metrics[].basis`。
|
||||
* 本模块把两种写法归一为同一判据(authorized ?? verified、basis ∪ metrics[].basis),
|
||||
* 而不是让调用方各写一套映射——那才是第二套真源。
|
||||
*/
|
||||
export interface GateableCaseItem {
|
||||
client?: string;
|
||||
industry?: string;
|
||||
challenge?: string;
|
||||
solution?: string;
|
||||
result?: string;
|
||||
/** 客户是否授权对外展示 */
|
||||
authorized?: boolean;
|
||||
/** cases.ts 历史字段名,与 authorized 同义(结果槽规则 1 用的就是它) */
|
||||
verified?: boolean;
|
||||
/** 该条「核心成果」的佐证口径,仅 verified 出得了闸(真源同 metrics-basis) */
|
||||
basis?: MetricBasis | string | null;
|
||||
/** cases.ts 形状:口径挂在各指标上,聚合成一条的可用口径集合 */
|
||||
metrics?: readonly { basis?: MetricBasis | string | null }[];
|
||||
}
|
||||
|
||||
/** 分区:可发布项与被封项(含原因),供渲染端过滤并把降级原因喊出来。 */
|
||||
export function gateCaseItems<T extends GateableCaseItem>(
|
||||
items: readonly T[],
|
||||
): { publishable: T[]; blocked: { item: T; blockers: string[] }[] } {
|
||||
const publishable: T[] = [];
|
||||
const blocked: { item: T; blockers: string[] }[] = [];
|
||||
for (const item of items) {
|
||||
const blockers = casePublishGateBlockers({
|
||||
authorized: item.authorized ?? item.verified,
|
||||
bases: [item.basis, ...(item.metrics ?? []).map((m) => m.basis)],
|
||||
copy: [item.client, item.industry, item.challenge, item.solution, item.result],
|
||||
});
|
||||
if (blockers.length === 0) publishable.push(item);
|
||||
else blocked.push({ item, blockers });
|
||||
}
|
||||
return { publishable, blocked };
|
||||
}
|
||||
@@ -6,6 +6,13 @@ export interface CaseStudy {
|
||||
challenge: string;
|
||||
solution: string;
|
||||
result: string;
|
||||
/**
|
||||
* DEC-N4 同闸(2026-10-19 新增,可选字段,既有数据零改动):
|
||||
* 卡片型案例进 case-publish-gate 的两维输入。缺任一 ⇒ 闸住不渲染
|
||||
* (fail-closed,与首页成果槽同一判据)。
|
||||
*/
|
||||
authorized?: boolean;
|
||||
basis?: MetricBasis;
|
||||
}
|
||||
|
||||
export interface DataProof {
|
||||
|
||||
Reference in new issue
Block a user