Skip to content

Conversation

@radofuchs
Copy link
Contributor

@radofuchs radofuchs commented Oct 21, 2025

Description

add integration tests for info 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-712
  • Closes #LCORE-712

Checklist before requesting a review

  • I have performed a self-review of my code.
  • PR has passed all pre-merge test jobs.
  • If it is a core feature, I have added thorough tests.

Testing

  • Please provide detailed steps to perform tests related to this code change.
  • How were the fix/results from this change verified? Please provide relevant screenshots or results.

Summary by CodeRabbit

  • Tests
    • Added integration test fixtures to reset configuration and provide a fresh in-memory database engine and session per test.
    • Added integration tests for the /info endpoint covering normal responses, configuration-driven values, and handling of external client connection errors.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 21, 2025

Walkthrough

Adds 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

Cohort / File(s) Summary
Test infrastructure
tests/integration/conftest.py
Adds pytest fixtures: autouse reset_configuration_state to reset configuration before each test; test_config to load real configuration; test_db_engine to create/manage an in-memory SQLite engine and lifecycle; test_db_session to provide a bound Session and ensure teardown.
Endpoint tests package
tests/integration/endpoints/__init__.py
Adds package initializer with a module docstring for integration endpoint tests.
Info endpoint integration tests
tests/integration/endpoints/test_info_integration.py
Adds tests for /info: fixtures to mock AsyncLlamaStackClientHolder (returning a version or raising APIConnectionError), real FastAPI Request, and NoopAuthDependency; tests success response fields, configuration-driven name, and error handling (HTTP 500 with detail).

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • tisnik

Poem

🐰 I hopped in to set fixtures warm and neat,
In-memory gardens where test databases meet,
I mocked a wise llama with a version to show,
Caught errors and sunsets in a tidy test flow,
Hooray — integration seeds ready to grow! 🌱

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 "add integration tests for info endpoint" accurately describes the primary deliverable of the changeset. The title directly corresponds to the main objective stated in the PR description and the test files added (test_info_integration.py with test cases for the /info endpoint). While the PR also includes supporting infrastructure in conftest.py with reusable test fixtures, this represents foundational setup rather than the primary feature being delivered. The title is concise, clear, and specific enough that a teammate scanning the repository history would immediately understand that this PR adds integration tests for the info endpoint.
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

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3e072ff and 4198dcb.

📒 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)
✅ Files skipped from review due to trivial changes (1)
  • tests/integration/endpoints/init.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/integration/endpoints/test_info_integration.py
  • tests/integration/conftest.py
⏰ 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)

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

  1. Missing type annotations for the parameter and return type.
  2. 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 real NoopAuthDependency, 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_AUTH constant 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

📥 Commits

Reviewing files that changed from the base of the PR and between a761489 and 04b17d8.

📒 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__.py
  • tests/integration/endpoints/test_info_integration.py
  • tests/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__.py
  • tests/integration/endpoints/test_info_integration.py
  • tests/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__.py
  • tests/integration/endpoints/test_info_integration.py
  • tests/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__.py files.

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.

@radofuchs radofuchs requested a review from tisnik October 21, 2025 11:58
Copy link
Contributor

@tisnik tisnik left a 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
Copy link
Contributor

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

@radofuchs radofuchs force-pushed the LCORE_712_info_endpoint_ITs branch from 3e072ff to 4198dcb Compare October 21, 2025 12:32
Copy link
Contributor

@tisnik tisnik left a comment

Choose a reason for hiding this comment

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

Nice one, TY

@tisnik tisnik merged commit f4f6684 into lightspeed-core:main Oct 23, 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.

2 participants