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

+58
View File
@@ -228,4 +228,62 @@ describe("CLI - workflow nodes 字典探针与灰度开通测试", () => {
expect(result.success).toBe(true);
expect(grantSpy).toHaveBeenCalled();
});
it("workflow analyze: 显式输出硬门禁与软建议边界,且支持 --fail 退出码门禁", async () => {
spies.push(
spyOn(helpers, "createClientsForCorp").mockResolvedValue({
ekbClient: {},
easoClient: {},
} as any),
spyOn(helpers, "createPiperClientForCorp").mockResolvedValue({} as any),
spyOn(services, "getWorkflowDetail").mockResolvedValue({
id: "wf-gate-test",
label: "门禁测试流程",
state: 0,
version: "1",
tasks: [
{
name: "bad_node",
type: "code-js2",
label: "未开通JS2节点",
code: "return 1;",
},
],
} as any),
spyOn(services, "getWorkflowAvailableNodes").mockResolvedValue({
allTypes: new Set(["http", "code"]),
catalog: { action: [], control: [], trigger: [] },
} as any)
);
// 1. 常规运行(无 --fail):展示门禁裁决,exitCode 为 0
const normalRes = await handleWorkflowCommand(
{
action: "analyze",
args: ["wf-gate-test"],
options: {},
raw: ["workflow", "analyze", "wf-gate-test"],
},
mockRuntime
);
expect(normalRes.exitCode).toBe(0);
expect(normalRes.stdout).toContain("门禁裁决");
expect(normalRes.stdout).toContain("硬门禁数");
expect(normalRes.stdout).toContain("软建议数");
expect(normalRes.stdout).toContain("⛔ 硬门禁");
expect(normalRes.stdout).toContain("💡 软建议");
expect(normalRes.stdout).toContain("PERMISSION_MISSING_NODE");
// 2. 带 --fail 运行:检测到硬门禁,exitCode 为 2
const failRes = await handleWorkflowCommand(
{
action: "analyze",
args: ["wf-gate-test"],
options: { fail: true },
raw: ["workflow", "analyze", "wf-gate-test", "--fail"],
},
mockRuntime
);
expect(failRes.exitCode).toBe(2);
});
});
+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,
};
}