Skip to content

Commit 2e39dc0

Browse files
spfinkmanodnyab
andauthored
Change logic for customization override to not override if user has manually selected a customization (#5231)
Co-authored-by: manodnyab <[email protected]>
1 parent 05d7054 commit 2e39dc0

File tree

3 files changed

+45
-14
lines changed

3 files changed

+45
-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" : "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

0 commit comments

Comments
 (0)