Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,7 @@ private static <T> ProviderEvaluation<T> resolveVariant(
final ProviderEvaluation<T> result =
ProviderEvaluation.<T>builder()
.value(mappedValue)
.reason(
!isEmpty(allocation.rules)
? Reason.TARGETING_MATCH.name()
: !isEmpty(split.shards) ? Reason.SPLIT.name() : Reason.STATIC.name())
.reason(resolveReason(allocation, split, flag))
.variant(variant.key)
.flagMetadata(metadataBuilder.build())
.build();
Expand All @@ -400,6 +397,25 @@ private static <T> ProviderEvaluation<T> resolveVariant(
return result;
}

private static String resolveReason(
final Allocation allocation, final Split split, final Flag flag) {
// ADR-004: SPLIT overrides TARGETING_MATCH when both rules and shard contributed
if (!isEmpty(allocation.rules) && !isEmpty(split.shards)) {
return Reason.SPLIT.name();
}
if (!isEmpty(allocation.rules)) {
return Reason.TARGETING_MATCH.name();
}
if (!isEmpty(split.shards)) {
return Reason.SPLIT.name();
}
// No rules, no shards (vacuous split). STATIC only when this is the sole allocation
// with no date-window constraints (ADR-003: time-gated result is not permanently stable).
final boolean hasDateWindow = allocation.startAt != null || allocation.endAt != null;
final boolean isSoleStaticAlloc = flag.allocations.size() == 1 && !hasDateWindow;
return isSoleStaticAlloc ? Reason.STATIC.name() : Reason.DEFAULT.name();
}

private static Object resolveAttribute(final String name, final EvaluationContext context) {
// Special handling for "id" attribute: if not explicitly provided, use targeting key
if ("id".equals(name) && !context.keySet().contains(name)) {
Expand Down
Loading