Skip to content

LCORE-814: fixed issues found by Pyright#661

Merged
tisnik merged 1 commit intolightspeed-core:mainfrom
tisnik:lcore-814-fixed-issues-found-by-pyright
Oct 13, 2025
Merged

LCORE-814: fixed issues found by Pyright#661
tisnik merged 1 commit intolightspeed-core:mainfrom
tisnik:lcore-814-fixed-issues-found-by-pyright

Conversation

@tisnik
Copy link
Contributor

@tisnik tisnik commented Oct 13, 2025

Description

LCORE-814: 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-814

Summary by CodeRabbit

  • Tests
    • Expanded unit test coverage for endpoint utilities with stricter type and value assertions across edge cases (metadata handling, deduplication, invalid URLs, empty sources).
    • Strengthened verification of referenced document creation to ensure consistent structure and content.
    • Improves reliability and confidence in behavior under varied scenarios.
    • No functional changes to the user experience.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 13, 2025

Walkthrough

Tests in tests/unit/utils/test_endpoints.py were expanded to include stricter runtime assertions and type checks involving ReferencedDocument. Multiple test scenarios for create_referenced_documents were augmented to validate instance types, presence, and specific field values across different input variations and edge cases.

Changes

Cohort / File(s) Summary of edits
Unit tests: endpoints
tests/unit/utils/test_endpoints.py
Imported ReferencedDocument; reformatted QueryRequest constructions; added pyright ignores; expanded assertions to check result counts, non-nullity, instance types, and specific doc_url/doc_title across cases (with/without metadata, deduping, skipping tool names/empty sources, invalid URLs).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

In labs of tests I thump and hop,
I sniff each doc from tip to top.
Two carrots tall, their titles true—
URLs crisp like morning dew.
With type checks snug, I cheer, “All right!”
Our burrow’s safer every night. 🥕✨

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title Check ❓ Inconclusive The title labels a ticket and states a generic fix for Pyright issues but does not convey the specific changes such as adding type checks and updating test fixtures for ReferencedDocument, making it too broad to describe the main changes clearly. Consider refining the title to specify the main change, for example: “LCORE-814: update tests for ReferencedDocument and add Pyright ignore comments,” so it clearly reflects the scope of updates.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
tests/unit/utils/test_endpoints.py (2)

873-880: Remove redundant runtime type assertions.

The added assertions checking for non-None values and isinstance(ReferencedDocument) are redundant and don't address the root cause of Pyright issues:

  1. Redundant None checks: After asserting len(result) == 2, checking result[0] is not None is unnecessary - if a list has length 2, both elements exist.

  2. Implementation testing vs. contract testing: The isinstance checks verify runtime types rather than testing behavior. If create_referenced_documents is properly typed to return list[ReferencedDocument], Pyright should trust that without runtime checks.

  3. Runtime checks don't fix static analysis: These assertions only execute during tests and don't help Pyright understand the types. To fix Pyright issues, you need proper type hints and type guards in the implementation, not runtime assertions in tests.

Instead, focus the tests on behavioral aspects (correct URLs, titles, deduplication, filtering) which are already being tested by the subsequent assertions.

If Pyright is complaining about potential None values or wrong types in the create_referenced_documents function, the fix should be in that function's type hints or implementation, not in the tests.

Also applies to: 901-908, 922-927, 942-947, 965-972, 984-991


115-117: Add explanatory comment to Pyright ignores on QueryRequest

The # pyright: ignore[reportCallIssue] on QueryRequest(...) is necessary because Pydantic’s BaseModel uses a dynamic __init__ signature that Pyright can’t statically infer. Keep the ignore and append a note, e.g.:

# pyright: ignore[reportCallIssue]  # Pydantic BaseModel dynamic __init__ signature
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8cea1a0 and afcb1b9.

📒 Files selected for processing (1)
  • tests/unit/utils/test_endpoints.py (10 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.py

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.py: All modules start with descriptive module-level docstrings explaining purpose
Use logger = logging.getLogger(name) for module logging after import logging
Define type aliases at module level for clarity
All functions require docstrings with brief descriptions
Provide complete type annotations for all function parameters and return types
Use typing_extensions.Self in model validators where appropriate
Use modern union syntax (str | int) and Optional[T] or T | None consistently
Function names use snake_case with descriptive, action-oriented prefixes (get_, validate_, check_)
Avoid in-place parameter modification; return new data structures instead of mutating arguments
Use appropriate logging levels: debug, info, warning, error with clear messages
All classes require descriptive docstrings explaining purpose
Class names use PascalCase with conventional suffixes (Configuration, Error/Exception, Resolver, Interface)
Abstract base classes should use abc.ABC and @AbstractMethod for interfaces
Provide complete type annotations for all class attributes
Follow Google Python docstring style for modules, classes, and functions, including Args, Returns, Raises, Attributes sections as needed

Files:

  • tests/unit/utils/test_endpoints.py
tests/{unit,integration}/**/*.py

📄 CodeRabbit inference engine (CLAUDE.md)

tests/{unit,integration}/**/*.py: Use pytest for all unit and integration tests
Do not use unittest in tests; pytest is the standard

Files:

  • tests/unit/utils/test_endpoints.py
tests/**/*.py

📄 CodeRabbit inference engine (CLAUDE.md)

tests/**/*.py: Use pytest-mock to create AsyncMock objects for async interactions in tests
Use the shared auth mock constant: MOCK_AUTH = ("mock_user_id", "mock_username", False, "mock_token") in tests

Files:

  • tests/unit/utils/test_endpoints.py
🧬 Code graph analysis (1)
tests/unit/utils/test_endpoints.py (4)
src/models/responses.py (1)
  • ReferencedDocument (164-176)
src/models/requests.py (1)
  • QueryRequest (73-225)
src/models/config.py (1)
  • Action (328-374)
src/utils/endpoints.py (1)
  • validate_model_provider_override (164-184)
⏰ 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). (3)
  • GitHub Check: build-pr
  • GitHub Check: e2e_tests (ci)
  • GitHub Check: e2e_tests (azure)
🔇 Additional comments (1)
tests/unit/utils/test_endpoints.py (1)

11-11: LGTM!

The import is necessary for the runtime type checks added in the test assertions.

@tisnik tisnik merged commit d1427be into lightspeed-core:main Oct 13, 2025
18 of 20 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