Skip to content

Commit f4de94e

Browse files
committed
feat: enhance vector store fixture with dataset support
Refactor the vector store fixture to support Dataset instances for document uploads, improving test setup flexibility. Update vector store upload functions to handle datasets and their associated attributes. Remove deprecated constants and adjust test cases to use the new dataset structure. Signed-off-by: Jorge Garcia Oncins <jgarciao@redhat.com> Made-with: Cursor
2 parents 809a9c5 + 84eb111 commit f4de94e

File tree

6 files changed

+73
-9
lines changed

6 files changed

+73
-9
lines changed

tests/llama_stack/conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,11 @@ def vector_store(
834834
LOGGER.info(f"vector_store successfully created (provider_id={vector_io_provider}, id={vector_store.id})")
835835

836836
if dataset or doc_sources:
837+
if dataset and doc_sources:
838+
LOGGER.warning(
839+
"Both 'dataset' and 'doc_sources' were provided; only 'dataset' will be used "
840+
"(these parameters are mutually exclusive)"
841+
)
837842
try:
838843
if dataset:
839844
vector_store_upload_dataset(

tests/llama_stack/dataset/corpus/finance/documents.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"period_year": 2025,
4545
"document_type": "earnings_press_release",
4646
"language": "en",
47-
"publication_date": 1738022400
47+
"publication_date": 1769558400
4848
}
4949
}
5050
]

tests/llama_stack/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def vector_store_create_and_poll(
7979
vector_store_id: str,
8080
file_id: str,
8181
*,
82-
attributes: Any,
82+
attributes: dict[str, str | int | float | bool] | None = None,
8383
poll_interval_sec: float = 5.0,
8484
wait_timeout: float = 240.0,
8585
) -> VectorStoreFile:
@@ -290,7 +290,7 @@ def vector_store_create_file_from_path(
290290
_assert_file_uploaded(uploaded_file=uploaded_file, expected_purpose="assistants")
291291
LOGGER.info(f"Uploaded {file_path.name} (file_id={uploaded_file.id}) to the llama-stack files provider")
292292

293-
LOGGER.info(f"Adding uploaded file (filename{uploaded_file.filename} to vector store {vector_store.id}")
293+
LOGGER.info(f"Adding uploaded file (filename={uploaded_file.filename}) to vector store {vector_store.id}")
294294
vs_file = vector_store_create_and_poll(
295295
llama_stack_client=llama_stack_client,
296296
vector_store_id=vector_store.id,
@@ -300,7 +300,7 @@ def vector_store_create_file_from_path(
300300
_assert_vector_store_file_attached(
301301
filename=uploaded_file.filename, vs_file=vs_file, vector_store_id=vector_store.id, attributes=attributes
302302
)
303-
LOGGER.info(f"Added uploaded file (filename{uploaded_file.filename} to vector store {vector_store.id}")
303+
LOGGER.info(f"Added uploaded file (filename={uploaded_file.filename}) to vector store {vector_store.id}")
304304
return vs_file
305305

306306

tests/llama_stack/vector_io/test_vector_stores.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ def test_response_file_search_tool_invocation(
196196
a completed file_search_call with results carrying file metadata, and that the
197197
message includes file_citation annotations with file_id and filename.
198198
"""
199-
vector_question = next(r.question for r in dataset.load_qa(retrieval_mode="vector"))
199+
vector_question = next((r.question for r in dataset.load_qa(retrieval_mode="vector")), None)
200+
assert vector_question is not None, "No vector-mode QA records found in dataset ground truth"
200201

201202
response = unprivileged_llama_stack_client.responses.create(
202203
input=vector_question,

tests/model_explainability/evalhub/test_evalhub_health.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
import pytest
22
from ocp_resources.route import Route
33

4-
from tests.model_explainability.evalhub.utils import validate_evalhub_health
4+
from tests.model_explainability.evalhub.utils import validate_evalhub_health, validate_evalhub_providers
55

66

77
@pytest.mark.parametrize(
88
"model_namespace",
99
[
1010
pytest.param(
11-
{"name": "test-evalhub-health"},
11+
{"name": "test-evalhub-health-providers"},
1212
),
1313
],
1414
indirect=True,
1515
)
1616
@pytest.mark.smoke
1717
@pytest.mark.model_explainability
18-
class TestEvalHubHealth:
19-
"""Tests for basic EvalHub service health and availability."""
18+
class TestEvalHub:
19+
"""Tests for basic EvalHub service health and providers."""
2020

2121
def test_evalhub_health_endpoint(
2222
self,
@@ -30,3 +30,19 @@ def test_evalhub_health_endpoint(
3030
token=current_client_token,
3131
ca_bundle_file=evalhub_ca_bundle_file,
3232
)
33+
34+
def test_evalhub_providers_list(
35+
self,
36+
current_client_token: str,
37+
evalhub_ca_bundle_file: str,
38+
evalhub_route: Route,
39+
model_namespace,
40+
) -> None:
41+
"""Test that the evaluations providers endpoint returns a non-empty list."""
42+
43+
validate_evalhub_providers(
44+
host=evalhub_route.host,
45+
token=current_client_token,
46+
ca_bundle_file=evalhub_ca_bundle_file,
47+
tenant=model_namespace.name,
48+
)

tests/model_explainability/evalhub/utils.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,31 @@
33
from tests.model_explainability.evalhub.constants import (
44
EVALHUB_HEALTH_PATH,
55
EVALHUB_HEALTH_STATUS_HEALTHY,
6+
EVALHUB_PROVIDERS_PATH,
67
)
78
from utilities.guardrails import get_auth_headers
89
from utilities.opendatahub_logger import get_logger
910

1011
LOGGER = get_logger(name=__name__)
1112

13+
TENANT_HEADER: str = "X-Tenant"
14+
15+
16+
def _build_headers(token: str, tenant: str | None = None) -> dict[str, str]:
17+
"""Build request headers with auth and optional tenant.
18+
19+
Args:
20+
token: Bearer token for authentication.
21+
tenant: Namespace for the X-Tenant header. Omitted if None.
22+
23+
Returns:
24+
Headers dict.
25+
"""
26+
headers = get_auth_headers(token=token)
27+
if tenant is not None:
28+
headers[TENANT_HEADER] = tenant
29+
return headers
30+
1231

1332
def validate_evalhub_health(
1433
host: str,
@@ -45,3 +64,26 @@ def validate_evalhub_health(
4564
f"Expected status '{EVALHUB_HEALTH_STATUS_HEALTHY}', got '{data['status']}'"
4665
)
4766
assert "timestamp" in data, "Health response missing 'timestamp' field"
67+
68+
69+
def validate_evalhub_providers(
70+
host: str,
71+
token: str,
72+
ca_bundle_file: str,
73+
tenant: str | None = None,
74+
) -> dict:
75+
"""Smoke test for the EvalHub providers endpoint."""
76+
url = f"https://{host}{EVALHUB_PROVIDERS_PATH}"
77+
78+
response = requests.get(
79+
url=url,
80+
headers=_build_headers(token=token, tenant=tenant),
81+
verify=ca_bundle_file,
82+
timeout=10,
83+
)
84+
response.raise_for_status()
85+
86+
data = response.json()
87+
assert data.get("items"), f"Smoke test failed: Providers list is empty for tenant {tenant}"
88+
89+
return data

0 commit comments

Comments
 (0)