Skip to content

fix: check documentation links on pull requests - #363

Merged
sromoam merged 6 commits into
awslabs:devfrom
hugosmoreira:bugfix/355-docs-pr-link-check
Oct 19, 2026
Merged

sromoam merged 6 commits into
awslabs:devfrom
hugosmoreira:bugfix/355-docs-pr-link-check

Conversation

@hugosmoreira

@hugosmoreira hugosmoreira commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Issue #, if available:

Fixes #355.

Description of changes:

Add a read-only PR documentation build and make check that fail on MkDocs warnings and errors, including broken page, anchor, navigation and API references. Register the existing orphan guide and report configuration errors without a traceback.

The checker tolerates each of six existing griffe annotation warnings once per build, matching logger, file and message while allowing line numbers to move. Duplicates and changed diagnostics fail. Fence the StructuredModel example as code, removing its three autorefs warnings and all autorefs exemptions. Warnings remain visible. The frozen docs-only workflow installs no Stickler package; its path-filtered status must remain non-required.

Validation against dev 6abbf26:

  • The exact prepended-comment example failed before the correction in both working directories. The regression matrix went from 33 failures / 44 passes to 77 passes; the negative control restores the same 33 failures.
  • All 77 checker tests pass on Windows Python 3.10–3.14 and Linux Python 3.12.
  • Full Linux suite under coverage: 2,856 passed, 12 skipped, one expected failure. Full Windows suite: 2,850 passed, six failures identical to unchanged dev's unavailable signal.SIGALRM, 12 skipped, one expected failure.
  • Real make check passes valid docs and rejects the planted API reference with exactly one counted diagnostic. The original stale anchor is rejected; five additional real-site controls pass. make docs serves locally, and the example renders as code.
  • Scoped lint/format, workflow lint, lock consistency, wheel/sdist builds and source Bandit pass. Whole-repository Ruff retains 16 findings identical to current dev.

macOS, the full optional-dependency matrix, ASH and ShellCheck were not run. Hosted CI requires maintainer approval. External URLs are not fetched, and Python warnings such as DeprecationWarning are outside this gate.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@sromoam sromoam left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for picking up #355, @hugosmoreira. The approach is right, and running a real MkDocs build rather than parsing Markdown is what makes this trustworthy. I ran docs/check_links.py from this branch against our actual docs and planted three broken links. All three exited 0, so the check isn't catching them yet.

Blocking

1. Missing navigation targets pass. Our site builds its nav with awesome-nav, which reports missing targets on the mkdocs.plugins.awesome-nav logger. The script only counts mkdocs.structure.pages and mkdocs.structure.nav. Adding - Does-Not-Exist.md to Guides/.nav.yml logs:

WARNING - awesome-nav: The nav item 'Does-Not-Exist.md' doesn't match any files or directories

and the check exits 0.

I'd fix this by failing closed instead of adding one more logger to the list: count every WARNING under mkdocs, and exclude only the known-noisy sources (mkdocstrings/griffe, autorefs). Then a new source of link warnings breaks CI where we can see it, instead of being ignored. That also covers awesome-nav's ERROR-level .nav.yml parse failures, which pass today too.

2. Extensionless and absolute links pass. Only anchors and not_found are raised to WARNING. unrecognized_links and absolute_links stay at INFO, so [x](Nope/) and [x](/nope.md) both exit 0.

3. The tests don't exercise our real config. test_missing_navigation_target_fails uses a mkdocs nav: key with plugins: []. Our mkdocs.yml has no nav: and relies on awesome-nav .nav.yml files, which is why #1 got past 17 passing tests. One fixture that loads awesome-nav with a .nav.yml pointing at a missing page would pin it.

4. docs/README.md:50 still says mkdocs build "validates all internal links and references". The new paragraph right below it says the opposite, which is the premise of the PR. Please update or remove that line.

