diff --git a/core/engine/Cargo.toml b/core/engine/Cargo.toml index 55407796..19fbabf2 100644 --- a/core/engine/Cargo.toml +++ b/core/engine/Cargo.toml @@ -22,7 +22,7 @@ json_dotpath = { workspace = true } fixedbitset = "0.4.2" tokio = { workspace = true, features = ["sync", "time"] } reqwest = { version = "0.12", features = ["json", "rustls-tls"], default-features = false } -rquickjs = { version = "0.6.2", features = ["macro", "loader", "rust-alloc", "futures", "either", "properties"] } +rquickjs = { git = "https://github.com/stefan-gorules/rquickjs.git", branch = "master", features = ["macro", "loader", "rust-alloc", "futures", "either", "properties"] } itertools = { workspace = true } zen-expression = { path = "../expression", version = "0.24.0" } zen-tmpl = { path = "../template", version = "0.24.0" } diff --git a/core/engine/tests/engine.rs b/core/engine/tests/engine.rs index d7ca8e18..dc9e9c74 100644 --- a/core/engine/tests/engine.rs +++ b/core/engine/tests/engine.rs @@ -236,3 +236,33 @@ async fn engine_graph_tests() { } } } + +#[tokio::test] +#[cfg_attr(miri, ignore)] +async fn engine_function_v2() { + let engine = DecisionEngine::default().with_loader(create_fs_loader().into()); + + for _ in 0..1_000 { + let function_opt_r = engine + .evaluate_with_opts( + "function-v2.json", + &json!({ "input": 12 }), + EvaluationOptions { + trace: Some(true), + max_depth: None, + }, + ) + .await; + + assert!(function_opt_r.is_ok(), "function v2 has errored"); + + let function_opt = function_opt_r.unwrap(); + let trace = function_opt.trace.unwrap(); + assert_eq!(trace.len(), 3); // trace for each node + + assert_eq!( + function_opt.result, + json!({ "hello": "world", "multiplied": 24 }) + ) + } +} diff --git a/test-data/function-v2.json b/test-data/function-v2.json new file mode 100644 index 00000000..b5b6cdbb --- /dev/null +++ b/test-data/function-v2.json @@ -0,0 +1,48 @@ +{ + "edges": [ + { + "id": "8ec75bf7-5229-4138-8fdc-486c8f82b600", + "type": "edge", + "sourceId": "c4dbea62-f0b1-421c-a504-a82983cea33a", + "targetId": "54b6b317-0681-4f8f-b13a-18c579282500" + }, + { + "id": "2d45f4f3-0afe-499f-9bc9-5d247bc036db", + "type": "edge", + "sourceId": "54b6b317-0681-4f8f-b13a-18c579282500", + "targetId": "48984a7a-71c9-4642-adb3-f6ce0a75bcca" + } + ], + "nodes": [ + { + "id": "c4dbea62-f0b1-421c-a504-a82983cea33a", + "name": "request", + "type": "inputNode", + "position": { + "x": 100, + "y": 95 + } + }, + { + "id": "48984a7a-71c9-4642-adb3-f6ce0a75bcca", + "name": "response", + "type": "outputNode", + "position": { + "x": 515, + "y": 255 + } + }, + { + "id": "54b6b317-0681-4f8f-b13a-18c579282500", + "name": "function1", + "type": "functionNode", + "content": { + "source": "export const handler = async (input) => ({ hello: 'world', multiplied: input.input * 2 })" + }, + "position": { + "x": 210, + "y": 285 + } + } + ] +} \ No newline at end of file