From 0c5ff79b42217d58f5817cf05ad009dc429c25b2 Mon Sep 17 00:00:00 2001 From: que01 Date: Sun, 27 Sep 2026 14:37:07 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=A0=A1=E9=AA=8C=E5=BF=85=E9=9C=80?= =?UTF-8?q?=E4=BF=A1=E4=BB=BB=E5=86=85=E5=AE=B9=E5=AE=8C=E6=95=B4=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trust-items-content-migration/PROGRESS.md | 8 +++ .../trust-items-content-migration/TODO.csv | 1 + apps/api/src/brand-release-api.service.ts | 13 ++-- apps/api/test/http.integration.test.js | 59 +++++++++++++++++-- 4 files changed, 71 insertions(+), 10 deletions(-) diff --git a/.codex-tasks/trust-items-content-migration/PROGRESS.md b/.codex-tasks/trust-items-content-migration/PROGRESS.md index 0eaea06..262a9e9 100644 --- a/.codex-tasks/trust-items-content-migration/PROGRESS.md +++ b/.codex-tasks/trust-items-content-migration/PROGRESS.md @@ -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。 diff --git a/.codex-tasks/trust-items-content-migration/TODO.csv b/.codex-tasks/trust-items-content-migration/TODO.csv index 05ddb1d..ff9809a 100644 --- a/.codex-tasks/trust-items-content-migration/TODO.csv +++ b/.codex-tasks/trust-items-content-migration/TODO.csv @@ -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,通用信任内容有效性校验不绑定行业字段 diff --git a/apps/api/src/brand-release-api.service.ts b/apps/api/src/brand-release-api.service.ts index 30e95f8..bd2627b 100644 --- a/apps/api/src/brand-release-api.service.ts +++ b/apps/api/src/brand-release-api.service.ts @@ -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", }); } diff --git a/apps/api/test/http.integration.test.js b/apps/api/test/http.integration.test.js index 0c0eaf3..9a5f394 100644 --- a/apps/api/test/http.integration.test.js +++ b/apps/api/test/http.integration.test.js @@ -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 } });