fix: 校验必需信任内容完整性

This commit is contained in:
que01 committed 2026-09-27 14:37:07 +08:00
1 parent 5ed06b1abe
commit 0c5ff79b42
4 files changed
+71 -10

No files matched your search

@@ -21,3 +21,11 @@
- API integration:37/37 通过,包含模板化信任类型声明和历史类型迁移。
- readiness 集成测试验证取消发布餐饮必需的 `schedule` 后无法通过发布检查。
- 全量 lint、Admin production build、Prisma validate、模板包验证:通过。
## 发布内容有效性加固
- 通用信任内容检查仅接受标题和正文去除首尾空格后均非空的已发布条目。
- 模板声明的 required 信任类型也按相同规则判定;readiness 提示明确说明标题和详细内容都必填,并保留模板提供的说明。
- API 集成测试覆盖取消发布、空白标题、空白正文均失败,以及恢复完整内容后重新通过;测试使用 `finally` 恢复数据库记录。
- 验证:API integration 37/37、typecheck、lint、Admin production build、template validation、`git diff --check` 通过。
- `pnpm format:check` 仍报告两个未由本任务改动的模板 JSON 格式告警:`packages/template-acheng-campus-food/template.json` 和 `packages/template-linjing-editorial/template.json`;本次改动文件已单独通过 Prettier。
@@ -4,3 +4,4 @@ id,task,status,acceptance_criteria,validation_command,completed_at,retry_count,n
3,改造阿成三个页面,DONE,首页、出摊服务、主理人页面按 trustItems 渲染且无数据时隐藏对应区块,pnpm --filter @personal-brand/miniapp test:visual-fixture,2026-09-27,0,多行 content 在 miniapp view model 拆分
4,固化模板与数据库边界,DONE,AGENTS.md 明确禁止将所有模板 sample data 写入全局 seed,pnpm typecheck && pnpm lint,2026-09-27,0,规则已落盘
5,按模板必需类型校验发布完整性,DONE,readiness 对 manifest 标记 required 的信任类型逐项检查且 API 测试覆盖缺项,pnpm --filter @personal-brand/api test:integration,2026-09-27,0,阿成 schedule coverage process 必需;林境 process credential 必需
6,校验必需信任内容的标题与正文,DONE,未发布或标题/正文去空格后为空的信任条目不能满足发布 readiness 且 API 集成测试覆盖失败与恢复成功,pnpm --filter @personal-brand/api test:integration,2026-09-27,0,通用信任内容有效性校验不绑定行业字段
1 id task status acceptance_criteria validation_command completed_at retry_count notes
4 3 改造阿成三个页面 DONE 首页、出摊服务、主理人页面按 trustItems 渲染且无数据时隐藏对应区块 pnpm --filter @personal-brand/miniapp test:visual-fixture 2026-09-27 0 多行 content 在 miniapp view model 拆分
5 4 固化模板与数据库边界 DONE AGENTS.md 明确禁止将所有模板 sample data 写入全局 seed pnpm typecheck && pnpm lint 2026-09-27 0 规则已落盘
6 5 按模板必需类型校验发布完整性 DONE readiness 对 manifest 标记 required 的信任类型逐项检查且 API 测试覆盖缺项 pnpm --filter @personal-brand/api test:integration 2026-09-27 0 阿成 schedule coverage process 必需;林境 process credential 必需
7 6 校验必需信任内容的标题与正文 DONE 未发布或标题/正文去空格后为空的信任条目不能满足发布 readiness 且 API 集成测试覆盖失败与恢复成功 pnpm --filter @personal-brand/api test:integration 2026-09-27 0 通用信任内容有效性校验不绑定行业字段
+8 -5
View File
@@ -80,9 +80,12 @@ export class BrandReleaseApiService {
}),
database.trustContent.findMany({
where: { brandId, isPublished: true },
select: { type: true },
select: { type: true, title: true, content: true },
}),
]);
const validTrustItems = trustItems.filter(
(item) => item.title.trim().length > 0 && item.content.trim().length > 0,
);
const offeringIds = new Set(offerings.map((item) => item.id));
const usableForms = forms.filter(
(form) =>
@@ -132,18 +135,18 @@ export class BrandReleaseApiService {
{
key: "trust",
label: "至少需要一条已发布的信任内容",
passed: trustItems.length > 0,
passed: validTrustItems.length > 0,
destination: "/admin/trust",
},
];
const publishedTrustTypes = new Set(trustItems.map((item) => item.type));
const publishedTrustTypes = new Set(validTrustItems.map((item) => item.type));
for (const type of packageManifest?.trustContentTypes ?? []) {
if (type.required !== true) continue;
checks.push({
key: `trust:${type.type}`,
label: `请补充${type.label}`,
label: `请完善${type.label}`,
passed: publishedTrustTypes.has(type.type),
...(type.help ? { help: type.help } : {}),
help: ["标题和详细内容都填写后才能发布。", type.help].filter(Boolean).join(" "),
destination: "/admin/trust",
});
}
+54 -5
View File
@@ -98,11 +98,16 @@ test("admin release lifecycle is authorized, brand-scoped, and versioned", async
where: { brandId, type: "schedule", isPublished: true },
});
assert.ok(scheduleTrust);
await prisma.trustContent.update({
where: { id: scheduleTrust.id },
data: { isPublished: false },
});
const originalScheduleTrust = {
isPublished: scheduleTrust.isPublished,
title: scheduleTrust.title,
content: scheduleTrust.content,
};
try {
await prisma.trustContent.update({
where: { id: scheduleTrust.id },
data: { isPublished: false },
});
const missingTrust = await request("/admin/releases/readiness", {
headers: { authorization: `Bearer ${adminToken}` },
});
@@ -112,10 +117,54 @@ test("admin release lifecycle is authorized, brand-scoped, and versioned", async
missingTrustBody.checks.find((check) => check.key === "trust:schedule")?.passed,
false,
);
await prisma.trustContent.update({
where: { id: scheduleTrust.id },
data: { isPublished: true, title: " " },
});
const missingTitle = JSON.parse(
(
await request("/admin/releases/readiness", {
headers: { authorization: `Bearer ${adminToken}` },
})
).body,
);
assert.equal(missingTitle.ready, false);
assert.equal(
missingTitle.checks.find((check) => check.key === "trust:schedule")?.passed,
false,
);
await prisma.trustContent.update({
where: { id: scheduleTrust.id },
data: { title: originalScheduleTrust.title, content: " \n " },
});
const missingContent = JSON.parse(
(
await request("/admin/releases/readiness", {
headers: { authorization: `Bearer ${adminToken}` },
})
).body,
);
assert.equal(missingContent.ready, false);
assert.equal(
missingContent.checks.find((check) => check.key === "trust:schedule")?.passed,
false,
);
await prisma.trustContent.update({
where: { id: scheduleTrust.id },
data: originalScheduleTrust,
});
const validTrust = JSON.parse(
(
await request("/admin/releases/readiness", {
headers: { authorization: `Bearer ${adminToken}` },
})
).body,
);
assert.equal(validTrust.checks.find((check) => check.key === "trust:schedule")?.passed, true);
} finally {
await prisma.trustContent.update({
where: { id: scheduleTrust.id },
data: { isPublished: true },
data: originalScheduleTrust,
});
}
const originalBrand = await prisma.brandProfile.findUniqueOrThrow({ where: { id: brandId } });