Smaller

  • Set the levels in mkdocs.yml rather than in the script. A validation: block would make mkdocs serve show the same warnings locally that CI fails on. As written, an author sees nothing locally and then CI fails, and any level set in mkdocs.yml is silently overridden.
  • The "Test documentation check" step duplicates run_pytest.yaml, which already collects tests/test_docs_build.py on 5 Python versions. I'd drop the step.
  • Add a paths filter and a concurrency group to docs-check.yml. Right now every PR, including ones that only touch tests, installs the whole dev group and builds the site. uv sync --no-default-groups --group docs would also make the install lighter.
  • test_pr_workflow_only_builds_with_read_permissions asserts exact run: strings and on, so the paths change above would force a matching test edit. Keeping just the permissions and SHA-pinning assertions keeps the security value.
  • test_repeated_builds_do_not_leak_warning_state runs two full builds only to write config. Splitting the fixture into "write config" and "run build" removes them.

Happy to help with the logger exclusion list if the mkdocstrings noise is hard to separate out. Thanks again, this closes a gap that has bitten us before.

@hugosmoreira

Copy link
Copy Markdown
Contributor Author

@sromoam Thanks for the specific reproductions. The checker now counts MkDocs warnings/errors from configuration loading onward, with only the known griffe/autorefs warnings exempted. Validation levels live in mkdocs.yml, and awesome-nav errors, missing targets, extensionless links and absolute links now fail.

The 28 checker tests pass, including real awesome-nav fixtures. I also tested copies of the complete site: the unchanged site passes, and each of the four planted navigation/link faults fails. Running the final tests against the unchanged published checker reproduces ten failures.

The workflow now has paths/concurrency, uses docs-only dependencies and leaves test execution to the existing test matrix. I corrected the README, loosened the workflow assertions and split config writing from builds.

The updated PR description records the verification and the six baseline Windows SIGALRM failures. Hosted Linux results remain pending.

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Security Scan Results

ASH Security Scan Report

  • Report generated: 2026-10-19T16:04:04+00:00
  • Time since scan: 3 minutes

Scan Metadata

  • Project: ASH
  • Scan executed: 2026-10-19T16:00:52+00:00
  • ASH version: 3.1.2

Summary

Scanner Results

The table below shows findings by scanner, with status based on severity thresholds and dependencies:

  • Severity levels:
    • Suppressed (S): Findings that have been explicitly suppressed and don't affect scanner status
    • Critical (C): Highest severity findings that require immediate attention
    • High (H): Serious findings that should be addressed soon
    • Medium (M): Moderate risk findings
    • Low (L): Lower risk findings
    • Info (I): Informational findings with minimal risk
  • Duration (Time): Time taken by the scanner to complete its execution
  • Actionable: Number of findings at or above the threshold severity level that require attention
  • Result:
    • PASSED = No findings at or above threshold
    • FAILED = Findings at or above threshold
    • MISSING = Required dependencies not available
    • SKIPPED = Scanner explicitly disabled
    • ERROR = Scanner execution error
  • Threshold: The minimum severity level that will cause a scanner to fail
    • Thresholds: ALL, LOW, MEDIUM, HIGH, CRITICAL
    • Source: Values in parentheses indicate where the threshold is set:
      • global (global_settings section in the ASH_CONFIG used)
      • config (scanner config section in the ASH_CONFIG used)
      • scanner (default configuration in the plugin, if explicitly set)
  • Statistics calculation:
    • All statistics are calculated from the final aggregated SARIF report
    • Suppressed findings are counted separately and do not contribute to actionable findings
    • Scanner status is determined by comparing actionable findings to the threshold
Scanner Suppressed Critical High Medium Low Info Actionable Result Threshold
bandit 0 3 0 0 5810 0 3 FAILED MEDIUM (global)
cdk-nag 0 0 0 0 0 0 0 PASSED MEDIUM (global)
cfn-nag 0 0 0 0 0 0 0 MISSING MEDIUM (global)
checkov 0 0 0 0 0 0 0 PASSED MEDIUM (global)
detect-secrets 0 1 0 0 0 0 1 SKIPPED MEDIUM (global)
grype 0 0 0 0 0 0 0 MISSING MEDIUM (global)
npm-audit 0 0 0 0 0 0 0 PASSED MEDIUM (global)
opengrep 0 0 0 0 0 0 0 MISSING MEDIUM (global)
semgrep 3 0 0 0 0 0 0 PASSED MEDIUM (global)
syft 0 0 0 0 0 0 0 MISSING MEDIUM (global)

Top 2 Hotspots

Files with the highest number of security findings:

