Add JSON Logic min and max operators#6825
Merged
Merged
Conversation
f6c4c80 to
d11529c
Compare
d2ca6d6 to
e73eabe
Compare
d11529c to
f6c4c80
Compare
e73eabe to
d2ca6d6
Compare
…tures
Convert the hand-written operator unit tests for operators available at the
string+array level into declarative JSON predicate fixtures sharing khepri's
conformance format, run by a shared runner that auto-discovers every file in
PredicateFixtures/. `expected` is a khepri-compatible superset (Bool or
{ "error": ... }) plus optional `description` and `expectedWarnings`.
Adds a test-only Value: Decodable conformance so predicates and variables
decode straight into the engine's value model; production Value is unchanged.
Tests that can't be expressed as predicate->Bool stay in Swift; ValueTests
untouched. Test-only change.
Co-authored-by: Cursor <cursoragent@cursor.com>
(cherry picked from commit 40901e5)
f6c4c80 to
874649b
Compare
d2ca6d6 to
03295d9
Compare
Load the in-repo fixtures once and feed the decoded cases straight into the parameterized test, instead of collecting IDs and re-reading every file to find the matching case per ID. PredicateConformanceFixtureCase gains Identifiable + Sendable (for the arguments) and a CustomTestStringConvertible extension so each case still displays by id. Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Asserting an exact warning count coupled the fixtures to engine internals. Match warnings by substring only (count-agnostic); an empty `contains` now asserts that no warning is emitted, preserving the "does not warn" cases. The three count-only fixtures gain the "missing variable" substring they actually emit. Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Drop the khepri single-file plumbing (defaultFixtureURL, fixtureURL, the no-arg loadCases(), the env var, and the unused fixtureNotFound error). This PR only runs the in-repo PredicateFixtures/ directory; the khepri conformance loader lands with its test in the conformance PR. Co-authored-by: Cursor <cursoragent@cursor.com>
Implements the json-logic-js some/all iteration predicates. Operator coverage is expressed as JSON predicate fixtures (some.json / all.json) run by the shared fixture runner introduced downstack, replacing hand-written unit tests. Co-authored-by: Cursor <cursoragent@cursor.com> (cherry picked from commit d11529c)
874649b to
db50103
Compare
Implements the json-logic-js min/max operators (variadic flat list, ±∞ for empty input, NaN propagation for non-numeric operands). Coverage is expressed as JSON predicate fixtures (min.json / max.json) run by the shared fixture runner, replacing hand-written unit tests. Co-authored-by: Cursor <cursoragent@cursor.com> (cherry picked from commit e73eabe)
03295d9 to
8a445e2
Compare
Co-authored-by: Cursor <cursoragent@cursor.com>
ajpallares
added a commit
that referenced
this pull request
Jun 3, 2026
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # RevenueCat.xcodeproj/project.pbxproj
Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # RevenueCat.xcodeproj/project.pbxproj
ajpallares
added a commit
that referenced
this pull request
Jun 5, 2026
Expresses the "empty-string key resolves to the whole scope and is not
missing" case as a `{"!!":{"missing":[""]}}` -> false fixture; the string
coercion the other missing fixtures use can't distinguish [] from [""].
Bumps the pinned fixture count to 237. Keeps the corpus in sync with the
purchases-android counterpart.
Co-authored-by: Cursor <cursoragent@cursor.com>
Adds fixtures for the empty-segment dot-path splits, var default-vs-null-leaf behavior, and the non-numeric missing_some threshold (7 new cases), bumping the pinned count to 244. Also adds the var-null-path Swift test so the non-fixturizable cases match the purchases-android counterpart. Keeps the fixture corpus byte-identical across both repos. Co-authored-by: Cursor <cursoragent@cursor.com>
…-logic-iteration-operators Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # Tests/RulesEngineInternalTests/PredicateFixtureTests.swift
…json-logic-min-max-operators Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # Tests/RulesEngineInternalTests/PredicateFixtureTests.swift
Co-authored-by: Cursor <cursoragent@cursor.com>
…json-logic-min-max-operators
- Rename the object-array some/all fixtures to describe behavior instead of referencing the khepri oracle - Add fixtures for literal predicates and non-boolean truthy predicate results - Drop the unused opName parameter from parseIterationArgs and return an optional items list so a non-array source is distinguishable from an empty one - Bump pinned fixture count to 271 Co-authored-by: Cursor <cursoragent@cursor.com>
Place operator docs on each op instead of duplicating at the type level; drop "not vacuous truth" wording. Co-authored-by: Cursor <cursoragent@cursor.com>
…-logic-iteration-operators
Add var-fed cases (including the single-array-arg NaN gotcha), min fail-closed and empty-list fail-closed coverage. Collapse the two-pass NaN scan + extremum into a single reducing fold. Pinned fixture count 294 -> 301. Co-authored-by: Cursor <cursoragent@cursor.com>
…erators' into pallares/json-logic-min-max-operators Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # Tests/RulesEngineInternalTests/PredicateFixtureTests.swift
2 tasks
…teration-operators Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # Tests/RulesEngineInternalTests/PredicateFixtureTests.swift
Label each operator grouping in Operators.dispatch per PR review feedback. Co-authored-by: Cursor <cursoragent@cursor.com>
Rename the all-match fixture and add cases where only the first or only the middle item matches, addressing PR review feedback that the existing some coverage was order dependent. Co-authored-by: Cursor <cursoragent@cursor.com>
khepri guards all with notEmpty, so it returns false for an empty array like json-logic-js; drop the inaccurate claim that khepri returns true. Co-authored-by: Cursor <cursoragent@cursor.com>
…teration-operators
…erators' into pallares/json-logic-min-max-operators Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # Tests/RulesEngineInternalTests/PredicateFixtureTests.swift
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 4d696d6. Configure here.
Remove the duplicate WorkflowsCacheTests.swift PBXFileReference introduced during a merge, and add a dedicated "Min and max" grouping comment so the min/max cases are no longer lumped under arithmetic. Co-authored-by: Cursor <cursoragent@cursor.com>
Member
Author
|
Merging based on the prior approval + the approval from RevenueCat/purchases-android#3552 which is the same diff but in Android |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Checklist
Motivation
Adds
min/maxso audience predicates can compare values against numeric extrema. Resolves SDK-4344. Stacked on #6817.Description
Number()(like-///%, notparseFloatas in+/*). No iteration or projection.±∞(mirrorsMath.min()/Math.max()); non-numeric operands coerce toNaNand poison the result, so a malformed predicate fails closed against a numeric threshold.min.json/max.json) run by the shared fixture runner; no Swift unit tests.Note
Low Risk
Isolated rules-engine operator addition with extensive fixture tests; no auth, purchases, or data-path changes.
Overview
Adds JSON Logic
minandmaxoperators to the rules engine so audience predicates can compare values against numeric extrema (aligned with JSMath.min/Math.max).Operands are a flat variadic list (
{"min": [a, b, ...]}); each value coerces viaValue.asNumber(JSNumber()). Empty lists yield±∞; invalid operands yieldNaN, which fails closed when compared to thresholds. Wiring is inOperators.dispatchvia newMinMaxOperators; coverage is declarative fixtures (min.json,max.json) with the shared fixture count raised to 307.Reviewed by Cursor Bugbot for commit 7482442. Bugbot is set up for automated code reviews on this repo. Configure here.