Repository navigation
Description
Summary
The docs evaluation workflow gives contributors inconsistent instructions for calculating, registering, inspecting, and comparing a metric. It also obscures why an apparently matching document was excluded when reporting an input-count failure.
Scenarios (5)
1. The link_validity example counts an external URL against a valid intra-doc link.
docs/contributing-metric.md:28 defines link_validity as the fraction of intra-doc links that resolve to a known anchor. With known_anchors={"known"}, the inputs are [local](#known) alone and [local](#known) [external](https://example.invalid/).
On 50ea6312, the example prints local=1.0 and with_external=0.5. Both inputs should score 1.0 because each has one intra-doc link and that link resolves.
python - <<'PY'
import re
from pathlib import Path
guide = Path("docs/contributing-metric.md").read_text()
module = re.search(r"^```python\n(.*?)^```", guide, re.M | re.S)[1]
scope = {}
exec(module, scope)
anchor = "[local](#known)"
score = scope["score"]
print(f"local={score(anchor, known_anchors={'known'})}")
print(f"with_external={score(anchor + ' [external](https://example.invalid/)', known_anchors={'known'})}")
PY2. docs check rejects link_validity in a document row after the documented registration.
docs/contributing-metric.md adds link_validity to the runner, the per-document output, benchmarks/spec.v1.yaml, and dokimi/runner/spec.schema.json.
On 50ea6312, docs check exits 1 and reports docs/0: Additional properties are not allowed ('link_validity' was unexpected). The new score is 1 in baselines/current.json.rejected.
The guide says the new metric should appear in baselines/current.json and contribute to the weighted score. The command below runs the attached metric-registration.sh from dokimi/.
export DOKIMI_PROJECT="$PWD"
sed -e 's|^source=.*|source="$DOKIMI_PROJECT"|' \
-e 's|^source = Path(.*)$|source = Path(__import__("os").environ["DOKIMI_PROJECT"])|' \
metric-registration.sh | shmetric-registration.sh
#!/bin/sh
set -eu
work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT
source=.
cd "$work"
mkdir -p docs benchmarks
cp "$source/cli.py" cli.py
cp "$source/benchmarks/spec.v1.yaml" benchmarks/spec.v1.yaml
for n in 0 1 2 3 4 5 6 7 8 9; do
printf '# Anchor\n\nSee [known](#anchor) and [missing](#missing).\n' > "docs/$n.md"
done
cp -R "$source/dokimi" dokimi
cp "$source/README.md" README.md
mkdir -p tests
python - <<'PY'
import re
from pathlib import Path
source = Path(".")
guide = (source / "docs/contributing-metric.md").read_text()
module, unit = re.findall(r"^```python\n(.*?)^```", guide, re.M | re.S)
import json
import yaml
# Section 1.
Path("dokimi/metrics/link_validity.py").write_text(module)
# Section 2.
runner = Path("dokimi/runner/run.py")
text = runner.read_text()
for old, new in (
("from dokimi.metrics import coverage, freshness_lite, readability",
"from dokimi.metrics import coverage, freshness_lite, link_validity, readability"),
(' manifest = spec.get("golden_manifest")',
' link_cfg = spec["metrics"].get("link_validity", {})\n'
' if link_cfg.get("enabled", False):\n'
' active_metrics.append("link_validity")\n\n'
' manifest = spec.get("golden_manifest")'),
(' row["score"] = _weighted_score(row, weights, active_metrics)',
' if "link_validity" in active_metrics:\n'
' row["link_validity"] = link_validity.score(text)\n'
' row["score"] = _weighted_score(row, weights, active_metrics)'),
(' docs_out.append(d)',
' if "link_validity" in row:\n'
' d["link_validity"] = row["link_validity"]\n'
' docs_out.append(d)'),
):
assert text.count(old) == 1, old
text = text.replace(old, new)
runner.write_text(text)
# Section 3.
spec_path = Path("benchmarks/spec.v1.yaml")
spec = yaml.safe_load(spec_path.read_text())
example = yaml.safe_load(re.search(r"^```yaml\n(.*?)^```", guide, re.M | re.S)[1])
for section in ("weights", "metrics"):
spec[section].update(example[section])
spec_path.write_text(yaml.safe_dump(spec, sort_keys=False))
schema_path = Path("dokimi/runner/spec.schema.json")
schema = json.loads(schema_path.read_text())
weights = schema["properties"]["weights"]["properties"]
metrics = schema["properties"]["metrics"]["properties"]
weights["link_validity"] = weights["coverage"]
metrics["link_validity"] = metrics["coverage"]
schema_path.write_text(json.dumps(schema, indent=2) + "\n")
# Section 4.
Path("tests/test_link_validity.py").write_text(unit)
PY
cat > tests/test_link_validity_integration.py <<'PY'
import json
from pathlib import Path
import subprocess
import sys
def test_link_validity_flows_through_docs_check():
run = subprocess.run(
[sys.executable, "cli.py", "docs", "check", "--root", ".",
"--spec", "benchmarks/spec.v1.yaml", "--out", "baselines/current.json",
"--out-md", "reports/current.md"],
capture_output=True, text=True,
)
assert run.returncode == 0, run.stdout + run.stderr
row = json.loads(Path("baselines/current.json").read_text())["docs"][0]
assert "link_validity" in row, "snapshot omits link_validity"
assert 0 <= row["link_validity"] <= 1
PY
python -m pytest -q -p no:cacheprovider tests/test_link_validity.py
unit_rc=0
python -m pytest -q -p no:cacheprovider tests/test_link_validity_integration.py || unit_rc=$?
# Section 5.
python - <<'PY'
from pathlib import Path
readme = Path("README.md")
text = readme.read_text()
old = "currently uses four active metrics:"
assert text.count(old) == 1
text = text.replace(old, "currently uses five active metrics:")
old = "| `example_pass_rate` | Executes supported fenced code examples in isolation. |"
assert text.count(old) == 1
text = text.replace(old, old + "\n| `link_validity` | Scores anchor link validity. |")
readme.write_text(text)
PY
# Section 6.
check_rc=0
python cli.py docs check --root . --spec benchmarks/spec.v1.yaml --out baselines/current.json --out-md reports/current.md || check_rc=$?
printf 'integration exit=%s\n' "$unit_rc"
printf 'docs check exit=%s\n' "$check_rc"
if test -s baselines/current.json.rejected; then
jq -ce '{rejected_doc_metric:.docs[0].link_validity,weighted_score:.docs[0].score}' baselines/current.json.rejected
fi
if test -s baselines/current.json; then
jq -ce '{saved_doc_metric:.docs[0].link_validity}' baselines/current.json
fi3. The jq selector in contributing-metric.md prints null on a populated snapshot.
baselines/current.json is the snapshot from docs check on ten Markdown files using benchmarks/spec.v1.yaml.
On 50ea6312, docs check exits 0 and the guide's jq '.documents[0].metrics' prints null. The snapshot stores coverage and score directly under .docs[0].
The example should show the first document's metric scores.
set -e
root=$(mktemp -d)
mkdir "$root/docs"
for n in 0 1 2 3 4 5 6 7 8 9; do
printf '# Anchor\n\nSee [known](#anchor) and [missing](#missing).\n' > "$root/docs/$n.md"
done
python cli.py docs check --root "$root" --spec benchmarks/spec.v1.yaml \
--out "$root/baselines/current.json" --out-md "$root/reports/current.md"
jq '.documents[0].metrics' "$root/baselines/current.json"
jq -c '.docs[0] | {path, coverage, score}' "$root/baselines/current.json"4. docs compare omits link_validity from the diff when only the candidate snapshot has it.
baselines/baseline.json comes from docs check. baselines/current.json is derived from that snapshot with link_validity=0.5 and scores recomputed using the guide's weights.
On 50ea6312, docs compare exits 0 and reports a score delta of -0.0049. In reports/compare.json, .candidate.link_validity is 0.5 and .diff has no link_validity entry.
docs/contributing-metric.md:139 says the compare command picks up the new metric automatically. The comparison should show that link_validity was added.
set -e
root=$(mktemp -d)
mkdir "$root/docs"
for n in 0 1 2 3 4 5 6 7 8 9; do
printf '# Anchor\n\nSee [known](#anchor) and [missing](#missing).\n' > "$root/docs/$n.md"
done
python cli.py docs check --root "$root" --spec benchmarks/spec.v1.yaml \
--out "$root/baselines/baseline.json" --out-md "$root/reports/current.md"
jq '(.docs[].link_validity) = 0.5 | .summary.link_validity = 0.5
| .docs |= map(.score = ((10000 * (0.30 * .coverage + 0.20 * .freshness_lite
+ 0.15 * .readability + 0.20 * .example_pass_rate + 0.15 * .link_validity))
| round / 10000))
| .summary.score = .docs[0].score' \
"$root/baselines/baseline.json" > "$root/baselines/current.json"
python cli.py docs compare --baseline "$root/baselines/baseline.json" \
--candidate "$root/baselines/current.json" --spec benchmarks/spec.v1.yaml \
--out "$root/reports/compare.json" --out-md "$root/reports/compare.md"
jq -c '{candidate_metric: .candidate.link_validity,
delta_has_metric: (.diff | has("link_validity")),
overall_delta_nonzero: (.diff.score != 0)}' "$root/reports/compare.json"5. docs check min_docs refusal does not say that symlinked .md files are skipped
Input: a root with docs/d1.md to docs/d9.md as regular files and docs/ten.md as a symlink to a Markdown file outside the root.
python cli.py docs check --root <root> exits 2 with Error: golden_manifest violation: matched 9 document(s) under <root>, fewer than min_docs=10. include=['docs/**/*.md'] exclude=['docs/archive/**']. The skipped link docs/ten.md is not named and links are not mentioned.
The same happens when docs itself is a symlink to a directory of 11 files: exit 2, matched 0 document(s), no word about links. Symlinked files are never scored and no outside path reaches the snapshot or report, so the skipping is sound. Expected: the message names the skipped link or says that symlinks are skipped, so the reader can tell why existing files did not match. The message is built at runner/spec.py:136.
mkdir -p root/docs outside && echo '# O' > outside/o.md && for i in 1 2 3 4 5 6 7 8 9; do printf "# Doc $i\n\nText.\n" > root/docs/d$i.md; done && ln -s "$PWD/outside/o.md" root/docs/ten.md
python cli.py docs check --root root --out s.json
Tests are attached as tests/test_docs_check_skipped_link.py and tests/test_docs_check_linked_docs.py; both fail on 50ea6312.
tests/test_docs_check_skipped_link.py
import subprocess
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
def test_min_docs_refusal_names_skipped_link(tmp_path: Path) -> None:
docs = tmp_path / "root" / "docs"
docs.mkdir(parents=True)
outside = tmp_path / "outside"
outside.mkdir()
(outside / "o.md").write_text("# O\n", encoding="utf-8")
for i in range(1, 10):
(docs / f"d{i}.md").write_text(f"# Doc {i}\n\nText.\n", encoding="utf-8")
(docs / "ten.md").symlink_to(outside / "o.md")
run = subprocess.run(
[sys.executable, str(ROOT / "cli.py"), "docs", "check", "--root", str(tmp_path / "root"),
"--out", str(tmp_path / "s.json")],
capture_output=True, text=True, cwd=ROOT,
)
out = run.stdout + run.stderr
assert "Traceback" not in out, out
assert run.returncode == 2, out
assert "ten.md" in out or "link" in out, outtests/test_docs_check_linked_docs.py
# Copyright (C) 2026 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
import subprocess
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
def test_zero_match_message_explains_docs_alias(tmp_path: Path) -> None:
real = tmp_path / "real"
root = tmp_path / "root"
real.mkdir()
root.mkdir()
for i in range(1, 12):
(real / f"d{i}.md").write_text(f"# Doc {i}\n\nSome text.\n", encoding="utf-8")
(root / "docs").symlink_to(real, target_is_directory=True)
run = subprocess.run(
[sys.executable, str(ROOT / "cli.py"), "docs", "check", "--root", str(root),
"--out", str(tmp_path / "s.json")],
capture_output=True, text=True, cwd=ROOT,
)
out = (run.stdout + run.stderr).replace(str(tmp_path), "").lower()
assert run.returncode == 2, out
assert "link" in out, out
Activity