Skip to content

Conversation

@tisnik
Copy link
Contributor

@tisnik tisnik commented Jul 16, 2025

Description

LCORE-303: fixed issues found by pyright

Type of change

  • Refactor
  • New feature
  • Bug fix
  • CVE fix
  • Optimization
  • Documentation Update
  • Configuration Update
  • Bump-up service version
  • Bump-up dependent library
  • Bump-up library or tool used for development (does not change the final image)
  • CI configuration change
  • Konflux configuration change
  • Unit tests improvement
  • Integration tests improvement
  • End to end tests improvement

Related Tickets & Documents

  • Related Issue #LCORE-303

Summary by CodeRabbit

  • Chores
    • Extended Python linter checks to include both source code and test directories.
    • Updated test cases to use more appropriate input types and added assertions or comments to improve reliability and suppress static analysis warnings.
    • Enhanced test setup and input validation for improved consistency and error prevention.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 16, 2025

Walkthrough

The changes extend linting to include both source and test directories in the workflow and Makefile. Several tests are updated to use more appropriate input types, such as FastAPI Request, Path objects, and Headers. Additional assertions and type checker suppression comments are added to improve test robustness and static analysis compatibility.

Changes

Files/Groups Change Summary
.github/workflows/pylint.yaml, Makefile Linting scope expanded to include both src and tests directories.
tests/unit/app/endpoints/test_models.py Replaced request = None with FastAPI Request objects and updated imports accordingly.
tests/unit/auth/test_auth.py Added assertions to check configuration presence before modifying authentication module in tests.
tests/unit/auth/test_utils.py Switched from dicts to Headers objects for headers input in token extraction tests.
tests/unit/models/test_config.py Updated to use Path objects for TLS paths and added # pyright: ignore comments for static type suppression.
tests/unit/models/test_responses.py Added # pyright: ignore to lines intentionally missing required fields to suppress static checker warnings.
tests/unit/utils/test_checks.py Changed file argument from string to Path object and imported Path from pathlib.
tests/unit/utils/test_types.py Added assertions to ensure tool_parser is not None before further test logic.

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant GitHubActions
    participant Pylint

    Developer->>GitHubActions: Push code
    GitHubActions->>Pylint: Run pylint on src/
    GitHubActions->>Pylint: Run pylint on tests/
    Pylint-->>GitHubActions: Report results
    GitHubActions-->>Developer: Display lint results
Loading

Poem

In the warren, code gets checked,
Now both tests and src are decked.
Paths and headers, typed just right,
Pyright warnings out of sight.
With every hop, our tests grow strong—
Lint and logic, they both belong!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8833716 and 3a94da0.

