Repository navigation
fix: check documentation links on pull requests - #363
Conversation
sromoam
left a comment
There was a problem hiding this comment.
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.ymlrather than in the script. Avalidation:block would makemkdocs serveshow the same warnings locally that CI fails on. As written, an author sees nothing locally and then CI fails, and any level set inmkdocs.ymlis silently overridden. - The "Test documentation check" step duplicates
run_pytest.yaml, which already collectstests/test_docs_build.pyon 5 Python versions. I'd drop the step. - Add a
pathsfilter and aconcurrencygroup todocs-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 docswould also make the install lighter. test_pr_workflow_only_builds_with_read_permissionsasserts exactrun:strings andon, so thepathschange 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_stateruns 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.
|
@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. |
Security Scan ResultsASH Security Scan Report
Scan Metadata
SummaryScanner ResultsThe table below shows findings by scanner, with status based on severity thresholds and dependencies:
Top 2 HotspotsFiles with the highest number of security findings:
Detailed FindingsShow 4 actionable findingsFinding 1: SECRET-HEX-HIGH-ENTROPY-STRING
Description: Code Snippet: Finding 2: B108
Description: Code Snippet: Finding 3: B307
Description: Code Snippet: Finding 4: B307
Description: Code Snippet: Report generated by Automated Security Helper (ASH) at 2026-10-19T16:04:05+00:00 |
sromoam
left a comment
There was a problem hiding this comment.
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): thebuildtarget comment still saysmkdocs buildvalidates that "Internal links resolve properly". That's the same claim this PR corrects indocs/README.md, so the two docs now disagree. Please fix the comment and add achecktarget that runspython check_links.py, somakeusers 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.
| 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", | ||
| ) | ||
| ): |
There was a problem hiding this comment.
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 fromstructured_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 atstructured_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.
| validation: | ||
| nav: | ||
| not_found: warn |
There was a problem hiding this comment.
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.
| logging.basicConfig(level=logging.INFO, format="%(levelname)s - %(message)s") | ||
| try: | ||
| return check_links(args.config_file, args.site_dir) | ||
| except Abort as error: |
There was a problem hiding this comment.
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.
| config.plugins.on_startup(command="build", dirty=False) | ||
| try: | ||
| build(config) |
There was a problem hiding this comment.
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.
| with: | ||
| python-version: "3.12" | ||
| - name: Install dependencies | ||
| run: uv sync --frozen --no-default-groups --group docs |
There was a problem hiding this comment.
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.
| - 'src/**' | ||
| - 'pyproject.toml' | ||
| - 'uv.lock' | ||
| - '.python-version' |
There was a problem hiding this comment.
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.
| pull_request: | ||
| paths: |
There was a problem hiding this comment.
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.
| from pathlib import Path | ||
|
|
||
| import pytest | ||
| import yaml |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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.
| # 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)''" | ||
| ) |
There was a problem hiding this comment.
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 there.subat line 46, which already normalizes the path. - Use
:\d+instead of:262in_AUTOREFS_WARNING. - Optionally, tolerate each known entry at most once, so a second copy of the same warning (say, a new
**kwargswithout an annotation infield.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.
| ), | ||
| ( | ||
| "mkdocs.plugins.griffe", | ||
| "src/stickler/structured_object_evaluator/models/structured_model.py:1842: No type or annotation for parameter '**kwargs'", |
There was a problem hiding this comment.
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.
| 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`. |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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 firstsrc/stickler/in an absolute path, so a clone under a directory like~/src/sticklerreports 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_warningsis non-empty after the build would keep the list from going stale. tests/test_docs_build.pytakes about 71s and runs on every Python version in the matrix. Marking the subprocess buildsslow, or running them in one job, would save CI time.
Issue #, if available:
Fixes #355.
Description of changes:
Add a read-only PR documentation build and
make checkthat 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:signal.SIGALRM, 12 skipped, one expected failure.make checkpasses 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 docsserves locally, and the example renders as code.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
DeprecationWarningare 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.