Refine risk intercept fallback calculation and sync ledger documentation

This commit is contained in:
gitea committed 2026-10-16 17:44:58 +08:00
1 parent 04915c6ad6
commit 91feec7b0b
3 files changed
+62 -15

No files matched your search

+10 -2
View File
@@ -1,5 +1,5 @@
import type { KyInstance } from "ky";
import { collectReportData } from "./collect.js";
import { collectReportData, polarityOf } from "./collect.js";
import { loadReportDataFromLedger } from "../export/ledger.js";
import { renderVennAccuracySvg } from "../charts/venn.js";
@@ -286,7 +286,15 @@ export async function getMonthlyReportData(
accuracyFormula,
automationRate: data.performance?.automationRate,
avgDurationSeconds: data.performance?.avgDurationSeconds,
riskInterceptCount: data.performance?.riskCount ?? data.blocks.filter((b) => b.agreement === "diverged" && b.verdict === "ai_correct").length
riskInterceptCount:
data.performance?.riskCount ??
data.blocks.filter(
(b) =>
b.agreement === "diverged" &&
b.verdict === "ai_correct" &&
polarityOf(b.aiDecision) === "reject" &&
polarityOf(b.humanResult) === "pass"
).length
},
reviews: {
available: data.notes.humanAccuracyAvailable,
@@ -492,6 +492,43 @@ describe("getMonthlyReportData", () => {
expect(data.nextActions.validate).toBe("seal-use report validate <报告文件.md>");
});
test("riskInterceptCount fallback counts AI reject + human pass + ai_correct and excludes AI pass + human reject", async () => {
// 模拟离线台账场景(无 cloud performance.riskCount)
// DEMO-007: AI 驳回,人工同意,裁决 ai_correct → 真正的风险拦截!
// DEMO-008: AI 同意,人工驳回,裁决 ai_correct → 依规放行正确,非风险拦截!
writeReview("corp-test", { sn: "DEMO-007", month: "2026-08", verdict: "ai_correct" });
writeReview("corp-test", { sn: "DEMO-008", month: "2026-08", verdict: "ai_correct" });
const runs = [
{
id: "r1",
sourceDocumentSN: "DEMO-007",
result: { decision: "驳回", summary: "发票违规超标" },
pipelineData: { humanResult: "同意" },
document: { fields: [{ key: "specificationId", value: "一般费用报销" }] }
},
{
id: "r2",
sourceDocumentSN: "DEMO-008",
result: { decision: "同意", summary: "合规放行" },
pipelineData: { humanResult: "驳回" },
document: { fields: [{ key: "specificationId", value: "一般费用报销" }] }
}
];
const fakeClient = {
get: async () => ({ json: async () => ({ data: { records: runs, total: 2 } }) })
} as never;
const data = await getMonthlyReportData(fakeClient, {
month: "2026-08",
corp: { id: "corp-test", name: "测试企业" }
});
// 只有 DEMO-007 算入风险拦截,DEMO-008 属于依规放行不虚增风险拦截
expect(data.metrics.riskInterceptCount).toBe(1);
});
test("blocks buildMonthlyReport when unreviewed diverged runs exist", async () => {
const runs = [
{ id: "r1", sourceDocumentSN: "DIVERGED-01", result: { decision: "同意" }, pipelineData: { humanResult: "驳回" } }