Skip to content

Health scan: a links check for the READMEs - #92

Merged
martin-henz merged 11 commits into
mainfrom
health/links-check
Nov 28, 2026
Merged

martin-henz merged 11 commits into
mainfrom
health/links-check

Conversation

@martin-henz

@martin-henz martin-henz commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

For #27: the monthly organisation scan gets a tenth check, README with dead links. It reads each public, active repository's README and asks for every absolute link in it.

What counts as dead. Only a definite sign, on two tries: the answer 404 or 410, or a host that does not exist (name not found; a resolver that is merely unavailable does not count). A site that refuses automated clients (403, 429), a timeout, a TLS error or a server error is not reported: the network is noisy, and a link that is really gone is found by a later scan. This differs on purpose from the calls to GitHub, whose failure stops the scan; the README explains it. Skipped: placeholders (localhost, example.com, your-…, {…}) and everything in a code block or between backticks (examples and commands, not links that a reader follows). Balanced parentheses stay part of a URL. Results are cached, so a link used in many READMEs is asked once.

The report keeps the baseline as counts per repository, and gets a section Dead links in READMEs that lists the links of each failing repository. The README of tools/org-health has the new row and the rule.

Tested: unit tests for the extraction (Markdown, HTML, plain text, parentheses, code, placeholders), the 404/410/dns rule, a 404 that goes away, the number of tries, the DNS cases, the cache, a repository's check and the report section; all 43 pass. A dry run of scan.py --dry-run against the organisation (read-only), before the last changes: 40 repositories, 15 with dead links, 11 of them the moved Node.js page (the README PRs are open), and the others handled in separate PRs and issues (backend#1404, modules#1018, and issues in sicp and sinter). Two of the 15 were example base addresses in code blocks (grader), which the scan now skips.

The first scan with this check reports the failing repositories as new, as with any new check.

🤖 Generated with Claude Code

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@martin-henz

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-28T06:04:36.572423Z 9642562 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d00f5e1b6d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tools/org-health/scan.py Outdated
# server error is not reported: if the page is really gone, a later scan finds it. (This differs on purpose from the
# calls to GitHub above, whose failure stops the scan: there a failure says nothing about the repository, here an
# unreachable site says nothing about a link.)
LINK = re.compile(r"""https?://[^\s<>"'`)\]]+""")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve balanced parentheses in README links

