From 220ece524dcb455ce681f44f383f223e39684715 Mon Sep 17 00:00:00 2001 From: zhangxiang Date: Sat, 17 Oct 2026 10:14:49 +0800 Subject: [PATCH] =?UTF-8?q?fix(detail):=20=E6=A1=88=E4=BE=8B=E9=97=A8?= =?UTF-8?q?=E6=A7=9B=E5=8F=AA=E5=BD=93=E4=BA=86=E6=95=B4=E5=9D=97=E5=BC=80?= =?UTF-8?q?=E5=85=B3=EF=BC=8C=E6=9C=AA=E8=BF=87=E9=97=B8=E6=9D=A1=E7=9B=AE?= =?UTF-8?q?=E4=BB=8D=E9=80=90=E6=9D=A1=E6=B8=B2=E6=9F=93=EF=BC=88fail-open?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 第 97 行算了 gateCaseItems、第 105/160 行用 publishableCases.length 决定出现与否, 但第 175 行渲染的仍是 caseStudies.map ⇒ 只要组里有一条过闸,未授权或口径为 target 的案例照样出现在页面上。DEC-N4 声称的逐条 fail-closed 在这里没生效。 - 改为 publishableCases.map。 - 新增 src/components/detail/detail-trust-gate.test.tsx 3 例:过闸的出、 没过闸的一条都不出(含「有授权但 basis=target」这一维)、全被闸时整块不出现 且 console.error 逐条喊原因、被闸条目不得占用网格位置。 - 变异验证:把渲染回退成 caseStudies.map ⇒ MUTANT=1(2 条精确转红、1 条仍绿), 恢复 ⇒ 35 例 EXIT=0。另一处 detail-case-studies-section 复核为已正确使用 publishable.map,无同类漏洞。 来源:§14 补跑全量功能 E2E 时暴露(本批引入,非基线既有)。 --- .../detail/detail-trust-gate.test.tsx | 107 ++++++++++++++++++ .../detail/detail-trust-section.tsx | 2 +- 2 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 src/components/detail/detail-trust-gate.test.tsx diff --git a/src/components/detail/detail-trust-gate.test.tsx b/src/components/detail/detail-trust-gate.test.tsx new file mode 100644 index 0000000..e41cef7 --- /dev/null +++ b/src/components/detail/detail-trust-gate.test.tsx @@ -0,0 +1,107 @@ +/** + * @jest-environment jsdom + */ +import { describe, it, expect, jest, beforeEach } from '@jest/globals'; +import { render, screen } from '@testing-library/react'; +import React from 'react'; + +/** + * DEC-N4 的渲染侧守卫(2026-10-17 补,抓到一条真缺陷)。 + * + * 缺陷本身:`DetailTrustSection` 第 97 行算了 `gateCaseItems(caseStudies)`, + * 第 105 行用 `publishableCases.length > 0` 决定整块要不要出现, + * 第 160 行也用 `publishableCases.length > 0` 包住了案例网格—— + * **但第 175 行渲染的是 `caseStudies.map`**。 + * 后果是 fail-open:只要有一条过了闸,未授权 / 无 verified 口径的案例照样出现在页面上。 + * 门槛只当了"这块要不要出现"的开关,没做它声称的逐条隐藏。 + * 全量功能 E2E 补跑(§14)把这条暴露出来后修的为 `publishableCases.map`。 + * + * 本文件的断言方向刻意与"缺陷存在时"相反 ⇒ 回退成 `caseStudies.map` 必须转红(变异验证已做)。 + */ + +const passable = { + client: '甲客户集团', + industry: '制造', + challenge: '挑战甲', + solution: '方案甲', + result: '成果甲', + authorized: true, + basis: 'verified' as const, +}; + +const failable = { + client: '乙客户公司', + industry: '零售', + challenge: '挑战乙', + solution: '方案乙', + result: '成果乙', + // 缺 authorized 与 basis ⇒ 必须被闸住(fail-closed) +}; + +const failableNoVerified = { + client: '丙客户实业', + industry: '能源', + challenge: '挑战丙', + solution: '方案丙', + result: '成果丙', + authorized: true, + basis: 'target' as const, // 有授权但口径是目标 ⇒ 仍闸住 +}; + +beforeEach(() => { + jest.restoreAllMocks(); + jest.spyOn(console, 'error').mockImplementation(() => undefined); +}); + +async function loadSection() { + const mod = await import('./detail-trust-section'); + const Section = (mod as { DetailTrustSection?: React.ComponentType> }).DetailTrustSection + ?? (mod as unknown as { default: React.ComponentType> }).default; + return Section; +} + +describe('DetailTrustSection · 案例逐条过闸(渲染侧)', () => { + it('过了闸的出、没过闸的一条都不出(即使同组里有过闸的)', async () => { + const Section = await loadSection(); + render( +
, + ); + expect(screen.getByText('甲客户集团')).toBeInTheDocument(); + // 下面三条是缺陷存在时会失败的核心断言 + expect(screen.queryByText('乙客户公司')).not.toBeInTheDocument(); + expect(screen.queryByText('丙客户实业')).not.toBeInTheDocument(); + expect(screen.queryByText('挑战乙')).not.toBeInTheDocument(); + expect(screen.queryByText('成果丙')).not.toBeInTheDocument(); + }); + + it('全部没过闸 ⇒ 案例区整块不出现,且隐藏原因逐条 console.error(不静默)', async () => { + const spy = jest.spyOn(console, 'error').mockImplementation(() => undefined); + const Section = await loadSection(); + render(
); + expect(screen.queryByText('乙客户公司')).not.toBeInTheDocument(); + expect(screen.queryByText('他们已经实现了转型突破')).not.toBeInTheDocument(); + expect(spy.mock.calls.flat().join(' ')).toContain('反伪造门槛'); + }); + + it('被闸住的条目不得占用网格位置(数量对账,防"隐藏但仍渲染")', async () => { + const Section = await loadSection(); + const { container } = render( +
, + ); + // 网格标题 + 每条一个卡片;只有 1 条应出现 + const heading = screen.getByText('他们已经实现了转型突破'); + const grid = heading.parentElement?.parentElement as HTMLElement; + const cards = grid.querySelectorAll('[class*="rounded"], article'); + expect(heading).toBeTruthy(); + expect(cards.length).toBeGreaterThan(0); + expect(container.textContent).not.toContain('挑战乙'); + }); +}); diff --git a/src/components/detail/detail-trust-section.tsx b/src/components/detail/detail-trust-section.tsx index 729931e..51b80c2 100644 --- a/src/components/detail/detail-trust-section.tsx +++ b/src/components/detail/detail-trust-section.tsx @@ -172,7 +172,7 @@ export function DetailTrustSection({
- {caseStudies.map((study, index) => ( + {publishableCases.map((study, index) => (