chore: add ruff linter and pyright for Python test code#784
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. 🗂️ Base branches to auto review (2)
Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Enterprise Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #784 +/- ##
=======================================
Coverage 27.96% 27.96%
=======================================
Files 21 21
Lines 2596 2596
Branches 2596 2596
=======================================
Hits 726 726
Misses 1867 1867
Partials 3 3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
6ce4ab0 to
5c3f632
Compare
Move ruff.toml and pyrightconfig.json into tests/ so both tools find their config when run from that directory. Add a lint target to tests/Makefile and a top-level lint target that also runs cargo clippy. Wire up an isolated lint-tests CI job. Assisted-by: Claude Code (claude-opus-4-6)
Add type annotations to all test function parameters and fix import sorting for first-party modules. Add assert guards for Container.id (typed str | None by docker stubs) and getoption return values. Add pyright ignore comments for generated protobuf imports. Assisted-by: Claude Code (claude-opus-4-6)
5c3f632 to
9bc97b4
Compare
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
tests/event.py (1)
282-296:⚠️ Potential issue | 🟠 Major | ⚡ Quick winMissing guard for
Noneexpected values.The
_diff_pathmethod now acceptsexpected: str | Pattern[str] | None, but whenexpectedisNone, the current implementation will incorrectly record a diff. Line 295 evaluatesNone != actualasTrue(sinceactualis a string), causing an unwanted diff entry.If
expectedisNone, the intent is likely to skip validation entirely (e.g., when the test doesn't care aboutold_fileorold_host_pathin rename events). Add an early return whenexpected is None.🛡️ Proposed fix
def _diff_path( cls, diff: dict, name: str, expected: str | Pattern[str] | None, actual: str, ): """ Compare paths with regex pattern support. """ + if expected is None: + return if isinstance(expected, Pattern): if not expected.match(actual): diff[name] = {'expected': f'{expected}', 'actual': actual} elif expected != actual: diff[name] = {'expected': expected, 'actual': actual}🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/event.py` around lines 282 - 296, The _diff_path method incorrectly treats expected=None as a mismatch; update the function (named _diff_path) to early-return when expected is None so no diff is recorded for unspecified expectations, e.g., add a guard "if expected is None: return" at the start of the method before the Pattern check so only strings or regex patterns are validated and diff[name] is only set for real mismatches.
🧹 Nitpick comments (1)
.github/workflows/ci.yml (1)
102-117: 💤 Low valueConsider adding explicit permissions and disabling credential persistence.
The static analysis tool flagged potential security improvements for this job:
- No explicit
permissions:block (defaults to broad permissions)persist-credentials: falsenot set in checkout actionWhile these are low-risk for a lint-only job without secrets, adding explicit minimal permissions follows security best practices.
🔒 Suggested hardening
lint-tests: runs-on: ubuntu-24.04 + permissions: + contents: read steps: - uses: actions/checkout@v4 with: submodules: true + persist-credentials: false🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In @.github/workflows/ci.yml around lines 102 - 117, The lint-tests job lacks explicit permissions and doesn't disable credential persistence; update the job "lint-tests" to add a minimal permissions: block (e.g., set contents: read and other required actions to least privilege) and modify the actions/checkout step by adding persist-credentials: false to prevent token persistence; ensure these changes are applied within the lint-tests job definition to harden the workflow while keeping the job's existing steps (setup-python, Lint commands) unchanged.Source: Linters/SAST tools
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@tests/event.py`:
- Around line 282-296: The _diff_path method incorrectly treats expected=None as
a mismatch; update the function (named _diff_path) to early-return when expected
is None so no diff is recorded for unspecified expectations, e.g., add a guard
"if expected is None: return" at the start of the method before the Pattern
check so only strings or regex patterns are validated and diff[name] is only set
for real mismatches.
---
Nitpick comments:
In @.github/workflows/ci.yml:
- Around line 102-117: The lint-tests job lacks explicit permissions and doesn't
disable credential persistence; update the job "lint-tests" to add a minimal
permissions: block (e.g., set contents: read and other required actions to least
privilege) and modify the actions/checkout step by adding persist-credentials:
false to prevent token persistence; ensure these changes are applied within the
lint-tests job definition to harden the workflow while keeping the job's
existing steps (setup-python, Lint commands) unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Enterprise
Run ID: 1c591760-7cb3-4f5b-aad6-468fd5141754
📒 Files selected for processing (27)
.github/workflows/ci.ymlCHANGELOG.mdMakefileruff.tomltests/Makefiletests/conftest.pytests/event.pytests/pyrightconfig.jsontests/ruff.tomltests/server.pytests/test_config_hotreload.pytests/test_editors/commons.pytests/test_editors/test_nvim.pytests/test_editors/test_sed.pytests/test_editors/test_vi.pytests/test_editors/test_vim.pytests/test_file_open.pytests/test_misc.pytests/test_path_chmod.pytests/test_path_chown.pytests/test_path_mkdir.pytests/test_path_rename.pytests/test_path_rmdir.pytests/test_path_unlink.pytests/test_rate_limit.pytests/test_wildcard.pytests/utils.py
💤 Files with no reviewable changes (1)
- ruff.toml
Description
This add linter checks via ruff and static type analysis with pyright. In order to make it easier to review, there are 2 commits in this PR:
ruffandpyright, both on CI and locally.Most of the issues were pretty trivial and were fixed with
ruff check --fix, most invasive change is adding type annotations to all functions and methods sopyrightcan work properly.Checklist
Automated testing
If any of these don't apply, please comment below.
Testing Performed
Run the new make targets locally.
Summary by CodeRabbit
Release Notes