Repository navigation
fix: split markdown numbered and dash acceptance criteria #111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
d29dda5
05d7397
752e486
8a27882
e504c1e
557c2d1
7f1b48f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,11 +15,18 @@ | |
| _COLOR_SECTION_HEADING_RE = re.compile(r"^\{color:[^}]+\}.+\{color\}\s*$", re.IGNORECASE) | ||
|
|
||
|
|
||
| def extract_jira_section(content: str, heading_prefix: str) -> str | None: | ||
| def _trim_section(lines: list[str], keep_indent: bool) -> str: | ||
| """Join section lines; `keep_indent` drops only surrounding blank lines so the first line keeps its indent.""" | ||
| body = "\n".join(lines) | ||
| return body.strip("\r\n").rstrip() if keep_indent else body.strip() | ||
|
|
||
|
|
||
| def extract_jira_section(content: str, heading_prefix: str, *, keep_indent: bool = False) -> str | None: | ||
| """Extract text after a Jira heading up to its next section boundary. | ||
|
|
||
| Jira h2./h3. headings end every section. Inline bold labels also stop at the next bold, | ||
| color-marked, panel, or h2./h3. section boundary. | ||
| color-marked, panel, or h2./h3. section boundary. The result is `.strip()`ed unless `keep_indent` | ||
| is set, in which case only blank lines around the section are removed so list indentation survives. | ||
| """ | ||
| lines = content.splitlines() | ||
| start = None | ||
|
|
@@ -38,29 +45,68 @@ def extract_jira_section(content: str, heading_prefix: str) -> str | None: | |
| or stripped == "{panel}" | ||
| ) | ||
| ): | ||
| return "\n".join(lines[start:i]).strip() | ||
| return "\n".join(lines[start:]).strip() if start is not None else None | ||
| return _trim_section(lines[start:i], keep_indent) | ||
| return _trim_section(lines[start:], keep_indent) if start is not None else None | ||
|
|
||
|
|
||
| _MARKDOWN_MARKER_RES = { | ||
| "numbered": re.compile(r"^(\s*)\d+\.\s+(.*)$"), | ||
| "dash": re.compile(r"^(\s*)-\s+(.*)$"), | ||
| } | ||
|
|
||
|
|
||
| def _split_markdown_list(section: str) -> list[str] | None: | ||
| """Split a section that opens with a markdown `1.` / `-` list into one string per top-level item. | ||
|
|
||
| Returns None unless the first non-blank line is a list marker, so paragraphs that merely contain | ||
| example sub-bullets stay in paragraph mode. Items start at a marker of the same kind and indent as | ||
| the first one; deeper nested bullets and continuation lines fold into the current item. | ||
| """ | ||
| lines = [line.expandtabs(4) for line in section.splitlines()] | ||
| first = next((line for line in lines if line.strip()), None) | ||
| if first is None: | ||
| return None | ||
| for pattern in _MARKDOWN_MARKER_RES.values(): | ||
| if match := pattern.match(first): | ||
| marker, top_indent = pattern, len(match.group(1)) | ||
| break | ||
| else: | ||
| return None | ||
|
|
||
| items: list[list[str]] = [] | ||
| for line in lines: | ||
| match = marker.match(line) | ||
| if match and len(match.group(1)) == top_indent: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [low] logic-error _split_markdown_list only treats a marker as a sibling when its indent equals the first item's indent exactly; a list of '1. First', ' 2. Second', '3. Third' yields two ACs with Second folded into First, so AC counts and citation numbering can be wrong. Edge case, unchanged since the prior review. Suggested fix: Decide nesting from the parent item's content indent rather than exact marker indent, and add a regression test for slightly indented siblings. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Resolved by the review agent: this is an older copy of a finding that a newer review thread also carries: #111 (comment) The finding is still open. Follow up in the newer thread. Resolving this duplicate. Unresolve it if you disagree. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [low] logic-error
Suggested fix: Treat a marker as nested only when its indent is at least the current item's content column; otherwise start a new top-level item, and add a regression test next to the nested-list test. |
||
| items.append([match.group(2)]) | ||
| elif items: | ||
| items[-1].append(line) | ||
|
Comment on lines
+77
to
+82
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Last one I think @Benkapner. Thanks This folds a paragraph after a blank line into the last item, merging criteria - Exports must preserve row order.
Imports must reject malformed files.
Fix: after a blank line, a non-marker line indented |
||
| return [" ".join(" ".join(parts).split()) for parts in items if "".join(parts).strip()] | ||
|
|
||
|
|
||
| def _extract_bulleted_texts(section: str) -> list[str]: | ||
| """Split a Jira wiki section body into merged, whitespace-normalized bullet-item strings. | ||
|
|
||
| Handles both `#` (numbered) and `*` (plain) bullet markers, and falls back to blank-line | ||
| paragraph splitting when no bullet marker is present. | ||
| Prefers Jira markers (`#` numbered, then `*` plain) so existing STRAT fixtures stay unchanged. | ||
| Overflow markdown attachments keep `1.` / `-` after heading normalization; those are recognized | ||
| only when the section body starts with the list (see `_split_markdown_list`). Falls back to | ||
| blank-line paragraph splitting otherwise. Pass the section with its indentation intact | ||
| (`extract_jira_section(..., keep_indent=True)`) so indented markdown lists split correctly. | ||
| """ | ||
| stripped = section.strip() | ||
|
|
||
| bullet_marker = None | ||
| if re.search(r"(?m)^#\s+", stripped): | ||
| bullet_marker = r"(?m)^#\s+" | ||
| elif re.search(r"(?m)^\*\s+", stripped): | ||
| bullet_marker = r"(?m)^\*\s+" | ||
| else: | ||
| bullet_marker = None | ||
|
|
||
| if bullet_marker: | ||
| # Split on the bullet marker directly so entries survive with no blank line between them. | ||
| return [" ".join(item.split()) for item in re.split(bullet_marker, stripped)[1:] if item.strip()] | ||
|
|
||
| if (markdown_items := _split_markdown_list(section)) is not None: | ||
| return markdown_items | ||
|
|
||
| merged = [] | ||
| for para in re.split(r"\n\n+", stripped): | ||
| if text := " ".join(para.split()): | ||
|
|
@@ -80,14 +126,14 @@ def parse_acceptance_criteria(content: str) -> dict: | |
| whose sentence exactly duplicates (case/whitespace-insensitive) one already present are | ||
| skipped; semantic near-duplicates are not detected. | ||
| """ | ||
| section = extract_jira_section(content, "h3. Acceptance Criteria") | ||
| section = extract_jira_section(content, "h3. Acceptance Criteria", keep_indent=True) | ||
| if section is None: | ||
| heading = next((line for line in content.splitlines() if _STRATEGY_AC_HEADING_RE.match(line)), None) | ||
| if heading is None: | ||
| heading = next((line for line in content.splitlines() if _ADDITIONAL_AC_HEADING_RE.match(line)), None) | ||
| section = extract_jira_section(content, heading) if heading is not None else None | ||
| section = extract_jira_section(content, heading, keep_indent=True) if heading is not None else None | ||
| if section is None: | ||
| section = extract_jira_section(content, "*Acceptance Criteria*") | ||
| section = extract_jira_section(content, "*Acceptance Criteria*", keep_indent=True) | ||
| if section is None: | ||
| return {"found": False, "count": 0, "acceptance_criteria": []} | ||
|
|
||
|
|
@@ -100,7 +146,9 @@ def parse_acceptance_criteria(content: str) -> dict: | |
| break | ||
|
|
||
| testability_section = ( | ||
| extract_jira_section(content, testability_heading) if testability_heading is not None else None | ||
| extract_jira_section(content, testability_heading, keep_indent=True) | ||
| if testability_heading is not None | ||
| else None | ||
| ) | ||
| if testability_section: | ||
| seen = {" ".join(_parse_bullet_item(text)["text"].split()).casefold() for text in texts} | ||
|
|
@@ -123,20 +171,16 @@ def parse_nfr(content: str) -> dict: | |
| if section is None: | ||
| return {"found": False, "requirements": []} | ||
|
|
||
| nfr_re = re.compile(r"^\*\s+\*([^*]+)\*:\s*(.+)") | ||
| nfr_re = re.compile(r"^\*\s+\*(?:([^*]+):\*|([^*]+)\*:)\s*(.+)") | ||
|
fullsend-ai-coder[bot] marked this conversation as resolved.
Resolved
|
||
| requirements = [] | ||
| for raw_line in section.splitlines(): | ||
| line = raw_line.strip() | ||
| if not line: | ||
| continue | ||
| match = nfr_re.match(line) | ||
| if match: | ||
| requirements.append( | ||
| { | ||
| "category": match.group(1).strip(), | ||
| "text": match.group(2).strip(), | ||
| } | ||
| ) | ||
| category = (match.group(1) or match.group(2)).strip() if match else "" | ||
| if category: | ||
| requirements.append({"category": category, "text": match.group(3).strip()}) | ||
| elif requirements and not line.startswith("*"): | ||
| # Merge wrapped continuation text, but not a new "*" bullet that failed nfr_re. | ||
| requirements[-1]["text"] = f"{requirements[-1]['text']} {line}" | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.