Skip to content

Read validate.py's Markdown and the README Link Definitions Through markdown-it-py - #3635

Merged
ptr727 merged 7 commits into
developfrom
3426-markdown-it-links
Oct 30, 2026
Merged

ptr727 merged 7 commits into
developfrom
3426-markdown-it-links

Conversation

@ptr727

@ptr727 ptr727 commented Oct 30, 2026 •

Copy link
Copy Markdown
Owner

Summary

Moves the last two hand-written Markdown readers onto markdown-it-py, per #3426.

  • spec/validate.py reads link targets, the verbatim-section region, and the section-declaration headings through spec/fidelity_text.py. So a code span, a code block, and a fenced ## line are content rather than links or headings, and an autolink counts as a link. The import stays lazy, held by a new import-probe test, so spec/resolve_description.py still imports the module under the plain python3 that repo-config/configure.sh finds. The validator gains a PEP 723 header, and CI and OPERATIONS.md run it under uv run --no-project --script.
  • spec/audit_markdown.py reads reference definitions from the parser for the link-naming, shield, and 3rd Party Tools checks, replacing the _LINK_DEF line scan. A definition-shaped line inside a paragraph is no longer a definition. Of two definitions whose labels fold together, the first wins, as GitHub renders it. Every reference lookup is folded the same way, so ![x][Docs] resolves to [docs].
  • spec/fidelity_text.py's cached block parse now emits definition tokens. It gains link_definitions (the token's label as written, the destination re-read from the source lines), link_targets (links, images, definitions, and duplicates, all decoded), reference_key, and a fenced_only switch on code_lines.

The comments label is for the PEP 723 header in spec/validate.py. #3634 tracks exempting such a block from comment-added.

Before and After

  • spec/validate.py prints the same output on the base and at every commit: 22 cataloged repos classify cleanly.
  • The full audit sweep (uv run --no-project --script spec/audit.py, every cataloged repo) ran on the base, on the first commit, on 97e63e9, and on 7ed8ecf, the last commit touching code the audit reads. Every finding line matched, except where a live repository moved between runs. Two main heads advanced. ESPHome-Config gained a branch-divergence DRIFT, which the base code also reports when run against that repository now.
  • One test fixture changed with the behavior. DOCKER_SHIELD in tests/test_audit_helpers.py placed [e]: ... directly under a paragraph line, which GitHub renders as text. Its definition now sits with the others.
  • New cases fail on the old code: the paragraph-line definition, the case-variant lookup, the autolink to the template repository, and the fenced ## Rule.

Local Review

Seven recorded local-strict-review passes ran, the last at ff63df6 with no findings. Every introduced finding the earlier passes raised was fixed on this branch:

  • A functools.cache that a Python 3.8 configure.sh host lacks, and mixed decoded and raw link targets.
  • An empty <> destination read as None, a wrapped label dropped, and a label re-parsed by regex rather than taken from the parser's definition token.
  • Duplicate definitions unread by link_targets, and a fenced-sample tool test that first-wins had made unable to fail.
  • A duplicated fenced-lines set, a second block parser, and docstrings and an OPERATIONS.md bullet that no longer matched the code.

Declined with evidence:

  • Merging audit_markdown.references() into the new definition readers. references() feeds strip_md_links, which needs markdown-it's env shape with normalized hrefs. The naming checks need labels and destinations as written, and both read the same parser table.
  • Sharing one inline parser between fidelity_text._LINKS and audit_markdown._MD. _MD disables text_join because strip_md_links rebuilds a line from its source tokens, a requirement sharing would move into fidelity_text.
  • validate.fidelity_text_module as a copy of the carry.py and build_dist.py helpers. Those also put spec/ on sys.path. This one is a two-line wrapper.

Closes #3426

🤖 Generated with Claude Code

ptr727 and others added 3 commits October 29, 2026 18:25
…arkdown-it-py

