mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 17:46:45 +00:00
fix(Structured Output Parser Node, Auto-fixing Output Parser Node, Tools Agent Node): Structured output improvements (#13908)
Co-authored-by: Oleg Ivaniv <me@olegivaniv.com>
This commit is contained in:
@@ -4,7 +4,7 @@ import { NodeOperationError } from 'n8n-workflow';
|
||||
import type { ISupplyDataFunctions, IExecuteFunctions, INode } from 'n8n-workflow';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { escapeSingleCurlyBrackets, getConnectedTools } from '../helpers';
|
||||
import { escapeSingleCurlyBrackets, getConnectedTools, unwrapNestedOutput } from '../helpers';
|
||||
import { N8nTool } from '../N8nTool';
|
||||
|
||||
describe('escapeSingleCurlyBrackets', () => {
|
||||
@@ -243,3 +243,101 @@ describe('getConnectedTools', () => {
|
||||
expect(tools[0]).toBe(mockN8nTool);
|
||||
});
|
||||
});
|
||||
|
||||
describe('unwrapNestedOutput', () => {
|
||||
it('should unwrap doubly nested output', () => {
|
||||
const input = {
|
||||
output: {
|
||||
output: {
|
||||
text: 'Hello world',
|
||||
confidence: 0.95,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const expected = {
|
||||
output: {
|
||||
text: 'Hello world',
|
||||
confidence: 0.95,
|
||||
},
|
||||
};
|
||||
|
||||
expect(unwrapNestedOutput(input)).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should not modify regular output object', () => {
|
||||
const input = {
|
||||
output: {
|
||||
text: 'Hello world',
|
||||
confidence: 0.95,
|
||||
},
|
||||
};
|
||||
|
||||
expect(unwrapNestedOutput(input)).toEqual(input);
|
||||
});
|
||||
|
||||
it('should not modify object without output property', () => {
|
||||
const input = {
|
||||
result: 'success',
|
||||
data: {
|
||||
text: 'Hello world',
|
||||
},
|
||||
};
|
||||
|
||||
expect(unwrapNestedOutput(input)).toEqual(input);
|
||||
});
|
||||
|
||||
it('should not modify when output is not an object', () => {
|
||||
const input = {
|
||||
output: 'Hello world',
|
||||
};
|
||||
|
||||
expect(unwrapNestedOutput(input)).toEqual(input);
|
||||
});
|
||||
|
||||
it('should not modify when object has multiple properties', () => {
|
||||
const input = {
|
||||
output: {
|
||||
output: {
|
||||
text: 'Hello world',
|
||||
},
|
||||
},
|
||||
meta: {
|
||||
timestamp: 123456789,
|
||||
},
|
||||
};
|
||||
|
||||
expect(unwrapNestedOutput(input)).toEqual(input);
|
||||
});
|
||||
|
||||
it('should not modify when inner output has multiple properties', () => {
|
||||
const input = {
|
||||
output: {
|
||||
output: {
|
||||
text: 'Hello world',
|
||||
},
|
||||
meta: {
|
||||
timestamp: 123456789,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
expect(unwrapNestedOutput(input)).toEqual(input);
|
||||
});
|
||||
|
||||
it('should handle null values properly', () => {
|
||||
const input = {
|
||||
output: null,
|
||||
};
|
||||
|
||||
expect(unwrapNestedOutput(input)).toEqual(input);
|
||||
});
|
||||
|
||||
it('should handle empty object values properly', () => {
|
||||
const input = {
|
||||
output: {},
|
||||
};
|
||||
|
||||
expect(unwrapNestedOutput(input)).toEqual(input);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user