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

- Decode TTSRequest via natsutil.Decode[messages.TTSRequest]
- Stream audio as raw bytes via messages.TTSAudioChunk (no base64)
- Non-stream response uses messages.TTSFullResponse
- Status updates use messages.TTSStatus
- Voice list/refresh use messages.TTSVoiceListResponse/TTSVoiceRefreshResponse
- Registry returns []messages.TTSVoiceInfo (not []map[string]any)
- Remove strVal/boolVal helpers
- Add .dockerignore, GOAMD64=v3 in Dockerfile
- Update tests for typed structs (13 tests pass)
This commit is contained in:
2026-02-20 07:11:13 -05:00
parent b8d9a277c5
commit 85b481b6c4
5 changed files with 138 additions and 90 deletions

View File

@@ -8,6 +8,10 @@ import (
"path/filepath"
"strings"
"testing"
"git.daviestechlabs.io/daviestechlabs/handler-base/messages"
"git.daviestechlabs.io/daviestechlabs/handler-base/natsutil"
"github.com/vmihailenco/msgpack/v5"
)
func TestVoiceRegistryRefresh(t *testing.T) {
@@ -100,20 +104,58 @@ func TestSynthesizeHTTP(t *testing.T) {
}
}
func TestHelperFunctions(t *testing.T) {
m := map[string]any{"text": "hello", "stream": true, "count": 42}
func TestTTSRequestDecode(t *testing.T) {
req := messages.TTSRequest{
Text: "hello world",
Speaker: "custom-en",
Language: "en",
Stream: true,
}
data, err := msgpack.Marshal(&req)
if err != nil {
t.Fatal(err)
}
decoded, err := natsutil.Decode[messages.TTSRequest](data)
if err != nil {
t.Fatal(err)
}
if decoded.Text != "hello world" {
t.Errorf("Text = %q", decoded.Text)
}
if decoded.Speaker != "custom-en" {
t.Errorf("Speaker = %q", decoded.Speaker)
}
if !decoded.Stream {
t.Error("Stream should be true")
}
}
if got := strVal(m, "text", ""); got != "hello" {
t.Errorf("strVal(text) = %q", got)
func TestTTSAudioChunkRoundtrip(t *testing.T) {
chunk := messages.TTSAudioChunk{
SessionID: "sess-001",
ChunkIndex: 0,
TotalChunks: 2,
Audio: make([]byte, 32768),
IsLast: false,
Timestamp: 1234567890,
SampleRate: 24000,
}
if got := strVal(m, "missing", "def"); got != "def" {
t.Errorf("strVal(missing) = %q", got)
data, err := msgpack.Marshal(&chunk)
if err != nil {
t.Fatal(err)
}
if got := boolVal(m, "stream", false); !got {
t.Errorf("boolVal(stream) = %v", got)
var got messages.TTSAudioChunk
if err := msgpack.Unmarshal(data, &got); err != nil {
t.Fatal(err)
}
if got := boolVal(m, "missing", true); !got {
t.Errorf("boolVal(missing) = %v", got)
if got.SessionID != "sess-001" {
t.Errorf("SessionID = %q", got.SessionID)
}
if len(got.Audio) != 32768 {
t.Errorf("Audio len = %d", len(got.Audio))
}
if got.SampleRate != 24000 {
t.Errorf("SampleRate = %d", got.SampleRate)
}
}