Skip to content
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

fix(Amazon Q): fix for test generation target file missing from payload. #5261

Merged
merged 21 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
526d8c9
Fix for Test generation zip to include target file, Regex pattern fix…
ashishrp-aws Jan 14, 2025
e182ec6
Merge branch 'main' into workspace-test
ashishrp-aws Jan 14, 2025
d943f8b
Merge branch 'main' into workspace-test
ashishrp-aws Jan 14, 2025
346cee3
Merge branch 'main' into workspace-test
ashishrp-aws Jan 14, 2025
556f3f1
Merge branch 'main' into workspace-test
ashishrp-aws Jan 15, 2025
a394c85
Removing FeatureDevSessionContext changes.
ashishrp-aws Jan 15, 2025
9276a46
Merge branch 'main' into workspace-test
ashishrp-aws Jan 15, 2025
e7544f0
Added comment explaining file inclusion.
ashishrp-aws Jan 15, 2025
f19f44a
Merge branch 'main' into workspace-test
ashishrp-aws Jan 15, 2025
7365162
Added Timeout and length check for pattern matching
ashishrp-aws Jan 15, 2025
37dc441
detekt correction.
ashishrp-aws Jan 15, 2025
4662cca
detekt Main correction for Nameshadowing.
ashishrp-aws Jan 15, 2025
62f896d
Merge branch 'main' into workspace-test
ashishrp-aws Jan 16, 2025
89545c2
Reverting the FeatureDevSessionContext pattern matching chnages.
ashishrp-aws Jan 16, 2025
1a8c609
Correcting the chnages for FeatureDevSessionContext
ashishrp-aws Jan 16, 2025
a48f031
Merge branch 'main' into workspace-test
ashishrp-aws Jan 17, 2025
7d2979c
Merge branch 'main' into workspace-test
ashishrp-aws Jan 17, 2025
86efb24
Merge branch 'main' into workspace-test
ashishrp-aws Jan 17, 2025
812c790
Merge branch 'main' into workspace-test
ashishrp-aws Jan 17, 2025
12fc617
Merge branch 'main' into workspace-test
ashishrp-aws Jan 20, 2025
fd92af6
Merge branch 'main' into workspace-test
ashishrp-aws Jan 21, 2025
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" : "bugfix",
"description" : "Amazon Q /test: Fix for test generation payload creation to not filter out target file."
}
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ class CodeTestChatController(

val requestData = ChatRequestData(
tabId = session.tabId,
message = "Generate unit tests for the following part of my code: ${message.prompt}",
message = "Generate unit tests for the following part of my code: ${message.prompt.ifBlank { fileInfo.fileName }}",
activeFileContext = activeFileContext,
userIntent = UserIntent.GENERATE_UNIT_TESTS,
triggerType = TriggerType.ContextMenu,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class FeatureDevSessionContextTest : FeatureDevTestBase(HeavyJavaCodeInsightTest
@Test
fun testZipProject() {
addFilesToProjectModule(
".gitignore",
".gradle/cached.jar",
"src/MyClass.java",
"gradlew",
Expand All @@ -83,6 +84,19 @@ class FeatureDevSessionContextTest : FeatureDevTestBase(HeavyJavaCodeInsightTest
"settings.gradle",
"build.gradle",
"gradle/wrapper/gradle-wrapper.properties",
"builder/GetTestBuilder.java", // check for false positives
".aws-sam/build/function1",
".gem/specs.rb",
"archive.zip",
"output.bin",
"images/logo.png",
"assets/header.jpg",
"icons/menu.svg",
"license.txt",
"License.md",
"node_modules/express",
"build/outputs",
"dist/bundle.js"
)

val zipResult = featureDevSessionContext.getProjectZip()
Expand All @@ -102,9 +116,10 @@ class FeatureDevSessionContextTest : FeatureDevTestBase(HeavyJavaCodeInsightTest
"gradlew",
"gradlew.bat",
"README.md",
"gradle/wrapper/gradle-wrapper.properties",
"builder/GetTestBuilder.java",
"settings.gradle",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noticed that settings.gradle and build.gradle are being dropped. These should be included as a part of the zip for /dev.

Is this the result of changing the gitignore used for the test or a change in the actual behavior of the function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can amend this for /dev.

"build.gradle",
"gradle/wrapper/gradle-wrapper.properties",
)

assertTrue(zippedFiles == expectedFiles)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class CodeTestSessionConfig(
}

// 2. Add the "utgRequiredArtifactsDir" directory
val utgDir = "utgRequiredArtifactsDir"
val utgDir = "utgRequiredArtifactsDir/" // Note the trailing slash which adds it as a directory and not a file
LOG.debug { "Adding directory to ZIP: $utgDir" }
val utgEntry = ZipEntry(utgDir)
it.putNextEntry(utgEntry)
Expand All @@ -150,7 +150,7 @@ class CodeTestSessionConfig(
val buildAndExecuteLogDir = "buildAndExecuteLogDir"
val subDirs = listOf(buildAndExecuteLogDir, "repoMapData", "testCoverageDir")
subDirs.forEach { subDir ->
val subDirPathString = Path.of(utgDir, subDir).name
val subDirPathString = Path.of(utgDir, subDir).toString() + "/" // Added trailing slash similar to utgRequiredArtifactsDir
LOG.debug { "Adding empty directory to ZIP: $subDirPathString" }
val zipEntry = ZipEntry(subDirPathString)
it.putNextEntry(zipEntry)
Expand All @@ -168,6 +168,18 @@ class CodeTestSessionConfig(
var currentTotalLines = 0L
val languageCounts = mutableMapOf<CodeWhispererProgrammingLanguage, Int>()

// Adding Target File to make sure target file doesn't get filtered out.
selectedFile?.let { selected ->
files.add(selected.path)
currentTotalFileSize += selected.length
currentTotalLines += countLinesInVirtualFile(selected)
selected.programmingLanguage().let { language ->
if (language !is CodeWhispererUnknownLanguage) {
languageCounts[language] = (languageCounts[language] ?: 0) + 1
}
}
}

moduleLoop@ for (module in project.modules) {
val changeListManager = ChangeListManager.getInstance(module.project)
if (module.guessModuleDir() != null) {
Expand All @@ -176,7 +188,8 @@ class CodeTestSessionConfig(
val current = stack.pop()

if (!current.isDirectory) {
if (current.isFile && !changeListManager.isIgnoredFile(current) &&
if (current.isFile && current.path != selectedFile?.path &&
!changeListManager.isIgnoredFile(current) &&
runBlocking { !featureDevSessionContext.ignoreFile(current) } &&
runReadAction { !fileIndex.isInLibrarySource(current) }
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ class FeatureDevSessionContext(val project: Project, val maxProjectSizeBytes: Lo
.replace(".", "\\.")
.replace("*", ".*")
.let { if (it.endsWith("/")) "$it.*" else "$it/.*" } // Add a trailing /* to all patterns. (we add a trailing / to all files when matching)

var selectedSourceFolder: VirtualFile
set(newRoot) {
_selectedSourceFolder = newRoot
Expand Down
Loading