Skip to content

Conversation

@tisnik
Copy link
Contributor

@tisnik tisnik commented Nov 4, 2025

Description

LCORE-740: type hints for rest of unit tests

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-740

Summary by CodeRabbit

  • Tests
    • Enhanced type safety across the test suite with comprehensive type annotations.
    • Added explicit return type hints to all test functions and fixtures.
    • Introduced parameter type annotations for test methods and helpers.
    • Strengthened mock class signatures with complete type declarations.
    • Improved code clarity and reliability through stronger static typing throughout test modules.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 4, 2025

Walkthrough

This PR systematically adds explicit type annotations throughout the test suite, introducing return type hints (primarily -> None) to test functions and fixtures, adding typed parameters to methods, and importing necessary typing utilities. No functional behavior changes; purely static type improvements.

Changes

Cohort / File(s) Summary
Database Tests
tests/unit/app/test_database.py
Added typing imports (Generator, MockType); added return type hints to fixtures (-> Generator, -> PostgreSQLDatabaseConfiguration) and all test methods (-> None); added type annotations to helper methods (_setup_common_mocks -> tuple[MockType, MockType], _verify_common_assertions with explicit MockType parameters).
Router Tests
tests/unit/app/test_routers.py
Extended include_router method signature with Optional[...] type annotations for parameters (tags, dependencies, responses, deprecated, include_in_schema, default_response_class, callbacks, generate_unique_id_function); added Sequence and Callable imports.
Authentication: JWT Token Tests
tests/unit/authentication/test_jwk_token.py
Added comprehensive type annotations to fixtures and helpers with return types (-> dict[str, Any], -> str, -> Request, -> Generator, -> tuple[str, str, str]); typed all fixture parameters (single_key_set: list[dict[str, Any]], token_header: dict[str, Any], etc.); updated test function signatures to include typed parameters and -> None returns.
Authentication: Kubernetes Tests
tests/unit/authentication/test_k8s.py
Added explicit type annotations to MockK8sResponseStatus, MockK8sUser, and MockK8sResponse constructors with Optional[...] parameters and -> None returns; updated all test function signatures to include -> None return types.
Authentication: NoOp Tests
tests/unit/authentication/test_noop.py
Added -> None return type annotations to test_noop_auth_dependency and test_noop_auth_dependency_custom_user_id.
Authentication: NoOp with Token Tests
tests/unit/authentication/test_noop_with_token.py
Added -> None return type annotations to four async test functions (test_noop_with_token_auth_dependency, test_noop_with_token_auth_dependency_custom_user_id, test_noop_with_token_auth_dependency_no_token, test_noop_with_token_auth_dependency_no_bearer).
Authentication: Utils Tests
tests/unit/authentication/test_utils.py
Added -> None return type annotations to three test functions.
Authorization: Resolvers Tests
tests/unit/authorization/test_resolvers.py
Added typing.Any import; added return type annotations to fixtures (JwtRoleRule, JwtRolesResolver, dict[str, Any], list[AccessRule]) and test methods (-> None); updated test method signatures with typed fixture parameters.
Configuration Tests
tests/unit/test_configuration_unknown_fields.py
Added -> None return type annotation to test_configuration_rejects_unknown_fields.
Utils: Version Tests
tests/unit/utils/test_llama_stack_version.py
Added typing imports (Any, SubTests); added return type annotations (-> None) to test functions; introduced _check_version_must_fail helper with typed parameters (mock_client: Any, bigger_version: Version) -> None; updated test_check_llama_stack_version_too_big_version to accept subtests: SubTests parameter.
Utils: Transcripts Tests
tests/unit/utils/test_transcripts.py
Updated imports to include Attachment; added -> None return type annotations; updated local variable typing (rag_chunks: list[dict], attachments: list[Attachment]).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Primary focus: Verify consistency of return type annotations across all test methods (predominantly -> None and appropriate fixture return types)
  • Secondary focus: Ensure all imported typing utilities (Generator, MockType, Any, SubTests, etc.) are correctly used and resolve without conflicts
  • Attention areas:
    • tests/unit/app/test_database.py: Complex tuple return types for helper methods; verify PostgreSQLDatabaseConfiguration type references
    • tests/unit/authentication/test_jwk_token.py: Extensive parametrized fixture chains with nested dict and tuple typing; confirm tuple[str, str, str] and dict[str, Any] patterns are consistent
    • tests/unit/authorization/test_resolvers.py: Multiple fixture return types; ensure JwtRoleRule, JwtRolesResolver, and AccessRule types are properly imported/defined

