-
Notifications
You must be signed in to change notification settings - Fork 1
feat(docs-12): docs command validation and cross-site link checks #449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
openspec/changes/docs-12-docs-validation-ci/TDD_EVIDENCE.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
35 changes: 17 additions & 18 deletions
35
openspec/changes/docs-12-docs-validation-ci/specs/docs-command-validation/spec.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
32 changes: 19 additions & 13 deletions
32
...pec/changes/docs-12-docs-validation-ci/specs/docs-cross-site-link-check/spec.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| 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}" | ||
|
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}") | ||
|
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()) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.