feat(cms): DEC-N4 补上 caseStudies 的 authorized/basis schema 声明与契约守卫;AUTH-NAV 核查后判定已达成
上一轮我把「扩 schema」误判成需要授权的库动作:ContentItem.data 是 JSON 列,没有表迁移。 真门槛是 prisma/seed.ts:364 —— ContentModel.fields 由 content-types.ts 生成,而后台能否填 authorized/basis 取决于那份声明(loadDeclaredFields 读它)。没有声明,case-publish-gate 会永远把所有案例拦在门外:表现为「防呆生效」,实际是业务用不上。 - 三处 caseStudies(product / service / standalone-product)补 authorized(boolean) 与 basis, basis 复用 metricBasisField 的选项表、只覆盖标签与说明语境 ⇒ 口径选项仍只有一份真源。 - 新增 src/lib/cms/case-field-contract.test.ts:①站点计数写死三处(新增带案例的内容类型忘记带 门槛字段即判红)②形状契约(authorized 必须 boolean、basis 必须含 target/team-history/verified) ③按声明填的案例确实过闸,且两维各缺一条都被闸住、字段全缺 fail-closed; ④仪器自证:摘掉 authorized 或 verified 时契约必须报问题。 - AUTH-NAV:dev.db 那行 mainNav 已是 行业/能力/洞察/关于我们,且 seed 前后 length(data)=2778 逐字节不变 ⇒ 早已随决策二的代码真源反转对齐;nav-dropdown + p6-missing-paths × 2 project 26 passed 证明 该行被采纳时契约门放行。判定关闭,不写库。生产侧同名行随部署核对。 - 自报:我先前那句「dev.db 里没有 navigation 行」的证据是 sqlite 报 「no such column: code」后被 2>/dev/null 吞掉的空输出 ⇒ 空结果不等于查询成功。已改判据重取。 读数:jest case-field-contract 4 例 EXIT=0、全量 jest 146 套件/1799 例 EXIT=0、tsc EXIT=0、db:seed EXIT=0 且 ContentItem 38→38 未变(跑前已 cp 备份 dev.db)。
This commit is contained in:
1 parent
5ced511c75
commit
1426dd1cf1
3 files changed
+157
No files matched your search
@@ -891,3 +891,33 @@ dev 下 `GoogleAnalytics.tsx` 提前 return null ⇒ 那 16 个 `@critical` 是
|
||||
|
||||
⇒ **§11.6 那个 104 至今没有名单可查**,所以 +9 仍不能从证据归因(只能说:113/12/5 这三个数现在自洽且可复算)。
|
||||
从本轮起每轮都留逐名清单,这类"聚合数对不上只能靠推断"的情形不会再出现。
|
||||
|
||||
### 12.12 两条原判「需你授权」的项:DEC-N4 的 schema 落地(可做,已做)与 AUTH-NAV(前提核查后判定为已达成)
|
||||
|
||||
**a) DEC-N4 的功能性前置已闭合(纯代码 + 本地 seed,非生产库动作)**
|
||||
我上一轮把「扩 schema」当成需要授权的库动作,判错了:`ContentItem.data` 是 JSON 列,**没有表迁移**。
|
||||
真正的门槛在 `prisma/seed.ts:364` —— `ContentModel.fields` 由 `content-types.ts` 生成,
|
||||
而后台能不能填 `authorized/basis` 取决于那份声明(`loadDeclaredFields()` 读它)。
|
||||
没有声明,闸就永远把所有案例拦在门外:**表现为"防呆生效",实际是业务用不上**。
|
||||
|
||||
| 动作 | 读数 |
|
||||
|---|---|
|
||||
| 三处 `caseStudies`(product / service / standalone-product)补 `authorized(boolean)` + `basis`(复用 `metricBasisField` 的选项表,只覆盖标签语境,不造第二份真源) | 新增 `src/lib/cms/case-field-contract.test.ts` 4 例 EXIT=0,全量 jest **146 套件 / 1799 例 EXIT=0** |
|
||||
| 契约守卫的自证 | 摘掉 `authorized` 或摘掉 `verified` 选项 ⇒ 契约报问题(用例内断言,仪器坏时仍然会失败);站点计数写死为三处 ⇒ 新增带案例的内容类型忘记带字段会当场判红 |
|
||||
| `npm run db:seed` 传播到库 | SEED=0;三行 `ContentModel.fields` 均含 `authorized` + `成果口径`;`ContentItem` 行数 **38 → 38 未变**(先 `cp` 出备份再跑,不盲跑重建) |
|
||||
|
||||
**b) AUTH-NAV:核查后判定「已达成」,不是待办**
|
||||
台账说「CMS `navigation/default` 行改写」。实查:dev.db 里那行 `mainNav` 已经是
|
||||
`行业 / 能力 / 洞察 / 关于我们`(无「产品」一级),且 `length(data)` 在我这次 seed 前后**逐字节相等(2778)**
|
||||
⇒ 不是我本轮改的,也说明它早已随决策二的代码真源反转对齐。
|
||||
`nav-dropdown.spec.ts` + `p6-missing-paths.spec.ts` × chromium/chromium-mobile ⇒ **26 passed / EXIT=0**,
|
||||
这是在「该行被采纳」的前提下跑的,即 fail-closed 的契约门确实放行了一行符合 IA 的数据。
|
||||
⇒ **AUTH-NAV 无需写库,判定关闭**;生产侧同名行是否同形,属部署期核对项(需要 SSH 只读,随发布一起做)。
|
||||
|
||||
**c) 我自报一次同类仪器错配(§5.45 的同族,第三次)**
|
||||
上一条消息我说过「dev.db 里根本没有 navigation 行」——那句话的证据是
|
||||
`sqlite3 … "select code, substr(data,…) from ContentItem where modelCode='navigation';" 2>/dev/null`,
|
||||
而 `ContentItem` **没有 `code` 列**,sqlite3 报 `Parse error: no such column: code` 被 `2>/dev/null` 吞掉,
|
||||
空 stdout 被我读成"没有这行"。⇒ 与 §5.44(`sed` 按行号删错行)、§5.45(正则只扫顶层)三条同判:
|
||||
**查询工具的报错也是证据,不能丢;空结果必须同时证明"这次查询本身成功了"**。
|
||||
本条结论已改用 `select count(*) …`(不含未知列)与逐字节长度对账重取。
|
||||
@@ -0,0 +1,100 @@
|
||||
import { describe, it, expect } from '@jest/globals';
|
||||
import { CONTENT_TYPE_CONFIGS } from './content-types';
|
||||
import { gateCaseItems } from '@/lib/constants/case-publish-gate';
|
||||
|
||||
/**
|
||||
* DEC-N4 的 schema 契约守卫。
|
||||
*
|
||||
* 为什么要有:闸(`case-publish-gate`)判的是**数据里有没有 `authorized` + `basis==='verified'`**,
|
||||
* 而后台能不能填这两个键,取决于 `ContentModel.fields` —— 那份是 `prisma/seed.ts:364`
|
||||
* 从 `content-types.ts` 生成的。缺了声明,闸就永远把所有案例拦在门外:
|
||||
* 表现为"防呆生效",实际是业务用不上。本文件把这件事钉成机器判据,
|
||||
* 让"新增一个带案例的内容类型却忘了带门槛字段"当场判红。
|
||||
*/
|
||||
|
||||
type FieldLike = { name: string; type?: string; label?: string; options?: { value: string }[] };
|
||||
type CaseStudiesField = { name: string; type: string; fields?: FieldLike[] };
|
||||
|
||||
function caseSitesOf(configs: Record<string, { model?: { fields?: CaseStudiesField[] }; [k: string]: unknown }>) {
|
||||
const sites: { code: string; field: CaseStudiesField }[] = [];
|
||||
for (const [code, cfg] of Object.entries(configs)) {
|
||||
for (const f of cfg.model?.fields ?? []) {
|
||||
if (f.name === 'caseStudies') sites.push({ code, field: f });
|
||||
}
|
||||
}
|
||||
return sites;
|
||||
}
|
||||
|
||||
/** 纯函数判据,便于自证:喂一份缺字段的副本必须报出问题 */
|
||||
function contractProblems(sites: ReturnType<typeof caseSitesOf>): string[] {
|
||||
const problems: string[] = [];
|
||||
for (const { code, field } of sites) {
|
||||
const subs = field.fields ?? [];
|
||||
const authorized = subs.find((s) => s.name === 'authorized');
|
||||
const basis = subs.find((s) => s.name === 'basis');
|
||||
if (!authorized) problems.push(`${code}.caseStudies 缺 authorized 声明 ⇒ 后台无法授权,闸会永久拦下所有案例`);
|
||||
else if (authorized.type !== 'boolean') problems.push(`${code}.caseStudies.authorized 必须是 boolean(现为 ${authorized.type})`);
|
||||
if (!basis) problems.push(`${code}.caseStudies 缺 basis 声明 ⇒ 无法标「已验证」,闸会永久拦下所有案例`);
|
||||
else {
|
||||
const values = (basis.options ?? []).map((o) => o.value);
|
||||
for (const need of ['target', 'team-history', 'verified']) {
|
||||
if (!values.includes(need)) problems.push(`${code}.caseStudies.basis 选项缺 "${need}"(须与 metrics 的口径表同源同集)`);
|
||||
}
|
||||
}
|
||||
}
|
||||
return problems;
|
||||
}
|
||||
|
||||
describe('DEC-N4 · caseStudies 的 schema 契约', () => {
|
||||
const sites = caseSitesOf(CONTENT_TYPE_CONFIGS as never);
|
||||
|
||||
it('带案例的内容类型必须存在,且数量可数(新增站点要显式记账)', () => {
|
||||
expect(sites.length).toBeGreaterThan(0);
|
||||
// 实取三处:product / service / standalone-product(solution 没有 caseStudies 站点)。
|
||||
expect(sites.map((s) => s.code).sort()).toEqual(['product', 'service', 'standalone-product']);
|
||||
});
|
||||
|
||||
it('每个 caseStudies 都声明了 authorized(boolean) 与 basis(含三档口径)', () => {
|
||||
expect(contractProblems(sites)).toEqual([]);
|
||||
});
|
||||
|
||||
it('声明的形状与闸的输入一致:按声明填出来的案例能过闸', () => {
|
||||
const ok = {
|
||||
client: '某制造集团', industry: '制造', challenge: 'c', solution: 's', result: 'r',
|
||||
authorized: true, basis: 'verified',
|
||||
};
|
||||
// 闸的真实入口是 gateCaseItems(把 authorized/verified 两种历史写法与
|
||||
// basis ∪ metrics[].basis 归一),不要绕过它直接喂 casePublishGateBlockers。
|
||||
expect(gateCaseItems([ok]).publishable).toHaveLength(1);
|
||||
expect(gateCaseItems([ok]).blocked).toHaveLength(0);
|
||||
// 反例:有授权但口径是目标 ⇒ 仍闸住(闸要真的两维都看)
|
||||
expect(gateCaseItems([{ ...ok, basis: 'target' }]).blocked[0].blockers.join()).toContain('verified');
|
||||
// 反例:口径 verified 但没授权 ⇒ 闸住
|
||||
expect(gateCaseItems([{ ...ok, authorized: false }]).blocked.length).toBe(1);
|
||||
// 反例:字段全缺(既有 seeds/CMS 的真实形状)⇒ fail-closed,一条都不出
|
||||
expect(gateCaseItems([{ client: 'x', result: 'y' }]).publishable).toHaveLength(0);
|
||||
});
|
||||
|
||||
/**
|
||||
* 仪器自证(负对照):本守卫必须能失败。
|
||||
* 把 authorized 摘掉 / 把 verified 选项摘掉,各自都要报出问题 ——
|
||||
* 否则"契约成立"只是自称(本仓反复吃的"空断言/恒绿守卫")。
|
||||
*/
|
||||
it('自证:摘掉 authorized 或 verified 时契约判红', () => {
|
||||
const withoutAuthorized = JSON.parse(JSON.stringify(sites));
|
||||
withoutAuthorized[0].field.fields = withoutAuthorized[0].field.fields.filter((s: FieldLike) => s.name !== 'authorized');
|
||||
expect(contractProblems(withoutAuthorized)).toEqual(expect.arrayContaining([
|
||||
expect.stringContaining('缺 authorized 声明'),
|
||||
]));
|
||||
|
||||
const withoutVerified = JSON.parse(JSON.stringify(sites));
|
||||
const basisField = withoutVerified[0].field.fields.find((s: FieldLike) => s.name === 'basis');
|
||||
// 显式守卫:取不到 basis 说明上一维用例的前提没了,此时应报「夹具不符」而不是 TypeError 被吞
|
||||
if (!basisField) throw new Error('夹具里没有 basis 字段:契约用例的前提已变,请同步本文件');
|
||||
basisField.options = basisField.options.filter((o: { value: string }) => o.value !== 'verified');
|
||||
expect(contractProblems(withoutVerified).length).toBeGreaterThan(0);
|
||||
|
||||
const empty: never[] = [];
|
||||
expect(contractProblems(empty)).toEqual([]); // 站点为空时不报问题 ⇒ 由上面的计数用例兜住
|
||||
});
|
||||
});
|
||||
@@ -17,6 +17,30 @@ const metricBasisField: FieldDefinition = {
|
||||
],
|
||||
};
|
||||
|
||||
/**
|
||||
* DEC-N4 的两个门槛输入(2026-10-17 补 schema)。
|
||||
*
|
||||
* 为什么必须存在这里而不只在 TS 类型里:`loadDeclaredFields()` 读的是**库里的
|
||||
* `ContentModel.fields`**,而那份由 `prisma/seed.ts:364` 从本文件生成。
|
||||
* 没有这两条声明,后台就填不出 `authorized/basis`,`case-publish-gate` 只能永远
|
||||
* 把所有案例闸住 —— 防呆是真的,但业务用不上。
|
||||
* `basis` 复用 `metricBasisField`(选项表只有一份真源),只覆盖标签与说明的语境。
|
||||
*/
|
||||
const casePublishGateFields: FieldDefinition[] = [
|
||||
{
|
||||
name: 'authorized',
|
||||
type: 'boolean',
|
||||
label: '客户授权展示',
|
||||
description: '未勾选则该条案例不对外渲染(DEC-N4:与首页成果槽同一判据)',
|
||||
},
|
||||
{
|
||||
...metricBasisField,
|
||||
label: '成果口径',
|
||||
description: '案例成果须选「已验证」(有可核验实测出处)才会渲染;留空按目标口径处理 ⇒ 闸住不显示',
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
export interface ContentTypeConfig {
|
||||
model: {
|
||||
id: string;
|
||||
@@ -194,6 +218,7 @@ const serviceFields: FieldDefinition[] = [
|
||||
{ name: 'challenge', type: 'textarea', label: '挑战', required: true },
|
||||
{ name: 'solution', type: 'textarea', label: '解决方案', required: true },
|
||||
{ name: 'result', type: 'textarea', label: '成果', required: true },
|
||||
...casePublishGateFields,
|
||||
],
|
||||
},
|
||||
{
|
||||
@@ -395,6 +420,7 @@ const productFields: FieldDefinition[] = [
|
||||
{ name: 'challenge', type: 'textarea', label: '挑战', required: true },
|
||||
{ name: 'solution', type: 'textarea', label: '解决方案', required: true },
|
||||
{ name: 'result', type: 'textarea', label: '成果', required: true },
|
||||
...casePublishGateFields,
|
||||
],
|
||||
},
|
||||
{
|
||||
@@ -582,6 +608,7 @@ const standaloneProductFields: FieldDefinition[] = [
|
||||
{ name: 'challenge', type: 'textarea', label: '挑战', required: true },
|
||||
{ name: 'solution', type: 'textarea', label: '解决方案', required: true },
|
||||
{ name: 'result', type: 'textarea', label: '成果', required: true },
|
||||
...casePublishGateFields,
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user