Markdown destinations may legally contain balanced parentheses, but this pattern stops at the first ). For example, [Source](https://en.wikipedia.org/wiki/Source_(programming_language)) is checked as https://en.wikipedia.org/wiki/Source_(programming_language, so the scan requests a different path and can report a working link as dead when that truncated path returns 404. Parse balanced Markdown destinations or otherwise retain URL parentheses before removing only the Markdown delimiter.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in a093580: a trailing ) is stripped only while the parentheses are unbalanced, so …/Source_(programming_language) is kept whole and the ) that closes a Markdown destination is dropped. Tested with that example, a URL with two balanced pairs and a link in parentheses in prose.

Comment thread tools/org-health/scan.py Outdated
Comment on lines +173 to +174
except urllib.error.URLError as e:
return "dns" if isinstance(e.reason, socket.gaierror) else None

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Distinguish temporary DNS failures from missing hosts

When DNS returns a transient socket.EAI_AGAIN, it is represented by socket.gaierror just like a permanent EAI_NONAME, so this branch converts both to "dns". If the resolver remains unavailable for the two attempts only two seconds apart, is_dead records a healthy link as definitively dead, contrary to the stated policy of ignoring noisy network failures. Return "dns" only for permanent name-not-found error codes and treat temporary resolution errors as None.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in a093580: http_status answers "dns" only for the permanent name-not-found codes (EAI_NONAME, EAI_NODATA); a temporary resolver failure (EAI_AGAIN) and any other error is None, which is_dead never counts. Tested with gaierror of each kind.

…ing in code

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@martin-henz

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a093580a45

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tools/org-health/scan.py Outdated
# calls to GitHub above, whose failure stops the scan: there a failure says nothing about the repository, here an
# unreachable site says nothing about a link.)
LINK = re.compile(r"""https?://[^\s<>"'`\[\]]+""")
CODE = re.compile(r"```.*?```|~~~.*?~~~|`[^`\n]+`", re.S) # examples and commands, not links that a reader follows

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Exclude all Markdown code-block forms

When a README uses a four-space indented code block or a fenced block that reaches EOF without a closing fence, this regex leaves the block untouched even though both are rendered as code by Markdown. readme_links consequently probes example URLs inside those blocks and can report the repository as failing when an example returns 404 or has a missing host, contrary to the documented rule that code blocks are skipped.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 6b60047: a fence that is never closed hides the rest of the text, and an indented code block (four spaces or a tab after a blank line) is blanked, except inside a list, where such lines continue an item (a full Markdown parser would tell exactly; this errs towards keeping links). Tested with an unclosed fence, an indented block, a list continuation and a lazy continuation line; on 13 real READMEs the indented rule dropped no link. The README of tools/org-health says so.

Comment thread tools/org-health/scan.py Outdated
Comment on lines +160 to +161
while url.endswith(")") and url.count("(") < url.count(")"):
url = url[:-1].rstrip(".,;:!?*_") # the `)` that closes a Markdown destination; a balanced one is part of the URL

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve valid trailing URL characters

When a Markdown destination legitimately ends in _, *, !, or another character in this rstrip set—for example [docs](https://host/page_)—removing the closing ) also strips that character from the URL. The scan then requests a different resource and may report a working link as dead, or miss a dead link if the truncated resource exists; only punctuation outside the parsed destination should be removed.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 6b60047: the punctuation of the prose around a link is stripped only while no closing parenthesis has been removed, so a _, ! or * inside a Markdown destination stays part of the URL (docs), while a link in prose followed by a full stop, or in parentheses followed by a full stop, still loses them. Tested with each.

…nside a destination

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@martin-henz

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6b60047ad4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tools/org-health/scan.py Outdated
Comment on lines +180 to +181
elif not closed and url[-1] in ".,;:!?*_":
url = url[:-1]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve trailing characters in autolinks and HTML attributes

The Markdown-destination case from the prior review is fixed, but fresh evidence shows that valid trailing characters are still removed from angle autolinks and HTML attributes: both <https://host.org/page_> and <a href="https://host.org/page_"> are extracted as https://host.org/page. In these contexts the surrounding delimiter is already excluded by LINK, so stripping _, !, *, or similar characters changes the requested resource and can produce false positives or negatives.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 909419c: a link between delimiters is now taken exactly as written. Angle autolinks, HTML href/src attributes and Markdown destinations (up to the ) that closes them, with balanced pairs inside, and an optional title after a space) are extracted first and not trimmed; only a link in running text loses the punctuation of the sentence around it. Tested: <https://a.org/page_>, <a href="https://b.org/hi!">, [c](https://c.org/x*), an image destination ending in _.png, and a destination with a title. On 13 real READMEs the counts are unchanged except py-slang, where the old code had extracted the bogus https://github.com/source-academy/sinter)/Pynter from [sinter](…/sinter)/Pynter; that one is gone.

Comment thread tools/org-health/scan.py Outdated
LINK = re.compile(r"""https?://[^\s<>"'`\[\]]+""")
CODE = re.compile(r"```.*?(?:```|\Z)|~~~.*?(?:~~~|\Z)|`[^`\n]+`", re.S) # examples and commands, not links that a reader follows
LIST_ITEM = re.compile(r"\s*(?:[-*+]|\d+[.)])\s")
LINK_SKIP = re.compile(r"^https?://(localhost\b|127\.|0\.0\.0\.0|example\.(com|org)\b|your-)|[{}$]", re.I)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Require a hostname boundary when skipping placeholders

Because a word boundary also exists before ., these alternatives skip real hosts whose names merely begin with a placeholder, such as https://example.com.au/page or https://localhost.example.org/page. Such links are never probed, so dead links on those domains are silently omitted; constrain the match to the complete hostname, followed by a port, path delimiter, or end of URL.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 909419c: a placeholder is skipped only if it is the whole hostname, followed by a port, a path delimiter or the end of the URL: localhost, 127.x.x.x (an IPv4 address), 0.0.0.0, example.com, example.org and a host that starts with your-. Tested both ways: example.com.au, localhost.example.org, 127.example.com and examples.org are kept and probed; localhost:4000, example.org/a, 127.0.0.1:8080 and 0.0.0.0 are skipped.

… whole hostname

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@martin-henz

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 909419c0cd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tools/org-health/scan.py Outdated
indent = len(line.expandtabs(4)) - len(line.expandtabs(4).lstrip(" "))
if indent < 4:
in_list = bool(LIST_ITEM.match(line))
out.append("" if prev_blank and indent >= 4 and not in_list else line)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep continuation lines inside indented code blocks excluded

Fresh evidence beyond the earlier indented-block fix is a block containing two consecutive indented lines: only the first line is blanked because prev_blank becomes false immediately, so a URL on the second or later line is scanned even though Markdown still renders it as code. For example, echo example followed by https://dead.example/x can falsely mark the repository as failing; remain in an indented-block state until the block actually ends.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in e32381b: once an indented block has started (four spaces or a tab after a blank line, outside a list) it stays code through all the indented lines that follow, and through blank lines inside it, until a line that is not indented. Tested with two consecutive indented lines and a second block after a blank line.

Comment thread tools/org-health/scan.py Outdated
# calls to GitHub above, whose failure stops the scan: there a failure says nothing about the repository, here an
# unreachable site says nothing about a link.)
LINK = re.compile(r"""https?://[^\s<>"'`\[\]]+""")
CODE = re.compile(r"```.*?(?:```|\Z)|~~~.*?(?:~~~|\Z)|`[^`\n]+`", re.S) # examples and commands, not links that a reader follows

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Match fenced blocks using the opening fence length

When a README uses a four-backtick fence so that a literal triple-backtick sequence can appear inside its example, this pattern treats that shorter sequence as the closing fence and scans any subsequent example URLs. Markdown requires the closing fence to be at least as long as the opening fence, so track the opening marker and length rather than closing every block at the next three markers.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in e32381b: the closing fence must be the same character and at least as long as the opening one (a backreference to the opening run), or the end of the text. Tested with a four-backtick fence that contains a triple-backtick line and a URL after it.

Comment thread tools/org-health/scan.py Outdated
Comment on lines +150 to +151
LINK_SKIP = re.compile(
r"^https?://(?:localhost|127(?:\.\d{1,3}){3}|0\.0\.0\.0|example\.(?:com|org)|your-[^/:?#]*)(?=[:/?#]|$)|[{}$]", re.I)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Do not skip every URL containing a dollar sign

The unqualified [{}$] alternative classifies every URL containing $ as a placeholder, including legitimate links such as https://host.example/api/$metadata. Those links are silently omitted even if dead; constrain placeholder detection to actual variable/template syntax instead of treating a valid URL character anywhere in the path or query as sufficient.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in e32381b: only template syntax marks a placeholder now: {...} and ${...}. A $ elsewhere (https://h.org/api/$metadata) is an ordinary URL character and the link is probed. Tested with all three.

Comment thread tools/org-health/scan.py Outdated
LINK_SKIP = re.compile(
r"^https?://(?:localhost|127(?:\.\d{1,3}){3}|0\.0\.0\.0|example\.(?:com|org)|your-[^/:?#]*)(?=[:/?#]|$)|[{}$]", re.I)
ANGLE = re.compile(r"<(https?://[^\s<>]+)>") # an autolink
ATTR = re.compile(r"""(?:href|src)=["'](https?://[^"'\s]+)["']""", re.I) # an HTML attribute

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Recognize valid spacing in HTML link attributes

Fresh evidence beyond the earlier HTML-attribute fix is <a href = "https://host.example/page_">: HTML permits whitespace around =, but ATTR does not recognize this form, so the generic extraction path passes the URL through trim_url and probes /page rather than /page_. Accept optional whitespace around = (and, if supported by the scanner, valid unquoted attributes) so trailing URL characters remain intact.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in e32381b: the attribute pattern accepts whitespace around =, double or single quotes and an unquoted value, and takes the value as written. Tested with <a href = "…/page_">, a single-quoted href and an unquoted src.

martin-henz and others added 2 commits November 28, 2026 13:43
…late syntax, spaces in attributes

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…Hub token

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@martin-henz

Copy link
Copy Markdown
Member Author

Pushed e32381b (the four findings above) and 1b7dc33: the Links check failed on the previous commit because github.com answered 503 for three pages of the organisation's .github repository (the run passed on the commit before; nothing in this pull request changes those links), so lychee.toml no longer fails on a 5xx, and lychee gets the workflow's GitHub token so that it is not rate limited. @codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1b7dc33f72

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tools/org-health/scan.py Outdated
Comment on lines +148 to +149
CODE = re.compile( # examples and commands, not links that a reader follows
r"(?P<b>`{3,}).*?(?:(?P=b)`*|\Z)|(?P<t>~{3,}).*?(?:(?P=t)~*|\Z)|`[^`\n]+`", re.S)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Require closing fences to occupy a valid fence line

When a fenced block contains the opening marker anywhere in a content line, this regex treats it as the closing fence even if it has trailing non-whitespace text. For example, in `````sh\n...\nnot-a-close\nhttps://inside.example\n ``, Markdown keeps the URL inside the code block, but CODE stops at the marker before `not-a-close` and the scan can report the example URL as dead. Only recognize a closing run on a line with permitted indentation and whitespace after the marker.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 334acd6: a fence is recognised only when its opening and its closing marker each stand on a line of their own, and the closing line holds nothing but the marker and whitespace; a marker followed by text (```not-a-close) does not close the block. A block that is never closed runs to the end of the text. Tested with exactly that example.

Comment thread tools/org-health/scan.py
Comment on lines +189 to +191
def take(m):
found.append(next(g for g in m.groups() if g))
return " "

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Decode HTML character references before probing attributes

When an HTML attribute escapes a character, take stores the source spelling rather than the destination a browser follows. For example, <a href="https://host.example/a&amp;b"> navigates to /a&b, while the scan requests /a&amp;b; if only the former exists, a valid README link is reported dead. Decode HTML character references in captured attribute values before checking them.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 334acd6: the values of HTML attributes and of Markdown link destinations are decoded (html.unescape) before they are probed, so <a href="…/a&amp;b"> is asked for as …/a&b. Angle autolinks are not decoded, as Markdown does not decode them. Tested with all three forms.

…coded

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@martin-henz

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 334acd62df

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tools/org-health/scan.py Outdated
# unreachable site says nothing about a link.)
LINK = re.compile(r"""https?://[^\s<>"'`\[\]]+""")
CODE = re.compile( # examples and commands, not links that a reader follows
r"^[ \t]*(?P<f>`{3,}|~{3,})[^\n]*\n.*?(?:^[ \t]*(?P=f)[`~]*[ \t]*$|\Z)|`[^`\n]+`", re.S | re.M)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Normalize CRLF before matching closing fences

When a README uses CRLF line endings, the closing fence retains a \r before \n, so the [ \t]*$ suffix cannot match it. The fence is consequently treated as unclosed through \Z, and every real link after the block is blanked and silently omitted from the scan; normalize line endings or permit \r on fence lines.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 67a0a6b: the text is normalised to LF line endings before anything else, so a closing fence in a CRLF README matches and the links after the block are kept. Tested with a CRLF README (closed fence, then a real link). None of the 43 public READMEs uses CRLF today, so this is preventive.

Comment thread tools/org-health/scan.py Outdated
# unreachable site says nothing about a link.)
LINK = re.compile(r"""https?://[^\s<>"'`\[\]]+""")
CODE = re.compile( # examples and commands, not links that a reader follows
r"^[ \t]*(?P<f>`{3,}|~{3,})[^\n]*\n.*?(?:^[ \t]*(?P=f)[`~]*[ \t]*$|\Z)|`[^`\n]+`", re.S | re.M)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Match multi-backtick code spans by delimiter length

When a valid multi-backtick code span contains a literal backtick before an example URL, such as tick ` https://dead.example/x`` ``, the single-backtick alternative removes only the prefix through that literal backtick and leaves the URL to be probed. A dead example can therefore falsely fail the repository; recognize matching runs of backticks so the entire code span is excluded.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 67a0a6b: a code span is a run of backticks up to the next run of the same length (and not across a blank line), so a double-backtick span that holds a single backtick is excluded whole. Also: a backtick fence cannot have a backtick in its info line, so triple backticks inside a line are a code span, not a fence that would run to the end of the text. Tested with both.

…backtick runs

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@martin-henz

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 67a0a6ba39

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tools/org-health/scan.py Outdated
Comment on lines +152 to +153
r"^[ \t]*(?P<f>`{3,})[^`\n]*\n.*?(?:^[ \t]*(?P=f)`*[ \t]*$|\Z)"
r"|^[ \t]*(?P<t>~{3,})[^\n]*\n.*?(?:^[ \t]*(?P=t)~*[ \t]*$|\Z)"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Restrict fenced blocks to valid indentation

