Skip to content

Conversation

@tisnik
Copy link
Contributor

@tisnik tisnik commented Aug 4, 2025

Description

LCORE-381: added missing 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-381

Summary by CodeRabbit

  • Tests
    • Added new unit tests to ensure proper validation and error handling for JWK token authentication configuration.
    • Enhanced client lifecycle tests to verify closed state before and after closing, including updates for both synchronous and asynchronous clients.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 4, 2025

Walkthrough

This update introduces new unit tests for the AuthenticationConfiguration model, focusing on validation and error handling for JWK token authentication configuration. Additionally, it enhances existing client tests by verifying the closed state of both synchronous and asynchronous Llama Stack clients before and after closure, including proper use of async context management.

Changes

Cohort / File(s) Change Summary
AuthenticationConfiguration JWK Token Tests
tests/unit/models/test_config.py
Added three unit tests for AuthenticationConfiguration covering: valid JWK config, missing fields, and missing config, ensuring correct validation and error handling for JWK token authentication.
Llama Stack Client Closed State Tests
tests/unit/test_client.py
Enhanced tests to assert client closed state before/after close() for sync clients; refactored async client test to use async with and added closed state assertions, marking it with @pytest.mark.asyncio.

Sequence Diagram(s)

sequenceDiagram
    participant Test as Unit Test
    participant AuthConfig as AuthenticationConfiguration

    Test->>AuthConfig: Create with valid JwkConfiguration
    AuthConfig-->>Test: Success

    Test->>AuthConfig: Create with empty JwkConfiguration
    AuthConfig-->>Test: Raise ValidationError

    Test->>AuthConfig: Create with AUTH_MOD_JWK_TOKEN but no jwk_config
    AuthConfig-->>Test: Raise ValidationError
Loading
sequenceDiagram
    participant Test as Unit Test
    participant Client as LlamaStackClient

    Test->>Client: Obtain client instance
    Test->>Client: Assert not closed
    Test->>Client: Call close()/await close()
    Test->>Client: Assert closed
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

Possibly related PRs

Poem

In the warren of code where the tests now reside,
New checks for JWK hop in with pride.
Clients close their doors, both sync and async,
While rabbits review, quicker than you’d think!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 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 0ac8fc4 and 6b08230.

📒 Files selected for processing (1)
  • tests/unit/test_client.py (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/unit/test_client.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). (1)
  • GitHub Check: build-pr
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • 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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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 (1)
tests/unit/test_client.py (1)

104-108: Consider the redundancy of explicit close() in async context manager.

The async context manager usage is excellent practice for resource management. However, explicitly calling await ls_client.close() inside the context may be redundant since the context manager should handle cleanup automatically when exiting.

Consider whether the explicit close() call is necessary:

 async with client.get_client() as ls_client:
     assert ls_client is not None
     assert not ls_client.is_closed()
-    await ls_client.close()
-    assert ls_client.is_closed()

Or if you want to test explicit closure within the context, add a comment explaining the intention.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 58d6101 and 0ac8fc4.

📒 Files selected for processing (2)
  • tests/unit/models/test_config.py (2 hunks)
  • tests/unit/test_client.py (4 hunks)
🧰 Additional context used
🪛 GitHub Actions: Black
tests/unit/test_client.py

[error] 1-1: Black formatting check failed. File would be reformatted. Run 'black --write' to fix code style issues.

⏰ 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). (1)
  • GitHub Check: e2e_tests
🔇 Additional comments (6)
tests/unit/test_client.py (2)

49-51: LGTM! Good addition of client lifecycle verification.

These assertions properly test the client's closed state before and after calling close(), which improves test coverage for client resource management.


68-70: LGTM! Consistent client lifecycle testing.

The same client state verification pattern is applied here, maintaining consistency with the library client test and ensuring both client types are properly tested.

tests/unit/models/test_config.py (4)

13-13: LGTM! Necessary imports for JWK token testing.

The added imports AUTH_MOD_JWK_TOKEN and JwkConfiguration are correctly placed and required for the new authentication tests.

Also applies to: 21-21


687-702: LGTM! Comprehensive positive test case for JWK token authentication.

This test properly verifies the successful creation and configuration of AuthenticationConfiguration with the JWK token module, including all relevant assertions for the configuration properties.


704-715: LGTM! Good validation test for insufficient JWK configuration.

This test properly verifies that a ValidationError is raised when JwkConfiguration is provided but lacks required fields, ensuring proper validation behavior.


717-731: LGTM! Thorough validation test for missing JWK configuration.

This test ensures that a ValidationError with a specific message is raised when the JWK token authentication module is specified but no JwkConfiguration is provided, completing the validation test coverage.

@tisnik tisnik force-pushed the lcore-381-added-unit-tests branch from 0ac8fc4 to 6b08230 Compare August 4, 2025 06:20
@tisnik tisnik merged commit 86d08bf into lightspeed-core:main Aug 4, 2025
17 of 18 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