Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Fixed

- **Release check respects comments and fences in `CHANGELOG.md`**: `scripts/check_release.py` no longer counts a bullet inside an HTML comment or a fenced code block as a release entry, and `--notes` no longer stops at a `## ` heading inside a fenced example. This affects maintainers cutting a release (#1335, #1290).
4 changes: 3 additions & 1 deletion dokimi/docs/releasing.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ the `Fragment for package changes` step in `ci.yml`'s `static` job asks for it.
python scripts/check_release.py vX.Y.Z # what the release workflow checks
```

Read the collected section as a user would and tidy it. Merge the PR.
Read the collected section as a user would and tidy it. The check ignores
bullets inside HTML comments and fenced code blocks, and a `## ` heading
inside a fence does not end the section. Merge the PR.

2. **Release.** A maintainer first runs the release workflow on `main` and
waits for it to pass while `main` is still the merge commit: the workflow
Expand Down
126 changes: 120 additions & 6 deletions dokimi/scripts/check_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,128 @@
_ENTRY = re.compile(r"^\s*[-*] \S", re.MULTILINE)


# A backtick fence's info string has no backtick: ```x``` is an inline span.
_FENCE = re.compile(r"^ {0,3}(`{3,}(?=[^`]*$)|~{3,})")
_TICKS = re.compile(r"`+")
_HEADING = re.compile(r"^ {0,3}#{1,6}(?:\s|$)")
# A heading, a list item or an HTML comment at the start of a line ends the paragraph a code span lives in.
_BLOCK = re.compile(r"^(?: {0,3}(?:#{1,6}(?:\s|$)|<!--)|\s*[-*+] \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.

bug · should fix
Stop code-span matching at ordered-list boundaries too.

Trigger: a release body of Example literal\n1. <!-- draft \n - Hidden entry\n -->.

Impact: a section with no visible release bullet passes validation.

Evidence: _BLOCK omits ordered markers, so _closes pairs the paragraph's backtick with the backtick inside the next list item's HTML comment. _inline consequently skips the real comment opener, and _entries counts - Hidden entry. In Markdown, 1. interrupts the preceding paragraph and the list item contains an HTML comment block, not a cross-paragraph code span. Recognize ordered-list interruptions and add a regression through problems().

Workaround: insert a blank line before 1..

Should fix: A run shows it; it was not judged to be met in ordinary use.

Shown by running: exit 1 (at the head) · exit 1 (at the merge base, which cannot run it) · exit 0 (at the head with the fix)

python scripts/proof_c2.py

What the proof does: Checks that a bullet inside an HTML comment opened on an ordered list item is not counted as a release entry.

The problem shows as the output ORDERED_LIST_SPAN_LEAK.

dokimi/scripts/proof_c2.py

import sys
sys.path.insert(0, 'scripts')
import check_release as c
text = "## [0.2.0]\n\nExample `literal\n1. <!- - draft `\n   - Hidden entry\n   -->\n"
if c._section_has_entry(text, '0.2.0'):
    print('ORDERED_LIST_SPAN_LEAK hidden entry counted')
    sys.exit(1)
ORDERED_LIST_SPAN_LEAK hidden entry counted



def _closes(lines: list[str], row: int, col: int, size: int) -> bool:
"""Whether a backtick run of exactly ``size`` follows, within the paragraph."""
for number in range(row, len(lines)):
line = lines[number][col:] if number == row else lines[number]
if number > row and (not line.strip() or _FENCE.match(line) or _BLOCK.match(line)):
return False
if any(len(run[0]) == size for run in _TICKS.finditer(line)):
return True
if _HEADING.match(lines[row]): # a heading is one line: no span runs past it
return False
return False


def _inline(lines: list[str], row: int, in_comment: bool, span: int) -> tuple[str, bool, int]:
"""The visible text of ``lines[row]`` and the comment and code span state at its end."""
line, text, col = lines[row], [], 0
if span:
text.append("x")
while col < len(line):
if in_comment:
end = line.find("-->", col)
if end < 0:
break
col, in_comment = end + 3, False
elif span:
match = next((m for m in _TICKS.finditer(line, col) if len(m[0]) == span), None)
if match is None:
break
col, span = match.end(), 0
elif line.startswith("<!--", col):
col, in_comment = col + 4, True
elif line[col] == "\\":
text.append(line[col:col + 2])
col += 2
elif line[col] == "`":
size = len(_TICKS.match(line, col)[0])
span = size if _closes(lines, row, col + size, size) else 0
text.append("x" if span else "`" * size)
col += size
else:
text.append(line[col])
col += 1
return "".join(text), in_comment, span


def _scan(lines: list[str]) -> list[tuple[bool, str]]:
"""For each line, whether it starts outside a fence and a comment, and its visible text.

The text has HTML comments removed and each inline code span (which may
run over several lines) replaced by ``x``; a fence line, a line inside a
fence and the part of a line inside a comment have none. Fence markers
inside a comment, comment markers inside a fence or a code span, and an
escaped ``\\<`` mean nothing; backticks inside a comment are literal.
"""
scanned, opener, in_comment, span = [], "", False, 0
for row, line in enumerate(lines):
if opener:
fence = _FENCE.match(line)
scanned.append((False, ""))
if (fence and fence[1][0] == opener[0] and len(fence[1]) >= len(opener)
and not line.strip().strip(opener[0])):
opener = ""
continue
fence = None if in_comment or span else _FENCE.match(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.

bug · should fix
Recognize fences opened on a list-item line. Trigger: release_notes("## [0.2.0]\n\n- ```markdown\n example\n ```\n\n- Real entry.\n\n## [0.1.0]\n- Old entry.\n", "0.2.0"). Impact: the emitted notes include the older release despite the example's fence being closed. Evidence: - ```markdown opens a valid Markdown fence within a list item, but _FENCE.match misses it; _closes also rejects its closing marker as a paragraph boundary. The subsequent ```` is therefore treated as a new opener, hiding the real next-version boundary. The opening list line still satisfies_ENTRY`, so validation permits these incorrect notes. Handle list-container prefixes/indentation when tracking fences and add an extraction regression. Workaround: put the fenced example outside the list item.

Should fix: A run shows it; it was not judged to be met in ordinary use.

Shown by running: exit 1 (at the head) · exit 0 (at the merge base) · exit 0 (at the head with the fix)

python scripts/proof_c3.py

What the proof does: Calls release_notes on a section with a fence opened on a list-item line and checks the notes do not include the next version.

The problem shows as the output LIST_FENCE_LEAK.

dokimi/scripts/proof_c3.py

import sys
sys.path.insert(0, 'scripts')
import check_release as c
text = "## [0.2.0]\n\n- ```markdown\n  example\n  ```\n\n- Real entry.\n\n## [0.1.0]\n- Old entry.\n"
notes = c.release_notes(text, '0.2.0')
if notes is None or 'Old entry' in notes:
    print('LIST_FENCE_LEAK', repr(notes))
    sys.exit(1)
LIST_FENCE_LEAK '- ```markdown\n  example\n  ```\n\n- Real entry.\n\n## [0.1.0]\n- Old entry.'

if fence:
opener = fence[1]
scanned.append((False, ""))
continue
starts_visible = not in_comment
text, in_comment, span = _inline(lines, row, in_comment, span)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

bug · should fix
Preserve literal comment markers in indented code.

Trigger: text = "## [0.2.0]\n\n <!- - literal example\n\n- Real entry.\n\n## [0.1.0]\n- Old entry.\n".

Impact: problems() rejects the visible real entry, and release_notes(text, "0.2.0") includes the older release.

Evidence: the four-space code line is not a fence, so this call passes it to _inline, which sets persistent in_comment=True at the literal <!- -; subsequent bullets and headings become invisible. The new indented-code test covers only backticks, not this comment-state leak.

Fix: Handle indented code before inline comment parsing and add acceptance/extraction regressions.

Workaround: use a fenced example.

Should fix: A run shows it; it was not judged to be met in ordinary use.

Shown by running: exit 1 (at the head) · exit 1 (at the merge base, which cannot run it) · exit 0 (at the head with the fix)

python scripts/proof_c1.py

What the proof does: Calls release_notes and _section_has_entry on a changelog whose section has an indented literal comment opener, and checks the notes stop at the next version and the entry is seen.

The problem shows as the output INDENTED_COMMENT_LEAK.

dokimi/scripts/proof_c1.py

import sys
sys.path.insert(0, 'scripts')
import check_release as c
text = "## [0.2.0]\n\n    <!- - literal example\n\n- Real entry.\n\n## [0.1.0]\n- Old entry.\n"
notes = c.release_notes(text, '0.2.0')
ok = notes is not None and 'Old entry' not in notes and c._section_has_entry(text, '0.2.0')
if not ok:
    print('INDENTED_COMMENT_LEAK', repr(notes), c._section_has_entry(text, '0.2.0'))
    sys.exit(1)
INDENTED_COMMENT_LEAK '    <!- - literal example\n\n- Real entry.\n\n## [0.1.0]\n- Old entry.' False

scanned.append((starts_visible, text))
return scanned


def _section(changelog: str, version: str) -> tuple[list[str], int, int, list[tuple[bool, str]]] | None:
lines = changelog.split("\n")
scanned = _scan(lines)
start = re.compile(rf"^## \[{re.escape(version)}\]")
begin = next((i for i, line in enumerate(lines) if scanned[i][0] and start.match(line)), None)
if begin is None:
return None
end = next((i for i in range(begin + 1, len(lines))
if scanned[i][0] and lines[i].startswith(("## ", "<a id="))), len(lines))
return lines, begin, end, scanned


def release_notes(changelog: str, version: str) -> str | None:
"""The body of the ``## [version]`` section, or None if there is none.

The section ends at the next heading or at the ``<a id=...>`` anchor scriv
writes above each version.
writes above each version. A heading or anchor inside a fenced code block
or an HTML comment does not end it.
"""
match = re.search(rf"^## \[{re.escape(version)}\][^\n]*\n(.*?)(?=^## |^<a id=|\Z)",
changelog, re.MULTILINE | re.DOTALL)
return match.group(1).strip() if match else None
section = _section(changelog, version)
if section is None:
return None
lines, begin, end, _ = section
body = "\n".join(lines[begin + 1:end])
Comment thread
vchamarthi marked this conversation as resolved.
Resolved
return re.sub(r"\A(?:[ \t]*\n)+", "", body).rstrip() # keep the first line's indent


def _entries(scanned: list[tuple[bool, str]]) -> bool:
return any(_ENTRY.search(text) for visible, text in scanned if visible)


def _has_entry(notes: str) -> bool:
"""Whether the notes hold a bullet outside HTML comments and fenced code blocks."""
return _entries(_scan(notes.split("\n")))


def _section_has_entry(changelog: str, version: str) -> bool:
"""Like ``_has_entry`` on the section's notes, but a comment opened on its heading still counts."""
section = _section(changelog, version)
return section is not None and _entries(section[3][section[1] + 1:section[2]])


def problems(tag: str, project: Path = PROJECT) -> tuple[list[str], str | None]:
Expand All @@ -43,8 +156,9 @@ def problems(tag: str, project: Path = PROJECT) -> tuple[list[str], str | None]:
found = []
if tag != f"v{version}":
found.append(f"tag {tag!r} does not match project.version {version!r} (want v{version})")
notes = release_notes((project / "CHANGELOG.md").read_text(encoding="utf-8"), version)
if not notes or not _ENTRY.search(notes):
changelog = (project / "CHANGELOG.md").read_text(encoding="utf-8")
notes = release_notes(changelog, version)
if not notes or not _section_has_entry(changelog, version):
found.append(f"CHANGELOG.md has no entries under '## [{version}]': "
f"run `scriv collect --version {version}`")
pending = sorted(p.name for p in (project / "changelog.d").glob("*.md") if p.name != "README.md")
Expand Down
135 changes: 135 additions & 0 deletions dokimi/tests/test_check_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,141 @@ def test_a_section_with_only_a_category_heading_has_no_entries(tmp_path):
assert any("no entries under '## [0.2.0]'" in p for p in found)


def _section(body: str) -> str:
return f"# Changelog\n\n## [0.2.0] — 2026-11-01\n\n{body}\n\n## [0.1.0] — 2026-10-15\n\n- **First** — x.\n"


@pytest.mark.parametrize("body", [
"### Fixed\n\n<!--\n- **Draft entry**\n-->",
"### Fixed\n\n<!--\n- **Draft entry**", # comment never closed
"### Fixed\n\n<!-- a -->\n<!-- b\n- x\n-->",
"### Fixed\n\n```markdown\n- **Example**\n```", # a bullet in an example is no entry
"### Fixed\n\n~~~\n- **Example**\n~~~",
])
def test_commented_or_fenced_bullets_are_not_entries(tmp_path, body):
"""#1290: a bullet inside a comment or a fence is not an entry."""
found, _ = cr.problems("v0.2.0", _project(tmp_path, changelog=_section(body)))
assert any("no entries under '## [0.2.0]'" in p for p in found)


def test_a_bullet_after_a_comment_or_fence_is_an_entry(tmp_path):
body = "<!--\n- x\n-->\n```\n- y\n```\n- **Real** — z."
found, _ = cr.problems("v0.2.0", _project(tmp_path, changelog=_section(body)))
assert found == []


def test_a_heading_inside_a_fence_does_not_end_the_section():
"""#1290: --notes copies the whole section, fenced example included."""
body = ("- **Example** — copy.\n\n```markdown\n## Example heading\n<a id='x'></a>\n```\n\n"
"- **Follow-up** — mine.")
assert cr.release_notes(_section(body), "0.2.0") == body
longer = "````\n```\n## [0.1.0]\n````\n- tail" # a shorter fence does not close a longer one
assert cr.release_notes(_section(longer), "0.2.0") == longer
tilde = "~~~\n## h\n~~~\n- tail"
assert cr.release_notes(_section(tilde), "0.2.0") == tilde


def test_a_version_heading_inside_a_fence_is_not_a_section():
"""#1290: a fenced example of a version heading is not a release section."""
text = "# Changelog\n\n```\n## [0.3.0]\n- x\n```\n"
assert cr.release_notes(text, "0.3.0") is None
assert cr.release_notes("", "0.3.0") is None


def test_a_version_heading_inside_a_comment_is_not_a_section(tmp_path):
"""#1290: a commented-out section is not a release section."""
text = "# Changelog\n\n<!--\n## [0.2.0]\n- Hidden entry\n-->\n"
assert cr.release_notes(text, "0.2.0") is None
found, _ = cr.problems("v0.2.0", _project(tmp_path, changelog=text))
assert any("no entries under '## [0.2.0]'" in p for p in found)


def test_a_fence_marker_inside_a_comment_opens_no_fence():
"""#1290: backticks in a comment do not hide the heading in the real fence."""
body = "- Real entry\n\n<!--\n```\n-->\n\n```\n## Example heading\n```\n\n- Later entry"
assert cr.release_notes(_section(body), "0.2.0") == body
inline = "<!-- a --> ```\n- x\n<!-- b -->\n- y" # text after a comment on a fence-like line
assert cr.release_notes(_section(inline), "0.2.0") == inline


def test_inline_code_does_not_open_a_comment():
"""#1290: a `<!--` in an inline code span does not hide the next section boundary."""
text = "## [0.2.0]\n\n- Document `<!--` syntax.\n\n## [0.1.0]\n\n- Old entry.\n"
assert cr.release_notes(text, "0.2.0") == "- Document `<!--` syntax."
assert cr._has_entry("- `<!--`")


def test_a_code_span_with_backticks_does_not_open_a_comment():
"""#1290: a longer delimiter lets a span hold backticks and a `<!--`."""
text = "## [0.2.0]\n\n- Write ``a ` <!-- b`` here.\n\n## [0.1.0]\n\n- Old entry.\n"
assert cr.release_notes(text, "0.2.0") == "- Write ``a ` <!-- b`` here."
assert not cr._has_entry("A lone ` then <!-- open\n- hidden\n-->") # no closer: literal tick


def test_a_multiline_code_span_does_not_open_a_comment():
"""#1290: a span may run over lines; a `<!--` inside it opens nothing."""
text = ("## [0.2.0]\n\n- Document `first\nsecond <!-- third` marker.\n\n"
"## [0.1.0]\n\n- Old entry.\n")
assert cr.release_notes(text, "0.2.0") == "- Document `first\nsecond <!-- third` marker."


def test_backticks_in_a_comment_do_not_hide_its_end():
"""#1290: backticks inside a comment are literal, so they cannot shield `-->`."""
assert cr._has_entry("<!-- ` --> `\n\n- Real entry.")


def test_an_escaped_comment_opener_opens_nothing():
"""#1290: ``\\<!--`` renders as text, so the bullet after it is visible."""
assert cr._has_entry("Write \\<!-- literally.\n\n- Real entry.")


def test_a_comment_opened_on_the_heading_hides_the_section_body(tmp_path):
"""#1290: the release check keeps the comment state of the heading line."""
text = "## [0.2.0] <!-- draft\n- Hidden entry\n-->\n\n## [0.1.0]\n- Old entry\n"
assert not cr._section_has_entry(text, "0.2.0")
found, _ = cr.problems("v0.2.0", _project(tmp_path, changelog=text))
assert any("no entries under '## [0.2.0]'" in p for p in found)


def test_a_code_span_does_not_cross_a_heading_or_comment_block(tmp_path):
"""#1290: a tick on the heading cannot pair with one inside the next comment."""
text = "## [0.2.0] `\n<!-- `\n- Hidden entry\n-->\n"
assert not cr._section_has_entry(text, "0.2.0")
found, _ = cr.problems("v0.2.0", _project(tmp_path, changelog=text))
assert any("no entries under '## [0.2.0]'" in p for p in found)
assert cr._has_entry("A `tick\n## Heading `\n- Real entry")


def test_a_code_span_does_not_cross_a_list_item(tmp_path):
"""#1290: a list item interrupts a paragraph, so two lone ticks pair with nothing."""
text = "## [0.2.0]\n\nExample `literal\n- Real entry with ` marker\n"
assert cr._section_has_entry(text, "0.2.0")
found, _ = cr.problems("v0.2.0", _project(tmp_path, changelog=text))
assert found == []


def test_an_indented_code_example_is_not_a_fence(tmp_path):
"""#1290: four spaces make code, not a fence, and notes keep the first line's indent."""
text = "## [0.2.0]\n\n ```\n\n- Real entry.\n"
assert cr.release_notes(text, "0.2.0") == " ```\n\n- Real entry."
found, _ = cr.problems("v0.2.0", _project(tmp_path, changelog=text))
assert found == []


def test_a_triple_backtick_span_is_not_a_fence(tmp_path):
"""#1290: ```example``` closes on its line, so it opens no fence."""
text = "## [0.2.0]\n\n```example```\n\n- Real entry.\n"
found, _ = cr.problems("v0.2.0", _project(tmp_path, changelog=text))
assert found == []
assert cr.release_notes("## [0.2.0]\n```js x\n## h\n```\n- y\n", "0.2.0") == "```js x\n## h\n```\n- y"


def test_an_unclosed_fence_runs_to_the_end():
"""#1290: an unclosed fence hides the rest of the file, as Markdown renders it."""
text = "## [0.3.0]\n\n- a\n```\n## [0.2.0]\n- b\n"
assert cr.release_notes(text, "0.3.0") == "- a\n```\n## [0.2.0]\n- b"


def test_version_needs_a_changelog_section(tmp_path):
found, _ = cr.problems("v0.3.0", _project(tmp_path, version="0.3.0"))
assert any("scriv collect --version 0.3.0" in p for p in found)
Expand Down
Loading