feat(workflow): 显式化静态分析硬门禁与软建议边界、完善发布门禁与架构演进文档

This commit is contained in:
gitea committed 2026-10-20 13:30:23 +08:00
1 parent c1e94ce63e
commit 18da4cc066
9 files changed
+694 -438

No files matched your search

+40 -15
View File
@@ -5,7 +5,7 @@ import {
type WorkflowFormSpecLike,
} from "../../../domains/platform/workflow/analysis/index.js";
import { getFormSpecification } from "../../../domains/bill/tools.js";
import { stringOption } from "../../parser.js";
import { stringOption, booleanOption } from "../../parser.js";
import { printJson, printTable, printKeyValue } from "../../printer.js";
import type { CliParsedArgs, CliResult, CliRuntime } from "../../types.js";
import { createWorkflowDetailClient } from "./shared.js";
@@ -39,19 +39,44 @@ export async function handleAnalyze(parsed: CliParsedArgs, runtime: CliRuntime):
}
const result = analyzeWorkflow(detail, { specifications, availableNodeTypes });
if (runtime.jsonMode) return { stdout: printJson(result, runtime.outputOptions), stderr: "", exitCode: 0 };
const diagnosticRows = result.diagnostics.map((item) => [item.severity, item.code, item.path, item.message]);
const failOnAlert = booleanOption(parsed.options, ["fail", "fail-on-alert", "failOnAlert"]);
const exitCode = failOnAlert && !result.summary.passed ? 2 : 0;
if (runtime.jsonMode) return { stdout: printJson(result, runtime.outputOptions), stderr: "", exitCode };
const gateDecision =
result.summary.hardBlocks > 0
? `❌ 发现 ${result.summary.hardBlocks} 项硬门禁阻断 (禁止发布上线)`
: result.summary.softAdvices > 0
? `⚠️ 硬门禁全通过,存在 ${result.summary.softAdvices} 项优化建议`
: "✅ 全部门禁通过,可安全发布上线";
const diagnosticRows = result.diagnostics.map((item) => [
item.category === "hard_block" ? "⛔ 硬门禁" : "💡 软建议",
item.severity,
item.code,
item.path,
item.message,
]);
const dependencyRows = result.dependencies.map((item) => [item.path, item.taskType, item.references.join(", ")]);
return { stdout: [
`====== 工作流静态分析 (${detail.label || detail.id}) ======`,
printKeyValue({
"工作流 ID": detail.id,
"状态": detail.state === 1 ? "🟢 启用 (state=1)" : "⚪ 停用/草稿 (state=0)",
"根节点数": result.ast.length,
"依赖节点数": result.dependencies.length,
"诊断数": result.diagnostics.length,
}),
`\n依赖引用:\n${dependencyRows.length ? printTable(["节点路径", "类型", "引用"], dependencyRows) : "暂无代码引用"}`,
`\n诊断:\n${diagnosticRows.length ? printTable(["级别", "代码", "节点路径", "说明"], diagnosticRows) : "未发现明显配置问题"}`, "",
].join("\n"), stderr: "", exitCode: 0 };
return {
stdout: [
`====== 工作流静态分析 (${detail.label || detail.id}) ======`,
printKeyValue({
"工作流 ID": detail.id,
"状态": detail.state === 1 ? "🟢 启用 (state=1)" : "⚪ 停用/草稿 (state=0)",
"门禁裁决": gateDecision,
"硬门禁数": `${result.summary.hardBlocks} 项 (致命配置/无权限/崩溃)`,
"软建议数": `${result.summary.softAdvices} 项 (规范与最佳实践)`,
"根节点数": result.ast.length,
"依赖节点数": result.dependencies.length,
}),
`\n依赖引用:\n${dependencyRows.length ? printTable(["节点路径", "类型", "引用"], dependencyRows) : "暂无代码引用"}`,
`\n诊断列表 (硬门禁 ⛔ / 软建议 💡):\n${diagnosticRows.length ? printTable(["分类", "级别", "代码", "节点路径", "说明"], diagnosticRows) : "未发现明显配置问题"}`,
"",
].join("\n"),
stderr: "",
exitCode,
};
}