📒 Files selected for processing (9)
  • .github/workflows/pylint.yaml (1 hunks)
  • Makefile (1 hunks)
  • tests/unit/app/endpoints/test_models.py (5 hunks)
  • tests/unit/auth/test_auth.py (1 hunks)
  • tests/unit/auth/test_utils.py (2 hunks)
  • tests/unit/models/test_config.py (3 hunks)
  • tests/unit/models/test_responses.py (2 hunks)
  • tests/unit/utils/test_checks.py (2 hunks)
  • tests/unit/utils/test_types.py (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (4)
tests/unit/models/test_responses.py (1)
src/models/responses.py (2)
  • AuthorizedResponse (247-268)
  • UnauthorizedResponse (271-285)
tests/unit/models/test_config.py (1)
src/models/config.py (2)
  • TLSConfiguration (13-23)
  • ModelContextProtocolServer (49-54)
tests/unit/auth/test_utils.py (1)
src/auth/utils.py (1)
  • extract_user_token (7-26)
tests/unit/utils/test_checks.py (1)
src/utils/checks.py (1)
  • file_check (22-27)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build-pr
🔇 Additional comments (17)
Makefile (1)

63-63: Good practice to extend linting coverage to tests.

Including the tests directory in pylint ensures consistent code quality across both source and test files, which aligns with the PR objective of improving static analysis coverage.

.github/workflows/pylint.yaml (1)

23-23: Consistent linting configuration between local and CI environments.

The change maintains alignment with the Makefile pylint target, ensuring both local development and CI pipeline check the same directories for code quality.

tests/unit/models/test_responses.py (3)

65-65: Appropriate use of pyright ignore for intentional type violations.

The comment correctly suppresses static type checker warnings for test cases that intentionally omit required fields to verify ValidationError handling.


68-70: Appropriate use of pyright ignore for intentional type violations.

The comment correctly suppresses static type checker warnings for test cases that intentionally omit required fields to verify ValidationError handling.


86-86: Appropriate use of pyright ignore for intentional type violations.

The comment correctly suppresses static type checker warnings for test cases that intentionally omit required fields to verify ValidationError handling.

tests/unit/auth/test_auth.py (3)

11-11: Good defensive programming with null checks.

Adding assertions to verify configuration.authentication_configuration is not None before accessing its attributes prevents potential AttributeError exceptions and makes the tests more robust.


19-19: Good defensive programming with null checks.

Adding assertions to verify configuration.authentication_configuration is not None before accessing its attributes prevents potential AttributeError exceptions and makes the tests more robust.


27-27: Good defensive programming with null checks.

Adding assertions to verify configuration.authentication_configuration is not None before accessing its attributes prevents potential AttributeError exceptions and makes the tests more robust.

tests/unit/utils/test_checks.py (2)

4-4: Good import addition for Path type.

Importing Path from pathlib enables more type-safe file path handling in the test.


73-73: Improved type safety with Path object.

Using Path("does-not-exists") instead of a string literal provides better type safety and aligns with modern Python practices for file path handling.

tests/unit/auth/test_utils.py (2)

4-4: Good addition of proper import for Headers.

The import aligns with the function signature and improves type correctness.


11-11: Excellent improvement to use proper Headers objects.

The change from plain dictionaries to Headers objects correctly matches the expected parameter type in extract_user_token function, which expects headers: Headers as shown in the relevant code snippet from src/auth/utils.py. This improves type safety and test accuracy.

Also applies to: 18-18, 28-28

tests/unit/utils/test_types.py (1)

31-31: Good defensive programming with null checks.

The added assertions ensure that tool_parser is not None before proceeding with the test logic, preventing potential AttributeError exceptions and making the tests more robust. This aligns with the PR objective of fixing pyright issues.

Also applies to: 37-37, 47-47

tests/unit/models/test_config.py (2)

190-192: Excellent improvement to use Path objects.

The change from string paths to Path objects correctly aligns with the FilePath type used in TLSConfiguration as shown in the relevant code snippet. This improves type safety and test accuracy.

Also applies to: 204-206, 214-216, 224-226, 234-236, 244-246, 254-256


286-286: Appropriate use of pyright ignore comments.

The # pyright: ignore comments are correctly placed on lines that intentionally create ModelContextProtocolServer objects without required fields to test validation errors. This suppresses expected type checker warnings for these intentional test cases.

Also applies to: 289-289, 292-292

tests/unit/app/endpoints/test_models.py (2)

7-7: Good addition of Request import.

The import of Request from FastAPI enables the creation of proper request objects in tests.


22-27: Excellent improvement to use proper Request objects.

The change from request = None to creating proper Request objects with minimal HTTP scope and authorization headers significantly improves test accuracy and realism. This addresses type correctness issues and makes the tests more representative of actual HTTP requests.

Also applies to: 67-72, 105-110, 152-157

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@tisnik tisnik force-pushed the lcore-303-fixed-issues-found-by-pyright branch from 7500b07 to 3a94da0 Compare July 16, 2025 06:19
@tisnik tisnik merged commit 27c7894 into lightspeed-core:main Jul 16, 2025
17 checks passed
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