Skip to content

fix: only toggle %% comment state at line boundaries#51

Merged
aliasunder merged 6 commits into
mainfrom
fix/kanban-stray-pct-comment-bug
May 19, 2026
Merged

fix: only toggle %% comment state at line boundaries#51
aliasunder merged 6 commits into
mainfrom
fix/kanban-stray-pct-comment-bug

Conversation

@aliasunder
Copy link
Copy Markdown
Owner

Summary

vault_patch_note mis-located the trailing %% kanban:settings %% block on TASKS.md when any card contained a stray %% in its text (e.g. 100%%, 50%% off). When that happened, an append to the Done lane landed after the settings block, corrupting the board's kanban-plugin config position.

Root cause: findTrailingCommentBlockStart counted every %% substring on every line via /%%/g, but Obsidian treats %% as a comment delimiter only at line boundaries. A mid-line %% toggled the parser's comment state spuriously; an odd total count left the parser in the "open" state when it reached the real %% kanban:settings opener, which the parser then misinterpreted as a closer — so no trailing block was detected and parseHeadings reported bodyEndLine past the settings block.

Fix: new private countCommentToggles(line) helper returns 0, 1, or 2 toggles based on whether the trimmed line starts and/or ends with %%. Mid-line %% is now ignored. The existing fence/comment state machine in findTrailingCommentBlockStart is preserved — only the per-line toggle count changes.

Test plan

  • Flipped the 2 it.fails integration tests (added in 936e7bf) to it — both now pass.
  • Added 5 focused unit tests directly against findTrailingCommentBlockStart locking down the line-boundary rule at the helper level (ignores a mid-line %%, ignores multiple mid-line %% on separate lines (odd substring count), ignores %% embedded mid-word, treats a line that is exactly %% as a single toggle, toggles for a line that ends with %% (multi-line closer)).
  • All existing trailing-comment tests still pass (12 direct unit tests + 8 patchNote integration tests).
  • Full suite: 489/489 tests pass.
  • npm run lint clean.
  • npm run build clean.
  • Live verification post-merge: call vault_patch_note against a real TASKS.md with a stray-%% card; confirm the appended card lands above %% kanban:settings.

Closes the bug tracked as ^bug-kanban-stray-pct on the project board.


Generated by Claude Code

aliasunder and others added 6 commits May 19, 2026 02:42
findTrailingCommentBlockStart counts every %% on every line via /%%/g,
but Obsidian only treats %% as a comment delimiter at line boundaries.
A stray %% in card text (e.g. "100%%") toggles comment state; an odd
count leaves the parser open, misidentifying the actual kanban:settings
block. Marked as it.fails — flip to it() when the fix lands.

4 new tests: 2 it.fails (stray %%, odd count), 2 passing (large board,
inline comment with even count).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
findTrailingCommentBlockStart counted every %% substring per line via
/%%/g, but Obsidian treats %% as a comment delimiter only at line
boundaries. A stray %% inside card text (e.g. 100%%) toggled the
parser's comment state spuriously; an odd count left the parser in
"open" state when it reached the real %% kanban:settings opener,
misidentifying it as a closer and skipping trailing block detection
— so append to the final Kanban lane landed AFTER the settings block.

Fix: new countCommentToggles helper counts toggles only when %%
appears at the start and/or end of the trimmed line. Mid-line %%
no longer affects detection.

Flipped 2 it.fails -> it (now passing). Added 5 focused unit tests
against findTrailingCommentBlockStart locking down the line-boundary
rule at the helper level.
The large-board test fixture leaked a real production tunnel hostname
in one of the sample Done items. The test only needs the structural
shape (indented sub-item, backticks, arrow); the specific hostname adds
no coverage. Replaced with tunnel.example.com.
…fixture

The three wikilinks in the doneItems fixture referenced real vault
paths under `Code Projects/vault-cortex/task-notes/` along with one
display-text mention of `About Me/`. The test exercises wikilink
structural patterns (escaped pipe, display text, block ID); the
specific paths add no coverage. Replaced with `Notes/projects/sample-*`
plus matching `^sample-{a,b,c}` block IDs.
The doneItems list mirrored the real project history, including
security-related items (secret scan, port closure, SSH hardening,
DNS provider, CI secret handling) and project-specific tool/file
names. The test only needs structural variety — escaped pipes,
block IDs, backticks, indented sub-items, long lines, escaped
quotes — none of which depend on the specific task text.

Rewrote the list with fictional task content, generalising security
items (e.g. "SSH Tailscale hardening" → "Restrict admin access to
private overlay network"; "gitleaks + CI workflow" → "Add static
analysis to CI pipeline"; "secrets for deploy vars, IP masking" →
"secrets pulled from secret store, sensitive logs masked"), and
renamed real tool/file references (`vault_search` → "full-text search
backend", `verifyAccessToken` → "token verification", etc.).

Block IDs renamed to generic equivalents (`^cf-tunnel` → `^ingress`,
`^ssh-tailscale` → `^admin-net`, `^props-tool` → `^props`,
`^config-oss` → `^config-ext`). Title and comment updated to reflect
that all task text is fictional.
The first round of unit tests for the mid-line %% rule used small line
arrangements where the buggy per-substring counter and the fixed
line-boundary rule happened to produce the same return value — they
passed under both implementations, so they did not actually verify the
fix.

Rewrote the three "ignores mid-line %%" tests with line arrangements
that include a real multi-line trailing block (with a code fence
inside). Under the buggy counter, the stray mid-line %% misdirects
the parser and the detected block start shifts; under the fixed rule
it does not. Each test now fails under the buggy implementation and
passes under the fixed one (verified by temporarily reverting the
countCommentToggles call).

Removed the two contract tests ("`%%` alone as single toggle",
"`%%` at end of line as closer") — they verified preserved behaviors
that hold under both buggy and fixed code, so they only added noise
to a bug-fix PR. Those behaviors are covered implicitly by existing
tests like "finds a multi-line trailing comment block".
@aliasunder aliasunder merged commit 7b27acc into main May 19, 2026
5 checks passed
@aliasunder aliasunder deleted the fix/kanban-stray-pct-comment-bug branch May 19, 2026 12:28
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.

2 participants