Skip to content

Commit

Permalink
Change logic for customization override to not override if user has m…
Browse files Browse the repository at this point in the history
…anually selected a customization
  • Loading branch information
spfink committed Jan 7, 2025
1 parent 370ed03 commit 09a5ec6
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type" : "bugfix",
"description" : "Change logic for customization override to not override if user has manually selected a customization"
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,24 @@ class DefaultCodeWhispererModelConfigurator : CodeWhispererModelConfigurator, Pe
return@calculateIfIamIdentityCenterConnection customizationUiItems
}

/**
* Gets the active customization for a user. If a user has manually selected a customization,
* respect that choice. If a user has not selected a customization, check if they have a customization
* assigned to them via an AB feature. If so, use that customization.
*/
override fun activeCustomization(project: Project): CodeWhispererCustomization? {
val result = calculateIfIamIdentityCenterConnection(project) { connectionIdToActiveCustomizationArn[it.id] }

// A/B case
val customizationFeature = CodeWhispererFeatureConfigService.getInstance().getCustomizationFeature()
if (customizationFeature == null || customizationFeature.value.stringValue().isEmpty()) return result
return CodeWhispererCustomization(
arn = customizationFeature.value.stringValue(),
name = customizationFeature.variation,
description = result?.description
)
val selectedCustomization = calculateIfIamIdentityCenterConnection(project) { connectionIdToActiveCustomizationArn[it.id] }

if (selectedCustomization != null) {
return selectedCustomization
} else {
val customizationOverride = CodeWhispererFeatureConfigService.getInstance().getCustomizationFeature()
if (customizationOverride == null || customizationOverride.value.stringValue().isEmpty()) return null
return CodeWhispererCustomization(
arn = customizationOverride.value.stringValue(),
name = customizationOverride.variation,
)
}
}

override fun switchCustomization(project: Project, newCustomization: CodeWhispererCustomization?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,37 @@ class CodeWhispererModelConfiguratorTest {
}

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

sut.switchCustomization(projectRule.project, CodeWhispererCustomization("foo", "customization_1", "description_1"))
assertThat(sut.activeCustomization(projectRule.project)).isEqualTo(CodeWhispererCustomization("foo", "customization_1", "description_1"))
sut.switchCustomization(projectRule.project, CodeWhispererCustomization("selectedCustomizationArn", "customization_1", "description_1"))
assertThat(sut.activeCustomization(projectRule.project))
.isEqualTo(CodeWhispererCustomization("selectedCustomizationArn", "customization_1", "description_1"))

abManager.stub {
on { getCustomizationFeature() }.thenReturn(FeatureContext("customizationArnOverride", "foo", FeatureValue.builder().stringValue("bar").build()))
}
assertThat(sut.activeCustomization(projectRule.project)).isEqualTo(CodeWhispererCustomization("bar", "foo", "description_1"))
assertThat(sut.activeCustomization(projectRule.project))
.isEqualTo(CodeWhispererCustomization("selectedCustomizationArn", "customization_1", "description_1"))
}

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

sut.switchCustomization(projectRule.project, CodeWhispererCustomization("selectedCustomizationArn", "customization_1", "description_1"))
assertThat(sut.activeCustomization(projectRule.project))
.isEqualTo(CodeWhispererCustomization("selectedCustomizationArn", "customization_1", "description_1"))
sut.invalidateCustomization("selectedCustomizationArn")

abManager.stub {
on { getCustomizationFeature() }.thenReturn(
FeatureContext("customizationArnOverride", "foo", FeatureValue.builder().stringValue("overrideArn").build())
)
}
assertThat(sut.activeCustomization(projectRule.project)).isEqualTo(CodeWhispererCustomization("overrideArn", "foo", null))
}

@Test
Expand Down

0 comments on commit 09a5ec6

Please sign in to comment.