92 lines
3.3 KiB
JavaScript
92 lines
3.3 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
|
|
import {
|
|
parseWorkflowRunInputs,
|
|
rootNodeIds,
|
|
syncRootWorkflowInputs,
|
|
workflowInputDraft,
|
|
validateProductionRunSecurityGate,
|
|
} from "../../src/lib/workflow-inputs.js";
|
|
|
|
test("production accepts persisted root aliases but rejects invalid and mixed bindings", () => {
|
|
const nodes = [
|
|
{ id: "directory", data: { inputs: [{ id: "sourceDirectory", type: "file" }] } },
|
|
{ id: "reader", data: { inputs: [{ id: "directory", type: "file" }] } },
|
|
];
|
|
const edges = [{ source: "directory", target: "reader" }];
|
|
const definition = {
|
|
id: "sourceDirectory",
|
|
name: "sourceDirectory",
|
|
type: "file",
|
|
required: true,
|
|
bindings: [{ nodeId: "directory", targetPortId: "sourceDirectory" }],
|
|
};
|
|
for (const draft of [
|
|
{ mode: "ref", connectionId: "bos", bucket: "drobodata-fanyu", objectKind: "directory", prefix: "test_new" },
|
|
{ mode: "ref", connectionId: "bos", bucket: "drobodata-fanyu", objectKind: "object", key: "test_new" },
|
|
]) {
|
|
const inputs = parseWorkflowRunInputs([definition], { sourceDirectory: draft });
|
|
assert.equal(inputs.sourceDirectory.ref.prefix, "test_new");
|
|
assert.equal(validateProductionRunSecurityGate({ inputs }, nodes, edges, [definition]).valid, true);
|
|
for (const bindings of [
|
|
[],
|
|
[{ nodeId: "reader", targetPortId: "directory" }],
|
|
[{ nodeId: "directory", targetPortId: "missing" }],
|
|
[...definition.bindings, { nodeId: "reader", targetPortId: "directory" }],
|
|
]) {
|
|
assert.throws(
|
|
() => validateProductionRunSecurityGate({ inputs }, nodes, edges, [{ ...definition, bindings }]),
|
|
/production_input_forbidden/,
|
|
);
|
|
}
|
|
}
|
|
});
|
|
|
|
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 }], {}),
|
|
/必填输入/,
|
|
);
|
|
});
|