Skip to content

Conversation

@tisnik
Copy link
Contributor

@tisnik tisnik commented Oct 29, 2025

Description

LCORE-740: Added type hints into unit tests for checking endpoint handlers:

  • Added type hints into unit tests for checking /config endpoint
  • Added type hints into unit tests for checking /feedback endpoint
  • Added type hints into unit tests for checking /health endpoint

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
    • Added explicit return types and consistent parameter typing across many tests.
    • Replaced ad-hoc auth tuples with a typed auth variable and standardized auth usage.
    • Introduced richer typing for request payloads, configuration fixtures, and helpers.
    • Updated assertions and minor formatting to align with stricter typing and improve clarity.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 29, 2025

Walkthrough

Added explicit type annotations (parameter and return types), introduced AuthTuple and Any imports, and applied local variable typing across multiple unit tests under tests/unit/app/endpoints/*; no production logic or control-flow changes.

Changes

Cohort / File(s) Summary
Config tests typing
tests/unit/app/endpoints/test_config.py
Added Any and AuthTuple imports; annotated mocker: MockerFixture params and -> None return types on async tests; typed config_dict and auth variables; updated assertions to check HTTPException detail as a dict.
Feedback tests typing
tests/unit/app/endpoints/test_feedback.py
Widespread addition of parameter and return type annotations (e.g., mocker: MockerFixture, dict[str, Any], -> None); imported AuthTuple and replaced ad-hoc auth tuples with auth: AuthTuple; adjusted calls to handlers to pass typed auth.
Health tests typing
tests/unit/app/endpoints/test_health.py
Added AuthTuple import; annotated mocker: MockerFixture params and -> None returns; replaced inline tuple auth with AuthTuple variables; minor formatting/comments updated.
Info tests typing
tests/unit/app/endpoints/test_info.py
Annotated mocker: MockerFixture and -> None returns; added Any, MockerFixture, and AuthTuple imports; typed config_dict and auth locals; minor comment and ignore adjustments.
Query tests typing
tests/unit/app/endpoints/test_query.py
Extensive typing: annotated many helper functions and tests (e.g., MockerFixture, Request, AppConfig, AgentFixtures), added Any imports, changed several helpers to return typed AppConfig, and adjusted assertions to treat HTTPException detail as dicts; numerous function signature updates across the file.

Sequence Diagram(s)

(No sequence diagram — changes are typing-only and do not alter runtime control flow.)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Rationale: Many files changed with repeated, low-risk typing edits but across a broad surface (multiple endpoint test modules) requiring spot-checking for consistency.
  • Spot-check areas:
    • tests/unit/app/endpoints/test_feedback.py — ensure AuthTuple usage matches authentication.interface and handler callsites.
    • tests/unit/app/endpoints/test_query.py — verify typed fixtures (AgentFixtures, AppConfig) align with conftest and helper return types.
    • tests/unit/app/endpoints/test_config.py — confirm HTTPException detail assertions and any # type: ignore usages are necessary.

Possibly related PRs

Suggested reviewers

  • umago
  • manstis

Poem

🐰 I hopped through tests with a careful nibble,

Gave mocks and auth a tidy little scribble,
Async lines now polite and thin,
Types tucked in, all neat and grin,
A carrot cheer for tests that win. 🥕

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "LCORE-740: Added type hints into unit tests for checking endpoint handlers" accurately and directly describes the primary change across all modified files. The changeset consistently adds explicit type hints to unit test functions, including return type annotations (-> None), parameter type hints (MockerFixture, Request, AuthTuple, etc.), and typed local variables (dict[Any, Any], etc.) across multiple endpoint test files. The title is specific, clear, and communicates the main objective without vague language or unnecessary details.
Docstring Coverage ✅ Passed Docstring coverage is 89.29% 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 (5)
tests/unit/app/endpoints/test_config.py (5)

18-18: Make the docstring more descriptive.

The docstring should describe the specific test scenario being validated. Consider: "Test the config endpoint handler when configuration is not loaded."

As per coding guidelines.

Apply this diff:

-    """Test the config endpoint handler."""
+    """Test the config endpoint handler when configuration is not loaded."""

35-35: Use the shared MOCK_AUTH constant instead of creating a custom auth tuple.

The coding guidelines specify using the shared auth mock constant: MOCK_AUTH = ("mock_user_id", "mock_username", False, "mock_token") in tests.

As per coding guidelines.

Apply this diff to import and use the constant:

+from tests.unit.utils.auth_helpers import MOCK_AUTH

Then update the auth assignment:

-    # authorization tuple required by URL endpoint handler
-    auth: AuthTuple = ("test_user_id", "test_user", True, "test_token")
+    # authorization tuple required by URL endpoint handler
+    auth: AuthTuple = MOCK_AUTH

49-49: Make the docstring more descriptive and unique.

The docstring is identical to the first test but should describe the specific test scenario. Consider: "Test the config endpoint handler when configuration is loaded."

As per coding guidelines.

Apply this diff:

-    """Test the config endpoint handler."""
+    """Test the config endpoint handler when configuration is loaded."""

52-52: Consider using more precise type hints for the config dictionary.

The dict[Any, Any] type annotation is imprecise. Consider using a TypedDict or more specific types for the configuration structure.

Based on learnings.

For example:

config_dict: dict[str, Any] = {
    # ... configuration keys are strings
}

90-90: Use the shared MOCK_AUTH constant instead of creating a custom auth tuple.

The coding guidelines specify using the shared auth mock constant: MOCK_AUTH = ("mock_user_id", "mock_username", False, "mock_token") in tests.

As per coding guidelines.

Apply this diff to import and use the constant:

+from tests.unit.utils.auth_helpers import MOCK_AUTH

Then update the auth assignment:

-    # authorization tuple required by URL endpoint handler
-    auth: AuthTuple = ("test_user_id", "test_user", True, "test_token")
+    # authorization tuple required by URL endpoint handler
+    auth: AuthTuple = MOCK_AUTH
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 037c3dd and 6d05d3a.

📒 Files selected for processing (1)
  • tests/unit/app/endpoints/test_config.py (3 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/app/endpoints/test_config.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/app/endpoints/test_config.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/app/endpoints/test_config.py
🧠 Learnings (1)
📓 Common learnings
Learnt from: CR
PR: lightspeed-core/lightspeed-stack#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)
🧬 Code graph analysis (1)
tests/unit/app/endpoints/test_config.py (3)
src/app/endpoints/config.py (1)
  • config_endpoint_handler (63-85)
src/configuration.py (2)
  • configuration (73-77)
  • AppConfig (39-181)
tests/unit/utils/auth_helpers.py (1)
  • mock_authorization_resolvers (8-26)
⏰ 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 (2)
tests/unit/app/endpoints/test_config.py (2)

3-3: LGTM! Import additions support the type annotations.

The new imports are necessary and appropriate for the type hints added to the test functions.

Also applies to: 8-8


42-42: The review comment is incorrect; no legitimate type issue exists.

The # type: ignore suppression is not masking a bug. The code intentionally passes detail as a dictionary in src/utils/endpoints.py:120-122:

raise HTTPException(
    status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
    detail={"response": "Configuration is not loaded"},
)

The test correctly accesses detail["response"]. This pattern appears throughout the test suite (test_models.py, test_shields.py, test_query.py, test_conversations.py, test_streaming_query.py) and many of these identical accesses work without the # type: ignore comment. The suppression addresses a known Starlette type annotation limitation where detail is typed as str but accepts any JSON-serializable value—not a code correctness issue.

Likely an incorrect or invalid review comment.

@tisnik tisnik force-pushed the lcore-727-type-info-for-endpoint-unit-tests branch from 6d05d3a to a392d03 Compare October 29, 2025 07:54
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/app/endpoints/test_feedback.py (2)

79-81: Type annotations correctly applied to parametrized tests.

The parameter and return type annotations are properly added. The use of dict[Any, Any] for feedback payload parameters is safe and flexible.

Consider using dict[str, Any] instead of dict[Any, Any] for slightly more precise typing, since feedback payloads typically have string keys:

-    mocker: MockerFixture, feedback_request_data: dict[Any, Any]
+    mocker: MockerFixture, feedback_request_data: dict[str, Any]

This would apply to the parameters in lines 80, 159, 207, and 274.

Also applies to: 158-160, 206-208, 273-275


94-96: LGTM! Auth tuple type annotations correctly applied.

The local auth: AuthTuple variables are properly typed and intentionally use "test_user_id" to match the assertions in the respective tests (e.g., lines 238, 258). This differs appropriately from the MOCK_AUTH constant used in other tests.

The comments "Authorization tuple required by URL endpoint handler" are somewhat redundant given the explicit auth: AuthTuple type annotation. Consider removing them for brevity:

-    # Authorization tuple required by URL endpoint handler
     auth: AuthTuple = ("test_user_id", "test_user", True, "test_token")
-

Also applies to: 123-125, 227-229, 247-249

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a392d03 and f87fb34.

📒 Files selected for processing (1)
  • tests/unit/app/endpoints/test_feedback.py (12 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/app/endpoints/test_feedback.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/app/endpoints/test_feedback.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/app/endpoints/test_feedback.py
🧬 Code graph analysis (1)
tests/unit/app/endpoints/test_feedback.py (3)
src/configuration.py (2)
  • configuration (73-77)
  • user_data_collection_configuration (94-98)
src/app/endpoints/feedback.py (4)
  • is_feedback_enabled (79-89)
  • feedback_endpoint_handler (114-152)
  • assert_feedback_enabled (92-109)
  • update_feedback_status (210-246)
src/models/requests.py (1)
  • FeedbackStatusUpdateRequest (390-415)
⏰ 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 (azure)
  • GitHub Check: e2e_tests (ci)
🔇 Additional comments (4)
tests/unit/app/endpoints/test_feedback.py (4)

3-3: LGTM! Necessary imports for type hints.

The additions of Any and AuthTuple imports appropriately support the type annotations introduced throughout the test file.

Also applies to: 16-16


29-29: LGTM! Return type annotations correctly applied.

The -> None return type annotations and MockerFixture parameter types are correctly applied and follow the coding guidelines for complete type annotations.

Also applies to: 35-35, 41-41, 54-54, 109-109


135-135: LGTM! Appropriate use of type: ignore.

The # type: ignore comment is correctly applied here. The endpoint handler raises HTTPException with a dictionary detail (as seen in the handler implementation), but the type checker may expect detail to be a string. This is a legitimate suppression of a false positive.


223-223: LGTM! Type annotations properly added to feedback status update tests.

The addition of mocker: MockerFixture parameter typing and -> None return annotations completes the type hint coverage for these test functions. The mocker parameter is appropriately used with mocker.ANY in the test assertions.

Also applies to: 243-243

@tisnik tisnik force-pushed the lcore-727-type-info-for-endpoint-unit-tests branch from f87fb34 to fcb8b0f Compare October 29, 2025 08:14
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 (4)
tests/unit/app/endpoints/test_feedback.py (4)

79-81: Good type annotations, but consider using the existing MOCK_AUTH constant.

The type annotations are correct and improve type safety. However, this test creates a custom auth tuple instead of using the MOCK_AUTH constant defined at line 21. For consistency and maintainability, consider reusing the shared constant. As per coding guidelines, using the shared auth mock constant is recommended.

Apply this diff to use the shared constant:

-    # Authorization tuple required by URL endpoint handler
-    auth: AuthTuple = ("test_user_id", "test_user", True, "test_token")
-
     # Call the endpoint handler
     result = await feedback_endpoint_handler(
         feedback_request=feedback_request,
         _ensure_feedback_enabled=assert_feedback_enabled,
-        auth=auth,
+        auth=MOCK_AUTH,
     )

Based on coding guidelines.

Also applies to: 94-96, 101-101


109-109: Type annotations look good, consider MOCK_AUTH for consistency.

Similar to the previous test, the type annotations are correct but creating a custom auth tuple instead of using MOCK_AUTH reduces consistency across the test suite.

Consider using the shared MOCK_AUTH constant for consistency:

-    # Authorization tuple required by URL endpoint handler
-    auth: AuthTuple = ("test_user_id", "test_user", True, "test_token")
-
     # Call the endpoint handler and assert it raises an exception
     with pytest.raises(HTTPException) as exc_info:
         await feedback_endpoint_handler(
             feedback_request=feedback_request,
             _ensure_feedback_enabled=assert_feedback_enabled,
-            auth=auth,
+            auth=MOCK_AUTH,
         )

Based on coding guidelines.

Also applies to: 123-125, 131-131


223-229: Type annotations are correct, but auth tuple usage is inconsistent.

The type annotations properly document the function signatures. However, these tests create custom auth tuples while test_feedback_endpoint_valid_requests (line 282) uses the shared MOCK_AUTH constant. For consistency and maintainability, consider using MOCK_AUTH throughout the file.

Consider standardizing on MOCK_AUTH:

-    # Authorization tuple required by URL endpoint handler
-    auth: AuthTuple = ("test_user_id", "test_user", True, "test_token")
-
     req = FeedbackStatusUpdateRequest(status=False)
     resp = await update_feedback_status(
         req,
-        auth=auth,
+        auth=MOCK_AUTH,
     )

And similarly for test_update_feedback_status_no_change. Based on coding guidelines.

Also applies to: 233-233, 243-249, 253-253


135-135: Consider a more specific type: ignore comment.

The broad # type: ignore comment suppresses all type checking for this line. Consider using a more specific suppression like # type: ignore[index] or restructuring to make the type explicit.

For example:

-    assert exc_info.value.detail["response"] == "Error storing user feedback"  # type: ignore
+    detail = exc_info.value.detail
+    assert isinstance(detail, dict)
+    assert detail["response"] == "Error storing user feedback"

Or use a more specific ignore:

-    assert exc_info.value.detail["response"] == "Error storing user feedback"  # type: ignore
+    assert exc_info.value.detail["response"] == "Error storing user feedback"  # type: ignore[index]
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f87fb34 and 5539cb6.

📒 Files selected for processing (2)
  • tests/unit/app/endpoints/test_feedback.py (12 hunks)
  • tests/unit/app/endpoints/test_health.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/app/endpoints/test_health.py
  • tests/unit/app/endpoints/test_feedback.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/app/endpoints/test_health.py
  • tests/unit/app/endpoints/test_feedback.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/app/endpoints/test_health.py
  • tests/unit/app/endpoints/test_feedback.py
🧬 Code graph analysis (2)
tests/unit/app/endpoints/test_health.py (1)
tests/unit/utils/auth_helpers.py (1)
  • mock_authorization_resolvers (8-26)
tests/unit/app/endpoints/test_feedback.py (1)
src/app/endpoints/feedback.py (4)
  • is_feedback_enabled (79-89)
  • feedback_endpoint_handler (114-152)
  • assert_feedback_enabled (92-109)
  • update_feedback_status (210-246)
⏰ 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 (5)
tests/unit/app/endpoints/test_health.py (3)

7-7: LGTM! Excellent type annotation work.

The import of AuthTuple and its usage with explicit type annotations improves type safety and code clarity. The inline comment explaining the auth tuple is helpful.

Also applies to: 18-20, 38-40


53-53: LGTM! Consistent typing pattern.

The return type annotations and AuthTuple usage maintain consistency across all test functions. The pattern is clean and well-documented.

Also applies to: 76-78, 90-96


105-105: LGTM! Complete type coverage.

All test methods now have proper return type annotations, completing the type coverage for this test module.

Also applies to: 114-114, 125-125, 176-178

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

3-3: LGTM! Good foundation with type imports.

The addition of Any and AuthTuple imports along with return type annotations establishes proper type coverage for the test module.

Also applies to: 16-16, 29-29, 35-35, 41-41, 54-54


158-160: LGTM! Clean parameter type annotations.

The use of dict[str, Any] for the feedback request data parameter is correct and follows modern Python typing conventions.

Also applies to: 206-208

@tisnik
Copy link
Contributor Author

tisnik commented Oct 29, 2025

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 29, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@tisnik tisnik force-pushed the lcore-727-type-info-for-endpoint-unit-tests branch from f2aa278 to a9297d7 Compare October 29, 2025 08:52
@tisnik tisnik force-pushed the lcore-727-type-info-for-endpoint-unit-tests branch from a9297d7 to 27f3f92 Compare October 29, 2025 08:56
@tisnik
Copy link
Contributor Author

tisnik commented Oct 29, 2025

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 29, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@tisnik
Copy link
Contributor Author

tisnik commented Oct 29, 2025

@coderabbitai fullreview

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 29, 2025

@tisnik: I'll perform a full review of all the changes in this PR.

✅ Actions performed

Full review triggered.

@tisnik
Copy link
Contributor Author

tisnik commented Oct 29, 2025

@coderabbitai fullreview

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 29, 2025

@tisnik: I'll perform a full review of all the changes in this PR.

✅ Actions performed

Full review triggered.

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: 1

🧹 Nitpick comments (4)
tests/unit/app/endpoints/test_info.py (1)

69-69: Consider using the shared MOCK_AUTH constant.

Both test functions construct identical auth tuples inline. As per coding guidelines, tests should use the shared auth mock constant. Consider defining a module-level constant or using a shared constant from a test utilities module to reduce duplication and improve maintainability.

Based on coding guidelines.

Apply this diff to use a shared constant:

+# Shared auth constant for tests
+MOCK_AUTH: AuthTuple = ("test_user_id", "test_user", True, "test_token")
+
 @pytest.mark.asyncio
 async def test_info_endpoint(mocker: MockerFixture) -> None:
     """Test the info endpoint handler."""
     ...
-    # Authorization tuple required by URL endpoint handler
-    auth: AuthTuple = ("test_user_id", "test_user", True, "test_token")
+    # Authorization tuple required by URL endpoint handler
+    auth: AuthTuple = MOCK_AUTH

Then apply the same pattern to line 130.

Also applies to: 130-130

tests/unit/app/endpoints/test_config.py (1)

36-36: Consider using the shared MOCK_AUTH constant.

Both test functions construct identical auth tuples inline. As per coding guidelines, tests should use a shared auth mock constant to reduce duplication.

Based on coding guidelines.

Consider defining a module-level constant:

+# Shared auth constant for tests
+MOCK_AUTH: AuthTuple = ("test_user_id", "test_user", True, "test_token")
+
 @pytest.mark.asyncio
 async def test_config_endpoint_handler_configuration_not_loaded(
     mocker: MockerFixture,
 ) -> None:
     ...
-    # authorization tuple required by URL endpoint handler
-    auth: AuthTuple = ("test_user_id", "test_user", True, "test_token")
+    # authorization tuple required by URL endpoint handler
+    auth: AuthTuple = MOCK_AUTH

Also applies to: 97-97

tests/unit/app/endpoints/test_health.py (1)

40-40: Consider using the shared MOCK_AUTH constant.

Multiple test functions construct identical auth tuples inline. As per coding guidelines, tests should use a shared auth mock constant to reduce duplication and improve consistency.

Based on coding guidelines.

Consider defining a module-level constant:

+# Shared auth constant for tests
+MOCK_AUTH: AuthTuple = ("test_user_id", "test_user", True, "test_token")

Then replace the inline constructions with references to this constant.

Also applies to: 78-78, 95-95

tests/unit/app/endpoints/test_feedback.py (1)

95-95: Inconsistent auth tuple usage.

This file defines a module-level MOCK_AUTH constant at line 21, and one test (test_feedback_endpoint_valid_requests at line 285) correctly uses it. However, several other tests construct inline auth tuples with different values ("test_user_id" vs "mock_user_id").

For consistency and maintainability, consider using the module-level MOCK_AUTH constant across all tests unless there's a specific requirement for different auth values.

Based on coding guidelines.

-    # Authorization tuple required by URL endpoint handler
-    auth: AuthTuple = ("test_user_id", "test_user", True, "test_token")
+    # Authorization tuple required by URL endpoint handler
+    auth: AuthTuple = MOCK_AUTH

Also applies to: 124-124, 231-231, 251-251

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 037c3dd and 27f3f92.

📒 Files selected for processing (5)
  • tests/unit/app/endpoints/test_config.py (2 hunks)
  • tests/unit/app/endpoints/test_feedback.py (12 hunks)
  • tests/unit/app/endpoints/test_health.py (10 hunks)
  • tests/unit/app/endpoints/test_info.py (5 hunks)
  • tests/unit/app/endpoints/test_query.py (50 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/app/endpoints/test_health.py
  • tests/unit/app/endpoints/test_feedback.py
  • tests/unit/app/endpoints/test_info.py
  • tests/unit/app/endpoints/test_config.py
  • tests/unit/app/endpoints/test_query.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/app/endpoints/test_health.py
  • tests/unit/app/endpoints/test_feedback.py
  • tests/unit/app/endpoints/test_info.py
  • tests/unit/app/endpoints/test_config.py
  • tests/unit/app/endpoints/test_query.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/app/endpoints/test_health.py
  • tests/unit/app/endpoints/test_feedback.py
  • tests/unit/app/endpoints/test_info.py
  • tests/unit/app/endpoints/test_config.py
  • tests/unit/app/endpoints/test_query.py
🧠 Learnings (1)
📚 Learning: 2025-09-18T16:46:33.353Z
Learnt from: CR
PR: lightspeed-core/lightspeed-stack#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-18T16:46:33.353Z
Learning: Applies to src/client.py : Use Llama Stack client import: from llama_stack_client import AsyncLlamaStackClient

Applied to files:

  • tests/unit/app/endpoints/test_info.py

Comment on lines +758 to 759
def __init__(self, identifier: str):
self.identifier = identifier
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

Add missing return type annotation.

The __init__ method in the MockShield class at line 758 is missing a return type annotation. Other similar MockShield classes in this file (lines 702 and 817) correctly include -> None on their __init__ methods.

Based on coding guidelines.

Apply this diff:

-        def __init__(self, identifier: str):
+        def __init__(self, identifier: str) -> None:
             self.identifier = identifier
🤖 Prompt for AI Agents
In tests/unit/app/endpoints/test_query.py around lines 758-759, the
MockShield.__init__ method is missing a return type annotation; update its
signature to include "-> None" (making it def __init__(self, identifier: str) ->
None:) to match the other MockShield classes in the file and adhere to the
project's typing guidelines.

@tisnik tisnik merged commit 8aca35f into lightspeed-core:main Oct 29, 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