-
Notifications
You must be signed in to change notification settings - Fork 52
LCORE-740: minor fixes in endpoint unit tests #763
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
Conversation
WalkthroughThis PR updates unit test files to align with authentication tuple shape changes (from 3-tuple to 4-tuple), adds async mocking for the metrics endpoint, refines type annotations in test utilities, and expands streaming payload structures with richer nested fields in the streaming query tests. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 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: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
tests/unit/app/endpoints/test_metrics.py(1 hunks)tests/unit/app/endpoints/test_models.py(6 hunks)tests/unit/app/endpoints/test_query_v2.py(12 hunks)tests/unit/app/endpoints/test_streaming_query.py(2 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_streaming_query.pytests/unit/app/endpoints/test_query_v2.pytests/unit/app/endpoints/test_models.pytests/unit/app/endpoints/test_metrics.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_streaming_query.pytests/unit/app/endpoints/test_query_v2.pytests/unit/app/endpoints/test_models.pytests/unit/app/endpoints/test_metrics.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_streaming_query.pytests/unit/app/endpoints/test_query_v2.pytests/unit/app/endpoints/test_models.pytests/unit/app/endpoints/test_metrics.py
🧠 Learnings (7)
📓 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 tests/**/*.py : Use the shared auth mock constant: MOCK_AUTH = ("mock_user_id", "mock_username", False, "mock_token") in tests
📚 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/app/endpoints/test_query_v2.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/**/*.py,configuration.py} : Use precise type hints in configuration (e.g., Optional[FilePath], PositiveInt, SecretStr)
Applied to files:
tests/unit/app/endpoints/test_query_v2.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/app/endpoints/test_query_v2.pytests/unit/app/endpoints/test_models.pytests/unit/app/endpoints/test_metrics.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/client.py : Handle Llama Stack APIConnectionError when interacting with the Llama client
Applied to files:
tests/unit/app/endpoints/test_query_v2.pytests/unit/app/endpoints/test_models.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/app/endpoints/test_models.pytests/unit/app/endpoints/test_metrics.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/client.py : Use Llama Stack client import: from llama_stack_client import AsyncLlamaStackClient
Applied to files:
tests/unit/app/endpoints/test_models.py
🧬 Code graph analysis (2)
tests/unit/app/endpoints/test_streaming_query.py (1)
src/models/responses.py (1)
ToolCall(157-162)
tests/unit/app/endpoints/test_query_v2.py (1)
src/configuration.py (1)
llama_stack_configuration(87-91)
⏰ 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)
| streaming_content: list[str] = [] | ||
| # response.body_iterator is an async generator, iterate over it directly | ||
| async for chunk in response.body_iterator: | ||
| streaming_content.append(chunk) | ||
| streaming_content.append(str(chunk)) | ||
|
|
||
| # Convert to string for assertions | ||
| full_content = "".join(streaming_content) # type: ignore | ||
| full_content = "".join(streaming_content) | ||
|
|
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.
Decode streaming chunks instead of coercing to repr strings
Casting chunk with str() turns the byte payload into its repr ("b'data: …'"). Later assertions slice the string and feed it to json.loads, which now blows up because of the leading b'/trailing '. Decode the bytes (and fall back to the original string) so the test still exercises the SSE payload rather than its repr.
Apply this diff:
- streaming_content.append(str(chunk))
+ streaming_content.append(
+ chunk if isinstance(chunk, str) else chunk.decode("utf-8")
+ )🤖 Prompt for AI Agents
In tests/unit/app/endpoints/test_streaming_query.py around lines 358 to 365, the
test currently uses str(chunk) which produces the Python repr (e.g. "b'...'" )
and breaks later JSON parsing; update the loop to decode chunk when it's bytes
(e.g. chunk.decode('utf-8')) and fall back to using the original chunk if it's
already a str, appending the decoded/normalized string to streaming_content so
the assembled full_content contains the actual SSE payload instead of its repr.
Description
LCORE-740: minor fixes in endpoint unit tests
Type of change
Related Tickets & Documents
Summary by CodeRabbit