Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/validation/getFlowValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,25 @@ export const getFlowValidation = (
}
}

const functionIdentifiers = new Set(functions?.map(f => f.identifier));
const unreachableFunctionDiagnostics = (flow.nodes?.nodes ?? [])
.filter(n => n?.functionDefinition && !functionIdentifiers.has(n.functionDefinition.identifier))
.map(n => ({
nodeId: n!.id,
parameterIndex: null,
code: 0,
message: `The function definition "${n!.functionDefinition!.identifier}" is not reachable.`,
severity: "error" as const,
}));

if (unreachableFunctionDiagnostics.length > 0) {
return {
isValid: false,
returnType: "void",
diagnostics: unreachableFunctionDiagnostics,
}
}

const sourceCode = generateFlowSourceCode(flow, functions, dataTypes);

// 3. Virtual TypeScript Compilation
Expand Down
56 changes: 52 additions & 4 deletions test/flowValidation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -934,10 +934,19 @@ describe('getFlowValidation - Integrationstest', () => {

const result = getFlowValidation(flow, FUNCTION_SIGNATURES, DATA_TYPES);

expect(result.isValid).toBe(true);
result.diagnostics.forEach((error) => {
expect(error.parameterIndex).toBeDefined()
})
expect(result.isValid).toBe(false);
expect(result.diagnostics).toEqual(expect.arrayContaining([
expect.objectContaining({
nodeId: "gid://sagittarius/NodeFunction/1",
message: 'The function definition "http::response::create" is not reachable.',
severity: "error",
}),
expect.objectContaining({
nodeId: "gid://sagittarius/NodeFunction/4",
message: 'The function definition "http::response::create" is not reachable.',
severity: "error",
}),
]));
});

it('11', () => {
Expand Down Expand Up @@ -1278,4 +1287,43 @@ describe('getFlowValidation - Integrationstest', () => {
})
});

it('fails when a node references an unreachable function definition', () => {

const flow: Flow = {
startingNodeId: "gid://sagittarius/NodeFunction/1",
nodes: {
nodes: [
{
id: "gid://sagittarius/NodeFunction/1",
functionDefinition: {identifier: "std::number::add"},
parameters: {
nodes: [
{value: {__typename: "LiteralValue", value: 1}},
{value: {__typename: "LiteralValue", value: 2}}
]
},
nextNodeId: "gid://sagittarius/NodeFunction/2"
},
{
id: "gid://sagittarius/NodeFunction/2",
functionDefinition: {identifier: "std::imaginary::nonexistent"},
parameters: {nodes: []}
}
]
}
};

const result = getFlowValidation(flow, FUNCTION_SIGNATURES, DATA_TYPES);

expect(result.isValid).toBe(false);
expect(result.diagnostics).toEqual([
expect.objectContaining({
nodeId: "gid://sagittarius/NodeFunction/2",
parameterIndex: null,
message: 'The function definition "std::imaginary::nonexistent" is not reachable.',
severity: "error",
})
]);
});

});