feat(workflow): implement real-time workflow tail and watch commands
This commit is contained in:
1 parent
71f9879f68
commit
53201ba4e1
11 files changed
+1310
-7
No files matched your search
@@ -1683,4 +1683,141 @@ describe("CLI - workflow job 执行详情与异常精准透视", () => {
|
||||
)
|
||||
).rejects.toThrow("触发源节点");
|
||||
});
|
||||
|
||||
it("handles workflow tail and watch commands for real-time streaming and snapshots", async () => {
|
||||
// 1. Missing target -> usage
|
||||
const noArgRes = await handleWorkflowCommand(
|
||||
{
|
||||
area: "workflow",
|
||||
action: "tail",
|
||||
args: [],
|
||||
options: {},
|
||||
raw: ["workflow", "tail"],
|
||||
},
|
||||
mockRuntime
|
||||
);
|
||||
expect(noArgRes.exitCode).toBe(1);
|
||||
expect(noArgRes.stderr).toContain("用法: hose-use workflow tail");
|
||||
|
||||
const mockJobDetail = {
|
||||
id: "job_tail_101",
|
||||
pipelineId: "pipe_tail_test",
|
||||
label: "实时监控流程",
|
||||
status: "COMPLETED",
|
||||
runType: "DEBUG",
|
||||
durationTime: 850,
|
||||
successTaskCount: 2,
|
||||
errorTaskCount: 0,
|
||||
hasError: false,
|
||||
};
|
||||
|
||||
const mockExecutions = [
|
||||
{
|
||||
id: "ex_node_1",
|
||||
name: "trigger_webhook",
|
||||
label: "发票接入",
|
||||
type: "webhook",
|
||||
status: "COMPLETED",
|
||||
executionTime: 15,
|
||||
},
|
||||
{
|
||||
id: "ex_node_2",
|
||||
name: "action_clean",
|
||||
label: "数据清洗",
|
||||
type: "code-js2",
|
||||
status: "COMPLETED",
|
||||
executionTime: 120,
|
||||
},
|
||||
];
|
||||
|
||||
const mockClient = {
|
||||
get: (url: string) => {
|
||||
if (url.includes("api/easo/pipelines/pipe_tail_test/log")) {
|
||||
return {
|
||||
json: async () => ({
|
||||
code: 200,
|
||||
data: {
|
||||
jobList: [{ jobId: "job_tail_101", status: "COMPLETED" }],
|
||||
},
|
||||
}),
|
||||
};
|
||||
}
|
||||
if (url.includes("api/easo/jobs/running")) {
|
||||
return { json: async () => ({ code: 200, data: [] }) };
|
||||
}
|
||||
if (url.includes("api/easo/jobs/job_tail_101/execution/level/failed")) {
|
||||
return { json: async () => ({ code: 200, data: { items: [] } }) };
|
||||
}
|
||||
if (url.includes("api/easo/jobs/job_tail_101/execution")) {
|
||||
return { json: async () => ({ code: 200, data: mockExecutions }) };
|
||||
}
|
||||
if (url.includes("api/easo/jobs/job_tail_101")) {
|
||||
return { json: async () => ({ code: 200, data: mockJobDetail }) };
|
||||
}
|
||||
if (url.includes("api/easo/pipelines/pipe_tail_test")) {
|
||||
return { json: async () => ({ code: 200, data: { id: "pipe_tail_test", label: "实时监控流程" } }) };
|
||||
}
|
||||
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)
|
||||
);
|
||||
|
||||
// 2. tail --once snapshot
|
||||
const onceRes = await handleWorkflowCommand(
|
||||
{
|
||||
area: "workflow",
|
||||
action: "tail",
|
||||
args: ["pipe_tail_test"],
|
||||
options: { once: true },
|
||||
raw: ["workflow", "tail", "pipe_tail_test", "--once"],
|
||||
},
|
||||
mockRuntime
|
||||
);
|
||||
expect(onceRes.exitCode).toBe(0);
|
||||
expect(onceRes.stdout).toContain("trigger_webhook");
|
||||
expect(onceRes.stdout).toContain("action_clean");
|
||||
expect(onceRes.stdout).toContain("Job [job_tail_101] 执行结束");
|
||||
|
||||
// 3. tail --once --json
|
||||
const onceJsonRes = await handleWorkflowCommand(
|
||||
{
|
||||
area: "workflow",
|
||||
action: "tail",
|
||||
args: ["pipe_tail_test"],
|
||||
options: { once: true },
|
||||
raw: ["workflow", "tail", "pipe_tail_test", "--once"],
|
||||
},
|
||||
{ ...mockRuntime, jsonMode: true }
|
||||
);
|
||||
expect(onceJsonRes.exitCode).toBe(0);
|
||||
const parsedReport = JSON.parse(onceJsonRes.stdout);
|
||||
expect(parsedReport.totalJobsWatched).toBe(1);
|
||||
expect(parsedReport.jobs[0].jobId).toBe("job_tail_101");
|
||||
expect(parsedReport.jobs[0].successCount).toBe(2);
|
||||
|
||||
// 4. watch alias targeting specific job
|
||||
const watchJobRes = await handleWorkflowCommand(
|
||||
{
|
||||
area: "workflow",
|
||||
action: "watch",
|
||||
args: ["pipe_tail_test"],
|
||||
options: { job: "job_tail_101", interval: 1, once: true },
|
||||
raw: ["workflow", "watch", "pipe_tail_test", "--job=job_tail_101", "--once"],
|
||||
},
|
||||
mockRuntime
|
||||
);
|
||||
expect(watchJobRes.exitCode).toBe(0);
|
||||
expect(watchJobRes.stdout).toContain("Job [job_tail_101]");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user