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:
José Braulio González Valido 2026-10-05 13:57:14 +00:00 committed by GitHub
parent 206fc6f317
commit b7071c91c7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 38 additions and 1 deletions

View File

@ -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 () => {

View File

@ -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) {