Skip to content

Commit 83d23dc

Browse files
jkebingerclaude
andcommitted
Add envId field to Match class to report environment ID
Adds an Optional<Long> envId field to the Match class that reports the environment ID of the ConfigRow that matched during config evaluation. This allows consumers to know which environment's configuration was used. Changes: - Add envId field to Match class with getter - Update ConfigRuleEvaluator to extract project_env_id from ConfigRow - Update ConfigResolver to preserve envId when reifying matches - Update test files to include envId parameter in Match constructors Ported from prefab-cloud/prefab-cloud-java#154 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 0bde383 commit 83d23dc

File tree

6 files changed

+37
-8
lines changed

6 files changed

+37
-8
lines changed

sdk/src/main/java/com/reforge/sdk/config/Match.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,24 @@ public class Match {
1313
private final int rowIndex;
1414
private final int conditionalValueIndex;
1515
private final Optional<Integer> weightedValueIndex;
16+
private final Optional<Long> envId;
1617

1718
public Match(
1819
Prefab.ConfigValue configValue,
1920
ConfigElement configElement,
2021
List<EvaluatedCriterion> evaluatedCriterion,
2122
int rowIndex,
2223
int conditionalValueIndex,
23-
Optional<Integer> weightedValueIndex
24+
Optional<Integer> weightedValueIndex,
25+
Optional<Long> envId
2426
) {
2527
this.configValue = configValue;
2628
this.configElement = configElement;
2729
this.evaluatedCriterion = evaluatedCriterion;
2830
this.rowIndex = rowIndex;
2931
this.conditionalValueIndex = conditionalValueIndex;
3032
this.weightedValueIndex = weightedValueIndex;
33+
this.envId = envId;
3134
}
3235

3336
public int getRowIndex() {
@@ -42,6 +45,10 @@ public Optional<Integer> getWeightedValueIndex() {
4245
return weightedValueIndex;
4346
}
4447

48+
public Optional<Long> getEnvId() {
49+
return envId;
50+
}
51+
4552
public Prefab.ConfigValue getConfigValue() {
4653
return configValue;
4754
}
@@ -74,6 +81,7 @@ public String toString() {
7481
.add("rowIndex", rowIndex)
7582
.add("conditionalValueIndex", conditionalValueIndex)
7683
.add("weightedValueIndex", weightedValueIndex)
84+
.add("envId", envId)
7785
.toString();
7886
}
7987
}

sdk/src/main/java/com/reforge/sdk/internal/ConfigResolver.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ private Match reify(Match match, LookupContext lookupContext) {
8989
match.getEvaluatedCriterion(),
9090
match.getRowIndex(),
9191
match.getConditionalValueIndex(),
92-
match.getWeightedValueIndex()
92+
match.getWeightedValueIndex(),
93+
match.getEnvId()
9394
);
9495
}
9596

sdk/src/main/java/com/reforge/sdk/internal/ConfigRuleEvaluator.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ private Optional<Match> getMatch(
113113
conditionalValueIndex,
114114
lookupContext,
115115
rowPropertiesStack,
116-
configElement
116+
configElement,
117+
configRow
117118
);
118119

