fix: harden CLI parsing, MCP startup and release integrity
This commit is contained in:
1 parent
f0902f5f20
commit
103ead0fe5
53 files changed
+3713
-1945
No files matched your search
@@ -0,0 +1,168 @@
|
||||
import { describe, expect, it } from "bun:test";
|
||||
import { analyzeWorkflow } from "./index.js";
|
||||
import { PlatformSchema } from "../../types.js";
|
||||
|
||||
describe("Workflow static analysis", () => {
|
||||
it("accepts nullable app center metadata", () => {
|
||||
const platform = PlatformSchema.parse({ id: "app-1", name: "测试应用", corporationId: "corp-1", adminIds: null, importMethod: null });
|
||||
expect(platform.adminIds).toEqual([]);
|
||||
expect(platform.importMethod).toEqual([]);
|
||||
});
|
||||
|
||||
it("builds a recursive AST and extracts code references", () => {
|
||||
const result = analyzeWorkflow({ id: "wf-1", label: "审批", state: 1, version: "3", tasks: [{ name: "条件", type: "condition", label: "条件", groupName: "", orderIndex: 0, levelIndex: [0], status: "", tasks: [{ name: "脚本", type: "code-js2", label: "脚本", groupName: "", orderIndex: 1, levelIndex: [0, 0], status: "", code: "return {{bill.amount}} + ctx.user.id;" }] }] } as any);
|
||||
expect(result.ast[0]?.children[0]?.path).toBe("0.0"); expect(result.dependencies[0]?.references).toEqual(["bill.amount", "user.id"]); expect(result.diagnostics).toHaveLength(0);
|
||||
});
|
||||
it("reports empty scripts, branches, and disabled workflow state", () => {
|
||||
const result = analyzeWorkflow({ id: "wf-2", label: "异常", state: 0, version: "", tasks: [{ name: "脚本", type: "code", label: "", groupName: "", orderIndex: 0, levelIndex: [0], status: "", code: "" }, { name: "条件", type: "condition", label: "", groupName: "", orderIndex: 1, levelIndex: [1], status: "", tasks: [] }] } as any);
|
||||
expect(result.diagnostics.map((item) => item.code)).toEqual(["WORKFLOW_DISABLED", "EMPTY_CODE", "EMPTY_BRANCH"]);
|
||||
});
|
||||
|
||||
it("detects UNSAFE_SKIP_WITHOUT_STATUS_GUARD and LINKAGE_PRIORITY_OVERRIDE", () => {
|
||||
const wf = {
|
||||
id: "886351399301758976",
|
||||
label: "【生产】每30分钟创建采购申请单",
|
||||
state: 1,
|
||||
version: "10",
|
||||
tasks: [
|
||||
{
|
||||
name: "every_0",
|
||||
type: "every",
|
||||
label: "循环每条支付计划",
|
||||
groupName: "control",
|
||||
orderIndex: 1,
|
||||
levelIndex: [0],
|
||||
status: "",
|
||||
tasks: [
|
||||
{
|
||||
name: "ekuaibao_flow_create_task_0",
|
||||
type: "flow-create-task",
|
||||
label: "创建预付申请单",
|
||||
groupName: "ekuaibao",
|
||||
orderIndex: 0,
|
||||
levelIndex: [0, 0],
|
||||
status: "",
|
||||
onError: { defaultAction: "SKIP" },
|
||||
inputs: {
|
||||
specificationId: "ID01TxgE3fhD6n",
|
||||
form: {
|
||||
u_关联合同流程: "{{every_0.item.E_contract}}",
|
||||
u_我方签约主体: "{{every_0.item.E_company}}",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "ekuaibao_datalink_edit_0",
|
||||
type: "ekuaibao-datalink-edit",
|
||||
label: "更新支付计划状态为创建成功",
|
||||
groupName: "ekuaibao",
|
||||
orderIndex: 1,
|
||||
levelIndex: [0, 1],
|
||||
status: "",
|
||||
inputs: {
|
||||
dataLinkId: "{{every_0.item.id}}",
|
||||
form: {
|
||||
状态: "创建成功",
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const specifications = {
|
||||
ID01TxgE3fhD6n: {
|
||||
id: "ID01TxgE3fhD6n",
|
||||
name: "预付申请单",
|
||||
form: [
|
||||
{
|
||||
id: "f1",
|
||||
name: "u_关联合同流程",
|
||||
label: "关联合同流程",
|
||||
type: "dataLink",
|
||||
optional: false,
|
||||
entityId: "e23d0d5451b1ccabfd7a",
|
||||
assignmentRule: "ID01TRWvYFAulh",
|
||||
isLinkageAssignment: false,
|
||||
priorityList: [
|
||||
{ type: "LINKAGE_ASSIGNMENT", priority: 10 },
|
||||
{ type: "MANUALLY_FILL_IN", priority: 5 },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "f2",
|
||||
name: "u_我方签约主体",
|
||||
label: "我方签约主体",
|
||||
type: "dimension",
|
||||
optional: false,
|
||||
isLinkageAssignment: true,
|
||||
priorityList: [
|
||||
{ type: "LINKAGE_ASSIGNMENT", priority: 10 },
|
||||
{ type: "MANUALLY_FILL_IN", priority: 5 },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
const result = analyzeWorkflow(wf as any, { specifications: specifications as any });
|
||||
const codes = result.diagnostics.map((d) => d.code);
|
||||
expect(codes).toContain("UNSAFE_SKIP_WITHOUT_STATUS_GUARD");
|
||||
expect(codes).toContain("LINKAGE_PRIORITY_OVERRIDE");
|
||||
});
|
||||
|
||||
it("detects DEADLOCK_TRIGGER_STATE_FILTER when trigger specifies state APPROVING", () => {
|
||||
const wf = {
|
||||
id: "wf-trigger-deadlock",
|
||||
label: "资金调拨自动审批",
|
||||
state: 1,
|
||||
version: "1",
|
||||
tasks: [
|
||||
{
|
||||
name: "trigger_1",
|
||||
type: "ekuaibao-flowform-trigger",
|
||||
label: "单据审批事件触发器",
|
||||
combineFilters: {
|
||||
filters: [
|
||||
{
|
||||
filters: [
|
||||
{ key: "formSpecification", value: "ID01RUq5zrhZTh", compare: "eq" },
|
||||
{ key: "state", value: "APPROVING", compare: "eq" },
|
||||
],
|
||||
condition: "and",
|
||||
},
|
||||
],
|
||||
condition: "or",
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
const result = analyzeWorkflow(wf as any);
|
||||
const codes = result.diagnostics.map((d) => d.code);
|
||||
expect(codes).toContain("DEADLOCK_TRIGGER_STATE_FILTER");
|
||||
expect(result.diagnostics.find((d) => d.code === "DEADLOCK_TRIGGER_STATE_FILTER")?.severity).toBe("error");
|
||||
});
|
||||
|
||||
it("detects MISSING_BACKLOG_DATA_BRACKETS on backlog openapi http task", () => {
|
||||
const wf = {
|
||||
id: "wf-http-no-brackets",
|
||||
label: "自动审批",
|
||||
state: 1,
|
||||
version: "1",
|
||||
tasks: [
|
||||
{
|
||||
name: "action_1",
|
||||
type: "http",
|
||||
label: "审批接口调用",
|
||||
url: "https://app.ekuaibao.com/api/openapi/v1/backlog/data/ID01X4mbLfjvpt",
|
||||
},
|
||||
],
|
||||
};
|
||||
const result = analyzeWorkflow(wf as any);
|
||||
const codes = result.diagnostics.map((d) => d.code);
|
||||
expect(codes).toContain("MISSING_BACKLOG_DATA_BRACKETS");
|
||||
expect(result.diagnostics.find((d) => d.code === "MISSING_BACKLOG_DATA_BRACKETS")?.severity).toBe("warning");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user