feat: migrate to typed messages, drop base64
- Switch OnMessage → OnTypedMessage with natsutil.Decode[messages.ChatRequest] - Return *messages.ChatResponse / *messages.ChatStreamChunk (not map[string]any) - Audio as raw []byte in msgpack (25% wire savings vs base64) - Remove strVal/boolVal/intVal helpers - Add .dockerignore, GOAMD64=v3 in Dockerfile - Update tests for typed structs (9 tests pass)
This commit is contained in:
63
e2e_test.go
63
e2e_test.go
@@ -9,6 +9,8 @@ import (
|
||||
"time"
|
||||
|
||||
"git.daviestechlabs.io/daviestechlabs/handler-base/clients"
|
||||
"git.daviestechlabs.io/daviestechlabs/handler-base/messages"
|
||||
"github.com/vmihailenco/msgpack/v5"
|
||||
)
|
||||
|
||||
// ────────────────────────────────────────────────────────────────────────────
|
||||
@@ -161,39 +163,38 @@ t.Error("expected timeout error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestChatPipeline_RequestBuilding(t *testing.T) {
|
||||
// Test the map construction logic from main.go's OnMessage.
|
||||
data := map[string]any{
|
||||
"request_id": "req-e2e-001",
|
||||
"user_id": "user-1",
|
||||
"message": "hello",
|
||||
"premium": true,
|
||||
"enable_rag": false,
|
||||
"enable_streaming": false,
|
||||
"system_prompt": "Be brief.",
|
||||
}
|
||||
func TestChatPipeline_TypedDecoding(t *testing.T) {
|
||||
// Verify typed struct decoding from msgpack (same path as OnTypedMessage).
|
||||
raw := map[string]any{
|
||||
"request_id": "req-e2e-001",
|
||||
"user_id": "user-1",
|
||||
"message": "hello",
|
||||
"premium": true,
|
||||
"enable_rag": false,
|
||||
"enable_streaming": false,
|
||||
"system_prompt": "Be brief.",
|
||||
}
|
||||
data, _ := msgpack.Marshal(raw)
|
||||
|
||||
requestID := strVal(data, "request_id", "unknown")
|
||||
userID := strVal(data, "user_id", "unknown")
|
||||
query := strVal(data, "message", "")
|
||||
premium := boolVal(data, "premium", false)
|
||||
enableRAG := boolVal(data, "enable_rag", premium)
|
||||
systemPrompt := strVal(data, "system_prompt", "")
|
||||
var req messages.ChatRequest
|
||||
if err := msgpack.Unmarshal(data, &req); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if requestID != "req-e2e-001" {
|
||||
t.Errorf("requestID = %q", requestID)
|
||||
}
|
||||
if userID != "user-1" {
|
||||
t.Errorf("userID = %q", userID)
|
||||
}
|
||||
if query != "hello" {
|
||||
t.Errorf("query = %q", query)
|
||||
}
|
||||
if enableRAG {
|
||||
t.Error("enable_rag=false should override premium=true")
|
||||
}
|
||||
if systemPrompt != "Be brief." {
|
||||
t.Errorf("systemPrompt = %q", systemPrompt)
|
||||
if req.RequestID != "req-e2e-001" {
|
||||
t.Errorf("RequestID = %q", req.RequestID)
|
||||
}
|
||||
if req.UserID != "user-1" {
|
||||
t.Errorf("UserID = %q", req.UserID)
|
||||
}
|
||||
if req.EffectiveQuery() != "hello" {
|
||||
t.Errorf("query = %q", req.EffectiveQuery())
|
||||
}
|
||||
if req.EnableRAG {
|
||||
t.Error("EnableRAG should be false")
|
||||
}
|
||||
if req.SystemPrompt != "Be brief." {
|
||||
t.Errorf("SystemPrompt = %q", req.SystemPrompt)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user