Skip to content

Fix fenced code block escaping in extract_relevant_lines_str#2312

Open
evandrocoan wants to merge 5 commits intoThe-PR-Agent:mainfrom
evandroforks:fix-nest-ticks-on-content
Open

Fix fenced code block escaping in extract_relevant_lines_str#2312
evandrocoan wants to merge 5 commits intoThe-PR-Agent:mainfrom
evandroforks:fix-nest-ticks-on-content

Conversation

@evandrocoan
Copy link
Copy Markdown

When a file's extracted lines contain their own fenced code blocks (e.g. a README with a ```bash section), wrapping them in the standard triple-backtick fence caused the Markdown parser to misinterpret the inner ``` as a closing fence. This broke rendering inside GitHub <details> collapsible blocks, producing a stray ``` before </details>.

Introduce _get_fence(content) in pr_agent/algo/utils.py. The helper scans the content for the longest consecutive run of backticks and returns a fence that is one backtick longer (minimum three). This guarantees the outer fence can never be prematurely closed by any backtick sequence inside the content.

Update extract_relevant_lines_str to call _get_fence instead of hard-coding ```. The guard "if relevant_lines_str" that now wraps the fence assignment also prevents building a fence string around an empty result, which was a latent bug.

Add tests/unittest/test_extract_relevant_lines_str.py covering:

  • Empty/missing file list returns an empty string.
  • Single-line and multi-line extraction with correct fences.
  • Language identifier propagated into the opening fence.
  • Optional dedent of common leading whitespace.
  • Fallback path that mines lines from the patch when head_file is None.
  • Filename with leading/trailing spaces is matched correctly.
  • Content containing ``` triggers a 4-backtick outer fence, and the inner block is preserved verbatim.
  • End-to-end check via convert_to_markdown_v2 with a real README containing a ```bash block: the <details> body uses ````markdown and the inner ```bash is kept intact.

