feat(editor): findLatestIo helper for pulling a node's row out of an ExecutionDetail

This commit is contained in:
Claude
2026-08-30 11:30:05 +00:00
parent abf6332855
commit 1153e56cc5
2 changed files with 58 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
import { describe, it, expect } from "vitest";
import { findLatestIo } from "./nodeIoLookup";
import type { ExecutionDetail } from "@/api/types";
const detail = (nodes: Array<{ nodeId: string; inputs: unknown; outputs: unknown }>): ExecutionDetail => ({
id: "e1", workflowId: "wf", trigger: "manual", status: "completed",
startedAt: "", endedAt: null, error: null,
nodes: nodes.map(n => ({
nodeId: n.nodeId, status: "completed",
startedAt: "", endedAt: "", error: null,
inputs: n.inputs, outputs: n.outputs,
})),
});
describe("findLatestIo", () => {
it("returns inputs and outputs for a matching node id", () => {
const d = detail([
{ nodeId: "n1", inputs: [[{ json: { a: 1 } }]], outputs: [[{ json: { b: 2 } }]] },
{ nodeId: "n2", inputs: [[{ json: { c: 3 } }]], outputs: [[{ json: { d: 4 } }]] },
]);
const io = findLatestIo(d, "n2");
expect(io).toEqual({
inputs: [[{ json: { c: 3 } }]],
outputs: [[{ json: { d: 4 } }]],
});
});
it("returns null when the node did not appear in the execution", () => {
const d = detail([{ nodeId: "n1", inputs: [], outputs: [] }]);
expect(findLatestIo(d, "missing")).toBeNull();
});
it("returns null when the execution is undefined", () => {
expect(findLatestIo(undefined, "n1")).toBeNull();
});
it("returns inputs and outputs verbatim (does not clone or reshape)", () => {
const inputs = [[{ json: { a: 1 } }]];
const outputs = [[{ json: { b: 2 } }]];
const d = detail([{ nodeId: "n1", inputs, outputs }]);
const io = findLatestIo(d, "n1")!;
expect(io.inputs).toBe(inputs);
expect(io.outputs).toBe(outputs);
});
});

View File

@@ -0,0 +1,13 @@
import type { ExecutionDetail } from "@/api/types";
export interface NodeIo {
inputs: unknown;
outputs: unknown;
}
export function findLatestIo(execution: ExecutionDetail | undefined, nodeId: string): NodeIo | null {
if (!execution) return null;
const row = execution.nodes.find((n) => n.nodeId === nodeId);
if (!row) return null;
return { inputs: row.inputs, outputs: row.outputs };
}