feat(workflow): 准确识别工作流延时执行与在途运行状态并补全节点字典

This commit is contained in:
gitea committed 2026-10-21 17:21:35 +08:00
1 parent 36a4d3b27b
commit aea30fbcd5
15 files changed
+615 -78

No files matched your search

+178
View File
@@ -1989,5 +1989,183 @@ describe("CLI - workflow job 执行详情与异常精准透视", () => {
expect(wfEvalRes.stdout).toContain("执行成功 ✅");
expect(wfEvalRes.stdout).toContain('"total": 100');
});
it("workflow logs correctly detects and formats running/delayed jobs and in-progress count", async () => {
const mockDetail = {
id: "pipe_delay_test",
pipelineName: "审批延时测试流程",
state: 1,
tasks: [
{ name: "trigger_1", type: "clock", label: "定时触发" },
{ name: "action_delay_1", type: "task-dynamic-delay", label: "延时等待节点", sleepTime: 60 },
{ name: "action_js_1", type: "code-js2", label: "通知节点" },
],
};
const mockLogs = {
executeCount: 3,
successCount: 2,
errorCount: 0,
number: 1,
size: 10,
totalPages: 1,
totalItems: 3,
jobList: [
{
state: 0,
jobName: "审批延时测试流程",
jobId: "job_running_001",
executeTime: "2026-10-21 17:15:00",
status: "STARTED",
runType: "DEBUG",
successTaskCount: 1,
errorTaskCount: 0,
hasError: "不存在",
},
{
state: 0,
jobName: "审批延时测试流程",
jobId: "job_completed_002",
executeTime: "2026-10-21 17:10:00",
status: "COMPLETED",
runType: "DEBUG",
successTaskCount: 3,
errorTaskCount: 0,
hasError: "不存在",
},
],
};
const mockClient = {
get: (url: string) => ({
json: async () => {
if (url.includes("/log")) return { code: 200, data: mockLogs };
return { code: 200, data: mockDetail };
},
}),
};
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. All logs view
const allLogsRes = await handleWorkflowCommand(
{
area: "workflow",
action: "logs",
args: ["pipe_delay_test"],
options: {},
raw: ["workflow", "logs", "pipe_delay_test"],
},
mockRuntime
);
expect(allLogsRes.exitCode).toBe(0);
expect(allLogsRes.stdout).toContain("运行中/延时");
expect(allLogsRes.stdout).toContain("1 (正在执行或延时等待中)");
expect(allLogsRes.stdout).toContain("⏳ 运行中");
expect(allLogsRes.stdout).toContain("✅ 已完成");
expect(allLogsRes.stdout).toContain("⏳ 执行中");
// 2. Client-side filtering by --state=RUNNING
const runningOnlyRes = await handleWorkflowCommand(
{
area: "workflow",
action: "logs",
args: ["pipe_delay_test"],
options: { state: "RUNNING" },
raw: ["workflow", "logs", "pipe_delay_test", "--state=RUNNING"],
},
mockRuntime
);
expect(runningOnlyRes.exitCode).toBe(0);
expect(runningOnlyRes.stdout).toContain("job_running_001");
expect(runningOnlyRes.stdout).not.toContain("job_completed_002");
});
it("workflow job correctly displays mid-flight delayed job progress and non-interruptive hints", async () => {
const mockDetail = {
id: "pipe_delay_test",
pipelineName: "审批延时测试流程",
state: 1,
tasks: [
{ name: "trigger_1", type: "clock", label: "定时触发" },
{ name: "action_delay_1", type: "task-dynamic-delay", label: "延时等待节点", sleepTime: 60 },
{ name: "action_js_1", type: "code-js2", label: "通知节点" },
],
};
const mockRunningJob = {
id: "job_running_001",
pipelineId: "pipe_delay_test",
status: "STARTED",
state: 0,
startTime: 1792574000000,
};
const mockExecutionTree = [
{ id: "exec_1", name: "trigger_1", label: "定时触发", type: "clock", status: "COMPLETED", durationTime: 10 },
{ id: "exec_2", name: "action_delay_1", label: "延时等待节点", type: "task-dynamic-delay", status: "STARTED" },
];
const mockClient = {
get: (url: string) => ({
json: async () => {
if (url.includes("/execution")) return { code: 200, data: mockExecutionTree };
if (url.includes("/failed")) return { code: 200, data: { items: [] } };
if (url.includes("/jobs/job_running_001")) return { code: 200, data: mockRunningJob };
return { code: 200, data: mockDetail };
},
}),
};
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. Overview view
const jobRes = await handleWorkflowCommand(
{
area: "workflow",
action: "job",
args: ["job_running_001"],
options: {},
raw: ["workflow", "job", "job_running_001"],
},
mockRuntime
);
expect(jobRes.exitCode).toBe(0);
expect(jobRes.stdout).toContain("⏳ 运行中 (STARTED)");
expect(jobRes.stdout).toContain("当前正在执行第 2 步(延时等待中或任务处理中)");
expect(jobRes.stdout).not.toContain("本次调度在第 2 步中断");
expect(jobRes.stdout).toContain("⏳ 延时等待中");
// 2. Timeline view
const timelineRes = await handleWorkflowCommand(
{
area: "workflow",
action: "job",
args: ["job_running_001"],
options: { timeline: true },
raw: ["workflow", "job", "job_running_001", "--timeline"],
},
mockRuntime
);
expect(timelineRes.exitCode).toBe(0);
expect(timelineRes.stdout).toContain("✅ 已完成");
expect(timelineRes.stdout).toContain("⏳ 延时等待中");
expect(timelineRes.stdout).toContain("⏳ 等待前序步骤执行完成");
expect(timelineRes.stdout).not.toContain("因前序步骤中断");
});
});