nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: CacheControl/json-rules-engine
Pull request #64 (2018-01-26 18:05:42)

Add factResults to condition json if available, increase auditability.
Adding `factResult` and `result` to the JSON generated for `Condition`

The use case here is that I'd like to store the results of a run and know what the fact (specifically facts that are computed) was at the time and the result of each condition. 

This will allow us to audit decision in the future and know exactly what the decision looked like at the time.

Feedback is welcome!

CacheControl: Interesting!  Thanks for the contribution @bjacobso !  I'll take a look at this over the weekend

Patch:
diff --git a/src/condition.js b/src/condition.js
index ff6b89f..3910ffd 100644
--- a/src/condition.js
+++ b/src/condition.js
@@ -49,6 +49,12 @@ export default class Condition {
       props.operator = this.operator
       props.value = this.value
       props.fact = this.fact
+      if (this.factResult !== undefined) {
+        props.factResult = this.factResult
+      }
+      if (this.result !== undefined) {
+        props.result = this.result
+      }
       if (this.params) {
         props.params = this.params
       }


Test patch:
diff --git a/test/engine-event.test.js b/test/engine-event.test.js
index efaf649..bf27f85 100644
--- a/test/engine-event.test.js
+++ b/test/engine-event.test.js
@@ -305,7 +305,7 @@ describe('Engine: event', () => {
       rule.on('success', successSpy)
       await engine.run()
       let ruleResult = successSpy.getCall(0).args[2]
-      let expected = '{"conditions":{"priority":1,"any":[{"operator":"greaterThanInclusive","value":21,"fact":"age"},{"operator":"equal","value":true,"fact":"qualified"}]},"event":{"type":"setDrinkingFlag","params":{"canOrderDrinks":true}},"priority":100,"result":true}'
+      let expected = '{"conditions":{"priority":1,"any":[{"operator":"greaterThanInclusive","value":21,"fact":"age","factResult":21,"result":true},{"operator":"equal","value":true,"fact":"qualified","factResult":false,"result":false}]},"event":{"type":"setDrinkingFlag","params":{"canOrderDrinks":true}},"priority":100,"result":true}'
       expect(JSON.stringify(ruleResult)).to.equal(expected)
     })
   })
Repository: CacheControl/json-rules-engine
Pull request #123 (2019-04-13 17:38:42)

fix for issue : https://github.com/CacheControl/json-rules-engine/iss…
This pull request contains fix for issue:#120, and tests.


Patch:
diff --git a/src/engine.js b/src/engine.js
index 2a0ee48..178bc83 100644
--- a/src/engine.js
+++ b/src/engine.js
@@ -66,6 +66,7 @@ class Engine extends EventEmitter {
 
     let index = this.rules.indexOf(rule)
     if (index === -1) return false
+    this.prioritizedRules = null
     return Boolean(this.rules.splice(index, 1).length)
   }
 


Test patch:
diff --git a/test/engine.test.js b/test/engine.test.js
index f72c451..f5b48cb 100644
--- a/test/engine.test.js
+++ b/test/engine.test.js
@@ -89,6 +89,7 @@ describe('Engine', () => {
         expect(engine.rules.length).to.equal(1)
         engine.removeRule(rule)
         expect(engine.rules.length).to.equal(0)
+        expect(engine.prioritizedRules).to.equal(null)
       })
     })
 
@@ -106,6 +107,14 @@ describe('Engine', () => {
       const isRemoved = engine.removeRule(rule)
       expect(isRemoved).to.equal(false)
     })
+
+    it('clears the "prioritizedRules" cache', () => {
+      let rule = new Rule(factories.rule())
+      engine.addRule(rule)
+      engine.prioritizeRules()
+      engine.removeRule(rule)
+      expect(engine.prioritizedRules).to.equal(null)
+    })
   })
 
   describe('addOperator()', () => {
Repository: CacheControl/json-rules-engine
Pull request #404 (2024-11-21 21:46:20)

call Rule.ruleEvent by its correct name
Currently, the [types](https://github.com/CacheControl/json-rules-engine/blob/00061aceb905d1b0e8f571ef3baf200dc32ded61/types/index.d.ts#L178) suggest that `Rule` has a property called `event`, but the property is actually called `ruleEvent`, as evidenced by [this test](https://github.com/CacheControl/json-rules-engine/blob/00061aceb905d1b0e8f571ef3baf200dc32ded61/test/rule.test.js#L32). This PR fixes that by changing the type of `Rule`. This is not breaking because any TypeScript code referring to a `Rule`'s `event` can never have worked.


Patch:
diff --git a/src/rule.js b/src/rule.js
index 3d52fbf..98007e8 100644
--- a/src/rule.js
+++ b/src/rule.js
@@ -101,6 +101,7 @@ class Rule extends EventEmitter {
     this.ruleEvent = {
       type: event.type
     }
+    this.event = this.ruleEvent
     if (event.params) this.ruleEvent.params = event.params
     return this
   }
diff --git a/types/index.d.ts b/types/index.d.ts
index 6dea6b8..aaa22f8 100644
--- a/types/index.d.ts
+++ b/types/index.d.ts
@@ -175,7 +175,11 @@ export class Rule implements RuleProperties {
   constructor(ruleProps: RuleProperties | string);
   name: string;
   conditions: TopLevelCondition;
-  event: Event;
+  /**
+   * @deprecated Use {@link Rule.event} instead.
+   */
+  ruleEvent: Event;
+  event: Event
   priority: number;
   setConditions(conditions: TopLevelCondition): this;
   setEvent(event: Event): this;


Test patch:
diff --git a/test/rule.test.js b/test/rule.test.js
index fc3357b..75a5fee 100644
--- a/test/rule.test.js
+++ b/test/rule.test.js
@@ -30,6 +30,7 @@ describe('Rule', () => {
       expect(rule.priority).to.eql(opts.priority)
       expect(rule.conditions).to.eql(opts.conditions)
       expect(rule.ruleEvent).to.eql(opts.event)
+      expect(rule.event).to.eql(opts.event)
       expect(rule.name).to.eql(opts.name)
     })
 
@@ -52,6 +53,7 @@ describe('Rule', () => {
       expect(rule.priority).to.eql(opts.priority)
       expect(rule.conditions).to.eql(opts.conditions)
       expect(rule.ruleEvent).to.eql(opts.event)
+      expect(rule.event).to.eql(opts.event)
       expect(rule.name).to.eql(opts.name)
     })
   })
@@ -322,6 +324,7 @@ describe('Rule', () => {
       expect(hydratedRule.conditions).to.eql(rule.conditions)
       expect(hydratedRule.priority).to.eql(rule.priority)
       expect(hydratedRule.ruleEvent).to.eql(rule.ruleEvent)
+      expect(hydratedRule.event).to.eql(rule.event)
       expect(hydratedRule.name).to.eql(rule.name)
     })
 
@@ -333,6 +336,7 @@ describe('Rule', () => {
       expect(hydratedRule.conditions).to.eql(rule.conditions)
       expect(hydratedRule.priority).to.eql(rule.priority)
       expect(hydratedRule.ruleEvent).to.eql(rule.ruleEvent)
+      expect(hydratedRule.event).to.eql(rule.event)
       expect(hydratedRule.name).to.eql(rule.name)
     })
   })