Possibly related PRs

Suggested reviewers

  • manstis
  • ldjebran
  • maorfr

Poem

🐰 Hops with glee through typed test halls,
Where annotations now grace every call,
From fixtures to functions, return types bloom,
None declares clarity, doubt finds no room! 🎀

Pre-merge checks and finishing touches

✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and clearly describes the main objective of the PR: adding type hints across the remaining unit tests. It accurately reflects the primary change across all modified test files.
✨ 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: 7

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b52ea28 and 56d8e06.

📒 Files selected for processing (11)
  • tests/unit/app/test_database.py (21 hunks)
  • tests/unit/app/test_routers.py (2 hunks)
  • tests/unit/authentication/test_jwk_token.py (29 hunks)
  • tests/unit/authentication/test_k8s.py (11 hunks)
  • tests/unit/authentication/test_noop.py (2 hunks)
  • tests/unit/authentication/test_noop_with_token.py (4 hunks)
  • tests/unit/authentication/test_utils.py (2 hunks)
  • tests/unit/authorization/test_resolvers.py (19 hunks)
  • tests/unit/test_configuration_unknown_fields.py (1 hunks)
  • tests/unit/utils/test_llama_stack_version.py (6 hunks)
  • tests/unit/utils/test_transcripts.py (4 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/authentication/test_utils.py
  • tests/unit/test_configuration_unknown_fields.py
  • tests/unit/utils/test_llama_stack_version.py
  • tests/unit/utils/test_transcripts.py
  • tests/unit/authentication/test_noop.py
  • tests/unit/authentication/test_k8s.py
  • tests/unit/app/test_database.py
  • tests/unit/authentication/test_noop_with_token.py
  • tests/unit/app/test_routers.py
  • tests/unit/authorization/test_resolvers.py
  • tests/unit/authentication/test_jwk_token.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/authentication/test_utils.py
  • tests/unit/test_configuration_unknown_fields.py
  • tests/unit/utils/test_llama_stack_version.py
  • tests/unit/utils/test_transcripts.py
  • tests/unit/authentication/test_noop.py
  • tests/unit/authentication/test_k8s.py
  • tests/unit/app/test_database.py
  • tests/unit/authentication/test_noop_with_token.py
  • tests/unit/app/test_routers.py
  • tests/unit/authorization/test_resolvers.py
  • tests/unit/authentication/test_jwk_token.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/authentication/test_utils.py
  • tests/unit/test_configuration_unknown_fields.py
  • tests/unit/utils/test_llama_stack_version.py
  • tests/unit/utils/test_transcripts.py
  • tests/unit/authentication/test_noop.py
  • tests/unit/authentication/test_k8s.py
  • tests/unit/app/test_database.py
  • tests/unit/authentication/test_noop_with_token.py
  • tests/unit/app/test_routers.py
  • tests/unit/authorization/test_resolvers.py
  • tests/unit/authentication/test_jwk_token.py
🧠 Learnings (8)
📓 Common learnings
Learnt from: CR
Repo: lightspeed-core/lightspeed-stack PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-09-18T16:46:33.353Z
Learning: Applies to **/*.py : Provide complete type annotations for all function parameters and return types
Learnt from: CR
Repo: lightspeed-core/lightspeed-stack PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-09-18T16:46:33.353Z
Learning: Applies to **/*.py : Provide complete type annotations for all class attributes
Learnt from: CR
Repo: lightspeed-core/lightspeed-stack PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-09-18T16:46:33.353Z
Learning: Applies to src/{models/**/*.py,configuration.py} : Use precise type hints in configuration (e.g., Optional[FilePath], PositiveInt, SecretStr)
📚 Learning: 2025-09-18T16:46:33.353Z
Learnt from: CR
Repo: lightspeed-core/lightspeed-stack PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-09-18T16:46:33.353Z
Learning: Applies to **/*.py : Provide complete type annotations for all function parameters and return types

Applied to files:

  • tests/unit/authentication/test_utils.py
📚 Learning: 2025-09-18T16:46:33.353Z
Learnt from: CR
Repo: lightspeed-core/lightspeed-stack PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-09-18T16:46:33.353Z
Learning: Applies to **/*.py : Provide complete type annotations for all class attributes

Applied to files:

  • tests/unit/authentication/test_utils.py
📚 Learning: 2025-09-18T16:46:33.353Z
Learnt from: CR
Repo: lightspeed-core/lightspeed-stack PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-09-18T16:46:33.353Z
Learning: Applies to src/{models/config.py,configuration.py} : Configuration base models must set model_config with extra="forbid" to reject unknown fields

Applied to files:

  • tests/unit/test_configuration_unknown_fields.py
📚 Learning: 2025-09-02T11:09:40.404Z
Learnt from: radofuchs
Repo: lightspeed-core/lightspeed-stack PR: 485
File: tests/e2e/features/environment.py:87-95
Timestamp: 2025-09-02T11:09:40.404Z
Learning: In the lightspeed-stack e2e tests, noop authentication tests use the default lightspeed-stack.yaml configuration, while noop-with-token tests use the Authorized tag to trigger a config swap to the specialized noop-with-token configuration file.

Applied to files:

  • tests/unit/authentication/test_noop.py
  • tests/unit/authentication/test_noop_with_token.py
  • tests/unit/authentication/test_jwk_token.py
📚 Learning: 2025-09-18T16:46:33.353Z
Learnt from: CR
Repo: lightspeed-core/lightspeed-stack PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-09-18T16:46:33.353Z
Learning: Applies to tests/**/*.py : Use the shared auth mock constant: MOCK_AUTH = ("mock_user_id", "mock_username", False, "mock_token") in tests

Applied to files:

  • tests/unit/authentication/test_k8s.py
📚 Learning: 2025-09-18T16:46:33.353Z
Learnt from: CR
Repo: lightspeed-core/lightspeed-stack PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-09-18T16:46:33.353Z
Learning: Applies to tests/**/*.py : Use pytest-mock to create AsyncMock objects for async interactions in tests

Applied to files:

  • tests/unit/authentication/test_k8s.py
📚 Learning: 2025-09-02T11:15:02.411Z
Learnt from: radofuchs
Repo: lightspeed-core/lightspeed-stack PR: 485
File: tests/e2e/test_list.txt:2-3
Timestamp: 2025-09-02T11:15:02.411Z
Learning: In the lightspeed-stack e2e tests, the Authorized tag is intentionally omitted from noop authentication tests because they are designed to test against the default lightspeed-stack.yaml configuration rather than the specialized noop-with-token configuration.

Applied to files:

  • tests/unit/authentication/test_noop_with_token.py
🧬 Code graph analysis (6)
tests/unit/authentication/test_utils.py (1)
src/authentication/utils.py (1)
  • extract_user_token (7-26)
tests/unit/utils/test_transcripts.py (1)
src/models/requests.py (2)
  • Attachment (16-70)
  • QueryRequest (73-225)
tests/unit/authentication/test_k8s.py (1)
src/authentication/k8s.py (1)
  • K8sClientSingleton (30-164)
tests/unit/app/test_database.py (1)
src/models/config.py (1)
  • PostgreSQLDatabaseConfiguration (87-105)
tests/unit/authorization/test_resolvers.py (2)
src/models/config.py (3)
  • JwtRoleRule (268-326)
  • AccessRule (378-382)
  • Action (329-375)
src/authorization/resolvers.py (11)
  • JwtRolesResolver (53-116)
  • resolve_roles (29-30)
  • resolve_roles (36-39)
  • resolve_roles (60-67)
  • GenericAccessResolver (146-202)
  • check_access (123-124)
  • check_access (134-138)
  • check_access (171-188)
  • get_actions (127-128)
  • get_actions (140-143)
  • get_actions (190-202)
tests/unit/authentication/test_jwk_token.py (1)
src/models/config.py (2)
  • JwkConfiguration (403-407)
  • JwtConfiguration (393-400)
⏰ 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). (4)
  • GitHub Check: build-pr
  • GitHub Check: Konflux kflux-prd-rh02 / lightspeed-stack-on-pull-request
  • GitHub Check: e2e_tests (ci)
  • GitHub Check: e2e_tests (azure)
