Replace RulesEngine.logger global with task-local override + module default#6963
Merged
Conversation
…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)
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)
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)
Completes the json-logic-js iteration family (none/map/filter/reduce) on top of some/all. Coverage is expressed as JSON predicate fixtures (none.json / map.json / filter.json / reduce.json) run by the shared fixture runner, replacing hand-written unit tests. Co-authored-by: Cursor <cursoragent@cursor.com> (cherry picked from commit 46d6925)
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
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>
Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # RevenueCat.xcodeproj/project.pbxproj
Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # RevenueCat.xcodeproj/project.pbxproj
Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # RevenueCat.xcodeproj/project.pbxproj
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
…on-logic-iteration-mapping-operators Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # Tests/RulesEngineInternalTests/PredicateFixtureTests.swift
…ators' into pallares/json-logic-iteration-mapping-operators Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # Tests/RulesEngineInternalTests/PredicateFixtureTests.swift
…teration-mapping-operators Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # Tests/RulesEngineInternalTests/PredicateFixtureTests.swift # Tests/RulesEngineInternalTests/PredicateFixtures/max.json # Tests/RulesEngineInternalTests/PredicateFixtures/min.json
Co-authored-by: Cursor <cursoragent@cursor.com>
…ument) Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Cover logging ±Infinity, NaN, empty object, and empty array. Empty array and empty args were indistinguishable under substring matching (they log "" and "null"), so `expectedLogs` now asserts the exact, ordered list of emitted messages. `expectedWarnings` is unchanged. Co-authored-by: Cursor <cursoragent@cursor.com>
The tag was always the single `[RulesEngine]` constant and never varied at any call site, so it added protocol surface without flexibility. For the `log` channel a prefix also defeats the verbatim passthrough. Hosts that bridge the logger prepend their own identifier when they need one. Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Wrap NaN- and infinity-producing subexpressions in `log` and assert the exact emitted string via `expectedLogs`, so these fixtures verify the intermediate value, not just the final truthiness. Covers arithmetic, min, max, reduce, missing_some, and evaluator edge cases. Co-authored-by: Cursor <cursoragent@cursor.com>
Place a `log` in a branch that should be skipped and assert it never fires (`expectedLogs: []`), with positive controls that log when the branch is evaluated — verifying and/or/if laziness. Co-authored-by: Cursor <cursoragent@cursor.com>
… default Layer a `@TaskLocal scopedLogger` over a write-once module default so test logger injection is race-safe under parallel execution, and add an `@_spi(Internal)` host-SDK wiring entry point. Resolves SDK-4351. Co-authored-by: Cursor <cursoragent@cursor.com>
Defer the host-SDK wiring entry point to a follow-up. This keeps the change to the internal `@TaskLocal scopedLogger` test mechanism layered over a constant default logger. Co-authored-by: Cursor <cursoragent@cursor.com>
Base automatically changed from
pallares/ios-rules-fixture-log-assertions
to
main
June 9, 2026 12:33
…ocal-logger Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # RulesEngineInternal/Logger.swift # Tests/RulesEngineInternalTests/Helpers/CapturingLogger.swift # Tests/RulesEngineInternalTests/Helpers/PredicateConformanceRunner.swift # Tests/RulesEngineInternalTests/PredicateFixtures/log.json
ajpallares
commented
Jun 9, 2026
|
|
||
| /// Logging facade for the rules engine. | ||
| protocol RulesEngineLogger { | ||
| protocol RulesEngineLogger: Sendable { |
Member
Author
There was a problem hiding this comment.
Sendable conformance is required by @TaskLocal
Brings back the lock-guarded `LoggerStorage` so the default logger can be replaced (host-SDK wiring will expose this in a follow-up PR), while keeping everything internal to the module. Co-authored-by: Cursor <cursoragent@cursor.com>
Member
Author
|
@RCGitBot please test |
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.
Motivation
Resolves SDK-4351. The previous
RulesEngine.loggerwas a mutableNSLockcell whose test save/restore raced under parallel execution.Description
@TaskLocal scopedLoggerlayered over a constant default;loggeris now read-only (scopedLogger ?? defaultLogger).RulesEngine.$scopedLogger.withValue(...)instead of mutating shared global state.Note
Low Risk
Logging resolution changes are localized to diagnostics; production still uses configure-time setLogger with optional per-task overrides.
Overview
Replaces mutable global test logger swapping with a
@TaskLocalscopedLoggerlayered on the existing locked module default, soRulesEngine.loggerresolves asscopedLogger ?? defaultwithout parallel tests fighting oversetLogger.RulesEngineLoggeris nowSendable;LoggerStorageand testCapturingLoggeradopt@unchecked Sendablefor concurrency checks.setLoggerremains for one-time SDK configure of the module default only.Tests wire capture loggers via
RulesEngine.$scopedLogger.withValue(...)(invokeTestin accessor tests; predicate conformance runner for warning/log fixtures) instead of save/restore around shared global state.Reviewed by Cursor Bugbot for commit a4b7e67. Bugbot is set up for automated code reviews on this repo. Configure here.