Skip to content

Commit fe717b5

Browse files
authored
Merge branch 'main' into fix/cancel-button
2 parents fae5522 + f5ed158 commit fe717b5

File tree

8 files changed

+148
-168
lines changed

8 files changed

+148
-168
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type" : "bugfix",
3+
"description" : "Amazon Q /test: Test generation fails for files outside the project"
4+
}

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ mockitoKotlin = "5.4.0"
2727
mockk = "1.13.10"
2828
nimbus-jose-jwt = "9.40"
2929
node-gradle = "7.0.2"
30-
telemetryGenerator = "1.0.291"
30+
telemetryGenerator = "1.0.293"
3131
testLogger = "4.0.0"
3232
testRetry = "1.5.10"
3333
# test-only; platform provides slf4j transitively at runtime

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqCodeTest/CodeWhispererUTGChatManager.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,7 @@ class CodeWhispererUTGChatManager(val project: Project, private val cs: Coroutin
512512
AmazonqTelemetry.utgGenerateTests(
513513
cwsprChatProgrammingLanguage = session.programmingLanguage.languageId,
514514
hasUserPromptSupplied = session.hasUserPromptSupplied,
515+
isFileInWorkspace = true,
515516
isSupportedLanguage = true,
516517
credentialStartUrl = getStartUrl(project),
517518
jobGroup = session.testGenerationJobGroupName,

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqCodeTest/controller/CodeTestChatController.kt

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import com.intellij.openapi.application.ApplicationManager
1212
import com.intellij.openapi.fileEditor.FileDocumentManager
1313
import com.intellij.openapi.fileEditor.FileEditorManager
1414
import com.intellij.openapi.project.Project
15+
import com.intellij.openapi.project.guessProjectDir
1516
import com.intellij.openapi.vfs.LocalFileSystem
1617
import com.intellij.openapi.vfs.VirtualFile
1718
import com.intellij.openapi.vfs.VirtualFileManager
@@ -22,6 +23,7 @@ import kotlinx.coroutines.future.await
2223
import kotlinx.coroutines.launch
2324
import kotlinx.coroutines.withContext
2425
import migration.software.aws.toolkits.jetbrains.services.codewhisperer.customization.CodeWhispererModelConfigurator
26+
import software.amazon.awssdk.services.codewhispererruntime.model.IdeCategory
2527
import software.amazon.awssdk.services.codewhispererruntime.model.Position
2628
import software.amazon.awssdk.services.codewhispererruntime.model.Range
2729
import software.amazon.awssdk.services.codewhispererruntime.model.Reference
@@ -87,6 +89,7 @@ import software.aws.toolkits.resources.message
8789
import software.aws.toolkits.telemetry.AmazonqTelemetry
8890
import software.aws.toolkits.telemetry.MetricResult
8991
import software.aws.toolkits.telemetry.UiTelemetry
92+
import java.io.File
9093
import java.nio.file.Files
9194
import java.nio.file.Path
9295
import java.nio.file.Paths
@@ -184,7 +187,7 @@ class CodeTestChatController(
184187
message.tabId,
185188
false
186189
)
187-
if (isLanguageSupported(fileInfo.fileLanguage.languageId)) {
190+
if (fileInfo.fileInWorkspace && isLanguageSupported(fileInfo.fileLanguage.languageId)) {
188191
// Send Capability card to chat
189192
codeTestChatHelper.addNewMessage(
190193
CodeTestChatMessageContent(informationCard = true, message = null, type = ChatMessageType.Answer, canBeVoted = false),
@@ -230,9 +233,15 @@ class CodeTestChatController(
230233
}
231234
.build()
232235

233-
val messageContent = "<span style=\"color: #EE9D28;\">&#9888;<b> ${fileInfo.fileLanguage.languageId} is not a " +
234-
"language I support specialized unit test generation for at the moment.</b><br></span>The languages " +
235-
"I support now are Python and Java. I can still provide examples, instructions and code suggestions."
236+
val messageContent = if (fileInfo.fileInWorkspace) {
237+
"<span style=\"color: #EE9D28;\">&#9888;<b> ${fileInfo.fileLanguage.languageId} is not a " +
238+
"language I support specialized unit test generation for at the moment.</b><br></span>The languages " +
239+
"I support now are Python and Java. I can still provide examples, instructions and code suggestions."
240+
} else {
241+
"<span style=\"color: #EE9D28;\">&#9888;<b> I can't generate tests for ${fileInfo.fileName}" +
242+
" because it's outside the project directory.</b><br></span> " +
243+
"I can still provide examples, instructions and code suggestions."
244+
}
236245

237246
codeTestChatHelper.addNewMessage(
238247
CodeTestChatMessageContent(
@@ -287,7 +296,8 @@ class CodeTestChatController(
287296
AmazonqTelemetry.utgGenerateTests(
288297
cwsprChatProgrammingLanguage = session.programmingLanguage.languageId,
289298
hasUserPromptSupplied = session.hasUserPromptSupplied,
290-
isSupportedLanguage = false,
299+
isFileInWorkspace = fileInfo.fileInWorkspace,
300+
isSupportedLanguage = isLanguageSupported(fileInfo.fileLanguage.languageId),
291301
credentialStartUrl = getStartUrl(project),
292302
result = MetricResult.Succeeded,
293303
perfClientLatency = (Instant.now().toEpochMilli() - session.startTimeOfTestGeneration),
@@ -571,6 +581,7 @@ class CodeTestChatController(
571581
session.testGenerationJob,
572582
session.testGenerationJobGroupName,
573583
session.programmingLanguage,
584+
IdeCategory.JETBRAINS,
574585
session.numberOfUnitTestCasesGenerated,
575586
session.numberOfUnitTestCasesGenerated,
576587
session.linesOfCodeGenerated,
@@ -588,6 +599,7 @@ class CodeTestChatController(
588599
AmazonqTelemetry.utgGenerateTests(
589600
cwsprChatProgrammingLanguage = session.programmingLanguage.languageId,
590601
hasUserPromptSupplied = session.hasUserPromptSupplied,
602+
isFileInWorkspace = true,
591603
isSupportedLanguage = true,
592604
credentialStartUrl = getStartUrl(project = context.project),
593605
jobGroup = session.testGenerationJobGroupName,
@@ -766,6 +778,7 @@ class CodeTestChatController(
766778
session.testGenerationJob,
767779
session.testGenerationJobGroupName,
768780
session.programmingLanguage,
781+
IdeCategory.JETBRAINS,
769782
session.numberOfUnitTestCasesGenerated,
770783
0,
771784
session.linesOfCodeGenerated,
@@ -782,6 +795,7 @@ class CodeTestChatController(
782795
AmazonqTelemetry.utgGenerateTests(
783796
cwsprChatProgrammingLanguage = session.programmingLanguage.languageId,
784797
hasUserPromptSupplied = session.hasUserPromptSupplied,
798+
isFileInWorkspace = true,
785799
isSupportedLanguage = true,
786800
credentialStartUrl = getStartUrl(project = context.project),
787801
jobGroup = session.testGenerationJobGroupName,
@@ -1111,6 +1125,7 @@ class CodeTestChatController(
11111125
val filePath: String,
11121126
val fileName: String,
11131127
val fileLanguage: CodeWhispererProgrammingLanguage,
1128+
val fileInWorkspace: Boolean = true,
11141129
)
11151130

11161131
private suspend fun updateUIState() {
@@ -1142,6 +1157,9 @@ class CodeTestChatController(
11421157
val fileEditorManager = FileEditorManager.getInstance(project)
11431158
val activeEditor = fileEditorManager.selectedEditor
11441159
val activeFile = fileEditorManager.selectedFiles.firstOrNull()
1160+
val projectRoot = project.basePath?.let { Path.of(it) }?.toFile()?.toVirtualFile() ?: run {
1161+
project.guessProjectDir() ?: error("Cannot guess base directory for project ${project.name}")
1162+
}
11451163

11461164
if (activeEditor == null || activeFile == null) {
11471165
handleInvalidFileState(message.tabId)
@@ -1156,6 +1174,7 @@ class CodeTestChatController(
11561174
filePath = activeFile.path,
11571175
fileName = activeFile.name,
11581176
fileLanguage = programmingLanguage,
1177+
fileInWorkspace = activeFile.path.startsWith(projectRoot.path)
11591178
)
11601179
} catch (e: Exception) {
11611180
LOG.debug { "Error checking active file: $e" }
@@ -1169,6 +1188,8 @@ class CodeTestChatController(
11691188
}
11701189
}
11711190

1191+
private fun File.toVirtualFile() = LocalFileSystem.getInstance().findFileByIoFile(this)
1192+
11721193
/* UTG Tab Chat input use cases:
11731194
* 1. If User exits the flow and want to start a new generate unit test cycle.
11741195
* 2. If User clicks on Modify build command option and can enter the build command from chat input

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/credentials/CodeWhispererClientAdaptor.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import software.amazon.awssdk.services.codewhispererruntime.model.GenerateComple
2727
import software.amazon.awssdk.services.codewhispererruntime.model.GetCodeFixJobRequest
2828
import software.amazon.awssdk.services.codewhispererruntime.model.GetCodeFixJobResponse
2929
import software.amazon.awssdk.services.codewhispererruntime.model.GetTestGenerationResponse
30+
import software.amazon.awssdk.services.codewhispererruntime.model.IdeCategory
3031
import software.amazon.awssdk.services.codewhispererruntime.model.InlineChatUserDecision
3132
import software.amazon.awssdk.services.codewhispererruntime.model.ListAvailableCustomizationsRequest
3233
import software.amazon.awssdk.services.codewhispererruntime.model.ListFeatureEvaluationsResponse
@@ -199,6 +200,7 @@ interface CodeWhispererClientAdaptor : Disposable {
199200
jobId: String,
200201
groupName: String,
201202
language: CodeWhispererProgrammingLanguage?,
203+
ideCategory: IdeCategory?,
202204
numberOfUnitTestCasesGenerated: Int?,
203205
numberOfUnitTestCasesAccepted: Int?,
204206
linesOfCodeGenerated: Int?,
@@ -668,6 +670,7 @@ open class CodeWhispererClientAdaptorImpl(override val project: Project) : CodeW
668670
jobId: String,
669671
groupName: String,
670672
language: CodeWhispererProgrammingLanguage?,
673+
ideCategory: IdeCategory?,
671674
numberOfUnitTestCasesGenerated: Int?,
672675
numberOfUnitTestCasesAccepted: Int?,
673676
linesOfCodeGenerated: Int?,
@@ -682,6 +685,7 @@ open class CodeWhispererClientAdaptorImpl(override val project: Project) : CodeW
682685
}
683686
it.jobId(jobId)
684687
it.groupName(groupName)
688+
it.ideCategory(ideCategory)
685689
it.numberOfUnitTestCasesGenerated(numberOfUnitTestCasesGenerated)
686690
it.numberOfUnitTestCasesAccepted(numberOfUnitTestCasesAccepted)
687691
it.linesOfCodeGenerated(linesOfCodeGenerated)

plugins/core/jetbrains-community/resources/telemetryOverride.json

Lines changed: 0 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
11
{
22
"types": [
3-
{
4-
"name": "acceptedCharactersCount",
5-
"type": "int",
6-
"description": "The number of accepted characters"
7-
},
8-
{
9-
"name": "acceptedCount",
10-
"type": "int",
11-
"description": "The number of accepted cases"
12-
},
13-
{
14-
"name": "acceptedLinesCount",
15-
"type": "int",
16-
"description": "The number of accepted lines of code"
17-
},
183
{
194
"name": "amazonqIndexFileSizeInMB",
205
"type": "int",
@@ -40,16 +25,6 @@
4025
"type": "string",
4126
"description": "Source triggering token refresh"
4227
},
43-
{
44-
"name": "buildPayloadBytes",
45-
"type": "int",
46-
"description": "The uncompressed payload size in bytes of the source files in customer project context"
47-
},
48-
{
49-
"name": "buildZipFileBytes",
50-
"type": "int",
51-
"description": "The compressed payload size of source files in bytes of customer project context sent"
52-
},
5328
{
5429
"name": "component",
5530
"allowedValues": [
@@ -190,46 +165,6 @@
190165
"type": "int",
191166
"description": "The number of executed operations"
192167
},
193-
{
194-
"name": "generatedCharactersCount",
195-
"type": "int",
196-
"description": "Number of characters of code generated"
197-
},
198-
{
199-
"name": "generatedCount",
200-
"type": "int",
201-
"description": "The number of generated cases"
202-
},
203-
{
204-
"name": "generatedLinesCount",
205-
"type": "int",
206-
"description": "The number of generated lines of code"
207-
},
208-
{
209-
"name": "hasUserPromptSupplied",
210-
"type": "boolean",
211-
"description": "True if user supplied prompt message as input else false"
212-
},
213-
{
214-
"name": "isCodeBlockSelected",
215-
"type": "boolean",
216-
"description": "True if user selected code snippet as input else false"
217-
},
218-
{
219-
"name": "isSupportedLanguage",
220-
"type": "boolean",
221-
"description": "Indicate if the language is supported"
222-
},
223-
{
224-
"name": "jobGroup",
225-
"type": "string",
226-
"description": "Job group name used in the operation"
227-
},
228-
{
229-
"name": "jobId",
230-
"type": "string",
231-
"description": "Job id used in the operation"
232-
},
233168
{
234169
"name": "reAuth",
235170
"type": "boolean",
@@ -519,92 +454,6 @@
519454
}
520455
]
521456
},
522-
{
523-
"name": "amazonq_utgGenerateTests",
524-
"description": "Client side invocation of the AmazonQ Unit Test Generation",
525-
"metadata": [
526-
{
527-
"type": "acceptedCharactersCount",
528-
"required": false
529-
},
530-
{
531-
"type": "acceptedCount",
532-
"required": false
533-
},
534-
{
535-
"type": "acceptedLinesCount",
536-
"required": false
537-
},
538-
{
539-
"type": "artifactsUploadDuration",
540-
"required": false
541-
},
542-
{
543-
"type": "buildPayloadBytes",
544-
"required": false
545-
},
546-
{
547-
"type": "buildZipFileBytes",
548-
"required": false
549-
},
550-
{
551-
"type": "credentialStartUrl",
552-
"required": false
553-
},
554-
{
555-
"type": "cwsprChatProgrammingLanguage"
556-
},
557-
{
558-
"type": "generatedCharactersCount",
559-
"required": false
560-
},
561-
{
562-
"type": "generatedCount",
563-
"required": false
564-
},
565-
{
566-
"type": "generatedLinesCount",
567-
"required": false
568-
},
569-
{
570-
"type": "hasUserPromptSupplied"
571-
},
572-
{
573-
"type": "isCodeBlockSelected",
574-
"required": false
575-
},
576-
{
577-
"type": "isSupportedLanguage"
578-
},
579-
{
580-
"type": "jobGroup",
581-
"required": false
582-
},
583-
{
584-
"type": "jobId",
585-
"required": false
586-
},
587-
{
588-
"type": "perfClientLatency",
589-
"required": false
590-
},
591-
{
592-
"type": "result"
593-
},
594-
{
595-
"type": "reason",
596-
"required": false
597-
},
598-
{
599-
"type": "reasonDesc",
600-
"required": false
601-
},
602-
{
603-
"type": "source",
604-
"required": false
605-
}
606-
]
607-
},
608457
{
609458
"name": "auth_modifyConnection",
610459
"description": "An auth connection was modified in some way, e.g. deleted, updated",

0 commit comments

Comments
 (0)