Rules : Fix logical operation for negative matchers with multiple values#1147
Merged
PravinPK merged 1 commit intoadobe:dev-v5.5.1from Jun 11, 2025
Merged
Rules : Fix logical operation for negative matchers with multiple values#1147PravinPK merged 1 commit intoadobe:dev-v5.5.1from
PravinPK merged 1 commit intoadobe:dev-v5.5.1from
Conversation
sbenedicadb
approved these changes
Jun 9, 2025
Member
sbenedicadb
left a comment
There was a problem hiding this comment.
looks good pending adding another test or two
Comment on lines
+192
to
+216
| // Matcher: ne | ||
| func testMatcherNe_multipleValues() { | ||
| /// Given: | ||
| resetRulesEngine(withNewRules: "rules_testMatcherNe_multipleValues") | ||
|
|
||
| mockRuntime.simulateSharedState(for: "com.adobe.module.lifecycle", data: (value: ["lifecyclecontextdata": ["carriername": "AT&T"]], status: .set)) | ||
| /// When: | ||
| rulesEngine.process(event: defaultEvent) | ||
| /// Then: | ||
| XCTAssertEqual(0, mockRuntime.dispatchedEvents.count) | ||
|
|
||
| /// When: | ||
| mockRuntime.simulateSharedState(for: "com.adobe.module.lifecycle", data: (value: ["lifecyclecontextdata": ["carriername": "Blue"]], status: .set)) | ||
| rulesEngine.process(event: defaultEvent) | ||
| /// Then: | ||
| XCTAssertEqual(1, mockRuntime.dispatchedEvents.count) | ||
| let consequenceEvent = mockRuntime.dispatchedEvents[0] | ||
| XCTAssertEqual(EventType.rulesEngine, consequenceEvent.type) | ||
| XCTAssertEqual(EventSource.responseContent, consequenceEvent.source) | ||
| guard let data = consequenceEvent.data?["triggeredconsequence"], let dataWithType = data as? [String: Any] else { | ||
| XCTFail() | ||
| return | ||
| } | ||
| XCTAssertEqual("pb", dataWithType["type"] as! String) | ||
| } |
Member
There was a problem hiding this comment.
do we already have this same test where we simulate for one of the values in the list and assert that there are no dispatched consequence events?
Contributor
Author
There was a problem hiding this comment.
Hey Steve, yes we had a test for that case already
aepsdk-core-ios/AEPCore/Tests/TestResources/rules_testMatcherNe.json
Lines 63 to 66 in ba38bd2
Its following tests evaluates ne matchers both positive and negative cases with single value
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.
Problem
When processing multiple values, the rules engine used OR logic for all matchers , which creates a logical flaw for negative
conditions. For example
This is always true for negative matchers! If carriername = "AT&T", the condition carriername != "Verizon" makes the entire OR expression true, causing incorrect rule firing.
Impact
This was causing rules to fire when they shouldn't. (Customer issue : IAM was fired too often)
Solution
Modified JSONRulesParser.swift to use AND logic for negative matchers like notContains (nc) and notExists (ne).
Correct evaluation