From cc476dd775c666d7d6e076d6b802e36b6ea53afd Mon Sep 17 00:00:00 2001 From: C Tidd Date: Tue, 26 Nov 2024 13:13:25 -0800 Subject: [PATCH] fix(amazonq): Normalize generated file paths in feature dev. (#5130) The agent may generate files with or without a leading slash in the generated file path. In JetBrains, this results in an exception thrown when attempting to write to the root directory on MacOS. (Various other failure modes may occur due to lack of normalization, depending on OS.) This change normalized handling within /dev, to avoid breakage or other side effects of non-normalized file paths. --- .../bugfix-fd7f4f61-241e-40a6-b92a-3e4fe7e832db.json | 4 ++++ .../amazonqFeatureDev/session/CodeGenerationState.kt | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 .changes/next-release/bugfix-fd7f4f61-241e-40a6-b92a-3e4fe7e832db.json diff --git a/.changes/next-release/bugfix-fd7f4f61-241e-40a6-b92a-3e4fe7e832db.json b/.changes/next-release/bugfix-fd7f4f61-241e-40a6-b92a-3e4fe7e832db.json new file mode 100644 index 0000000000..aefce81abc --- /dev/null +++ b/.changes/next-release/bugfix-fd7f4f61-241e-40a6-b92a-3e4fe7e832db.json @@ -0,0 +1,4 @@ +{ + "type" : "bugfix", + "description" : "Amazon Q /dev: Fix error when accepting changes if leading slash is present." +} diff --git a/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqFeatureDev/session/CodeGenerationState.kt b/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqFeatureDev/session/CodeGenerationState.kt index 5b172e73c7..f0aa2e8f41 100644 --- a/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqFeatureDev/session/CodeGenerationState.kt +++ b/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqFeatureDev/session/CodeGenerationState.kt @@ -258,7 +258,8 @@ private suspend fun CodeGenerationState.generateCode( fun registerNewFiles(newFileContents: Map): List = newFileContents.map { NewFileZipInfo( - zipFilePath = it.key, + // Note: When managing file state, we normalize file paths returned from the agent in order to ensure they are handled as relative paths. + zipFilePath = it.key.removePrefix("/"), fileContent = it.value, rejected = false, changeApplied = false @@ -268,7 +269,8 @@ fun registerNewFiles(newFileContents: Map): List fun registerDeletedFiles(deletedFiles: List): List = deletedFiles.map { DeletedFileInfo( - zipFilePath = it, + // Note: When managing file state, we normalize file paths returned from the agent in order to ensure they are handled as relative paths. + zipFilePath = it.removePrefix("/"), rejected = false, changeApplied = false )