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

- Switch OnMessage → OnTypedMessage with natsutil.Decode[messages.VoiceRequest]
- Return *messages.VoiceResponse with raw []byte audio (no base64)
- Use messages.DocumentSource for RAG sources
- Remove strVal/boolVal helpers
- Add .dockerignore, GOAMD64=v3 in Dockerfile
- Update tests for typed structs (7 tests pass)
This commit is contained in:
2026-02-20 07:10:51 -05:00
parent f41198d8f2
commit 8ef0c93e47
4 changed files with 117 additions and 82 deletions

View File

@@ -2,25 +2,59 @@ package main
import (
"testing"
"git.daviestechlabs.io/daviestechlabs/handler-base/messages"
"git.daviestechlabs.io/daviestechlabs/handler-base/natsutil"
"github.com/vmihailenco/msgpack/v5"
)
func TestStrVal(t *testing.T) {
m := map[string]any{"key": "value"}
if got := strVal(m, "key", ""); got != "value" {
t.Errorf("strVal(key) = %q", got)
func TestVoiceRequestDecode(t *testing.T) {
req := messages.VoiceRequest{
RequestID: "req-123",
Audio: []byte{0x01, 0x02, 0x03},
Language: "en",
Collection: "docs",
}
if got := strVal(m, "missing", "def"); got != "def" {
t.Errorf("strVal(missing) = %q", got)
data, err := msgpack.Marshal(&req)
if err != nil {
t.Fatal(err)
}
decoded, err := natsutil.Decode[messages.VoiceRequest](data)
if err != nil {
t.Fatal(err)
}
if decoded.RequestID != "req-123" {
t.Errorf("RequestID = %q", decoded.RequestID)
}
if len(decoded.Audio) != 3 {
t.Errorf("Audio len = %d", len(decoded.Audio))
}
}
func TestBoolVal(t *testing.T) {
m := map[string]any{"flag": true}
if got := boolVal(m, "flag", false); !got {
t.Error("expected true")
func TestVoiceResponseRoundtrip(t *testing.T) {
resp := messages.VoiceResponse{
RequestID: "req-456",
Response: "It is sunny today.",
Audio: make([]byte, 8000),
Transcription: "What is the weather?",
Sources: []messages.DocumentSource{{Text: "weather doc", Score: 0.9}},
}
if got := boolVal(m, "missing", false); got {
t.Error("expected false fallback")
data, err := msgpack.Marshal(&resp)
if err != nil {
t.Fatal(err)
}
var got messages.VoiceResponse
if err := msgpack.Unmarshal(data, &got); err != nil {
t.Fatal(err)
}
if got.Response != "It is sunny today." {
t.Errorf("Response = %q", got.Response)
}
if len(got.Audio) != 8000 {
t.Errorf("Audio len = %d", len(got.Audio))
}
if len(got.Sources) != 1 || got.Sources[0].Text != "weather doc" {
t.Errorf("Sources = %v", got.Sources)
}
}