Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
should start failing so the leak is caught rather than silently reappearing.
"""

from urllib.parse import unquote, urlsplit

import pytest

# Path segment unique to the OpenShift Virtualization documentation book in the
Expand All @@ -28,31 +30,48 @@

class TestOKPVirtualizationFilter:
@pytest.mark.parametrize("question", VIRTUALIZATION_ADJACENT_QUESTIONS)
def test_query_excludes_openshift_virtualization_docs(self, client, question):
"""Virtualization-adjacent questions must not be grounded in OpenShift
Virtualization docs.
"""
response = client.query(question)
def test_responses_excludes_openshift_virtualization_docs(self, client, question):
"""Check the configured OKP document filter through the Responses API."""
response = client.responses(
{
"input": question,
"store": False,
"stream": False,
"tool_choice": {"type": "file_search"},
"include": ["file_search_call.results"],
Comment on lines +40 to +41

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Issue (blocking): Since lightspeed-core/lightspeed-stack#3255 has been merged then after we merge openstack-k8s-operators/lightspeed-operator#163, this will no longer work. LCS now strips server-managed file_search_call items from the /v1/responses output whenever the request doesn't declare a file_search tool in tools ... tool_choice and include don't change that. You can force the presence by specifying file_search in tools.

Additionally, this is not how Goose queries lightspeed-stack via the /v1/responses API. The aim here is to emulate Goose request as closely as possible. Here's a thing we could explore:


🤖 Generated with the help of AI (not 100 % guaranteed to work but worth of exploring in this direction)

  1. Send the request with "store": true (no tools, no tool_choice, no include — the response body won't contain the file search results either way, since they're sanitized out).
  2. Query /v2/conversations/{conversation_id} (the ID comes back in the response's conversation field). The turn is persisted before sanitization, so it records what really happened in the background:
    • tool_calls — contains a file_search entry (name: "file_search", args.queries) iff the model actually performed retrieval;
    • referenced_documents on the assistant message — the deduplicated list of retrieved docs with full doc_urls (LCS builds these from source_path/reference_url chunk attributes), which is what the OpenStack-docs-present / no-virtualization-book assertions should run against.

}
)
assert response.status_code == 200

data = response.json()
rag_chunks = data.get("rag_chunks", [])
doc_urls = [
chunk.get("attributes", {}).get("doc_url", "") for chunk in rag_chunks
results = [
result
for item in response.json().get("output") or []
if item.get("type") == "file_search_call"
for result in item.get("results") or []
]

assert rag_chunks, (
f"Query {question!r} returned no rag_chunks; OKP retrieval may be broken"
assert results, (
f"Question {question!r} returned no file search results; "
"OKP retrieval may be broken"
)

openstack_docs = [
url for url in doc_urls if OPENSTACK_DOC_MARKER in url.lower()
]
# OKP uses source_path offline and reference_url for online documents.
doc_paths = []
for result in results:
attributes = result.get("attributes") or {}
reference = attributes.get("source_path") or attributes.get("reference_url")
assert isinstance(reference, str) and reference.strip(), (
f"Question {question!r} returned a result without a document path"
)
# The service hostname may contain 'openstack' for every product.
doc_paths.append(unquote(urlsplit(reference).path).lower())

assert all(doc_paths), f"Question {question!r} returned empty document paths"
openstack_docs = [path for path in doc_paths if OPENSTACK_DOC_MARKER in path]
assert openstack_docs, (
f"Query {question!r} returned no OpenStack-related rag_chunks: {doc_urls}"
f"Question {question!r} returned no OpenStack-related documents: {doc_paths}"
)

leaked = [url for url in doc_urls if VIRTUALIZATION_BOOK_PATH in url]
leaked = [path for path in doc_paths if VIRTUALIZATION_BOOK_PATH in path]
assert not leaked, (
f"Query {question!r} retrieved OpenShift Virtualization docs: {leaked}"
f"Question {question!r} retrieved OpenShift Virtualization docs: {leaked}"
)
Loading