diff --git a/docs/template-completion-rules.md b/docs/template-completion-rules.md index d7c12fd..2ee5075 100644 --- a/docs/template-completion-rules.md +++ b/docs/template-completion-rules.md @@ -24,7 +24,9 @@ 运行 pnpm template:doctor,自动扫描 packages/template-*/template.json 和 Taro renderer;支持 --template packageKey、--output path 输出 JSON。每个问题包含 code、page、target、binding、位置和修复方向。 -staticStatus 只代表支持范围内的静态检查。completionStatus 保持 unverified,直到交互、隔离数据库保存发布、视觉证据经过审阅。退出 0 仅表示静态通过,1 表示 blocker/review,2 表示执行故障。 +staticStatus 只代表支持范围内的静态检查。completionStatus 保持 unverified,直到交互、隔离数据库保存发布、视觉证据经过审阅。退出 1 表示存在 blocker、未登记 review 或执行后的登记校验失败,退出 2 表示执行故障。 + +已逐条完成源码审阅的 review 可登记在 `.codex-tasks/template-audit-execution/raw/manual-review.json`。登记必须使用和诊断报告一致的 `file/page/target/binding/line/message`,并保留结论与证据;doctor 只把精确匹配的 review 标记为 `source-reviewed`,不改变 `completionStatus`。未匹配的新 review 和全部 blocker 仍会让命令失败。 AST 解析可追踪 workspace.brand、presentation、object 和局部别名。动态路径、跨组件和间接映射等未知情况标为 review,不能猜测为通过。诊断器包含正反故障注入测试。 diff --git a/scripts/lib/template-doctor.mjs b/scripts/lib/template-doctor.mjs index 2609cf5..dc84da8 100644 --- a/scripts/lib/template-doctor.mjs +++ b/scripts/lib/template-doctor.mjs @@ -372,3 +372,38 @@ export function diagnoseTemplate(manifest, source, file = "taro/index.tsx") { issues, }; } + +const REVIEW_KEY_FIELDS = ["file", "page", "target", "binding", "line", "message"]; + +function reviewKey(item) { + return JSON.stringify( + Object.fromEntries(REVIEW_KEY_FIELDS.map((key) => [key, item[key] ?? null])), + ); +} + +export function applyManualReview(reports, reviews, reviewScope) { + if (reviewScope !== "人工映射审查,保留原诊断,不是自动豁免或全条件组合证明") + throw new Error("Manual review registry has an unsupported scope"); + const byKey = new Map(); + for (const item of reviews) { + if (item.severity !== "review" || item.reviewStatus !== "source-reviewed" || !item.decision) + throw new Error("Manual review registry contains an invalid entry"); + byKey.set(reviewKey(item), item); + } + for (const report of reports) { + let unresolved = 0; + report.issues.forEach((issue) => { + const reviewed = issue.severity === "review" && byKey.get(reviewKey(issue)); + if (reviewed) issue.reviewStatus = "source-reviewed"; + else unresolved++; + }); + report.reviewedIssues = report.issues.length - unresolved; + report.unresolvedIssues = unresolved; + report.staticStatus = report.issues.some( + (issue) => issue.severity === "blocker" || issue.reviewStatus !== "source-reviewed", + ) + ? "fail" + : "pass"; + } + return reports; +} diff --git a/scripts/template-doctor.mjs b/scripts/template-doctor.mjs index 4107d72..ddb4268 100644 --- a/scripts/template-doctor.mjs +++ b/scripts/template-doctor.mjs @@ -1,7 +1,7 @@ import fs from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; -import { diagnoseTemplate } from "./lib/template-doctor.mjs"; +import { applyManualReview, diagnoseTemplate } from "./lib/template-doctor.mjs"; try { const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), ".."); @@ -25,6 +25,12 @@ try { ); } if (!reports.length) throw new Error("No matching templates found"); + const registryPath = path.join( + root, + ".codex-tasks/template-audit-execution/raw/manual-review.json", + ); + const registry = JSON.parse(fs.readFileSync(registryPath, "utf8")); + applyManualReview(reports, registry.items, registry.scope); const report = { schemaVersion: 1, completionStatus: "unverified", templates: reports }; const output = JSON.stringify(report, null, 2) + "\n"; if (options["--output"]) { diff --git a/scripts/test/template-doctor.test.mjs b/scripts/test/template-doctor.test.mjs index 81d0331..85a0e48 100644 --- a/scripts/test/template-doctor.test.mjs +++ b/scripts/test/template-doctor.test.mjs @@ -2,7 +2,7 @@ import assert from "node:assert/strict"; import test from "node:test"; import fs from "node:fs"; import { spawnSync } from "node:child_process"; -import { diagnoseTemplate } from "../lib/template-doctor.mjs"; +import { applyManualReview, diagnoseTemplate } from "../lib/template-doctor.mjs"; test("真实模板自动发现并读取完整声明,生成可追溯区域报告", () => { const root = new URL("../../packages/", import.meta.url); @@ -70,6 +70,73 @@ test("CLI 自动发现全部模板,问题退出 1,未知模板退出 2", () assert.equal(missing.status, 2); }); +test("人工审阅登记只能匹配真实 review,新问题仍会失败", () => { + const report = { + template: "fixture", + staticStatus: "pass", + completionStatus: "unverified", + issues: [], + }; + const reviewed = { + file: "taro/index.tsx", + page: "home", + target: "identity", + binding: null, + line: 20, + message: "条件显示需验证全部分支与空数据入口。", + severity: "review", + reviewStatus: "source-reviewed", + decision: "已核对空数据分支。", + }; + const clone = (issue) => structuredClone({ ...report, issues: issue ? [issue] : [] }); + const issue = { + code: "CONDITIONAL_RENDER_REVIEW", + file: "taro/index.tsx", + page: "home", + target: "identity", + line: 20, + message: "条件显示需验证全部分支与空数据入口。", + severity: "review", + }; + const empty = applyManualReview( + [clone()], + [], + "人工映射审查,保留原诊断,不是自动豁免或全条件组合证明", + ); + assert.equal(empty[0].staticStatus, "pass"); + assert.equal( + applyManualReview( + [clone(issue)], + [reviewed], + "人工映射审查,保留原诊断,不是自动豁免或全条件组合证明", + )[0].staticStatus, + "pass", + ); + assert.equal( + applyManualReview( + [clone(issue)], + [], + "人工映射审查,保留原诊断,不是自动豁免或全条件组合证明", + )[0].staticStatus, + "fail", + ); + assert.throws(() => + applyManualReview( + [clone(issue)], + [{ ...reviewed, severity: "blocker" }], + "人工映射审查,保留原诊断,不是自动豁免或全条件组合证明", + ), + ); + assert.throws(() => + applyManualReview( + [clone(issue)], + [{ ...reviewed, reviewStatus: "verified" }], + "人工映射审查,保留原诊断,不是自动豁免或全条件组合证明", + ), + ); + assert.throws(() => applyManualReview([clone(issue)], [reviewed], "unsupported scope")); +}); + const manifest = () => ({ packageKey: "independent-template", admin: {