From a8c589397d955b598406bdfa3ec253c843b1a796 Mon Sep 17 00:00:00 2001 From: Muse Sweep Date: Tue, 20 Oct 2026 07:08:16 -0500 Subject: [PATCH] fix(workflow): keep a closed inner example exempt in an unclosed draft MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The #407 trailing-fence drop in issue_drafts() assumed an unclosed draft's trailing bare fence was the draft's own closing fence, mis-consumed as the embedded example's close. When the trailing fence is instead a properly closed example's genuine close (the example is the draft's last element), dropping it stripped the example's exemption and link-checked its contents (#410). Drop the trailing fence only when doing so is what surfaces the draft's workflow:issue marker into the prose — i.e. the marker itself was trapped inside the example the fence appeared to close, which is exactly the #401 shape. Otherwise keep the fence and the closed example stays exempt. Regression tests: an unclosed draft ending with a properly closed inner example containing a broken link-shaped string now passes, while the same draft with a broken concept pointer still fails. --- scripts/research_workflow.py | 22 +++++++++--- scripts/tests/test_research_workflow.py | 48 +++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 4 deletions(-) diff --git a/scripts/research_workflow.py b/scripts/research_workflow.py index 211dccd4f5..9692e517cf 100644 --- a/scripts/research_workflow.py +++ b/scripts/research_workflow.py @@ -543,10 +543,20 @@ def issue_drafts(text): if "workflow:issue" in block: if not closed: # The draft's fence was never closed at document level, - # so a trailing bare fence line in the block was the + # so a trailing bare fence line in the block may be the # draft's own closing fence, consumed as the embedded - # example's close (#401): drop it so draft_prose() sees - # the example as the unclosed one it is. + # example's close (#401): dropping it lets draft_prose() + # see that example as the unclosed one it is and recover + # the draft prose trapped inside it. But the same shape + # arises when the trailing fence is a properly closed + # example's genuine close and the example is simply the + # draft's last element (#410): dropping it there strips + # the closed example's exemption and link-checks its + # contents. The shapes are indistinguishable from the + # block alone, so drop the fence only when doing so is + # what surfaces the draft's own marker into the prose — + # i.e. the marker itself was trapped inside the example + # the fence appeared to close. lines = block.splitlines() found = ( re.match(r"^ {0,3}(`{3,}|~{3,})\s*(.*?)\s*$", lines[-1]) @@ -554,7 +564,11 @@ def issue_drafts(text): else None ) if found and not found[2]: - block = "\n".join(lines[:-1]) + dropped = "\n".join(lines[:-1]) + if "workflow:issue" not in draft_prose( + block + ) and "workflow:issue" in draft_prose(dropped): + block = dropped # Nested fenced blocks inside a draft are embedded code # examples, not draft prose: strip them whole (as # unfenced() does at document level) so their contents are diff --git a/scripts/tests/test_research_workflow.py b/scripts/tests/test_research_workflow.py index 3932a5a0ca..9f7f0a9905 100644 --- a/scripts/tests/test_research_workflow.py +++ b/scripts/tests/test_research_workflow.py @@ -916,6 +916,54 @@ def test_issue_draft_with_a_short_closed_inner_code_block_passes_when_valid( ) self.check(package, ok=True) + def append_issue_draft_ending_with_closed_inner_code( + self, package, concept_pointer + ): + document = package / "concepts" / "C001-source-preservation.md" + # Byte-level append, for the same \r\n reason as append_issue_draft. + # The draft's own fence is never closed and a properly closed + # code example is its last element (#410): the example's genuine + # closing fence is the document's last line, and the example + # contains a broken link-shaped string that must stay exempt. + # The marker sits before the example, as in a draft whose + # example is an appendix. + draft = ( + "\n\n## Trigger Issue Draft\n\n```markdown\n" + "# Research: Exact source preservation\n\n" + f"- Concept Document: [concept]({concept_pointer})\n\n" + '\n\n' + "```python\n" + "# [not a pointer](missing/code-example.md)\n" + "print('example')\n" + "```\n" + ) + document.write_bytes(document.read_bytes() + draft.encode("utf-8")) + + def test_unclosed_issue_draft_ending_with_a_closed_inner_code_block_passes_when_valid( + self, + ): + package = self.init() + # #410: the trailing fence is the example's genuine close, not + # the draft's mis-consumed one — dropping it (#407) stripped the + # closed example's exemption and failed this valid draft on the + # example's broken link-shaped string. + self.append_issue_draft_ending_with_closed_inner_code( + package, "C001-source-preservation.md" + ) + self.check(package, ok=True) + + def test_unclosed_issue_draft_ending_with_a_closed_inner_code_block_and_a_broken_pointer_fails_check( + self, + ): + package = self.init() + # #410: keeping the example exempt must not exempt the draft's + # own prose — its broken pointer is still checked. + self.append_issue_draft_ending_with_closed_inner_code( + package, "concepts/C001-source-preservation.md" + ) + self.check(package, ok=False) + def test_unclosed_issue_draft_with_a_broken_pointer_fails_check(self): package = self.init() # #393: a draft whose fence is never closed used to be dropped