feat(workflow): add end-to-end workflow debug test command and condition branch explanation
This commit is contained in:
1 parent
26a6b7318c
commit
fe6183dd44
13 files changed
+1026
-3
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { KyInstance } from "ky";
|
||||
import { CorpConfig } from "../../core/config/types.js";
|
||||
import * as api from "./api.js";
|
||||
import { explainConditionBranches } from "./workflow-branch.js";
|
||||
import {
|
||||
Platform,
|
||||
WorkflowSummary,
|
||||
@@ -645,3 +646,103 @@ export function diffWorkflowJobs(
|
||||
};
|
||||
}
|
||||
|
||||
export function getWorkflowDebugSource(...args: Parameters<typeof api.getWorkflowDebugSource>) {
|
||||
return api.getWorkflowDebugSource(...args);
|
||||
}
|
||||
|
||||
export function triggerWorkflowDebug(...args: Parameters<typeof api.triggerWorkflowDebug>) {
|
||||
return api.triggerWorkflowDebug(...args);
|
||||
}
|
||||
|
||||
export async function runWorkflowDebugTest(
|
||||
client: import("ky").KyInstance,
|
||||
pipelineId: string,
|
||||
options: {
|
||||
flowCodeOrId: string;
|
||||
autoPublish?: boolean;
|
||||
timeoutMs?: number;
|
||||
pollIntervalMs?: number;
|
||||
}
|
||||
): Promise<import("./types.js").WorkflowTestReport> {
|
||||
let targetEntityId = options.flowCodeOrId;
|
||||
const isDirectCode = options.flowCodeOrId.includes("-") || options.flowCodeOrId.startsWith("ID01");
|
||||
if (!isDirectCode) {
|
||||
try {
|
||||
const source = await api.getWorkflowDebugSource(client, pipelineId, {
|
||||
page: 1,
|
||||
pageSize: 10,
|
||||
keywords: options.flowCodeOrId,
|
||||
});
|
||||
const matched = source.items.find(
|
||||
(item) => item.id === options.flowCodeOrId || item.title.includes(options.flowCodeOrId)
|
||||
);
|
||||
if (matched) {
|
||||
targetEntityId = matched.id;
|
||||
}
|
||||
} catch {
|
||||
// 关键字搜索超时或失败时直接回退使用传入值
|
||||
}
|
||||
}
|
||||
|
||||
const jobId = await api.triggerWorkflowDebug(client, pipelineId, {
|
||||
entityId: targetEntityId,
|
||||
autoPublish: options.autoPublish ?? false,
|
||||
});
|
||||
|
||||
const timeoutMs = options.timeoutMs ?? 15000;
|
||||
const pollIntervalMs = options.pollIntervalMs ?? 500;
|
||||
const start = Date.now();
|
||||
|
||||
let finalJob: import("./types.js").WorkflowJobDetail | undefined;
|
||||
|
||||
while (Date.now() - start < timeoutMs) {
|
||||
try {
|
||||
const job = await api.getJob(client, jobId);
|
||||
const state = (job.status || (job as any).state || "").toUpperCase();
|
||||
if (state === "COMPLETED" || state === "FAILED" || state === "STOP") {
|
||||
finalJob = job;
|
||||
break;
|
||||
}
|
||||
} catch {
|
||||
// 任务刚创建可能存在短延时,继续轮询
|
||||
}
|
||||
await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
|
||||
}
|
||||
|
||||
if (!finalJob) {
|
||||
finalJob = await api.getJob(client, jobId);
|
||||
}
|
||||
|
||||
const [tree, failedPage] = await Promise.all([
|
||||
api.getJobExecutionTree(client, jobId).catch(() => []),
|
||||
api.getJobFailedExecutions(client, jobId).catch(() => ({
|
||||
number: 1,
|
||||
size: 100,
|
||||
totalPages: 0,
|
||||
totalItems: 0,
|
||||
items: [],
|
||||
})),
|
||||
]);
|
||||
|
||||
const rawFailed = extractFailureExecutions(tree, failedPage.items);
|
||||
const conditionDiagnoses = explainConditionBranches(tree);
|
||||
|
||||
return {
|
||||
jobId,
|
||||
pipelineId,
|
||||
status: finalJob.status || (finalJob as any).state || "UNKNOWN",
|
||||
runType: finalJob.runType || "DEBUG",
|
||||
durationTime: typeof (finalJob as any).durationTime === "number" ? (finalJob as any).durationTime : undefined,
|
||||
targetEntityId,
|
||||
executionTree: tree,
|
||||
failedExecutions: rawFailed,
|
||||
conditionDiagnoses,
|
||||
};
|
||||
}
|
||||
|
||||
export {
|
||||
explainConditionBranches,
|
||||
type ConditionBranchExplanation,
|
||||
type ConditionRuleExplanation,
|
||||
} from "./workflow-branch.js";
|
||||
|
||||
Reference in new issue
Block a user