Finding Count File Location
2 tests/comparators/test_anls_leaf_semantics.py
2 tests/structured_object_evaluator/test_rollup_node_semantics.py

Detailed Findings

Show 4 actionable findings

Finding 1: SECRET-HEX-HIGH-ENTROPY-STRING

  • Severity: HIGH
  • Scanner: detect-secrets
  • Rule ID: SECRET-HEX-HIGH-ENTROPY-STRING
  • Location: tests/comparators/test_anls_leaf_semantics.py:89

Description:
Secret of type 'Hex High Entropy String' detected in file 'tests/comparators/test_anls_leaf_semantics.py' at line 89

Code Snippet:

Secret of type Hex High Entropy String detected

Finding 2: B108

  • Severity: HIGH
  • Scanner: bandit
  • Rule ID: B108
  • Location: tests/comparators/test_anls_leaf_semantics.py:210-212

Description:
Probable insecure usage of temp file/directory.

Code Snippet:

uuid.UUID(int=1),
            pathlib.Path("/tmp/x"),
            b"bytes",

Finding 3: B307

  • Severity: HIGH
  • Scanner: bandit
  • Rule ID: B307
  • Location: tests/structured_object_evaluator/test_rollup_node_semantics.py:1362-1368

Description:
Use of possibly insecure function - consider using safer ast.literal_eval.

Code Snippet:

def published_label(node: dict, section: str, object_lists: set) -> str:
            counts_objects = eval(  # noqa: S307
                cond.group(1),
                {},
                {"data": node, "section": section, "OBJECT_LISTS": object_lists},
            )
            return eval(unit.group(1), {}, {"counts_objects": counts_objects})  # noqa: S307

Finding 4: B307

  • Severity: HIGH
  • Scanner: bandit
  • Rule ID: B307
  • Location: tests/structured_object_evaluator/test_rollup_node_semantics.py:1367-1369

Description:
Use of possibly insecure function - consider using safer ast.literal_eval.

Code Snippet:

)
            return eval(unit.group(1), {}, {"counts_objects": counts_objects})  # noqa: S307

Report generated by Automated Security Helper (ASH) at 2026-10-19T16:04:05+00:00

@sromoam sromoam left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @hugosmoreira, this addresses everything from the last round: awesome-nav faults, extensionless and absolute links all fail now, and the unchanged site passes. I re-ran it on 36fb938.

