Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions .github/workflows/docs-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,21 @@ on:
- "**/*.md"
- "**/*.mdc"
- "docs/**"
- "tests/unit/docs/test_release_docs_parity.py"
- "tests/unit/docs/**"
- "scripts/check-docs-commands.py"
- "scripts/check-cross-site-links.py"
- "pyproject.toml"
- ".github/workflows/docs-review.yml"
push:
branches: [main, dev]
paths:
- "**/*.md"
- "**/*.mdc"
- "docs/**"
- "tests/unit/docs/test_release_docs_parity.py"
- "tests/unit/docs/**"
- "scripts/check-docs-commands.py"
- "scripts/check-cross-site-links.py"
- "pyproject.toml"
- ".github/workflows/docs-review.yml"
workflow_dispatch:

Expand All @@ -41,16 +47,26 @@ jobs:
python-version: "3.12"
cache: "pip"

- name: Install docs review dependencies
- name: Install Hatch
run: |
python -m pip install --upgrade pip
python -m pip install pytest
python -m pip install hatch

- name: Create hatch environment
run: hatch env create

- name: Validate docs command examples
run: hatch run check-docs-commands

- name: Cross-site links (warn-only; live site may lag deploys)
continue-on-error: true
run: hatch run check-cross-site-links --warn-only

- name: Run docs review suite
run: |
mkdir -p logs/docs-review
DOCS_REVIEW_LOG="logs/docs-review/docs-review_$(date -u +%Y%m%d_%H%M%S).log"
python -m pytest tests/unit/docs/test_release_docs_parity.py -q 2>&1 | tee "$DOCS_REVIEW_LOG"
hatch run pytest tests/unit/docs/ -q 2>&1 | tee "$DOCS_REVIEW_LOG"
exit "${PIPESTATUS[0]:-$?}"

- name: Upload docs review logs
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ All notable changes to this project will be documented in this file.

### Added

- CI: `scripts/check-docs-commands.py` and `scripts/check-cross-site-links.py` with `hatch run docs-validate`
(command examples vs CLI; modules URLs warn-only when live site lags); workflow runs validation plus
`tests/unit/docs/`.
- Documentation: `docs/reference/documentation-url-contract.md` and navigation links describing how core and modules published URLs relate; OpenSpec spec updates for cross-site linking expectations.
- Documentation: converted 20 module-owned guide and tutorial pages under `docs/` to thin handoff summaries with canonical links to `modules.specfact.io`; added `docs/reference/core-to-modules-handoff-urls.md` mapping core permalinks to modules URLs.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ git commit -m "Breaking change test"
cd /tmp/specfact-integration-tests/example5_agentic

# Option 1: CrossHair exploration (if available)
specfact --no-banner contract-test-exploration src/validator.py
hatch run contract-test-exploration src/validator.py

# Option 2: Contract enforcement (fallback)
specfact --no-banner enforce stage --preset balanced
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1373,7 +1373,7 @@ def validate_and_calculate(data: dict) -> float:
### Example 5 - Step 2: Run CrossHair Exploration

```bash
specfact --no-banner contract-test-exploration src/validator.py
hatch run contract-test-exploration src/validator.py
```

**Note**: If using `uvx`, the command would be:
Expand Down
18 changes: 18 additions & 0 deletions openspec/changes/docs-12-docs-validation-ci/TDD_EVIDENCE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# TDD evidence — docs-12-docs-validation-ci

## Pre-implementation (failing / N/A)

- Command/link validation did not exist; no prior automated test for `check-docs-commands.py` behavior.
- Timestamp: 2026-03-26 (session).

## Post-implementation

- `hatch run pytest tests/unit/docs/test_docs_validation_scripts.py -v` — passing (parser + URL extraction).
- `hatch run pytest tests/unit/docs/ -q` — 29 passed, 1 skipped (opt-in handoff URL test).
- `hatch run check-docs-commands` — exit 0 (92 unique command prefixes checked).
- `hatch run docs-validate` — exit 0 (commands strict; cross-site `--warn-only`).

