From 82c8d78fd32f89cf6f6a3afc846e67065415e973 Mon Sep 17 00:00:00 2001 From: cflmy Date: Sun, 1 Nov 2026 09:43:51 +0800 Subject: [PATCH] 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 --- .cursor/skills/marqdo/SKILL.md | 2 +- .github/workflows/release.yml | 3 + CHANGELOG.md | 22 ++++ Cargo.lock | 4 +- Cargo.toml | 2 +- README.md | 9 +- crates/marqdo-wasm/Cargo.toml | 2 +- debian/changelog | 7 ++ doc/design/foreign-kernel.md | 14 ++- doc/design/v-safe-json.md | 66 +++++++++++ ext/VERSION | 2 +- src/host/json.rs | 109 +++++++++++++++++- tests/gold.rs | 87 ++++++++++++++ tests/lib/foreign-session-vsafe-refuse.mq.md | 13 +++ .../lib/foreign-vsafe-postarith-refuse.mq.md | 24 ++++ tests/lib/foreign-vsafe-refuse.mq.md | 23 ++++ tests/lib/foreign-vsafe-string-ok.mq.md | 24 ++++ tests/lib/json-vsafe-max-safe-ok.mq.md | 15 +++ tests/lib/json-vsafe-refuse.mq.md | 12 ++ tests/lib/json-vsafe-string-ok.mq.md | 13 +++ tests/lib/json-vsafe-stringify-refuse.mq.md | 13 +++ 21 files changed, 449 insertions(+), 17 deletions(-) create mode 100644 doc/design/v-safe-json.md create mode 100644 tests/lib/foreign-session-vsafe-refuse.mq.md create mode 100644 tests/lib/foreign-vsafe-postarith-refuse.mq.md create mode 100644 tests/lib/foreign-vsafe-refuse.mq.md create mode 100644 tests/lib/foreign-vsafe-string-ok.mq.md create mode 100644 tests/lib/json-vsafe-max-safe-ok.mq.md create mode 100644 tests/lib/json-vsafe-refuse.mq.md create mode 100644 tests/lib/json-vsafe-string-ok.mq.md create mode 100644 tests/lib/json-vsafe-stringify-refuse.mq.md diff --git a/.cursor/skills/marqdo/SKILL.md b/.cursor/skills/marqdo/SKILL.md index 5a4b6e8..f16b29b 100644 --- a/.cursor/skills/marqdo/SKILL.md +++ b/.cursor/skills/marqdo/SKILL.md @@ -221,7 +221,7 @@ Design: [ext-quantum.md](../../doc/design/ext-quantum.md) · Q7: [ext-quantum-q7 - `invoke` returns a record (`ok`, `code`, `stdout`, `stderr`, `ms`, `timed_out`, `truncated`, `result`); pass `input` for JSON stdin and `output="json"` for a parsed result. - `call` is JSON-in / JSON-out; `call_many` fans out one program over a list with ordered results. -- `session_open` starts a persistent Python/Node kernel; `session_eval` evaluates source; `session_set` / `session_get` bridge values explicitly as JSON. Close it with `session_close`. +- `session_open` starts a persistent Python/Node kernel; `session_eval` evaluates source; `session_set` / `session_get` bridge values explicitly as JSON. Close it with `session_close`. JSON integers outside \(\pm(2^{53}-1)\) are refused (`json: integer outside V_safe`); use a decimal string + host `BigInt` for wider ints (`doc/design/v-safe-json.md`). - A view document opts into kernel state with `会话 = > foreign.session kernels=... cells=...`; the table names are free. `view` consumes only the `会话` handle and never scans source lines or reserved table names. Without `会话`, cells are stateless one-shot runs; no kernel is created. Clearing outputs calls `/api/session/clear` and keeps persistent kernel state. There is no separate notebook CLI mode or command, and no new Markdown marker exists. - The same source remains the authority; state crossing kernels is explicit, never implicitly mirrored. diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2e7ccb2..f232739 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -126,6 +126,9 @@ jobs: ## Marqdo ${{ github.ref_name }} ### 亮点 / Highlights + - **v2.2.2**:\(V_{\mathsf{safe}}\) JSON 整数——外联/`json` 拒绝域外整数,禁止静默扭曲;宽整数用十进制字符串 + - **v2.2.2**: \(V_{\mathsf{safe}}\) JSON integers — foreign/`json` refuse OOD ints (no silent distortion); wide ints via decimal strings + - **v2.2.2 ext**:扩展包同步 2.2.2 / Ext pack 2.2.2 - **v2.2.1**:view / 静态导出——修复 occlusion 与中等宽度下大纲侧栏掉到正文下方 - **v2.2.1**: view / static export — fix outline rail nested under document (occlusion + mid-width layout) - **v2.2.1 ext**:扩展包同步 2.2.1 / Ext pack 2.2.1 diff --git a/CHANGELOG.md b/CHANGELOG.md index 508580a..ce9467a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,28 @@ ### Changed +## v2.2.2 — 2026-11-01 + +### Highlights + +**\(V_{\mathsf{safe}}\) JSON 整数契约落地**:外联 / `json.parse` / `json.stringify` / `session_set` 等共用映射对齐 Lean ForeignJSON——`|n| > 2^{53}-1` 的 JSON 整数显式拒绝(错误前缀 `json: integer outside V_safe`),禁止 Node 路径静默扭曲;宽整数仍用十进制字符串 + 对端 `BigInt`。CLI · wasm · ext **2.2.2**。 + +**核心表面 Δ(Core surface Δ)**:**无增删**(仍 19 个构造)——宿主 JSON 契约与测试,不改 Markdown 标记。 + +### Added + +- **`doc/design/v-safe-json.md`**:宿主 ↔ Lean \(V_{\mathsf{safe}}\) 契约锁定(`MAX_SAFE`、encode/decode refuse、嵌套、float 为宿主扩展)。 +- **回归**:`tests/lib/json-vsafe-*`、`foreign-vsafe-*`、`foreign-session-vsafe-refuse`(含算术后越界 refuse)。 + +### Fixed + +- **`src/host/json.rs`**:对域外整数与 `u64 > i64::MAX` 显式失败;不再经 `f64`/`Text` 静默降级。 +- **`doc/design/foreign-kernel.md`**:Int→number 仅当 `|n| ≤ 2^{53}-1`;宽整数走 string 桥。 + +### Changed + +- 外联 JSON 桥与 `lib/json` 行为:OOD 整数从「可能静默失真」改为「诊断失败」。 + ## v2.2.1 — 2026-10-30 ### Highlights diff --git a/Cargo.lock b/Cargo.lock index e3e37a3..f36e6fb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -572,7 +572,7 @@ checksum = "0ceec5bc11778974d1bcb055b18002eba7f4b3518b6a0081b3af5f21666da9ad" [[package]] name = "marqdo" -version = "2.2.1" +version = "2.2.2" dependencies = [ "anyhow", "assert_cmd", @@ -611,7 +611,7 @@ dependencies = [ [[package]] name = "marqdo-wasm" -version = "2.2.1" +version = "2.2.2" dependencies = [ "marqdo", "serde_json", diff --git a/Cargo.toml b/Cargo.toml index 62f00d1..e044fa9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "marqdo" -version = "2.2.1" +version = "2.2.2" edition = "2021" license = "Apache-2.0" description = "Marqdo — Markdown markers as an interpreted programming language" diff --git a/README.md b/README.md index e68dc91..b7d2c68 100644 --- a/README.md +++ b/README.md @@ -284,8 +284,9 @@ marqdo catalog public -o .marqdo --- -## 现状(v2.2.1) +## 现状(v2.2.2) +- **\(V_{\mathsf{safe}}\) JSON 整数(v2.2.2)**:外联与 `lib/json` 拒绝 `|n| > 2^{53}-1` 的 JSON 整数(对齐 Lean ForeignJSON);宽整数用十进制字符串 + Node `BigInt`。扩展包同步 **2.2.2** - **view 大纲侧栏(v2.2.1)**:修复 occlusion 文档与中等宽度下 Functions / Variables 掉到正文下方的问题;静态 `view output` 同源。 - **函数级调用(v2.2.0)**:`marqdo call <文件.mq.md> <函数> 名字=值`。同一份文档给人读,也按函数执行;Tree 与 Bytecode 都跑被点名的函数,不回退到 `# main`。默认只执行纯函数。`--json` 给 Agent 读取结果或诊断。说明与价值见 [22-函数调用](public/features/22-函数调用.mq.md)。示例:`marqdo call examples/calculator.mq.md 计算器.加法 a=2 b=3` → `5`。扩展包同步 **2.2.1** - **Agent 可靠工作台(v2.1.5)**:ResourceView(JSON/CSV/PDF/image)· ToolSpec 授权先于调用 · CheckpointV2 / EffectLedger / ContextPackV2 · EKC `ir.json` 暖机与 `--refresh` · Web 短读/控制与 execute 槽隔离;扩展包同步 **2.1.5** @@ -330,7 +331,7 @@ marqdo catalog public -o .marqdo - **浏览器 Marqdo(WASM)**:`marqdo wasm build` + 官方 bridge 自启(作者零业务 JS;桥内可含列表/路由/storage/ws/文件/Canvas/音频/Observer/拖放);`lib/browser` + GFM;`web.client_embed`;示例 [browser-hello](examples/browser-hello/) · [browser-app](examples/browser-app/) · [browser-media](examples/browser-media/) · [web-client-site](examples/web-client-site/)([ADR 0002](doc/adr/0002-browser-marqdo-wasm.md) · [D](doc/roadmap/browser-wasm-d.md) · [E](doc/roadmap/browser-wasm-e.md) · [F](doc/roadmap/browser-wasm-f.md)) - 选型:[ADR 0001 — Rust](doc/adr/0001-implementation-language.md) · [ADR 0002 — 浏览器 WASM](doc/adr/0002-browser-marqdo-wasm.md)(C0–C5 完结,见 [roadmap/browser-wasm.md](doc/roadmap/browser-wasm.md))· [ADR 0003 — 异步效应](doc/adr/0003-browser-async-effects.md) -### 如何使用最新 Marqdo(v2.2.1) +### 如何使用最新 Marqdo(v2.2.2) **安装解释器(任选其一)** @@ -345,7 +346,7 @@ marqdo catalog public -o .marqdo ```bash # 1) 源码安装(跟 tag 或 main) git clone https://github.com/cflmy/marqdo.git && cd marqdo -git checkout v2.2.1 # 或留在 main +git checkout v2.2.2 # 或留在 main cargo build --release export PATH="$PWD/target/release:$PATH" marqdo version @@ -386,7 +387,7 @@ marqdo wasm build # → dist/wasm/ … 见 examples/browser-hello/ # 6) Releases:Windows exe/zip/vsix;Linux CLI zip + native `.so` zip -# https://github.com/cflmy/marqdo/releases/tag/v2.2.1 +# https://github.com/cflmy/marqdo/releases/tag/v2.2.2 ``` 开发期也可用 `cargo run -- …` 代替已安装的 `marqdo`: diff --git a/crates/marqdo-wasm/Cargo.toml b/crates/marqdo-wasm/Cargo.toml index 45bef61..a37bcff 100644 --- a/crates/marqdo-wasm/Cargo.toml +++ b/crates/marqdo-wasm/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "marqdo-wasm" -version = "2.2.1" +version = "2.2.2" edition = "2021" license = "Apache-2.0" description = "Marqdo interpreter as WebAssembly (browser host bridge)" diff --git a/debian/changelog b/debian/changelog index d36f1aa..d27bfd5 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +marqdo (2.2.2-1ppa1) noble; urgency=medium + + * Marqdo 2.2.2: V_safe JSON integer contract on foreign/json bridge — + refuse integers outside +/- (2^53-1); wide ints via decimal string. + + -- Marqdo Maintainers Sat, 01 Nov 2026 09:45:00 +0800 + marqdo (2.2.1-1ppa1) noble; urgency=medium * Marqdo 2.2.1: fix view/static-export outline rail under document diff --git a/doc/design/foreign-kernel.md b/doc/design/foreign-kernel.md index 224fcf9..e8ee6fa 100644 --- a/doc/design/foreign-kernel.md +++ b/doc/design/foreign-kernel.md @@ -214,19 +214,23 @@ template = ["php", "-r", "{inline}"] ### 4.1 值映射 +Canonical integer contract: [`v-safe-json.md`](v-safe-json.md) (Lean \(V_{\mathsf{safe}}\): `|n| ≤ 2^{53}-1`). + | Marqdo | JSON | |---|---| | None | null | | Bool | bool | -| Int | number | -| Num | number(NaN/Inf → null) | -| Text | string | -| List | array | -| Map | object | +| Int | number **仅当** `|n| ≤ 2^{53}-1`;越界 → 显式失败(禁止静默扭曲) | +| Num | number(NaN/Inf → null);float 为宿主扩展,∉ mechanized \(V_{\mathsf{safe}}\) | +| Text | string(宽整数用十进制字符串过桥,对端 `BigInt` / Python `int`) | +| List | array(子树递归;任一越界整数使整体失败) | +| Map | object(同上) | | Formula | 矩阵 → 二维数组;其它 → 数字或字符串 | | Code | 源码字符串 | | Secret | JSON 中 ``;`env` 显式交付时取真实值 | +错误前缀:`json: integer outside V_safe (±(2^53-1)): `。 + ### 4.2 输入 - `input=` → JSON;写 stdin;同时提供 `MARQDO_INPUT`(≤8 KiB)与 `MARQDO_INPUT_FILE`(任意大小)。 diff --git a/doc/design/v-safe-json.md b/doc/design/v-safe-json.md new file mode 100644 index 0000000..632413f --- /dev/null +++ b/doc/design/v-safe-json.md @@ -0,0 +1,66 @@ +# \(V_{\mathsf{safe}}\) JSON integer contract (host ↔ Lean) + +Canonical Lean model: `MarqdoThesis/PLDI/proofs/MarqdoProof/MarqdoProof/ForeignJSON.lean`. +Host mapper: `src/host/json.rs` (`json_to_value` / `value_to_json`). + +This document freezes **runtime conformance** of the Marqdo JSON bridge to the +mechanized \(V_{\mathsf{safe}}\) integer domain. It is **not** a verified +compilation of the Rust interpreter. + +## Domain + +``` +MAX_SAFE = 9007199254740991 # 2^53 - 1 +``` + +\(V_{\mathsf{safe}}\) values (mechanized): + +| JSON | Marqdo | +|---|---| +| `null` | `None` | +| `bool` | `Bool` | +| integer with `\|n\| ≤ MAX_SAFE` | `Int` | +| `string` | `Text` | +| `array` | `List` | +| `object` | `Map` | + +**Host extension (not in Lean `SafeVal`):** JSON non-integer numbers → `Value::Num(f64)` (NaN/Inf encode as `null`). Floats are documented host behavior; they are **not** claimed as mechanized \(V_{\mathsf{safe}}\) fidelity. + +## Encode (`value_to_json`) + +- `Value::Int(n)` with `|n| ≤ MAX_SAFE` → JSON number. +- `Value::Int(n)` with `|n| > MAX_SAFE` → **refuse** (error). +- Nested `List` / `Map`: any child refuse fails the whole tree. +- Wide integers that must cross a language boundary: author converts to a + **decimal string** (∈ \(V_{\mathsf{safe}}\)); the foreign program may use + `BigInt` / Python `int` on that string. + +## Decode (`json_to_value`) + +- JSON integer with `|n| ≤ MAX_SAFE` → `Int`. +- JSON integer with `|n| > MAX_SAFE` → **refuse**. +- JSON unsigned integer `> i64::MAX` → **refuse** (do **not** coerce via `f64` or `Text`). +- Nested array/object: any child refuse fails the whole tree. +- Decimal-string encodings of wide integers → `Text` (in domain). + +## Error prefix + +All refuse messages use a fixed prefix for probes and diagnostics: + +``` +json: integer outside V_safe (±(2^53-1)): +``` + +## In-domain roundtrip + +`±MAX_SAFE`, bool, null, string, array, and object roundtrips through +`encode → decode` must succeed. Integers `MAX_SAFE+1`, `-MAX_SAFE-1`, `2^53`, +`2^60`, `2^60+1` (and nested forms) must refuse. + +## Non-claims + +- Not verified Rust ↔ Lean compilation. +- Not arbitrary host-object fidelity (DataFrame, functions, heap sharing). +- Not automatic BigInt promotion inside Node/Python bootstraps. +- Document-level `Value::Int` may still hold i64 values that are OOD for JSON; + the gate fires when those values enter JSON encode/decode. diff --git a/ext/VERSION b/ext/VERSION index c043eea..b1b25a5 100644 --- a/ext/VERSION +++ b/ext/VERSION @@ -1 +1 @@ -2.2.1 +2.2.2 diff --git a/src/host/json.rs b/src/host/json.rs index f382f07..9e8c07e 100644 --- a/src/host/json.rs +++ b/src/host/json.rs @@ -1,7 +1,21 @@ //! JSON host primitives + Value↔JSON mapping. +//! +//! Integer gate matches Lean \(V_{\mathsf{safe}}\) (`doc/design/v-safe-json.md`): +//! JSON integers with `|n| > 2^53-1` refuse on encode and decode. use crate::value::Value; +/// JavaScript `Number.MAX_SAFE_INTEGER` / Lean `ForeignJSON.maxSafe`. +pub const MAX_SAFE_INT: i64 = 9_007_199_254_740_991; // 2^53 - 1 + +pub fn in_safe_int(n: i64) -> bool { + (-MAX_SAFE_INT..=MAX_SAFE_INT).contains(&n) +} + +fn ood_int_err(n: impl std::fmt::Display) -> String { + format!("json: integer outside V_safe (±(2^53-1)): {n}") +} + pub fn parse(text: &Value) -> Result { let s = match text { Value::Text(s) => s.as_str(), @@ -70,11 +84,18 @@ pub(crate) fn json_to_value(v: &serde_json::Value) -> Result { serde_json::Value::Bool(b) => Value::Bool(*b), serde_json::Value::Number(n) => { if let Some(i) = n.as_i64() { + if !in_safe_int(i) { + return Err(ood_int_err(i)); + } Value::Int(i) + } else if let Some(u) = n.as_u64() { + // Always > i64::MAX ⇒ outside V_safe; never coerce via f64/Text. + return Err(ood_int_err(u)); } else if let Some(f) = n.as_f64() { + // Host extension: non-integer JSON numbers → Num (not in Lean SafeVal). Value::Num(f) } else { - Value::Text(n.to_string()) + return Err(format!("json: unsupported number: {n}")); } } serde_json::Value::String(s) => Value::Text(s.clone()), @@ -99,7 +120,12 @@ pub(crate) fn value_to_json(v: &Value) -> Result { Ok(match v { Value::None => serde_json::Value::Null, Value::Bool(b) => serde_json::Value::Bool(*b), - Value::Int(n) => serde_json::Value::Number((*n).into()), + Value::Int(n) => { + if !in_safe_int(*n) { + return Err(ood_int_err(*n)); + } + serde_json::Value::Number((*n).into()) + } Value::Num(n) => serde_json::Number::from_f64(*n) .map(serde_json::Value::Number) .unwrap_or(serde_json::Value::Null), @@ -159,4 +185,83 @@ mod tests { let q = quote(&Value::Text("a\"b".into())).unwrap(); assert_eq!(q, Value::Text("\"a\\\"b\"".into())); } + + #[test] + fn roundtrip_max_safe() { + for n in [MAX_SAFE_INT, -MAX_SAFE_INT, 0_i64, 1, -1] { + let j = value_to_json(&Value::Int(n)).unwrap(); + let v = json_to_value(&j).unwrap(); + assert_eq!(v, Value::Int(n)); + } + } + + #[test] + fn refuse_ood_encode() { + for n in [ + MAX_SAFE_INT + 1, + -MAX_SAFE_INT - 1, + 1_i64 << 53, // 2^53 + 1_i64 << 60, // 2^60 + (1_i64 << 60) + 1, // 2^60+1 + ] { + let err = value_to_json(&Value::Int(n)).unwrap_err(); + assert!( + err.contains("outside V_safe"), + "encode {n}: {err}" + ); + } + } + + #[test] + fn refuse_ood_decode() { + for n in [ + MAX_SAFE_INT + 1, + -MAX_SAFE_INT - 1, + 1_i64 << 53, + 1_i64 << 60, + (1_i64 << 60) + 1, + ] { + let raw = format!("{n}"); + let j: serde_json::Value = serde_json::from_str(&raw).unwrap(); + let err = json_to_value(&j).unwrap_err(); + assert!( + err.contains("outside V_safe"), + "decode {n}: {err}" + ); + } + } + + #[test] + fn refuse_nested_ood() { + let j: serde_json::Value = + serde_json::from_str("{\"a\":[1152921504606846977]}").unwrap(); + let err = json_to_value(&j).unwrap_err(); + assert!(err.contains("outside V_safe"), "{err}"); + } + + #[test] + fn decimal_string_ok() { + let j = serde_json::Value::String("1152921504606846977".into()); + assert_eq!( + json_to_value(&j).unwrap(), + Value::Text("1152921504606846977".into()) + ); + } + + #[test] + fn float_host_extension_ok() { + let j: serde_json::Value = serde_json::from_str("1.5").unwrap(); + match json_to_value(&j).unwrap() { + Value::Num(f) => assert!((f - 1.5).abs() < 1e-12), + other => panic!("expected Num, got {other:?}"), + } + } + + #[test] + fn refuse_u64_above_i64_max() { + // 2^63 as JSON integer: as_i64 fails, as_u64 succeeds. + let j: serde_json::Value = serde_json::from_str("9223372036854775808").unwrap(); + let err = json_to_value(&j).unwrap_err(); + assert!(err.contains("outside V_safe"), "{err}"); + } } diff --git a/tests/gold.rs b/tests/gold.rs index 5d63696..406c7b7 100644 --- a/tests/gold.rs +++ b/tests/gold.rs @@ -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( diff --git a/tests/lib/foreign-session-vsafe-refuse.mq.md b/tests/lib/foreign-session-vsafe-refuse.mq.md new file mode 100644 index 0000000..5786e9c --- /dev/null +++ b/tests/lib/foreign-session-vsafe-refuse.mq.md @@ -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`** diff --git a/tests/lib/foreign-vsafe-postarith-refuse.mq.md b/tests/lib/foreign-vsafe-postarith-refuse.mq.md new file mode 100644 index 0000000..ef4f4b4 --- /dev/null +++ b/tests/lib/foreign-vsafe-postarith-refuse.mq.md @@ -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`** diff --git a/tests/lib/foreign-vsafe-refuse.mq.md b/tests/lib/foreign-vsafe-refuse.mq.md new file mode 100644 index 0000000..3389e44 --- /dev/null +++ b/tests/lib/foreign-vsafe-refuse.mq.md @@ -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`** diff --git a/tests/lib/foreign-vsafe-string-ok.mq.md b/tests/lib/foreign-vsafe-string-ok.mq.md new file mode 100644 index 0000000..e5e1381 --- /dev/null +++ b/tests/lib/foreign-vsafe-string-ok.mq.md @@ -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`** diff --git a/tests/lib/json-vsafe-max-safe-ok.mq.md b/tests/lib/json-vsafe-max-safe-ok.mq.md new file mode 100644 index 0000000..e73f1a7 --- /dev/null +++ b/tests/lib/json-vsafe-max-safe-ok.mq.md @@ -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` diff --git a/tests/lib/json-vsafe-refuse.mq.md b/tests/lib/json-vsafe-refuse.mq.md new file mode 100644 index 0000000..e3dd520 --- /dev/null +++ b/tests/lib/json-vsafe-refuse.mq.md @@ -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` diff --git a/tests/lib/json-vsafe-string-ok.mq.md b/tests/lib/json-vsafe-string-ok.mq.md new file mode 100644 index 0000000..b7a5e0d --- /dev/null +++ b/tests/lib/json-vsafe-string-ok.mq.md @@ -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` diff --git a/tests/lib/json-vsafe-stringify-refuse.mq.md b/tests/lib/json-vsafe-stringify-refuse.mq.md new file mode 100644 index 0000000..a17b030 --- /dev/null +++ b/tests/lib/json-vsafe-stringify-refuse.mq.md @@ -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`