diff --git a/.husky/pre-commit b/.husky/pre-commit old mode 100644 new mode 100755 diff --git a/docs/acceptance/2026-10-17-final/run-lane.sh b/docs/acceptance/2026-10-17-final/run-lane.sh new file mode 100644 index 0000000..676cc70 --- /dev/null +++ b/docs/acceptance/2026-10-17-final/run-lane.sh @@ -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" diff --git a/docs/acceptance/qa-tracker.md b/docs/acceptance/qa-tracker.md index b169287..66ef501 100644 --- a/docs/acceptance/qa-tracker.md +++ b/docs/acceptance/qa-tracker.md @@ -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 跑到。 diff --git a/src/app/(marketing)/solutions/solution-detail-content-v3.test.tsx b/src/app/(marketing)/solutions/solution-detail-content-v3.test.tsx index ca7af17..143d829 100644 --- a/src/app/(marketing)/solutions/solution-detail-content-v3.test.tsx +++ b/src/app/(marketing)/solutions/solution-detail-content-v3.test.tsx @@ -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(); + + expect(screen.queryByText('同行业落地案例')).not.toBeInTheDocument(); + expect(screen.queryByText('某制造集团')).not.toBeInTheDocument(); + spy.mockRestore(); + }); + it('renders certifications when data is available', () => { const withCerts: Solution = { ...baseSolution, diff --git a/src/components/detail/detail-case-studies-section.test.tsx b/src/components/detail/detail-case-studies-section.test.tsx new file mode 100644 index 0000000..111590c --- /dev/null +++ b/src/components/detail/detail-case-studies-section.test.tsx @@ -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 }) =>
{children}
, + StaggerReveal: ({ children }: { children: React.ReactNode }) =>
{children}
, +})); +jest.mock('@/components/ui/page-decoration', () => ({ + SectionLabel: ({ children }: { children: React.ReactNode }) => {children}, +})); + +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(); + 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( + , + ); + 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( + , + ); + expect(container.innerHTML).toBe(''); + expect(spy).toHaveBeenCalledWith(expect.stringMatching(/未授权公开/)); + spy.mockRestore(); + }); + + it('basis 非法值(如 "已验证")按最弱口径回落 target ⇒ 照样被闸住', () => { + const spy = jest.spyOn(console, 'error').mockImplementation(() => {}); + const { container } = render( + , + ); + expect(container.innerHTML).toBe(''); + expect(spy).toHaveBeenCalledWith(expect.stringMatching(/basis === "verified"/)); + spy.mockRestore(); + }); + + it('好条目照常渲染、坏条目单独隐藏(混合列表逐条过闸,不整段连坐)', () => { + const spy = jest.spyOn(console, 'error').mockImplementation(() => {}); + render( + , + ); + 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( + , + ); + expect(container.innerHTML).toBe(''); + expect(spy).toHaveBeenCalledWith(expect.stringMatching(/禁词/)); + spy.mockRestore(); + }); + + it('空入参维持原契约:return null(L3EmptyFallback 接管)', () => { + const { container } = render(); + expect(container.innerHTML).toBe(''); + }); +}); diff --git a/src/components/detail/detail-case-studies-section.tsx b/src/components/detail/detail-case-studies-section.tsx index af3088c..a2e0ae3 100644 --- a/src/components/detail/detail-case-studies-section.tsx +++ b/src/components/detail/detail-case-studies-section.tsx @@ -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 ( -
+
@@ -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) => (
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({
)} - {caseStudies.length > 0 && ( -
+ {publishableCases.length > 0 && ( +
{ 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( + + ); + 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( + + ); + expect(screen.queryByText('他们已经实现了转型突破')).not.toBeInTheDocument(); + expect(spy).toHaveBeenCalledWith(expect.stringMatching(/未授权公开/)); + spy.mockRestore(); + }); + + it('授权 + verified 口径 ⇒ 渲染(正控制,防"闸恒真/恒假"两种假绿)', async () => { + const { DetailTrustSection } = await import('./detail-trust-section'); + render(); + 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( + + ); + 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( diff --git a/src/components/sections/results-slot.tsx b/src/components/sections/results-slot.tsx index 899c2f3..3e1ff2b 100644 --- a/src/components/sections/results-slot.tsx +++ b/src/components/sections/results-slot.tsx @@ -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 ?? ''], + }); } /** 兼容旧调用名:抛错版本,留给构建期/测试期使用。组件渲染路径**不**用它。 */ diff --git a/src/lib/constants/case-publish-gate.test.ts b/src/lib/constants/case-publish-gate.test.ts new file mode 100644 index 0000000..8ba356d --- /dev/null +++ b/src/lib/constants/case-publish-gate.test.ts @@ -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); + }); +}); diff --git a/src/lib/constants/case-publish-gate.ts b/src/lib/constants/case-publish-gate.ts new file mode 100644 index 0000000..005e52e --- /dev/null +++ b/src/lib/constants/case-publish-gate.ts @@ -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( + 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 }; +} diff --git a/src/lib/constants/products.ts b/src/lib/constants/products.ts index 1659125..e6d6f61 100644 --- a/src/lib/constants/products.ts +++ b/src/lib/constants/products.ts @@ -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 {