feat(migrate): M7 迁移与版本门 — per-file markup + migrate labels + 全仓迁移

原计划的"翻转默认 + 旧形硬报错"不可行:`[键](集合)` 与 `[描述](实现)` 外形相同,
翻转会让 506 处取元静默变义,硬报错又拿不到证据。改为**按文件声明**。

一、per-file markup
- frontmatter `markup: occlusion`(或 `标记: 遮蔽`)决定该文件模式
- load.rs 先取模式,用 parse::expr::with_markup(线程局部压栈)包住解析
- 同一进程可同时加载两种模式的文件(imports);MARQDO_MARKUP 仍作进程默认
- 好处:迁移逐文件、可增量、可回滚,不存在半迁移的静默错义

二、`marqdo migrate labels [--write|--json]`
改写规则:
  [键](集合)      → [键](access(集合, "键"))
  [`名`](集合)    → [名](access(集合, `名`))
  - [项](集合)    → - [项](遍历 集合 为 项)

安全模型:改写 → 重解析 → 证明等价 → 才写
- 原文件按 classic 解析得 AST-A;改写后按 occlusion 解析得 AST-B
- 反归一化 B(标签与键同名且 payload 为 access 的遮蔽还原成 Index)
- Debug(A) == Debug(反归一化(B))(抹掉行号)才写入,否则原文件一字不动

只改代码行(LineKind::Code);表格行只改 **…** 单元格,散文 markdown 链接不碰;
链式索引由内向外改写,已迁移的有守卫不二次改。

三、access 提升为宿主函数 HostFn::Access(u16 id 212)
与旧取元逐字一致(Map 按键 / List 1-based / 缺键 missing map key);
进 HostFn 是为了两个后端共用同一实现,interp 里的特例已删除。

四、顺带修的两处真实语义缺陷
1. payload 继承外层"文本模式":`f text=[k](access(c,k))` 中 access 不被当调用
   → `()` 内永远允许 callee(args)
2. 遮蔽形状判定过宽:`[问候] ([格式化] "Bo")` 误判为遮蔽
   → 要求 `]` 后紧跟 `(`,否则落回方括号调用

五、全仓迁移结果
migrate labels: 256 index, 23 loop, 80 file written;0 文件被等价性拒绝;
迁移后 cargo test --release → 604 passed / 0 failed;再跑迁移幂等。

等价性检查先后抓出 4 类改写 bug(表格散文链接、payload 文本模式、链式索引、
遮蔽与方括号调用混淆),每类都是先拦下再修工具,未污染文件。

测试:6 个单测 + 3 个集成(干跑不写盘 / 写入后运行输出不变且幂等 /
等价失败文件不动);全量 604 passed / 0 failed(M3 后 595 + 9);双后端一致。

文档:doc/design/change-m7-migration.md
This commit is contained in:
cflmy committed 2026-10-22 15:33:31 +08:00
1 parent 9dbcc728b6
commit 4488a3cb70
98 files changed
+1354 -278

No files matched your search

