Files
swarm-house/simulator/tests/test_check_docs.py
T
eSlider 826cef0c3e
CI & Release / Verify documentation (push) Skipped
CI & Release / Verify simulator (push) Skipped
CI & Release / Trivy scan (push) Skipped
CI & Release / Semantic Release (push) Skipped
CI & Release / Verify documentation (pull_request) Successful in 4s
CI & Release / Verify simulator (pull_request) Successful in 11s
CI & Release / Trivy scan (pull_request) Successful in 8s
CI & Release / Semantic Release (pull_request) Skipped
fix: drop PyYAML dep so verify job pytest passes
Store doc rules in bin/docs_rules.json (stdlib json). test_check_docs no
longer fails in the simulator job that only installs simulator/requirements.txt.
2026-07-10 11:02:55 +01:00

78 lines
2.2 KiB
Python

"""Tests for bin/check_docs.py — documentation CI rules."""
from __future__ import annotations
import json
import sys
from pathlib import Path
import pytest
SCRIPTS = Path(__file__).resolve().parents[2] / "bin"
sys.path.insert(0, str(SCRIPTS))
from check_docs import ( # noqa: E402
collect_anchors,
run_checks,
slug_heading,
split_link_target,
)
ROOT = Path(__file__).resolve().parents[2]
GLOSSARY = ROOT / "docs/00-glossary.md"
def test_slug_heading_matches_glossary_anchors() -> None:
assert slug_heading("T0 — hot") == "t0--hot"
assert slug_heading("T3 — warehouse") == "t3--warehouse"
assert slug_heading("Source of truth") == "source-of-truth"
assert slug_heading("Data & storage") == "data--storage"
def test_glossary_term_anchors_exist() -> None:
anchors = collect_anchors(GLOSSARY)
for term in (
"t0--hot",
"t1--warm",
"t2--shared",
"t3--warehouse",
"t4--dev",
"source-of-truth",
"bulk-sync",
"offload",
):
assert term in anchors, f"missing glossary anchor #{term}"
def test_split_link_target() -> None:
assert split_link_target("foo.md#bar") == ("foo.md", "bar")
assert split_link_target("foo.md") == ("foo.md", None)
def test_repo_docs_pass() -> None:
assert run_checks() == 0
def test_broken_link_detected(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
docs = tmp_path / "docs"
docs.mkdir()
(docs / "00-glossary.md").write_text("# Glossary\n\n## Data & storage\n")
(docs / "bad.md").write_text("See [missing](missing.md).\n")
rules = tmp_path / "bin"
rules.mkdir()
(rules / "docs_rules.json").write_text(
json.dumps(
{
"markdown_paths": ["docs/**/*.md"],
"glossary": {"file": "docs/00-glossary.md"},
"banned_link_targets": [],
"glossary_section_anchors": [],
"preferred_term_anchors": [],
"readability": {"forbid_bare_see_refs": False},
}
)
)
monkeypatch.setattr("check_docs.ROOT", tmp_path)
monkeypatch.setattr("check_docs.RULES_PATH", rules / "docs_rules.json")
assert run_checks() == 1