Blocker (and it's on us): last round I suggested excluding "the known-noisy sources (mkdocstrings/griffe, autorefs)", and you did exactly that. That wording was too broad. Because the exemption covers the whole autorefs logger, a new broken API cross-reference passes. I appended See [Nope][stickler.DoesNotExist]. to Guides/Document_Packet_Splitting.md. The build logs WARNING - mkdocs_autorefs: ... Could not find cross-reference target 'stickler.DoesNotExist', and check_links.py still exits 0. Details and a suggested fix are inline.

Should fix:

  • Orphan pages pass (inline on mkdocs.yml).
  • docs/Makefile (not in the diff, so no inline comment): the build target comment still says mkdocs build validates that "Internal links resolve properly". That's the same claim this PR corrects in docs/README.md, so the two docs now disagree. Please fix the comment and add a check target that runs python check_links.py, so make users get the real gate.
  • A config parse error prints a raw traceback (inline on check_links.py:67).

The rest are non-blocking. Address them if they're cheap, otherwise we can follow up.

Comment thread docs/check_links.py Outdated
Comment on lines +20 to +26
if record.levelno == logging.WARNING and any(
record.name == name or record.name.startswith(name + ".")
for name in (
"mkdocs.plugins.griffe",
"mkdocs.plugins.mkdocs_autorefs",
)
):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocker. Exempting the whole mkdocs.plugins.griffe and mkdocs.plugins.mkdocs_autorefs namespaces hides every future warning from them, including a new broken cross-reference in a guide or a docstring (reproduced above). The point is to tolerate today's 9 known warnings, not everything those plugins will ever log.

Two ways to tighten it:

  • Match the known messages, not the logger. Today's 9 are 6 griffe No type or annotation for ... warnings and 3 autorefs warnings, all from structured_model.py:262. Match on the logger plus the message (and, for autorefs, the source location), so anything new is counted.
  • Or remove the autorefs exemption entirely. The 3 autorefs warnings come from the [tp]/[fd]/[derived] brackets in one docstring at structured_model.py:262, and escaping those brackets makes them go away. That leaves only griffe's annotation warnings, which are safe to exempt by message.

Either way, a test that plants an unknown [x][stickler.DoesNotExist] reference and expects a non-zero exit would pin this.

Comment thread docs/mkdocs.yml
Comment on lines +7 to +9
validation:
nav:
not_found: warn

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should fix. nav.omitted_files is left at its default, info, so a page that's in docs/ but in no .nav.yml builds, can't be reached from navigation, and the check passes. There's one today. This build logs at INFO:

The following pages exist in the docs directory, but are not included in the "nav" configuration:
  - Guides/Document_Packet_Splitting.md

Adding omitted_files: warn under nav: catches it. You'll also need to either add that page to Guides/.nav.yml or explicitly exclude it, or the site won't pass its own check.

Comment thread docs/check_links.py Outdated
logging.basicConfig(level=logging.INFO, format="%(levelname)s - %(message)s")
try:
return check_links(args.config_file, args.site_dir)
except Abort as error:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should fix. Only Abort is caught, so a ConfigurationError (a missing file, or a YAML parse error) escapes as a raw traceback. check_links.py -f bad.yml, with nav: [ in the file, prints a full Python traceback ending in mkdocs.exceptions.ConfigurationError. Catching mkdocs.exceptions.MkDocsException, the base the CLI handles, gives a clean one-line error.

Comment thread docs/check_links.py
Comment on lines +39 to +41
config.plugins.on_startup(command="build", dirty=False)
try:
build(config)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking. This re-creates the CLI's build sequence but skips its _enable_warnings(), so Python DeprecationWarnings from mkdocs or plugins never reach the mkdocs logger and aren't counted. That's a difference from mkdocs build --strict, which counts them, and the module docstring says this fails on MkDocs diagnostics. Worth either routing them the same way or noting the difference.

Comment thread .github/workflows/docs-check.yml Outdated
with:
python-version: "3.12"
- name: Install dependencies
run: uv sync --frozen --no-default-groups --group docs

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking. --no-default-groups --group docs still installs the project and its runtime dependencies (numpy, pydantic, rapidfuzz, ...), roughly 60 packages, which griffe never imports because it reads src/ statically. --only-group docs (or --no-install-project) is lighter. The uv run --frozen on the next line syncs by itself, so this step can probably go.

Comment thread .github/workflows/docs-check.yml Outdated
- 'src/**'
- 'pyproject.toml'
- 'uv.lock'
- '.python-version'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit. .python-version triggers this job, but python-version: "3.12" on line 30 overrides that file, so changing it doesn't affect what this job runs. Drop it from paths, or drop the pin.

Comment on lines +4 to +5
pull_request:
paths:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, for the future. With paths:, PRs outside those paths never report this check. That's fine today, but if "Check Documentation" is ever made a required status check, those PRs will wait forever. A line in .github/workflows/README.md saying this check must stay non-required (or a paths-filter step that always reports) would prevent the surprise.

Comment thread tests/test_docs_build.py Outdated
from pathlib import Path

import pytest
import yaml

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit. This module needs yaml, mkdocs and mkdocs-awesome-nav from the docs group, but imports them unconditionally. CI is fine because the default dev group includes docs, but under the documented test group alone it errors at collection instead of skipping. pytest.importorskip("mkdocs") (and the same for yaml) at the top would make it skip cleanly.

@sromoam sromoam left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @hugosmoreira, this round fixes everything we asked for. Broken API references in guides and in docstrings now fail, orphan pages fail, a bad config gives a one-line error, and the Makefile and README match what the checker does. The non-blocking items are all done too. I re-ran each case on ac23eae.

One thing left, and part of it is on us. Last round I suggested matching the known autorefs warnings by "source location", and the allowlist now pins line numbers for all nine. That keeps your goal (a changed diagnostic needs review), but it also fails on edits that change no diagnostic. If you add one line at the top of structured_model.py, Check Documentation fails and so does test_real_site_review_cases in Run Tests. That file is edited often, and #360 already shifts comparable_field.py:102 to :121.

The middle ground: keep logger, file and message explicit, and drop only the line number. A new or changed warning still fails, and a line shift doesn't. Details are inline. Once that's in, this is ready to approve.

Comment thread docs/check_links.py Outdated
Comment on lines +15 to +33
# Issue #355's existing annotation warnings. Keep messages and source locations
# explicit: a changed diagnostic needs review, not a blanket plugin exemption.
_GRIFFE_WARNINGS = {
"griffe: src/stickler/structured_object_evaluator/" + warning
for warning in (
"bulk_structured_model_evaluator.py:965: No type or annotation for parameter 'df'",
"models/structured_model.py:1842: No type or annotation for parameter '**kwargs'",
"models/structured_model.py:1845: No type or annotation for returned value 1",
"models/comparable_field.py:102: No type or annotation for parameter '**field_kwargs'",
"models/comparable_field.py:105: No type or annotation for returned value 1",
"models/field.py:51: No type or annotation for parameter '**kwargs'",
)
}
_AUTOREFS_WARNING = re.compile(
r"mkdocs_autorefs: API-Reference/models\.md: from (?:.*?/)?"
r"src/stickler/structured_object_evaluator/models/structured_model\.py:262: "
r"\(stickler\.structured_object_evaluator\.models\.structured_model\.StructuredModel\) "
r"Could not find cross-reference target ''(?:tp|fd|derived)''"
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should fix. The :<line> in these entries is what breaks on harmless edits. Repro: prepend # comment to structured_model.py. The warnings move to 1843/1846/263, and the check fails with 5 warnings even though no diagnostic changed.

Suggestion, keeping your "explicit, not a blanket exemption" intent:

  • Drop the line numbers from _GRIFFE_WARNINGS, and strip :<digits> from the incoming message in the re.sub at line 46, which already normalizes the path.
  • Use :\d+ instead of :262 in _AUTOREFS_WARNING.
  • Optionally, tolerate each known entry at most once, so a second copy of the same warning (say, a new **kwargs without an annotation in field.py) still counts.

Separately, and optional: the three autorefs warnings come from the unfenced >>> example at structured_model.py:412-414. Wrapping it in a ```python fence removes all three (we checked), and then _AUTOREFS_WARNING can go entirely.

Comment thread tests/test_docs_build.py Outdated
),
(
"mkdocs.plugins.griffe",
"src/stickler/structured_object_evaluator/models/structured_model.py:1842: No type or annotation for parameter '**kwargs'",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixture, and the autorefs one at line 136, embed the line numbers, so they'll need the same edit. It's also worth adding one test that shifts a line in a copy of the site (for example, prepending a comment to structured_model.py) and expects the check to pass, so the line independence is pinned.

Comment thread docs/README.md Outdated
The checker fails on logged MkDocs warnings and errors, including awesome-nav
failures, orphan pages, missing pages/images/anchors, broken API references, and
unrecognized or absolute links. It tolerates only the nine existing griffe/autorefs
warnings identified by logger, message and source location in `check_links.py`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: once the line numbers are gone, "identified by logger, message and source location" should read something like "identified by logger, file and message", and "changed messages/locations" on the next line becomes "changed messages".

@sromoam sromoam added this to the 1.0.1 (Minor) milestone Oct 15, 2026

@sromoam sromoam left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @hugosmoreira. Dropping the line numbers was the last thing we asked for, and e57a48d does it: exemptions are keyed by logger, file and message, so a line shift no longer fails the gate and a new or changed warning still does. I ran it merged onto current dev. The real site passes with the six tolerated griffe warnings, and all 77 checker tests pass. Approving.

None of the following blocks the merge. They're ideas, and we can pick any of them up ourselves:

  • docs/check_links.py:42: (?:.*?/)? matches the first src/stickler/ in an absolute path, so a clone under a directory like ~/src/stickler reports all six known warnings as new. A greedy .*/ would avoid it. CI's path isn't affected.
  • An exemption that stops matching is never reported. Warning when remaining_warnings is non-empty after the build would keep the list from going stale.
  • tests/test_docs_build.py takes about 71s and runs on every Python version in the matrix. Marking the subprocess builds slow, or running them in one job, would save CI time.

@sromoam
sromoam merged commit b53e2f7 into awslabs:dev Oct 19, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CI: build the docs on pull requests

2 participants