8000 fix(blocks): an empty subject ends its header in a space, and trim() took it by simon-inkie · Pull Request #2 · simon-inkie/inkie-deck · GitHub
[go: up one dir, main page]

Skip to content

fix(blocks): an empty subject ends its header in a space, and trim() took it - #2

Merged
simon-inkie merged 2 commits into
mainfrom
fix/split-blocks-empty-subject-header
Aug 18, 2026
Merged

simon-inkie merged 2 commits into
mainfrom
fix/split-blocks-empty-subject-header

Conversation

@simon-inkie
@simon-inkie simon-inkie commented Aug 17, 2026 •
Copy link
Copy Markdown
Owner

The defect

isBlockHeaderLine matched HEADER_RE against line.trim(). HEADER_RE requires subject:\s+ ahead of the subject capture, and serializeHeader interpolates the subject straight after "subject: ", so a message written without a subject serialises to a line whose last character is that required space and nothing after it.

.trim() took that space off, the line stopped matching, and the header stopped opening a block:

  • with a message above it, the empty-subject message was served as the tail of that message, over the wrong sender's name;
  • as the only header in a file, it produced no blocks at all and the thread rendered empty.

Nothing was missing from disk and nothing errored in either case, so both failed silently on every read.

The fix

Strip leading whitespace only: HEADER_RE.test(line.replace(/^\s+/, "")).

The .trim() was there to keep an indented well-formed header a boundary, a known departure from protocol section 4 recorded as corpus case indented-pseudo-header. replace(/^\s+/, "") keeps exactly that behaviour and leaves the end of the line as the writer emitted it. The comment above the function is rewritten to describe what it now does; it previously explained the .trim() as a deliberate choice, which would have been the wrong thing to leave standing.

Verification

Red-then-green by hand, in both directions, because one direction only shows the new tests test something:

mutation result
back to line.trim() the two empty-subject tests fail (2 blocks where 3 are expected, 0 where 1 is expected) and the new corpus case fails with them
no stripping at all the indented-header pin fails, alongside the existing corpus deviation record for the same behaviour

The fixture is built by serializeHeader rather than typed out, and the test asserts the line really does end in a space: a trailing space in a source file is one formatter away from vanishing and taking the regression with it.

Full suite green on a clean tree: deck 1824 passed / 11 skipped / 88 files, base 38 / 0 / 4. check:leaks, check:licence, check:boundaries, check:dashes and pnpm typecheck all clean; node rig/self-test.mjs 77/77.

Two things beyond the one-line fix, both deliberate

A corpus case, empty-subject-trailing-space. There is already an empty-subject case for the bare-label spelling, and it could not have caught this: the answer recorded for deck there is "no blocks", so a reader that also stopped recognising the spelled-with-a-space form would have left it passing and said nothing. Both implementations satisfy the new case as written, and it is red for deck before this fix. The CLI never had the defect: it matches the raw line and its own subject group needs no whitespace before it.

The indented-pseudo-header deviation text. It described the boundary test as line.trim().startsWith('## '), which stopped being true two fixes ago. The recorded behaviour never moved, only the explanation of it, so this is a correction to the reason field alone.

Test count 1819 -> 1824 in rig/expected.mjs and in the README's three published figures, measured rather than remembered.

CI is red for reasons that predate this branch

Both failures reproduce identically on main and on #1, and neither involves the code here:

  • test (22.x) / test (24.x): the runner has no ripgrep, so the four dashes.test.ts cases that shell out to rg error. What the runner measured is 1820 passing, which is this PR's new figure for a ripgrep-less machine to the digit, so the README's degraded numbers are corroborated by the run rather than only by arithmetic.
  • guards: the leak-gate self-test and the leak gate both pass; gitleaks then fails with 403 Resource n 8000 ot accessible by integration on GET /pulls/{n}/commits. The workflow's GITHUB_TOKEN has no pull-requests: read on a pull_request event. It has never passed on a PR; it passes on main only because a push event never calls that endpoint.

Not fixed here

check:leaks:messages and check:leaks:history are each red on main today, one finding apiece, both predating this branch and unrelated to it: a company email address in the co-author trailer that the merge of #1 added, and the internal product name in the first draft of CLAUDE.md, whose blob is still reachable from that same merge even though the file itself was corrected before it landed. Worth a look, but not something to fold into a reader fix.

…took it

The block-boundary test matched HEADER_RE against line.trim(). HEADER_RE
requires `subject:\s+` ahead of the subject capture, and serializeHeader
interpolates the subject straight after "subject: ", so a message written
without a subject serialises to a line whose last character is that required
space and nothing after it. Trimming took it off, the line stopped matching,
and the header stopped opening a block: the message was served as the tail of
the message above it, over that sender's name, with nothing missing from disk
and no error anywhere. A file whose ONLY header is one of those produced no
blocks at all and rendered as an empty thread, which is the worse half.

