Skip to content

LCORE-1206: add extra e2e tests to align with OLS#1103

Merged
tisnik merged 1 commit intolightspeed-core:mainfrom
radofuchs:E2E_OLS_Alignment
Feb 4, 2026
Merged

LCORE-1206: add extra e2e tests to align with OLS#1103
tisnik merged 1 commit intolightspeed-core:mainfrom
radofuchs:E2E_OLS_Alignment

Conversation

@radofuchs
Copy link
Contributor

@radofuchs radofuchs commented Feb 4, 2026

add new tests for token quotas

Description

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

Tools used to create PR

Identify any AI code assistants used in this PR (for transparency and review context)

  • Assisted-by: (e.g., Claude, CodeRabbit, Ollama, etc., N/A if not used)
  • Generated by: (e.g., tool name and version; N/A if not used)

Related Tickets & Documents

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
    • Expanded end-to-end test coverage to validate token metrics tracking for query operations across standard and streaming responses, including error scenarios.

add new tests for token quotas
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 4, 2026

Walkthrough

This pull request adds end-to-end test coverage for token usage metrics validation. It introduces new step definitions for capturing and asserting token metrics from API responses and Prometheus endpoints, and updates existing test scenarios to verify token metrics increase after successful queries and remain unchanged during error conditions.

Changes

Cohort / File(s) Summary
Feature Test Scenarios
tests/e2e/features/query.feature, tests/e2e/features/streaming_query.feature
Added token metrics capture and assertion steps to multiple scenarios to verify token counters (input_tokens, output_tokens, available_quotas) are populated for successful responses and metrics increase after queries, while remaining unchanged after error conditions (401, 404, 422, 503).
Token Counter Step Definitions
tests/e2e/features/steps/token_counters.py
New module providing 8 step definition functions to validate token counter fields in responses, capture Prometheus metrics, compare metrics state before/after queries, and extract token data from streamed end-events. Includes helper utilities for fetching current metrics from Prometheus endpoint, parsing SSE stream responses, and aggregating token metrics from Prometheus text format.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Suggested reviewers

  • tisnik
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly references a ticket (LCORE-1206) and describes the main change: adding extra e2e tests to align with OLS, which matches the actual changes that add token metrics validation to feature files and introduce a new step definitions module.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Important

Action Needed: IP Allowlist Update

If your organization protects your Git platform with IP whitelisting, please add the new CodeRabbit IP address to your allowlist:

  • 136.113.208.247/32 (new)
  • 34.170.211.100/32
  • 35.222.179.152/32

Reviews will stop working after February 8, 2026 if the new IP is not added to your allowlist.


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.

@radofuchs radofuchs requested a review from tisnik February 4, 2026 09:46
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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tests/e2e/features/query.feature (1)

96-129: ⚠️ Potential issue | 🟠 Major

Duplicate scenario names and incorrect scenario content.

There are two issues here:

  1. Lines 106-114: This scenario is titled "Check if LLM responds for query request with error for missing query" but the request body contains a valid query field and tests for "Improper conversation ID" error. This appears to be a copy of the scenario above (lines 96-105).

  2. Lines 116-129: Another scenario with the same title "Check if LLM responds for query request with error for missing query" which correctly tests the missing query case.

The scenario at lines 106-114 should be removed as it duplicates the scenario at lines 96-105.

🐛 Proposed fix - remove duplicate scenario
       Then The status code of the response is 422
       And The body of the response contains Value error, Improper conversation ID '123e4567'
 
-Scenario: Check if LLM responds for query request with error for missing query
-    Given The system is in default state
-     And I set the Authorization header to Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6Ikpva
-     When I use "query" to ask question with authorization header
-     """
-     {"conversation_id": "123e4567", "query": "Write a simple code for reversing string", "model": "{MODEL}", "provider": "{PROVIDER}"}
-     """
-      Then The status code of the response is 422
-      And The body of the response contains Value error, Improper conversation ID '123e4567'
-
   Scenario: Check if LLM responds for query request with error for missing query
     Given The system is in default state
       And I set the Authorization header to Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6Ikpva
