Skip to content

fix(generator): CSI numbering skips note/continuation/vanish siblings (#122, 1/2)#123

Merged
thewrz merged 1 commit into
mainfrom
fix/csi-numbering-skip-notes
Jun 8, 2026
Merged

fix(generator): CSI numbering skips note/continuation/vanish siblings (#122, 1/2)#123
thewrz merged 1 commit into
mainfrom
fix/csi-numbering-skip-notes

Conversation

@thewrz
Copy link
Copy Markdown
Contributor

@thewrz thewrz commented Jun 8, 2026

PR 1 of 2 for #122 (numbering fix; sanitization follows in PR 2).

Problem

renderMarkdown (shared by MCP + the API, and ported to the mockup) numbered a node's children by their raw array index. Specifier-note, continuation, and vanish siblings therefore consumed CSI ordinals and shifted the numbered siblings: in paring-fixes.docx, a 1–15 "Related Sections" list rendered as 5–20 (4 leading [NOTE] banners pushed it by 4). This happened at every level (part→article, article→pr, pr→pr).

Fix

Advance the CSI ordinal only past nodes that actually carry a number. New consumesNumber() (false for note/continuation/vanish) + renderChildren() helper; getLabel is unchanged.

Verify

Real-file render of "Related Sections" after the fix now starts at 1.:

B. Related Sections:
> **[NOTE]** ****...            (notes unnumbered — correct)
   1. Section 01 30 00 ...      (was 5.)
   2. Section 01 33 00 ...
   ...
  • pnpm test → 49 files, 590 unit tests pass (incl. new regression in markdown.test.ts: leading note siblings → list still starts at 1.). Verified RED before, GREEN after.
  • pnpm lint (eslint + tsc + prettier) clean.

Scope

  • Numbering only. The leftover phantom rows still visible after this PR — a blank pr2 and a stray ] — are ingestion artifacts handled in PR 2 (inference.ts sanitization), which will also commit paring-fixes.docx as a regression fixture.
  • The mockup's public/js/tree.js carries the same raw-index logic and gets the identical fix applied on the mockup branch.
  • Refs #122 (left open until PR 2).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Fixed list item numbering in markdown output to correctly skip notes and continuations while maintaining proper sequential numbering for remaining items starting from 1.
  • Tests

    • Added regression test verifying correct numbering behavior when certain sibling items should be excluded from the numbering sequence.

…#122)

renderMarkdown numbered children by raw array index, so specifier-note,
continuation, and vanish siblings consumed CSI ordinals and shifted the
numbered siblings — a 1..15 "Related Sections" list rendered 5..20.

Advance the ordinal only past nodes that actually carry a number
(new consumesNumber/renderChildren helpers), at every level
(part/article/pr). getLabel is unchanged. The shared markdown renderer
feeds MCP + API; the mockup's public/js/tree.js gets the same fix.

Refs #122
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 8, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: b80cea7f-cf61-4611-b661-ec4fe529f71f

📥 Commits

Reviewing files that changed from the base of the PR and between a844386 and 93e71cd.

📒 Files selected for processing (2)
  • src/generator/markdown.test.ts
  • src/generator/markdown.ts

📝 Walkthrough

Walkthrough

This PR fixes sibling numbering in markdown rendering by introducing ordinal tracking that skips notes, continuations, and vanished nodes. New helper functions track a "number-consuming" ordinal, and three renderers now use ordinal-aware child rendering instead of array indices. A regression test validates the fix.

Changes

Ordinal-aware sibling numbering

Layer / File(s) Summary
Ordinal-aware rendering helpers and renderer updates
src/generator/markdown.ts
consumesNumber and renderChildren helpers track a CSI ordinal that increments only for number-consuming siblings (excluding note, continuation, and meta.vanish nodes). renderPrNode, renderArticle, and renderPart are updated to use ordinal-aware child rendering, ensuring notes and vanished nodes interleave without shifting subsequent numbering.
Regression test for sibling numbering with vanished notes
src/generator/markdown.test.ts
New test verifies that renderMarkdown correctly numbers pr2 siblings starting from 1 while skipping leading note siblings marked meta.vanish: true, asserting expected indented list entries (1. and 2.) and confirming absence of incorrect numbering (3.).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related issues

Poem

🐰 A note slips by with vanished grace,
While siblings number in their place,
No ordinals skip or leap astray,
When helpers guide the render's way!
Numbering flows, the test holds true. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically summarizes the main change: fixing CSI numbering to skip note/continuation/vanish siblings, directly matching the core modification in both markdown.ts and the test.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/csi-numbering-skip-notes

Comment @coderabbitai help to get the list of available commands and usage tips.

@thewrz thewrz merged commit d9e2be8 into main Jun 8, 2026
5 checks passed
@thewrz thewrz deleted the fix/csi-numbering-skip-notes branch June 8, 2026 17:55
thewrz added a commit that referenced this pull request Jun 8, 2026
…des (#122)

A blank paragraph that inherited a numbered style (Signal 2) was emitted as an
empty numbered node — a phantom "13." row that also consumed a CSI number.
buildTree now filters empty paragraphs before structuring (generalizing the
prior continuation-only empty drop). Non-empty punctuation-only lines (e.g. a
stray tailoring "]") are intentionally kept — Word numbers them too.

Combined with PR #123's numbering fix, the manufacturer "Related Sections"
example now renders 1..15, matching Word.

- inference.test.ts: drops-empty + keeps-"]" unit regressions
- paring-fixes.integration.test.ts: local-only end-to-end test; the fixture is
  copyrighted and gitignored, so it skips in CI like the ARCAT tests

Closes #122
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