Skip to content

feat(amazonq): Remove unsupported message for non-java python languages in /test #5579

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type" : "feature",
"description" : "Amazon Q /test: Remove unsupported message for non-java python languages"
}
Original file line number Diff line number Diff line change
Expand Up @@ -244,26 +244,22 @@ class CodeTestChatController(
})
}
.build()
if (!fileInfo.fileInWorkspace) {
val messageContent =
"<span style=\"color: #EE9D28;\">&#9888;<b> I can't generate tests for ${fileInfo.fileName}" +
" because it's outside the project directory.</b><br></span> " +
"I can still provide examples, instructions and code suggestions."

val messageContent = if (fileInfo.fileInWorkspace) {
"<span style=\"color: #EE9D28;\">&#9888;<b> ${fileInfo.fileLanguage.languageId} is not a " +
"language I support specialized unit test generation for at the moment.</b><br></span>The languages " +
"I support now are Python and Java. I can still provide examples, instructions and code suggestions."
} else {
"<span style=\"color: #EE9D28;\">&#9888;<b> I can't generate tests for ${fileInfo.fileName}" +
" because it's outside the project directory.</b><br></span> " +
"I can still provide examples, instructions and code suggestions."
codeTestChatHelper.addNewMessage(
CodeTestChatMessageContent(
message = messageContent,
type = ChatMessageType.Answer,
canBeVoted = false
),
message.tabId,
false
)
}

codeTestChatHelper.addNewMessage(
CodeTestChatMessageContent(
message = messageContent,
type = ChatMessageType.Answer,
canBeVoted = false
),
message.tabId,
false
)
testResponseMessageId = codeTestChatHelper.addAnswer(
CodeTestChatMessageContent(
message = "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,42 +157,6 @@ class QTestGenerationChatTest {
}
}

@Test
fun `test unsupported language error path from the chat`() {
val testCase = TestCase(
IdeProductProvider.IC,
LocalProjectInfo(
Paths.get("tstData", "qTestGenerationTestProject/")
)
).withVersion(System.getProperty("org.gradle.project.ideProfileName"))

// inject connection
useExistingConnectionForTest()

Starter.newContext(CurrentTestMethod.hyphenateWithClass(), testCase).apply {
System.getProperty("ui.test.plugins").split(File.pathSeparator).forEach { path ->
pluginConfigurator.installPluginFromPath(
Path.of(path)
)
}

copyExistingConfig(Paths.get("tstData", "configAmazonQTests"))
updateGeneralSettings()
}.runIdeWithDriver()
.useDriverAndCloseIde {
waitForProjectOpen()
openFile(Paths.get("testModule2", "UnSupportedLanguage.kt").toString())
Thread.sleep(30000)
val result = executePuppeteerScript(unsupportedLanguagePath)

assertThat(result)
.contains(
"new tab opened",
"Test generation complete with expected error"
)
}
}

companion object {
@JvmStatic
@AfterAll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,83 +247,3 @@ val expectedErrorPath = """
}
testNavigation().catch(console.error);
""".trimIndent()

val unsupportedLanguagePath = """
const puppeteer = require('puppeteer');
async function testNavigation() {
const browser = await puppeteer.connect({
browserURL: "http://localhost:9222"
})
try {
const pages = await browser.pages()
//console.log(pages)
for(const page of pages) {
const contents = await page.evaluate(el => el.innerHTML, await page.${'$'}(':root'));
//console.log(contents)
const element = await page.${'$'}('.mynah-chat-prompt-input')
if(element) {
const elements = await page.${'$'}${'$'}('.mynah-chat-command-selector-command');
const attr = await Promise.all(
elements.map(elem => elem.evaluate(el => el.getAttribute('command')))
);
await page.type('.mynah-chat-prompt-input', '/test')

await page.keyboard.press('Enter');
await page.keyboard.press('Enter');

try {
await waitForElementWithText(page, "Q - Test")
console.log("new tab opened")
await page.waitForFunction(
(expectedText) => {
const pageContent = document.body.textContent || '';
return pageContent.includes(expectedText);
},
{
timeout: 300000 // 5 minutes timeout
},
"is not a language I support specialized unit test generation for at the moment."
);
console.log("Test generation complete with expected error")

} catch (e) {
console.log("Element with text not found")
console.log(e)
throw e
}

}
}
} finally {
await browser.close();
}
}

async function waitForElementWithText(page, text) {
await page.waitForFunction(
(expectedText) => {
const elements = document.querySelectorAll('*');
return Array.from(elements).find(element =>
element.textContent?.trim() === expectedText
);
},
{},
text
);
}

async function waitAndGetElementByText(page, text) {
const element = await page.waitForFunction(
(expectedText) => {
const elements = document.querySelectorAll('*');
return Array.from(elements).find(element =>
element.textContent?.trim() === expectedText
);
},
{},
text
);
return element;
}
testNavigation().catch(console.error);
""".trimIndent()

This file was deleted.

Loading