Skip to content

Commit

Permalink
Merge branch '1.3.4-hotfix'
Browse files Browse the repository at this point in the history
  • Loading branch information
k13gomez committed Jul 25, 2024
2 parents a11cdad + 867a8af commit 271e5ef
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ This is a history of changes to k13labs/clara-rules.
* add `defdata` macro to define facts and collections of facts in namespaces allowing to easily embed and insert them during mk-session.
* rename `clear-ns-productions!` to `clear-ns-vars!` since now there are ns-installed vars that are not productions.

# 1.3.4
* Update CyclicalRulesListener to return the cycles-count value when converted to persistent.

# 1.3.3
* Upgrade to clojure 1.11.2 to fix `CVE-2024-22871`, despite not really affecting clara-rules.
* Add clj-kondo linter updates to fix bad docstring expression.
Expand Down
2 changes: 1 addition & 1 deletion deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
:deps/prep-lib {:alias :build
:fn compile-main-java
:ensure "target/main/classes"}
:deps {org.clojure/clojure {:mvn/version "1.11.2"}
:deps {org.clojure/clojure {:mvn/version "1.11.3"}
org.clojure/core.cache {:mvn/version "1.1.234"}
org.clj-commons/digest {:mvn/version "1.4.100"}
com.github.k13labs/futurama {:mvn/version "1.0.3"}
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<dependency>
<groupId>org.clojure</groupId>
<artifactId>clojure</artifactId>
<version>1.11.2</version>
<version>1.11.3</version>
</dependency>
<dependency>
<groupId>com.cnuernber</groupId>
Expand Down
7 changes: 5 additions & 2 deletions src/main/clojure/clara/tools/loop_detector.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
(ns clara.tools.loop-detector
(:require [clara.rules.listener :as l]
[clara.rules.engine :as eng]
[clara.tools.tracing :as trace]))
[clara.tools.tracing :as trace])
(:import [clojure.lang IDeref]))

;; Although we use a single type here note that the cycles-count and the on-limit-delay fields
;; will be nil during the persistent state of the listener.
Expand Down Expand Up @@ -44,7 +45,9 @@
@on-limit-delay)
(swap! cycles-count inc))
(to-persistent! [listener]
(CyclicalRuleListener. nil max-cycles on-limit-fn nil))
(CyclicalRuleListener. (if (instance? IDeref cycles-count)
(deref cycles-count)
cycles-count) max-cycles on-limit-fn nil))

l/IPersistentEventListener
(to-transient [listener]
Expand Down
35 changes: 34 additions & 1 deletion src/test/clojure/clara/test_infinite_loops.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
[clara.rules.accumulators :as acc]
[clara.tools.loop-detector :as ld]
[clojure.core.async :refer [timeout]]
[futurama.core :refer [!<!! !<! async async-cancel!]])
[futurama.core :refer [!<!! !<! async async-cancel!]]
[clara.rules.engine :as eng])
(:import [java.util.concurrent CancellationException]
[clara.rules.testfacts Cold Hot First Second]
[clara.tools.loop_detector
CyclicalRuleListener]
[clara.tools.tracing
PersistentTracingListener]))

Expand Down Expand Up @@ -264,6 +267,36 @@
(query first-query)))
21)))

(def-rules-test test-cycle-count-returned
;; As the name suggests, this is a test to validate that cycle-count is returned on the persistend listener.
{:rules [recursive-rule-with-end [[[First]]
(when (< @side-effect-holder 20)
(do
(insert-unconditional! (->First))
(swap! side-effect-holder inc)))]]

:queries [first-query [[] [[?f <- First]]]]

:sessions [empty-session [recursive-rule-with-end first-query] {}]}

(reset! side-effect-holder 0)

(is (= (count (-> (ld/with-loop-detection empty-session 30 :throw-exception)
(insert (->First))
fire-rules
(query first-query)))
21))

(reset! side-effect-holder 0)

(is (= (let [^CyclicalRuleListener listener (-> (ld/with-loop-detection empty-session 30 :throw-exception)
(insert (->First))
fire-rules
(eng/find-listeners (partial instance? CyclicalRuleListener))
first)]
(.cycles-count listener))
20)))

(def-rules-test test-max-cycles-per-fire-rules-call

{:rules [recursive-rule-with-end [[[First]]
Expand Down

0 comments on commit 271e5ef

Please sign in to comment.