feat(approval): introduce configurable gateway policy script and enforce strict reject/approve guardrails

This commit is contained in:
gitea committed 2026-09-07 14:03:22 +08:00
1 parent 01a3263423
commit 27660bed92
6 files changed
+698 -98

No files matched your search

+8 -23
View File
@@ -12,6 +12,7 @@ import {
CreateFindingInput,
RuleRecord,
parseRuleBody,
validateGatewayAction,
} from "./domains/approval/index.js";
import { getRawBillFlow } from "./domains/bill/api.js";
import { approveBill, rejectBill } from "./domains/bill/tools.js";
@@ -878,31 +879,15 @@ export async function runAiProCli(rawArgs: string[]): Promise<{ stdout: string;
throw new Error("必须提供小于 150 字的审批意见: --opinion '<审批意见>'");
}
if (opinion.length > 150) {
throw new Error(`[参数校验阻断] 审批意见不可超过 150 字符,当前长度为 ${opinion.length} 字符,请精简。`);
}
const findings = repo.getFindingsByRunId(runRecord.id);
if (findings.length === 0) {
throw new Error(`[网关安全阻断] 会话 [${runRecord.shortId || runRecord.id}] 尚未挂载任何规约审核要点,审批链路物理不通!请先执行 bind 挂载。`);
}
// 网关刚性阻拦检查(它只阻拦,不决断)
if (action === "APPROVE") {
// 门禁 1: 漏检拦截
const pendingFindings = findings.filter((f) => f.checkStatus === "PENDING");
if (pendingFindings.length > 0) {
const pendingIndices = pendingFindings.map((f) => `#${findings.indexOf(f) + 1}`).join(", ");
throw new Error(`[网关安全阻断] 尚有 ${pendingFindings.length} 处审核要点处于“待核验”状态(要点 ${pendingIndices}),禁止盲目放行同意!`);
}
// 门禁 2: 硬性一票否决
const hardFailed = findings.filter((f) => f.checkStatus === "FAIL" && f.strictness === "硬性");
if (hardFailed.length > 0) {
const failedNames = hardFailed.map((f) => `【#${findings.indexOf(f) + 1} ${f.clauseText}】`).join("、");
throw new Error(`[网关安全阻断] 单据存在硬性违规条款未通过(${failedNames}),物理切断“同意”流转,绝对禁止放行!`);
}
}
// 网关刚性安全门禁检查(统一由可配置网关 TS 策略执行:意见长度、待核验漏检、硬性违规禁止同意、无硬性/弹性违规禁止驳回)
validateGatewayAction({
documentSn: runRecord.documentSn,
findings,
requestedAction: action === "APPROVE" ? "approve" : "reject",
opinion,
});
// Apply execution
const apply = booleanOption(parsed.options, ["apply", "execute", "run", "do"]);