Repository navigation
chore: evaluate client-side rules and rollouts - #13
Conversation
Ports .NET's ServerSideEvaluation, ClientSideRule and Conditions so a flag deferred to the client resolves from its rules: - Rules are OR'd and the first match wins, with reason "Matched rule '<name>'.". Conditions within a rule are AND'd and short-circuit. No match gives false with "Did not match any rules.". - context-attribute-is-one-of and is-not-one-of compare keys and values case-insensitively, and treat non-string attributes as absent. - percentage-by-context buckets with a pure-Python MurmurHash3 x86_32 over "evaluationKey:targetingKey". A missing targeting key matches only at 100. - Unrecognised condition types never match. Rules and conditions are parsed into typed objects. A field of the wrong type reads as absent, so it raises ParseError when its flag is evaluated and costs only that flag. Tests cover the 114 shared rollout vectors, wrong-typed fields and non-string context attributes. The specification fixtures cover the rest. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
str.upper applies Unicode's full case mappings, so "Straße" matched "STRASSE", where .NET's OrdinalIgnoreCase and Java's equalsIgnoreCase don't. Keys and values are now uppercased one character at a time, keeping any character that would expand. Also: - Make "Did not match any rules." a constant rather than a function. - Say in parse_condition's docstring that a missing type raises at evaluation, unlike an unrecognised one. - Test as_int directly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Nothing checks a response up front, so a malformed rule behind a matching one, or a malformed condition behind a failing one, never fails the flag. That was agreed in the review of the .NET provider's client-side evaluation, and the .NET, Java and browser providers each pin it with the same tests. The specification fixtures don't cover it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
liamhughes
left a comment
There was a problem hiding this comment.
A couple of things I'd be interested for your opinion on, but looks good. 👍
| Written out rather than taken from ``mmh3`` so the provider doesn't need a | ||
| native wheel. The blocks are read little-endian, as every provider does. |
There was a problem hiding this comment.
Probably doesn't matter too much, but curious about the decision to roll our own.
There was a problem hiding this comment.
It's to avoid a native dependency. The other providers' libraries are plain .NET/Java/JS, but Python's only maintained option, mmh3, is a C extension. On any platform without a prebuilt wheel (a new CPython release, free-threaded builds, unusual Linux images), installing the provider would need a compiler, and it's one more runtime dependency in customers' apps.
| pytest.param("пользователь", "ПОЛЬЗОВАТЕЛЬ", True, id="cyrillic"), | ||
| ], | ||
| ) | ||
| def test_a_non_ascii_value_compares_one_character_at_a_time( |
There was a problem hiding this comment.
Not sure about the non-ASCII stuff. I know .NET/Java and TypeScript disagree and it is pretty hard to get it to align. Not sure if we want to lock in the edge cases, but I guess at least the tests show that we're aware of it.
There was a problem hiding this comment.
Yeah the it's been a bit of a headache, I've had Claude update BMBB-1553 to set fixtures for what we want to do, if we want to do anything or just accept that they may be a bit different 🤷
The accented and Cyrillic cases behave the same in every provider, so they pinned nothing. What's left are the "ß" and ligature cases, where .NET and Java differ from the browser provider, with a pointer to BMBB-1553, which will settle which way the specification goes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolves BMBB-1514.
Ports .NET's
V4/ServerSideEvaluation,ClientSideRuleandConditions/*, so a flag deferred to the client resolves from its rules.evaluate(slug, context)is unchanged.What's in it
Matched rule '<name>'.). Conditions within a rule are AND'd and short-circuit. No match givesfalse(Did not match any rules.).context-attribute-is-one-of/is-not-one-of: keys and values compare case-insensitively, uppercased one character at a time as .NET'sOrdinalIgnoreCaseand Java'sequalsIgnoreCasedo. SoStraßedoesn't matchSTRASSE, although the browser provider'stoUpperCasewould match them. Every case variant of a key is checked, and non-string attributes count as absent. The second condition is the exact negation of the first.percentage-by-context: pure-Python MurmurHash3 x86_32, seed 0, over the UTF-8 bytes ofevaluationKey:targetingKey. Bucket ishash % 100 + 1, included whenbucket <= percentage. An empty or missing targeting key matches only at 100. Out-of-range percentages raiseParseErrorrather than clamping.ParseErrorat evaluation, as in .NET.ParseErrorat evaluation and costs only that flag.trueand50.0aren't accepted as a percentage. An emptyvalueslist raisesParseError, as in .NET.Tests
[evaluationKey, targetingKey, bucket]vectors, copied verbatim from .NET'sPercentageRolloutTests.cswith the "DO NOT modify" comment.int,bool,float,datetime, sequence and mapping attributes; non-ASCII keys and values where the providers disagree (ß, ligatures); and a malformed rule or condition that evaluation never reaches.as_intdirectly, alongside the other JSON helpers.main, 0f49852) pass against the evaluator on value, reason and error code. That runner isn't committed; BMBB-1548 adds the real one.Malformed parts are only read if evaluation reaches them
Nothing checks the response up front. A malformed rule behind a matching one, or a malformed condition behind a failing one, never fails the flag. This is deliberate and matches the other providers: it was agreed in the review of openfeature-provider-dotnet PR 93, so every library "bails on an evaluation" the same OpenFeature-supported way. .NET, Java and the browser provider each test it, and so does this PR now.
The spec fixture saying a missing type "fails the whole evaluation rather than just its own rule" contrasts it with an unknown type, which fails only its own rule. It doesn't mean validating up front. BMBB-1553 proposes spec fixtures that pin this behaviour, and non-ASCII case matching, for every provider.
Errors resolve to the caller's default
The ticket says that on any error the evaluator must return
value=default_valueandreason=ERRORitself. That's because the SDK passes a returned error resolution through unchanged. The evaluator doesn't return errors, though. It raisesParseError, as before, and the SDK (v0.10.0,openfeature/client.py) catches anyOpenFeatureErrorand returnsvalue=default_value, reason=ERRORwith its error code and message.I checked this through a real
OpenFeatureClientwith a stub provider callingevaluateon an untyped condition.get_boolean_detailsreturned the caller's default for bothTrueandFalse, withreason=ERRORandPARSE_ERROR.So this needs nothing more here or in BMBB-1515. The provider only has to let
ParseErrorpropagate rather than turning it into a returned resolution.🤖 Generated with Claude Code