spec/validate.py's link targets, section reader, and section-declaration
headings now read through spec/fidelity_text.py, so a code span, a code
block, and a fenced "## " line are content rather than links or headings.
The import stays lazy, so spec/resolve_description.py still imports the
module under a plain python3, and CI and OPERATIONS.md run the validator
under uv.

The README link-naming, shield, and 3rd Party Tools checks read reference
definitions from the parser rather than the _LINK_DEF line scan. A line
that would interrupt a paragraph is no longer a definition, and of two
definitions whose labels fold together the first wins, as GitHub renders
it, with every reference lookup folded the same way.

Closes #3426

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…and Drop the Validator's Import Cache

The validator's import helper no longer uses functools.cache, which a
Python 3.8 interpreter configure.sh accepts does not have. Link targets
read each definition from the parser's table, decoded as a link is, so a
link and its definition compare as one target. An empty destination reads
as the empty string, and a label wrapped onto a second line is kept.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…Order

link_definitions reads the label markdown-it-py's definition token keeps
as written, so a label wrapped inside a blockquote folds to the key the
parser resolves it by. Only the destination, which the parser stores
normalized, is read from the source lines. link_targets' docstring now
says links come first and definitions after them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI lite review requested due to automatic review settings October 30, 2026 01:56
@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@ptr727 ptr727 added the comments Permits the comment lines the pull request adds or edits, which the prose gate otherwise refuses label Oct 30, 2026
@ptr727

ptr727 commented Oct 30, 2026

Copy link
Copy Markdown
Owner Author

A recorded local strict-review pass covers head 97e63e9fc265d28837c9a04784e2d7a9cd1308c3, the content this pull request carries at that commit against develop, and it recorded 2 findings.

Copilot AI 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.

🟡 Changes recommended

The change still has an active moderate documentation issue because the docstring incorrectly promises that duplicate reference definitions are returned.

1 open issue
What changed in this PR

This pull request replaces the remaining hand-written Markdown readers with markdown-it-py, preserving rendered Markdown behavior across validation and README auditing while updating validator execution to use uv.

Changes:

  • Adds parser-backed handling for links, headings, sections, reference definitions, and folded reference keys.
  • Updates validation, README auditing, CI, and operations documentation.
  • Adds regression coverage for autolinks, fenced content, reference resolution, and lazy imports.
  • Remaining findings include a moderate P2 docstring contract issue in spec/fidelity_text.py (3 votes) and P2 nit findings for the fenced-definition regression fixture in spec/fidelity_text.py and tests/test_audit_helpers.py (1 vote each).

This pull request requires changes.

File Description
tests/​test_spec_validate.py Tests autolinks, fenced headings, validation behavior, and lazy imports.
tests/​test_fidelity_text.py Tests parser-backed headings, links, definitions, folding, and code exclusion.
tests/​test_audit_helpers.py Updates fixtures and tests rendered reference resolution and audit behavior.
spec/​validate.py Uses lazy parser-backed Markdown validation and adds PEP 723 metadata.
spec/​fidelity_text.py Adds shared parser-backed link targets, reference definitions, and folded reference keys.
spec/​audit_markdown.py Replaces regex-based reference scanning with parser-backed definitions.
OPERATIONS.md Documents running validation through uv.
.github/​actions/​validate/​action.yml Sets up uv and runs validation with the script metadata.

Review effort: Lite

Comment thread spec/fidelity_text.py Resolved
…First

link_targets also reads the duplicate definitions the parser resolves
nothing to, so a carried duplicate's destination is checked as it was
before. The fenced-sample tool case now places its sample ahead of the
real definition, since under first-wins a later one could not override
it and the case would pass whether or not fences were read.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@codecov

codecov Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.59155% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 81.69%. Comparing base (e15559f) to head (ff63df6).

Files with missing lines Patch % Lines
spec/validate.py 87.50% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3635      +/-   ##
===========================================
+ Coverage    81.63%   81.69%   +0.06%     
===========================================
  Files           26       26              
  Lines         9081     9111      +30     
