mirror of
https://github.com/n8n-io/n8n.git
synced 2026-10-17 05:29:44 +02:00
fix(ai-builder): Treat a blank folder path as no folder in the build tool (#40116)
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
206fc6f317
commit
b7071c91c7
|
|
@ -475,6 +475,40 @@ describe('createBuildWorkflowTool', () => {
|
|||
expect(context.workflowService.updateFromWorkflowJSON).not.toHaveBeenCalled();
|
||||
expect(result.errors?.join(' ')).toContain('move-workflow-to-folder');
|
||||
});
|
||||
|
||||
it.each(['', ' ', '/'])(
|
||||
'creates at the project root when folderPath is %j',
|
||||
async (folderPath) => {
|
||||
const { context, filePath } = makeContext({
|
||||
overrides: { folderExplorationEnabled: true },
|
||||
});
|
||||
|
||||
const result = await executeTool<BuildToolOutput>(createBuildWorkflowTool(context), {
|
||||
filePath,
|
||||
name: 'Root workflow',
|
||||
folderPath,
|
||||
});
|
||||
|
||||
expect(result.success).toBe(true);
|
||||
expect(context.workflowService.createFromWorkflowJSON).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ name: 'Root workflow' }),
|
||||
{ markAsAiTemporary: true },
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
it('updates an existing workflow when folderPath is blank', async () => {
|
||||
const { context, filePath } = makeContext({ overrides: { folderExplorationEnabled: true } });
|
||||
|
||||
const result = await executeTool<BuildToolOutput>(createBuildWorkflowTool(context), {
|
||||
filePath,
|
||||
workflowId: 'wf-1',
|
||||
folderPath: '',
|
||||
});
|
||||
|
||||
expect(result.success).toBe(true);
|
||||
expect(context.workflowService.updateFromWorkflowJSON).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
it('builds a new workflow from a workspace source file', async () => {
|
||||
|
|
|
|||
|
|
@ -775,8 +775,11 @@ export function createBuildWorkflowTool(context: InstanceAiContext) {
|
|||
const targetWorkflowId = binding.workflowId;
|
||||
// Only the folder-enabled schema carries the field; the narrowing keeps the
|
||||
// handler valid for both shapes without a cast.
|
||||
// Blank or "/" names no folder: OpenAI's strict tool schemas make models fill every field.
|
||||
const folderPath =
|
||||
'folderPath' in input && typeof input.folderPath === 'string'
|
||||
'folderPath' in input &&
|
||||
typeof input.folderPath === 'string' &&
|
||||
/[^\s/]/.test(input.folderPath)
|
||||
? input.folderPath
|
||||
: undefined;
|
||||
if (folderPath !== undefined && targetWorkflowId) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user