feat: migrate from msgpack to protobuf (handler-base v1.0.0)
- 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:
38
e2e_test.go
38
e2e_test.go
@@ -13,7 +13,7 @@ import (
|
||||
|
||||
"git.daviestechlabs.io/daviestechlabs/handler-base/clients"
|
||||
"git.daviestechlabs.io/daviestechlabs/handler-base/messages"
|
||||
"github.com/vmihailenco/msgpack/v5"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
// ────────────────────────────────────────────────────────────────────────────
|
||||
@@ -167,33 +167,33 @@ func TestChatPipeline_LLMTimeout(t *testing.T) {
|
||||
}
|
||||
|
||||
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.",
|
||||
// Verify typed struct decoding from proto (same path as OnTypedMessage).
|
||||
original := &messages.ChatRequest{
|
||||
RequestId: "req-e2e-001",
|
||||
UserId: "user-1",
|
||||
Message: "hello",
|
||||
Premium: true,
|
||||
EnableRag: false,
|
||||
EnableStreaming: false,
|
||||
SystemPrompt: "Be brief.",
|
||||
}
|
||||
data, _ := msgpack.Marshal(raw)
|
||||
data, _ := proto.Marshal(original)
|
||||
|
||||
var req messages.ChatRequest
|
||||
if err := msgpack.Unmarshal(data, &req); err != nil {
|
||||
if err := proto.Unmarshal(data, &req); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if req.RequestID != "req-e2e-001" {
|
||||
t.Errorf("RequestID = %q", req.RequestID)
|
||||
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.UserId != "user-1" {
|
||||
t.Errorf("UserID = %q", req.UserId)
|
||||
}
|
||||
if req.EffectiveQuery() != "hello" {
|
||||
t.Errorf("query = %q", req.EffectiveQuery())
|
||||
if messages.EffectiveQuery(&req) != "hello" {
|
||||
t.Errorf("query = %q", messages.EffectiveQuery(&req))
|
||||
}
|
||||
if req.EnableRAG {
|
||||
if req.EnableRag {
|
||||
t.Error("EnableRAG should be false")
|
||||
}
|
||||
if req.SystemPrompt != "Be brief." {
|
||||
|
||||
Reference in New Issue
Block a user