Skip to content

Commit 3392b17

Browse files
committed
Add new E2E tests for shields endpoint
1 parent e837f6c commit 3392b17

File tree

7 files changed

+232
-175
lines changed

7 files changed

+232
-175
lines changed

run.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ server:
131131
tls_cafile: null
132132
tls_certfile: null
133133
tls_keyfile: null
134-
shields: []
134+
shields:
135+
- shield_id: llama-guard-shield
136+
provider_id: llama-guard
135137
vector_dbs:
136138
- vector_db_id: my_knowledge_base
137139
embedding_model: sentence-transformers/all-mpnet-base-v2

tests/e2e/configs/run-azure.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ server:
120120
tls_cafile: null
121121
tls_certfile: null
122122
tls_keyfile: null
123-
shields: []
123+
shields:
124+
- shield_id: llama-guard-shield
125+
provider_id: llama-guard
124126
models:
125127
- model_id: gpt-4o-mini
126128
model_type: llm

tests/e2e/configs/run-ci.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ server:
131131
tls_cafile: null
132132
tls_certfile: null
133133
tls_keyfile: null
134-
shields: []
134+
shields:
135+
- shield_id: llama-guard-shield
136+
provider_id: llama-guard
135137
vector_dbs:
136138
- vector_db_id: my_knowledge_base
137139
embedding_model: sentence-transformers/all-mpnet-base-v2

tests/e2e/configs/run-rhaiis.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ server:
123123
tls_cafile: null
124124
tls_certfile: null
125125
tls_keyfile: null
126-
shields: []
126+
shields:
127+
- shield_id: llama-guard-shield
128+
provider_id: llama-guard
127129
models:
128130
- metadata:
129131
embedding_dimension: 768 # Depends on chosen model

tests/e2e/features/info.feature

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Feature: Info tests
3737
And The body of the response for model gpt-4o-mini has proper structure
3838

3939

40-
Scenario: Check if models endpoint is working
40+
Scenario: Check if models endpoint reports error when llama-stack in unreachable
4141
Given The system is in default state
4242
And The llama-stack connection is disrupted
4343
When I access REST API endpoint "models" using HTTP GET method
@@ -47,6 +47,22 @@ Feature: Info tests
4747
{"detail": {"response": "Unable to connect to Llama Stack", "cause": "Connection error."}}
4848
"""
4949

50+
Scenario: Check if shields endpoint is working
51+
Given The system is in default state
52+
When I access REST API endpoint "shields" using HTTP GET method
53+
Then The status code of the response is 200
54+
And The body of the response has proper shield structure
55+
56+
57+
Scenario: Check if shields endpoint reports error when llama-stack in unreachable
58+
Given The system is in default state
59+
And The llama-stack connection is disrupted
60+
When I access REST API endpoint "shields" using HTTP GET method
61+
Then The status code of the response is 500
62+
And The body of the response is the following
63+
"""
64+
{"detail": {"response": "Unable to connect to Llama Stack", "cause": "Connection error."}}
65+
"""
5066

5167
Scenario: Check if metrics endpoint is working
5268
Given The system is in default state

tests/e2e/features/steps/info.py

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,53 @@ def check_model_structure(context: Context, model: str) -> None:
3737
models = response_json["models"]
3838
assert len(models) > 0, "Models list should not be empty"
3939

40-
gpt_model = None
40+
llm_model = None
4141
for model_id in models:
4242
if "gpt-4o-mini" in model_id.get("identifier", ""):
43-
gpt_model = model_id
43+
llm_model = model_id
4444
break
4545

46-
assert gpt_model is not None
46+
assert llm_model is not None
4747

48-
assert gpt_model["type"] == "model", "type should be 'model'"
49-
assert gpt_model["api_model_type"] == "llm", "api_model_type should be 'llm'"
50-
assert gpt_model["model_type"] == "llm", "model_type should be 'llm'"
51-
assert gpt_model["provider_id"] == "openai", "provider_id should be 'openai'"
48+
assert llm_model["type"] == "model", "type should be 'model'"
49+
assert llm_model["api_model_type"] == "llm", "api_model_type should be 'llm'"
50+
assert llm_model["model_type"] == "llm", "model_type should be 'llm'"
51+
assert llm_model["provider_id"] == "openai", "provider_id should be 'openai'"
5252
assert (
53-
gpt_model["provider_resource_id"] == model
53+
llm_model["provider_resource_id"] == model
5454
), "provider_resource_id should be 'gpt-4o-mini'"
5555
assert (
56-
gpt_model["identifier"] == f"openai/{model}"
56+
llm_model["identifier"] == f"openai/{model}"
5757
), "identifier should be 'openai/gpt-4o-mini'"
58+
59+
60+
@then("The body of the response has proper shield structure")
61+
def check_shield_structure(context: Context) -> None:
62+
"""Check that the first shield has the correct structure and required fields."""
63+
response_json = context.response.json()
64+
assert response_json is not None, "Response is not valid JSON"
65+
66+
assert "shields" in response_json, "Response missing 'shields' field"
67+
shields = response_json["shields"]
68+
assert len(shields) > 0, "Response has empty list of shields"
69+
70+
# Find first shield
71+
found_shield = None
72+
for shield in shields:
73+
if shield.get("type") == "shield":
74+
found_shield = shield
75+
break
76+
77+
assert found_shield is not None, "No LLM model found in response"
78+
79+
# Validate structure and values
80+
assert found_shield["type"] == "shield", "type should be 'model'"
81+
assert (
82+
found_shield["provider_id"] == "llama-guard"
83+
), "provider_id should be 'llama-guard'"
84+
assert (
85+
found_shield["provider_resource_id"] == "llama-guard-shield"
86+
), "provider_resource_id should be 'llama-guard-shield'"
87+
assert (
88+
found_shield["identifier"] == "llama-guard-shield"
89+
), "identifier should be 'llama-guard-shield'"

0 commit comments

Comments
 (0)