fix(core): Coerce non-string node names in buildNodeIndex (#31411)

This commit is contained in:
Jaakko Husso 2026-06-01 00:35:08 +03:00 committed by GitHub
parent 945349e89d
commit 6cf3b0b679
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 1 deletions

View File

@ -438,6 +438,23 @@ describe('buildNodeIndex', () => {
it('returns an empty array when nodes is missing', () => {
expect(buildNodeIndex({ connections: {} } as unknown as WorkflowJSON)).toEqual([]);
});
it('coerces non-string node names to an empty string', () => {
const json = {
nodes: [
{ name: 123, type: 'x', position: [0, 0], parameters: {} },
{ type: 'y', position: [0, 0], parameters: {} },
{ name: null, type: 'z', position: [0, 0], parameters: {} },
],
connections: {},
} as unknown as WorkflowJSON;
expect(buildNodeIndex(json)).toEqual([
{ index: 0, name: '' },
{ index: 1, name: '' },
{ index: 2, name: '' },
]);
});
});
describe('buildErrorDetails', () => {

View File

@ -116,7 +116,12 @@ export function extractStructureIssues(error: unknown): WorkflowStructureIssue[]
* counting entries in its own SDK-builder code.
*/
export function buildNodeIndex(json: WorkflowJSON): Array<{ index: number; name: string }> {
return (json.nodes ?? []).map((node, index) => ({ index, name: node.name ?? '' }));
// Defensively coerce: a malformed workflow may carry a non-string node name,
// which would otherwise violate the `z.string()` output schema downstream.
return (json.nodes ?? []).map((node, index) => ({
index,
name: typeof node.name === 'string' ? node.name : '',
}));
}
/**