Visitar URL original
fix(diff): compare bad file extensions case-insensitively by MaxFreedomPollard · Pull Request #3103 · The-PR-Agent/pr-agent · GitHub
Skip to content

fix(diff): compare bad file extensions case-insensitively - #3103

Merged
IsmaelMartinez merged 1 commit into
The-PR-Agent:mainfrom
MaxFreedomPollard:fix/bad-extension-case
Sep 7, 2026
Merged

IsmaelMartinez merged 1 commit into
The-PR-Agent:mainfrom
MaxFreedomPollard:fix/bad-extension-case

Conversation

@MaxFreedomPollard

Copy link
Copy Markdown
Contributor

What

pr_agent/algo/language_handler.py: lower-case both sides of the extension comparison in is_valid_file(), so bad_extensions matches whatever casing a repository actually uses.

tests/unittest/test_bad_extension_case.py: 15 new tests covering uppercase and mixed-case extensions, the unchanged lower-case behaviour, files that must still be reviewed, a user-supplied bad_extensions entry in either casing, and filter_bad_extensions().

Why

is_valid_file() ended with return filename.split('.')[-1] not in bad_extensions (pr_agent/algo/language_handler.py:35), and every entry of bad_extensions.default in pr_agent/settings/language_extensions.toml is spelled in lower case. The comparison only ever matched a lower-case extension, so the same file was filtered or not depending on how its name happens to be capitalised.

On main:

>>> from pr_agent.algo.language_handler import is_valid_file
>>> is_valid_file("logo.svg"), is_valid_file("logo.SVG")
(False, True)
>>> is_valid_file("report.csv"), is_valid_file("report.CSV")
(False, True)

That is not only a cosmetic mismatch, because several of the filtered types are text rather than binary. GitHub and GitLab return a real patch for .SVG and .CSV, so an uppercase-named one survives the filter, reaches sort_files_by_main_languages(), and lands in the diff sent to the model, taking token budget away from the source files the review is about. .JPG and .ZIP files stay in the file list for the same reason. Every provider filters through this one function, so this is not provider-specific: github_provider.py:318, gitlab_provider.py:831, bitbucket_provider.py:323, bitbucket_server_provider.py:283, gitea_provider.py:194 and :590, azuredevops_provider.py:555 and :807, codecommit_provider.py:139.

Only the extension comparison changed. The auto-generated lockfile names and the .min.js style suffixes just above it are untouched, and no uppercase extension in language_extension_map_org (.C, .H, .E, .ML, .tmTheme and friends) collides with a bad_extensions entry once lower-cased, so no language loses files to this.

Testing

PYTHONPATH=. uv run pytest tests/unittest/test_bad_extension_case.py -q on this branch: 15 passed. With only the language_handler.py change reverted: 8 failed, 7 passed, the 7 passing ones being the cases that pin the existing behaviour.

PYTHONPATH=. uv run pytest tests/unittest -q: 3738 passed, 1 skipped, 1 xfailed in 164s.

uv run ruff check pr_agent/algo/language_handler.py tests/unittest/test_bad_extension_case.py: All checks passed.

uv run pre-commit run --files pr_agent/algo/language_handler.py tests/unittest/test_bad_extension_case.py: every applicable hook passed.

is_valid_file() ended with `filename.split('.')[-1] not in bad_extensions`
(pr_agent/algo/language_handler.py:35), and every entry of
bad_extensions.default in pr_agent/settings/language_extensions.toml is
spelled in lower case. A file named logo.SVG, report.CSV or photo.JPG was
therefore treated as reviewable while the identical lower-case name was
filtered out. SVG and CSV are text, so those diffs are real and spend the
token budget the source files need. Every git provider filters through this
one function, so the leak was not provider-specific.

Lower-case both sides of the extension comparison, and add
tests/unittest/test_bad_extension_case.py covering uppercase and mixed-case
extensions, the unchanged lower-case behaviour, files that must still be
reviewed, and a user-configured bad_extensions entry in either casing.
@github-actions github-actions Bot added the bug label Sep 6, 2026
@qodo-code-review

qodo-code-review Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Code Review by Qodo

Grey Divider

Sorry, something went wrong

We weren't able to complete the code review on our side. Please try again manually by commenting /agentic_review on this PR.

Grey Divider

Qodo Logo

@IsmaelMartinez IsmaelMartinez left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks, and welcome. First direct test is_valid_file has had, and it goes red on main.

@IsmaelMartinez
IsmaelMartinez merged commit d6c8b9a into The-PR-Agent:main Sep 7, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants