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:
zhangxiang committed 2026-10-17 07:51:24 +08:00
1 parent 20d5cd0943
commit 2e0099426f
12 files changed
+574 -23

No files matched your search

@@ -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"
+21 -3
View File
@@ -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 }}
+58 -1
View File
@@ -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(
+12 -16
View File
@@ -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 ?? ''],
});
}
/** 兼容旧调用名:抛错版本,留给构建期/测试期使用。组件渲染路径**不**用它。 */