Skip to content

Commit 221fbfa

Browse files
authored
Merge branch 'main' into main
2 parents 3f6b265 + 2e39dc0 commit 221fbfa

File tree

5 files changed

+57
-17
lines changed

5 files changed

+57
-17
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 /dev: Fix issue when files are deleted while preparing context"
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type" : "bugfix",
3+
"description" : "Prevent customization override if user has manually selected a customization"
4+
}

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/customization/CodeWhispererModelConfigurator.kt

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -157,17 +157,24 @@ class DefaultCodeWhispererModelConfigurator : CodeWhispererModelConfigurator, Pe
157157
return@calculateIfIamIdentityCenterConnection customizationUiItems
158158
}
159159

160+
/**
161+
* Gets the active customization for a user. If a user has manually selected a customization,
162+
* respect that choice. If a user has not selected a customization, check if they have a customization
163+
* assigned to them via an AB feature. If so, use that customization.
164+
*/
160165
override fun activeCustomization(project: Project): CodeWhispererCustomization? {
161-
val result = calculateIfIamIdentityCenterConnection(project) { connectionIdToActiveCustomizationArn[it.id] }
162-
163-
// A/B case
164-
val customizationFeature = CodeWhispererFeatureConfigService.getInstance().getCustomizationFeature()
165-
if (customizationFeature == null || customizationFeature.value.stringValue().isEmpty()) return result
166-
return CodeWhispererCustomization(
167-
arn = customizationFeature.value.stringValue(),
168-
name = customizationFeature.variation,
169-
description = result?.description
170-
)
166+
val selectedCustomization = calculateIfIamIdentityCenterConnection(project) { connectionIdToActiveCustomizationArn[it.id] }
167+
168+
if (selectedCustomization != null) {
169+
return selectedCustomization
170+
} else {
171+
val customizationOverride = CodeWhispererFeatureConfigService.getInstance().getCustomizationFeature()
172+
if (customizationOverride == null || customizationOverride.value.stringValue().isEmpty()) return null
173+
return CodeWhispererCustomization(
174+
arn = customizationOverride.value.stringValue(),
175+
name = customizationOverride.variation,
176+
)
177+
}
171178
}
172179

173180
override fun switchCustomization(project: Project, newCustomization: CodeWhispererCustomization?) {

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,17 +113,37 @@ class CodeWhispererModelConfiguratorTest {
113113
}
114114

115115
@Test
116-
fun `should override customization arn if there is one under AB test`() {
116+
fun `should not override customization arn if there is one under AB test and manual selection has been made`() {
117117
val ssoConn = spy(LegacyManagedBearerSsoConnection(region = "us-east-1", startUrl = "url 1", scopes = Q_SCOPES))
118118
ToolkitConnectionManager.getInstance(projectRule.project).switchConnection(ssoConn)
119119

120-
sut.switchCustomization(projectRule.project, CodeWhispererCustomization("foo", "customization_1", "description_1"))
121-
assertThat(sut.activeCustomization(projectRule.project)).isEqualTo(CodeWhispererCustomization("foo", "customization_1", "description_1"))
120+
sut.switchCustomization(projectRule.project, CodeWhispererCustomization("selectedCustomizationArn", "customization_1", "description_1"))
121+
assertThat(sut.activeCustomization(projectRule.project))
122+
.isEqualTo(CodeWhispererCustomization("selectedCustomizationArn", "customization_1", "description_1"))
122123

123124
abManager.stub {
124125
on { getCustomizationFeature() }.thenReturn(FeatureContext("customizationArnOverride", "foo", FeatureValue.builder().stringValue("bar").build()))
125126
}
126-
assertThat(sut.activeCustomization(projectRule.project)).isEqualTo(CodeWhispererCustomization("bar", "foo", "description_1"))
127+
assertThat(sut.activeCustomization(projectRule.project))
128+
.isEqualTo(CodeWhispererCustomization("selectedCustomizationArn", "customization_1", "description_1"))
129+
}
130+
131+
@Test
132+
fun `should override customization arn if there is one under AB test and manual selection has not been made`() {
133+
val ssoConn = spy(LegacyManagedBearerSsoConnection(region = "us-east-1", startUrl = "url 1", scopes = Q_SCOPES))
134+
ToolkitConnectionManager.getInstance(projectRule.project).switchConnection(ssoConn)
135+
136+
sut.switchCustomization(projectRule.project, CodeWhispererCustomization("selectedCustomizationArn", "customization_1", "description_1"))
137+
assertThat(sut.activeCustomization(projectRule.project))
138+
.isEqualTo(CodeWhispererCustomization("selectedCustomizationArn", "customization_1", "description_1"))
139+
sut.invalidateCustomization("selectedCustomizationArn")
140+
141+
abManager.stub {
142+
on { getCustomizationFeature() }.thenReturn(
143+
FeatureContext("customizationArnOverride", "foo", FeatureValue.builder().stringValue("overrideArn").build())
144+
)
145+
}
146+
assertThat(sut.activeCustomization(projectRule.project)).isEqualTo(CodeWhispererCustomization("overrideArn", "foo", null))
127147
}
128148

129149
@Test

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,15 +204,20 @@ class FeatureDevSessionContext(val project: Project, val maxProjectSizeBytes: Lo
204204
val zipFilePath = createTemporaryZipFileAsync { zipfs ->
205205
val isPosix = FileSystems.getDefault().supportedFileAttributeViews().contains("posix")
206206
filesToIncludeFlow.collect { file ->
207+
207208
if (!file.isDirectory) {
208209
val externalFilePath = Path(file.path)
209210
val relativePath = Path(file.path).relativeTo(projectRootPath)
210211
val zipfsPath = zipfs.getPath("/$relativePath")
211212
runBlocking {
212213
zipfsPath.createParentDirectories()
213-
Files.copy(externalFilePath, zipfsPath, StandardCopyOption.REPLACE_EXISTING)
214-
if (isPosix) {
215-
Files.setAttribute(zipfsPath, "zip:permissions", externalFilePath.getPosixFilePermissions())
214+
try {
215+
Files.copy(externalFilePath, zipfsPath, StandardCopyOption.REPLACE_EXISTING)
216+
if (isPosix) {
217+
Files.setAttribute(zipfsPath, "zip:permissions", externalFilePath.getPosixFilePermissions())
218+
}
219+
} catch (e: NoSuchFileException) {
220+
// Noop: Skip if file was deleted
216221
}
217222
}
218223
}

0 commit comments

Comments
 (0)