🤖 Fix all issues with AI agents
In `@tests/e2e/features/steps/token_counters.py`:
- Around line 98-106: The precondition in check_streamed_token_counter_fields
incorrectly asserts context.response_data but then uses context.response.text;
update the precondition to assert the actual dependency, e.g., verify
context.response is not None and that context.response.text is present before
calling _get_end_event_data, so replace the assert on context.response_data with
an assertion that context.response and context.response.text (or equivalent) are
available to avoid a misleading check and potential AttributeError when
extracting end_event_data.
🧹 Nitpick comments (3)
tests/e2e/features/steps/token_counters.py (1)

166-169: Consider creating a new dict to avoid mutating the parsed event data.

Line 167 retrieves the data dict from the event, and line 168 mutates it. This modifies the original parsed JSON object. While acceptable in test code, creating a shallow copy would be safer.

♻️ Proposed fix
                 if event.get("event") == "end":
                     # Merge data contents with available_quotas from parent level
-                    result = event.get("data", {})
+                    result = {**event.get("data", {})}
                     result["available_quotas"] = event.get("available_quotas", {})
                     return result
tests/e2e/features/streaming_query.feature (2)

107-115: Consider adding token metrics validation for consistency.

This scenario doesn't capture or validate token metrics, unlike similar 422 error scenarios (missing query, missing model). Consider adding token metrics capture and unchanged validation for consistency across error scenarios.


117-137: Inconsistent token metrics validation between similar error scenarios.

The "unknown provider" scenario (lines 127-137) captures and validates token metrics unchanged, but the "unknown model" scenario (lines 117-125) does not. Both are 404 errors - consider adding token metrics validation to the unknown model scenario for consistency.

♻️ Proposed fix
   Scenario: Check if LLM responds for streaming_query request with error for unknown model
     Given The system is in default state
       And I set the Authorization header to Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6Ikpva
+      And I capture the current token metrics
     When I use "streaming_query" to ask question with authorization header
     """
     {"query": "Say hello", "provider": "{PROVIDER}", "model":"unknown"}
     """
     Then The status code of the response is 404
       And The body of the response contains Model with ID unknown does not exist
+      And The token metrics should not have changed

Comment on lines +98 to +106
@then("The streamed response should contain token counter fields")
def check_streamed_token_counter_fields(context: Context) -> None:
"""Check that streamed response end event contains token fields."""
assert context.response_data is not None, "Response data needs to be parsed first"

# Parse the end event from the streaming response to get token info
end_event_data = _get_end_event_data(context.response.text)
assert end_event_data is not None, "End event not found in streaming response"

Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Misleading precondition assertion.

Line 101 asserts context.response_data is not None, but line 104 accesses context.response.text. The assertion doesn't validate what's actually used. Consider aligning the precondition check with the actual dependency.

🔧 Proposed fix
 def check_streamed_token_counter_fields(context: Context) -> None:
     """Check that streamed response end event contains token fields."""
-    assert context.response_data is not None, "Response data needs to be parsed first"
+    assert context.response is not None, "Response needs to be available first"
 
     # Parse the end event from the streaming response to get token info
     end_event_data = _get_end_event_data(context.response.text)
🤖 Prompt for AI Agents
In `@tests/e2e/features/steps/token_counters.py` around lines 98 - 106, The
precondition in check_streamed_token_counter_fields incorrectly asserts
context.response_data but then uses context.response.text; update the
precondition to assert the actual dependency, e.g., verify context.response is
not None and that context.response.text is present before calling
_get_end_event_data, so replace the assert on context.response_data with an
assertion that context.response and context.response.text (or equivalent) are
available to avoid a misleading check and potential AttributeError when
extracting end_event_data.

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

@tisnik tisnik merged commit d57022a into lightspeed-core:main Feb 4, 2026
21 of 22 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