forked from longtao.wu/droboticflow
214 lines
5.5 KiB
JavaScript
214 lines
5.5 KiB
JavaScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
import {
|
|
decorateWorkflowEdges,
|
|
decorateWorkflowNodes,
|
|
getRunDisplayStatus,
|
|
getCurrentNodeLabel,
|
|
getEdgeOutputArtifacts,
|
|
getNodeArtifacts,
|
|
getNodeExecutionState,
|
|
getTrackedRunId,
|
|
isRunInFlight,
|
|
} from "../../src/lib/workflow-run.js";
|
|
|
|
const nodes = [
|
|
{ id: "source", data: { label: "Source" } },
|
|
{ id: "infer", data: { label: "Infer" } },
|
|
{ id: "upload", data: { label: "Upload" } },
|
|
];
|
|
|
|
const edges = [
|
|
{ id: "e1", source: "source", target: "infer" },
|
|
{ id: "e2", source: "infer", target: "upload" },
|
|
];
|
|
|
|
test("identifies active run statuses", () => {
|
|
assert.equal(isRunInFlight({ status: "queued" }), true);
|
|
assert.equal(isRunInFlight({ status: "running" }), true);
|
|
assert.equal(isRunInFlight({ status: "stopping" }), true);
|
|
assert.equal(isRunInFlight({ status: "waiting_for_audit" }), true);
|
|
assert.equal(isRunInFlight({ status: "completed" }), false);
|
|
});
|
|
|
|
test("treats stale completed runs with active node executions as in flight", () => {
|
|
const run = {
|
|
status: "completed",
|
|
currentNodeId: "infer",
|
|
nodeExecutions: [
|
|
{ nodeId: "source", nodeLabel: "Source", status: "completed" },
|
|
{ nodeId: "infer", nodeLabel: "Infer", status: "running" },
|
|
],
|
|
};
|
|
|
|
assert.equal(getRunDisplayStatus(run), "running");
|
|
assert.equal(isRunInFlight(run), true);
|
|
});
|
|
|
|
test("derives node execution states from current run payload", () => {
|
|
const run = {
|
|
status: "running",
|
|
currentNodeId: "infer",
|
|
nodeExecutions: [
|
|
{ nodeId: "source", nodeLabel: "Source", status: "completed" },
|
|
{ nodeId: "infer", nodeLabel: "Infer", status: "running" },
|
|
],
|
|
};
|
|
|
|
assert.equal(getNodeExecutionState(run, "source"), "completed");
|
|
assert.equal(getNodeExecutionState(run, "infer"), "running");
|
|
assert.equal(getNodeExecutionState(run, "upload"), "idle");
|
|
});
|
|
|
|
test("decorates nodes and edges for an in-progress run", () => {
|
|
const run = {
|
|
status: "running",
|
|
currentNodeId: "infer",
|
|
nodeExecutions: [
|
|
{ nodeId: "source", nodeLabel: "Source", status: "completed" },
|
|
{ nodeId: "infer", nodeLabel: "Infer", status: "running" },
|
|
],
|
|
};
|
|
|
|
const decoratedNodes = decorateWorkflowNodes(nodes, run);
|
|
const decoratedEdges = decorateWorkflowEdges(edges, nodes, run);
|
|
|
|
assert.equal(decoratedNodes[0].data.executionState, "completed");
|
|
assert.equal(decoratedNodes[1].data.executionState, "running");
|
|
assert.equal(decoratedNodes[1].data.running, true);
|
|
assert.equal(decoratedEdges[0].animated, true);
|
|
assert.equal(decoratedEdges[0].data.executionState, "running");
|
|
assert.equal(decoratedEdges[1].data.executionState, "idle");
|
|
});
|
|
|
|
test("finds the current node label from node executions or graph data", () => {
|
|
const run = {
|
|
currentNodeId: "upload",
|
|
nodeExecutions: [],
|
|
};
|
|
|
|
assert.equal(getCurrentNodeLabel(run, nodes), "Upload");
|
|
});
|
|
|
|
test("restores tracked run id from route or running workflow metadata", () => {
|
|
assert.equal(
|
|
getTrackedRunId("run-from-query", {
|
|
status: "running",
|
|
lastRunId: "run-from-workflow",
|
|
}),
|
|
"run-from-query",
|
|
);
|
|
|
|
assert.equal(
|
|
getTrackedRunId("", {
|
|
status: "running",
|
|
lastRunId: "run-from-workflow",
|
|
}),
|
|
"run-from-workflow",
|
|
);
|
|
|
|
assert.equal(
|
|
getTrackedRunId("", {
|
|
status: "completed",
|
|
lastRunId: "run-from-workflow",
|
|
}),
|
|
"run-from-workflow",
|
|
);
|
|
});
|
|
|
|
test("falls back to run-level artifacts when node execution artifacts are absent", () => {
|
|
const run = {
|
|
artifacts: [
|
|
{
|
|
id: "artifact-1",
|
|
nodeId: "source",
|
|
portId: "out-1",
|
|
portName: "manifest",
|
|
},
|
|
],
|
|
nodeExecutions: [{ nodeId: "source", nodeLabel: "Source", status: "completed" }],
|
|
};
|
|
|
|
assert.deepEqual(getNodeArtifacts(run, "source"), run.artifacts);
|
|
});
|
|
|
|
test("resolves edge output artifacts by source handle and source port definition", () => {
|
|
const run = {
|
|
artifacts: [],
|
|
nodeExecutions: [
|
|
{
|
|
nodeId: "source",
|
|
nodeLabel: "Source",
|
|
status: "completed",
|
|
artifacts: [
|
|
{
|
|
id: "artifact-1",
|
|
nodeId: "source",
|
|
portId: "out-1",
|
|
portName: "manifest",
|
|
name: "manifest.json",
|
|
},
|
|
{
|
|
id: "artifact-2",
|
|
nodeId: "source",
|
|
portId: "out-2",
|
|
portName: "debug",
|
|
name: "debug.json",
|
|
},
|
|
],
|
|
},
|
|
],
|
|
};
|
|
|
|
const graphNodes = [
|
|
{
|
|
id: "source",
|
|
data: {
|
|
outputs: [
|
|
{ id: "out-1", name: "manifest" },
|
|
{ id: "out-2", name: "debug" },
|
|
],
|
|
},
|
|
},
|
|
];
|
|
|
|
assert.deepEqual(getEdgeOutputArtifacts({ id: "edge-1", source: "source", sourceHandle: "out-1" }, run, graphNodes), [
|
|
run.nodeExecutions[0].artifacts[0],
|
|
]);
|
|
});
|
|
|
|
test("resolves edge output artifacts by port name when the run payload lacks port ids", () => {
|
|
const run = {
|
|
nodeExecutions: [
|
|
{
|
|
nodeId: "source",
|
|
nodeLabel: "Source",
|
|
status: "completed",
|
|
artifacts: [
|
|
{
|
|
id: "artifact-1",
|
|
nodeId: "source",
|
|
portName: "审核通过",
|
|
name: "approved.json",
|
|
},
|
|
],
|
|
},
|
|
],
|
|
};
|
|
|
|
const graphNodes = [
|
|
{
|
|
id: "source",
|
|
data: {
|
|
outputs: [{ id: "approved", name: "审核通过" }],
|
|
},
|
|
},
|
|
];
|
|
|
|
assert.deepEqual(
|
|
getEdgeOutputArtifacts({ id: "edge-1", source: "source", sourceHandle: "approved" }, run, graphNodes),
|
|
[run.nodeExecutions[0].artifacts[0]],
|
|
);
|
|
});
|