Skip to content

Conversation

@radofuchs
Copy link
Contributor

@radofuchs radofuchs commented Oct 3, 2025

Description

Add E2E tests for query 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-488
  • Closes #LCORE-488

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 coverage requiring Authorization header.
    • Added scenarios for conversation continuity, system prompt variations, and missing inputs/provider/model validations.
    • Validated server-side error paths (400, 403, 422, 500).
    • Adjusted streaming query flow to clarify action steps.
  • Chores

    • CI now surfaces stack logs on failure for easier troubleshooting.
    • Updated file metadata storage path to an absolute location for improved stability.

@radofuchs radofuchs requested a review from tisnik October 3, 2025 07:04
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 3, 2025

Walkthrough

Updates E2E tests to require authorization, add conversation-aware scenarios, and expand error-path coverage. Introduces new step functions for authorized requests and response storage. Adjusts streaming step keywords. Modifies the e2e GitHub Actions workflow to use an absolute metadata path and print logs on failure.

Changes

Cohort / File(s) Summary
Workflow updates
.github/workflows/e2e_tests.yaml
Switched files_metadata.db path to /app-root/.llama/...; added a failure-only step to print llama-stack and lightspeed-stack logs.
E2E query feature overhaul
tests/e2e/features/query.feature
Replaced scenarios to enforce Authorization headers, add conversation reuse, vary system prompts, and cover expanded 400/403/422/500 error cases including unauthorized conversation access and backend disruption.
E2E step implementations
tests/e2e/features/steps/llm_query_response.py
Added ask_question_authorized and store_conversation_details; updated same-conversation requests to include auth headers when present.
Streaming feature step tweaks
tests/e2e/features/streaming_query.feature
Changed step keyword from “And” to “When” for three scenarios; no payload/expectation changes.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Tester
  participant Feature as Feature (Gherkin)
  participant Steps as Step Impl
  participant API as Backend API
  participant Store as Conversation Store

  Note over Feature,Steps: Authorized query with conversation creation
  Tester->>Feature: Run scenario @Authorized
  Feature->>Steps: ask_question_authorized(endpoint)
  Steps->>API: POST /query with Authorization + payload
  API->>Store: Create conversation (if absent)
  Store-->>API: conversation_id
  API-->>Steps: 200 + body (conversation_id, answer)
  Steps->>Steps: store_conversation_details()

  Note over Feature,Steps: Follow-up in same conversation
  Feature->>Steps: ask_question_in_same_conversation()
  Steps->>API: POST /query (Authorization, conversation_id)
  API->>Store: Validate access to conversation
  Store-->>API: OK / Forbidden
  alt Access OK
    API-->>Steps: 200 + body (answer)
  else Forbidden
    API-->>Steps: 403 + error
  end
Loading
sequenceDiagram
  autonumber
  actor Tester
  participant Steps as Step Impl
  participant API as Backend API

  Note over Steps,API: Error paths (examples)
  Steps->>API: POST /query (missing Authorization)
  API-->>Steps: 401/403 + error

  Steps->>API: POST /query (missing query/provider/model)
  API-->>Steps: 400/422 + validation error

  Steps->>API: POST /query during stack disruption
  API-->>Steps: 500 + server error
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • tisnik

Poem

In moonlit logs I nibble bytes so bright,
New headers hop—authorization’s right.
Conversations burrow, IDs tight,
When errors loom, we print the night.
From burrow to stack, I leap with glee—
All tests now squeak: authenticated, wee! 🐇✨

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 PR title concisely describes the main change—adding end-to-end tests for the query endpoint—and includes the related ticket reference in conventional form. It is clear, specific, and focused on the primary purpose of the changeset.
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

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

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4f8fbac and 94b94be.

📒 Files selected for processing (4)
  • .github/workflows/e2e_tests.yaml (2 hunks)
  • tests/e2e/features/query.feature (1 hunks)
  • tests/e2e/features/steps/llm_query_response.py (2 hunks)
  • tests/e2e/features/streaming_query.feature (3 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
**/*.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/e2e/features/steps/llm_query_response.py
tests/e2e/features/steps/**/*.py

📄 CodeRabbit inference engine (CLAUDE.md)

Place behave step definitions under tests/e2e/features/steps/

Files:

  • tests/e2e/features/steps/llm_query_response.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/e2e/features/steps/llm_query_response.py
tests/e2e/features/**/*.feature

📄 CodeRabbit inference engine (CLAUDE.md)

Write E2E tests as Gherkin feature files for behave

Files:

  • tests/e2e/features/streaming_query.feature
  • tests/e2e/features/query.feature
⏰ 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). (2)
  • GitHub Check: build-pr
  • GitHub Check: e2e_tests

Comment on lines +12 to +16
And I set the Authorization header to Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6Ikpva
When I use "query" to ask question with authorization header
"""
{"query": "Generate sample yaml file for simple GitHub Actions workflow.", "system_prompt": "refuse to answer anything but openshift questions"}
"""
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 | 🔴 Critical

Restore complete JWT token for authorized scenarios

The bearer token here (and in the other scenarios) stops after the payload segment and drops the signature, leaving only two JWT sections. Any code that parses or verifies the token will reject it (Not enough segments/invalid signature), so the “authorized” scenarios will fail instead of exercising the intended flow. Please supply the full three-part token (or switch to a reusable constant) everywhere this step appears.

-    And I set the Authorization header to Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6Ikpva
+    And I set the Authorization header to Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c

Apply the same fix to every scenario that sets this header.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
And I set the Authorization header to Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6Ikpva
When I use "query" to ask question with authorization header
"""
{"query": "Generate sample yaml file for simple GitHub Actions workflow.", "system_prompt": "refuse to answer anything but openshift questions"}
"""
And I set the Authorization header to Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
When I use "query" to ask question with authorization header
"""
{"query": "Generate sample yaml file for simple GitHub Actions workflow.", "system_prompt": "refuse to answer anything but openshift questions"}
"""
🤖 Prompt for AI Agents
In tests/e2e/features/query.feature around lines 12 to 16, the Authorization
header uses a truncated JWT missing the signature part which causes token
parsing/verification to fail; restore the full three-part JWT
(header.payload.signature) or replace the literal with a shared reusable
constant used across scenarios, and apply the same change to every scenario in
the test suite that sets this header so authorized scenarios exercise the
intended flow.

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 b6698ed into lightspeed-core:main Oct 3, 2025
18 of 19 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