Skip to content

Commit 5fc3120

Browse files
[AI-FSSDK] [FSSDK-12750] Use attribute id instead of key for CMAB prediction requests (#635)
Co-authored-by: Muzahidul Islam <129880873+muzahidul-opti@users.noreply.github.com>
1 parent ef214b7 commit 5fc3120

2 files changed

Lines changed: 14 additions & 21 deletions

File tree

core-api/src/main/java/com/optimizely/ab/cmab/service/DefaultCmabService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2025, Optimizely
2+
* Copyright 2025-2026, Optimizely
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -154,7 +154,7 @@ private Map<String, Object> filterAttributes(ProjectConfig projectConfig, Optimi
154154
Attribute attribute = attributeIdMapping.get(attributeId);
155155
if (attribute != null) {
156156
if (userAttributes.containsKey(attribute.getKey())) {
157-
filteredAttributes.put(attribute.getKey(), userAttributes.get(attribute.getKey()));
157+
filteredAttributes.put(attribute.getId(), userAttributes.get(attribute.getKey()));
158158
} else {
159159
logger.debug("User attribute '{}' not found for attribute ID '{}'", attribute.getKey(), attributeId);
160160
}

core-api/src/test/java/com/optimizely/ab/cmab/DefaultCmabServiceTest.java

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2025, Optimizely
2+
* Copyright 2025-2026, Optimizely
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -142,8 +142,8 @@ public void testIgnoresCacheWhenOptionGiven() {
142142
assertNotNull(decision.getCmabUuid());
143143

144144
Map<String, Object> expectedAttributes = new HashMap<>();
145-
expectedAttributes.put("age", 25);
146-
expectedAttributes.put("location", "USA");
145+
expectedAttributes.put("66", 25);
146+
expectedAttributes.put("77", "USA");
147147
verify(mockCmabClient).fetchDecision(eq("exp1"), eq("user123"), eq(expectedAttributes), anyString());
148148
}
149149

@@ -199,8 +199,8 @@ public void testNewDecisionWhenHashChanges() {
199199
assertEquals("varE", decision.getVariationId());
200200

201201
Map<String, Object> expectedAttributes = new HashMap<>();
202-
expectedAttributes.put("age", 25);
203-
expectedAttributes.put("location", "USA");
202+
expectedAttributes.put("66", 25);
203+
expectedAttributes.put("77", "USA");
204204
verify(mockCmabClient).fetchDecision(eq("exp1"), eq("user123"), eq(expectedAttributes), anyString());
205205
}
206206

@@ -221,12 +221,11 @@ public void testOnlyCmabAttributesPassedToClient() {
221221
List<OptimizelyDecideOption> options = Arrays.asList(OptimizelyDecideOption.IGNORE_CMAB_CACHE);
222222
CmabDecision decision = cmabService.getDecision(mockProjectConfig, mockUserContext, "exp1", options);
223223

224-
// Verify only age and location are passed (attributes configured in setUp)
225224
Map<String, Object> expectedAttributes = new HashMap<>();
226-
expectedAttributes.put("age", 25);
227-
expectedAttributes.put("location", "USA");
225+
expectedAttributes.put("66", 25);
226+
expectedAttributes.put("77", "USA");
228227
verify(mockCmabClient).fetchDecision(eq("exp1"), eq("user123"), eq(expectedAttributes), anyString());
229-
228+
230229
assertEquals("varF", decision.getVariationId());
231230
assertNotNull(decision.getCmabUuid());
232231
}
@@ -275,10 +274,9 @@ public void testAttributeFilteringBehavior() {
275274
List<OptimizelyDecideOption> options = Arrays.asList(OptimizelyDecideOption.IGNORE_CMAB_CACHE);
276275
cmabService.getDecision(mockProjectConfig, mockUserContext, "exp1", options);
277276

278-
// Verify only the configured attributes (age, location) are passed
279277
Map<String, Object> expectedAttributes = new HashMap<>();
280-
expectedAttributes.put("age", 25);
281-
expectedAttributes.put("location", "USA");
278+
expectedAttributes.put("66", 25);
279+
expectedAttributes.put("77", "USA");
282280
verify(mockCmabClient).fetchDecision(eq("exp1"), eq("user123"), eq(expectedAttributes), anyString());
283281
}
284282

@@ -306,9 +304,8 @@ public void testMissingAttributeMappingBehavior() {
306304
List<OptimizelyDecideOption> options = Arrays.asList(OptimizelyDecideOption.IGNORE_CMAB_CACHE);
307305
cmabService.getDecision(mockProjectConfig, mockUserContext, "exp1", options);
308306

309-
// Should only include the attribute that exists (age with ID 66)
310307
Map<String, Object> expectedAttributes = new HashMap<>();
311-
expectedAttributes.put("age", 25);
308+
expectedAttributes.put("66", 25);
312309
verify(mockCmabClient).fetchDecision(eq("exp1"), eq("user123"), eq(expectedAttributes), anyString());
313310

314311
// Verify debug log was called for missing attribute
@@ -328,13 +325,9 @@ public void testMissingUserAttributeBehavior() {
328325
List<OptimizelyDecideOption> options = Arrays.asList(OptimizelyDecideOption.IGNORE_CMAB_CACHE);
329326
cmabService.getDecision(mockProjectConfig, mockUserContext, "exp1", options);
330327

331-
// Should only include the attribute the user has
332328
Map<String, Object> expectedAttributes = new HashMap<>();
333-
expectedAttributes.put("age", 25);
329+
expectedAttributes.put("66", 25);
334330
verify(mockCmabClient).fetchDecision(eq("exp1"), eq("user123"), eq(expectedAttributes), anyString());
335-
336-
// Remove the logger verification if it's causing issues
337-
// verify(mockLogger).debug(anyString(), eq("location"), eq("exp1"));
338331
}
339332

340333
@Test

0 commit comments

Comments
 (0)