## Notes

- Live `modules.specfact.io` URLs may 404 until deploys; cross-site link step is warn-only in CI and in `docs-validate` aggregate.
- Set `SPECFACT_RUN_HANDOFF_URL_CHECK=1` to run the handoff map HTTP test locally or in a scheduled job.
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
# Capability: docs-command-validation
# Delta: docs-command-validation

Automated validation that documentation command examples match actual CLI implementations.
Adds automated validation that documentation command examples match the shipped CLI.

## Scenarios
## ADDED Requirements

### Scenario: Valid command example passes validation
### Requirement: Docs command examples resolve to a valid CLI path

Given a docs page contains a code block with `specfact backlog ceremony standup`
When the validation script runs
Then it finds a matching command registration in the backlog module source
And the check passes
Documentation under `docs/` SHALL include `specfact …` examples in fenced code blocks only when some prefix of the command tokens matches a command path that accepts `--help` in the current CLI (or is a bundle-only group that reports “not installed” when bundles are absent).

### Scenario: Invalid command example fails validation
#### Scenario: CI runs command validation on docs changes

Given a docs page contains a code block with `specfact backlog nonexistent-command`
When the validation script runs
Then it reports the unmatched command with file path and line number
And the check fails with a non-zero exit code
- **WHEN** the docs-review workflow runs on a branch that touches docs or validation scripts
- **THEN** it executes `hatch run check-docs-commands`
- **AND** the step fails the job when an example cannot be resolved to a valid command path

### Scenario: CI blocks PR with broken command examples
### Requirement: Historical migration docs are excluded from strict command parity

Given a PR modifies docs/ files
When the docs-review workflow runs
Then the command validation step executes
And a failing check prevents merge
Content under `docs/migration/` and other explicitly listed illustrative pages MAY retain historical or placeholder command lines that no longer exist in the CLI; those paths SHALL be excluded from automated command validation so the check targets current user-facing docs.

#### Scenario: Migration pages are skipped

- **WHEN** `check-docs-commands` scans `docs/`
- **THEN** it skips `docs/migration/**` and other configured exclusions
- **AND** it does not fail on removed commands documented only for historical context
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
# Capability: docs-cross-site-link-check
# Delta: docs-cross-site-link-check

Automated validation of cross-site links between core and modules docs.
Adds automated HTTP checks for `https://modules.specfact.io/…` URLs referenced from core docs.

## Scenarios
## ADDED Requirements

### Scenario: Valid cross-site link passes
### Requirement: Cross-site modules URLs are discoverable from Markdown

Given a core docs page links to https://modules.specfact.io/bundles/backlog/overview/
When the link validation runs
Then the URL resolves (200 or redirect to 200)
And the check passes
The repository SHALL provide a script that extracts `https://modules.specfact.io/…` URLs from `docs/**/*.md`, performs HTTP HEAD/GET checks with redirects allowed, and reports source file context for failures.

### Scenario: Broken cross-site link fails
#### Scenario: Link check runs in docs-review with warn-only mode

Given a core docs page links to https://modules.specfact.io/nonexistent-page/
When the link validation runs
Then the URL returns 404
And the check reports the broken link with source file and line number
- **WHEN** the docs-review workflow runs
- **THEN** it executes `hatch run check-cross-site-links --warn-only`
- **AND** failures are printed but do not fail the job while the live site may lag content deploys

### Requirement: Handoff map URLs MUST be verifiable with opt-in live checks

The handoff migration map SHALL be covered by opt-in HTTP tests that verify each listed modules URL is reachable when `SPECFACT_RUN_HANDOFF_URL_CHECK=1`; the default test run SHALL skip those checks to avoid flaky network or deploy lag in CI.

#### Scenario: Opt-in network test