Fresh evidence beyond the earlier code-block fixes is an indented block whose literal content begins with a fence marker: when a line starts with four spaces followed by ``` or ~~~, Markdown treats the marker as content of the indented block, but this alternative accepts unlimited indentation as a fence opener. If there is no later matching marker, the \Z branch blanks every subsequent rendered link, so dead links after the indented example are silently omitted; recognize fence indentation in its Markdown container rather than treating every indented marker as an opener.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 9642562: fences and indented blocks are now found by one pass over the lines, with one idea of indentation. A fence opens with up to three spaces of indentation, or more inside a list item; four spaces outside a list start an indented block, and a fence marker inside that block is content, not an opener. A fence still runs to the end if it is never closed, but only if it could open. Tested with an indented block that begins with a marker (the links after it are kept) and with a fence indented inside a list item.

Comment thread tools/org-health/scan.py Outdated
Comment on lines +240 to +241
text = text.replace("\r\n", "\n").replace("\r", "\n") # a README with Windows line endings
delimited, rest = delimited_links(strip_indented_code(CODE.sub(" ", text)))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Exclude links hidden in HTML comments

When a README retains an obsolete or example URL inside <!-- ... -->, GitHub renders no link for a reader to follow, but this preprocessing leaves the comment intact and the generic LINK scan probes its URL. A 404 or missing host in such a comment therefore falsely fails the repository; remove HTML comments before extracting rendered links.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 9642562: HTML comments are removed before links are extracted (an unclosed one hides the rest, as the browser does). Tested with a closed and an unclosed comment; the README of tools/org-health lists it among the things that are skipped.

…L comments

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@martin-henz

Copy link
Copy Markdown
Member Author

@codex review

@martin-henz
martin-henz merged commit 1c38090 into main Nov 28, 2026
10 checks passed
@martin-henz
martin-henz deleted the health/links-check branch November 28, 2026 06:03

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9642562a95

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tools/org-health/scan.py
def readme_links(text):
"""The absolute links of a README, without the placeholders of examples and without what is in code."""
text = text.replace("\r\n", "\n").replace("\r", "\n") # a README with Windows line endings
text = SPAN.sub(" ", COMMENT.sub(" ", strip_code_blocks(text)))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Remove comments before interpreting their fence markers

When an HTML comment contains a fence marker on its own line, strip_code_blocks processes that marker before COMMENT removes the comment. For example, <!--\n```\n-->\n[real](https://dead.example/x) is treated as an unclosed fence and the rendered link after the comment is silently omitted. The comment/fence preprocessing needs to preserve Markdown context so markers inside comments cannot hide subsequent content.

Useful? React with 👍 / 👎.

Comment thread tools/org-health/scan.py
# a code span: a run of backticks up to the next run of the same length (not across a blank line)
SPAN = re.compile(r"(?<!`)(?P<c>`+)(?!`)(?:(?!\n[ \t]*\n).)+?(?<!`)(?P=c)(?!`)", re.S)
COMMENT = re.compile(r"<!--.*?(?:-->|\Z)", re.S) # not rendered, so not a link that a reader follows
FENCE = re.compile(r"^[ \t]*(`{3,}|~{3,})(.*)$")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Recognize fenced blocks inside block quotes

When a block quote contains a tilde-fenced code block, such as > ~~~sh followed by > https://dead.example/x, the fence pattern cannot see past the > container prefix, so the example URL is probed and can falsely fail the repository. Strip or track block-quote prefixes before recognizing fenced and indented code blocks.

Useful? React with 👍 / 👎.

Comment thread tools/org-health/scan.py
# server error is not reported: if the page is really gone, a later scan finds it. (This differs on purpose from the
# calls to GitHub above, whose failure stops the scan: there a failure says nothing about the repository, here an
# unreachable site says nothing about a link.)
LINK = re.compile(r"""https?://[^\s<>"'`\[\]]+""")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Match URL schemes case-insensitively

HTTP URI schemes are case-insensitive, but the generic URL, angle-autolink, and Markdown-destination paths only recognize lowercase http. Consequently valid rendered links such as [docs](HTTPS://host.example/missing) or <HTTPS://host.example/missing> are silently skipped and can never fail the check; apply case-insensitive matching consistently across these extractors.

Useful? React with 👍 / 👎.

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.

1 participant