You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(github): honor line references in ?plain=1 links in github_files_tool - #2525
GitHub adds ?plain=1 to line links for rendered files such as Markdown. The URL pattern in github_files_tool stopped at the ?, so the line reference was lost and the tool returned the whole file. The pattern now skips the query string.
While in the same code, two line references returned wrong output with no error. #L0 returned the last line of the file, and a reversed range returned an empty block. Both now return an Error: message, like line numbers past the end of the file already do.
Real calls through the tool's function, for links to README.md at 349aacd:
Added test_get_file_handles_line_references in packages/nvidia_nat_core/tests/nat/tools/test_github_tools.py, using the same httpx.MockTransport setup as the other file tool test. Four of its five cases fail on develop. The fifth, a ?plain=1 link with no line, passes on both and guards the whole file path.
Validation:
pytest packages/nvidia_nat_core/tests/nat/tools/test_github_tools.py: 34 passed (4 failed, 30 passed on develop).
yapf --diff and ruff check on both changed files: no changes or findings.
We require that all contributors "sign-off" on their commits. This certifies that the contribution is your original work, or you have rights to submit it under the same license, or a compatible license.
Any contribution which contains commits that are not Signed-Off will not be accepted.
When the PR is ready for review, new or existing tests cover these changes.
When the PR is ready for review, the documentation is up to date with these changes.
Summary by CodeRabbit
Bug Fixes
GitHub file links with query strings and line references are now handled correctly.
Invalid line numbers and reversed line ranges now return errors.
…tool
GitHub adds ?plain=1 to line links for rendered files such as Markdown.
The URL pattern stopped at the query string and lost the line reference,
so the tool returned the whole file. Also report #L0 and reversed ranges
as errors instead of returning the last line or an empty block.
Signed-off-by: abhishekacharya200 <abhishekacharya200@users.noreply.github.com>
github_files_tool now accepts query strings before line fragments and validates requested line ranges. Parameterized tests cover selected lines, full-file output, and invalid ranges.
Changes
GitHub file line references
Layer / File(s)
Summary
URL matching and line-range handling packages/nvidia_nat_core/src/nat/tool/github_tools.py, packages/nvidia_nat_core/tests/nat/tools/test_github_tools.py
The URL pattern accepts a query string before a line fragment. The tool rejects start line 0 and reversed ranges. Tests cover selected lines, full-file output, and range errors.
No actionable merge-blocking risk is established by the reviewed change.
Pre-merge checks: 5
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title clearly describes the GitHub line-reference fix and uses imperative mood. At 73 characters, it is approximately within the 72-character target.
Linked Issues check
Issue #2524 requires three coding outcomes. The URL pattern now accepts query text before the fragment, so ?plain=1#L... references remain available. The implementation rejects start lines below 1 a…
Out of Scope Changes check
The diff changes only github_tools.py and its focused test file. The production changes implement issue #2524. The added tests directly verify the requested behavior. No unrelated change is demonstr…
Docstring Coverage
Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Full details: Linked Issues check
Explanation
Issue #2524 requires three coding outcomes. The URL pattern now accepts query text before the fragment, so ?plain=1#L... references remain available. The implementation rejects start lines below 1 and rejects reversed ranges with Error: messages. The added parameterized test covers a query-string line, a query-string range, a query string without a line, #L0, and a reversed range.
Full details: Out of Scope Changes check
Explanation
The diff changes only github_tools.py and its focused test file. The production changes implement issue #2524. The added tests directly verify the requested behavior. No unrelated change is demonstrated.
Full details: Docstring Coverage
Explanation
Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 2 files.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
508-508: Minor · Functional Correctness · Quick win
Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.
Use GitHub-compatible line boundaries.
splitlines() treats form feeds as line boundaries, unlike GitHub Markdown line endings. (docs.python.org) For alpha\fbravo\ncharlie\n, a newly supported ?plain=1#L2 link returns bravo instead of charlie. Split on CR, LF, and CRLF boundaries instead.
Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
GitHub adds
?plain=1to line links for rendered files such as Markdown. The URL pattern ingithub_files_toolstopped at the?, so the line reference was lost and the tool returned the whole file. The pattern now skips the query string.While in the same code, two line references returned wrong output with no error.
#L0returned the last line of the file, and a reversed range returned an empty block. Both now return anError:message, like line numbers past the end of the file already do.Real calls through the tool's function, for links to
README.mdat 349aacd:develop(349aacd)?plain=1#L18?plain=1#L18-L19#L0Error: Line 0 is out of range for the file ...#L19-L18Error: Line range 19-18 is reversed#L18Added
test_get_file_handles_line_referencesinpackages/nvidia_nat_core/tests/nat/tools/test_github_tools.py, using the samehttpx.MockTransportsetup as the other file tool test. Four of its five cases fail ondevelop. The fifth, a?plain=1link with no line, passes on both and guards the whole file path.Validation:
pytest packages/nvidia_nat_core/tests/nat/tools/test_github_tools.py: 34 passed (4 failed, 30 passed ondevelop).yapf --diffandruff checkon both changed files: no changes or findings.Closes #2524
Maintainer metadata: please add the
bugandnon-breakinglabels.By Submitting this PR I confirm:
Summary by CodeRabbit