Skip to content

Commit 76027b6

Browse files
committed
fix for /test for files outside of workspace.
1 parent 5e1a94b commit 76027b6

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

packages/core/src/amazonqTest/chat/controller/controller.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -439,16 +439,24 @@ export class TestController {
439439

440440
const language = await this.getLanguageForFilePath(filePath)
441441
session.fileLanguage = language
442+
const workspaceFolder = vscode.workspace.getWorkspaceFolder(fileEditorToTest.document.uri)
442443

443444
/*
444445
For Re:Invent 2024 we are supporting only java and python for unit test generation, rest of the languages shows the similar experience as CWC
445446
*/
446-
if (language !== 'java' && language !== 'python') {
447-
const unsupportedLanguage = language.charAt(0).toUpperCase() + language.slice(1)
448-
let unsupportedMessage = `<span style="color: #EE9D28;">&#9888;<b>I'm sorry, but /test only supports Python and Java</b><br></span> While ${unsupportedLanguage} is not supported, I will generate a suggestion below. `
449-
// handle the case when language is undefined
450-
if (!unsupportedLanguage) {
451-
unsupportedMessage = `<span style="color: #EE9D28;">&#9888;<b>I'm sorry, but /test only supports Python and Java</b><br></span> I will still generate a suggestion below. `
447+
if (!['java', 'python'].includes(language) || workspaceFolder == undefined) {
448+
let unsupportedMessage: string
449+
const unsupportedLanguage = language ? language.charAt(0).toUpperCase() + language.slice(1) : ''
450+
if (!workspaceFolder) {
451+
// File is outside of workspace
452+
unsupportedMessage = `<span style="color: #EE9D28;">&#9888;<b>External File Detected:</b> ${fileName} is outside of workspace scope.<br></span> However, I can still help you create unit tests for ${fileName} here.`
453+
} else {
454+
// File is in workspace, check language support
455+
if (unsupportedLanguage) {
456+
unsupportedMessage = `<span style="color: #EE9D28;">&#9888;<b>I'm sorry, but /test only supports Python and Java</b><br></span> While ${unsupportedLanguage} is not supported, I will generate a suggestion below.`
457+
} else {
458+
unsupportedMessage = `<span style="color: #EE9D28;">&#9888;<b>I'm sorry, but /test only supports Python and Java</b><br></span> I will still generate a suggestion below.`
459+
}
452460
}
453461
this.messenger.sendMessage(unsupportedMessage, tabID, 'answer')
454462
await this.onCodeGeneration(session, message.prompt, tabID, fileName, filePath)

0 commit comments

Comments
 (0)