When a file's extracted lines contain their own fenced code blocks
(e.g. a README with a ```bash section), wrapping them in the standard
triple-backtick fence caused the Markdown parser to misinterpret the
inner ``` as a closing fence. This broke rendering inside GitHub
<details> collapsible blocks, producing a stray ``` before </details>.

Introduce _get_fence(content) in pr_agent/algo/utils.py. The helper
scans the content for the longest consecutive run of backticks and
returns a fence that is one backtick longer (minimum three). This
guarantees the outer fence can never be prematurely closed by any
backtick sequence inside the content.

Update extract_relevant_lines_str to call _get_fence instead of
hard-coding ``` . The guard "if relevant_lines_str" that now wraps
the fence assignment also prevents building a fence string around an
empty result, which was a latent bug.

Add tests/unittest/test_extract_relevant_lines_str.py covering:

- Empty/missing file list returns an empty string.
- Single-line and multi-line extraction with correct fences.
- Language identifier propagated into the opening fence.
- Optional dedent of common leading whitespace.
- Fallback path that mines lines from the patch when head_file is None.
- Filename with leading/trailing spaces is matched correctly.
- Content containing ``` triggers a 4-backtick outer fence, and the
  inner block is preserved verbatim.
- End-to-end check via convert_to_markdown_v2 with a real README
  containing a ```bash block: the <details> body uses ````markdown
  and the inner ```bash is kept intact.
@qodo-free-for-open-source-projects
Copy link
Copy Markdown
Contributor

Review Summary by Qodo

Fix fenced code block escaping in extract_relevant_lines_str

🐞 Bug fix 🧪 Tests

Grey Divider

Walkthroughs

Description
• Add _get_fence() helper to dynamically determine fence length
• Prevents inner backtick sequences from prematurely closing outer fence
• Fixes markdown rendering in GitHub <details> collapsible blocks
• Comprehensive test suite covering edge cases and end-to-end scenarios
Diagram
flowchart LR
  A["Content with inner backticks"] --> B["_get_fence scans for longest run"]
  B --> C["Returns fence one backtick longer"]
  C --> D["extract_relevant_lines_str wraps with dynamic fence"]
  D --> E["Markdown renders correctly in details blocks"]
Loading

Grey Divider

File Changes

1. pr_agent/algo/utils.py 🐞 Bug fix +15/-1

Add dynamic fence generation for nested code blocks

• Add _get_fence(content) helper function that scans for longest consecutive backtick run
• Returns fence with minimum 3 backticks, one longer than any sequence found in content
• Update extract_relevant_lines_str() to use _get_fence() instead of hardcoded triple backticks
• Add guard to prevent wrapping empty content in fence

pr_agent/algo/utils.py


2. tests/unittest/test_extract_relevant_lines_str.py 🧪 Tests +360/-0

Comprehensive test suite for extract_relevant_lines_str

• Test empty/missing file list returns empty string
• Test single-line and multi-line extraction with correct fences
• Test language identifier propagation into opening fence
• Test optional dedent of common leading whitespace
• Test fallback to patch when head_file is None
• Test filename with leading/trailing spaces matched correctly
• Test content with inner triple backticks triggers 4-backtick outer fence
• Test end-to-end convert_to_markdown_v2() with README containing bash code block
• Test three-issue scenario with mixed Python and Markdown files
• Verify fenced blocks used instead of <pre> tags in GitHub details blocks

tests/unittest/test_extract_relevant_lines_str.py


Grey Divider

Qodo Logo

@qodo-free-for-open-source-projects
Copy link
Copy Markdown
Contributor

qodo-free-for-open-source-projects bot commented Apr 11, 2026

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX Issues (0)

Grey Divider


Action required

1. Single quotes in tests📘
Description
New unit tests use extensive single-quoted strings (including dict keys/values), conflicting with
the repository requirement to use double quotes and potentially causing Ruff/pre-commit failures.
Code

tests/unittest/test_extract_relevant_lines_str.py[R201-260]

+        'if response.get("error"):\n'
+        '    raise RuntimeError(f"lorem {name!r} error: {response[\"error\"]}"  )\n'
+        'if "result" not in response:\n'
+        '    raise RuntimeError(f"lorem {name!r}: unexpected response: {response}")\n'
+        'return response["result"]'
+    )
+
+    # Generic Python block at lines 25-38: no backtick sequences inside.
+    _PY_LINES_25_38 = (
+        'def ipsum_fetch(base_url: str) -> str:\n'
+        '    url = f"{base_url}/dolor"\n'
+        '    payload = json.dumps({"sit": "amet"}).encode()\n'
+        '    req = urllib.request.Request(\n'
+        '        url,\n'
+        '        data=payload,\n'
+        '        headers={"Content-Type": "application/json"},\n'
+        '        method="GET",\n'
+        '    )\n'
+        '    with urllib.request.urlopen(req) as resp:\n'
+        '        data = json.loads(resp.read())\n'
+        '    if "consectetur" not in data:\n'
+        '        raise RuntimeError(f"ipsum_fetch: unexpected response: {data}")\n'
+        '    return data["consectetur"]'
+    )
+
+    def _make_py_file(self) -> FilePatchInfo:
+        """Build a synthetic .py file with the two blocks at the correct line positions."""
+        # 24 filler lines so that line 25 starts _PY_LINES_25_38
+        filler_24 = '\n'.join(f'# filler {i}' for i in range(1, 25))
+        # filler between end of block 1 (line 38) and start of block 2 (line 59)
+        filler_between = '\n'.join(f'# filler {i}' for i in range(39, 59))
+        content = (
+            filler_24 + '\n' + self._PY_LINES_25_38 + '\n'
+            + filler_between + '\n' + self._PY_LINES_59_63 + '\n'
+        )
+        return _make_file('src/lorem/script.py', content, language='python')
+
+    def _make_readme_file(self) -> FilePatchInfo:
+        """Build a synthetic README.md where line 43 is a closing ``` fence.
+
+        Lines 41-43:
+          41: lorem ipsum flag value \\
+          42: dolor sit amet flag value
+          43: ```          ← closing fence of a bash block already open in the README
+        """
+        filler_40 = '\n'.join(f'lorem ipsum line {i}' for i in range(1, 41))
+        readme_lines_41_43 = (
+            "  --lorem-param 'adipiscing-elit-sed-do-eiusmod' \\\n"
+            "  --ipsum-param 'tempor-incididunt'\n"
+            '```'
+        )
+        content = filler_40 + '\n' + readme_lines_41_43 + '\n'
+        return _make_file('docs/ipsum/README.md', content, language='markdown')
+
+    def _make_input_data(self) -> dict:
+        return {
+            'review': {
+                'estimated_effort_to_review_[1-5]': '2\n',
+                'relevant_tests': 'No\n',
+                'security_concerns': (
Evidence
PR Compliance ID 6 requires Python changes to follow Ruff style, including a double-quote string
convention. The added test code introduces many single-quoted literals (e.g., in _PY_LINES_59_63,
_PY_LINES_25_38, and the _make_input_data() dict), violating that convention.

AGENTS.md
tests/unittest/test_extract_relevant_lines_str.py[201-260]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The new unit test file uses many single-quoted string literals (including large blocks and dict keys/values), which violates the repo Ruff style requirement to use double quotes and may fail lint/pre-commit.
## Issue Context
The compliance checklist explicitly requires double quotes for Python changes.
## Fix Focus Areas
- tests/unittest/test_extract_relevant_lines_str.py[201-260]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Overlong test lines📘
Description
The new test file introduces multiple lines that exceed the 120-character limit, which is likely to
fail Ruff/formatting hooks and CI. This reduces readability and violates the repository’s stated
Ruff/isort style requirements.
Code

tests/unittest/test_extract_relevant_lines_str.py[231]

+        content = filler_24 + '\n' + self._PY_LINES_25_38 + '\n' + filler_between + '\n' + self._PY_LINES_59_63 + '\n'
Evidence
PR Compliance IDs 8 and 19 require Python changes to conform to Ruff-enforced formatting including a
120-character line limit. The added test code includes very long single-line expressions/asserts
(e.g., the long content = ... concatenation and long assert-with-message lines), which violate
that constraint.

AGENTS.md
tests/unittest/test_extract_relevant_lines_str.py[231-231]
tests/unittest/test_extract_relevant_lines_str.py[304-306]
Best Practice: Learned patterns

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The new tests include lines that exceed the repo’s 120-character limit (Ruff/formatting compliance), which can cause lint/format CI failures.
## Issue Context
Several long one-line string concatenations and `assert ... , f"..."` statements should be wrapped across multiple lines using parentheses or intermediate variables.
## Fix Focus Areas
- tests/unittest/test_extract_relevant_lines_str.py[231-231]
- tests/unittest/test_extract_relevant_lines_str.py[304-306]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

3. _get_fence uses single quotes📘
Description
New/modified Python code introduces single-quoted string literals (e.g., regex patterns and fence
characters) instead of the project’s preferred double-quote style. This can cause inconsistent
formatting and conflicts with the repository’s stated Ruff/isort style expectations.
Code

pr_agent/algo/utils.py[R136-147]

+    for m in re.finditer(r'`+', content):
+        max_backticks = max(max_backticks, len(m.group()))
+    backtick_len = max_backticks + 1
+
+    max_tildes = 2
+    for m in re.finditer(r'~+', content):
+        max_tildes = max(max_tildes, len(m.group()))
+    tilde_len = max_tildes + 1
+
+    if tilde_len < backtick_len:
+        return '~' * tilde_len
+    return '`' * backtick_len
Evidence
PR Compliance ID 9 requires new/modified Python code to prefer double quotes. The added _get_fence
implementation (and new tests) use single-quoted string literals such as r'+', r'~+', '~'`,
and '`' in newly-added lines.

AGENTS.md
pr_agent/algo/utils.py[136-147]
tests/unittest/test_extract_relevant_lines_str.py[201-223]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
New/modified Python code uses single-quoted string literals, but the repo compliance checklist requires preferring double quotes in new/modified code.
## Issue Context
This impacts the newly-added `_get_fence()` helper and some newly-added test fixture strings.
## Fix Focus Areas
- pr_agent/algo/utils.py[136-147]
- tests/unittest/test_extract_relevant_lines_str.py[201-223]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Advisory comments

4. Unbounded fence length🐞
Description
_get_fence() can generate an arbitrarily long backtick fence when extracted content contains a very
long run of backticks, producing extremely long opening/closing fence lines. Since providers
hard-truncate comment bodies to a max length, this can truncate away the closing fence and break
Markdown rendering for the rest of the published comment.
Code

pr_agent/algo/utils.py[R134-137]

+    max_consecutive = 2
+    for m in re.finditer(r'`+', content):
+        max_consecutive = max(max_consecutive, len(m.group()))
+    return '`' * (max_consecutive + 1)
Evidence
The new helper constructs the fence as one longer than the longest backtick run in the content, with
no upper bound, so pathological input can inflate the wrapper significantly. Separately, the
GitProvider truncates any published comment body by naive slicing and appending "...", and
GithubProvider applies this truncation before publishing; truncation can remove the closing fence,
leaving an unterminated code block in the comment.

pr_agent/algo/utils.py[128-137]
pr_agent/git_providers/git_provider.py[404-405]
pr_agent/git_providers/github_provider.py[39-40]
pr_agent/git_providers/github_provider.py[371-386]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`_get_fence()` always uses backticks and returns a fence whose length is `max_backticks_in_content + 1`. With pathological content containing a very long run of backticks, this creates extremely long fence lines, increasing the chance the provider-side output truncation cuts off the closing fence and breaks Markdown formatting for the rest of the comment.
## Issue Context
Providers truncate published comments by slicing to a fixed maximum and appending `...`, which can remove the closing fence.
## Fix Focus Areas
- pr_agent/algo/utils.py[128-137]
- pr_agent/git_providers/git_provider.py[404-405]
## Suggested implementation direction
- Update `_get_fence` to consider **both** backtick fences and tilde fences:
- Compute `max_consecutive` for ``` and for `~` in `content`.
- Choose the fence character that yields the **shorter** safe fence (length `max_run + 1`, minimum 3).
- Return that fence string.
- (Optional) If you keep truncation as-is, ensure any future output limiting preserves fence integrity (e.g., trim inner content while keeping the closing fence), but the primary mitigation here is selecting a shorter safe fence when backticks are pathological.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Grey Divider

Previous review results

Review updated until commit 2a98e81

Results up to commit N/A


🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX Issues (0)

Grey Divider
Action required
1. Single quotes in tests📘
Description
New unit tests use extensive single-quoted strings (including dict keys/values), conflicting with
the repository requirement to use double quotes and potentially causing Ruff/pre-commit failures.
Code

tests/unittest/test_extract_relevant_lines_str.py[R201-260]

+        'if response.get("error"):\n'
+        '    raise RuntimeError(f"lorem {name!r} error: {response[\"error\"]}"  )\n'
+        'if "result" not in response:\n'
+        '    raise RuntimeError(f"lorem {name!r}: unexpected response: {response}")\n'
+        'return response["result"]'
+    )
+
+    # Generic Python block at lines 25-38: no backtick sequences inside.
+    _PY_LINES_25_38 = (
+        'def ipsum_fetch(base_url: str) -> str:\n'
+        '    url = f"{base_url}/dolor"\n'
+        '    payload = json.dumps({"sit": "amet"}).encode()\n'
+        '    req = urllib.request.Request(\n'
+        '        url,\n'
+        '        data=payload,\n'
+        '        headers={"Content-Type": "application/json"},\n'
+        '        method="GET",\n'
+        '    )\n'
+        '    with urllib.request.urlopen(req) as resp:\n'
+        '        data = json.loads(resp.read())\n'
+        '    if "consectetur" not in data:\n'
+        '        raise RuntimeError(f"ipsum_fetch: unexpected response: {data}")\n'
+        '    return data["consectetur"]'
+    )
+
+    def _make_py_file(self) -> FilePatchInfo:
+        """Build a synthetic .py file with the two blocks at the correct line positions."""
+        # 24 filler lines so that line 25 starts _PY_LINES_25_38
+        filler_24 = '\n'.join(f'# filler {i}' for i in range(1, 25))
+        # filler between end of block 1 (line 38) and start of block 2 (line 59)
+        filler_between = '\n'.join(f'# filler {i}' for i in range(39, 59))
+        content = (
+            filler_24 + '\n' + self._PY_LINES_25_38 + '\n'
+            + filler_between + '\n' + self._PY_LINES_59_63 + '\n'
+        )
+        return _make_file('src/lorem/script.py', content, language='python')
+
+    def _make_readme_file(self) -> FilePatchInfo:
+        """Build a synthetic README.md where line 43 is a closing ``` fence.
+
+        Lines 41-43:
+          41: lorem ipsum flag value \\
+          42: dolor sit amet flag value
+          43: ```          ← closing fence of a bash block already open in the README
+        """
+        filler_40 = '\n'.join(f'lorem ipsum line {i}' for i in range(1, 41))
+        readme_lines_41_43 = (
+            "  --lorem-param 'adipiscing-elit-sed-do-eiusmod' \\\n"
+            "  --ipsum-param 'tempor-incididunt'\n"
+            '```'
+        )
+        content = filler_40 + '\n' + readme_lines_41_43 + '\n'
+        return _make_file('docs/ipsum/README.md', content, language='markdown')
+
+    def _make_input_data(self) -> dict:
+        return {
+            'review': {
+                'estimated_effort_to_review_[1-5]': '2\n',
+                'relevant_tests': 'No\n',
+                'security_concerns': (
Evidence
PR Compliance ID 6 requires Python changes to follow Ruff style, including a double-quote string
convention. The added test code introduces many single-quoted literals (e.g., in _PY_LINES_59_63,
_PY_LINES_25_38, and the _make_input_data() dict), violating that convention.

AGENTS.md
tests/unittest/test_extract_relevant_lines_str.py[201-260]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The new unit test file uses many single-quoted string literals (including large blocks and dict keys/values), which violates the repo Ruff style requirement to use double quotes and may fail lint/pre-commit.
## Issue Context
The compliance checklist explicitly requires double quotes for Python changes.
## Fix Focus Areas
- tests/unittest/test_extract_relevant_lines_str.py[201-260]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Overlong test lines📘
Description
The new test file introduces multiple lines that exceed the 120-character limit, which is likely to
fail Ruff/formatting hooks and CI. This reduces readability and violates the repository’s stated
Ruff/isort style requirements.
Code

tests/unittest/test_extract_relevant_lines_str.py[231]

+        content = filler_24 + '\n' + self._PY_LINES_25_38 + '\n' + filler_between + '\n' + self._PY_LINES_59_63 + '\n'
Evidence
PR Compliance IDs 8 and 19 require Python changes to conform to Ruff-enforced formatting including a
120-character line limit. The added test code includes very long single-line expressions/asserts
(e.g., the long content = ... concatenation and long assert-with-message lines), which violate
that constraint.

AGENTS.md
tests/unittest/test_extract_relevant_lines_str.py[231-231]
tests/unittest/test_extract_relevant_lines_str.py[304-306]
Best Practice: Learned patterns

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The new tests include lines that exceed the repo’s 120-character limit (Ruff/formatting compliance), which can cause lint/format CI failures.
## Issue Context
Several long one-line string concatenations and `assert ... , f"..."` statements should be wrapped across multiple lines using parentheses or intermediate variables.
## Fix Focus Areas
- tests/unittest/test_extract_relevant_lines_str.py[231-231]
- tests/unittest/test_extract_relevant_lines_str.py[304-306]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended
3. _get_fence uses single quotes📘
Description
New/modified Python code introduces single-quoted string literals (e.g., regex patterns and fence
characters) instead of the project’s preferred double-quote style. This can cause inconsistent
formatting and conflicts with the repository’s stated Ruff/isort style expectations.
Code

pr_agent/algo/utils.py[R136-147]

+    for m in re.finditer(r'`+', content):
+        max_backticks = max(max_backticks, len(m.group()))
+    backtick_len = max_backticks + 1
+
+    max_tildes = 2
+    for m in re.finditer(r'~+', content):
+        max_tildes = max(max_tildes, len(m.group()))
+    tilde_len = max_tildes + 1
+
+    if tilde_len < backtick_len:
+        return '~' * tilde_len
+    return '`' * backtick_len
Evidence
PR Compliance ID 9 requires new/modified Python code to prefer double quotes. The added _get_fence
implementation (and new tests) use single-quoted string literals such as r'+', r'~+', '~'`,
and '`' in newly-added lines.

AGENTS.md
pr_agent/algo/utils.py[136-147]
tests/unittest/test_extract_relevant_lines_str.py[201-223]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
New/modified Python code uses single-quoted string literals, but the repo compliance checklist requires preferring double quotes in new/modified code.
## Issue Context
This impacts the newly-added `_get_fence()` helper and some newly-added test fixture strings.
## Fix Focus Areas
- pr_agent/algo/utils.py[136-147]
- tests/unittest/test_extract_relevant_lines_str.py[201-223]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Advisory comments
4. Unbounded fence length🐞
Description
_get_fence() can generate an arbitrarily long backtick fence when extracted content contains a very
long run of backticks, producing extremely long opening/closing fence lines. Since providers
hard-truncate comment bodies to a max length, this can truncate away the closing fence and break
Markdown rendering for the rest of the published comment.
Code

pr_agent/algo/utils.py[R134-137]

+    max_consecutive = 2
+    for m in re.finditer(r'`+', content):
+        max_consecutive = max(max_consecutive, len(m.group()))
+    return '`' * (max_consecutive + 1)
Evidence
The new helper constructs the fence as one longer than the longest backtick run in the content, with
no upper bound, so pathological input can inflate the wrapper significantly. Separately, the
GitProvider truncates any published comment body by naive slicing and appending "...", and
GithubProvider applies this truncation before publishing; truncation can remove the closing fence,
leaving an unterminated code block in the comment.

pr_agent/algo/utils.py[128-137]
pr_agent/git_providers/git_provider.py[404-405]
pr_agent/git_providers/github_provider.py[39-40]
pr_agent/git_providers/github_provider.py[371-386]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`_get_fence()` always uses backticks and returns a fence whose length is `max_backticks_in_content + 1`. With pathological content containing a very long run of backticks, this creates extremely long fence lines, increasing the chance the provider-side output truncation cuts off the closing fence and breaks Markdown formatting for the rest of the comment.
## Issue Context
Providers truncate published comments by slicing to a fixed maximum and appending `...`, which can remove the closing fence.
## Fix Focus Areas
- pr_agent/algo/utils.py[128-137]
- pr_agent/git_providers/git_provider.py[404-405]
## Suggested implementation direction
- Update `_get_fence` to consider **both** backtick fences and tilde fences:
- Compute `max_consecutive` for ``` and for `~` in `content`.
- Choose the fence character that yields the **shorter** safe fence (length `max_run + 1`, minimum 3).
- Return that fence string.
- (Optional) If you keep truncation as-is, ensure any future output limiting preserves fence integrity (e.g., trim inner content while keeping the closing fence), but the primary mitigation here is selecting a shorter safe fence when backticks are pathological.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider Grey Divider

Qodo Logo

Comment thread tests/unittest/test_extract_relevant_lines_str.py Outdated
Updated the content construction in the
_test_make_file method for better readability
by using parentheses for multiline strings.
Also improved the assertion message in the
test case to enhance clarity when the
expected output does not match.
@qodo-free-for-open-source-projects
Copy link
Copy Markdown
Contributor

qodo-free-for-open-source-projects bot commented Apr 11, 2026

Persistent review updated to latest commit ea88c41

The `_get_fence` utility previously only considered backtick sequences when
computing a safe outer fence for Markdown code blocks. When content (such
as a README) contained triple-backtick fenced blocks, the function would
produce a four-backtick fence. For content with even longer backtick runs,
the fence could grow arbitrarily long, risking truncation by LLM providers
or Markdown renderers with line-length limits.

The updated algorithm evaluates both backtick and tilde fence candidates
independently, then selects whichever yields the shorter safe fence. Since
most real-world Markdown content uses backtick fences and rarely contains
tilde sequences, a triple-backtick block in the content now triggers a
three-tilde fence rather than a four-backtick fence. This keeps the outer
fence at the minimum safe length in the common case.

The tie-breaking rule preserves the previous default: when both candidates
produce the same length, backticks are returned, so plain content without
either character still produces the familiar ``` fence.

All affected unit tests are updated to assert tilde fences where the old
logic would have produced four-backtick fences, and a new dedicated test
suite for `_get_fence` covers empty input, single-character runs, long
runs of each character, mixed content, tie-breaking, and the invariant
that the returned fence never appears verbatim inside the content.

Reduces the risk of provider-side truncation caused by unexpectedly long
fence lines when wrapping Markdown content that itself contains fenced
code blocks.
@qodo-free-for-open-source-projects
Copy link
Copy Markdown
Contributor

qodo-free-for-open-source-projects bot commented Apr 11, 2026

Persistent review updated to latest commit 6ca6bf5

Comment thread tests/unittest/test_extract_relevant_lines_str.py Outdated
… double quotes

Updated string literals in the test file to use double quotes for consistency
and improved readability. This change affects various sections of the code,
including the definition of Python code blocks and the construction of
synthetic files for testing. The adjustments ensure uniformity in string
formatting across the test cases.
@qodo-free-for-open-source-projects
Copy link
Copy Markdown
Contributor

qodo-free-for-open-source-projects bot commented Apr 11, 2026

Persistent review updated to latest commit 8aaea37

…unction

The change updates string literals in the `_get_fence` function from single
quotes to double quotes. This is a purely cosmetic, style-consistency
change with no behavioral impact.

Python projects often enforce a single quoting style across the codebase
to maintain readability and reduce cognitive overhead when reading code.
Tools like `black`, the widely adopted Python formatter, default to double
quotes. Aligning with this convention ensures the codebase remains
consistent and passes automated style checks without requiring exceptions
or suppressions.

Standardizing quote style reduces noise in future diffs, making it easier
to spot meaningful changes rather than stylistic ones.
@qodo-free-for-open-source-projects
Copy link
Copy Markdown
Contributor

qodo-free-for-open-source-projects bot commented Apr 12, 2026

Persistent review updated to latest commit 2a98e81

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