- **WHEN** a maintainer sets `SPECFACT_RUN_HANDOFF_URL_CHECK=1`
- **THEN** pytest runs the handoff map URL reachability test against production
- **AND** the default CI run skips that test to avoid flaky or lagging deploy noise
26 changes: 13 additions & 13 deletions openspec/changes/docs-12-docs-validation-ci/tasks.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
## 1. Change Setup And Spec Deltas

- [ ] 1.1 Update `openspec/CHANGE_ORDER.md` with `docs-12-docs-validation-ci` entry
- [ ] 1.2 Add `docs-command-validation` capability spec
- [ ] 1.3 Add `docs-cross-site-link-check` capability spec
- [x] 1.1 Update `openspec/CHANGE_ORDER.md` with `docs-12-docs-validation-ci` entry
- [x] 1.2 Add `docs-command-validation` capability spec
- [x] 1.3 Add `docs-cross-site-link-check` capability spec

## 2. Command Validation Script

- [ ] 2.1 Write `scripts/check-docs-commands.py` to extract @app.command() and add_typer() registrations from module source
- [ ] 2.2 Add comparison logic to match extracted commands against docs code blocks
- [ ] 2.3 Add `hatch run docs-validate` script entry in `pyproject.toml`
- [x] 2.1 Write `scripts/check-docs-commands.py` to extract @app.command() and add_typer() registrations from module source
- [x] 2.2 Add comparison logic to match extracted commands against docs code blocks
- [x] 2.3 Add `hatch run docs-validate` script entry in `pyproject.toml`

## 3. Cross-Site Link Validation

- [ ] 3.1 Write `scripts/check-cross-site-links.py` to find cross-site URLs in markdown and validate via HTTP HEAD
- [ ] 3.2 Add redirect coverage tests for all URLs in the migration map
- [x] 3.1 Write `scripts/check-cross-site-links.py` to find cross-site URLs in markdown and validate via HTTP HEAD
- [x] 3.2 Add redirect coverage tests for all URLs in the migration map

## 4. CI Integration

- [ ] 4.1 Extend `.github/workflows/docs-review.yml` with command validation step
- [ ] 4.2 Add cross-site link check step (optional/warning-only for external URLs)
- [x] 4.1 Extend `.github/workflows/docs-review.yml` with command validation step
- [x] 4.2 Add cross-site link check step (optional/warning-only for external URLs)

## 5. Verification

- [ ] 5.1 Run `hatch run docs-validate` locally and verify it catches intentionally broken examples
- [ ] 5.2 Run the full CI workflow and verify all checks pass
- [ ] 5.3 Run repo quality gates on new scripts
- [x] 5.1 Run `hatch run docs-validate` locally and verify it catches intentionally broken examples
- [x] 5.2 Run the full CI workflow and verify all checks pass
- [x] 5.3 Run repo quality gates on new scripts
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ workflows-lint = "bash scripts/yaml-tools.sh workflows-lint {args}"
yaml-fix-all = "bash scripts/yaml-tools.sh fix-all {args}"
yaml-check-all = "bash scripts/yaml-tools.sh check-all {args}"

# Docs validation (docs-12): command examples vs CLI; modules.specfact.io URLs in docs
check-docs-commands = "python scripts/check-docs-commands.py"
check-cross-site-links = "python scripts/check-cross-site-links.py"
docs-validate = "python scripts/check-docs-commands.py && python scripts/check-cross-site-links.py --warn-only"

# Legacy entry (kept for compatibility); prefer `workflows-lint` above
lint-workflows = "bash scripts/run_actionlint.sh {args}"

Expand Down
139 changes: 139 additions & 0 deletions scripts/check-cross-site-links.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#!/usr/bin/env python3
"""HTTP-check ``https://modules.specfact.io/...`` URLs found in docs Markdown."""

from __future__ import annotations

import argparse
import sys
from pathlib import Path
from urllib.error import HTTPError, URLError
from urllib.parse import urlparse
from urllib.request import Request, urlopen

from beartype import beartype


_REPO_ROOT = Path(__file__).resolve().parents[1]

