Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
df4324f3e3 |
No files matched your search
@@ -10,8 +10,9 @@ Marqdo **Web 领域聚合仓库**(状态:`planned`)。本仓固定 Web 作
|
|||||||
| --- | --- |
|
| --- | --- |
|
||||||
| [docs/WEB-DESIGN.md](docs/WEB-DESIGN.md) | **唯一现行 Web 作者合同**:作者写什么、如何被确定性解释、什么被拒绝、命令/退出码/安全/handoff/诊断/变更流程 |
|
| [docs/WEB-DESIGN.md](docs/WEB-DESIGN.md) | **唯一现行 Web 作者合同**:作者写什么、如何被确定性解释、什么被拒绝、命令/退出码/安全/handoff/诊断/变更流程 |
|
||||||
| [docs/DEVELOPMENT.md](docs/DEVELOPMENT.md) | 领域治理与开发流程:组件关系、依赖规则、激活门禁、组件→领域→根候选晋升、三层验收、工单路由 |
|
| [docs/DEVELOPMENT.md](docs/DEVELOPMENT.md) | 领域治理与开发流程:组件关系、依赖规则、激活门禁、组件→领域→根候选晋升、三层验收、工单路由 |
|
||||||
| [examples/research-workspace/](examples/research-workspace/) | 根规范 §8 科研工作台示例(六个 `.mq.md` 原样收录);状态 `UNVERIFIED` |
|
| [examples/research-workspace/](examples/research-workspace/) | 根规范 §8 科研工作台示例(六个 `.mq.md` 原样收录);入口 Analysis 已由 WEB-00 实测,Design/Preview 解释前整体仍 `UNVERIFIED` |
|
||||||
| [tests/README.md](tests/README.md) | 领域/跨组件验收的目录、证据与当前状态 |
|
| [tests/README.md](tests/README.md) | 领域/跨组件验收的目录、证据与当前状态 |
|
||||||
|
| [docs/evidence/WEB-00-analysis-probe.md](docs/evidence/WEB-00-analysis-probe.md) | WEB-00:真实 CLI Analysis 3 对合同依赖的探测证据(入口/链接/目标/负例,PASS) |
|
||||||
| [components.toml](components.toml) | 直接子组件的治理记录(均为 planned,无 entry) |
|
| [components.toml](components.toml) | 直接子组件的治理记录(均为 planned,无 entry) |
|
||||||
|
|
||||||
## 领域边界
|
## 领域边界
|
||||||
@@ -37,6 +38,14 @@ Marqdo **Web 领域聚合仓库**(状态:`planned`)。本仓固定 Web 作
|
|||||||
- Design 和 Preview 在各自的独立仓库开发。 [marqdo-web-design](https://git.cflmy.cn/cflmy/marqdo-web-design) · [marqdo-web-preview](https://git.cflmy.cn/cflmy/marqdo-web-preview)
|
- Design 和 Preview 在各自的独立仓库开发。 [marqdo-web-design](https://git.cflmy.cn/cflmy/marqdo-web-design) · [marqdo-web-preview](https://git.cflmy.cn/cflmy/marqdo-web-preview)
|
||||||
- 本仓库不提供运行时入口,也不需要另一份 `tool.json`;唯一工具入口属于 Preview 的 `web` 命令。
|
- 本仓库不提供运行时入口,也不需要另一份 `tool.json`;唯一工具入口属于 Preview 的 `web` 命令。
|
||||||
|
|
||||||
|
## 独立验收入口(WEB-00 起)
|
||||||
|
|
||||||
|
```sh
|
||||||
|
MARQDO_BIN=<verified marqdo> MARQDO_CLI_SHA256=<digest> scripts/ci.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
`scripts/risk-probe.py` 只消费真实 CLI 的公开 Analysis 3(`check --emit`),检查 WEB-DESIGN 依赖的表 AST、anchor、references `candidate_path`、目标 anchor 与负例事实;输出机器证据,缺事实即失败。它不解析 Markdown、不模拟 CLI。
|
||||||
|
|
||||||
## 仓库结构
|
## 仓库结构
|
||||||
|
|
||||||
```text
|
```text
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
# WEB-00 真实 Analysis 风险探测(W-M0)证据
|
||||||
|
|
||||||
|
日期:2026-11-27。责任仓:`marqdo-ext-web`;父工单:[marqdo#6](https://git.cflmy.cn/cflmy/marqdo/issues/6);本仓工单:[marqdo-ext-web#1](https://git.cflmy.cn/cflmy/marqdo-ext-web/issues/1)。
|
||||||
|
|
||||||
|
本文件记录 `docs/WEB-DESIGN.md` 对公开 Analysis 3 的依赖是否被真实 CLI 满足,是**候选证据**,不声称 Design/Preview 已实现或 Web 领域已激活。
|
||||||
|
|
||||||
|
## 输入身份
|
||||||
|
|
||||||
|
| 对象 | 身份 |
|
||||||
|
| --- | --- |
|
||||||
|
| 根生态组合 | `cflmy/marqdo@d4ccb7700392e87b240d20f84539921f46540dda`(六个 stdlib active、CLI Phase B) |
|
||||||
|
| CLI | 由根固定的 `cli/` 提交 `deadf6e` 构建的 `marqdo 3.0.0-rc.4`,SHA-256 `sha256:6ede3b9e8bcfad3942573e68b5f54b2c5bc2866b37d102f63acd49a55cb212db` |
|
||||||
|
| 平台 | Linux x86_64(本机验证) |
|
||||||
|
| 示例根 | `examples/research-workspace/`(`--root` 显式) |
|
||||||
|
| 入口 | `index.mq.md`,设计单元 anchor `工作台` |
|
||||||
|
|
||||||
|
## 执行
|
||||||
|
|
||||||
|
```sh
|
||||||
|
MARQDO_BIN=<verified marqdo> MARQDO_CLI_SHA256=<digest> \
|
||||||
|
scripts/ci.sh
|
||||||
|
# out/web00-analysis-probe.json 为机器证据
|
||||||
|
```
|
||||||
|
|
||||||
|
`scripts/risk-probe.py` 只消费真实 `check --emit` 的 Analysis 3,不解析 Markdown;它对入口、两个设计链接目标与两个负例 fixture 分别生成 Analysis 并检查合同所需事实。
|
||||||
|
|
||||||
|
## 结果:PASS(gaps 为空)
|
||||||
|
|
||||||
|
均已由真实 Analysis 提供:
|
||||||
|
|
||||||
|
- Knowledge H2 `工作台` 的精确 anchor、`unit_id`、`heading_span`/`span`;`anchors` 把 anchor 映射到 Unit。
|
||||||
|
- `组件` 直接 H3 节内的单张 GFM 表:AST `table` 节点、`table_row`(首行 header)、四个 `table_cell`,表头文本精确为 `行 | 槽 | 组件 | 宽度`,整表 span 与节 span 一致。
|
||||||
|
- 每个组件单元格恰好包含一个 Link;Link 的 AST span 与单元格 span 可精确比较,正文链接不会被误当作组件边。
|
||||||
|
- 设计链接对应 Analysis `references`:`source_unit` 指向所在 H3、`url`/`span` 与原链接一致、`state = not_loaded`、`candidate_path`/`fragment` 精确且相对路径;无需按 label/文件名猜测。
|
||||||
|
- 目标解析:对 `components/navigation.mq.md#导航` 与 `components/workspace.mq.md#科研工作区` 分别 `check --emit`,其 `anchors` 均能映射到 Knowledge H2,并记录 `source_digest` 作为源身份;目标均在显式 `--root` 内。
|
||||||
|
- 负例事实:普通段落链接只形成普通 reference(无保留表格);缺失 anchor 仍暴露 `candidate_path`/`fragment`,Design 可确定性拒绝。
|
||||||
|
|
||||||
|
## 合同结论与修正
|
||||||
|
|
||||||
|
- `docs/WEB-DESIGN.md` 对 Analysis 3 的依赖(GFM 表 AST、精确 anchor、references `candidate_path`、source_digest、显式 root)**与实测一致,无需修改**;未发现公开 Analysis 合同缺口,因此不向 CLI 提交新的语法/私有字段需求。
|
||||||
|
- `--unit` 的“精确 anchor”在 Analysis 中由 `anchors[].anchor` 给出,并映射到 Knowledge H2 `unit_id`;Design 必须使用该映射而不是猜路径。
|
||||||
|
|
||||||
|
## 未验证 / 后续
|
||||||
|
|
||||||
|
- 本探测只覆盖合同示例入口与两个组件目标及负例 fixture;Design(WEB-01)对递归布局/场景/诊断的实现与 Preview(WEB-02)渲染仍待开发,示例整体仍为 `UNVERIFIED`。
|
||||||
|
- `marqdo-web-design`/`marqdo-web-preview` 不在本仓;本证据不替代组件 CI。
|
||||||
|
- 领域激活与根接入(WEB-05)仍未开始。
|
||||||
Executable
+12
@@ -0,0 +1,12 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# WEB-00 independent component entry: explicit verified CLI in, evidence out.
|
||||||
|
set -eu
|
||||||
|
: "${MARQDO_BIN:?set MARQDO_BIN to the verified marqdo executable}"
|
||||||
|
out_dir="${MARQDO_WEB_EVIDENCE_DIR:-$PWD/out}"
|
||||||
|
mkdir -p "$out_dir"
|
||||||
|
args=(--cli "$MARQDO_BIN" --out "$out_dir/web00-analysis-probe.json")
|
||||||
|
if [[ -n "${MARQDO_CLI_SHA256:-}" ]]; then
|
||||||
|
args+=(--expected-cli-sha256 "$MARQDO_CLI_SHA256")
|
||||||
|
fi
|
||||||
|
python3 scripts/risk-probe.py "${args[@]}"
|
||||||
|
git rev-parse HEAD > "$out_dir/component-sha.txt" 2>/dev/null || true
|
||||||
Executable
+388
@@ -0,0 +1,388 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""WEB-00 W-M0: prove the public Analysis contract can bind the Web design model.
|
||||||
|
|
||||||
|
This probe consumes only the real CLI's public Analysis 3 (`check --emit`) and
|
||||||
|
never parses Markdown itself. It checks the facts `docs/WEB-DESIGN.md` depends
|
||||||
|
on:
|
||||||
|
|
||||||
|
* a design component is an exact Knowledge H2 with an anchor and spans;
|
||||||
|
* the `组件` retention table is a real GFM table in the AST, with the exact
|
||||||
|
header and one link per component cell;
|
||||||
|
* design links appear as Analysis references with `candidate_path` and
|
||||||
|
`fragment`, so Design never has to guess by label or filename;
|
||||||
|
* each candidate target resolves to a Knowledge H2 anchor in its own module
|
||||||
|
Analysis, with a source digest for identity;
|
||||||
|
* ordinary paragraph links and missing anchors stay distinguishable facts
|
||||||
|
(negative fixtures), so the contract's rejections are implementable.
|
||||||
|
|
||||||
|
Inputs are explicit: `--cli` names the verified CLI binary. The CLI digest and
|
||||||
|
platform are recorded in the evidence. The probe fails when a required fact is
|
||||||
|
missing; it does not claim a PASS from a substring or a mock.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import hashlib
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import platform
|
||||||
|
import shutil
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import tempfile
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
REPO = Path(__file__).resolve().parents[1]
|
||||||
|
DEFAULT_ROOT = REPO / "examples" / "research-workspace"
|
||||||
|
ENTRY = "index.mq.md"
|
||||||
|
DESIGN_H2_ANCHOR = "工作台"
|
||||||
|
COMPONENTS_SECTION = "组件"
|
||||||
|
COMPONENTS_HEADER = ["行", "槽", "组件", "宽度"]
|
||||||
|
|
||||||
|
|
||||||
|
class ProbeError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class Probe:
|
||||||
|
def __init__(self, cli: Path, root: Path, work: Path):
|
||||||
|
self.cli = cli
|
||||||
|
self.root = root
|
||||||
|
self.work = work
|
||||||
|
self.checks: list[dict] = []
|
||||||
|
self.facts: dict = {}
|
||||||
|
self.inputs: dict[str, dict] = {}
|
||||||
|
|
||||||
|
# -- helpers -----------------------------------------------------------
|
||||||
|
def record(self, check_id: str, ok: bool, detail: str) -> bool:
|
||||||
|
self.checks.append({"id": check_id, "status": "PASS" if ok else "FAIL", "detail": detail})
|
||||||
|
return ok
|
||||||
|
|
||||||
|
def require(self, check_id: str, ok: bool, detail: str) -> None:
|
||||||
|
if not self.record(check_id, ok, detail):
|
||||||
|
raise ProbeError(f"{check_id}: {detail}")
|
||||||
|
|
||||||
|
def analyze(self, document: Path) -> dict:
|
||||||
|
out = self.work / (hashlib.sha256(str(document).encode()).hexdigest()[:16] + ".analysis.json")
|
||||||
|
result = subprocess.run(
|
||||||
|
[str(self.cli), "check", str(document), "--emit", str(out)],
|
||||||
|
cwd=str(REPO),
|
||||||
|
capture_output=True,
|
||||||
|
)
|
||||||
|
if result.returncode != 0:
|
||||||
|
raise ProbeError(
|
||||||
|
f"CLI check failed for {document} ({result.returncode}): "
|
||||||
|
f"{result.stderr.decode(errors='replace')}"
|
||||||
|
)
|
||||||
|
analysis = json.loads(out.read_text())
|
||||||
|
if analysis.get("schema") != "marqdo.analysis" or analysis.get("schema_version") != 3:
|
||||||
|
raise ProbeError(f"{document}: not public Analysis 3")
|
||||||
|
if len(analysis.get("modules", [])) != 1:
|
||||||
|
raise ProbeError(f"{document}: expected one analyzed module")
|
||||||
|
module = analysis["modules"][0]
|
||||||
|
try:
|
||||||
|
label = document.relative_to(self.root).as_posix()
|
||||||
|
except ValueError:
|
||||||
|
label = "fixture/" + document.name
|
||||||
|
self.inputs[label] = {
|
||||||
|
"source_digest": module["source_digest"],
|
||||||
|
"module_id": module["id"],
|
||||||
|
}
|
||||||
|
return module
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def text(module: dict, span: dict) -> str:
|
||||||
|
raw = module["source"].encode()
|
||||||
|
return raw[span["start"] : span["end"]].decode(errors="replace")
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def children(node: dict, kind: str):
|
||||||
|
for child in node.get("children") or []:
|
||||||
|
if child.get("kind") == kind:
|
||||||
|
yield child
|
||||||
|
yield from Probe.children(child, kind)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def unit_by_anchor(module: dict, anchor: str) -> dict | None:
|
||||||
|
for entry in module.get("anchors", []):
|
||||||
|
if entry.get("anchor") == anchor:
|
||||||
|
return next(
|
||||||
|
(unit for unit in module["units"] if unit["id"] == entry["unit_id"]),
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
return None
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def reference_for(module: dict, url: str, span: dict) -> dict | None:
|
||||||
|
for reference in module.get("references", []):
|
||||||
|
if reference.get("url") == url and reference.get("span") == span:
|
||||||
|
return reference
|
||||||
|
return None
|
||||||
|
|
||||||
|
# -- checks ------------------------------------------------------------
|
||||||
|
def check_cli_identity(self, expected_sha256: str | None) -> None:
|
||||||
|
version = subprocess.run([str(self.cli), "--version"], capture_output=True, text=True)
|
||||||
|
self.require("cli-version", version.returncode == 0 and bool(version.stdout.strip()), version.stdout.strip())
|
||||||
|
digest = "sha256:" + hashlib.sha256(self.cli.read_bytes()).hexdigest()
|
||||||
|
self.facts["cli"] = {
|
||||||
|
"path": str(self.cli),
|
||||||
|
"version": version.stdout.strip(),
|
||||||
|
"sha256": digest,
|
||||||
|
"platform": {"system": platform.system(), "machine": platform.machine()},
|
||||||
|
}
|
||||||
|
if expected_sha256:
|
||||||
|
self.require(
|
||||||
|
"cli-pinned-digest",
|
||||||
|
digest == expected_sha256,
|
||||||
|
f"CLI digest {digest} vs expected {expected_sha256}",
|
||||||
|
)
|
||||||
|
|
||||||
|
def check_entry(self) -> dict:
|
||||||
|
module = self.analyze(self.root / ENTRY)
|
||||||
|
self.require(
|
||||||
|
"entry-source-identity",
|
||||||
|
len(module.get("source_digest", "")) == 64,
|
||||||
|
f"source_digest={module.get('source_digest')}",
|
||||||
|
)
|
||||||
|
unit = self.unit_by_anchor(module, DESIGN_H2_ANCHOR)
|
||||||
|
self.require("design-unit-anchor", unit is not None, f"anchor {DESIGN_H2_ANCHOR!r}")
|
||||||
|
assert unit is not None
|
||||||
|
self.require(
|
||||||
|
"design-unit-shape",
|
||||||
|
unit.get("kind") == "knowledge"
|
||||||
|
and unit.get("level") == 2
|
||||||
|
and unit.get("heading_span")
|
||||||
|
and unit.get("span"),
|
||||||
|
f"unit kind/level/spans: {unit.get('kind')}/{unit.get('level')}/{bool(unit.get('heading_span'))}",
|
||||||
|
)
|
||||||
|
return module
|
||||||
|
|
||||||
|
def check_components_table(self, module: dict) -> tuple[dict, dict]:
|
||||||
|
section = next(
|
||||||
|
(
|
||||||
|
unit
|
||||||
|
for unit in module["units"]
|
||||||
|
if unit.get("name") == COMPONENTS_SECTION and unit.get("level") == 3
|
||||||
|
),
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
self.require("components-section", section is not None, f"H3 {COMPONENTS_SECTION!r}")
|
||||||
|
assert section is not None
|
||||||
|
tables = [
|
||||||
|
node
|
||||||
|
for node in self.children(module["document"], "table")
|
||||||
|
if node["span"]["start"] >= section["span"]["start"]
|
||||||
|
and node["span"]["end"] <= section["span"]["end"]
|
||||||
|
]
|
||||||
|
self.require("components-table-is-ast", len(tables) == 1, f"{len(tables)} GFM table(s) in section")
|
||||||
|
table = tables[0]
|
||||||
|
rows = list(self.children(table, "table_row"))
|
||||||
|
self.require("components-table-rows", len(rows) >= 2, f"{len(rows)} rows")
|
||||||
|
header = rows[0]
|
||||||
|
self.require("components-table-header-row", header.get("header") is True, "first row is header")
|
||||||
|
header_cells = list(self.children(header, "table_cell"))
|
||||||
|
texts = [self.text(module, cell["span"]).strip() for cell in header_cells]
|
||||||
|
self.require(
|
||||||
|
"components-table-header",
|
||||||
|
texts == COMPONENTS_HEADER,
|
||||||
|
f"header cells {texts!r}",
|
||||||
|
)
|
||||||
|
self.facts["components_table"] = {
|
||||||
|
"span": table["span"],
|
||||||
|
"rows": len(rows),
|
||||||
|
"header": texts,
|
||||||
|
"alignments": table.get("alignments"),
|
||||||
|
}
|
||||||
|
return table, section
|
||||||
|
|
||||||
|
def check_component_links(self, module: dict, table: dict, section: dict) -> list[dict]:
|
||||||
|
rows = list(self.children(table, "table_row"))[1:]
|
||||||
|
self.require("component-rows-present", bool(rows), "no component rows")
|
||||||
|
links = []
|
||||||
|
for index, row in enumerate(rows, start=1):
|
||||||
|
cells = list(self.children(row, "table_cell"))
|
||||||
|
self.require("component-row-cells", len(cells) == 4, f"row {index}: {len(cells)} cells")
|
||||||
|
component_cell = cells[2]
|
||||||
|
cell_links = list(self.children(component_cell, "link"))
|
||||||
|
self.require("component-cell-one-link", len(cell_links) == 1, f"row {index}: {len(cell_links)} links")
|
||||||
|
link = cell_links[0]
|
||||||
|
cell_text = self.text(module, component_cell["span"])
|
||||||
|
link_text = self.text(module, link["span"])
|
||||||
|
self.require(
|
||||||
|
"component-cell-link-only",
|
||||||
|
cell_text.strip() == link_text.strip(),
|
||||||
|
f"row {index} cell content {cell_text!r}",
|
||||||
|
)
|
||||||
|
reference = self.reference_for(module, link["url"], link["span"])
|
||||||
|
self.require(
|
||||||
|
"component-link-has-reference",
|
||||||
|
reference is not None,
|
||||||
|
f"row {index}: reference for {link['url']}: {reference is not None}",
|
||||||
|
)
|
||||||
|
assert reference is not None
|
||||||
|
candidate = reference.get("candidate_path")
|
||||||
|
fragment = reference.get("fragment")
|
||||||
|
self.require(
|
||||||
|
"component-link-candidate",
|
||||||
|
bool(candidate) and bool(fragment) and not Path(candidate).is_absolute()
|
||||||
|
and ".." not in Path(candidate).parts,
|
||||||
|
f"row {index}: candidate_path={candidate!r} fragment={fragment!r}",
|
||||||
|
)
|
||||||
|
self.require(
|
||||||
|
"component-link-state",
|
||||||
|
reference.get("state") in ("not_loaded", "resolved"),
|
||||||
|
f"row {index}: state={reference.get('state')!r}",
|
||||||
|
)
|
||||||
|
links.append(
|
||||||
|
{
|
||||||
|
"row": index,
|
||||||
|
"url": link["url"],
|
||||||
|
"span": link["span"],
|
||||||
|
"cell_span": component_cell["span"],
|
||||||
|
"reference_state": reference.get("state"),
|
||||||
|
"candidate_path": candidate,
|
||||||
|
"fragment": fragment,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
self.facts["design_links"] = links
|
||||||
|
return links
|
||||||
|
|
||||||
|
def check_target_anchors(self, links: list[dict]) -> None:
|
||||||
|
resolved = []
|
||||||
|
for link in links:
|
||||||
|
target = (self.root / link["candidate_path"]).resolve()
|
||||||
|
self.require(
|
||||||
|
"target-inside-root",
|
||||||
|
target.is_file() and str(target).startswith(str(self.root.resolve())),
|
||||||
|
f"{link['candidate_path']} exists inside --root: "
|
||||||
|
f"{target.is_file() and str(target).startswith(str(self.root.resolve()))}",
|
||||||
|
)
|
||||||
|
module = self.analyze(target)
|
||||||
|
unit = self.unit_by_anchor(module, link["fragment"])
|
||||||
|
self.require(
|
||||||
|
"target-anchor-resolves",
|
||||||
|
unit is not None and unit.get("kind") == "knowledge",
|
||||||
|
f"{link['candidate_path']}#{link['fragment']} did not resolve to a Knowledge H2",
|
||||||
|
)
|
||||||
|
resolved.append(
|
||||||
|
{
|
||||||
|
"candidate_path": link["candidate_path"],
|
||||||
|
"fragment": link["fragment"],
|
||||||
|
"target_module_id": module["id"],
|
||||||
|
"target_source_digest": module["source_digest"],
|
||||||
|
"target_unit_id": unit["id"],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
self.facts["resolved_targets"] = resolved
|
||||||
|
|
||||||
|
def check_negative_fixtures(self) -> None:
|
||||||
|
fixtures = self.work / "negative"
|
||||||
|
fixtures.mkdir(parents=True, exist_ok=True)
|
||||||
|
(fixtures / "target.mq.md").write_text("# 目标页\n\n## @knowledge 目标组件\n\n正文。\n")
|
||||||
|
(fixtures / "plain-link.mq.md").write_text(
|
||||||
|
"# 普通文档\n\n## 正文\n\n见 [目标](target.mq.md#目标组件)。\n"
|
||||||
|
)
|
||||||
|
(fixtures / "missing-anchor.mq.md").write_text(
|
||||||
|
"## @knowledge 页面\n\n### 组件\n\n| 行 | 槽 | 组件 | 宽度 |\n| --- | --- | --- | --- |\n"
|
||||||
|
"| 1 | a | [缺失](target.mq.md#不存在) | 1fr |\n"
|
||||||
|
)
|
||||||
|
plain = self.analyze(fixtures / "plain-link.mq.md")
|
||||||
|
plain_tables = list(self.children(plain["document"], "table"))
|
||||||
|
plain_refs = plain.get("references", [])
|
||||||
|
self.require(
|
||||||
|
"negative-plain-link-not-a-table",
|
||||||
|
not plain_tables and any(r.get("candidate_path") == "target.mq.md" for r in plain_refs),
|
||||||
|
"ordinary paragraph link must stay a normal reference, not a component table row",
|
||||||
|
)
|
||||||
|
missing = self.analyze(fixtures / "missing-anchor.mq.md")
|
||||||
|
missing_ref = next(
|
||||||
|
(r for r in missing.get("references", []) if r.get("fragment") == "不存在"), None
|
||||||
|
)
|
||||||
|
self.require(
|
||||||
|
"negative-missing-anchor-has-candidate",
|
||||||
|
missing_ref is not None and missing_ref.get("state") == "not_loaded",
|
||||||
|
"missing anchor must still expose candidate_path/fragment for a deterministic rejection",
|
||||||
|
)
|
||||||
|
self.facts["negative_fixtures"] = {
|
||||||
|
"plain_link": {"tables": len(plain_tables), "references": len(plain_refs)},
|
||||||
|
"missing_anchor": {
|
||||||
|
"state": missing_ref.get("state") if missing_ref else None,
|
||||||
|
"candidate_path": missing_ref.get("candidate_path") if missing_ref else None,
|
||||||
|
"fragment": missing_ref.get("fragment") if missing_ref else None,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
def run(self, expected_sha256: str | None) -> dict:
|
||||||
|
self.check_cli_identity(expected_sha256)
|
||||||
|
module = self.check_entry()
|
||||||
|
table, section = self.check_components_table(module)
|
||||||
|
links = self.check_component_links(module, table, section)
|
||||||
|
self.check_target_anchors(links)
|
||||||
|
self.check_negative_fixtures()
|
||||||
|
gaps = []
|
||||||
|
facts = self.facts
|
||||||
|
if "components_table" not in facts:
|
||||||
|
gaps.append("Analysis does not expose the GFM table AST needed by the contract")
|
||||||
|
if "design_links" not in facts:
|
||||||
|
gaps.append("Analysis does not expose design link references with candidate_path/fragment")
|
||||||
|
if "resolved_targets" not in facts:
|
||||||
|
gaps.append("Analysis cannot resolve target Knowledge H2 anchors")
|
||||||
|
failures = [check for check in self.checks if check["status"] == "FAIL"]
|
||||||
|
repo_sha = None
|
||||||
|
if (REPO / ".git").exists():
|
||||||
|
repo_sha = subprocess.run(
|
||||||
|
["git", "-C", str(REPO), "rev-parse", "HEAD"], capture_output=True, text=True
|
||||||
|
).stdout.strip()
|
||||||
|
return {
|
||||||
|
"schema": "marqdo.web-analysis-probe",
|
||||||
|
"schema_version": 1,
|
||||||
|
"status": "PASS" if not failures and not gaps else "FAIL",
|
||||||
|
"repository": {"sha": repo_sha},
|
||||||
|
"inputs": self.inputs,
|
||||||
|
"facts": facts,
|
||||||
|
"checks": self.checks,
|
||||||
|
"gaps": gaps,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def main(argv: list[str]) -> int:
|
||||||
|
parser = argparse.ArgumentParser(description=__doc__)
|
||||||
|
parser.add_argument("--cli", required=True)
|
||||||
|
parser.add_argument("--root", default=str(DEFAULT_ROOT))
|
||||||
|
parser.add_argument("--out", default=None)
|
||||||
|
parser.add_argument("--expected-cli-sha256", default=None)
|
||||||
|
parser.add_argument("--json", action="store_true")
|
||||||
|
args = parser.parse_args(argv)
|
||||||
|
cli = Path(args.cli).resolve()
|
||||||
|
if not cli.is_file():
|
||||||
|
print(f"risk-probe: error: no CLI executable at {cli}", file=sys.stderr)
|
||||||
|
return 2
|
||||||
|
work = Path(tempfile.mkdtemp(prefix="marqdo-web00-"))
|
||||||
|
try:
|
||||||
|
report = Probe(cli, Path(args.root).resolve(), work).run(
|
||||||
|
args.expected_cli_sha256
|
||||||
|
)
|
||||||
|
except ProbeError as error:
|
||||||
|
print(f"risk-probe: FAIL: {error}", file=sys.stderr)
|
||||||
|
return 1
|
||||||
|
finally:
|
||||||
|
shutil.rmtree(work, ignore_errors=True)
|
||||||
|
text = json.dumps(report, ensure_ascii=False, indent=2) + "\n"
|
||||||
|
if args.out:
|
||||||
|
out = Path(args.out)
|
||||||
|
out.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
out.write_text(text)
|
||||||
|
if args.json:
|
||||||
|
print(text, end="")
|
||||||
|
else:
|
||||||
|
print(f"WEB-00 Analysis probe: {report['status']}")
|
||||||
|
for check in report["checks"]:
|
||||||
|
print(f" {check['status']} {check['id']}: {check['detail']}")
|
||||||
|
for gap in report["gaps"]:
|
||||||
|
print(f" GAP {gap}")
|
||||||
|
return 0 if report["status"] == "PASS" else 1
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
raise SystemExit(main(sys.argv[1:]))
|
||||||
Reference in new issue
Block a user