-
Notifications
You must be signed in to change notification settings - Fork 52
LCORE-712: add integration tests for info endpoint #703
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-712: add integration tests for info endpoint #703
Conversation
WalkthroughAdds integration test infrastructure and endpoint tests: new pytest fixtures to reset configuration and provide an in-memory SQLite engine/session, plus integration tests for the /info endpoint covering success, configuration-driven response, and Llama Stack connection error handling. Changes
Sequence Diagram(s)sequenceDiagram
participant Test as Integration Test
participant Handler as /info Handler
participant Config as Configuration
participant Llama as LlamaStackClient (mock)
Note over Test,Config: Setup fixtures
Test->>Config: load configuration
Test->>Llama: configure mock (version or raise error)
Note over Test,Handler: Request flow
Test->>Handler: call /info (Request + Auth)
Handler->>Config: read service name & version
Handler->>Llama: inspect.version (async)
alt Llama returns version
Llama-->>Handler: version "0.2.22"
Handler-->>Test: 200 { name, service_version, llama_stack_version }
else Llama raises connection error
Llama-->>Handler: APIConnectionError
Handler-->>Test: 500 { detail: { response, cause } }
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (3)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (2)
⏰ 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)
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: 0
🧹 Nitpick comments (8)
tests/integration/endpoints/test_info_integration.py (4)
15-31: Consider adding return type annotation.The fixture is missing a return type annotation. While pytest fixtures often omit these, adding them improves code clarity and enables better IDE support.
Apply this diff to add the type annotation:
@pytest.fixture(name="mock_llama_stack_client") -def mock_llama_stack_client_fixture(): +def mock_llama_stack_client_fixture() -> AsyncMock: """Mock only the external Llama Stack client.
34-43: Consider adding return type annotation.The fixture is missing a return type annotation.
Apply this diff to add the type annotation:
@pytest.fixture(name="test_request") -def test_request_fixture(): +def test_request_fixture() -> Request: """Create a test FastAPI Request object with proper scope."""
46-54: Consider adding type annotations and verify auth approach.Two observations:
- Missing type annotations for the parameter and return type.
- The coding guidelines recommend using
MOCK_AUTH = ("mock_user_id", "mock_username", False, "mock_token")for tests. However, since this is an integration test explicitly testing the realNoopAuthDependency, the current approach may be intentional.As per coding guidelines
Apply this diff to add type annotations:
+from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from authentication.noop import AuthTuple + @pytest.fixture(name="test_auth") -async def test_auth_fixture(test_request): +async def test_auth_fixture(test_request: Request) -> AuthTuple: """Create authentication using real noop auth module.If not testing the authentication integration specifically, consider using the
MOCK_AUTHconstant instead:+MOCK_AUTH = ("mock_user_id", "mock_username", False, "mock_token") + @pytest.fixture(name="test_auth") -async def test_auth_fixture(test_request): +def test_auth_fixture() -> tuple[str, str, bool, str]: """Create authentication using real noop auth module. This uses the actual NoopAuthDependency instead of mocking, making this a true integration test. """ - noop_auth = NoopAuthDependency() - return await noop_auth(test_request) + return MOCK_AUTH
57-87: LGTM! Consider adding type annotations.The test thoroughly validates the integration between the endpoint handler, configuration system, and external client. The test logic is sound and well-documented.
Optionally add type annotations to test parameters for better IDE support:
@pytest.mark.asyncio async def test_info_endpoint_returns_service_information( - test_config, mock_llama_stack_client, test_request, test_auth + test_config, + mock_llama_stack_client: AsyncMock, + test_request: Request, + test_auth: tuple[str, str, bool, str], ):tests/integration/conftest.py (4)
13-24: Consider adding return type annotation.The autouse fixture properly ensures test independence by resetting the configuration singleton. The protected member access is appropriately handled with pylint disable.
Apply this diff to add the type annotation:
+from collections.abc import Generator + @pytest.fixture(autouse=True) -def reset_configuration_state(): +def reset_configuration_state() -> Generator[None, None, None]: """Reset configuration state before each integration test.
27-43: Consider adding return type annotation.The fixture properly loads real configuration for integration tests with good path validation.
Apply this diff to add the type annotation:
+from collections.abc import Generator +from configuration import Configuration + @pytest.fixture(name="test_config", scope="function") -def test_config_fixture(): +def test_config_fixture() -> Generator[Configuration, None, None]: """Load real configuration for integration tests.
46-67: Consider adding return type annotation.The fixture properly sets up an in-memory database with appropriate cleanup. The multi-threaded access configuration and metadata management are correct.
Apply this diff to add the type annotation:
+from collections.abc import Generator +from sqlalchemy import Engine + @pytest.fixture(name="test_db_engine", scope="function") -def test_db_engine_fixture(): +def test_db_engine_fixture() -> Generator[Engine, None, None]: """Create an in-memory SQLite database engine for testing.
70-81: Consider adding type annotations.The fixture properly creates a database session with correct configuration and cleanup.
Apply this diff to add type annotations:
+from collections.abc import Generator +from sqlalchemy import Engine +from sqlalchemy.orm import Session + @pytest.fixture(name="test_db_session", scope="function") -def test_db_session_fixture(test_db_engine): +def test_db_session_fixture(test_db_engine: Engine) -> Generator[Session, None, None]: """Create a database session for testing.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
tests/integration/conftest.py(1 hunks)tests/integration/endpoints/__init__.py(1 hunks)tests/integration/endpoints/test_info_integration.py(1 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
**/*.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/integration/endpoints/__init__.pytests/integration/endpoints/test_info_integration.pytests/integration/conftest.py
**/__init__.py
📄 CodeRabbit inference engine (CLAUDE.md)
Package init.py files contain brief package descriptions
Files:
tests/integration/endpoints/__init__.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/integration/endpoints/__init__.pytests/integration/endpoints/test_info_integration.pytests/integration/conftest.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/integration/endpoints/__init__.pytests/integration/endpoints/test_info_integration.pytests/integration/conftest.py
tests/**/conftest.py
📄 CodeRabbit inference engine (CLAUDE.md)
Use conftest.py for shared pytest fixtures
Files:
tests/integration/conftest.py
🧬 Code graph analysis (2)
tests/integration/endpoints/test_info_integration.py (4)
src/app/endpoints/info.py (1)
info_endpoint_handler(39-83)src/authentication/noop.py (1)
NoopAuthDependency(17-42)src/client.py (1)
get_client(49-55)src/configuration.py (1)
configuration(65-69)
tests/integration/conftest.py (2)
src/configuration.py (2)
configuration(65-69)load_configuration(52-58)src/models/database/base.py (1)
Base(6-7)
⏰ 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: ruff
- GitHub Check: e2e_tests (ci)
- GitHub Check: e2e_tests (azure)
🔇 Additional comments (5)
tests/integration/endpoints/__init__.py (1)
1-1: LGTM!The package initializer follows the coding guideline for brief package descriptions in
__init__.pyfiles.tests/integration/endpoints/test_info_integration.py (3)
1-12: LGTM!Module docstring and imports are well-organized and appropriate for integration tests.
90-122: LGTM!The test properly validates error handling when the external Llama Stack service is unavailable. The assertions verify both the HTTP status code and error detail structure.
125-149: LGTM!The test validates that the endpoint correctly reads and uses configuration values. The dual assertion (checking both the config value and the expected literal) provides good validation.
tests/integration/conftest.py (1)
1-10: LGTM!Module docstring and imports are well-organized and appropriate for integration test fixtures.
tisnik
left a 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.
LGTM in overall, just please use mocker from pytest-mock package.
| @@ -0,0 +1,149 @@ | |||
| """Integration tests for the /info endpoint.""" | |||
|
|
|||
| from unittest.mock import AsyncMock, Mock, patch | |||
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.
pls. use mocker object from pytest-mock package instead of unittest.mock
3e072ff to
4198dcb
Compare
tisnik
left a 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.
Nice one, TY
Description
add integration tests for info endpoint
Type of change
Related Tickets & Documents
Checklist before requesting a review
Testing
Summary by CodeRabbit