Skip to content

fix(todo): read a section by its whole heading line, outside code fences - #347

Open
zerone0x wants to merge 1 commit into
azrtydxb:mainfrom
zerone0x:fix/todo-close-heading-match
Open

zerone0x wants to merge 1 commit into
azrtydxb:mainfrom
zerone0x:fix/todo-close-heading-match

Conversation

@zerone0x

@zerone0x zerone0x commented Nov 9, 2026

Copy link
Copy Markdown

What

procoder todo close now finds ## Acceptance criteria and ## Evidence only when the heading is a line of its own, outside a fenced code block. If the heading is quoted in prose, after > or - , or inside a fence, it no longer counts as the section. The same applies to every other reader that takes a section from a Markdown document.

Why

Fixes #336. textutil.Section found the heading with strings.Index(text, "## "+name), so it took the first line that contained the heading text. In repro 1, prose quoting `## Acceptance criteria` above the real section was read as the criteria, and the task closed with its real criterion still - [ ]. In repro 2, a fenced ## Evidence example above an empty real ## Evidence was read as the evidence, and the task closed with no evidence.

How

The fix goes in textutil.Section, because todo close, backlog close story, spec, plan, analysis, adr and sprint all read sections through it:

  • textutil.SectionSpan walks the text line by line. A heading matches only when the line is exactly ## <name>, with trailing whitespace allowed (so a CRLF \r still matches). Backtick and tilde fences (three or more characters, indented by up to three spaces) are tracked. A heading inside a fence does not start a section, and a ## line inside a fence does not end one.
  • Section and the new HasSection both use SectionSpan.
  • spec/truth.go had its own copy (sectionOf / lineOf, which searched for "## name\n"), so it had the same problem. It now uses SectionSpan on the EOL-normalised text. Line numbers are unchanged.
  • Some checks decided whether a section was present with strings.Contains(text, "## "+s): backlog missingSections, and the section missing checks in spec, plan and analysis. They now use textutil.HasSection, so a quoted heading can't count as a real one there either.

Behaviour change to question: a heading with extra text on the same line (e.g. ## Evidence (draft)) used to be accepted as a prefix match and no longer is. The issue asks for exact whole-line matching, and the templates procoder writes always produce the bare heading.

Testing

  • go test ./...: all packages pass.
  • New internal/todo test TestCloseReadsTheRealHeadingNotAQuoteOfIt covers both repros from the issue. Both tasks must be refused (exit 1) with "unchecked" / "Evidence is empty".
  • New internal/textutil test TestSectionIgnoresQuotedAndFencedHeadings covers headings quoted in backticks, after > and - , and inside a fence; a fenced ## line in the body; a CRLF heading; and HasSection.
  • I applied the mutations named in the // proved by: lines and saw the tests fail:
    • Changing line == heading to strings.Contains(line, heading): the backtick repro closes with exit 0, and the textutil test reads the quoted copy.
    • Disabling fence tracking: the fenced repro closes with exit 0, and the textutil test reads the fenced copy.
  • go run ./cmd/procoder check: formatting, lint (golangci-lint 2.15.0) and Go complexity are clean. The docs obligation for the new exported SectionSpan / HasSection is acknowledged with a docs: none line in the commit message. gitleaks, semgrep and ruff are not installed locally, so those checks did not run.
  • go run ./cmd/procoder git: no findings beyond the existing info notes.

Notes for the reviewer

Start at SectionSpan in internal/textutil/textutil.go. The other source changes are one-line switches over to it. There are no dist/, version or CHANGELOG changes.

`todo close` found `## Acceptance criteria` and `## Evidence` by the first
line containing that text, so a quote of the heading in prose or inside a
code fence was read as the section and a task closed with its real
criterion unticked or its real evidence empty. textutil.Section now
matches the heading as a whole line outside fences, and the spec reader
and the section-presence checks go through the same rule.

Fixes azrtydxb#336

docs: none — internal parsing fix, the documented heading format is unchanged

This branch has not been deployed

No deployments
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.

todo close finds the Evidence and Acceptance criteria sections by a quoted heading in prose or a code fence

1 participant