refactor(PR-02): protocol/reader architecture, /api/documents and reader IA

- migrate crate to RFC-0002 §5.3 Reader layout: src/protocol/{analysis_v2,
  trace_v2,tool_v1}.rs, src/reader/{source,markdown,model,assemble,render,
  assets}.rs, src/config.rs; lib.rs is the composition root; delete app/project/
  semantic/trace/document/presentation/source_map/render/assets top-level files
- split presentation into model (types) and assemble (merge/stale/DocumentService)
- merge controlled project root/path boundary and UTF-8 byte spans into
  reader/source.rs; move view.json config to config.rs
- replace GET /api/document with read-only GET /api/documents (documents list +
  current outline/function/analysis summary) and add contract tests
- reading UI: drop variable/memory placeholder actions, keep one explicit
  unsupported explanation, add simple dark theme toggle over the single token
  layer; assert via rendering test
- reorganize tests into Cargo [[test]] suites tests/contract and
  tests/integration; record docs/evidence/PR-02
- unit 41 + contract 41 + integration 33 all pass; clippy clean
This commit is contained in:
cflmy committed 2026-11-22 13:08:09 +08:00
1 parent 5a61788bc9
commit 5c9a313424
43 files changed
+1222 -936

No files matched your search

+16 -16
View File
@@ -17,12 +17,12 @@
| 条款 | 实现 | 测试/证据 |
|---|---|---|
| `tool.json` schema/字段/SemVer/command/entrypoint | `tool.json`、`scripts/package.sh` | `tests/no_coupling.rs`;`scripts/install-smoke.sh` |
| `tool.json` schema/字段/SemVer/command/entrypoint | `tool.json`、`scripts/package.sh` | `tests/contract/no_coupling.rs`;`scripts/install-smoke.sh` |
| 冻结核心安装、整包摘要、启动校验 | `scripts/install-smoke.sh`、`scripts/acceptance.sh` | acceptance `archive_install` PASS;手工篡改字节验证 README(PR-01 证据) |
| 环境变量 `MARQDO_BIN`/协议协商 | `src/core_client.rs`、`src/version.rs` | `tests/core_contract.rs`、`tests/http_live.rs` |
| argv 数组、无 shell、保留退出码/stdio | `src/core_client.rs` | `tests/core_contract.rs`(argv、timeout、fake core) |
| 不链接/不重编译/不读 CLI 源码 | 依赖图 | `tests/no_coupling.rs`、`docs/ADR/0001` |
| 篡改/缺文件/协议不兼容拒绝 | CLI 自身 + View 侧协商 | `tests/core_contract.rs`、`scripts/install-smoke.sh` |
| 环境变量 `MARQDO_BIN`/协议协商 | `src/core_client.rs`、`src/version.rs` | `tests/contract/core_contract.rs`、`tests/integration/http_live.rs` |
| argv 数组、无 shell、保留退出码/stdio | `src/core_client.rs` | `tests/contract/core_contract.rs`(argv、timeout、fake core) |
| 不链接/不重编译/不读 CLI 源码 | 依赖图 | `tests/contract/no_coupling.rs`、`docs/ADR/0001` |
| 篡改/缺文件/协议不兼容拒绝 | CLI 自身 + View 侧协商 | `tests/contract/core_contract.rs`、`scripts/install-smoke.sh` |
## 3. Analysis v2
@@ -32,7 +32,7 @@
| `schema/schema_version=2`、未知 major 拒绝 | `src/semantic.rs`、`src/app.rs`、`verify` |
| `producer.markdown_profile=marqdo.md.v1` | `src/semantic.rs` |
| `project.root_id/identity_kind/lock_digest/stdlib` | `SemanticProjection` 字段 + `verify --json` |
| `source_digest` 精确字节校验 | `src/semantic.rs`、`tests/unicode_spans.rs`(CRLF) |
| `source_digest` 精确字节校验 | `src/semantic.rs`、`tests/integration/unicode_spans.rs`(CRLF) |
| modules/units/functions/signature/body kind/span | `src/semantic.rs`(typed projection) |
| `resources[]` formula/code + `display`/language | `StaticResource`,渲染为惰性资源 |
| `imports[]`/`references[]`/`calls[]` | 标签与引用状态;不重新解析优先级 |
@@ -44,7 +44,7 @@
| 条款 | 实现 |
|---|---|
| `schema/schema_version=2` | `src/trace.rs` |
| `sha256(analysis bytes)==source.analysis_digest` | `verify_trace`;`tests/trace_contract.rs` |
| `sha256(analysis bytes)==source.analysis_digest` | `verify_trace`;`tests/contract/trace_contract.rs` |
| `source.root_id==project.root_id` | `verify_trace` |
| 事件 `module_id` ∈ Analysis modules | `verify_trace` |
| `seq` 严格递增 | `verify_trace` |
@@ -62,28 +62,28 @@
| 原始 Markdown 是阅读主体 | `DocumentModel` + `ReaderRenderer` |
| 不重新决定可执行性 | 只有 `semantic.rs` 的 Analysis 事实创建锚点 |
| `@exec/@knowledge` 显示前缀仅显示层剥离 | `docs/ADR/0003` |
| 知识区强调/行内代码不执行 | `tests/unicode_spans.rs::knowledge_emphasis_never_becomes_an_execution_anchor` |
| GFM 表/任务列表/围栏/数学可读且惰性 | `tests/rendering.rs`、`tests/export.rs` |
| 知识区强调/行内代码不执行 | `tests/integration/unicode_spans.rs::knowledge_emphasis_never_becomes_an_execution_anchor` |
| GFM 表/任务列表/围栏/数学可读且惰性 | `tests/integration/rendering.rs`、`tests/integration/export.rs` |
| 原始 HTML 默认忽略、URL scheme 净化 | `src/render.rs`、浏览器安全 fixture |
## 6. Security 边界(View 自身)
| 条款 | 实现 | 测试 |
|---|---|---|
| loopback-only + Host 校验 | `src/server.rs` | `tests/http_live.rs` |
| CSRF/Origin/确认 | `POST /api/run` | `tests/http_live.rs` |
| 路径边界/单次解码/无遍历 | `SafeRelativePath`、`percent_decode` | `tests/http_live.rs`、`tests/project` 单测 |
| 导出纯只读、无执行 | `src/export.rs` | `tests/export.rs`(marker 假核心) |
| loopback-only + Host 校验 | `src/server.rs` | `tests/integration/http_live.rs` |
| CSRF/Origin/确认 | `POST /api/run` | `tests/integration/http_live.rs` |
| 路径边界/单次解码/无遍历 | `SafeRelativePath`、`percent_decode` | `tests/integration/http_live.rs`、`tests/project` 单测 |
| 导出纯只读、无执行 | `src/export.rs` | `tests/integration/export.rs`(marker 假核心) |
| 离线文件:// | 内嵌资产 + 相对链接 | `scripts/test-export.sh` Chromium file:// |
| 输出/错误不泄露绝对路径 | `ViewError::public_message`、manifest 相对路径 | `tests/http_live.rs`、`tests/export.rs` |
| 无第二渲染器/第二主题 | 代码门禁 | `tests/no_coupling.rs`、`tests/asset_integrity.rs` |
| 输出/错误不泄露绝对路径 | `ViewError::public_message`、manifest 相对路径 | `tests/integration/http_live.rs`、`tests/integration/export.rs` |
| 无第二渲染器/第二主题 | 代码门禁 | `tests/contract/no_coupling.rs`、`tests/contract/asset_integrity.rs` |
## 7. 明确 UNSUPPORTED / 非目标
- 逐语句赋值实际值、参数实际值、变量历史、Memory 全状态:Trace v2 不提供,UI 只显示静态分析目标并明确说明。
- 知识“已证明”/Prove/Lint/Knowledge 引擎:不实现,等独立版本化协议。
- 调试器/断点/单步、Notebook/旧 2.x 语法兼容、SSE 流式运行、多运行历史:非首版目标。
- `inspect --ir` / 私有 IR / 旧 `ViewExecutionReport`:没有作为依赖;`tests/no_coupling.rs` 门禁。
- `inspect --ir` / 私有 IR / 旧 `ViewExecutionReport`:没有作为依赖;`tests/contract/no_coupling.rs` 门禁。
- 严格模式/项目 grants:首版运行仅 `pure`;`project`/`strict` 需要未来独立授权界面。
## 8. 复核命令