🔇 Additional comments (12)
tests/unit/authentication/test_utils.py (1)

9-9: LGTM! Proper return type annotations added.

The explicit -> None return type annotations align with the coding guidelines for complete type annotations.

Also applies to: 16-16, 26-26

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

7-7: LGTM! Comprehensive type annotations added.

The changes properly annotate test functions with return types and improve local variable type hints. The Attachment import is correctly added to support the type hint on line 88.

Also applies to: 16-16, 55-55, 86-86, 88-88

tests/unit/test_configuration_unknown_fields.py (1)

9-9: LGTM! Return type annotation added.

The explicit return type annotation is correct and aligns with the coding guidelines.

tests/unit/authentication/test_noop.py (1)

8-8: LGTM! Async function return types added.

The -> None return type annotations are correct for async test functions.

Also applies to: 25-25

tests/unit/app/test_routers.py (1)

3-3: LGTM! Mock method properly typed.

The type annotations for include_router parameters align with FastAPI's actual signature, improving type safety in tests.

Also applies to: 35-48

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

3-9: LGTM! Comprehensive type annotations added.

The changes properly annotate test functions, helper functions, and fixtures. The SubTests type annotation is particularly good for clarity.

Also applies to: 25-27, 41-43, 57-59, 77-77, 90-92

