chatsbt/test-backend.hurl

165 lines
3.6 KiB
Text
Raw Normal View History

2025-08-04 14:06:28 -04:00
# Hurl Test Script for Chat Backend API
# This script tests the complete flow of the backend API
# Test 1: Get available models
GET http://localhost:8000/api/models
HTTP 200
[Captures]
models: jsonpath "$.models"
# Validate models response
[Asserts]
jsonpath "$.models" count > 0
# Test 2: Create a new chat
POST http://localhost:8000/api/chats
Content-Type: application/json
{
"model": "qwen/qwen3-235b-a22b-2507"
}
HTTP 200
[Captures]
chat_id: jsonpath "$.id"
model: jsonpath "$.model"
# Validate chat creation response
[Asserts]
jsonpath "$.id" != null
jsonpath "$.model" == "qwen/qwen3-235b-a22b-2507"
# Test 3: Get chat history (should be empty initially)
GET http://localhost:8000/api/chats/{{chat_id}}
HTTP 200
[Captures]
messages: jsonpath "$.messages"
# Validate empty history
[Asserts]
jsonpath "$.messages" count == 0
# Test 4: Post a message to the chat
POST http://localhost:8000/api/chats/{{chat_id}}/messages
Content-Type: application/json
{
"message": "Hello, this is a test message",
"model": "{{model}}"
}
HTTP 200
[Captures]
message_id: jsonpath "$.message_id"
status: jsonpath "$.status"
# Validate message posting
[Asserts]
jsonpath "$.status" == "queued"
jsonpath "$.message_id" != null
# Test 5: Stream the response (SSE)
GET http://localhost:8000/api/chats/{{chat_id}}/stream?message_id={{message_id}}
HTTP 200
[Asserts]
header "Content-Type" == "text/event-stream; charset=utf-8"
# Test 6: Verify chat history now contains messages
GET http://localhost:8000/api/chats/{{chat_id}}
HTTP 200
[Captures]
updated_messages: jsonpath "$.messages"
# Validate messages are stored
[Asserts]
jsonpath "$.messages" count == 2
jsonpath "$.messages[0].role" == "human"
jsonpath "$.messages[0].content" == "Hello, this is a test message"
jsonpath "$.messages[1].role" == "assistant"
# Test 7: Post another message to test multi-turn conversation
POST http://localhost:8000/api/chats/{{chat_id}}/messages
Content-Type: application/json
{
"message": "Can you tell me a joke?",
"model": "{{model}}"
}
HTTP 200
[Captures]
message_id2: jsonpath "$.message_id"
# Test 8: Stream second response
GET http://localhost:8000/api/chats/{{chat_id}}/stream?message_id={{message_id2}}
HTTP 200
# Test 9: Verify multi-turn conversation history
GET http://localhost:8000/api/chats/{{chat_id}}
HTTP 200
[Captures]
final_messages: jsonpath "$.messages"
# Validate 4 messages (2 human + 2 assistant)
[Asserts]
jsonpath "$.messages" count == 4
# Test 10: Error handling - Invalid model
POST http://localhost:8000/api/chats
Content-Type: application/json
{
"model": "invalid-model-name"
}
HTTP 400
[Asserts]
jsonpath "$.error" == "Unknown model"
# Test 11: Error handling - Chat not found
GET http://localhost:8000/api/chats/non-existent-chat-id
HTTP 404
[Asserts]
jsonpath "$.error" == "Not found"
# Test 12: Error handling - Invalid chat ID for messages
POST http://localhost:8000/api/chats/non-existent-chat-id/messages
Content-Type: application/json
{
"message": "This should fail",
"model": "qwen/qwen3-235b-a22b-2507"
}
HTTP 404
[Asserts]
jsonpath "$.error" == "Chat not found"
# Test 13: Error handling - Missing message in post
POST http://localhost:8000/api/chats/{{chat_id}}/messages
Content-Type: application/json
{
"model": "{{model}}"
}
HTTP 200
# Note: The backend seems to accept empty messages, so this might not fail
# Test 14: Create another chat with different model
POST http://localhost:8000/api/chats
Content-Type: application/json
{
"model": "openai/gpt-4.1"
}
HTTP 200
[Captures]
chat_id2: jsonpath "$.id"
model2: jsonpath "$.model"
# Test 15: Verify second chat has different ID
[Asserts]
variable "chat_id" != "chat_id2"
variable "model2" == "openai/gpt-4.1"