feat: migrate from msgpack to protobuf (handler-base v1.0.0)
Some checks failed
CI / Lint (push) Failing after 2m49s
CI / Test (push) Successful in 3m36s
CI / Notify (push) Has been cancelled
CI / Docker Build & Push (push) Has been cancelled
CI / Release (push) Has been cancelled

- Replace msgpack encoding with protobuf wire format
- Update field names to proto convention (UserId, RequestId, EnableRag, etc.)
- Use messages.EffectiveQuery() standalone function
- Cast TopK to int32 for proto compatibility
- Rewrite tests for proto round-trips
This commit is contained in:
2026-02-21 15:30:04 -05:00
parent 87d0545d2c
commit e2176331c8
5 changed files with 62 additions and 63 deletions

View File

@@ -5,28 +5,31 @@ import (
"testing"
"git.daviestechlabs.io/daviestechlabs/handler-base/messages"
"github.com/vmihailenco/msgpack/v5"
"google.golang.org/protobuf/proto"
)
func TestChatRequestDecode(t *testing.T) {
// Verify a msgpack-encoded map decodes cleanly into typed struct.
raw := map[string]any{
"request_id": "req-1",
"user_id": "user-1",
"message": "hello",
"premium": true,
"top_k": 10,
// Verify a proto-encoded struct round-trips cleanly.
original := &messages.ChatRequest{
RequestId: "req-1",
UserId: "user-1",
Message: "hello",
Premium: true,
TopK: 10,
}
data, _ := msgpack.Marshal(raw)
var req messages.ChatRequest
if err := msgpack.Unmarshal(data, &req); err != nil {
data, err := proto.Marshal(original)
if err != nil {
t.Fatal(err)
}
if req.RequestID != "req-1" {
t.Errorf("RequestID = %q", req.RequestID)
var req messages.ChatRequest
if err := proto.Unmarshal(data, &req); err != nil {
t.Fatal(err)
}
if req.EffectiveQuery() != "hello" {
t.Errorf("EffectiveQuery = %q", req.EffectiveQuery())
if req.RequestId != "req-1" {
t.Errorf("RequestID = %q", req.RequestId)
}
if messages.EffectiveQuery(&req) != "hello" {
t.Errorf("EffectiveQuery = %q", messages.EffectiveQuery(&req))
}
if !req.Premium {
t.Error("Premium should be true")
@@ -38,20 +41,20 @@ func TestChatRequestDecode(t *testing.T) {
func TestChatResponseRoundtrip(t *testing.T) {
resp := &messages.ChatResponse{
UserID: "user-1",
UserId: "user-1",
Response: "answer",
Success: true,
Audio: []byte{0x01, 0x02, 0x03},
}
data, err := msgpack.Marshal(resp)
data, err := proto.Marshal(resp)
if err != nil {
t.Fatal(err)
}
var decoded messages.ChatResponse
if err := msgpack.Unmarshal(data, &decoded); err != nil {
if err := proto.Unmarshal(data, &decoded); err != nil {
t.Fatal(err)
}
if decoded.UserID != "user-1" || !decoded.Success {
if decoded.UserId != "user-1" || !decoded.Success {
t.Errorf("decoded = %+v", decoded)
}
if len(decoded.Audio) != 3 {