feat: migrate to typed messages, drop base64
Some checks failed
CI / Lint (pull_request) Failing after 58s
CI / Test (pull_request) Failing after 1m22s
CI / Notify (pull_request) Successful in 1s
CI / Release (pull_request) Has been skipped
CI / Docker Build & Push (pull_request) Has been skipped

- 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:
2026-02-20 07:10:43 -05:00
parent 609b44de83
commit 4175e2070c
5 changed files with 150 additions and 139 deletions

View File

@@ -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)
}
}