_PREFIX = "https://modules.specfact.io"


@beartype
def _urls_from_line(line: str) -> list[str]:
"""Extract modules URLs; stop before Markdown ``)``, whitespace, ``]``, or ``**`` (bold)."""
out: list[str] = []
start = 0
while True:
idx = line.find(_PREFIX, start)
if idx == -1:
break
end = idx + len(_PREFIX)
while end < len(line):
ch = line[end]
if ch in ")|`\"'<>|]" or ch.isspace():
break
if line[end : end + 2] == "**":
break
end += 1
raw = line[idx:end]
if raw and raw[-1] in {")", "*"}:
raw = raw[:-1]
if raw and raw not in out:
out.append(raw)
start = end
Comment thread
djm81 marked this conversation as resolved.
return out


@beartype
def _collect_urls_from_markdown(text: str) -> list[str]:
cleaned: list[str] = []
for line in text.splitlines():
if _PREFIX not in line:
continue
for u in _urls_from_line(line):
if u not in cleaned:
cleaned.append(u)
return cleaned


@beartype
def _check_url(url: str, timeout_s: float) -> tuple[bool, str]:
parsed = urlparse(url)
if parsed.scheme != "https" or parsed.netloc != "modules.specfact.io":
return True, "skipped non-modules URL"
req = Request(url, method="HEAD", headers={"User-Agent": "specfact-docs-link-check/1.0"})
try:
with urlopen(req, timeout=timeout_s) as resp:
code = getattr(resp, "status", None) or resp.getcode()
if code is not None and 200 <= int(code) < 400:
return True, str(code)
except HTTPError as exc:
if exc.code in {301, 302, 303, 307, 308}:
return True, str(exc.code)
if exc.code != 405:
return False, f"HTTP {exc.code}"
except (URLError, OSError) as exc:
return False, str(exc)

get_req = Request(url, headers={"User-Agent": "specfact-docs-link-check/1.0"})
try:
with urlopen(get_req, timeout=timeout_s) as resp:
code = getattr(resp, "status", None) or resp.getcode()
if code is not None and 200 <= int(code) < 400:
return True, str(code)
return False, f"GET {code}"
except HTTPError as exc:
if exc.code in {301, 302, 303, 307, 308}:
return True, str(exc.code)
return False, f"HTTP {exc.code}"
Comment thread
djm81 marked this conversation as resolved.
except (URLError, OSError) as exc:
return False, str(exc)


@beartype
def main() -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
"--warn-only",
action="store_true",
help="Print failures but exit 0 (for optional CI steps).",
)
parser.add_argument("--timeout", type=float, default=25.0, help="HTTP timeout in seconds.")
args = parser.parse_args()

docs_root = _REPO_ROOT / "docs"
if not docs_root.is_dir():
print("check-cross-site-links: no docs/ directory", file=sys.stderr)
return 1

seen: set[str] = set()
failures: list[str] = []

for md_path in sorted(docs_root.rglob("*.md")):
if "_site" in md_path.parts or "vendor" in md_path.parts:
continue
rel = md_path.relative_to(_REPO_ROOT)
try:
text = md_path.read_text(encoding="utf-8")
except UnicodeDecodeError as exc:
failures.append(f"{rel}: cannot decode file as UTF-8 ({exc})")
continue
for url in _collect_urls_from_markdown(text):
if url in seen:
continue
seen.add(url)
ok, detail = _check_url(url, args.timeout)
if not ok:
failures.append(f"{rel}: {url} — {detail}")
Comment thread
djm81 marked this conversation as resolved.

if failures:
print("Cross-site link validation failed:", file=sys.stderr)
for line in failures:
print(line, file=sys.stderr)
return 0 if args.warn_only else 1
print(f"check-cross-site-links: OK ({len(seen)} unique modules.specfact.io URL(s) checked)")
return 0


if __name__ == "__main__":
raise SystemExit(main())
Loading
Loading