feat: 接入模板诊断人工审阅登记
This commit is contained in:
1 parent
f57e1b1336
commit
d2ce2d2a84
4 files changed
+113
-3
No files matched your search
@@ -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;
|
||||
}
|
||||
@@ -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"]) {
|
||||
|
||||
@@ -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: {
|
||||
|
||||
Reference in new issue
Block a user