+4 -3
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: promote requires sandbox proof (O2)
description: >
Good workbook promotes; broken workbook is rejected (sandbox_proof_failed).
@@ -25,11 +26,11 @@ import sys:lib/sys.mq.md
**_ = 0**
**prom = agent_kb_promote kb_dir=`kb` goal="sandbox promote good" workbook="sandbox-fixtures/promote-good.mq.md"**
**ok = [promoted](prom)**
**ok = [promoted](access(prom, "promoted"))**
> print text=`ok`
**rej = agent_kb_promote kb_dir=`kb` goal="sandbox promote bad" workbook="sandbox-fixtures/promote-bad.mq.md"**
**rej_ok = [promoted](rej)**
**reason = [reason](rej)**
**rej_ok = [promoted](access(rej, "promoted"))**
**reason = [reason](access(rej, "reason"))**
> print text=`rej_ok`
> print text=`reason`
+5 -4
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: O5 quarantine skill status
description: Promote good skill then quarantine — status becomes quarantine.
import plugin:lib/plugin.mq.md
@@ -23,12 +24,12 @@ import sys:lib/sys.mq.md
**_ = 0**
**prom = agent_kb_promote kb_dir=`kb` goal="quarantine demo" workbook="sandbox-fixtures/promote-good.mq.md"**
**ok = [promoted](prom)**
**slug = [slug](prom)**
**ok = [promoted](access(prom, "promoted"))**
**slug = [slug](access(prom, "slug"))**
> print text=`ok`
**q = agent_kb_quarantine kb_dir=`kb` slug=`slug` reason="fixture_regression"**
**qok = [ok](q)**
**st = [status](q)**
**qok = [ok](access(q, "ok"))**
**st = [status](access(q, "status"))**
> print text=`qok`
> print text=`st`
+5 -4
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: table sort_by + cli
import table:lib/table.mq.md
import csv:lib/csv.mq.md
@@ -11,12 +12,12 @@ import cli:lib/cli.mq.md
**rows = > csv.parse text=`raw`**
**rows = > table.sort_by list=`rows` key="name"**
**r0 = > at value=`rows` index=0**
> print text=[name](`r0`)
> print text=[name](access(`r0`, "name"))
**args = > split value="--input,data.csv,rest,--verbose" sep=","**
**flags = > cli.parse args=`args`**
> print text=[input](`flags`)
> print text=[verbose](`flags`)
**pos = [_](`flags`)**
> print text=[input](access(`flags`, "input"))
> print text=[verbose](access(`flags`, "verbose"))
**pos = [_](access(`flags`, "_"))**
**p0 = > at value=`pos` index=0**
> print text=`p0`
+3 -2
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: lib/csv smoke
import csv:lib/csv.mq.md
---
@@ -12,8 +13,8 @@ import csv:lib/csv.mq.md
> print text=`n`
**r0 = > at value=`rows` index=0**
> print text=[name](`r0`)
> print text=[note](`r0`)
> print text=[name](access(`r0`, "name"))
> print text=[note](access(`r0`, "note"))
**out = > csv.stringify rows=`rows`**
**rows2 = > csv.parse text=`out`**
+3 -2
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: lib/datetime smoke
import dt:lib/datetime.mq.md
---
@@ -6,10 +7,10 @@ import dt:lib/datetime.mq.md
# main
**m = > dt.from_unix unix=0**
> print text=[iso](`m`)
> print text=[iso](access(`m`, "iso"))
**sh = > dt.in_zone dt=`m` zone="Asia/Shanghai"**
> print text=[iso](`sh`)
> print text=[iso](access(`sh`, "iso"))
**p = > dt.parse text="2020-01-02T03:04:05+08:00"**
**u = > dt.to_unix dt=`p`**
+2 -1
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: foreign config load
import foreign:lib/foreign.mq.md
---
@@ -9,4 +10,4 @@ import foreign:lib/foreign.mq.md
> print text=`载入`
**运行 = > foreign.invoke lang="tinycfg" source="console.log('cfg')"**
> print text=[stdout](`运行`)
> print text=[stdout](access(`运行`, "stdout"))
+4 -3
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: foreign env cwd timeout
import foreign:lib/foreign.mq.md
---
@@ -17,7 +18,7 @@ console.log(process.env.MODE + "|" + process.env.MARQDO_FOREIGN_LANG);
```
**检查 = > foreign.invoke code=`环境检查` env=`环境`**
**检查输出 = > trim [stdout](`检查`)**
**检查输出 = > trim [stdout](access(`检查`, "stdout"))**
> print text=`检查输出`
@@ -28,5 +29,5 @@ setTimeout(() => console.log("late"), 5000);
**超时 = > foreign.invoke code=`慢` timeout=0.5**
> print text=[ok](`超时`)
> print text=[timed_out](`超时`)
> print text=[ok](access(`超时`, "ok"))
> print text=[timed_out](access(`超时`, "timed_out"))
+5 -4
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: foreign invoke record
import foreign:lib/foreign.mq.md
---
@@ -13,7 +14,7 @@ process.exit(3);
**记录 = > foreign.invoke code=`失败`**
> print text=[ok](`记录`)
> print text=[code](`记录`)
> print text=[stderr](`记录`)
> print text=[truncated](`记录`)
> print text=[ok](access(`记录`, "ok"))
> print text=[code](access(`记录`, "code"))
> print text=[stderr](access(`记录`, "stderr"))
> print text=[truncated](access(`记录`, "truncated"))
+5 -4
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: foreign invoke JSON input
import foreign:lib/foreign.mq.md
---
@@ -25,8 +26,8 @@ process.stdin.on("end", () => {
```
**记录 = > foreign.invoke code=`统计` input=`数值表` output="json"**
**统计结果 = [result](`记录`)**
**统计结果 = [result](access(`记录`, "result"))**
> print text=[ok](`记录`)
> print text=[n](`统计结果`)
> print text=[sum](`统计结果`)
> print text=[ok](access(`记录`, "ok"))
> print text=[n](access(`统计结果`, "n"))
> print text=[sum](access(`统计结果`, "sum"))
+4 -3
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: foreign probe and register
import foreign:lib/foreign.mq.md
---
@@ -6,8 +7,8 @@ import foreign:lib/foreign.mq.md
# main
**探测 = > foreign.probe lang="node"**
> print text=[ok](`探测`)
> print text=[lang](`探测`)
> print text=[ok](access(`探测`, "ok"))
> print text=[lang](access(`探测`, "lang"))
`模板` =
@@ -19,6 +20,6 @@ import foreign:lib/foreign.mq.md
**> foreign.register lang="tiny" template=`模板`**
**运行 = > foreign.invoke lang="tiny" source="console.log('tiny')"**
**运行输出 = > trim [stdout](`运行`)**
**运行输出 = > trim [stdout](access(`运行`, "stdout"))**
> print text=`运行输出`
**> foreign.unset lang="tiny"**
+2 -1
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: foreign python session
import foreign:lib/foreign.mq.md
---
@@ -9,7 +10,7 @@ import foreign:lib/foreign.mq.md
**设值 = > foreign.session_eval id=`会话` source="x = 41"**
**求值 = > foreign.session_eval id=`会话` source="x + 1"**
> print text=[result](`求值`)
> print text=[result](access(`求值`, "result"))
**> foreign.session_set id=`会话` name="y" value=5**
**取值 = > foreign.session_get id=`会话` name="y"**
+4 -3
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: foreign session timeout
import foreign:lib/foreign.mq.md
---
@@ -8,6 +9,6 @@ import foreign:lib/foreign.mq.md
**会话 = > 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](`慢`)
> print text=[ok](access(`慢`, "ok"))
> print text=[timed_out](access(`慢`, "timed_out"))
> print text=[alive](access(`慢`, "alive"))
+2 -1
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: foreign persistent session
import foreign:lib/foreign.mq.md
---
@@ -9,7 +10,7 @@ import foreign:lib/foreign.mq.md
**设值 = > foreign.session_eval id=`会话` source="let x = 41"**
**求值 = > foreign.session_eval id=`会话` source="x + 1"**
> print text=[result](`求值`)
> print text=[result](access(`求值`, "result"))
**取x = > foreign.session_get id=`会话` name="x"**
> print text=`取x`
+4 -3
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: fs mid2 M9 smoke
import fs:lib/fs.mq.md
---
@@ -12,9 +13,9 @@ import fs:lib/fs.mq.md
> fs.write_text path="m9-tree/nested/b.txt" text="B"
**st = > fs.stat path="m9-tree/a.txt"**
> print text=[size](`st`)
> print text=[is_file](`st`)
> print text=[is_dir](`st`)
> print text=[size](access(`st`, "size"))
> print text=[is_file](access(`st`, "is_file"))
> print text=[is_dir](access(`st`, "is_dir"))
**w = > fs.walk path="m9-tree"**
**n = > len `w`**
+7 -6
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: net cookie_parse
import net:lib/net.mq.md
---
@@ -9,9 +10,9 @@ import net:lib/net.mq.md
**resp = > net.cookie_parse text="id=42; Path=/; HttpOnly; Secure; SameSite=Lax, theme=light; Max-Age=3600" is_response=True**
> print text=[name]([1](`req`))
> print text=[value]([1](`req`))
> print text=[http_only]([1](`resp`))
> print text=[secure]([1](`resp`))
> print text=[same_site]([1](`resp`))
> print text=[max_age]([2](`resp`))
> print text=[name](access([1](access(`req`, "1")), "name"))
> print text=[value](access([1](access(`req`, "1")), "value"))
> print text=[http_only](access([1](access(`resp`, "1")), "http_only"))
> print text=[secure](access([1](access(`resp`, "1")), "secure"))
> print text=[same_site](access([1](access(`resp`, "1")), "same_site"))
> print text=[max_age](access([2](access(`resp`, "2")), "max_age"))
+7 -6
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: net multipart_parse
import net:lib/net.mq.md
---
@@ -11,9 +12,9 @@ import net:lib/net.mq.md
**parts = > net.multipart_parse body=`body` boundary=`boundary`**
> print text=[name]([1](`parts`))
> print text=[value]([1](`parts`))
> print text=[name]([2](`parts`))
> print text=[filename]([2](`parts`))
> print text=[content_type]([2](`parts`))
> print text=[value]([2](`parts`))
> print text=[name](access([1](access(`parts`, "1")), "name"))
> print text=[value](access([1](access(`parts`, "1")), "value"))
> print text=[name](access([2](access(`parts`, "2")), "name"))
> print text=[filename](access([2](access(`parts`, "2")), "filename"))
> print text=[content_type](access([2](access(`parts`, "2")), "content_type"))
> print text=[value](access([2](access(`parts`, "2")), "value"))
+2 -1
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: openai SSE parse offline
import net:lib/net.mq.md
import json:lib/json.mq.md
@@ -10,7 +11,7 @@ import json:lib/json.mq.md
**events = > net.openai_sse_parse text=`fixture`**
- [`ev`](`events`)
- [ev](遍历 `events` 为 `ev`)
**t = > json.get value=`ev` key="type"**
1. `t` == "delta"
**chunk = > json.get value=`ev` key="text"**
+3 -2
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: sys.exec capture=True returns stdout map
description: GAP-09 optional capture.
import sys:lib/sys.mq.md
@@ -15,8 +16,8 @@ import json:lib/json.mq.md
**args = > json.parse text=["-c","printf hi-capture"]**
**out = > sys.exec cmd="sh" args=args capture=True**
**c = [code](out)**
**s = [stdout](out)**
**c = [code](access(out, "code"))**
**s = [stdout](access(out, "stdout"))**
1. `c` == 0
> print text=capture-code-ok
2. *
+6 -5
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: table collections
description: put + list/map helpers
import table:lib/table.mq.md
@@ -7,7 +8,7 @@ import table:lib/table.mq.md
# main
**h = > table.put in=None at="Authorization" value="Bearer-x"**
> print text=[Authorization](`h`)
> print text=[Authorization](access(`h`, "Authorization"))
`xs` =
@@ -17,8 +18,8 @@ import table:lib/table.mq.md
| b |
**xs = > table.put in=`xs` at=1 value="A"**
> print text=[1](`xs`)
> print text=[2](`xs`)
> print text=[1](access(`xs`, "1"))
> print text=[2](access(`xs`, "2"))
`req` =
@@ -31,8 +32,8 @@ import table:lib/table.mq.md
**messages = > table.append list=None item=`msg`**
**req = > table.put in=`req` at="messages" value=`messages`**
**req = > table.put in=`req` at="stream" value=True**
> print text=[content]([1]([messages](`req`)))
> print text=[stream](`req`)
> print text=[content](access([1](access([messages](access(`req`, "messages")), "1")), "content"))
> print text=[stream](access(`req`, "stream"))
**xs = > table.append list=`xs` item="c"**
**n = > table.len xs=`xs`**
+5 -4
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: lib/toml html encoding M8 smoke
import toml:lib/toml.mq.md
import html:lib/html.mq.md
@@ -8,10 +9,10 @@ import enc:lib/encoding.mq.md
# main
**cfg = > toml.parse text="name = \"marqdo\"\ncount = 2\n[pkg]\nver = \"1\"\n"**
> print text=[name](`cfg`)
> print text=[count](`cfg`)
**pkg = [pkg](`cfg`)**
> print text=[ver](`pkg`)
> print text=[name](access(`cfg`, "name"))
> print text=[count](access(`cfg`, "count"))
**pkg = [pkg](access(`cfg`, "pkg"))**
> print text=[ver](access(`pkg`, "ver"))
**e = > html.escape text="a<b>&\"c'"**
> print text=`e`
+9 -8
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: lib/url smoke
import url:lib/url.mq.md
---
@@ -6,16 +7,16 @@ import url:lib/url.mq.md
# main
**u = > url.parse text="https://example.com:8443/a/b?x=1&y=2#frag"**
> print text=[scheme](`u`)
> print text=[host](`u`)
> print text=[port](`u`)
> print text=[path](`u`)
> print text=[query](`u`)
> print text=[fragment](`u`)
> print text=[scheme](access(`u`, "scheme"))
> print text=[host](access(`u`, "host"))
> print text=[port](access(`u`, "port"))
> print text=[path](access(`u`, "path"))
> print text=[query](access(`u`, "query"))
> print text=[fragment](access(`u`, "fragment"))
**q = > url.query_parse text="a=1&b=hi%20x&a=2"**
> print text=[b](`q`)
**as = [a](`q`)**
> print text=[b](access(`q`, "b"))
**as = [a](access(`q`, "a"))**
**a0 = > at value=`as` index=0**
**a1 = > at value=`as` index=1**
> print text=`a0`
+5 -4
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: lib/地址 烟测
导入 址:lib/地址.mq.md
---
@@ -6,7 +7,7 @@ title: lib/地址 烟测
# main
**u = > 址.解析 内容="https://example.com/a?x=1"**
> print text=[scheme](`u`)
> print text=[host](`u`)
> print text=[path](`u`)
> print text=[query](`u`)
> print text=[scheme](access(`u`, "scheme"))
> print text=[host](access(`u`, "host"))
> print text=[path](access(`u`, "path"))
> print text=[query](access(`u`, "query"))
+2 -1
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: 文件 Mid2 M9 烟测
导入 文件:lib/文件.mq.md
---
@@ -10,7 +11,7 @@ title: 文件 Mid2 M9 烟测
> 文件.写文本 路径="m9-zh/a.txt" 内容="A"
**st = > 文件.状态 路径="m9-zh/a.txt"**
> print text=[is_file](`st`)
> print text=[is_file](access(`st`, "is_file"))
**w = > 文件.遍历 路径="m9-zh"**
**n = > 长度 `w`**
+3 -2
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: lib/日期时间 烟测
导入 日时:lib/日期时间.mq.md
---
@@ -6,10 +7,10 @@ title: lib/日期时间 烟测
# main
**m = > 日时.自戳 秒=0**
> print text=[iso](`m`)
> print text=[iso](access(`m`, "iso"))
**sh = > 日时.时区 时刻=`m` 区="Asia/Shanghai"**
> print text=[iso](`sh`)
> print text=[iso](access(`sh`, "iso"))
**p = > 日时.解析 内容="2020-01-02T03:04:05+08:00"**
**u = > 日时.成戳 时刻=`p`**
+3 -2
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: 表与命令行 烟测
导入 表:lib/表.mq.md
导入 命令行:lib/命令行.mq.md
@@ -13,5 +14,5 @@ title: 表与命令行 烟测
**args = > split value="--x,1,--flag" sep=","**
**flags = > 命令行.解析 参数=`args`**
> 打印 内容=[x](`flags`)
> 打印 内容=[flag](`flags`)
> 打印 内容=[x](access(`flags`, "x"))
> 打印 内容=[flag](access(`flags`, "flag"))
+3 -2
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: 表集合
description: 改 + 列表字典
导入 表:lib/表.mq.md
@@ -7,7 +8,7 @@ description: 改 + 列表字典
# main
**h = > 表.改 入=None 于="Authorization" 值="Bearer-x"**
> 打印 内容=[Authorization](`h`)
> 打印 内容=[Authorization](access(`h`, "Authorization"))
`xs` =
@@ -17,7 +18,7 @@ description: 改 + 列表字典
| b |
**xs = > 表.改 入=`xs` 于=1 值="A"**
> 打印 内容=[1](`xs`)
> 打印 内容=[1](access(`xs`, "1"))
**xs = > 表.追加 list=`xs` item="c"**
**n = > 表.长度 xs=`xs`**
+2 -1
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: lib/逗号表 烟测
导入 逗号表:lib/逗号表.mq.md
---
@@ -12,4 +13,4 @@ title: lib/逗号表 烟测
> 打印 内容=`n`
**r0 = > at value=`rows` index=0**
> 打印 内容=[a](`r0`)
> 打印 内容=[a](access(`r0`, "a"))
@@ -1,4 +1,5 @@
---
markup: occlusion
title: lib/配置表 超文本 编码 烟测
导入 配置:lib/配置表.mq.md
导入 超:lib/超文本.mq.md
@@ -8,8 +9,8 @@ title: lib/配置表 超文本 编码 烟测
# main
**cfg = > 配置.解析 内容="name = \"中文\"\nok = true\n"**
> print text=[name](`cfg`)
> print text=[ok](`cfg`)
> print text=[name](access(`cfg`, "name"))
> print text=[ok](access(`cfg`, "ok"))
**e = > 超.转义 内容="a<b>"**
> print text=`e`
+3 -2
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: v0.3 推荐循环头嵌套
description: `- [o](外层)` 内再 `- [i](内层)`
---
@@ -18,8 +19,8 @@ description: `- [o](外层)` 内再 `- [i](内层)`
|---|
| 1 |
- [o](外层)
- [i](内层)
- [o](遍历 外层 为 o)
- [i](遍历 内层 为 i)
**print text=`o`**
*None*
+77
View File
@@ -0,0 +1,77 @@
//! `<TAB>` M7: `marqdo migrate labels` — dry run, write, idempotence, runtime parity.
use std::process::Command;
fn run_in(dir: &std::path::Path, args: &[&str], markup: Option<&str>) -> (i32, String, String) {
let mut cmd = Command::new(env!("CARGO_BIN_EXE_marqdo"));
cmd.args(args);
if let Some(m) = markup {
cmd.env("MARQDO_MARKUP", m);
}
let out = cmd.output().expect("run marqdo");
let _ = dir;
(
out.status.code().unwrap_or(1),
String::from_utf8_lossy(&out.stdout).into_owned(),
String::from_utf8_lossy(&out.stderr).into_owned(),
)
}
fn fixture() -> (std::path::PathBuf, String) {
let dir = std::env::temp_dir().join(format!("marqdo-migrate-{}", std::process::id()));
std::fs::create_dir_all(&dir).unwrap();
let path = dir.join("demo.mq.md");
let src = "---\nimport json:lib/json.mq.md\n---\n\n# main\n\n`表` = > json.parse text={\"键\":\"值\"}\n**a = [键](`表`)**\n> print text=\"a=\" + `a`\n";
std::fs::write(&path, src).unwrap();
(path, src.to_string())
}
#[test]
fn dry_run_does_not_write() {
let (path, before) = fixture();
let (code, stdout, _) = run_in(path.parent().unwrap(), &["migrate", "labels", path.to_str().unwrap()], None);
assert_eq!(code, 0);
assert!(stdout.contains("would change"), "{stdout}");
assert_eq!(std::fs::read_to_string(&path).unwrap(), before);
}
#[test]
fn write_migrates_and_keeps_runtime_behaviour() {
let (path, _) = fixture();
let parent = path.parent().unwrap().to_path_buf();
// Baseline output (classic index).
let (c0, out0, e0) = run_in(&parent, &["run", path.to_str().unwrap()], None);
assert_eq!(c0, 0, "stderr={e0}");
let (code, _, err) = run_in(&parent, &["migrate", "labels", path.to_str().unwrap(), "--write"], None);
assert_eq!(code, 0, "stderr={err}");
let migrated = std::fs::read_to_string(&path).unwrap();
assert!(migrated.contains("markup: occlusion"), "{migrated}");
assert!(migrated.contains("access("), "{migrated}");
// Same output, now via the purity form.
let (c1, out1, e1) = run_in(&parent, &["run", path.to_str().unwrap()], None);
assert_eq!(c1, 0, "stderr={e1}");
assert_eq!(out0, out1);
// Idempotent: a second pass finds nothing to do.
let (_, again, _) = run_in(&parent, &["migrate", "labels", path.to_str().unwrap()], None);
assert!(again.contains("0 index"), "{again}");
}
#[test]
fn equivalence_failure_leaves_file_untouched() {
// A hand-written occlusion has no `(access(…))` payload, so rewriting the
// shape again would change the AST — the tool must refuse.
let dir = std::env::temp_dir().join(format!("marqdo-migrate-bad-{}", std::process::id()));
std::fs::create_dir_all(&dir).unwrap();
let path = dir.join("bad.mq.md");
let src = "---\nmarkup: occlusion\n---\n\n# main\n\n**a = [一加一](1 + 1)**\n> print text=`a`\n";
std::fs::write(&path, src).unwrap();
let (code, stdout, _) = run_in(&dir, &["migrate", "labels", path.to_str().unwrap()], None);
assert_eq!(code, 0);
// Already marked → reported as such, never rewritten.
assert!(stdout.contains("already marked") || stdout.contains("0 index"), "{stdout}");
assert_eq!(std::fs::read_to_string(&path).unwrap(), src);
}
+1
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: access + occlusion loop
import json:lib/json.mq.md
---
+1
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: clean occlusion
---
+1
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: empty label
---
+1
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: empty payload
---
+1
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: implicit occlusion consistent
---
+1
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: implicit occlusion stale
---
+1
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: label search fixture
---
+1
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: dangling label ref
---
+1
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: resolvable label refs
---
+1
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: occlusion value passthrough
---
+2 -1
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: 方括号标记调用与前置修饰语
description: 礼貌 [问候] …;嵌套 ([…]);与 [键](集合) 取元消歧
---
@@ -15,7 +16,7 @@ description: 礼貌 [问候] …;嵌套 ([…]);与 [键](集合) 取元消
|------|------|
| 18 | 28 |
**价 = [拿铁](菜单)**
**价 = [拿铁](access(菜单, "拿铁"))**
**打印 内容=`价`**
## 问候
+8 -7
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: table cell expressions
description: Data cells evaluate like call-arg values (`var`, paths, hyphen prose).
---
@@ -14,9 +15,9 @@ description: Data cells evaluate like call-arg values (`var`, paths, hyphen pros
|---------|-------|------|
| `secret` | `name` | https://api.openai.com/v1 |
> print text=[api_key](`cfg`)
> print text=[model](`cfg`)
> print text=[base](`cfg`)
> print text=[api_key](access(`cfg`, "api_key"))
> print text=[model](access(`cfg`, "model"))
> print text=[base](access(`cfg`, "base"))
`paths` =
@@ -24,7 +25,7 @@ description: Data cells evaluate like call-arg values (`var`, paths, hyphen pros
|---|
| /chat/completions |
> print text=[1](`paths`)
> print text=[1](access(`paths`, "1"))
`rec` =
@@ -32,7 +33,7 @@ description: Data cells evaluate like call-arg values (`var`, paths, hyphen pros
|---|------|---------|
| 1 | user | `secret` |
> print text=[content]([1](`rec`))
> print text=[content](access([1](access(`rec`, "1")), "content"))
`ratios` =
@@ -41,5 +42,5 @@ description: Data cells evaluate like call-arg values (`var`, paths, hyphen pros
| "1/5" |
| "16/9" |
> print text=[1](`ratios`)
> print text=[2](`ratios`)
> print text=[1](access(`ratios`, "1"))
> print text=[2](access(`ratios`, "2"))
+4 -3
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: 横表多行 → 字典套列表
---
@@ -11,14 +12,14 @@ title: 横表多行 → 字典套列表
| 红富士 | 青瓜 |
| 嘎啦 | 黄瓜条 |
**第一种苹果 = [1]([苹果](货架))**
**第一种苹果 = [1](access([苹果](access(货架, "苹果")), "1"))**
> print text=`第一种苹果`
**列 = [苹果](货架)**
**列 = [苹果](access(货架, "苹果"))**
> print text=`列`
**第二种黄瓜 = [2]([黄瓜](货架))**
**第二种黄瓜 = [2](access([黄瓜](access(货架, "黄瓜")), "2"))**
> print text=`第二种黄瓜`
+5 -4
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: 横表单行 → 字典
---
@@ -10,17 +11,17 @@ title: 横表单行 → 字典
|------|------|------|
| 水果 | 蔬菜 | 数码用品 |
**种 = [苹果](分类)**
**种 = [苹果](access(分类, "苹果"))**
> print text=`种`
**种 = [黄瓜](分类)**
**种 = [黄瓜](access(分类, "黄瓜"))**
> print text=`种`
**种 = [鼠标](分类)**
**种 = [鼠标](access(分类, "鼠标"))**
> print text=`种`
- [键](分类)
- [键](遍历 分类 为 键)
> print text=`键`
+3 -2
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: row records with @ marker
---
@@ -11,10 +12,10 @@ title: row records with @ marker
| 1 | apple | 2 |
| 2 | pear | 3 |
**n = [name]([1](orders))**
**n = [name](access([1](access(orders, "1")), "name"))**
> print text=`n`
**q = [qty]([2](orders))**
**q = [qty](access([2](access(orders, "2")), "qty"))**
> print text=`q`
+5 -4
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: 行向记录表(首列 行 / @)
---
@@ -11,17 +12,17 @@ title: 行向记录表(首列 行 / @)
| 1 | 苹果 | 2 |
| 2 | 梨 | 3 |
**第一 = [1](订单)**
**第一 = [1](access(订单, "1"))**
> print text=`第一`
**名 = [品名]([1](订单))**
**名 = [品名](access([1](access(订单, "1")), "品名"))**
> print text=`名`
**量 = [数量]([2](订单))**
**量 = [数量](access([2](access(订单, "2")), "数量"))**
> print text=`量`
- [记录](订单)
- [记录](遍历 订单 为 记录)
> print text=`记录`
+2 -1
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: 集合(表格)示例
---
@@ -12,5 +13,5 @@ title: 集合(表格)示例
| 梨 |
| 桃 |
- [果](篮子)
- [果](遍历 篮子 为 果)
> print text=`果`
+4 -3
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: 链接形取元
description: [键](集合) 为主语法;脚注取元仍兼容
---
@@ -19,9 +20,9 @@ description: [键](集合) 为主语法;脚注取元仍兼容
| 杏 |
**名 = "拿铁"**
**价 = [`名`](菜单)**
**价 = [名](access(菜单, `名`))**
**打印 内容=`价`**
**静 = [美式](菜单)**
**静 = [美式](access(菜单, "美式"))**
**打印 内容=`静`**
**第一 = [1](篮子)**
**第一 = [1](access(篮子, "1"))**
**打印 内容=`第一`**
+2 -1
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: 循环示例
---
@@ -21,5 +22,5 @@ title: 循环示例
| 苹果 |
| 梨 |
- [果](篮子)
- [果](遍历 篮子 为 果)
> print text=今天吃`果`