Skip to content

Commit a4619da

Browse files
committed
Change logic for customization override to not override if user has manually selected a customization
1 parent 370ed03 commit a4619da

File tree

3 files changed

+43
-14
lines changed

3 files changed

+43
-14
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" : "Change logic for customization override to not 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: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ import com.intellij.util.concurrency.annotations.RequiresBackgroundThread
1818
import com.intellij.util.xmlb.annotations.MapAnnotation
1919
import com.intellij.util.xmlb.annotations.Property
2020
import software.amazon.awssdk.services.codewhispererruntime.model.CodeWhispererRuntimeException
21+
import software.amazon.awssdk.services.codewhispererruntime.model.FeatureValue
2122
import software.aws.toolkits.core.utils.debug
2223
import software.aws.toolkits.core.utils.getLogger
2324
import software.aws.toolkits.jetbrains.services.amazonq.CodeWhispererFeatureConfigService
25+
import software.aws.toolkits.jetbrains.services.amazonq.FeatureContext
2426
import software.aws.toolkits.jetbrains.services.amazonq.calculateIfIamIdentityCenterConnection
2527
import software.aws.toolkits.jetbrains.services.codewhisperer.credentials.CodeWhispererClientAdaptor
2628
import software.aws.toolkits.jetbrains.services.codewhisperer.util.CodeWhispererConstants
@@ -157,17 +159,25 @@ class DefaultCodeWhispererModelConfigurator : CodeWhispererModelConfigurator, Pe
157159
return@calculateIfIamIdentityCenterConnection customizationUiItems
158160
}
159161

162+
/**
163+
* Gets the active customization for a user. If a user has manually selected a customization,
164+
* respect that choice. If a user has not selected a customization, check if they have a customization
165+
* assigned to them via an AB feature. If so, use that customization.
166+
*/
160167
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-
)
168+
val selectedCustomization = calculateIfIamIdentityCenterConnection(project) { connectionIdToActiveCustomizationArn[it.id] }
169+
170+
if (selectedCustomization != null) {
171+
return selectedCustomization
172+
} else {
173+
val customizationFeature = CodeWhispererFeatureConfigService.getInstance().getCustomizationFeature()
174+
if (customizationFeature == null || customizationFeature.value.stringValue().isEmpty()) return selectedCustomization
175+
return CodeWhispererCustomization(
176+
arn = customizationFeature.value.stringValue(),
177+
name = customizationFeature.variation,
178+
description = selectedCustomization?.description
179+
)
180+
}
171181
}
172182

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

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

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,17 +113,32 @@ 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 not 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)).isEqualTo(CodeWhispererCustomization("selectedCustomizationArn", "customization_1", "description_1"))
122122

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

129144
@Test

0 commit comments

Comments
 (0)