Skip to content

okf: don't end a section at a fenced '#' comment line (bundle_tools)#193

Open
manumishra12 wants to merge 1 commit into
GoogleCloudPlatform:mainfrom
manumishra12:fix-section-parse-fenced-headings
Open

okf: don't end a section at a fenced '#' comment line (bundle_tools)#193
manumishra12 wants to merge 1 commit into
GoogleCloudPlatform:mainfrom
manumishra12:fix-section-parse-fenced-headings

Conversation

@manumishra12

Copy link
Copy Markdown

Bug

_section_content_lines (in okf/src/reference_agent/tools/bundle_tools.py) treats any line whose stripped form starts with # as a section heading — including # comment lines inside fenced code blocks (shell, Python, YAML, partition expressions, and so on). A code fence inside a # Schema or # Citations section therefore ends the section early.

Downstream, _schema_field_names and _citation_entry_count then under-read the section, and the web-pass augmentation guard in write_concept_doc can compare truncated field or citation sets — for example wrongly concluding that a rewrite drops fields, or missing a real shrinkage.

Repro

For a # Schema section that lists `id` followed by a fenced code block whose first line is a # comment, then `name`, _schema_field_names(body) returns {"id"}name is lost because the fenced # line is mistaken for a heading and ends the section. Expected {"id", "name"}.

Fix

Track fenced code blocks (backtick and tilde fences) and only treat # lines outside a fence as headings. Ordinary content and real headings behave exactly as before.

Tests

Adds test_section_survives_fenced_hash_comment and test_schema_fields_survive_fenced_hash_comment, each failing before the change and passing after. Full test_bundle_tools.py and test_viewer.py remain green (22 passed).

_section_content_lines treated any line starting with '# ' as a heading,
including '#' comment lines inside fenced code blocks. A code fence in a
'# Schema' or '# Citations' section therefore ended the section early, so
_schema_field_names and _citation_entry_count under-read it and the web-pass
augmentation guard in write_concept_doc could compare truncated field or
citation sets.

Track fenced code blocks (backtick and tilde fences) and only treat '# '
lines outside a fence as headings. Adds regression tests.
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