Skip to content

fix(roadmap): refine wraps no link in the model's code, and wraps each reference and link that GitHub makes from its text - #2540

Merged
dan-petty merged 2 commits into
mainfrom
fix/2525-refine-sanitize-code-spans
Oct 28, 2026
Merged

dan-petty merged 2 commits into
mainfrom
fix/2525-refine-sanitize-code-spans

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

sanitize_text in src/devops_cli/roadmap/refine.py now knows which text of the model GitHub shows as code. The review of #2507 found that the patterns of #2478 added backticks inside a code span, which closed the span early and made GitHub link the text after it, and that they missed references and links that GitHub links.

  • markdown-it-py (CommonMark with tables) finds the code spans and code blocks of the model's text. A link, a handle or a reference in code stays as it is.
  • An added code span takes one backtick more than the longest run in the text, so it closes on its own backticks only. A space keeps a replacement from a backtick next to it or a backslash before it.
  • In a text that shows a backtick as text, GitHub's parser (cmark) and markdown-it-py can take a later code span as text (GitHub's markdown API shows www.example.com linked in A `` `x` `see www.example.com` B). There, each added code span takes a length of its own, and a link in a code span is wrapped too.
  • One pattern finds URLs (also ftp:// and a scheme in capitals), www. links (also after > and in a table cell), handles and owner/repo#N references (also in emphasis, after a slash, a dot or a handle). A URL ends before a backtick, |, a bracket, a parenthesis or a backslash. An allowed link that a backtick follows before the next space goes in a code span, because GitHub's autolink would take that backtick.
  • Each point of a comment goes on one line before it is sanitized, so a code block that the sanitizer leaves cannot become a line of text.
  • The < of <! and <? still becomes &lt; in a code span, because split_record and the markers read the raw text. The design records this trade-off.

The OpenSpec change 2525-refine-sanitize-code-spans is archived in the last commit.

Closes #2525

…h reference and link that GitHub makes from its text

- sanitize_text finds the code in the model's text with markdown-it-py
  (CommonMark with tables) and wraps no link, handle or reference in a
  code span or a code block. A backtick added in a code span closed it
  early, and GitHub linked the text after it.
- An added code span takes one backtick more than the longest run in
  the text, so it closes on its own backticks only. A space keeps a
  replacement from a backtick next to it or a backslash before it.
- In a text that shows a backtick as text, GitHub's parser (cmark) and
  markdown-it-py can take a later code span as text. There, each added
  code span takes a length of its own, and a link in a code span is
  wrapped too.
- One pattern finds URLs (also ftp:// and a scheme in capitals), www.
  links (also after > and in a table cell), handles and owner/repo#N
  references (also in emphasis, after a slash, a dot or a handle), as
  GitHub links them. A URL ends before a backtick, |, a bracket, a
  parenthesis or a backslash, and an allowed link that a backtick
  follows before the next space goes in a code span.
- Each point of a comment goes on one line before it is sanitized.
- The < of <! and <? still becomes &lt; in code: the record block and
  the markers are found in the raw text.

Refs #2525
@dan-petty
dan-petty marked this pull request as ready for review October 28, 2026 21:15
@dan-petty
dan-petty merged commit 2d38f8d into main Oct 28, 2026
17 checks passed
@dan-petty
dan-petty deleted the fix/2525-refine-sanitize-code-spans branch October 28, 2026 21:15
@dan-petty

Copy link
Copy Markdown
Owner Author

Fail-to-pass: https://github.com/dan-petty/devops-cli/actions/runs/40769620051/job/123102971906 (the local replay against origin/main gave 30 tests that fail on the base and pass on the head).

Other checks before the push:

  • uv run devops ci test tests/test_roadmap_refine.py tests/test_swallowed_failures_ratchet.py tests/test_architectural_invariants.py: 246 passed. uv run mypy src: no issues.
  • 120 random sanitized texts of backticks, brackets, marks and links, rendered by GitHub's markdown API, showed no link, mention or reference outside code.
  • 60,000 random texts gave no link outside code against markdown-it-py and against a copy of cmark's backtick scan, and kept every code span of a text with no stray backtick.

Review findings of #2507:

  1. References in emphasis and after a slash: fixed.
  2. to 4. Backticks added inside a code span: fixed. The handle and URL patterns had the same defect, and are fixed too.
  3. &lt; in a code span: reproduced, and kept on purpose. split_record finds the record block, and refine finds its markers, in the raw text, which knows no code span. So a <!-- left as it is in a code span could forge a job record. test_sanitize_text_neutralizes_a_comment_opener_in_a_code_span_too holds this.

dan-petty pushed a commit that referenced this pull request Oct 28, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.11.3](v0.11.2...v0.11.3)
(2026-10-28)


### Bug Fixes

* **roadmap:** refine wraps no link in the model's code, and wraps each
reference and link that GitHub makes from its text
([#2540](#2540))
([2d38f8d](2d38f8d)),
closes [#2525](#2525)


### Code Refactoring

* **docker:** DockerEngineService is the Docker engine seam, with an
in-memory engine fake and its contract suite
([#2534](#2534))
([1244cbf](1244cbf)),
closes [#1316](#1316)
* **security:** one keyring seam owns the keyring and the Secret
Service, with a shared fake and its contract suite
([#2532](#2532))
([866d2cb](866d2cb)),
closes [#1318](#1318)
* **telemetry:** OTLP export goes through one exporter seam, and tests
read exported spans and metrics from a shared fake
([#2541](#2541))
([8da35e6](8da35e6)),
closes [#1319](#1319)

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: dan-petty-release[bot] <346998822+dan-petty-release[bot]@users.noreply.github.com>
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.

fix(roadmap): refine sanitizing breaks the model's code spans and misses references that GitHub links

1 participant