Skip to content

Commit a229124

Browse files
authored
Merge pull request #696 from radofuchs/LCORE_817_tools_e2e_tests
LCORE-817: add new e2e tests for tools endpoint
2 parents 09ec1f6 + 763cdd1 commit a229124

File tree

2 files changed

+118
-0
lines changed

2 files changed

+118
-0
lines changed

tests/e2e/features/info.feature

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,62 @@ Feature: Info tests
6464
{"detail": {"response": "Unable to connect to Llama Stack", "cause": "Connection error."}}
6565
"""
6666

67+
Scenario: Check if tools endpoint is working
68+
Given The system is in default state
69+
When I access REST API endpoint "tools" using HTTP GET method
70+
Then The status code of the response is 200
71+
And The response contains 2 tools listed for provider rag-runtime
72+
And The body of the response has the following schema
73+
"""
74+
{
75+
"$schema": "https://json-schema.org/draft/2020-12/schema",
76+
"type": "object",
77+
"properties": {
78+
"identifier": { "type": "string" },
79+
"description": { "type": "string" },
80+
"parameters": {
81+
"type": "array",
82+
"items": {
83+
"type": "object",
84+
"properties": {
85+
"description": { "type": "string" },
86+
"name": { "type": "string" },
87+
"parameter_type": { "type": "string" },
88+
"required": { "type": "boolean" },
89+
"default": { "type": ["string", "null"] }
90+
}
91+
}
92+
},
93+
"provider_id": { "type": "string" },
94+
"toolgroup_id": { "type": "string" },
95+
"server_source": { "type": "string" },
96+
"type": { "type": "string" }
97+
}
98+
}
99+
"""
100+
And The body of the response has proper structure for provider rag-runtime
101+
"""
102+
{
103+
"identifier": "insert_into_memory",
104+
"description": "Insert documents into memory",
105+
"provider_id": "rag-runtime",
106+
"toolgroup_id": "builtin::rag",
107+
"server_source": "builtin",
108+
"type": "tool"
109+
}
110+
"""
111+
112+
113+
Scenario: Check if tools endpoint reports error when llama-stack in unreachable
114+
Given The system is in default state
115+
And The llama-stack connection is disrupted
116+
When I access REST API endpoint "tools" using HTTP GET method
117+
Then The status code of the response is 500
118+
And The body of the response is the following
119+
"""
120+
{"detail": {"response": "Unable to connect to Llama Stack", "cause": "Connection error."}}
121+
"""
122+
67123
Scenario: Check if metrics endpoint is working
68124
Given The system is in default state
69125
When I access endpoint "metrics" using HTTP GET method

tests/e2e/features/steps/info.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Implementation of common test steps."""
22

3+
import json
34
from behave import then # pyright: ignore[reportAttributeAccessIssue]
45
from behave.runner import Context
56

@@ -97,3 +98,64 @@ def check_shield_structure(context: Context) -> None:
9798
assert (
9899
found_shield["identifier"] == "llama-guard-shield"
99100
), "identifier should be 'llama-guard-shield'"
101+
102+
103+
@then("The response contains {count:d} tools listed for provider {provider_name}")
104+
def check_tool_count(context: Context, count: int, provider_name: str) -> None:
105+
"""Check that the number of tools for defined provider is correct."""
106+
response_json = context.response.json()
107+
assert response_json is not None, "Response is not valid JSON"
108+
109+
assert "tools" in response_json, "Response missing 'tools' field"
110+
tools = response_json["tools"]
111+
assert len(tools) > 0, "Response has empty list of tools"
112+
113+
provider_tools = []
114+
115+
for tool in tools:
116+
if tool["provider_id"] == provider_name:
117+
provider_tools.append(tool)
118+
119+
assert len(provider_tools) == count
120+
121+
122+
@then("The body of the response has proper structure for provider {provider_name}")
123+
def check_tool_structure(context: Context, provider_name: str) -> None:
124+
"""Check that the first listed tool for defined provider has the correct structure."""
125+
response_json = context.response.json()
126+
assert response_json is not None, "Response is not valid JSON"
127+
128+
expected_json = json.loads(context.text)
129+
130+
assert "tools" in response_json, "Response missing 'tools' field"
131+
tools = response_json["tools"]
132+
assert len(tools) > 0, "Response has empty list of tools"
133+
134+
provider_tool = None
135+
136+
for tool in tools:
137+
if tool["provider_id"] == provider_name:
138+
provider_tool = tool
139+
break
140+
141+
assert provider_tool is not None, "No tool found in response"
142+
143+
# Validate structure and values
144+
assert (
145+
provider_tool["identifier"] == expected_json["identifier"]
146+
), f"identifier should be {expected_json["identifier"]}, but was {provider_tool["identifier"]}"
147+
assert (
148+
provider_tool["description"] == expected_json["description"]
149+
), f"description should be {expected_json["description"]}"
150+
assert (
151+
provider_tool["provider_id"] == expected_json["provider_id"]
152+
), f"provider_id should be {expected_json["provider_id"]}"
153+
assert (
154+
provider_tool["toolgroup_id"] == expected_json["toolgroup_id"]
155+
), f"toolgroup_id should be {expected_json["toolgroup_id"]}"
156+
assert (
157+
provider_tool["server_source"] == expected_json["server_source"]
158+
), f"server_source should be {expected_json["server_source"]}"
159+
assert (
160+
provider_tool["type"] == expected_json["type"]
161+
), f"type should be {expected_json["type"]}"

0 commit comments

Comments
 (0)