feat(foreign): persistent Python/Node kernels and state bridge
F3/F3.5: session_open/eval/close/list, session_set/get/names, Python and Node bootstraps, strict serial protocol, per-session timeout, crash isolation, drop cleanup, and node/bash gold tests (python conditional).
This commit is contained in:
1 parent
7859170aec
commit
050d71927f
12 files changed
+1122
-8
No files matched your search
@@ -3402,6 +3402,36 @@ fn lib_foreign_config() {
|
||||
assert_eq!(stdout.trim_end(), "1\ncfg", "stdout={stdout}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lib_foreign_session() {
|
||||
if !node_available() {
|
||||
eprintln!("skip lib_foreign_session: no node on PATH");
|
||||
return;
|
||||
}
|
||||
assert_out("tests/lib/foreign-session.mq.md", "42\n41\n5\n1\nTrue");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lib_foreign_session_timeout() {
|
||||
if !node_available() {
|
||||
eprintln!("skip lib_foreign_session_timeout: no node on PATH");
|
||||
return;
|
||||
}
|
||||
assert_out(
|
||||
"tests/lib/foreign-session-timeout.mq.md",
|
||||
"False\nTrue\nFalse",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lib_foreign_session_python() {
|
||||
if !python_available() {
|
||||
eprintln!("skip lib_foreign_session_python: no python on PATH");
|
||||
return;
|
||||
}
|
||||
assert_out("tests/lib/foreign-session-python.mq.md", "42\n5");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bytecode_lib_math_formula() {
|
||||
assert_out_backend(
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
---
|
||||
title: foreign python session
|
||||
import foreign:lib/foreign.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
**会话 = > foreign.session_open lang="python"**
|
||||
**设值 = > foreign.session_eval id=`会话` source="x = 41"**
|
||||
**求值 = > foreign.session_eval id=`会话` source="x + 1"**
|
||||
|
||||
> print text=[result](`求值`)
|
||||
|
||||
**> foreign.session_set id=`会话` name="y" value=5**
|
||||
**取值 = > foreign.session_get id=`会话` name="y"**
|
||||
|
||||
> print text=`取值`
|
||||
**> foreign.session_close id=`会话`**
|
||||
@@ -0,0 +1,13 @@
|
||||
---
|
||||
title: foreign session timeout
|
||||
import foreign:lib/foreign.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
**会话 = > foreign.session_open lang="node"**
|
||||
**慢 = > foreign.session_eval id=`会话` source="(async () => { await new Promise(r => setTimeout(r, 5000)); return 1; })()" timeout=0.3**
|
||||
|
||||
> print text=[ok](`慢`)
|
||||
> print text=[timed_out](`慢`)
|
||||
> print text=[alive](`慢`)
|
||||
@@ -0,0 +1,27 @@
|
||||
---
|
||||
title: foreign persistent session
|
||||
import foreign:lib/foreign.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
**会话 = > foreign.session_open lang="node"**
|
||||
**设值 = > foreign.session_eval id=`会话` source="let x = 41"**
|
||||
**求值 = > foreign.session_eval id=`会话` source="x + 1"**
|
||||
|
||||
> print text=[result](`求值`)
|
||||
|
||||
**取x = > foreign.session_get id=`会话` name="x"**
|
||||
> print text=`取x`
|
||||
|
||||
**> foreign.session_set id=`会话` name="y" value=5**
|
||||
**取值 = > foreign.session_get id=`会话` name="y"**
|
||||
|
||||
> print text=`取值`
|
||||
|
||||
**会话表 = > foreign.session_list**
|
||||
**数量 = > len `会话表`**
|
||||
> print text=`数量`
|
||||
|
||||
**关闭 = > foreign.session_close id=`会话`**
|
||||
> print text=`关闭`
|
||||
Reference in new issue
Block a user