Keep fenced shell comments inside the selected diagnostics section

The first publication correction retained the two original defects as history but its heading matcher treated the reviewed shell comment as a boundary. Parse headings only outside fenced blocks, and pin comment, duplicate-heading and missing-heading controls. All 17 passive diagnostics and safety-boundary fixtures now pass; no production or guidance bytes changed.

Change-source: pulse-maintainer
This commit is contained in:
pulse-triage[bot]
2026-10-04 18:43:10 +01:00
parent c4a72995c6
commit af73b0e6c6
+22 -2
View File
@@ -30,8 +30,20 @@ READS = [["status", "100"], ["config", "100", "--current"]]
def guide_section(guide, heading):
"""Select one named H3, never another section's executable examples."""
sections = re.findall(r"^### " + re.escape(heading) +
r"\n(.*?)(?=^#{1,3} |\Z)", guide, re.MULTILINE | re.DOTALL)
sections, current = [], None
fenced = False
for line in guide.splitlines(keepends=True):
boundary = None if fenced else re.match(r"^(#{1,3}) (.*?)\s*$", line)
if boundary:
if current is not None:
sections.append("".join(current))
current = [] if boundary.group(1) == "###" and boundary.group(2) == heading else None
elif current is not None:
current.append(line)
if line.lstrip().startswith("```"):
fenced = not fenced
if current is not None:
sections.append("".join(current))
if len(sections) != 1:
raise AssertionError(f"Expected one guide section: {heading}")
return sections[0]
@@ -287,6 +299,14 @@ class VMDiskDiagnosticsTest(unittest.TestCase):
class VMDiskHelpTest(unittest.TestCase):
def test_section_selection_preserves_shell_comments_and_rejects_missing_or_duplicate_headings(self):
content = "```bash\n# From the reviewed checkout\n### Shell comment, not a heading\ntrue\n```\n"
guide = "### Passive host preflight\n" + content + "## Next\nOther text\n"
self.assertEqual(guide_section(guide, "Passive host preflight"), content)
for invalid in ("## No passive section\n", guide + "### Passive host preflight\n"):
with self.subTest(guide=invalid), self.assertRaises(AssertionError):
guide_section(invalid, "Passive host preflight")
def assert_guide_commands(self, guide):
# The planned server pause is intentionally active, unlike the passive
# hypervisor diagnostic. Admit only the six reviewed server/timer blocks