Strip leading whitespace only. The trim was there to keep an INDENTED
well-formed header a boundary - a known departure from protocol section 4,
recorded as corpus case indented-pseudo-header - and replace(/^\s+/, "") keeps
exactly that while leaving the end of the line as the writer emitted it.

Red-then-green by hand, in both directions, because one direction would only
have shown that the new tests test something:

  reverted to line.trim()    the two empty-subject cases fail (2 blocks where
                             3 are expected, 0 where 1 is expected) and the
                             new corpus case fails with them
  no stripping at all        the indented-header pin fails alongside the
                             corpus deviation record for the same behaviour,
                             which is what makes that pin worth its line

The fixture is built by serializeHeader rather than typed out, and the test
asserts the line really does end in a space, because a trailing space in a
source file is one formatter away from disappearing and taking the regression
with it.

The corpus gains empty-subject-trailing-space. It has a sibling already, the
bare-label spelling, and the sibling could not have caught this: the answer
recorded for the application there is "no blocks", so a reader that stopped
recognising the spelled-with-a-space form too would leave it passing and say
nothing. Both implementations satisfy the new case as written; the CLI never
had the defect, since it matches the raw line and its own subject group needs
no whitespace before it. The indented-pseudo-header deviation text is corrected
in passing: it described the boundary test as line.trim().startsWith("## "),
which stopped being true two fixes ago, while the behaviour it records never
moved.

Test count 1819 -> 1824 in rig/expected.mjs and in the README's three
published figures, measured on this tree rather than remembered.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@simon-inkie simon-inkie left a comment
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Independent review outcome: clean. The leading-whitespace-only match preserves the existing indented-header behaviour while retaining the trailing space required for empty subjects. The regression coverage constructs the writer-produced header and exercises the full splitBlocks to parseBlock path. I would approve this change, but GitHub prevents the currently authenticated PR-author account from self-approving.

@simon-inkie
simon-inkie merged commit acbbef4 into main Aug 18, 2026
4 checks passed
@simon-inkie
simon-inkie deleted the fix/split-blocks-empty-subject-header branch August 18, 2026 15:27
simon-inkie added a commit that referenced this pull request Aug 18, 2026
…took it (#2)

The block-boundary test matched HEADER_RE against line.trim(). HEADER_RE
requires `subject:\s+` ahead of the subject capture, and serializeHeader
interpolates the subject straight after "subject: ", so a message written
without a subject serialises to a line whose last character is that required
space and nothing after it. Trimming took it off, the line stopped matching,
and the header stopped opening a block: the message was served as the tail of
the message above it, over that sender's name, with nothing missing from disk
and no error anywhere. A file whose ONLY header is one of those produced no
blocks at all and rendered as an empty thread, which is the worse half.

Strip leading whitespace only. The trim was there to keep an INDENTED
well-formed header a boundary - a known departure from protocol section 4,
recorded as corpus case indented-pseudo-header - and replace(/^\s+/, "") keeps
exactly that while leaving the end of the line as the writer emitted it.

Red-then-green by hand, in both directions, because one direction would only
have shown that the new tests test something:

  reverted to line.trim()    the two empty-subject cases fail (2 blocks where
                             3 are expected, 0 where 1 is expected) and the
                             new corpus case fails with them
  no stripping at all        the indented-header pin fails alongside the
                             corpus deviation record for the same behaviour,
                             which is what makes that pin worth its line

The fixture is built by serializeHeader rather than typed out, and the test
asserts the line really does end in a space, because a trailing space in a
source file is one formatter away from disappearing and taking the regression
with it.

The corpus gains empty-subject-trailing-space. It has a sibling already, the
bare-label spelling, and the sibling could not have caught this: the answer
recorded for the application there is "no blocks", so a reader that stopped
recognising the spelled-with-a-space form too would leave it passing and say
nothing. Both implementations satisfy the new case as written; the CLI never
had the defect, since it matches the raw line and its own subject group needs
no whitespace before it. The indented-pseudo-header deviation text is corrected
in passing: it described the boundary test as line.trim().startsWith("## "),
which stopped being true two fixes ago, while the behaviour it records never
moved.

Test count 1819 -> 1824 in rig/expected.mjs and in the README's three
published figures, measured on this tree rather than remembered.

Co-authored-by: Simon <simon@inkie.ink>
Co-authored-by: Claude Opus 5 <noreply@anthropic.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.

1 participant

0