mirror of
https://github.com/gorules/zen.git
synced 2026-11-30 00:07:34 +00:00
feat: engine version (#574)
* feat(engine): select the engine with a version option * ci: run the two feature sets as parallel jobs * refactor(engine): drop the global compiled switch * feat(engine): pin the clock through options instead of the environment The __ZEN_MOCK_UTC_TIME variable and the ZEN_EXPRESSION_CONFIG lane flag are gone. Isolate takes with_now and with_lane, and the interpreted engine now honours the now option in expressions, so tests pass the instant explicitly. * test(engine): count trace paths per thread and drop the trace test lock * ci: run tests with nextest * test(engine): share golden trace outcomes between variants
This commit is contained in:
@@ -239,10 +239,17 @@ impl PyZenEngine {
|
||||
None => Arc::new(PyDecisionLoader::default()),
|
||||
};
|
||||
|
||||
let engine = DecisionEngine::new(
|
||||
let mut engine = DecisionEngine::new(
|
||||
loader,
|
||||
Arc::new(PyCustomNode::new(custom_node, make_locals())),
|
||||
);
|
||||
if let Some(version) = options.get_item("version")? {
|
||||
let version: u32 = version.extract()?;
|
||||
engine.set_version(
|
||||
zen_engine::EngineVersion::try_from(version)
|
||||
.map_err(|e| pyo3::exceptions::PyValueError::new_err(e.to_string()))?,
|
||||
);
|
||||
}
|
||||
engine.compile();
|
||||
|
||||
Ok(Self {
|
||||
|
||||
@@ -8,7 +8,7 @@ import os
|
||||
|
||||
import zen
|
||||
|
||||
os.environ['__ZEN_MOCK_UTC_TIME'] = '2025-08-19T16:55:02.078Z'
|
||||
NOW = "2025-08-19T16:55:02.078Z"
|
||||
|
||||
async def loader(key):
|
||||
with open("../../test-data/" + key, "r") as f:
|
||||
@@ -90,9 +90,9 @@ class AsyncZenEngine(unittest.IsolatedAsyncioTestCase):
|
||||
for test_case in json_contents["tests"]:
|
||||
key = os.path.basename(json_file)
|
||||
|
||||
engine_response = await engine.async_evaluate(key, test_case["input"])
|
||||
engine_response = await engine.async_evaluate(key, test_case["input"], {"now": NOW})
|
||||
decision = engine.get_decision(key)
|
||||
decision_response = await decision.async_evaluate(test_case["input"])
|
||||
decision_response = await decision.async_evaluate(test_case["input"], {"now": NOW})
|
||||
|
||||
self.assertEqual(engine_response["result"], test_case["output"])
|
||||
self.assertEqual(decision_response["result"], test_case["output"])
|
||||
|
||||
@@ -6,7 +6,7 @@ import os
|
||||
|
||||
import zen
|
||||
|
||||
os.environ['__ZEN_MOCK_UTC_TIME'] = '2025-08-19T16:55:02.078Z'
|
||||
NOW = "2025-08-19T16:55:02.078Z"
|
||||
|
||||
def loader(key):
|
||||
with open("../../test-data/" + key, "r") as f:
|
||||
@@ -165,9 +165,9 @@ class ZenEngine(unittest.TestCase):
|
||||
for test_case in json_contents["tests"]:
|
||||
key = os.path.basename(json_file)
|
||||
|
||||
engine_response = engine.evaluate(key, test_case["input"])
|
||||
engine_response = engine.evaluate(key, test_case["input"], {"now": NOW})
|
||||
decision = engine.get_decision(key)
|
||||
decision_response = decision.evaluate(test_case["input"])
|
||||
decision_response = decision.evaluate(test_case["input"], {"now": NOW})
|
||||
|
||||
self.assertEqual(engine_response["result"], test_case["output"], key)
|
||||
self.assertEqual(decision_response["result"], test_case["output"], key)
|
||||
|
||||
@@ -43,6 +43,7 @@ ZenLoaderCallback: TypeAlias = Callable[[str], Union[str, dict, ZenDecisionConte
|
||||
class ZenEngineOptions(TypedDict, total=False):
|
||||
loader: Union[ZenLoaderCallback, ZenLoaderConfig]
|
||||
customHandler: Callable
|
||||
version: Literal[1, 2]
|
||||
|
||||
|
||||
class EvaluateBatchRequest(TypedDict):
|
||||
|
||||
Reference in New Issue
Block a user