Merge pull request #15 from codex/issue-13-14-doc-rules-and-release
ci/woodpecker/push/ci Pipeline was successful
ci/woodpecker/push/main Pipeline was successful

feat: document-structure rules + release/platform contract (#13/#14/#12)
This commit was merged in pull request #15.
This commit is contained in:
cflmy committed 2026-11-30 12:00:48 +08:00
commit cd01607fea
10 files changed
+515 -8

No files matched your search

+8 -5
View File
@@ -7,11 +7,11 @@ Rust crate,也不读取核心私有文件。
| 项目 | 固定值 |
|---|---|
| 产品版本 | `3.0.0-rc.4` |
| 源码提交 | `452e9a32bd9e40dba427d4180691c58bab74449e` |
| Linux x86_64 归档 SHA-256 | `9c3f166b5e5b8840d39d10019074e4e1c42432fc23e26c69670e64fdcf4e15d8` |
| 归档内 CLI SHA-256 | `a7306962689c635445a59043971ea2eb09298e01feeee81f0ba07b1f3e10306e` |
| Analysis schema SHA-256 | `03929300cec53bb29309a933f74c1aa807943bfd7dbecc80cf4f7f54d037eb30` |
| 当前候选产品版本 | `3.0.0-rc.6` |
| 当前候选源码提交 | `63776735e924ade279cdf59d5c733dc24bfdabbb` |
| 当前候选 Linux x86_64 归档 SHA-256 | `8dc0b006302e03c23451b8ea9f8a0fcdae8bf67c80c546bee2434bf69755bfe3` |
| 上一正式验证输入(v0.2.0 发布证据) | rc.4 `452e9a32bd9e40dba427d4180691c58bab74449e`,归档 SHA-256 `9c3f166b5e5b8840d39d10019074e4e1c42432fc23e26c69670e64fdcf4e15d8` |
| Analysis schema SHA-256(rc.4 基线) | `03929300cec53bb29309a933f74c1aa807943bfd7dbecc80cf4f7f54d037eb30` |
| Markdown Profile | `marqdo.md.v1` |
| Analysis | `marqdo.analysis`,revision 3(当前字段集合) |
| 外部工具 | `marqdo.cli-tool`,revision 1 |
@@ -19,6 +19,9 @@ Rust crate,也不读取核心私有文件。
版本门槛是 SemVer 预发布范围 `>=3.0.0-rc.4,<4.0.0`。rc.4 之前的核心虽然也
可能写 `schema_version: 3`,但字段集合不同,当前 Lint 明确拒绝这些旧制品。
rc.4–rc.6 使用同一公开 Analysis 3 字段集合;当前候选是 rc.6,而 CI 镜像仍提供
rc.5 二进制(迁移由 [marqdo-lint#11](https://git.cflmy.cn/cflmy/marqdo-lint/issues/11)
跟踪),版本门槛在镜像刷新前保持 rc.4 以兼容已验证输入。
## 唯一静态边界
+75
View File
@@ -0,0 +1,75 @@
# 发布与平台合同
本文件记录 `marqdo-lint` 的正式发行边界。发布是维护者的人工批准动作;仓库 CI 只
验证候选并通知根对账,**不自动 tag、不自动上传、不自动发布**。
## 1. 当前候选身份
| 项目 | 值 |
|---|---|
| 产品 | `marqdo-lint` |
| 版本 | `0.2.0`(已发布 tag `v0.2.0`,源码 `111e085f2445a9ba97808a15ad5a50645b8b2007`) |
| 当前协议输入 | Marqdo CLI `3.0.0-rc.6`,源码 `63776735e924ade279cdf59d5c733dc24bfdabbb` |
| CLI 归档 | `marqdo-3.0.0-rc.6-x86_64-unknown-linux-gnu.tar.gz`,SHA-256 `8dc0b006302e03c23451b8ea9f8a0fcdae8bf67c80c546bee2434bf69755bfe3` |
| 协议 | Markdown `marqdo.md.v1`、Analysis `marqdo.analysis` rev 3、CLI Tool `marqdo.cli-tool` rev 1 / API rev 1 |
| Lint 输出 | `marqdo.lint` schema version 1 |
| 兼容 CLI 范围 | `>=3.0.0-rc.4,<4.0.0`(rc.4–rc.6 使用同一公开 Analysis 3 字段集合) |
`docs/PROTOCOL_BASELINE.md` 记录协议输入;本文件只记录发布身份。两者都不得用
浮动 tag 或分支名作为证据。
## 2. 平台矩阵
| 平台 | 状态 | 证据 |
|---|---|---|
| Linux x86_64 / glibc ≥ 2.39 | **supported** | 真实发布 `v0.2.0` 资产(归档 + `.sha256` + `release-manifest.json`);本机 `cargo test --locked`、`scripts/package-tool.sh`、隔离 Tool 安装/卸载;G01–G09 门禁 |
| Linux aarch64 | **unsupported** | 无真实 runner 与产物;不声明 |
| macOS arm64 / x86_64 | **UNVERIFIED** | 无真实 runner;源码按 `cfg` 可移植不等于运行验收 |
| Windows x86_64 | **unsupported** | 无原生构建/运行证据;Tool 分发与路径语义未验证 |
状态词义:`supported` = 在固定 SHA 上真实构建、运行并通过发布门禁;
`UNVERIFIED` = 未在真实目标环境运行,不得写成支持;`unsupported` = 明确不提供。
## 3. 发布资产合同
一次正式 Release 至少包含:
| 资产 | 内容 |
|---|---|
| `marqdo-lint-<version>-x86_64-unknown-linux-gnu.tar.gz` | 解包目录 `marqdo-lint-<version>/`,含 `marqdo-lint`、`tool.json`、`SHA256SUMS`、`README.md`、`CHANGELOG.md`、`LICENSE*`、`examples/`、`docs/` |
| `...tar.gz.sha256` | 归档 SHA-256(下载后必须校验) |
| `release-manifest.json` | 产品版本、源码 SHA、平台、归档 SHA-256、二进制 SHA-256、`tool.json` 摘要、协议基线、CI 与已知问题 |
不可变规则:tag 与资产只增不改;同一 tag 重新上传必须字节一致;失败保留日志,
用新候选重发,不覆盖已发布资产。资产不得包含凭据、构建机绝对路径或用户数据。
`release-manifest.json` 字段沿用既有 `marqdo.release-info` 风格;任何字段语义变更
需要同时更新本文件与发布脚本,不维护第二份版本表。
## 4. 发布前置门禁
1. 候选提交通过同 SHA Woodpecker CI(`.woodpecker/ci.yml`):`check-no-legacy`、
fmt、clippy `-D warnings`、`cargo test --locked`、`package-tool.sh`、隔离安装/
运行/卸载。
2. `scripts/validate-control-flow.py` 生成绑定 CLI 源码/归档/二进制 SHA 的 manifest;
G01–G09 PASS,G10 保持 `UNVERIFIED` 并如实披露。
3. 平台状态与真实证据一致;Linux 以外未验证平台不得宣传。
4. 维护者批准后按 `v<version>` 打 tag 并发布资产;发布后由根 reconcile 对账
(`.woodpecker/release.yml` 只发通知,不持有发布密钥)。
## 5. 诊断与反馈约定
- `marqdo-lint --version` 输出 lint 版本;JSON 报告的 `source`/`protocol` 身份随
报告提供。
- 诊断码(`MQD-*`)稳定;新增规则只增加 ID,不重命名已发布 ID。
- 退出码:`0` 低于门槛、`1` 达到门槛或安全修复被拒绝、`2` 分析不可用/协议错误/
配置错误。反馈系统只引用版本、诊断码与 span,不附带文稿正文。
## 6. 已知问题与未验证项
- 独立应用 qdagent/qdqc 试跑:历史 `UNVERIFIED`。
- rc.4 时代 stdlib 部分参数 span 的展示问题不参与规则对齐(输入侧已知限制);
新规则只读取 `units[]`/`references[]`/`imports[]` 的稳定字段。
- CI 镜像仍提供 rc.5 二进制;迁移到 rc.6 由仓库工单
[marqdo-lint#11](https://git.cflmy.cn/cflmy/marqdo-lint/issues/11) 跟踪。仓库接受
rc.4–rc.6 同一 Analysis 3 字段集合,因此镜像刷新不属于规则代码改动。
+3
View File
@@ -22,6 +22,9 @@
| MQD-PROSE-002 | info | 已绑定的 I/O 调用或索引写入缺少相邻叙述 | 说明权限、后果或失败处理 |
| MQD-PARAM-001 | info | 显式签名附近没有自然文字 | 说明单位、范围和用途 |
| MQD-STYLE-001 | info | 用行内代码承载 `return`,或用斜体承载 `else if` 和循环跳转 | [推荐分支](../examples/good/branches.mq.md) 用斜体表示返回,粗体表示赋值;[读数扫描](../examples/good/control-flow.mq.md) 用行内代码表示控制头、`break` 和 `continue` |
| MQD-ENTRY-001 | info | 项目级入口不是 `index.mq.md`(仅 manifest 或多模块项目) | 为项目保留根 `index.mq.md` 导航入口。 |
| MQD-STRUCT-001 | info | 同名标题出现在多个作用域(裸锚点会编号) | 使用唯一标题名或完整 unit path。 |
| MQD-REL-001 | info | 链接指向未被 import 的模块(静态引用≠执行) | 需要执行目标时显式 import。 |
| MQD-KNOW-001 | warning | 在两个执行段之间切出一段纯文字,或出现跨段控制 | 普通说明留在 Exec,同段关闭控制;公式和富文本可留在 Knowledge |
| MQD-LINK-001 | error | `references[].state` 为 `missing`、`ambiguous`、`invalid` 或 `outside_scope` | 修正引用地址或目标;歧义时打印全部候选,不任选第一个 |
| MQD-LINK-002 | info | `references[].state` 为 `not_loaded` | 这是“未核验”,不是断链;需要时显式使用 `--refs` |
+1 -1
View File
@@ -1,6 +1,6 @@
# 验收记录
当前门禁只认 Marqdo `3.0.0-rc.4` 的公开协议。每次运行
当前门禁接受 Marqdo `3.0.0-rc.4`–`3.0.0-rc.6` 的同一公开 Analysis 3 协议(当前候选 rc.6,CI 镜像仍为 rc.5;见 PROTOCOL_BASELINE)。每次运行
`scripts/validate-control-flow.py` 都会写入
`docs/validation/<cli-source-sha>.json`,记录 lint commit、lint 版本、
Tool bundle 摘要、核心二进制前后摘要、平台、UTC 时间与逐门禁结果。
@@ -0,0 +1,90 @@
# Lint candidate 457cbbd — document-structure rules and release boundary
Date: 2026-11-30.
Repository: `cflmy/marqdo-lint`.
Candidate commit: `457cbbd807aaea964fabe9802f9f8e7e10bdfa52`
(branch `codex/issue-13-14-doc-rules-and-release`).
Issues: [marqdo-lint#13](https://git.cflmy.cn/cflmy/marqdo-lint/issues/13),
[#14](https://git.cflmy.cn/cflmy/marqdo-lint/issues/14),
[#12](https://git.cflmy.cn/cflmy/marqdo-lint/issues/12),
[#11](https://git.cflmy.cn/cflmy/marqdo-lint/issues/11),
[#9](https://git.cflmy.cn/cflmy/marqdo-lint/issues/9).
Parent tickets: `marqdo#55` §13, `marqdo#56` §4/§7.
Executed host: Linux x86_64, glibc 2.43, `rustc 1.100.0 (0ef1bc386
2026-11-09)`, Python 3.14.4.
## 1. Input identity used for acceptance
The CLI-side document-structure contract is
[`marqdo-cli/spec/document-structure.md`](https://git.cflmy.cn/cflmy/marqdo-cli/src/branch/codex/issue-25-26-environment-document-contract/spec/document-structure.md)
on CLI candidate `0f87f856dba28e34bbd2743d23b8f9b1fe96424a`
(PR `marqdo-cli#27`, merged after this record; regression condition: re-run the
acceptance below against the merged CLI SHA and the published rc.6 archive).
Real CLI binary used for the Tool acceptance:
`marqdo` 3.0.0-rc.6 built from CLI candidate `0f87f856…`, with the pinned
ecosystem Bundle `marqdo-stdlib 0.2.0`,
tree digest `sha256:db905508dde89763b9d43b47fc5d52c6a1d5445a91f3c86a550ced43e8aac9d7`.
The published rc.6 release archive was **not** downloaded in this run; the
upstream tracking issue #11 remains `UNVERIFIED` for the public archive.
## 2. Source gates
| Command | Result |
|---|---|
| `./scripts/check-no-legacy.sh` | PASS (0 hits) |
| `cargo fmt --all -- --check` | PASS |
| `cargo clippy --all-targets --locked -- -D warnings` | PASS |
| `cargo test --locked` | PASS: 64 passed, 0 failed (9 suites) |
| `sh scripts/package-tool.sh <out>` | PASS; binary SHA-256 `d6443802f4cc2162a9f45833c354f8a5026fe1efe251a8e1b17e90759a8f01b9`, `tool.json` SHA-256 `e68f22425c697948db95fad2053280e03a59be4d95568a5955254cca710f6edc` |
| Real Tool install/run/remove via candidate CLI | PASS: `tool install` → `lint examples/nested/inventory.mq.md --format json` (exit 0, report `marqdo.lint` with `source/diagnostics/analysis_status/metrics`) → `tool remove lint` |
New-rule coverage lives in `src/rules/structure.rs` unit tests (valid root /
namespace / child projections are validated by the strict Analysis-3
deserializer): duplicate heading names across parents (2 findings), unique names
(0), project entry outside `index.mq.md` (1, manifest project), standalone
single-file document (0). `tests/cli.rs` now expects the 25-rule catalog.
## 3. Rule-to-issue mapping
| Rule | marqdo#55 section | Evidence |
|---|---|---|
| `MQD-ENTRY-001` | §6 project-level entry | Analysis `project.entry_module_id` + `identity_kind`/module count |
| `MQD-STRUCT-001` | §7 directory/nesting, §13.1 B structure | `units[].name/path/heading_span` |
| `MQD-REL-001` | §9.1 three relations | `references[].state/target_module` vs `imports[].resolved` |
| existing `MQD-LINK-*`/`MQD-CALL-*` | §13.1 D relations | unchanged, already covered by #12 |
`MQD-ENTRY-001` is `info` and is limited to projects (manifest or >1 module) so
single-file examples never fail. All three rules are `info`: no exit-code or
fail-on-warning regression for authors.
## 4. Release boundary (#9/#14)
`docs/RELEASE.md` records the platform matrix and asset contract:
* Linux x86_64 / glibc ≥ 2.39: `supported`, backed by the published `v0.2.0`
assets (archive + `.sha256` + `release-manifest.json`) and the local gates
above.
* macOS/Windows: `UNVERIFIED`/`unsupported` (no native runner or artifact).
* Assets: `<name>-<version>-x86_64-unknown-linux-gnu.tar.gz`, `.sha256`,
`release-manifest.json`; immutable tag/assets; same-SHA CI required;
publication is a maintainer action and `.woodpecker/release.yml` only
notifies the root reconcile (no publish keys in repo CI).
Issue #9's requirement (same-SHA real CI + independent credential phase, no
secret-holding publish step in the repo workflow) is satisfied by the current
tree: the repo workflow has no publish step at all; the release notification
carries no package code or release token. Recommendation: close #9 after the
candidate CI is green.
## 5. Not verified / limits
- macOS/Windows native build/run: **UNVERIFIED** (no runner in this environment).
- Published rc.6 archive acceptance (issue #11): **UNVERIFIED**; CI image still
ships rc.5. The repo accepts the same Analysis-3 field set from rc.4–rc.6, so
this is a CI-image/infrastructure follow-up, not a rule change.
- Formal `v0.3.0` tag/release for the new rules: **not created**; publication
needs maintainer approval after same-SHA CI. No release claim is made here.
- Independent application (qdagent/qdqc) trial: historical `UNVERIFIED`
(unchanged).
+1
View File
@@ -146,6 +146,7 @@ pub fn run() -> Result<i32> {
document,
&project.core_diagnostics,
));
analysis.diagnostics.extend(rules::check_project(&project));
analysis
.diagnostics
.sort_by(|left, right| (left.span, &left.id).cmp(&(right.span, &right.id)));
+33 -1
View File
@@ -1,10 +1,12 @@
mod control;
mod documentation;
mod structure;
mod supplemental;
pub(crate) use control::check_aligned;
pub use control::{check_document, check_function};
pub use documentation::{check_documentation, check_function_documentation};
pub use structure::{check_document_structure, check_project};
pub use supplemental::{check_ast_document, check_entry_without_analysis, check_heading_boundary};
pub(crate) use supplemental::{check_entry_for_heading, check_supplemental_function};
@@ -242,6 +244,33 @@ pub const CATALOG: &[RuleSpec] = &[
"Analysis calls[].state 为 unresolved 及 reason。",
Manual
),
rule!(
"MQD-ENTRY-001",
Info,
"项目级入口不是 index.mq.md",
"读者与 AI 代理需要一个稳定的项目入口位置。",
"为多模块项目保留根 index.mq.md 作为导航入口;单文件文稿不受此约定约束。",
"Analysis project.entry_module_id 的 relative_path(identity_kind=manifest 或多模块)。",
Manual
),
rule!(
"MQD-STRUCT-001",
Info,
"同名标题出现在多个作用域",
"语言允许不同父级下重名,但裸锚点与跨文档引用会变得不明确。",
"使用唯一标题名,或让跨文档引用使用完整 unit path/id 而不是裸锚点。",
"Analysis units[].name/path/heading_span(同作用域名由 CLI 硬错误拦截)。",
Manual
),
rule!(
"MQD-REL-001",
Info,
"链接指向未 import 的模块",
"链接是静态引用,不会加载、import 或执行目标模块。",
"若需要执行目标,使用显式 YAML front matter import;否则保留为纯阅读链接。",
"Analysis references[].state/target_module 与 imports[].resolved 的关系差集。",
Manual
),
rule!(
"MQD-SAFETY-001",
Error,
@@ -265,11 +294,14 @@ mod tests {
#[test]
fn catalog_has_stable_unique_ids() {
let ids: BTreeSet<_> = CATALOG.iter().map(|rule| rule.id).collect();
assert_eq!(CATALOG.len(), 22);
assert_eq!(CATALOG.len(), 25);
assert_eq!(ids.len(), CATALOG.len());
assert!(ids.contains("MQD-BRANCH-001"));
assert!(ids.contains("MQD-SAFETY-001"));
assert!(ids.contains("MQD-LINK-001"));
assert!(ids.contains("MQD-CALL-001"));
assert!(ids.contains("MQD-ENTRY-001"));
assert!(ids.contains("MQD-STRUCT-001"));
assert!(ids.contains("MQD-REL-001"));
}
}
+302
View File
@@ -0,0 +1,302 @@
//! Document-level structure and navigation rules (issue #13, marqdo#55 §13.1).
//!
//! These rules read only the public Analysis revision 3 projection supplied by
//! one `check --emit`. They never parse Markdown, guess execution from text or
//! call another repository's private code. The facts they consume are the
//! `units[]` identity/mode projection, the `anchors[]` navigation names and the
//! `references[]`/`imports[]` relation split documented in
//! `spec/document-structure.md` (CLI).
use std::collections::BTreeMap;
use crate::{
diagnostics::Diagnostic,
input::{ProjectInput, SourceDocument},
model::{AnalysisModule, IdentityKind, ReferenceState, Span},
};
/// Document-local structure/navigation diagnostics.
pub fn check_document_structure(document: &SourceDocument) -> Vec<Diagnostic> {
let Some(module) = &document.module else {
return Vec::new();
};
let mut diagnostics = duplicate_heading_name_rules(module);
diagnostics.extend(link_not_import_rules(module));
diagnostics
}
/// Project-level entry rule.
///
/// The project-level entry convention (`index.mq.md`, marqdo#55 §6) is checked
/// only for real projects: a manifest-backed project or a multi-module load.
/// A standalone single-file document is not a project and is never warned
/// about its file name.
pub fn check_project(project: &ProjectInput) -> Vec<Diagnostic> {
let Some(analysis) = &project.analysis else {
return Vec::new();
};
let Some(entry) = analysis.entry_module() else {
return Vec::new();
};
let is_project =
analysis.project.identity_kind == IdentityKind::Manifest || analysis.modules.len() > 1;
if !is_project || entry.relative_path == "index.mq.md" {
return Vec::new();
}
vec![
Diagnostic::new("MQD-ENTRY-001", Span::new(0, 0)).with_message(format!(
"项目级入口约定为 `index.mq.md`,当前入口是 `{}`;导航入口名不改变执行语义,\
但项目级入口应稳定为 `index.mq.md`,便于读者从同一位置进入(marqdo#55 §6)",
entry.relative_path
)),
]
}
/// A heading name that is legal in the language but ambiguous for readers.
///
/// The language allows the same canonical heading name under different
/// parents; anchors then get numbered suffixes (`name`, `name-2`, ...). That is
/// valid, but a cross-document reader cannot rely on a bare anchor. This info
/// rule asks the author to use a unique name or the full unit path when the
/// document is intended as navigation.
fn duplicate_heading_name_rules(module: &AnalysisModule) -> Vec<Diagnostic> {
let mut by_name: BTreeMap<&str, Vec<&crate::model::AnalysisUnit>> = BTreeMap::new();
for unit in &module.units {
if unit.name.is_empty() || unit.path.is_empty() {
continue;
}
by_name.entry(unit.name.as_str()).or_default().push(unit);
}
let mut diagnostics = Vec::new();
for (name, units) in by_name {
if units.len() < 2 {
continue;
}
let paths = units
.iter()
.map(|unit| format!("`{}`", unit.path.join("/")))
.collect::<Vec<_>>()
.join("、");
for unit in &units {
let span = unit.heading_span.unwrap_or(unit.span);
diagnostics.push(
Diagnostic::new("MQD-STRUCT-001", span)
.with_message(format!("标题名 `{name}` 在多个作用域出现:{paths}")),
);
}
}
diagnostics
}
/// A Markdown link to a loaded module that the document never imports.
///
/// A link is a static reference; it never loads, imports or executes the
/// target (marqdo#55 §9.1). Readers and AI agents can mistake a resolved link
/// for an available executable entry, so the rule states the relation
/// explicitly. Fragment-only links are not covered: they address a unit inside
/// the same module.
fn link_not_import_rules(module: &AnalysisModule) -> Vec<Diagnostic> {
if module.references.is_empty() {
return Vec::new();
}
let imported = module
.imports
.iter()
.filter_map(|import| import.resolved.clone())
.collect::<Vec<_>>();
let mut diagnostics = Vec::new();
for reference in &module.references {
let Some(target) = reference.target_module.as_deref() else {
continue;
};
if target == module.id || reference.state != ReferenceState::Resolved {
continue;
}
if imported.iter().any(|import| import == target) {
continue;
}
diagnostics.push(
Diagnostic::new("MQD-REL-001", reference.span).with_message(format!(
"链接目标 `{}` 未被 import;链接只是静态引用,不会加载或执行目标模块",
reference.url
)),
);
}
diagnostics
}
#[cfg(test)]
mod tests {
use super::*;
use crate::model::{ExecutionProjection, MarkdownTree};
use serde_json::json;
fn analysis_with_units(namespaces: &[(&str, &[&str])]) -> serde_json::Value {
// One namespace per entry with the given child heading names. Every
// unit gets a valid span so the projection passes the strict
// Analysis-3 validator; the rules read identity/name/path only.
let source = "# @knowledge 甲\n\n## @exec main\n\n`return 1`\n";
let digest = {
use sha2::Digest;
let mut hasher = sha2::Sha256::new();
hasher.update(source.as_bytes());
format!("{:x}", hasher.finalize())
};
let module_id = "root:default::index.mq.md";
let root_id = format!("{module_id}#");
let mut units = vec![json!({
"id": root_id,
"path": [],
"parent_id": null,
"kind": "root",
"name": "",
"level": 0,
"mode": "knowledge",
"mode_origin": "default",
"mode_source_unit_id": root_id,
"heading_span": null,
"span": {"start": 0, "end": source.len()},
"function": null
})];
for (namespace, children) in namespaces {
let namespace_id = format!("{module_id}#{namespace}");
units.push(json!({
"id": namespace_id,
"path": [namespace],
"parent_id": root_id,
"kind": "namespace",
"name": namespace,
"level": 1,
"mode": "knowledge",
"mode_origin": "explicit",
"mode_source_unit_id": namespace_id,
"heading_span": {"start": 0, "end": 0},
"span": {"start": 0, "end": source.len()},
"function": null
}));
for child in *children {
let id = format!("{module_id}#{namespace}/{child}");
units.push(json!({
"id": id,
"path": [namespace, child],
"parent_id": namespace_id,
"kind": "knowledge",
"name": child,
"level": 2,
"mode": "knowledge",
"mode_origin": "inherited",
"mode_source_unit_id": namespace_id,
"heading_span": {"start": 0, "end": 0},
"span": {"start": 0, "end": source.len()},
"function": null
}));
}
}
json!({
"schema": "marqdo.analysis",
"schema_version": 3,
"producer": {"name": "marqdo", "version": "3.0.0-rc.6", "markdown_profile": "marqdo.md.v1"},
"project": {
"root_id": "sha256:0000000000000000000000000000000000000000000000000000000000000000",
"identity_kind": "workspace_snapshot",
"entry_module_id": module_id,
"lock_digest": "",
"manifest_digest": "",
"stdlib": null,
"extensions": []
},
"modules": [{
"id": module_id,
"package_instance_id": "root:default",
"relative_path": "index.mq.md",
"source_digest": digest,
"source": source,
"document": {"kind": "document", "span": {"start": 0, "end": source.len()}, "children": []},
"units": units,
"anchors": [],
"functions": [],
"imports": [],
"references": [],
"calls": [],
"resources": []
}],
"diagnostics": []
})
}
fn document_with(raw: serde_json::Value) -> SourceDocument {
let projection = ExecutionProjection::from_json(raw).unwrap();
let module = projection.entry_module().unwrap().clone();
let source = module
.source_snapshot(std::path::PathBuf::from("index.mq.md"))
.unwrap();
// Structure rules only need the Analysis units; no Markdown alignment.
SourceDocument {
markdown: MarkdownTree::empty(&source),
source,
module: Some(module),
}
}
#[test]
fn duplicate_heading_names_are_reported_once_per_unit() {
let document = document_with(analysis_with_units(&[("甲", &["说明"]), ("乙", &["说明"])]));
// The projection is valid at the language level (different parents are
// allowed), so the rule reports both headings.
let diagnostics = check_document_structure(&document);
assert_eq!(
diagnostics
.iter()
.filter(|d| d.id == "MQD-STRUCT-001")
.count(),
2
);
}
#[test]
fn unique_heading_names_produce_no_structure_diagnostic() {
let document = document_with(analysis_with_units(&[("甲", &["说明", "背景"])]));
assert!(check_document_structure(&document).is_empty());
}
#[test]
fn project_entry_outside_index_is_reported_for_multi_module_projects() {
let mut raw = analysis_with_units(&[("甲", &["说明"])]);
raw["project"]["entry_module_id"] = json!("root:default::other.mq.md");
raw["project"]["identity_kind"] = json!("manifest");
raw["project"]["root_id"] = json!("root:default@0.1.0");
raw["modules"][0]["id"] = json!("root:default::other.mq.md");
raw["modules"][0]["relative_path"] = json!("other.mq.md");
let projection = ExecutionProjection::from_json(raw.clone()).unwrap();
let project = ProjectInput {
entry: std::path::PathBuf::from("other.mq.md"),
documents: Vec::new(),
analysis: Some(projection),
analysis_status: crate::input::AnalysisStatus::Complete,
artifact_digest: None,
core_output: String::new(),
core_diagnostics: Vec::new(),
notices: Vec::new(),
};
let diagnostics = check_project(&project);
assert_eq!(diagnostics.len(), 1);
assert_eq!(diagnostics[0].id, "MQD-ENTRY-001");
}
#[test]
fn single_file_standalone_document_is_not_a_project_entry_violation() {
let projection =
ExecutionProjection::from_json(analysis_with_units(&[("甲", &["说明"])])).unwrap();
let project = ProjectInput {
entry: std::path::PathBuf::from("index.mq.md"),
documents: Vec::new(),
analysis: Some(projection),
analysis_status: crate::input::AnalysisStatus::Complete,
artifact_digest: None,
core_output: String::new(),
core_diagnostics: Vec::new(),
notices: Vec::new(),
};
assert!(check_project(&project).is_empty());
}
}
+1
View File
@@ -18,6 +18,7 @@ pub fn check_ast_document(document: &SourceDocument) -> Vec<Diagnostic> {
diagnostics.extend(knowledge_rule(markdown));
diagnostics.extend(reference_rules(document));
diagnostics.extend(call_rules(document));
diagnostics.extend(super::structure::check_document_structure(document));
diagnostics
}
+1 -1
View File
@@ -19,7 +19,7 @@ fn rule_commands_do_not_require_the_core() {
.unwrap();
assert!(output.status.success());
let rules: Vec<Value> = serde_json::from_slice(&output.stdout).unwrap();
assert_eq!(rules.len(), 22);
assert_eq!(rules.len(), 25);
let output = lint()
.env("MARQDO_BIN", "no-such-core")