Skip to content

Commit e1a4c57

Browse files
committed
Using AB variation value as customization name when overridden
1 parent 9763dbc commit e1a4c57

File tree

5 files changed

+23
-12
lines changed

5 files changed

+23
-12
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type" : "feature",
3+
"description" : "Uses AB variation as the name for overriden customizations"
4+
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,11 @@ class DefaultCodeWhispererModelConfigurator : CodeWhispererModelConfigurator, Pe
161161
val result = calculateIfIamIdentityCenterConnection(project) { connectionIdToActiveCustomizationArn[it.id] }
162162

163163
// A/B case
164-
val customizationArnFromAB = CodeWhispererFeatureConfigService.getInstance().getCustomizationArnOverride()
165-
if (customizationArnFromAB.isEmpty()) return result
164+
val customizationFeature = CodeWhispererFeatureConfigService.getInstance().getCustomizationFeature()
165+
if (customizationFeature == null || customizationFeature.value.stringValue().isEmpty()) return result
166166
return CodeWhispererCustomization(
167-
arn = customizationArnFromAB,
168-
name = result?.name.orEmpty(),
167+
arn = customizationFeature.value.stringValue(),
168+
name = customizationFeature.variation,
169169
description = result?.description
170170
)
171171
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import org.junit.Rule
1414
import org.mockito.kotlin.any
1515
import org.mockito.kotlin.doReturn
1616
import org.mockito.kotlin.eq
17+
import org.mockito.kotlin.isNull
1718
import org.mockito.kotlin.mock
1819
import org.mockito.kotlin.stub
1920
import software.amazon.awssdk.services.codewhispererruntime.CodeWhispererRuntimeClient
@@ -80,7 +81,7 @@ class CodeWhispererFeatureConfigServiceTest {
8081
listOf(
8182
FeatureEvaluation.builder()
8283
.feature(CodeWhispererFeatureConfigService.CUSTOMIZATION_ARN_OVERRIDE_NAME)
83-
.variation("customizationARN")
84+
.variation("customization-name")
8485
.value(FeatureValue.fromStringValue("test arn"))
8586
.build()
8687
)
@@ -122,9 +123,10 @@ class CodeWhispererFeatureConfigServiceTest {
122123
}
123124

124125
if (!isIdc || !isInListAvailableCustomizations) {
125-
assertThat(CodeWhispererFeatureConfigService.getInstance().getCustomizationArnOverride()).isEqualTo("")
126+
assertThat(CodeWhispererFeatureConfigService.getInstance().getCustomizationFeature()).isNull()
126127
} else {
127-
assertThat(CodeWhispererFeatureConfigService.getInstance().getCustomizationArnOverride()).isEqualTo("test arn")
128+
assertThat(CodeWhispererFeatureConfigService.getInstance().getCustomizationFeature()?.value?.stringValue()).isEqualTo("test arn")
129+
assertThat(CodeWhispererFeatureConfigService.getInstance().getCustomizationFeature()?.variation).isEqualTo("customization-name")
128130
}
129131
}
130132

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import org.mockito.kotlin.stub
2222
import software.amazon.awssdk.regions.Region
2323
import software.amazon.awssdk.services.codewhispererruntime.CodeWhispererRuntimeClient
2424
import software.amazon.awssdk.services.codewhispererruntime.model.Customization
25+
import software.amazon.awssdk.services.codewhispererruntime.model.FeatureValue
2526
import software.amazon.awssdk.services.codewhispererruntime.model.ListAvailableCustomizationsRequest
2627
import software.amazon.awssdk.services.codewhispererruntime.model.ListAvailableCustomizationsResponse
2728
import software.amazon.awssdk.services.ssooidc.SsoOidcClient
@@ -38,6 +39,7 @@ import software.aws.toolkits.jetbrains.core.credentials.sono.SONO_URL
3839
import software.aws.toolkits.jetbrains.core.credentials.sono.isSono
3940
import software.aws.toolkits.jetbrains.core.region.MockRegionProviderRule
4041
import software.aws.toolkits.jetbrains.services.amazonq.CodeWhispererFeatureConfigService
42+
import software.aws.toolkits.jetbrains.services.amazonq.FeatureContext
4143
import software.aws.toolkits.jetbrains.services.codewhisperer.customization.CodeWhispererCustomization
4244
import software.aws.toolkits.jetbrains.services.codewhisperer.customization.CodeWhispererCustomizationState
4345
import software.aws.toolkits.jetbrains.services.codewhisperer.customization.DefaultCodeWhispererModelConfigurator
@@ -100,7 +102,7 @@ class CodeWhispererModelConfiguratorTest {
100102
}
101103

102104
abManager = mock {
103-
on { getCustomizationArnOverride() }.thenReturn("")
105+
on { getCustomizationFeature() }.thenReturn(null)
104106
}
105107

106108
ApplicationManager.getApplication().replaceService(
@@ -119,9 +121,9 @@ class CodeWhispererModelConfiguratorTest {
119121
assertThat(sut.activeCustomization(projectRule.project)).isEqualTo(CodeWhispererCustomization("foo", "customization_1", "description_1"))
120122

121123
abManager.stub {
122-
on { getCustomizationArnOverride() }.thenReturn("bar")
124+
on { getCustomizationFeature() }.thenReturn(FeatureContext("customizationArnOverride", "foo", FeatureValue.builder().stringValue("bar").build()))
123125
}
124-
assertThat(sut.activeCustomization(projectRule.project)).isEqualTo(CodeWhispererCustomization("bar", "customization_1", "description_1"))
126+
assertThat(sut.activeCustomization(projectRule.project)).isEqualTo(CodeWhispererCustomization("bar", "foo", "description_1"))
125127
}
126128

127129
@Test

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/CodeWhispererFeatureConfigService.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class CodeWhispererFeatureConfigService {
109109
// 6) Add a test case for this feature.
110110
fun getTestFeature(): String = getFeatureValueForKey(TEST_FEATURE_NAME).stringValue()
111111

112-
fun getCustomizationArnOverride(): String = getFeatureValueForKey(CUSTOMIZATION_ARN_OVERRIDE_NAME).stringValue()
112+
fun getCustomizationFeature(): FeatureContext? = getFeature(CUSTOMIZATION_ARN_OVERRIDE_NAME)
113113

114114
fun getNewAutoTriggerUX(): Boolean = getFeatureValueForKey(NEW_AUTO_TRIGGER_UX).stringValue() == "TREATMENT"
115115

@@ -118,9 +118,12 @@ class CodeWhispererFeatureConfigService {
118118
// Get the feature value for the given key.
119119
// In case of a misconfiguration, it will return a default feature value of Boolean false.
120120
private fun getFeatureValueForKey(name: String): FeatureValue =
121-
featureConfigs[name]?.value ?: FEATURE_DEFINITIONS[name]?.value
121+
getFeature(name)?.value ?: FEATURE_DEFINITIONS[name]?.value
122122
?: FeatureValue.builder().boolValue(false).build()
123123

124+
// Gets the feature context for a given feature name.
125+
private fun getFeature(name: String): FeatureContext? = featureConfigs[name]
126+
124127
private fun connection(project: Project) =
125128
ToolkitConnectionManager.getInstance(project).activeConnectionForFeature(QConnection.getInstance())
126129

0 commit comments

Comments
 (0)