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
@@ -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