Files
zen/core/engine/Cargo.toml
stefan-gorules 0083a66418 fix: v2 equality gaps (#577)
* fix(expression): copy values that read the node's own output on the compiled path

* fix(expression): match a date against every text cell naming it

* test(engine): cover the fixed version differences on every evaluation path

* fix(engine): keep the table index and compiled plan off tables whose cells read the last tested value

* fix(engine): give batch rows the node values and replaced fields a single row sees

* test(engine): cover the batch and table differences on every evaluation path

* fix(engine): read declared date inputs in the evaluation's time zone

* fix(engine): keep script dates right beyond 2099, at extreme years and for object arguments

* fix(engine): name script modules alike on every traced batch row

* fix(expression): keep typed batch results and errors equal to the row engine

* fix(engine): keep loop items, traced table fields and batch node values equal to version 1

* fix(engine): record table references in batch traces when a rule has a description

* fix(nodejs): convert decision results, policy traces and handler values without aborting on large integers

* fix(nodejs): reject fractional engine versions

* test(engine): cover null leaves in multi-row batches

* fix(engine): keep a null written under a missing or scalar parent in multi-row batches

A layer over an upstream patched shape treated every null leaf as absent,
so obj.a = null over a row without obj (or with obj = 1) never created
{obj: {a: null}} for downstream reads, and an all-null column was dropped
outright. A dotted null leaf now stays present on the rows whose parent
is not an object before the write, matching version 1's merge.

* fix(engine): merge a parent reached by duplicate edges once in multi-row batches

Version 1 merges a node's output onto itself as a no-op when two edges
from the same node meet at a target, so nested nulls survive. The batch
path gathered the parent twice as separate copies and re-applied the
patch, deleting those nulls and letting a dangling node's value win over
a null written on the twice-connected branch. Consecutive duplicate
parents now merge once.

* fix(engine): let a later table output replace an earlier one under it in batches

A rule writing res, res.k and then res again keeps only the last res in
version 1, because the final write replaces the object that res.k went
into. The compiled table folded the duplicate paths into one slot per
path and re-inserted res.k on top. Non-collect outputs that a later
non-collect output of the same rule replaces are now left out.

* fix(engine): share common ancestry when batch rows merge related parents

Version 1 merges parent outputs copy-on-write: a pass-through node shares
every subtree it did not change with its input, and merging two values
that share an object skips it. So a nested null written once and reached
through two branches survives the join, and an input null survives a
pass-through that changed nothing. The batch path rebuilt each parent's
rows separately, lost that sharing and deleted those nulls. When parents
share a base or leading layers and the merged parent can hold a null,
the join now derives their rows from the shared prefix with the same
copy-on-write merge; other joins stay columnar. Traced batch rows derive
pass-through outputs from their merged input the same way.

* fix(engine): keep one materialization per node so batch joins see shared rows

Gathering a node's rows for each consumer, and clearing a table's
unmatched rows before a pass-through, materialized the same node output
more than once, so a pass-through built from one copy no longer shared
objects with the copy merged at the join, and the version 1 rule that a
shared object merges as a no-op could not apply. Gathered copies of a
node on the same rows now share one materialization, a cleared copy
reuses its source's rows, layers keep their identity when picked to a
row subset, and input rows match by object identity. The final output
still materializes its own copy, since cleaning it mutates in place.

* test(engine): cover policy columns for a tested value that fails

* fix(engine): return column traces in the legacy format when it is requested

* fix(engine): return an error instead of building a cyclic value when an expression entry writes an object into itself on version 2

An entry such as `a.c = obj` after `a = obj` wrote the object into itself,
and merging, cloning, comparing, tracing or serialising the result then
overflowed the stack. The hosted expression node now checks, before each
write, whether the value reaches the object it is written into and fails the
row with "cyclic value at <key>". Compiled nodes that write a possibly
container value under a key an earlier entry set are routed through the same
row evaluation, so every path (first call, repeated, compiled, batch,
columnar, traced) reports the error for that row only.

* test(engine): cover a script returning a cyclic object on version 2

Ignored until the version 2 JS runtime rejects cyclic results; it hangs today.

* fix(engine): match version 1 in script globals and dates, stop idle or cyclic scripts, and load date support lazily

* fix(engine): leave version 1 table indexes as released and give version 2 its own

* fix(engine): show the tested value under its key when a table reads the whole root

* fix(engine): copy values read through $ and leave written-back keys alone, as version 1 merges them

* perf(engine): keep tables whose outputs read the tested value on the compiled plan

* test(engine): record pinned Date results across zones, DST gaps and far years

* perf(engine): pin Date in Rust instead of a JavaScript shim on version 2

Function nodes on version 2 replaced Date with a JavaScript module whose
local getters, setters and string methods rebuilt every field through
native calls and allocations, and whose lazy half cost about 45 us to
load on the first Date use of each evaluation.

The pinned constructor, Date.now, Date.parse, Math.random and the zone
dependent prototype methods are now callable Rust classes built with the
safe rquickjs API. They read the time value through the native getTime,
compute fields and offsets with chrono-tz in Rust (fixed offset zones
skip the lookup, the last instant's fields are cached per evaluation)
and keep QuickJS's Date for storage and everything zone independent.
The constructor is a bound function so calls and constructions are
told apart exactly. The prototype methods are still installed on the
first construction or parse, now in about 6 us.

Results are unchanged: recorded per-zone results, version parity and
the isolation spec pass as before.

* fix(engine): keep the machine time zone out of parsed script dates
2026-11-23 17:49:17 +01:00

84 lines
2.9 KiB
TOML

[package]
authors = ["GoRules Team <bot@gorules.io>"]
description = "Business rules engine"
name = "zen-engine"
license = "MIT"
version = "2.1.6"
edition = "2021"
repository = "https://github.com/gorules/zen.git"
homepage = "https://gorules.io"
[lib]
doctest = false
[dependencies]
chrono = { workspace = true }
chrono-tz = "0.10"
ahash = { workspace = true }
anyhow = { workspace = true }
base64 = "0.22"
itoa = "1"
regex = { workspace = true }
thiserror = { workspace = true }
petgraph = { workspace = true }
serde_json = { workspace = true, features = ["raw_value"] }
serde = { workspace = true, features = ["derive", "rc"] }
serde_path_to_error = "0.1"
strum = { workspace = true, features = ["derive"] }
once_cell = { workspace = true }
json_dotpath = { workspace = true }
rust_decimal = { workspace = true, features = ["maths-nopanic"] }
fixedbitset = "0.5"
tokio = { workspace = true, features = ["sync", "time"] }
rquickjs = { version = "0.10", features = ["macro", "loader", "rust-alloc", "futures", "either", "properties"] }
zen-types = { path = "../types", version = "2.1.6" }
zen-expression = { path = "../expression", version = "2.1.6" }
zen-tmpl = { path = "../template", version = "2.1.6" }
smallvec = { version = "1", features = ["union"] }
nohash-hasher = { workspace = true }
downcast-rs = { version = "2.0", features = ["std", "sync"] }
arc-swap = "1"
flate2 = { version = "1", features = ["rust_backend"] }
zip = { version = "8", default-features = false, features = ["deflate-flate2"] }
swc_ts_fast_strip = "53.0.0"
swc_common = "23"
swc_ecma_parser = "41"
swc_ecma_ast = "25"
typed-arena = "2"
self_cell = "1"
[dev-dependencies]
serde_json = { workspace = true, features = ["unbounded_depth"] }
tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }
criterion = { workspace = true, features = ["async_tokio"] }
insta = { version = "1.43", features = ["yaml", "redactions"] }
toml = "0.8"
mimalloc = "0.1.52"
ctor = "1.0.13"
[target.'cfg(not(target_family = "wasm"))'.dependencies]
recursive = { workspace = true }
async-trait = { version = "0.1" }
http = { version = "1.3" }
reqwest = { version = "0.12", features = ["json", "rustls-tls"], default-features = false }
reqsign = { version = "0.20", features = ["aws", "azure", "google", "default-context"] }
sha2 = { version = "0.10" }
jsonschema = { version = "0.49" }
[target.'cfg(target_family = "wasm")'.dependencies]
jsonschema = { version = "0.49", default-features = false }
rquickjs = { version = "0.10", features = ["macro", "loader", "rust-alloc", "futures", "either", "properties", "bindgen"] }
[[bench]]
harness = false
name = "engine"
[features]
default = []
bindgen = ["rquickjs/bindgen"]
arbitrary_precision = ["serde_json/arbitrary_precision", "zen-expression/arbitrary_precision", "zen-types/arbitrary_precision", "zen-tmpl/arbitrary_precision"]
[[test]]
name = "golden"
required-features = ["arbitrary_precision"]