refactor: 拆分工作流执行查询与差异计算
This commit is contained in:
1 parent
c989e544e4
commit
22bd7a9995
10 files changed
+348
-338
No files matched your search
@@ -1,3 +1,3 @@
|
||||
# 工作流差异比较
|
||||
|
||||
[diff.ts](./diff.ts) 比较工作流配置快照和 Job 执行结果;执行实例索引来自同级 [execution](../execution/README.execution.md)。比较为纯本地计算,不发起请求或修改工作流。
|
||||
[diff.ts](./diff.ts) 保留差异比较出口:[snapshot.ts](./snapshot.ts) 比较配置快照,[job.ts](./job.ts) 比较 Job 执行结果,[text.ts](./text.ts) 生成文本差异。执行实例索引来自同级 [execution](../execution/README.execution.md)。比较为纯本地计算,不发起请求或修改工作流。
|
||||
@@ -1,298 +1,3 @@
|
||||
import { indexExecutionContexts } from "../execution/context.js";
|
||||
import { WorkflowTask, WorkflowTaskExecution, WorkflowSnapshot, WorkflowSnapshotDiff, TaskConfigDiff, WorkflowJobDetail, WorkflowJobDiff, NodeExecutionDiff } from "../types.js";
|
||||
import { flattenWorkflowTasks } from "../execution/tree.js";
|
||||
|
||||
|
||||
/**
|
||||
* 快速生成标准 Unified Diff 文本
|
||||
*/
|
||||
export function generateTextDiff(a: string, b: string, labelA = "from", labelB = "to"): string {
|
||||
if (a === b) return "";
|
||||
const linesA = a.split(/\r?\n/);
|
||||
const linesB = b.split(/\r?\n/);
|
||||
const output: string[] = [`--- ${labelA}`, `+++ ${labelB}`];
|
||||
|
||||
let start = 0;
|
||||
while (start < linesA.length && start < linesB.length && linesA[start] === linesB[start]) {
|
||||
start++;
|
||||
}
|
||||
let endA = linesA.length - 1;
|
||||
let endB = linesB.length - 1;
|
||||
while (endA >= start && endB >= start && linesA[endA] === linesB[endB]) {
|
||||
endA--;
|
||||
endB--;
|
||||
}
|
||||
|
||||
const hunkStart = Math.max(0, start - 2);
|
||||
const hunkEndA = Math.min(linesA.length, endA + 3);
|
||||
const hunkEndB = Math.min(linesB.length, endB + 3);
|
||||
|
||||
output.push(`@@ -${hunkStart + 1},${hunkEndA - hunkStart} +${hunkStart + 1},${hunkEndB - hunkStart} @@`);
|
||||
for (let i = hunkStart; i < start; i++) {
|
||||
output.push(` ${linesA[i]}`);
|
||||
}
|
||||
for (let i = start; i <= endA; i++) {
|
||||
output.push(`- ${linesA[i]}`);
|
||||
}
|
||||
for (let i = start; i <= endB; i++) {
|
||||
output.push(`+ ${linesB[i]}`);
|
||||
}
|
||||
for (let i = endA + 1; i < hunkEndA; i++) {
|
||||
output.push(` ${linesA[i]}`);
|
||||
}
|
||||
return output.join("\n");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 对比两个历史快照的节点、脚本代码(MVEL/JS)与参数配置差异
|
||||
*/
|
||||
export function diffWorkflowSnapshots(
|
||||
snapshotA: WorkflowSnapshot,
|
||||
snapshotB: WorkflowSnapshot
|
||||
): WorkflowSnapshotDiff {
|
||||
const tasksA = flattenWorkflowTasks(snapshotA.tasks);
|
||||
const tasksB = flattenWorkflowTasks(snapshotB.tasks);
|
||||
const indexPaths = (tasks: WorkflowTask[] = [], prefix = "tasks", paths = new Map<string, string>()): Map<string, string> => {
|
||||
tasks.forEach((task, i) => {
|
||||
const path = `${prefix}.${i}`;
|
||||
if (task.name) paths.set(task.name, path);
|
||||
if (task.tasks) indexPaths(task.tasks, `${path}.tasks`, paths);
|
||||
});
|
||||
return paths;
|
||||
};
|
||||
const pathsA = indexPaths(snapshotA.tasks || []);
|
||||
const pathsB = indexPaths(snapshotB.tasks || []);
|
||||
|
||||
const mapA = new Map<string, WorkflowTask>();
|
||||
for (const t of tasksA) {
|
||||
if (t?.name) mapA.set(t.name, t);
|
||||
}
|
||||
|
||||
const mapB = new Map<string, WorkflowTask>();
|
||||
for (const t of tasksB) {
|
||||
if (t?.name) mapB.set(t.name, t);
|
||||
}
|
||||
|
||||
const addedTasks: string[] = [];
|
||||
const removedTasks: string[] = [];
|
||||
const modifiedTasks: TaskConfigDiff[] = [];
|
||||
|
||||
// 1. 查找新增节点
|
||||
for (const [name, tB] of mapB) {
|
||||
if (!mapA.has(name)) {
|
||||
addedTasks.push(name);
|
||||
modifiedTasks.push({
|
||||
taskName: name,
|
||||
displayName: tB.displayName || tB.label,
|
||||
type: tB.type,
|
||||
changeType: "ADDED",
|
||||
configChanges: [],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 查找删除与修改节点
|
||||
for (const [name, tA] of mapA) {
|
||||
const tB = mapB.get(name);
|
||||
if (!tB) {
|
||||
removedTasks.push(name);
|
||||
modifiedTasks.push({
|
||||
taskName: name,
|
||||
displayName: tA.displayName || tA.label,
|
||||
type: tA.type,
|
||||
changeType: "REMOVED",
|
||||
configChanges: [],
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
// 两者均存在,深度比较配置与代码
|
||||
const configChanges: Array<{ field: string; from?: unknown; to?: unknown }> = [];
|
||||
let codeDiff: { from?: string; to?: string; unifiedDiff?: string } | undefined;
|
||||
let filterDiff: { from?: unknown; to?: unknown } | undefined;
|
||||
|
||||
// 代码脚本比较
|
||||
const codeA = typeof (tA as any).code === "string" ? (tA as any).code : undefined;
|
||||
const codeB = typeof (tB as any).code === "string" ? (tB as any).code : undefined;
|
||||
if (codeA !== codeB) {
|
||||
codeDiff = {
|
||||
from: codeA,
|
||||
to: codeB,
|
||||
unifiedDiff: generateTextDiff(
|
||||
codeA || "",
|
||||
codeB || "",
|
||||
`${snapshotA.version || snapshotA.id}`,
|
||||
`${snapshotB.version || snapshotB.id}`
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
// 过滤条件比较 (combineFilters / filters)
|
||||
const filtersA = (tA as any).combineFilters ?? (tA as any).filters;
|
||||
const filtersB = (tB as any).combineFilters ?? (tB as any).filters;
|
||||
if (JSON.stringify(filtersA) !== JSON.stringify(filtersB)) {
|
||||
filterDiff = { from: filtersA, to: filtersB };
|
||||
}
|
||||
|
||||
// 关键字段变动比较
|
||||
const checkFields = [...new Set([...Object.keys(tA), ...Object.keys(tB)])]
|
||||
.filter(field => !["name", "tasks", "code", "combineFilters", "filters"].includes(field));
|
||||
if (pathsA.get(name) !== pathsB.get(name)) {
|
||||
configChanges.push({ field: "$path", from: pathsA.get(name), to: pathsB.get(name) });
|
||||
}
|
||||
for (const f of checkFields) {
|
||||
const valA = (tA as any)[f];
|
||||
const valB = (tB as any)[f];
|
||||
if (JSON.stringify(valA) !== JSON.stringify(valB)) {
|
||||
configChanges.push({ field: f, from: valA, to: valB });
|
||||
}
|
||||
}
|
||||
|
||||
if (codeDiff || filterDiff || configChanges.length > 0) {
|
||||
modifiedTasks.push({
|
||||
taskName: name,
|
||||
displayName: tB.displayName || tB.label || tA.displayName || tA.label,
|
||||
type: tB.type || tA.type,
|
||||
changeType: "MODIFIED",
|
||||
codeDiff,
|
||||
filterDiff,
|
||||
configChanges,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
snapshotA: {
|
||||
id: snapshotA.id,
|
||||
version: snapshotA.version,
|
||||
updateTime: snapshotA.updateTime,
|
||||
staffName: snapshotA.staffName || snapshotA.staffId || undefined,
|
||||
},
|
||||
snapshotB: {
|
||||
id: snapshotB.id,
|
||||
version: snapshotB.version,
|
||||
updateTime: snapshotB.updateTime,
|
||||
staffName: snapshotB.staffName || snapshotB.staffId || undefined,
|
||||
},
|
||||
addedTasks,
|
||||
removedTasks,
|
||||
modifiedTasks,
|
||||
summary: {
|
||||
totalA: tasksA.length,
|
||||
totalB: tasksB.length,
|
||||
changedCount: modifiedTasks.length,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 对比两个 Job 的执行分支、入参 Payload、下游输出及报错信息
|
||||
*/
|
||||
export function diffWorkflowJobs(
|
||||
jobA: WorkflowJobDetail,
|
||||
treeA: WorkflowTaskExecution[],
|
||||
jobB: WorkflowJobDetail,
|
||||
treeB: WorkflowTaskExecution[]
|
||||
): WorkflowJobDiff {
|
||||
const flatA = indexExecutionContexts(treeA);
|
||||
const flatB = indexExecutionContexts(treeB);
|
||||
const byKeyA = new Map(flatA.map(context => [context.key, context]));
|
||||
const byKeyB = new Map(flatB.map(context => [context.key, context]));
|
||||
const allKeys = new Set([...byKeyA.keys(), ...byKeyB.keys()]);
|
||||
|
||||
const nodes: NodeExecutionDiff[] = [];
|
||||
let divergedNodesCount = 0;
|
||||
let statusDiffCount = 0;
|
||||
|
||||
for (const key of allKeys) {
|
||||
const contextA = byKeyA.get(key);
|
||||
const contextB = byKeyB.get(key);
|
||||
const nodeA = contextA?.node;
|
||||
const nodeB = contextB?.node;
|
||||
const name = nodeB?.name || nodeA?.name || nodeB?.type || nodeA?.type || "unnamed";
|
||||
|
||||
const statusA = nodeA?.status;
|
||||
const statusB = nodeB?.status;
|
||||
const isStatusDiff = statusA !== statusB;
|
||||
if (isStatusDiff) statusDiffCount++;
|
||||
|
||||
// 比较 inputs
|
||||
const inputsDiff: Array<{ field: string; from?: unknown; to?: unknown }> = [];
|
||||
const payloadFields = (value: unknown): Record<string, unknown> => value === undefined ? {} : value !== null && typeof value === "object" ? value as Record<string, unknown> : { $value: value };
|
||||
const inA = payloadFields(nodeA?.inputs);
|
||||
const inB = payloadFields(nodeB?.inputs);
|
||||
const inputKeys = Array.from(new Set([...Object.keys(inA), ...Object.keys(inB)]));
|
||||
for (const k of inputKeys) {
|
||||
if (JSON.stringify(inA[k]) !== JSON.stringify(inB[k])) {
|
||||
inputsDiff.push({ field: k, from: inA[k], to: inB[k] });
|
||||
}
|
||||
}
|
||||
|
||||
// 比较 outputs
|
||||
const outputsDiff: Array<{ field: string; from?: unknown; to?: unknown }> = [];
|
||||
const outA = payloadFields(nodeA?.outputs ?? nodeA?.output);
|
||||
const outB = payloadFields(nodeB?.outputs ?? nodeB?.output);
|
||||
const outputKeys = Array.from(new Set([...Object.keys(outA), ...Object.keys(outB)]));
|
||||
for (const k of outputKeys) {
|
||||
if (JSON.stringify(outA[k]) !== JSON.stringify(outB[k])) {
|
||||
outputsDiff.push({ field: k, from: outA[k], to: outB[k] });
|
||||
}
|
||||
}
|
||||
|
||||
const isDiverged =
|
||||
!nodeA ||
|
||||
!nodeB ||
|
||||
isStatusDiff ||
|
||||
JSON.stringify(nodeA.error) !== JSON.stringify(nodeB.error) ||
|
||||
inputsDiff.length > 0 || outputsDiff.length > 0;
|
||||
|
||||
if (isDiverged) divergedNodesCount++;
|
||||
|
||||
nodes.push({
|
||||
taskName: name,
|
||||
instanceKey: key,
|
||||
currentLoopPath: contextB?.loopPath || contextA?.loopPath || undefined,
|
||||
displayName: (nodeB?.displayName || nodeA?.displayName || nodeB?.label || nodeA?.label) ?? undefined,
|
||||
type: nodeB?.type || nodeA?.type,
|
||||
statusA,
|
||||
statusB,
|
||||
durationMsA: nodeA?.executionTime,
|
||||
durationMsB: nodeB?.executionTime,
|
||||
errorA: nodeA?.error,
|
||||
errorB: nodeB?.error,
|
||||
inputsDiff,
|
||||
outputsDiff,
|
||||
diverged: isDiverged,
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
jobA: {
|
||||
id: jobA.id,
|
||||
pipelineId: jobA.pipelineId,
|
||||
state: typeof jobA.state === "string" || typeof jobA.state === "number" ? jobA.state : undefined,
|
||||
startTime: jobA.startTime ? String(jobA.startTime) : undefined,
|
||||
durationTime: typeof jobA.durationTime === "number" ? jobA.durationTime : undefined,
|
||||
hasError: Boolean(jobA.hasError),
|
||||
errorCount: typeof (jobA as any).errorTaskCount === "number" ? (jobA as any).errorTaskCount : undefined,
|
||||
},
|
||||
jobB: {
|
||||
id: jobB.id,
|
||||
pipelineId: jobB.pipelineId,
|
||||
state: typeof jobB.state === "string" || typeof jobB.state === "number" ? jobB.state : undefined,
|
||||
startTime: jobB.startTime ? String(jobB.startTime) : undefined,
|
||||
durationTime: typeof jobB.durationTime === "number" ? jobB.durationTime : undefined,
|
||||
hasError: Boolean(jobB.hasError),
|
||||
errorCount: typeof (jobB as any).errorTaskCount === "number" ? (jobB as any).errorTaskCount : undefined,
|
||||
},
|
||||
nodes,
|
||||
summary: {
|
||||
totalNodesA: flatA.length,
|
||||
totalNodesB: flatB.length,
|
||||
divergedNodesCount,
|
||||
statusDiffCount,
|
||||
},
|
||||
};
|
||||
}
|
||||
export { generateTextDiff } from "./text.js";
|
||||
export { diffWorkflowSnapshots } from "./snapshot.js";
|
||||
export { diffWorkflowJobs } from "./job.js";
|
||||
@@ -0,0 +1,112 @@
|
||||
import { indexExecutionContexts } from "../execution/context.js";
|
||||
import type { WorkflowTaskExecution, WorkflowJobDetail, WorkflowJobDiff, NodeExecutionDiff } from "../types.js";
|
||||
|
||||
/**
|
||||
* 对比两个 Job 的执行分支、入参 Payload、下游输出及报错信息
|
||||
*/
|
||||
export function diffWorkflowJobs(
|
||||
jobA: WorkflowJobDetail,
|
||||
treeA: WorkflowTaskExecution[],
|
||||
jobB: WorkflowJobDetail,
|
||||
treeB: WorkflowTaskExecution[]
|
||||
): WorkflowJobDiff {
|
||||
const flatA = indexExecutionContexts(treeA);
|
||||
const flatB = indexExecutionContexts(treeB);
|
||||
const byKeyA = new Map(flatA.map(context => [context.key, context]));
|
||||
const byKeyB = new Map(flatB.map(context => [context.key, context]));
|
||||
const allKeys = new Set([...byKeyA.keys(), ...byKeyB.keys()]);
|
||||
|
||||
const nodes: NodeExecutionDiff[] = [];
|
||||
let divergedNodesCount = 0;
|
||||
let statusDiffCount = 0;
|
||||
|
||||
for (const key of allKeys) {
|
||||
const contextA = byKeyA.get(key);
|
||||
const contextB = byKeyB.get(key);
|
||||
const nodeA = contextA?.node;
|
||||
const nodeB = contextB?.node;
|
||||
const name = nodeB?.name || nodeA?.name || nodeB?.type || nodeA?.type || "unnamed";
|
||||
|
||||
const statusA = nodeA?.status;
|
||||
const statusB = nodeB?.status;
|
||||
const isStatusDiff = statusA !== statusB;
|
||||
if (isStatusDiff) statusDiffCount++;
|
||||
|
||||
// 比较 inputs
|
||||
const inputsDiff: Array<{ field: string; from?: unknown; to?: unknown }> = [];
|
||||
const payloadFields = (value: unknown): Record<string, unknown> => value === undefined ? {} : value !== null && typeof value === "object" ? value as Record<string, unknown> : { $value: value };
|
||||
const inA = payloadFields(nodeA?.inputs);
|
||||
const inB = payloadFields(nodeB?.inputs);
|
||||
const inputKeys = Array.from(new Set([...Object.keys(inA), ...Object.keys(inB)]));
|
||||
for (const k of inputKeys) {
|
||||
if (JSON.stringify(inA[k]) !== JSON.stringify(inB[k])) {
|
||||
inputsDiff.push({ field: k, from: inA[k], to: inB[k] });
|
||||
}
|
||||
}
|
||||
|
||||
// 比较 outputs
|
||||
const outputsDiff: Array<{ field: string; from?: unknown; to?: unknown }> = [];
|
||||
const outA = payloadFields(nodeA?.outputs ?? nodeA?.output);
|
||||
const outB = payloadFields(nodeB?.outputs ?? nodeB?.output);
|
||||
const outputKeys = Array.from(new Set([...Object.keys(outA), ...Object.keys(outB)]));
|
||||
for (const k of outputKeys) {
|
||||
if (JSON.stringify(outA[k]) !== JSON.stringify(outB[k])) {
|
||||
outputsDiff.push({ field: k, from: outA[k], to: outB[k] });
|
||||
}
|
||||
}
|
||||
|
||||
const isDiverged =
|
||||
!nodeA ||
|
||||
!nodeB ||
|
||||
isStatusDiff ||
|
||||
JSON.stringify(nodeA.error) !== JSON.stringify(nodeB.error) ||
|
||||
inputsDiff.length > 0 || outputsDiff.length > 0;
|
||||
|
||||
if (isDiverged) divergedNodesCount++;
|
||||
|
||||
nodes.push({
|
||||
taskName: name,
|
||||
instanceKey: key,
|
||||
currentLoopPath: contextB?.loopPath || contextA?.loopPath || undefined,
|
||||
displayName: (nodeB?.displayName || nodeA?.displayName || nodeB?.label || nodeA?.label) ?? undefined,
|
||||
type: nodeB?.type || nodeA?.type,
|
||||
statusA,
|
||||
statusB,
|
||||
durationMsA: nodeA?.executionTime,
|
||||
durationMsB: nodeB?.executionTime,
|
||||
errorA: nodeA?.error,
|
||||
errorB: nodeB?.error,
|
||||
inputsDiff,
|
||||
outputsDiff,
|
||||
diverged: isDiverged,
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
jobA: {
|
||||
id: jobA.id,
|
||||
pipelineId: jobA.pipelineId,
|
||||
state: typeof jobA.state === "string" || typeof jobA.state === "number" ? jobA.state : undefined,
|
||||
startTime: jobA.startTime ? String(jobA.startTime) : undefined,
|
||||
durationTime: typeof jobA.durationTime === "number" ? jobA.durationTime : undefined,
|
||||
hasError: Boolean(jobA.hasError),
|
||||
errorCount: typeof (jobA as any).errorTaskCount === "number" ? (jobA as any).errorTaskCount : undefined,
|
||||
},
|
||||
jobB: {
|
||||
id: jobB.id,
|
||||
pipelineId: jobB.pipelineId,
|
||||
state: typeof jobB.state === "string" || typeof jobB.state === "number" ? jobB.state : undefined,
|
||||
startTime: jobB.startTime ? String(jobB.startTime) : undefined,
|
||||
durationTime: typeof jobB.durationTime === "number" ? jobB.durationTime : undefined,
|
||||
hasError: Boolean(jobB.hasError),
|
||||
errorCount: typeof (jobB as any).errorTaskCount === "number" ? (jobB as any).errorTaskCount : undefined,
|
||||
},
|
||||
nodes,
|
||||
summary: {
|
||||
totalNodesA: flatA.length,
|
||||
totalNodesB: flatB.length,
|
||||
divergedNodesCount,
|
||||
statusDiffCount,
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
import type { WorkflowTask, WorkflowSnapshot, WorkflowSnapshotDiff, TaskConfigDiff } from "../types.js";
|
||||
import { flattenWorkflowTasks } from "../execution/tree.js";
|
||||
import { generateTextDiff } from "./text.js";
|
||||
|
||||
/**
|
||||
* 对比两个历史快照的节点、脚本代码(MVEL/JS)与参数配置差异
|
||||
*/
|
||||
export function diffWorkflowSnapshots(
|
||||
snapshotA: WorkflowSnapshot,
|
||||
snapshotB: WorkflowSnapshot
|
||||
): WorkflowSnapshotDiff {
|
||||
const tasksA = flattenWorkflowTasks(snapshotA.tasks);
|
||||
const tasksB = flattenWorkflowTasks(snapshotB.tasks);
|
||||
const indexPaths = (tasks: WorkflowTask[] = [], prefix = "tasks", paths = new Map<string, string>()): Map<string, string> => {
|
||||
tasks.forEach((task, i) => {
|
||||
const path = `${prefix}.${i}`;
|
||||
if (task.name) paths.set(task.name, path);
|
||||
if (task.tasks) indexPaths(task.tasks, `${path}.tasks`, paths);
|
||||
});
|
||||
return paths;
|
||||
};
|
||||
const pathsA = indexPaths(snapshotA.tasks || []);
|
||||
const pathsB = indexPaths(snapshotB.tasks || []);
|
||||
|
||||
const mapA = new Map<string, WorkflowTask>();
|
||||
for (const t of tasksA) {
|
||||
if (t?.name) mapA.set(t.name, t);
|
||||
}
|
||||
|
||||
const mapB = new Map<string, WorkflowTask>();
|
||||
for (const t of tasksB) {
|
||||
if (t?.name) mapB.set(t.name, t);
|
||||
}
|
||||
|
||||
const addedTasks: string[] = [];
|
||||
const removedTasks: string[] = [];
|
||||
const modifiedTasks: TaskConfigDiff[] = [];
|
||||
|
||||
// 1. 查找新增节点
|
||||
for (const [name, tB] of mapB) {
|
||||
if (!mapA.has(name)) {
|
||||
addedTasks.push(name);
|
||||
modifiedTasks.push({
|
||||
taskName: name,
|
||||
displayName: tB.displayName || tB.label,
|
||||
type: tB.type,
|
||||
changeType: "ADDED",
|
||||
configChanges: [],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 查找删除与修改节点
|
||||
for (const [name, tA] of mapA) {
|
||||
const tB = mapB.get(name);
|
||||
if (!tB) {
|
||||
removedTasks.push(name);
|
||||
modifiedTasks.push({
|
||||
taskName: name,
|
||||
displayName: tA.displayName || tA.label,
|
||||
type: tA.type,
|
||||
changeType: "REMOVED",
|
||||
configChanges: [],
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
// 两者均存在,深度比较配置与代码
|
||||
const configChanges: Array<{ field: string; from?: unknown; to?: unknown }> = [];
|
||||
let codeDiff: { from?: string; to?: string; unifiedDiff?: string } | undefined;
|
||||
let filterDiff: { from?: unknown; to?: unknown } | undefined;
|
||||
|
||||
// 代码脚本比较
|
||||
const codeA = typeof (tA as any).code === "string" ? (tA as any).code : undefined;
|
||||
const codeB = typeof (tB as any).code === "string" ? (tB as any).code : undefined;
|
||||
if (codeA !== codeB) {
|
||||
codeDiff = {
|
||||
from: codeA,
|
||||
to: codeB,
|
||||
unifiedDiff: generateTextDiff(
|
||||
codeA || "",
|
||||
codeB || "",
|
||||
`${snapshotA.version || snapshotA.id}`,
|
||||
`${snapshotB.version || snapshotB.id}`
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
// 过滤条件比较 (combineFilters / filters)
|
||||
const filtersA = (tA as any).combineFilters ?? (tA as any).filters;
|
||||
const filtersB = (tB as any).combineFilters ?? (tB as any).filters;
|
||||
if (JSON.stringify(filtersA) !== JSON.stringify(filtersB)) {
|
||||
filterDiff = { from: filtersA, to: filtersB };
|
||||
}
|
||||
|
||||
// 关键字段变动比较
|
||||
const checkFields = [...new Set([...Object.keys(tA), ...Object.keys(tB)])]
|
||||
.filter(field => !["name", "tasks", "code", "combineFilters", "filters"].includes(field));
|
||||
if (pathsA.get(name) !== pathsB.get(name)) {
|
||||
configChanges.push({ field: "$path", from: pathsA.get(name), to: pathsB.get(name) });
|
||||
}
|
||||
for (const f of checkFields) {
|
||||
const valA = (tA as any)[f];
|
||||
const valB = (tB as any)[f];
|
||||
if (JSON.stringify(valA) !== JSON.stringify(valB)) {
|
||||
configChanges.push({ field: f, from: valA, to: valB });
|
||||
}
|
||||
}
|
||||
|
||||
if (codeDiff || filterDiff || configChanges.length > 0) {
|
||||
modifiedTasks.push({
|
||||
taskName: name,
|
||||
displayName: tB.displayName || tB.label || tA.displayName || tA.label,
|
||||
type: tB.type || tA.type,
|
||||
changeType: "MODIFIED",
|
||||
codeDiff,
|
||||
filterDiff,
|
||||
configChanges,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
snapshotA: {
|
||||
id: snapshotA.id,
|
||||
version: snapshotA.version,
|
||||
updateTime: snapshotA.updateTime,
|
||||
staffName: snapshotA.staffName || snapshotA.staffId || undefined,
|
||||
},
|
||||
snapshotB: {
|
||||
id: snapshotB.id,
|
||||
version: snapshotB.version,
|
||||
updateTime: snapshotB.updateTime,
|
||||
staffName: snapshotB.staffName || snapshotB.staffId || undefined,
|
||||
},
|
||||
addedTasks,
|
||||
removedTasks,
|
||||
modifiedTasks,
|
||||
summary: {
|
||||
totalA: tasksA.length,
|
||||
totalB: tasksB.length,
|
||||
changedCount: modifiedTasks.length,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* 快速生成标准 Unified Diff 文本
|
||||
*/
|
||||
export function generateTextDiff(a: string, b: string, labelA = "from", labelB = "to"): string {
|
||||
if (a === b) return "";
|
||||
const linesA = a.split(/\r?\n/);
|
||||
const linesB = b.split(/\r?\n/);
|
||||
const output: string[] = [`--- ${labelA}`, `+++ ${labelB}`];
|
||||
|
||||
let start = 0;
|
||||
while (start < linesA.length && start < linesB.length && linesA[start] === linesB[start]) {
|
||||
start++;
|
||||
}
|
||||
let endA = linesA.length - 1;
|
||||
let endB = linesB.length - 1;
|
||||
while (endA >= start && endB >= start && linesA[endA] === linesB[endB]) {
|
||||
endA--;
|
||||
endB--;
|
||||
}
|
||||
|
||||
const hunkStart = Math.max(0, start - 2);
|
||||
const hunkEndA = Math.min(linesA.length, endA + 3);
|
||||
const hunkEndB = Math.min(linesB.length, endB + 3);
|
||||
|
||||
output.push(`@@ -${hunkStart + 1},${hunkEndA - hunkStart} +${hunkStart + 1},${hunkEndB - hunkStart} @@`);
|
||||
for (let i = hunkStart; i < start; i++) {
|
||||
output.push(` ${linesA[i]}`);
|
||||
}
|
||||
for (let i = start; i <= endA; i++) {
|
||||
output.push(`- ${linesA[i]}`);
|
||||
}
|
||||
for (let i = start; i <= endB; i++) {
|
||||
output.push(`+ ${linesB[i]}`);
|
||||
}
|
||||
for (let i = endA + 1; i < hunkEndA; i++) {
|
||||
output.push(` ${linesA[i]}`);
|
||||
}
|
||||
return output.join("\n");
|
||||
}
|
||||
|
||||
|
||||
@@ -3,5 +3,6 @@
|
||||
- [tree.ts](./tree.ts):执行树展开、失败识别和节点查找,也提供工作流任务树展开。
|
||||
- [context.ts](./context.ts):构建执行实例索引,供条件解释与 Job 差异比较复用。
|
||||
- [debug.ts](./debug.ts):调试输入、发起 Job、轮询和诊断汇总。
|
||||
- [queries.ts](./queries.ts):Job、执行树与日志读取服务出口。
|
||||
|
||||
执行监听位于同级 [watch](../watch/README.watch.md),条件解释位于 `branch/`;HTTP 传输位于上级 `api.ts`。
|
||||
@@ -0,0 +1,37 @@
|
||||
import * as api from "../api.js";
|
||||
|
||||
export function listWorkflowLogs(...args: Parameters<typeof api.listWorkflowLogs>) {
|
||||
return api.listWorkflowLogs(...args);
|
||||
}
|
||||
|
||||
|
||||
export function listRunningJobs(...args: Parameters<typeof api.listRunningJobs>) {
|
||||
return api.listRunningJobs(...args);
|
||||
}
|
||||
|
||||
|
||||
export function getJob(...args: Parameters<typeof api.getJob>) {
|
||||
return api.getJob(...args);
|
||||
}
|
||||
|
||||
|
||||
export function getJobExecutionTree(...args: Parameters<typeof api.getJobExecutionTree>) {
|
||||
return api.getJobExecutionTree(...args);
|
||||
}
|
||||
|
||||
|
||||
export function getJobFailedExecutions(...args: Parameters<typeof api.getJobFailedExecutions>) {
|
||||
return api.getJobFailedExecutions(...args);
|
||||
}
|
||||
|
||||
|
||||
export function getJobExecutionLevel(...args: Parameters<typeof api.getJobExecutionLevel>) {
|
||||
return api.getJobExecutionLevel(...args);
|
||||
}
|
||||
|
||||
|
||||
export function getExecutionLogs(...args: Parameters<typeof api.getExecutionLogs>) {
|
||||
return api.getExecutionLogs(...args);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# 工作流管理
|
||||
|
||||
- [configuration.ts](./configuration.ts):创建、复制、保存、启停和元数据刷新。
|
||||
- [queries.ts](./queries.ts):工作流列表与跨应用查询,以及 Job、日志等读取服务出口。
|
||||
- [queries.ts](./queries.ts):工作流列表、详情、快照及跨应用查询。
|
||||
- [save-error.ts](./save-error.ts):主保存成功而元数据刷新失败时的部分成功异常。
|
||||
|
||||
HTTP 传输和共享模型仍位于上级 `api.ts`、`types.ts`,对外业务出口为上级 `services.ts`。
|
||||
@@ -42,41 +42,6 @@ export function getWorkflowSnapshot(...args: Parameters<typeof api.getWorkflowSn
|
||||
}
|
||||
|
||||
|
||||
export function listWorkflowLogs(...args: Parameters<typeof api.listWorkflowLogs>) {
|
||||
return api.listWorkflowLogs(...args);
|
||||
}
|
||||
|
||||
|
||||
export function listRunningJobs(...args: Parameters<typeof api.listRunningJobs>) {
|
||||
return api.listRunningJobs(...args);
|
||||
}
|
||||
|
||||
|
||||
export function getJob(...args: Parameters<typeof api.getJob>) {
|
||||
return api.getJob(...args);
|
||||
}
|
||||
|
||||
|
||||
export function getJobExecutionTree(...args: Parameters<typeof api.getJobExecutionTree>) {
|
||||
return api.getJobExecutionTree(...args);
|
||||
}
|
||||
|
||||
|
||||
export function getJobFailedExecutions(...args: Parameters<typeof api.getJobFailedExecutions>) {
|
||||
return api.getJobFailedExecutions(...args);
|
||||
}
|
||||
|
||||
|
||||
export function getJobExecutionLevel(...args: Parameters<typeof api.getJobExecutionLevel>) {
|
||||
return api.getJobExecutionLevel(...args);
|
||||
}
|
||||
|
||||
|
||||
export function getExecutionLogs(...args: Parameters<typeof api.getExecutionLogs>) {
|
||||
return api.getExecutionLogs(...args);
|
||||
}
|
||||
|
||||
|
||||
// ── 服务层:跨应用聚合 ───────────────────────────────────────────────────────
|
||||
|
||||
export interface ListAllWorkflowsOptions {
|
||||
|
||||
@@ -6,6 +6,10 @@ export {
|
||||
getWorkflowDetail,
|
||||
listWorkflowSnapshots,
|
||||
getWorkflowSnapshot,
|
||||
listAllWorkflows,
|
||||
findWorkflowsByTaskType,
|
||||
} from "./management/queries.js";
|
||||
export {
|
||||
listWorkflowLogs,
|
||||
listRunningJobs,
|
||||
getJob,
|
||||
@@ -13,9 +17,7 @@ export {
|
||||
getJobFailedExecutions,
|
||||
getJobExecutionLevel,
|
||||
getExecutionLogs,
|
||||
listAllWorkflows,
|
||||
findWorkflowsByTaskType,
|
||||
} from "./management/queries.js";
|
||||
} from "./execution/queries.js";
|
||||
export type {
|
||||
WorkflowClients,
|
||||
ListAllWorkflowsOptions,
|
||||
|
||||
Reference in new issue
Block a user