Merge origin/main and preserve debug safeguards across trigger paths

This commit is contained in:
gitea committed 2026-10-15 14:56:11 +08:00
commit b605d7c2bb
7 files changed
+569 -61

No files matched your search

+246
View File
@@ -753,4 +753,250 @@ describe("CLI - workflow job 执行详情与异常精准透视", () => {
expect(res.stdout).toContain("特权调测通道");
expect(res.stdout).toContain("job_prod_999");
});
it("handles workflow test for clock trigger without requiring --flow", async () => {
const mockClient = {
get: (url: string) => {
if (url.includes("/level/failed")) return { json: async () => ({ code: 200, data: [] }) };
if (url.includes("api/easo/pipelines/")) {
return {
json: async () => ({
code: 200,
data: {
id: "wf_clock_1",
label: "定时摊销工作流",
state: 0,
tasks: [
{ id: "t1", name: "trigger_1", label: "定时触发", type: "clock" },
],
},
}),
};
}
if (url.includes("execution")) {
return {
json: async () => ({
code: 200,
data: [
{
id: "e1",
name: "trigger_1",
label: "定时触发",
type: "clock",
status: "COMPLETED",
},
],
}),
};
}
return {
json: async () => ({
code: 200,
data: {
id: "job_clock_101",
pipelineId: "wf_clock_1",
status: "COMPLETED",
runType: "DEBUG",
},
}),
};
},
post: () => ({ json: async () => ({ code: 200, data: "job_clock_101" }) }),
};
spies.push(
spyOn(helpers, "createClientsForCorp").mockResolvedValue({
ekbClient: mockClient as any,
easoClient: mockClient as any,
corp: mockCorp,
} as any)
);
spies.push(
spyOn(helpers, "createPiperClientForCorp").mockResolvedValue(mockClient as any)
);
// 未传 --flow,也无需报错,直接派发执行
const res = await handleWorkflowCommand(
{
area: "workflow",
action: "test",
args: ["wf_clock_1"],
options: { platformId: "p1", yes: true },
raw: ["workflow", "test", "wf_clock_1", "--platform-id=p1"],
},
mockRuntime
);
expect(res.exitCode).toBe(0);
expect(res.stdout).toContain("[SCHEDULE]");
expect(res.stdout).toContain("定时调度模拟触发");
expect(res.stdout).toContain("job_clock_101");
});
it("handles workflow test for webhook trigger requiring body or empty", async () => {
const mockClient = {
get: (url: string) => {
if (url.includes("/level/failed")) return { json: async () => ({ code: 200, data: [] }) };
if (url.includes("api/easo/pipelines/")) {
return {
json: async () => ({
code: 200,
data: {
id: "wf_webhook_1",
label: "外部回调工作流",
state: 0,
tasks: [
{ id: "t1", name: "trigger_1", label: "Webhook触发器", type: "webhook" },
],
},
}),
};
}
if (url.includes("execution")) {
return {
json: async () => ({
code: 200,
data: [
{
id: "e1",
name: "trigger_1",
label: "Webhook触发器",
type: "webhook",
status: "COMPLETED",
},
],
}),
};
}
return {
json: async () => ({
code: 200,
data: {
id: "job_webhook_202",
pipelineId: "wf_webhook_1",
status: "COMPLETED",
runType: "DEBUG",
},
}),
};
},
post: () => ({ json: async () => ({ code: 200, data: "job_webhook_202" }) }),
};
spies.push(
spyOn(helpers, "createClientsForCorp").mockResolvedValue({
ekbClient: mockClient as any,
easoClient: mockClient as any,
corp: mockCorp,
} as any)
);
spies.push(
spyOn(helpers, "createPiperClientForCorp").mockResolvedValue(mockClient as any)
);
// 1. 未传 body 时提示参数说明
const noBodyRes = await handleWorkflowCommand(
{
area: "workflow",
action: "test",
args: ["wf_webhook_1"],
options: { platformId: "p1" },
raw: ["workflow", "test", "wf_webhook_1", "--platform-id=p1"],
},
mockRuntime
);
expect(noBodyRes.exitCode).toBe(1);
expect(noBodyRes.stdout).toContain("外部事件触发器");
expect(noBodyRes.stdout).toContain("--body");
// 2. 传入 --body 成功派发
const withBodyRes = await handleWorkflowCommand(
{
area: "workflow",
action: "test",
args: ["wf_webhook_1"],
options: { body: '{"code":"XM-001"}', platformId: "p1", yes: true },
raw: ["workflow", "test", "wf_webhook_1", '--body={"code":"XM-001"}', "--platform-id=p1"],
},
mockRuntime
);
expect(withBodyRes.exitCode).toBe(0);
expect(withBodyRes.stdout).toContain("[WEBHOOK]");
expect(withBodyRes.stdout).toContain("Webhook Payload");
});
it("handles workflow test for datalink trigger displaying dynamic fields", async () => {
const mockClient = {
get: (url: string) => {
if (url.includes("/level/failed")) return { json: async () => ({ code: 200, data: [] }) };
if (url.includes("api/easo/pipelines/")) {
return {
json: async () => ({
code: 200,
data: {
id: "wf_datalink_1",
label: "合同台账生成单据",
state: 0,
tasks: [
{ id: "t1", name: "trigger_1", label: "新增业务对象数据时触发", type: "ekuaibao-datalink-create-trigger" },
],
},
}),
};
}
return { json: async () => ({ code: 200, data: null }) };
},
post: (url: string) => {
if (url.includes("debugSource")) {
return {
json: async () => ({
code: 200,
data: {
type: "dataLink",
total: 1,
label: "合同台账",
fields: [
{ key: "contractName", label: "合同名称" },
{ key: "owner", label: "负责人" },
],
items: [
{ id: "rec_123", contractName: "年度办公租赁合同", owner: "张三" },
],
},
}),
};
}
return { json: async () => ({ code: 200, data: null }) };
},
};
spies.push(
spyOn(helpers, "createClientsForCorp").mockResolvedValue({
ekbClient: mockClient as any,
easoClient: mockClient as any,
corp: mockCorp,
} as any)
);
spies.push(
spyOn(helpers, "createPiperClientForCorp").mockResolvedValue(mockClient as any)
);
const res = await handleWorkflowCommand(
{
area: "workflow",
action: "test",
args: ["wf_datalink_1"],
options: { platformId: "p1" },
raw: ["workflow", "test", "wf_datalink_1", "--platform-id=p1"],
},
mockRuntime
);
expect(res.exitCode).toBe(1);
expect(res.stdout).toContain("合同台账");
expect(res.stdout).toContain("合同名称");
expect(res.stdout).toContain("年度办公租赁合同");
expect(res.stdout).toContain("张三");
expect(res.stdout).toContain("--record=");
});
});