Skip to content

Commit aca090b

Browse files
committed
feat(amazonq): skip registering run command log file
1 parent ab9f5bc commit aca090b

File tree

4 files changed

+56
-2
lines changed

4 files changed

+56
-2
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type" : "feature",
3+
"description" : "The logs emitted by the Agent during user command execution will be accepted and written to `.amazonq/dev/run_command.log` file in the user's local repository."
4+
}

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqFeatureDev/session/CodeGenerationState.kt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
package software.aws.toolkits.jetbrains.services.amazonqFeatureDev.session
55

6+
import com.intellij.openapi.vfs.VirtualFile
67
import kotlinx.coroutines.delay
78
import software.amazon.awssdk.services.codewhispererruntime.model.CodeGenerationWorkflowStatus
89
import software.aws.toolkits.core.utils.getLogger
@@ -27,8 +28,11 @@ import software.aws.toolkits.jetbrains.services.cwc.controller.chat.telemetry.ge
2728
import software.aws.toolkits.resources.message
2829
import software.aws.toolkits.telemetry.AmazonqTelemetry
2930
import software.aws.toolkits.telemetry.MetricResult
31+
import java.nio.file.Path
32+
import java.nio.file.Paths
3033
import java.util.UUID
3134

35+
fun VirtualFile.toNioPath(): Path = Paths.get(this.path)
3236
private val logger = getLogger<CodeGenerationState>()
3337

3438
class CodeGenerationState(
@@ -211,7 +215,18 @@ private suspend fun CodeGenerationState.generateCode(
211215
conversationId = config.conversationId,
212216
)
213217

214-
val newFileInfo = registerNewFiles(newFileContents = codeGenerationStreamResult.new_file_contents)
218+
val mutableNewFileContents = codeGenerationStreamResult.new_file_contents.toMutableMap()
219+
val keysToRemove = mutableListOf<String>()
220+
for (file in mutableNewFileContents.keys) {
221+
if (file.endsWith(".amazonq/dev/run_command.log")) {
222+
val contents: String = mutableNewFileContents[file].orEmpty()
223+
logger.info(contents) { "Run command log: $contents" }
224+
keysToRemove.add(file)
225+
}
226+
}
227+
keysToRemove.forEach { key -> mutableNewFileContents.remove(key) }
228+
229+
val newFileInfo = registerNewFiles(newFileContents = mutableNewFileContents)
215230
val deletedFileInfo = registerDeletedFiles(deletedFiles = codeGenerationStreamResult.deleted_files)
216231

217232
return CodeGenerationResult(

plugins/amazonq/chat/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/amazonqFeatureDev/FeatureDevTestBase.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ open class FeatureDevTestBase(
6565
internal val otherStatus = "Other"
6666
internal val testTabId = "test-tab-id"
6767
internal val testFilePaths = mapOf(Pair("test.ts", "This is a comment"))
68+
internal val testRunCommandLogPath = ".amazonq/dev/run_command.log"
69+
internal val testLogPath = mapOf(Pair(testRunCommandLogPath, "This is a log"))
6870
internal val testDeletedFiles = listOf("deleted.ts")
6971
internal val testReferences = listOf(CodeReferenceGenerated())
7072
internal val testChecksumSha = "test-sha"

plugins/amazonq/chat/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/amazonqFeatureDev/session/CodeGenerationStateTest.kt

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,14 @@ class CodeGenerationStateTest : FeatureDevTestBase() {
3939
private lateinit var messenger: MessagePublisher
4040
private val action = SessionStateAction("test-task", userMessage)
4141
private lateinit var featureDevService: FeatureDevService
42+
private lateinit var repoContext: FeatureDevSessionContext
4243

4344
@Before
4445
override fun setup() {
4546
featureDevService = mockk<FeatureDevService>()
4647
every { featureDevService.project } returns projectRule.project
4748
messenger = mock()
48-
val repoContext = mock<FeatureDevSessionContext>()
49+
repoContext = mockk<FeatureDevSessionContext>()
4950
val sessionStateConfig = SessionStateConfig(testConversationId, repoContext, featureDevService)
5051

5152
codeGenerationState =
@@ -103,6 +104,38 @@ class CodeGenerationStateTest : FeatureDevTestBase() {
103104
coVerify(exactly = 1) { featureDevService.exportTaskAssistArchiveResult(testConversationId) }
104105
}
105106

107+
@Test
108+
fun `test generateCode excludes run_command log file and logs its content`() {
109+
val runCommandLogFileName = "run_command.log"
110+
111+
val archiveFiles = mapOf(
112+
runCommandLogFileName to "newLog",
113+
"other.ts" to "other content"
114+
)
115+
val deletedFiles = emptyList<DeletedFileInfo>()
116+
val references = emptyList<CodeReference>()
117+
118+
every { featureDevService.getTaskAssistCodeGeneration(any(), any()) } returns exampleCompleteGetTaskAssistCodeGenerationResponse
119+
every { featureDevService.startTaskAssistCodeGeneration(any(), any(), any(), any(), any()) } returns exampleStartTaskAssistConversationResponse
120+
coEvery { featureDevService.exportTaskAssistArchiveResult(any()) } returns
121+
CodeGenerationStreamResult(archiveFiles, deletedFiles, references)
122+
123+
runTest {
124+
val actual = codeGenerationState.interact(action)
125+
assertThat(actual.nextState).isInstanceOf(PrepareCodeGenerationState::class.java)
126+
val nextState = actual.nextState as PrepareCodeGenerationState
127+
128+
assertThat(nextState.logContent).isEqualTo("newLog")
129+
130+
assertThat(nextState.filePaths).doesNotContain(
131+
NewFileZipInfo(runCommandLogFileName, "newLog", rejected = false, changeApplied = false)
132+
)
133+
assertThat(nextState.filePaths).contains(
134+
NewFileZipInfo("other.ts", "other content", rejected = false, changeApplied = false)
135+
)
136+
}
137+
}
138+
106139
@Test(expected = FeatureDevException::class)
107140
fun `test code generation failed`() =
108141
runTest {

0 commit comments

Comments
 (0)