Skip to content

Commit 232a273

Browse files
authored
Update file generation logic and file upload functionality for dev-execution. (aws#5295)
#### Parameter Update for Testing: - Updated function parameters to address testing issues introduced by changes made in PR aws#5077. #### Enhanced Development Prompt: - Modified GENERATE_DEV_FILE_PROMPT to support running install, build, and test commands independently. #### Improved Build and Code File Upload Logic: - Updated the logic to enable uploading build files alongside code files.
1 parent 406d0ea commit 232a273

File tree

6 files changed

+25
-16
lines changed

6 files changed

+25
-16
lines changed

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqDoc/session/PrepareDocGenerationState.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class PrepareDocGenerationState(
3939
var zipFileLength: Long? = null
4040
val nextState: SessionState
4141
try {
42-
val repoZipResult = config.repoContext.getProjectZip()
42+
val repoZipResult = config.repoContext.getProjectZip(false)
4343
val zipFileChecksum = repoZipResult.checksum
4444
zipFileLength = repoZipResult.contentLength
4545
val fileToUpload = repoZipResult.payload

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const val FEATURE_EVALUATION_PRODUCT_NAME = "FeatureDev"
88
const val FEATURE_NAME = "Amazon Q Developer Agent for software development"
99

1010
@Suppress("MaxLineLength")
11-
const val GENERATE_DEV_FILE_PROMPT = "generate a devfile in my repository. Note that you should only use devfile version 2.0.0 and the only supported command is test, so you should bundle all install, build and test commands in “test”. also you can use public.ecr.aws/aws-mde/universal-image:latest as universal image if you aren’t sure which image to use. here is an example for a node repository (but don't assume it's always a node project. look at the existing repository structure before generating the devfile): schemaVersion: 2.0.0 components: - name: dev container: image: public.ecr.aws/aws-mde/universal-image:latest commands: - id: test exec: component: dev commandLine: \"npm install && npm run build && npm run test\""
11+
const val GENERATE_DEV_FILE_PROMPT = "generate a devfile in my repository. Note that you should only use devfile version 2.0.0 and the only supported commands are install, build and test (are all optional). so you may have to bundle some commands together using '&&'. also you can use \"public.ecr.aws/aws-mde/universal-image:latest\" as universal image if you aren’t sure which image to use. here is an example for a node repository (but don't assume it's always a node project. look at the existing repository structure before generating the devfile): schemaVersion: 2.0.0 components: - name: dev container: image: public.ecr.aws/aws-mde/universal-image:latest commands: - id: install exec: component: dev commandLine: \"npm install\" - id: build exec: component: dev commandLine: \"npm run build\" - id: test exec: component: dev commandLine: \"npm run test\""
1212

1313
// Max number of times a user can attempt to retry a code generation request if it fails
1414
const val CODE_GENERATION_RETRY_LIMIT = 3

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqFeatureDev/controller/FeatureDevController.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ class FeatureDevController(
736736
return
737737
}
738738

739-
session.preloader(message, messenger)
739+
session.preloader(messenger)
740740
broadcastQEvent(QFeatureEvent.INVOCATION)
741741

742742
when (session.sessionState.phase) {

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,9 @@ class FeatureDevSessionContextTest : FeatureDevTestBase(HeavyJavaCodeInsightTest
5555

5656
@Test
5757
fun testWithInvalidFile() {
58-
val txtFile = mock<VirtualFile>()
59-
whenever(txtFile.extension).thenReturn("txt")
60-
whenever(txtFile.path).thenReturn("file.txt")
61-
assertFalse(featureDevSessionContext.isFileExtensionAllowed(txtFile))
58+
val mediaFile = mock<VirtualFile>()
59+
whenever(mediaFile.extension).thenReturn("mp4")
60+
assertFalse(featureDevSessionContext.isFileExtensionAllowed(mediaFile))
6261
}
6362

6463
@Test
@@ -96,10 +95,11 @@ class FeatureDevSessionContextTest : FeatureDevTestBase(HeavyJavaCodeInsightTest
9695
"License.md",
9796
"node_modules/express",
9897
"build/outputs",
99-
"dist/bundle.js"
98+
"dist/bundle.js",
99+
"gradle/wrapper/gradle-wrapper.jar",
100100
)
101101

102-
val zipResult = featureDevSessionContext.getProjectZip()
102+
val zipResult = featureDevSessionContext.getProjectZip(false)
103103
val zipPath = zipResult.payload.path
104104

105105
val zippedFiles = mutableSetOf<String>()
@@ -120,6 +120,8 @@ class FeatureDevSessionContextTest : FeatureDevTestBase(HeavyJavaCodeInsightTest
120120
"builder/GetTestBuilder.java",
121121
"settings.gradle",
122122
"build.gradle",
123+
"gradle/wrapper/gradle-wrapper.jar",
124+
".gitignore",
123125
)
124126

125127
assertTrue(zippedFiles == expectedFiles)

plugins/amazonq/codewhisperer/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/codewhisperer/codescan/CodeWhispererProjectCodeScanTest.kt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class CodeWhispererProjectCodeScanTest : CodeWhispererCodeScanTestBase(PythonCod
3434
private lateinit var testYaml: VirtualFile
3535
private lateinit var helperPy: VirtualFile
3636
private lateinit var testTf: VirtualFile
37+
private lateinit var gitIgnore: VirtualFile
3738

3839
private lateinit var sessionConfigSpy: CodeScanSessionConfig
3940
private lateinit var sessionConfigSpy2: CodeScanSessionConfig
@@ -63,9 +64,9 @@ class CodeWhispererProjectCodeScanTest : CodeWhispererCodeScanTestBase(PythonCod
6364
fun `test createPayload`() {
6465
val payload = sessionConfigSpy.createPayload()
6566
assertNotNull(payload)
66-
assertThat(payload.context.totalFiles).isEqualTo(10)
67+
assertThat(payload.context.totalFiles).isEqualTo(11)
6768

68-
assertThat(payload.context.scannedFiles.size).isEqualTo(10)
69+
assertThat(payload.context.scannedFiles.size).isEqualTo(11)
6970
assertThat(payload.context.scannedFiles).contains(testYaml, testTf, readMeMd, utilsJs, utilsCs, testJson, testCs, helperPy, helperCs, helpGo)
7071

7172
assertThat(payload.context.srcPayloadSize).isEqualTo(totalSize)
@@ -80,12 +81,12 @@ class CodeWhispererProjectCodeScanTest : CodeWhispererCodeScanTestBase(PythonCod
8081
filesInZip += 1
8182
}
8283

83-
assertThat(filesInZip).isEqualTo(10)
84+
assertThat(filesInZip).isEqualTo(11)
8485
}
8586

8687
@Test
8788
fun `getProjectPayloadMetadata()`() {
88-
getProjectPayloadMetadata(sessionConfigSpy, 10, totalSize, this.totalLines, CodewhispererLanguage.Csharp)
89+
getProjectPayloadMetadata(sessionConfigSpy, 11, totalSize, this.totalLines, CodewhispererLanguage.Csharp)
8990
}
9091

9192
@Test
@@ -105,7 +106,7 @@ class CodeWhispererProjectCodeScanTest : CodeWhispererCodeScanTestBase(PythonCod
105106

106107
@Test
107108
fun `e2e happy path integration test`() = runTest {
108-
assertE2ERunsSuccessfully(sessionConfigSpy, project, totalLines, 10, totalSize, 1)
109+
assertE2ERunsSuccessfully(sessionConfigSpy, project, totalLines, 11, totalSize, 1)
109110
}
110111

111112
private fun setupCsharpProject() {
@@ -371,7 +372,10 @@ class CodeWhispererProjectCodeScanTest : CodeWhispererCodeScanTestBase(PythonCod
371372

372373
// Adding gitignore file and gitignore file member for testing.
373374
// The tests include the markdown file but not these two files.
374-
projectRule.fixture.addFileToProject("/.gitignore", "node_modules\n.idea\n.vscode\n.DS_Store").virtualFile
375+
gitIgnore = projectRule.fixture.addFileToProject("/.gitignore", "node_modules\n.idea\n.vscode\n.DS_Store").virtualFile
376+
totalSize += gitIgnore.length
377+
totalLines += gitIgnore.toNioPath().toFile().readLines().size
378+
375379
projectRule.fixture.addFileToProject("/.idea/ref", "ref: refs/heads/main")
376380
}
377381
}

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/FeatureDevSessionContext.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ class RepoSizeLimitError(override val message: String) : RuntimeException(), Rep
4747
class FeatureDevSessionContext(val project: Project, val maxProjectSizeBytes: Long? = null) {
4848
// TODO: Need to correct this class location in the modules going further to support both amazonq and codescan.
4949

50+
private val requiredFilesForExecution = setOf("gradle/wrapper/gradle-wrapper.jar")
5051
private val additionalGitIgnoreRules = setOf(
5152
".aws-sam",
5253
".gem",
5354
".git",
54-
".gitignore",
5555
".gradle",
5656
".hg",
5757
".idea",
@@ -136,6 +136,9 @@ class FeatureDevSessionContext(val project: Project, val maxProjectSizeBytes: Lo
136136
suspend fun ignoreFile(file: VirtualFile): Boolean = ignoreFile(file.presentableUrl)
137137

138138
suspend fun ignoreFile(path: String): Boolean {
139+
if (requiredFilesForExecution.any { path.endsWith(it) }) {
140+
return false
141+
}
139142
// this method reads like something a JS dev would write and doesn't do what the author thinks
140143
val deferredResults = ignorePatternsWithGitIgnore.map { pattern ->
141144
withContext(coroutineContext) {

0 commit comments

Comments
 (0)