Skip to content

Commit 9043851

Browse files
authored
Merge pull request #115 from code0-tech/feat/#114
Function definition not found error
2 parents 98ef6f7 + 87ed425 commit 9043851

2 files changed

Lines changed: 71 additions & 4 deletions

File tree

src/validation/getFlowValidation.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,25 @@ export const getFlowValidation = (
3939
}
4040
}
4141

42+
const functionIdentifiers = new Set(functions?.map(f => f.identifier));
43+
const unreachableFunctionDiagnostics = (flow.nodes?.nodes ?? [])
44+
.filter(n => n?.functionDefinition && !functionIdentifiers.has(n.functionDefinition.identifier))
45+
.map(n => ({
46+
nodeId: n!.id,
47+
parameterIndex: null,
48+
code: 0,
49+
message: `The function definition "${n!.functionDefinition!.identifier}" is not reachable.`,
50+
severity: "error" as const,
51+
}));
52+
53+
if (unreachableFunctionDiagnostics.length > 0) {
54+
return {
55+
isValid: false,
56+
returnType: "void",
57+
diagnostics: unreachableFunctionDiagnostics,
58+
}
59+
}
60+
4261
const sourceCode = generateFlowSourceCode(flow, functions, dataTypes);
4362

4463
// 3. Virtual TypeScript Compilation

test/flowValidation.test.ts

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -934,10 +934,19 @@ describe('getFlowValidation - Integrationstest', () => {
934934

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

937-
expect(result.isValid).toBe(true);
938-
result.diagnostics.forEach((error) => {
939-
expect(error.parameterIndex).toBeDefined()
940-
})
937+
expect(result.isValid).toBe(false);
938+
expect(result.diagnostics).toEqual(expect.arrayContaining([
939+
expect.objectContaining({
940+
nodeId: "gid://sagittarius/NodeFunction/1",
941+
message: 'The function definition "http::response::create" is not reachable.',
942+
severity: "error",
943+
}),
944+
expect.objectContaining({
945+
nodeId: "gid://sagittarius/NodeFunction/4",
946+
message: 'The function definition "http::response::create" is not reachable.',
947+
severity: "error",
948+
}),
949+
]));
941950
});
942951

943952
it('11', () => {
@@ -1278,4 +1287,43 @@ describe('getFlowValidation - Integrationstest', () => {
12781287
})
12791288
});
12801289

1290+
it('fails when a node references an unreachable function definition', () => {
1291+
1292+
const flow: Flow = {
1293+
startingNodeId: "gid://sagittarius/NodeFunction/1",
1294+
nodes: {
1295+
nodes: [
1296+
{
1297+
id: "gid://sagittarius/NodeFunction/1",
1298+
functionDefinition: {identifier: "std::number::add"},
1299+
parameters: {
1300+
nodes: [
1301+
{value: {__typename: "LiteralValue", value: 1}},
1302+
{value: {__typename: "LiteralValue", value: 2}}
1303+
]
1304+
},
1305+
nextNodeId: "gid://sagittarius/NodeFunction/2"
1306+
},
1307+
{
1308+
id: "gid://sagittarius/NodeFunction/2",
1309+
functionDefinition: {identifier: "std::imaginary::nonexistent"},
1310+
parameters: {nodes: []}
1311+
}
1312+
]
1313+
}
1314+
};
1315+
1316+
const result = getFlowValidation(flow, FUNCTION_SIGNATURES, DATA_TYPES);
1317+
1318+
expect(result.isValid).toBe(false);
1319+
expect(result.diagnostics).toEqual([
1320+
expect.objectContaining({
1321+
nodeId: "gid://sagittarius/NodeFunction/2",
1322+
parameterIndex: null,
1323+
message: 'The function definition "std::imaginary::nonexistent" is not reachable.',
1324+
severity: "error",
1325+
})
1326+
]);
1327+
});
1328+
12811329
});

0 commit comments

Comments
 (0)