Skip to content

Commit 6feb4e3

Browse files
authored
Merge pull request #682 from radofuchs/LCORE_816_shields_e2e_tests
LCORE-816: Add new E2E tests for shields endpoint
2 parents ccbcf2d + 324c286 commit 6feb4e3

File tree

6 files changed

+67
-5
lines changed

6 files changed

+67
-5
lines changed

run.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,10 @@ 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
137+
provider_shield_id: "gpt-3.5-turbo" # Model to use for safety checks
135138
vector_dbs:
136139
- vector_db_id: my_knowledge_base
137140
embedding_model: sentence-transformers/all-mpnet-base-v2

tests/e2e/configs/run-azure.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,10 @@ 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
126+
provider_shield_id: "gpt-4o-mini"
124127
models:
125128
- model_id: gpt-4o-mini
126129
model_type: llm

tests/e2e/configs/run-ci.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,10 @@ 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
137+
provider_shield_id: "gpt-4-turbo"
135138
vector_dbs:
136139
- vector_db_id: my_knowledge_base
137140
embedding_model: sentence-transformers/all-mpnet-base-v2

tests/e2e/configs/run-rhaiis.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,10 @@ 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
129+
provider_shield_id: "meta-llama/Llama-3.1-8B-Instruct"
127130
models:
128131
- metadata:
129132
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 has proper model 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: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,37 @@ def check_model_structure(context: Context) -> None:
6363
assert (
6464
llm_model["identifier"] == f"{expected_provider}/{expected_model}"
6565
), f"identifier should be '{expected_provider}/{expected_model}'"
66+
67+
68+
@then("The body of the response has proper shield structure")
69+
def check_shield_structure(context: Context) -> None:
70+
"""Check that the first shield has the correct structure and required fields."""
71+
response_json = context.response.json()
72+
assert response_json is not None, "Response is not valid JSON"
73+
74+
assert "shields" in response_json, "Response missing 'shields' field"
75+
shields = response_json["shields"]
76+
assert len(shields) > 0, "Response has empty list of shields"
77+
78+
# Find first shield
79+
found_shield = None
80+
for shield in shields:
81+
if shield.get("type") == "shield":
82+
found_shield = shield
83+
break
84+
85+
assert found_shield is not None, "No shield found in response"
86+
87+
expected_model = context.default_model
88+
89+
# Validate structure and values
90+
assert found_shield["type"] == "shield", "type should be 'shield'"
91+
assert (
92+
found_shield["provider_id"] == "llama-guard"
93+
), "provider_id should be 'llama-guard'"
94+
assert (
95+
found_shield["provider_resource_id"] == expected_model
96+
), f"provider_resource_id should be '{expected_model}'"
97+
assert (
98+
found_shield["identifier"] == "llama-guard-shield"
99+
), "identifier should be 'llama-guard-shield'"

0 commit comments

Comments
 (0)