Skip to content

normalise CRLF at the tracker boundary; assert task new applies cc:task #309

Closed

Description

@davison

Goal

Every issue body and comment body the tracker reads has CRLF normalised to LF once at the package boundary, so the line-anchored scans read a web-editor body as they read an LF one (table test per scanner, no regexp changes); and the task new tests assert the created issue carries exactly the cc:task label. Adopts #296 and #297.

Requirements

M15-R4

Adopts

Plan

Requirement covered: M15-R4 (adopts #296, #297).

The helper. tracker.NormalizeLineEndings(string) string — one \r\n → \n strings.ReplaceAll, exported so the GitHub reader, the scanners, the tests and a fake tracker all share one implementation. No regexp changes.

Where it is applied — two layers, and why both. The boundary alone does not give the guarantee R4 asks for, because Tracker is an interface: IssueBody and Comments are the seam, and a string crossing it carries no promise about its line endings. So the normalisation goes in both places.

  1. The GitHub-backed readers, where a body actually enters the package: IssueBody's return, and Comment.Body in Comments — the only two methods that return an issue or comment body (Task carries labels and state, no body; FileContent returns a file, not a record, and is out of scope).
  2. Each exported scanner's entry, so a scanner called with a body from anywhere — another backend, a fake tracker, a caller holding a body it did not read through the tracker — cannot see CRLF: PlanPresent, AdoptedRefs, RequirementIDs (and MismatchedRequirementIDs through it), ExtractRecords, UnresolvedGates, ParseVerdicts, StartedBy. It is free when there is nothing to replace — strings.Replace returns the input unchanged when it finds no match — so the second layer costs a scan, not an allocation.

The ad-hoc one goes. paragraphs (tracker.go ~701) does its own strings.ReplaceAll before splitting; its only callers are ExtractRecords and UnresolvedGates, which now normalise at their entry, so it is deleted and its doc comment says the body reaches it already normalised. Three layers of the same rule is noise; two is the seam.

task new: no behaviour change. taskNewFake.CreateIssue records the labels it is handed and a test asserts the created issue carries exactly [cc:task] — the constant, not a literal — and not cc:milestone (#297).

SPEC §4: one sentence added at the end of the record-grammar reading rules — line endings are not part of the grammar, a CRLF body reads as the LF one. It is a protocol-visible guarantee for anyone who writes a record in the web editor, and it sits beside the sibling rule that code is content.

Tests. A table test in internal/tracker driving every scanner twice, LF and CRLF, through the boundary — the fixture is served by the fakeGH helper as the issue/comment JSON and read back with GitHub{}.IssueBody / GitHub{}.Comments, so the test walks the path a GitHub body takes — asserting the two results are equal and the LF result is the expected one. Plus the task new label assertion in internal/cli. go test ./..., go vet, gofmt -l clean; CHANGELOG entry (#309).

Coordination. #308 paginates Comments, SubIssues and listIssues in the same file; this PR touches only the body line in each reader and rebases onto origin/main before opening.

Ask-the-human points

None.

Activity

  1. added
    cc:task
    on Sep 6, 2026
  2. radiusred-cody commented on Sep 6, 2026

    @radiusred-cody
    Contributor

    Started by @radiusred-cody[bot].

  3. radiusred-cody commented on Sep 7, 2026

    @radiusred-cody
    Contributor

    Decision: the CRLF normalisation lives in two layers, not one: NormalizeLineEndings is called in the GitHub-backed readers that return a body (IssueBody, Comments) and again at the entry of every exported scanner (PlanPresent, AdoptedRefs, RequirementIDs, ExtractRecords, UnresolvedGates, ParseVerdicts, StartedBy). The ad-hoc strings.ReplaceAll inside paragraphs is deleted, and nothing below those two layers repeats the rule.

    Trade-off: R4 asks for two guarantees that no single site gives. Tracker is an interface, so the reader is the boundary a real body crosses but not the only way a body reaches a scanner: a string crossing that seam carries no promise about its line endings, and milestone close, task finish and status all call the scanners with whatever their tracker handed them. Normalising only in github.go leaves a second backend, a fake tracker, or a caller holding a body it read some other way able to feed CRLF straight into a (?m)…$ scan. Normalising only in the scanners leaves Comment.Body itself carrying CRLF into internal/cli, where the citation walk reads the same text. So both: the reader makes the data one shape, and the scanner makes the reading unconditional. The second pass is free where there is nothing to replace — strings.Replace returns its input unchanged when it finds no match — so it costs a scan, not an allocation.

    Rejected: normalising inside the unexported helpers instead (section, adoptsSection, paragraphs, StripCode). It is the same work spread over more sites, it puts the rule below the level a reader looks for it, and it would have had to be repeated on each new helper. Keeping the ad-hoc call in paragraphs as a third layer was also rejected: its only two callers are exported scanners that now normalise at their entry, and three copies of one rule is noise — its doc comment states the precondition instead.

    Decision: the table test drives each scanner through GitHub{}.IssueBody and GitHub{}.Comments — the fixture is served as the issue and comment JSON by the existing fakeGH helper — rather than calling the scanners with hand-made strings.

    Trade-off: it needs a few lines in TestHelperGH (which now answers an issue read and a comment listing from the environment, finding the REST path by its repos/ prefix so a paginating reader's extra flags cannot hide it), but it proves the path a GitHub body actually takes instead of the path the test invented. It also means the test would still catch a regression if the boundary layer were removed and only the scanner layer left, and the other way round.

    Deviation: none from the plan; this is the plan as written, recorded here as the contract asks.

    Measured against the code with the normalisation removed everywhere, three of the eight rows fail: AdoptedRefs (the ## Adopts heading is matched by a (?m)…$ line, so a CRLF body yields no adoptions at all), ExtractRecords and UnresolvedGates (the paragraph split collapses the whole comment into one paragraph, so a **Decision:** swallows the **Gate raised:** after it). The rest — PlanPresent, RequirementIDs, MismatchedRequirementIDs, ParseVerdicts, StartedBy — read a CRLF body correctly already, by not being anchored to a line's end; their rows are the guard that keeps it that way, which is what R4 asks for.

  4. radiusred-cody commented on Sep 7, 2026

    @radiusred-cody
    Contributor

    Decision: SPEC §4 gets the sentence. At the end of the record-grammar reading rules, beside the rule that code is content: "Line endings are not part of the grammar: a body saved with CRLF — what a web editor writes — is read exactly as the same body written with LF, in the record scans and the ## Adopts section alike."

    Trade-off: R4 leaves the call to the implementer, and the argument for silence is that this is an implementation correction, not a protocol change — the grammar was always meant to be read this way, and §4 does not otherwise describe how bytes reach the scanner. The argument that won is that a human writing a record does so in GitHub's web editor, which is exactly the thing that produces CRLF: the reader who needs the guarantee is the reader §4 is written for, and until now nothing told them whether a Decision typed in the browser would be found. One sentence, no new grammar, and it sits with the sibling rule about code rather than opening a section of its own.

    Rejected: describing the normalisation itself (where it happens, that it is \r\n → \n). That is implementation, it belongs in the code and the changelog, and SPEC §4 states what a record is, not how the tracker reads bytes.

    Decision: Comment.Body is normalised, but UnresolvedGates still returns the Comment values it was given rather than normalised copies.

    Trade-off: the comments it returns already carry LF when they came through Comments, which is every caller; making the scanner rewrite them as well would change what it returns for a caller that built its own, for no gain — task finish reads .URL and the count. Scanning is the scanner's job; rewriting its input is not.

  5. 4 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    cc:task

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions