Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 33 additions & 7 deletions scripts/research_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,21 @@ def draft_prose(block):
return "\n".join(out)


def concept_pointers(text):
"""Return the draft's Concept Document pointer lines, as a set.

The pointer line (``- Concept Document: [..](..)``) is, with the
workflow:issue marker, one of the two elements that define a
trigger-issue draft: it is the link the draft check exists to
validate (#382).
"""
return {
line.strip()
for line in text.splitlines()
if re.match(r"^ {0,3}- Concept Document:", line)
}


def issue_drafts(text):
"""Yield fenced trigger-issue drafts: blocks carrying a workflow:issue marker.

Expand All @@ -553,10 +568,19 @@ def issue_drafts(text):
# 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.
# block alone, so drop the fence only when doing so
# surfaces a draft-defining element the kept prose
# lacks: the workflow:issue marker itself (#401, #411),
# or a Concept Document pointer line the kept prose
# does not already carry (#414 — a draft whose marker
# sits before an unclosed example traps its pointer
# inside the example the same way). A properly closed
# appendix example (#410) surfaces neither: its marker
# and pointer already sit in the kept prose, so its
# exemption stands. Trapped prose that is neither
# element, in a draft already carrying both before the
# example, remains indistinguishable from a closed
# example's contents and stays exempt (#414).
lines = block.splitlines()
found = (
re.match(r"^ {0,3}(`{3,}|~{3,})\s*(.*?)\s*$", lines[-1])
Expand All @@ -565,9 +589,11 @@ def issue_drafts(text):
)
if found and not found[2]:
dropped = "\n".join(lines[:-1])
if "workflow:issue" not in draft_prose(
block
) and "workflow:issue" in draft_prose(dropped):
kept = draft_prose(block)
recovered = draft_prose(dropped)
if (
"workflow:issue" not in kept and "workflow:issue" in recovered
) or concept_pointers(recovered) - concept_pointers(kept):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep Concept Document lines inside closed examples exempt

When an unclosed outer draft ends with a properly closed fenced example that itself contains a sample - Concept Document: line, this set difference treats that example-only line as recovered draft prose. It then drops the example's genuine closing fence, causing draft_prose() to expose the entire example and links() to reject any intentionally non-resolving links in it. This regresses the closed-appendix exemption preserved by the adjacent #410 logic; the recovery signal must distinguish the draft's pointer from pointer-shaped content inside a closed example.

Useful? React with 👍 / 👎.

block = dropped
# Nested fenced blocks inside a draft are embedded code
# examples, not draft prose: strip them whole (as
Expand Down
42 changes: 42 additions & 0 deletions scripts/tests/test_research_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,48 @@ def test_unclosed_issue_draft_ending_with_a_closed_inner_code_block_and_a_broken
)
self.check(package, ok=False)

def append_issue_draft_marker_before_unclosed_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 marker sits before the draft's embedded code example, as
# in the #410 appendix shape, but the example is never closed
# (#414): the draft's own closing fence is consumed as the
# example's close, so the Concept Document pointer written
# after the example's opening fence is trapped inside it.
draft = (
"\n\n## Trigger Issue Draft\n\n```markdown\n"
"# Research: Exact source preservation\n\n"
'<!-- workflow:issue {"package": "pkg", "concept": "C001", '
'"stage": "S1"} -->\n\n'
"```python\n"
"print('example')\n"
f"- Concept Document: [concept]({concept_pointer})\n"
"```\n"
)
document.write_bytes(document.read_bytes() + draft.encode("utf-8"))

def test_issue_draft_marker_before_unclosed_inner_code_and_a_broken_pointer_fails_check(
self,
):
package = self.init()
# #414: the #411 recovery keyed only on a trapped marker, so a
# marker-before draft's trapped broken pointer passed silently.
self.append_issue_draft_marker_before_unclosed_inner_code(
package, "concepts/C001-source-preservation.md"
)
self.check(package, ok=False)

def test_issue_draft_marker_before_unclosed_inner_code_passes_when_valid(
self,
):
package = self.init()
self.append_issue_draft_marker_before_unclosed_inner_code(
package, "C001-source-preservation.md"
)
self.check(package, ok=True)

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
Expand Down
Loading