119120
if (optionalMatch.isPresent()) {
@@ -145,7 +146,8 @@ private Optional<Match> evaluateConditionalValue(
145146
int conditionalValueIndex,
146147
LookupContext lookupContext,
147148
Deque<Map<String, Prefab.ConfigValue>> rowProperties,
148-
ConfigElement configElement
149+
ConfigElement configElement,
150+
Prefab.ConfigRow configRow
149151
) {
150152
List<EvaluatedCriterion> evaluatedCriteria = new ArrayList<>();
151153
for (Prefab.Criterion criterion : conditionalValue.getCriteriaList()) {
@@ -167,7 +169,8 @@ private Optional<Match> evaluateConditionalValue(
167169
conditionalValueIndex,
168170
configElement,
169171
lookupContext,
170-
evaluatedCriteria
172+
evaluatedCriteria,
173+
configRow
171174
)
172175
);
173176
}
@@ -181,8 +184,13 @@ private Match simplifyToMatch(
181184
int conditionalValueIndex,
182185
ConfigElement configElement,
183186
LookupContext lookupContext,
184-
List<EvaluatedCriterion> evaluatedCriteria
187+
List<EvaluatedCriterion> evaluatedCriteria,
188+
Prefab.ConfigRow configRow
185189
) {
190+
Optional<Long> envId = configRow.hasProjectEnvId()
191+
? Optional.of(configRow.getProjectEnvId())
192+
: Optional.empty();
193+
186194
if (selectedConditionalValue.getValue().hasWeightedValues()) {
187195
WeightedValueEvaluator.Result result = weightedValueEvaluator.toResult(
188196
selectedConditionalValue.getValue().getWeightedValues(),
@@ -195,7 +203,8 @@ private Match simplifyToMatch(
195203
evaluatedCriteria,
196204
(int) rowIndex,
197205
conditionalValueIndex,
198-
Optional.of(result.getIndex())
206+
Optional.of(result.getIndex()),
207+
envId
199208
);
200209
} else {
201210
return new Match(
@@ -204,7 +213,8 @@ private Match simplifyToMatch(
204213
evaluatedCriteria,
205214
(int) rowIndex,
206215
conditionalValueIndex,
207-
Optional.empty()
216+
Optional.empty(),
217+
envId
208218
);
209219
}
210220
}

sdk/src/test/java/com/reforge/sdk/internal/ConfigResolverTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ Match match(Prefab.ConfigValue configValue, Prefab.Config config) {
241241
Collections.emptyList(),
242242
0,
243243
0,
244+
Optional.empty(),
244245
Optional.empty()
245246
);
246247
}

sdk/src/test/java/com/reforge/sdk/internal/MatchStatsAggregatorTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ void itAggregates() {
6969
Collections.emptyList(),
7070
0,
7171
2,
72+
Optional.empty(),
7273
Optional.empty()
7374
),
7475
101
@@ -81,6 +82,7 @@ void itAggregates() {
8182
Collections.emptyList(),
8283
0,
8384
2,
85+
Optional.empty(),
8486
Optional.empty()
8587
),
8688
102
@@ -93,6 +95,7 @@ void itAggregates() {
9395
Collections.emptyList(),
9496
0,
9597
2,
98+
Optional.empty(),
9699
Optional.empty()
97100
),
98101
102
@@ -108,6 +111,7 @@ void itAggregates() {
108111
Collections.emptyList(),
109112
0,
110113
3,
114+
Optional.empty(),
111115
Optional.empty()
112116
),
113117
107

sdk/src/test/java/com/reforge/sdk/internal/TelemetryManagerTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ private static void reportSomeMatches(TelemetryManager telemetryManager) {
358358
Collections.emptyList(),
359359
1,
360360
2,
361+
Optional.empty(),
361362
Optional.empty()
362363
),
363364
new LookupContext(
@@ -379,6 +380,7 @@ private static void reportSomeMatches(TelemetryManager telemetryManager) {
379380
Collections.emptyList(),
380381
1,
381382
2,
383+
Optional.empty(),
382384
Optional.empty()
383385
),
384386
new LookupContext(
@@ -400,6 +402,7 @@ private static void reportSomeMatches(TelemetryManager telemetryManager) {
400402
Collections.emptyList(),
401403
1,
402404
2,
405+
Optional.empty(),
403406
Optional.empty()
404407
),
405408
new LookupContext(
@@ -418,6 +421,7 @@ private static void reportSomeMatches(TelemetryManager telemetryManager) {
418421
Collections.emptyList(),
419422
0,
420423
0,
424+
Optional.empty(),
421425
Optional.empty()
422426
),
423427
new LookupContext(
@@ -436,6 +440,7 @@ private static void reportSomeMatches(TelemetryManager telemetryManager) {
436440
Collections.emptyList(),
437441
0,
438442
0,
443+
Optional.empty(),
439444
Optional.empty()
440445
),
441446
new LookupContext(

0 commit comments

Comments
 (0)