===========================================
+ Hits          7413     7443      +30     
  Misses        1668     1668              
Flag Coverage Δ
python-3.13 81.69% <98.59%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

unfenced_text and readme_link_findings read fenced lines through one
helper, and the link-targets test now holds a fenced block whose link and
definition must not count.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ptr727

ptr727 commented Oct 30, 2026

Copy link
Copy Markdown
Owner Author

A recorded local strict-review pass covers head 145e80abcfc11ec98226690afbdb2f444a3d5851, the content this pull request carries at that commit against develop, and it recorded 4 findings.

ptr727 and others added 2 commits October 29, 2026 19:26
… code_lines

The block parser emits definition tokens, so link_definitions reads the
same cached parse headings and code blocks do rather than a second one.
code_lines takes fenced_only, which the README readers use in place of a
local copy. The validator's docstring names the hook that runs it, and
fidelity_text's names a document rather than a region as what a lazy
importer reads.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ptr727

ptr727 commented Oct 30, 2026

Copy link
Copy Markdown
Owner Author

A recorded local strict-review pass covers head ff63df62ea7b6b020f5ddc4da8d36ee01cb12060, the content this pull request carries at that commit against develop, and it recorded 0 findings.

@ptr727
ptr727 merged commit 04bd8ae into develop Oct 30, 2026
13 checks passed
@ptr727
ptr727 deleted the 3426-markdown-it-links branch October 30, 2026 03:07
ptr727 added a commit that referenced this pull request Oct 30, 2026
…3637)

## Summary

Fixes the finding Copilot raised on promotion #3636 against #3635's
`spec/fidelity_text.py` `_DESTINATION`, and the second one its review
body named. Both come from one root cause: the regex re-reading a
definition's as-written destination did not honor backslash escapes.

- An angle-bracket destination holding an escaped `>` was cut at it, so
`[b]: <https://example.test/a\>b>` read as `https://example.test/a\`.
- A label ending in an escaped backslash matched nothing, so `[a\\]:
one.md` raised `AttributeError` in `link_definitions`.

The regex now anchors on the label's opening `[` and honors escapes on
both sides, including a label the parser lets wrap after a backslash.
`test_an_escape_in_a_label_or_an_angle_destination_is_read_through` pins
all three shapes. The first two fail on the old regex, and the third on
this branch's first commit.

## Verification

- The full unittest suite ran 3103 tests, OK (skipped=7).
- `spec/validate.py` prints the same output as before #3635.
- Two recorded `local-strict-review` passes ran. The first raised the
wrapped-after-backslash label, fixed in 149f883. The second raised
nothing.

## Dropped findings

- `spec/fidelity_text.py` `_DESTINATION`, `pre-existing`: `[ \t>]*`
swallows a leading `>` of a bare destination, an angle destination
holding a backslash-newline falls back to `\S+`, and `\S+` stops at a
non-breaking space the parser keeps. The old regex behaved the same on
each, and none is a realistic README shape.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
ptr727 added a commit that referenced this pull request Oct 30, 2026
…nitions Through markdown-it-py (#3636)

Promotes the #3426 markdown-it-py link reading from `develop` to `main`.

- [#3635](#3635) Reads
`spec/validate.py`'s link targets, sections, and headings, and the
README audit's reference definitions, through `spec/fidelity_text.py`
and markdown-it-py. A definition resolves first-wins with folded lookup,
as GitHub renders it, and code is content rather than links. The
validator now runs under `uv run --no-project --script`.
- [#3637](#3637) Reads
backslash escapes in a definition's label and angle destination, so an
escaped `>` no longer cuts a destination short and a label ending in an
escaped backslash no longer raises. It answers both findings Copilot
raised on this promotion.

Closes #3426

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comments Permits the comment lines the pull request adds or edits, which the prose gate otherwise refuses

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants