-
Notifications
You must be signed in to change notification settings - Fork 60
LCORE-740: type hints for rest of unit tests #755
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LCORE-740: type hints for rest of unit tests #755
Conversation
WalkthroughThis PR systematically adds explicit type annotations throughout the test suite, introducing return type hints (primarily Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this 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
📒 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.pytests/unit/test_configuration_unknown_fields.pytests/unit/utils/test_llama_stack_version.pytests/unit/utils/test_transcripts.pytests/unit/authentication/test_noop.pytests/unit/authentication/test_k8s.pytests/unit/app/test_database.pytests/unit/authentication/test_noop_with_token.pytests/unit/app/test_routers.pytests/unit/authorization/test_resolvers.pytests/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.pytests/unit/test_configuration_unknown_fields.pytests/unit/utils/test_llama_stack_version.pytests/unit/utils/test_transcripts.pytests/unit/authentication/test_noop.pytests/unit/authentication/test_k8s.pytests/unit/app/test_database.pytests/unit/authentication/test_noop_with_token.pytests/unit/app/test_routers.pytests/unit/authorization/test_resolvers.pytests/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.pytests/unit/test_configuration_unknown_fields.pytests/unit/utils/test_llama_stack_version.pytests/unit/utils/test_transcripts.pytests/unit/authentication/test_noop.pytests/unit/authentication/test_k8s.pytests/unit/app/test_database.pytests/unit/authentication/test_noop_with_token.pytests/unit/app/test_routers.pytests/unit/authorization/test_resolvers.pytests/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.pytests/unit/authentication/test_noop_with_token.pytests/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
-> Nonereturn 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
Attachmentimport 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
-> Nonereturn 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_routerparameters 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
SubTeststype 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: ignorecomment on line 234 is appropriate since it's intentionally testing error handling withNone.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-> Nonefor 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
MockTypefor pytest-mock objects,Generatorfor fixtures, andPostgreSQLDatabaseConfigurationfor 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, buttoken_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
Description
LCORE-740: type hints for rest of unit tests
Type of change
Related Tickets & Documents
Summary by CodeRabbit