release: v2.2.2 V_safe JSON integer refuse on foreign bridge

Align host json encode/decode with Lean ForeignJSON: refuse OOD integers
instead of silent Node distortion; keep decimal-string BigInt author path.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
cflmyandCursor committed 2026-11-01 09:43:51 +08:00
1 parent 58791fc7d9
commit 82c8d78fd3
21 files changed
+449 -17

No files matched your search

+87
View File
@@ -1857,6 +1857,41 @@ fn lib_json_roundtrip() {
);
}
#[test]
fn lib_json_vsafe_max_safe_ok() {
assert_out(
"tests/lib/json-vsafe-max-safe-ok.mq.md",
"9007199254740991\n{\"n\":9007199254740991}",
);
}
#[test]
fn lib_json_vsafe_string_ok() {
assert_out(
"tests/lib/json-vsafe-string-ok.mq.md",
"1152921504606846977",
);
}
#[test]
fn lib_json_vsafe_refuse() {
// Span points at lib/json.mq.md `parse` body while path stays the caller file.
assert_err(
"tests/lib/json-vsafe-refuse.mq.md",
"16:1",
"json: integer outside V_safe",
);
}
#[test]
fn lib_json_vsafe_stringify_refuse() {
assert_err(
"tests/lib/json-vsafe-stringify-refuse.mq.md",
"24:1",
"json: integer outside V_safe",
);
}
#[test]
fn lib_table_collections() {
assert_out(
@@ -3579,6 +3614,58 @@ fn lib_foreign_session_python() {
assert_out("tests/lib/foreign-session-python.mq.md", "42\n5");
}
#[test]
fn lib_foreign_session_vsafe_refuse() {
if !node_available() {
eprintln!("skip lib_foreign_session_vsafe_refuse: no node on PATH");
return;
}
// Span points at lib/foreign.mq.md session_set body.
assert_err(
"tests/lib/foreign-session-vsafe-refuse.mq.md",
"206:1",
"json: integer outside V_safe",
);
}
#[test]
fn lib_foreign_vsafe_refuse() {
if !python_available() {
eprintln!("skip lib_foreign_vsafe_refuse: no python on PATH");
return;
}
assert_err(
"tests/lib/foreign-vsafe-refuse.mq.md",
"16:1",
"json: integer outside V_safe",
);
}
#[test]
fn lib_foreign_vsafe_postarith_refuse() {
if !python_available() {
eprintln!("skip lib_foreign_vsafe_postarith_refuse: no python on PATH");
return;
}
assert_err(
"tests/lib/foreign-vsafe-postarith-refuse.mq.md",
"16:1",
"json: integer outside V_safe",
);
}
#[test]
fn lib_foreign_vsafe_string_ok() {
if !node_available() {
eprintln!("skip lib_foreign_vsafe_string_ok: no node on PATH");
return;
}
assert_out(
"tests/lib/foreign-vsafe-string-ok.mq.md",
"{\"out\":\"1152921504606846978\"}",
);
}
#[test]
fn bytecode_lib_math_formula() {
assert_out_backend(
@@ -0,0 +1,13 @@
---
markup: occlusion
title: foreign session_set V_safe refuse
import:
foreign: lib/foreign.mq.md
---
# main
**node = > foreign.session_open lang="node" timeout=30**
**n = 1152921504606846977**
**> foreign.session_set id=`node` name="__n" value=`n`**
**> foreign.session_close id=`node`**
@@ -0,0 +1,24 @@
---
markup: occlusion
title: foreign V_safe refuse after Python arithmetic
import:
foreign: lib/foreign.mq.md
json: lib/json.mq.md
---
# main
**py = > foreign.session_open lang="python" timeout=30**
`emit` =
```python
import json
n = 2**53 - 1
print(json.dumps({"n": 2 * n}))
```
**raw = > foreign.session_eval id=`py` code=`emit`**
**stdout = > json.get value=`raw` key="stdout"**
**payload = > json.parse text=`stdout`**
**> print text=`payload`**
**> foreign.session_close id=`py`**
+23
View File
@@ -0,0 +1,23 @@
---
markup: occlusion
title: foreign Python JSON number V_safe refuse
import:
foreign: lib/foreign.mq.md
json: lib/json.mq.md
---
# main
**py = > foreign.session_open lang="python" timeout=30**
`emit` =
```python
import json
print(json.dumps({"n": 2**60 + 1}))
```
**raw = > foreign.session_eval id=`py` code=`emit`**
**stdout = > json.get value=`raw` key="stdout"**
**payload = > json.parse text=`stdout`**
**> print text=`payload`**
**> foreign.session_close id=`py`**
+24
View File
@@ -0,0 +1,24 @@
---
markup: occlusion
title: foreign V_safe string to Node BigInt
import:
foreign: lib/foreign.mq.md
json: lib/json.mq.md
---
# main
**node = > foreign.session_open lang="node" timeout=30**
**s = "1152921504606846977"**
`inc` =
```javascript
const out = (BigInt(globalThis.__s) + 1n).toString();
console.log(JSON.stringify({out}));
```
**> foreign.session_set id=`node` name="__s" value=`s`**
**js = > foreign.session_eval id=`node` code=`inc`**
**js_out = > json.get value=`js` key="stdout"**
**> print text=`js_out`**
**> foreign.session_close id=`node`**
+15
View File
@@ -0,0 +1,15 @@
---
markup: occlusion
title: json V_safe MAX_SAFE roundtrip
import:
json: lib/json.mq.md
---
# main
**obj = > json.parse text={"n":9007199254740991}**
**n = > json.get value=`obj` key="n"**
**out = > json.stringify value=`obj`**
> print text=`n`
> print text=`out`
+12
View File
@@ -0,0 +1,12 @@
---
markup: occlusion
title: json V_safe refuse OOD integer
import:
json: lib/json.mq.md
---
# main
**bad = > json.parse text={"n":1152921504606846977}**
> print text=`bad`
+13
View File
@@ -0,0 +1,13 @@
---
markup: occlusion
title: json V_safe decimal string ok
import:
json: lib/json.mq.md
---
# main
**obj = > json.parse text={"s":"1152921504606846977"}**
**s = > json.get value=`obj` key="s"**
> print text=`s`
@@ -0,0 +1,13 @@
---
markup: occlusion
title: json V_safe refuse OOD Int stringify
import:
json: lib/json.mq.md
---
# main
**n = 1152921504606846977**
**out = > json.stringify value=`n`**
> print text=`out`