forked from longtao.wu/droboticflow
57 lines
1.9 KiB
JavaScript
57 lines
1.9 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
|
|
import {
|
|
parseWorkflowRunInputs,
|
|
rootNodeIds,
|
|
syncRootWorkflowInputs,
|
|
workflowInputDraft,
|
|
} from "../../src/lib/workflow-inputs.js";
|
|
|
|
test("root inputs are derived only from nodes without incoming edges", () => {
|
|
const nodes = [
|
|
{ id: "source", data: { label: "Source", inputs: [{ id: "in", name: "Data", type: "json", required: true }] } },
|
|
{ id: "sink", data: { inputs: [{ id: "in", name: "Data", type: "json", required: true }] } },
|
|
];
|
|
const edges = [{ source: "source", target: "sink", targetHandle: "in" }];
|
|
assert.deepEqual([...rootNodeIds(nodes, edges)], ["source"]);
|
|
assert.deepEqual(syncRootWorkflowInputs(nodes, edges), [
|
|
{
|
|
id: "input-source-in",
|
|
name: "Data",
|
|
description: "",
|
|
type: "json",
|
|
required: true,
|
|
bindings: [{ nodeId: "source", targetPortId: "in" }],
|
|
},
|
|
]);
|
|
});
|
|
|
|
test("run inputs support inline json and directory refs", () => {
|
|
const definitions = [
|
|
{ id: "config", name: "Config", type: "json", required: true },
|
|
{ id: "dataset", name: "Dataset", type: "file", required: true },
|
|
];
|
|
const inputs = parseWorkflowRunInputs(definitions, {
|
|
config: { ...workflowInputDraft(), mode: "inline", inlineText: '{"ok":true}' },
|
|
dataset: {
|
|
...workflowInputDraft(),
|
|
mode: "ref",
|
|
connectionId: "storage-1",
|
|
bucket: "robot-data",
|
|
objectKind: "directory",
|
|
prefix: "incoming/session",
|
|
},
|
|
});
|
|
assert.deepEqual(inputs.config.inline, { ok: true });
|
|
assert.equal(inputs.dataset.ref.kind, "directory");
|
|
assert.equal(inputs.dataset.ref.prefix, "incoming/session");
|
|
});
|
|
|
|
test("required blank workflow inputs are rejected", () => {
|
|
assert.throws(
|
|
() => parseWorkflowRunInputs([{ id: "required", name: "Required", type: "json", required: true }], {}),
|
|
/必填输入/,
|
|
);
|
|
});
|