forked from longtao.wu/droboticflow
205 lines
7.0 KiB
JavaScript
205 lines
7.0 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
|
|
import {
|
|
artifactGroupCount,
|
|
groupArtifactsByLineage,
|
|
preferredArtifact,
|
|
runInputArtifacts,
|
|
} from "../../src/lib/artifact-groups.js";
|
|
|
|
const artifact = (id, nodeId, name, data = undefined) => ({
|
|
id,
|
|
nodeId,
|
|
name,
|
|
path: `/tmp/${name}`,
|
|
type: name.endsWith(".json") ? "json" : "file",
|
|
data,
|
|
});
|
|
|
|
test("groups external inputs separately from intermediate and final node outputs", () => {
|
|
const grouped = groupArtifactsByLineage(
|
|
[
|
|
artifact("prepared", "prepare", "prepared.zip"),
|
|
artifact("middle", "check", "episode-results.json"),
|
|
artifact("final", "report", "quality-report.html"),
|
|
],
|
|
{
|
|
nodes: [
|
|
{ nodeId: "prepare", nodeLabel: "数据准备", inputArtifacts: [artifact("input", "prepare", "input.zip")] },
|
|
{ nodeId: "check", nodeLabel: "质量检查" },
|
|
{ nodeId: "report", nodeLabel: "报告生成" },
|
|
],
|
|
edges: [
|
|
{ sourceNodeId: "prepare", targetNodeId: "check" },
|
|
{ sourceNodeId: "check", targetNodeId: "report" },
|
|
],
|
|
},
|
|
);
|
|
|
|
assert.equal(artifactGroupCount(grouped.groups, "input"), 1);
|
|
assert.equal(grouped.groups.input[0].artifacts[0].id, "input");
|
|
assert.equal(artifactGroupCount(grouped.groups, "intermediate"), 2);
|
|
assert.deepEqual(grouped.groups.intermediate.flatMap((node) => node.artifacts.map((item) => item.id)).sort(), [
|
|
"middle",
|
|
"prepared",
|
|
]);
|
|
assert.equal(artifactGroupCount(grouped.groups, "final"), 1);
|
|
assert.equal(preferredArtifact(grouped).id, "final");
|
|
});
|
|
|
|
test("places rendered pose and hand-prelabel videos before their JSON manifests", () => {
|
|
const grouped = groupArtifactsByLineage(
|
|
[
|
|
{ ...artifact("manifest", "headpose", "headpose-manifest.json"), type: "json" },
|
|
{ ...artifact("render", "headpose", "headpose-annotated.mp4"), type: "video" },
|
|
],
|
|
{ nodes: [{ nodeId: "headpose", nodeLabel: "HeadPose 预标" }], edges: [] },
|
|
);
|
|
assert.deepEqual(
|
|
grouped.groups.final[0].artifacts.map((item) => item.id),
|
|
["render", "manifest"],
|
|
);
|
|
assert.equal(preferredArtifact(grouped).id, "render");
|
|
});
|
|
|
|
test("recovers missing historical node ids from lineage output artifact paths", () => {
|
|
const grouped = groupArtifactsByLineage(
|
|
[
|
|
artifact("source-copy", undefined, "input.zip"),
|
|
artifact("check-copy", undefined, "episode-results.json"),
|
|
artifact("upload-copy", undefined, "quality-report.html"),
|
|
],
|
|
{
|
|
nodes: [
|
|
{
|
|
nodeId: "source",
|
|
nodeLabel: "数据源",
|
|
inputArtifacts: [artifact("workflow-input", "source", "source-directory")],
|
|
outputArtifacts: [artifact("source-output", "source", "input.zip")],
|
|
},
|
|
{
|
|
nodeId: "check",
|
|
nodeLabel: "质量检查",
|
|
outputArtifacts: [artifact("check-output", "check", "episode-results.json")],
|
|
},
|
|
{
|
|
nodeId: "upload",
|
|
nodeLabel: "结果上传",
|
|
outputArtifacts: [artifact("upload-output", "upload", "quality-report.html")],
|
|
},
|
|
],
|
|
edges: [
|
|
{ sourceNodeId: "source", targetNodeId: "check" },
|
|
{ sourceNodeId: "check", targetNodeId: "upload" },
|
|
],
|
|
},
|
|
);
|
|
|
|
assert.equal(artifactGroupCount(grouped.groups, "input"), 1);
|
|
assert.equal(grouped.groups.input[0].nodeId, "source");
|
|
assert.equal(grouped.groups.input[0].artifacts[0].id, "workflow-input");
|
|
assert.equal(artifactGroupCount(grouped.groups, "intermediate"), 2);
|
|
assert.equal(artifactGroupCount(grouped.groups, "final"), 1);
|
|
assert.equal(grouped.groups.final[0].nodeId, "upload");
|
|
});
|
|
|
|
test("builds protected fallback input artifacts from persisted run bindings", () => {
|
|
const payload = {
|
|
mode: "ref",
|
|
type: "file",
|
|
ref: { provider: "BOS", connectionId: "connection-1", bucket: "bucket-1", kind: "directory", sizeBytes: 42 },
|
|
};
|
|
const inputs = runInputArtifacts({
|
|
id: "run-1",
|
|
inputs: { sourceDirectory: payload },
|
|
resolvedInputBindings: [
|
|
{ workflowInputId: "sourceDirectory", nodeId: "prepare", targetPortId: "sourceDirectory", payload },
|
|
],
|
|
});
|
|
|
|
assert.equal(inputs.length, 1);
|
|
assert.equal(inputs[0].nodeId, "prepare");
|
|
assert.equal(inputs[0].size, "42 B");
|
|
assert.equal(inputs[0].data.inputReference, true);
|
|
assert.equal(inputs[0].data.contentAvailable, false);
|
|
assert.equal(inputs[0].data.datasetType, "directory");
|
|
|
|
const grouped = groupArtifactsByLineage([], undefined, inputs);
|
|
assert.equal(grouped.hasLineage, false);
|
|
assert.equal(artifactGroupCount(grouped.groups, "input"), 1);
|
|
});
|
|
|
|
test("deduplicates the same input from run bindings and lineage", () => {
|
|
const explicit = artifact("explicit", "prepare", "sourceDirectory");
|
|
explicit.portId = "sourceDirectory";
|
|
const inherited = artifact("inherited", "prepare", "sourceDirectory");
|
|
inherited.portId = "sourceDirectory";
|
|
const grouped = groupArtifactsByLineage(
|
|
[artifact("result", "prepare", "result.json")],
|
|
{ nodes: [{ nodeId: "prepare", nodeLabel: "准备", inputArtifacts: [inherited] }], edges: [] },
|
|
[explicit],
|
|
);
|
|
|
|
assert.equal(artifactGroupCount(grouped.groups, "input"), 1);
|
|
assert.equal(grouped.groups.input[0].artifacts[0].id, "explicit");
|
|
});
|
|
|
|
test("treats a single isolated workflow node as final output", () => {
|
|
const grouped = groupArtifactsByLineage([artifact("only", "single", "result.json")], {
|
|
nodes: [{ nodeId: "single", nodeLabel: "单节点" }],
|
|
edges: [],
|
|
});
|
|
|
|
assert.equal(artifactGroupCount(grouped.groups, "final"), 1);
|
|
assert.equal(artifactGroupCount(grouped.groups, "input"), 0);
|
|
});
|
|
|
|
test("returns no default selection when the requested final group is empty", () => {
|
|
const grouped = {
|
|
groups: {
|
|
final: [],
|
|
intermediate: [],
|
|
input: [{ nodeId: "source", nodeLabel: "输入", artifacts: [artifact("input", "source", "input.zip")] }],
|
|
},
|
|
};
|
|
|
|
assert.equal(preferredArtifact(grouped, ["final"]), null);
|
|
assert.equal(preferredArtifact(grouped).id, "input");
|
|
});
|
|
|
|
test("keeps every historical artifact visible when lineage is missing", () => {
|
|
const grouped = groupArtifactsByLineage(
|
|
[artifact("one", "unknown-a", "one.zip"), artifact("two", "unknown-b", "two.html")],
|
|
undefined,
|
|
);
|
|
|
|
assert.equal(grouped.hasLineage, false);
|
|
assert.equal(artifactGroupCount(grouped.groups, "final"), 2);
|
|
});
|
|
|
|
test("prefers quality summary, then rendered reports, JSON and other files", () => {
|
|
const grouped = groupArtifactsByLineage(
|
|
[
|
|
artifact("archive", "report", "bundle.zip"),
|
|
artifact("json", "report", "details.json"),
|
|
artifact("html", "report", "report.html"),
|
|
artifact("summary", "report", "summary.json", {
|
|
reportSummary: {
|
|
schemaVersion: 1,
|
|
kind: "quality",
|
|
totalCount: 1,
|
|
successCount: 1,
|
|
failureCount: 0,
|
|
},
|
|
}),
|
|
],
|
|
{ nodes: [{ nodeId: "report", nodeLabel: "报告" }], edges: [] },
|
|
);
|
|
|
|
assert.deepEqual(
|
|
grouped.groups.final[0].artifacts.map((item) => item.id),
|
|
["summary", "html", "json", "archive"],
|
|
);
|
|
});
|