tests/unit/authentication/test_noop_with_token.py (1)

10-10: LGTM! Async function return types added.

The return type annotations are consistent and correct for async test functions.

Also applies to: 34-34, 59-59, 88-88

tests/unit/authentication/test_k8s.py (1)

7-7: LGTM! Comprehensive type annotations added.

The remaining changes properly add type annotations throughout the test module. The # type: ignore comment on line 234 is appropriate since it's intentionally testing error handling with None.

Also applies to: 31-38, 42-42, 55-60, 87-87, 94-94, 127-127, 159-159, 199-199, 213-213, 234-234, 252-252, 264-264

tests/unit/authorization/test_resolvers.py (1)

8-8: Excellent type annotations throughout the file.

All fixtures and test methods now have complete and accurate type hints. The use of dict[str, Any] for JWT claims, proper return types for fixtures (JwtRoleRule, JwtRolesResolver, list[AccessRule]), and -> None for test methods aligns perfectly with the coding guidelines.

Also applies to: 37-38, 47-49, 54-54, 72-72, 82-83, 89-91, 102-104, 116-116, 130-130, 143-145, 152-152, 165-167, 173-175, 181-183, 194-194, 206-206, 218-218, 240-240, 262-264, 283-283, 288-288, 295-295, 310-310, 320-320, 330-330, 337-339, 344-346, 354-356

tests/unit/app/test_database.py (1)

5-5: Well-structured type annotations with proper use of MockType.

All fixtures, test methods, and helper functions now have complete type hints. The use of MockType for pytest-mock objects, Generator for fixtures, and PostgreSQLDatabaseConfiguration for typed parameters demonstrates good adherence to the typing guidelines.

Also applies to: 9-9, 18-18, 35-35, 51-51, 60-60, 72-72, 84-84, 95-95, 107-109, 121-121, 132-132, 141-141, 157-160, 179-182, 203-206, 224-227, 236-239, 262-265, 274-279, 287-290, 321-325

tests/unit/authentication/test_jwk_token.py (2)

306-310: Use fully-qualified dict type hints.

The parameter token_payload: dict[str, Any] is already correct, but token_header: dict[str, Any] should match for consistency (already correct in the code, but good practice to verify all parameters match this pattern).


7-8: Good type annotations for most of the file.

The majority of the type hints added are correct and follow the coding guidelines well, including proper use of Generator, MockerFixture, list[dict[str, Any]], and return type annotations. Just a few parameter types need correction as noted in the other comments.

Also applies to: 24-24, 30-30, 40-40, 51-51, 57-57, 74-74, 81-83, 121-123, 129-129, 140-140, 152-152, 164-164, 175-175, 184-184, 193-197, 220-224, 251-255, 321-325, 341-345, 356-360, 395-397, 409-413, 426-426, 432-432, 438-438, 444-444, 450-450, 456-456, 462-468, 493-498, 523-525, 530-534, 551-555

@tisnik tisnik merged commit 74a4f00 into lightspeed-core:main Nov 4, 2025
20 of 22 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