feat: migrate to typed messages, drop base64
- 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:
49
e2e_test.go
49
e2e_test.go
@@ -2,7 +2,6 @@ package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
@@ -11,6 +10,9 @@ import (
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"git.daviestechlabs.io/daviestechlabs/handler-base/messages"
|
||||
"github.com/vmihailenco/msgpack/v5"
|
||||
)
|
||||
|
||||
// ────────────────────────────────────────────────────────────────────────────
|
||||
@@ -63,26 +65,29 @@ func TestSynthesisE2E_StreamChunks(t *testing.T) {
|
||||
chunkIdx := i / chunkSize
|
||||
isLast := end >= len(audioBytes)
|
||||
|
||||
// Verify chunk message shape
|
||||
msg := map[string]any{
|
||||
"session_id": "test-session",
|
||||
"chunk_index": chunkIdx,
|
||||
"total_chunks": totalChunks,
|
||||
"audio_b64": base64.StdEncoding.EncodeToString(chunk),
|
||||
"is_last": isLast,
|
||||
"sample_rate": 24000,
|
||||
// Verify typed chunk struct
|
||||
msg := messages.TTSAudioChunk{
|
||||
SessionID: "test-session",
|
||||
ChunkIndex: chunkIdx,
|
||||
TotalChunks: totalChunks,
|
||||
Audio: chunk,
|
||||
IsLast: isLast,
|
||||
SampleRate: 24000,
|
||||
}
|
||||
|
||||
// Round-trip through JSON
|
||||
data, _ := json.Marshal(msg)
|
||||
var decoded map[string]any
|
||||
json.Unmarshal(data, &decoded)
|
||||
// Round-trip through msgpack
|
||||
data, _ := msgpack.Marshal(&msg)
|
||||
var decoded messages.TTSAudioChunk
|
||||
msgpack.Unmarshal(data, &decoded)
|
||||
|
||||
if decoded["session_id"] != "test-session" {
|
||||
t.Errorf("chunk %d: session = %v", chunkIdx, decoded["session_id"])
|
||||
if decoded.SessionID != "test-session" {
|
||||
t.Errorf("chunk %d: session = %v", chunkIdx, decoded.SessionID)
|
||||
}
|
||||
if decoded["is_last"] != isLast {
|
||||
t.Errorf("chunk %d: is_last = %v, want %v", chunkIdx, decoded["is_last"], isLast)
|
||||
if decoded.IsLast != isLast {
|
||||
t.Errorf("chunk %d: is_last = %v, want %v", chunkIdx, decoded.IsLast, isLast)
|
||||
}
|
||||
if len(decoded.Audio) != len(chunk) {
|
||||
t.Errorf("chunk %d: audio len = %d, want %d", chunkIdx, len(decoded.Audio), len(chunk))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -260,8 +265,14 @@ func BenchmarkAudioChunking(b *testing.B) {
|
||||
end = len(audioBytes)
|
||||
}
|
||||
chunk := audioBytes[i:end]
|
||||
_ = base64.StdEncoding.EncodeToString(chunk)
|
||||
_ = totalChunks
|
||||
msg := &messages.TTSAudioChunk{
|
||||
SessionID: "bench",
|
||||
ChunkIndex: i / chunkSize,
|
||||
TotalChunks: totalChunks,
|
||||
Audio: chunk,
|
||||
SampleRate: 24000,
|
||||
}
|
||||
msgpack.Marshal(msg)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user