Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
82c8d78fd3 | ||
|
|
58791fc7d9 |
No files matched your search
@@ -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.
|
||||
|
||||
|
||||
@@ -126,6 +126,12 @@ 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
|
||||
- **v2.2.0**:函数级调用 `marqdo call`——同一份 .mq.md 就是文档、知识和工具;Tree/Bytecode 执行被点名的函数;外部调用默认只跑纯函数
|
||||
- **v2.2.0**: `marqdo call` runs one function in any .mq.md — the file is the document, the knowledge and the tool; Tree and Bytecode execute that function; external calls stay pure
|
||||
- **v2.2.0 ext**:扩展包同步 2.2.0 / Ext pack 2.2.0
|
||||
|
||||
@@ -8,6 +8,41 @@
|
||||
|
||||
### 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
|
||||
|
||||
**view / 静态导出大纲侧栏修复**:带遮蔽(occlusion)语句的文档页里,Functions / Variables 右侧栏会掉到正文下面;中等窗口宽度下也会被错误叠成单列。CLI · wasm · ext **2.2.1**。
|
||||
|
||||
**核心表面 Δ(Core surface Δ)**:**无增删**(仍 19 个构造)——布局与 HTML 闭合修复,不改 Markdown 标记。
|
||||
|
||||
### Fixed
|
||||
|
||||
- **`marqdo view` / `view output`**:occlusion 行提前返回时未关闭 `.doc-block`,把 `#outline-rail` 嵌进 `document-surface`,侧栏排到文档下方;现已闭合并保留标注带。
|
||||
- **view 壳 CSS**:大纲折叠改为按主栏 `@container mq-panel` 宽度(32rem),不再用视口 `960px` 媒体查询把右侧栏压到正文下;极窄时大纲上移到文档上方。
|
||||
|
||||
## v2.2.0 — 2026-10-30
|
||||
|
||||
### Highlights
|
||||
|
||||
Generated
+2
-2
@@ -572,7 +572,7 @@ checksum = "0ceec5bc11778974d1bcb055b18002eba7f4b3518b6a0081b3af5f21666da9ad"
|
||||
|
||||
[[package]]
|
||||
name = "marqdo"
|
||||
version = "2.2.0"
|
||||
version = "2.2.2"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"assert_cmd",
|
||||
@@ -611,7 +611,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "marqdo-wasm"
|
||||
version = "2.2.0"
|
||||
version = "2.2.2"
|
||||
dependencies = [
|
||||
"marqdo",
|
||||
"serde_json",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "marqdo"
|
||||
version = "2.2.0"
|
||||
version = "2.2.2"
|
||||
edition = "2021"
|
||||
license = "Apache-2.0"
|
||||
description = "Marqdo — Markdown markers as an interpreted programming language"
|
||||
|
||||
@@ -284,9 +284,11 @@ marqdo catalog public -o .marqdo
|
||||
|
||||
---
|
||||
|
||||
## 现状(v2.2.0)
|
||||
## 现状(v2.2.2)
|
||||
|
||||
- **函数级调用(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.0**
|
||||
- **\(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**
|
||||
- **默认隔离 HTTP execute(v2.1.4 · ADR 0009)**:`execute` / `sse-live` / `stream:true` → Supervisor worker 池(`--call-lib-path`);父进程不再占 `INVOKE_LOCK`;`/_runtime/*`;`runtime.isolated_execution=1`;MR-01 金样例
|
||||
- **知识工作台运行时(v2.1.3)**:ModelSelection / RunContext / usage null≠0 · `view document` 只读嵌入 · LLM selection/messages/cancel · agent.step selection e2e · live smoke(设计 Partial:原生适配器 unavailable)
|
||||
@@ -329,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.0)
|
||||
### 如何使用最新 Marqdo(v2.2.2)
|
||||
|
||||
**安装解释器(任选其一)**
|
||||
|
||||
@@ -344,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.0 # 或留在 main
|
||||
git checkout v2.2.2 # 或留在 main
|
||||
cargo build --release
|
||||
export PATH="$PWD/target/release:$PATH"
|
||||
marqdo version
|
||||
@@ -385,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.0
|
||||
# https://github.com/cflmy/marqdo/releases/tag/v2.2.2
|
||||
```
|
||||
|
||||
开发期也可用 `cargo run -- …` 代替已安装的 `marqdo`:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "marqdo-wasm"
|
||||
version = "2.2.0"
|
||||
version = "2.2.2"
|
||||
edition = "2021"
|
||||
license = "Apache-2.0"
|
||||
description = "Marqdo interpreter as WebAssembly (browser host bridge)"
|
||||
|
||||
Vendored
+14
@@ -1,3 +1,17 @@
|
||||
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 <noreply@marqdo.com> 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
|
||||
(occlusion doc-block close + panel container query layout).
|
||||
|
||||
-- Marqdo Maintainers <noreply@marqdo.com> Fri, 30 Oct 2026 11:45:00 +0800
|
||||
|
||||
marqdo (2.2.0-1ppa1) noble; urgency=medium
|
||||
|
||||
* Marqdo 2.2.0: marqdo call runs one named function in any .mq.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 中 `<secret>`;`env` 显式交付时取真实值 |
|
||||
|
||||
错误前缀:`json: integer outside V_safe (±(2^53-1)): <n>`。
|
||||
|
||||
### 4.2 输入
|
||||
|
||||
- `input=` → JSON;写 stdin;同时提供 `MARQDO_INPUT`(≤8 KiB)与 `MARQDO_INPUT_FILE`(任意大小)。
|
||||
|
||||
@@ -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)): <n>
|
||||
```
|
||||
|
||||
## 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.
|
||||
+1
-1
@@ -1 +1 @@
|
||||
2.2.0
|
||||
2.2.2
|
||||
+107
-2
@@ -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<Value, String> {
|
||||
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<Value, String> {
|
||||
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<serde_json::Value, String> {
|
||||
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}");
|
||||
}
|
||||
}
|
||||
@@ -916,6 +916,17 @@ fn render_line_block(
|
||||
if let Some(body) = writeback_body {
|
||||
s.push_str(&crate::view::render::render_output_card(line_no, body));
|
||||
}
|
||||
// Must close `.doc-block` — an early return left the wrapper open and
|
||||
// nested the Functions/Variables outline under the document surface.
|
||||
let band_annots: Vec<ViewAnnot> = annots
|
||||
.iter()
|
||||
.filter(|a| !is_noisy_result_chip(a))
|
||||
.map(|a| (*a).clone())
|
||||
.collect();
|
||||
if !band_annots.is_empty() {
|
||||
s.push_str(&render_annot_band(&band_annots, MAX_VISIBLE_ANNOTS));
|
||||
}
|
||||
s.push_str("</div>");
|
||||
return s;
|
||||
}
|
||||
if bits.is_empty() {
|
||||
@@ -1545,6 +1556,52 @@ When we meet `who`, we **print text="Hi, `who`!"** and close with*None*.
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod occl_render_tests {
|
||||
use super::render_module_document;
|
||||
|
||||
fn div_balance(html: &str) -> i32 {
|
||||
let mut depth = 0i32;
|
||||
let b = html.as_bytes();
|
||||
let mut i = 0usize;
|
||||
while i + 3 < b.len() {
|
||||
if b[i] == b'<' {
|
||||
if i + 4 <= b.len() && &b[i..i + 4] == b"<div" && (b.get(i + 4) == Some(&b' ') || b.get(i + 4) == Some(&b'>')) {
|
||||
depth += 1;
|
||||
} else if i + 6 <= b.len() && &b[i..i + 6] == b"</div>" {
|
||||
depth -= 1;
|
||||
}
|
||||
}
|
||||
i += 1;
|
||||
}
|
||||
depth
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn occlusion_line_closes_doc_block() {
|
||||
let src = r#"---
|
||||
markup: occlusion
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
`v` = [描述](1)
|
||||
"#;
|
||||
let module = crate::parse::parse_source(src).unwrap();
|
||||
let html = render_module_document(&module, src, &[]);
|
||||
assert!(html.contains("doc-occl"), "{html}");
|
||||
assert_eq!(
|
||||
div_balance(&html),
|
||||
0,
|
||||
"occlusion must not leave .doc-block open: {html}"
|
||||
);
|
||||
assert!(
|
||||
html.contains("doc-occl") && html.contains("</div></div>"),
|
||||
"doc-block around occlusion must close: {html}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod occl_split_tests {
|
||||
use super::split_occlusion;
|
||||
|
||||
+34
-2
@@ -237,6 +237,11 @@ a:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
|
||||
min-width: 0;
|
||||
overflow: auto;
|
||||
background: var(--bg);
|
||||
/* Content-pane width (excludes file nav) drives outline stacking — not the
|
||||
* viewport. A 960px viewport media query wrongly put Functions/Variables
|
||||
* under a tall Structure while the left nav was still visible. */
|
||||
container-type: inline-size;
|
||||
container-name: mq-panel;
|
||||
}
|
||||
main.panel {
|
||||
padding: 2rem 2.25rem 3.5rem;
|
||||
@@ -719,9 +724,17 @@ body.notebook-page .exec-clear:hover { border-color: var(--nb-accent); color: va
|
||||
gap: 0.75rem;
|
||||
align-items: start;
|
||||
}
|
||||
@media (max-width: 960px) {
|
||||
/* Stack only when the *panel* is too narrow for Structure + outline rail.
|
||||
* Prefer keeping the rail beside the doc at tablet widths (matches ≤800px
|
||||
* shell collapse in doc/design/view.md). When stacked, pull the rail above
|
||||
* so it is not buried under a long document. */
|
||||
@container mq-panel (max-width: 32rem) {
|
||||
.struct-wrap { grid-template-columns: 1fr; }
|
||||
.outline-rail, .outline-panel { position: static; }
|
||||
.outline-rail {
|
||||
order: -1;
|
||||
position: static;
|
||||
}
|
||||
.outline-panel { position: static; }
|
||||
}
|
||||
.outline-rail {
|
||||
position: sticky;
|
||||
@@ -4527,6 +4540,25 @@ mod plan_card_tests {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn outline_rail_stacks_by_panel_container_not_960_viewport() {
|
||||
let css = stylesheet();
|
||||
assert!(
|
||||
css.contains("container-name: mq-panel"),
|
||||
"panel-wrap should be a size container for outline layout"
|
||||
);
|
||||
assert!(
|
||||
css.contains("@container mq-panel (max-width: 32rem)"),
|
||||
"outline must stack from panel width, not a mid-width viewport media query"
|
||||
);
|
||||
assert!(
|
||||
!css.contains("@media (max-width: 960px) {\n .struct-wrap"),
|
||||
"960px viewport media wrongly buried the outline under Structure"
|
||||
);
|
||||
let html = layout("t", "<p>nav</p>", "<p>main</p>");
|
||||
assert!(html.contains("container-name: mq-panel"), "{html}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn notebook_ui_has_controls() {
|
||||
let ui = notebook_ui();
|
||||
|
||||
@@ -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`**
|
||||
@@ -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`**
|
||||
@@ -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`**
|
||||
@@ -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`
|
||||
@@ -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`
|
||||
@@ -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`
|
||||
Reference in new issue
Block a user