Skip to content

fix: various custom operator conformance fixes#1778

Draft
toddbaert wants to merge 1 commit intomainfrom
chore/update-test-harness
Draft

fix: various custom operator conformance fixes#1778
toddbaert wants to merge 1 commit intomainfrom
chore/update-test-harness

Conversation

@toddbaert
Copy link
Copy Markdown
Member

@toddbaert toddbaert commented Apr 21, 2026

fix: various custom operator conformance fixes

  • support v/V prefix in semver
  • support partial versions in semver
  • support numeric context values in semver
  • return null on errors
  • fix fractional single-entry flattening

⚠️ wait until flagd/RPC is updated to merge.

Fixes: #1774

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces several improvements to the flagd core evaluation logic, including enhanced type handling for context values, more robust SemVer parsing with support for partial versions and numeric coercion, and fixes for fractional evaluation edge cases. I have provided a suggestion to optimize the fractional evaluation logic by using List operations instead of manual array copying to improve performance.

Comment on lines 44 to +59
Object[] source = arguments.toArray();
distributions = Arrays.copyOfRange(source, 1, source.length);
Object[] remaining = Arrays.copyOfRange(source, 1, source.length);

// json-logic pre-evaluation flattens a single-entry fractional
// e.g. [["single",1]] becomes ["single", 1]; detect and re-wrap
if (remaining.length > 0 && !(remaining[0] instanceof List)) {
List<Object> wrapped = new ArrayList<>();
wrapped.add(arg1);
for (Object r : remaining) {
wrapped.add(r);
}
distributions = new ArrayList<>();
distributions.add(wrapped);
} else {
distributions = Arrays.asList(remaining);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current implementation performs multiple array copies and manual list building, which can be inefficient as this code is executed during every flag evaluation. Using List.subList and List.addAll is more efficient and idiomatic for this purpose.

            List<Object> remaining = arguments.subList(1, arguments.size());

            // json-logic pre-evaluation flattens a single-entry fractional
            // e.g. [["single",1]] becomes ["single", 1]; detect and re-wrap
            if (!remaining.isEmpty() && !(remaining.get(0) instanceof List)) {
                List<Object> wrapped = new ArrayList<>(remaining.size() + 1);
                wrapped.add(arg1);
                wrapped.addAll(remaining);
                distributions = Arrays.asList((Object) wrapped);
            } else {
                distributions = remaining;
            }

@toddbaert toddbaert marked this pull request as draft April 21, 2026 00:37
@toddbaert toddbaert force-pushed the chore/update-test-harness branch from 7c5c7cd to 6977314 Compare April 21, 2026 16:57
@toddbaert toddbaert changed the title Chore/update test harness fix: various custom operator conformance fixes Apr 21, 2026
Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
@toddbaert toddbaert force-pushed the chore/update-test-harness branch from 6977314 to d4dbb57 Compare April 22, 2026 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update flagd-testbed to v3.6.2 and fix in-process evaluation edge cases

4 participants