feat: add message audit foundation
This commit is contained in:
@@ -46,6 +46,7 @@ type QARequest struct {
|
||||
SenderName string
|
||||
Query string
|
||||
Images []ImageInput
|
||||
MessageType string
|
||||
}
|
||||
|
||||
type Reference struct {
|
||||
@@ -84,6 +85,16 @@ type Turn struct {
|
||||
SessionKey string
|
||||
WeKnoraSessionID string
|
||||
WeKnoraRequestID string
|
||||
AgentID string
|
||||
ConversationType ConversationType
|
||||
ExternalChatID string
|
||||
ExternalUserID string
|
||||
SenderName string
|
||||
MessageType string
|
||||
ActorID string
|
||||
ConversationID string
|
||||
RequestMessageID string
|
||||
AnswerMessageID string
|
||||
Question string
|
||||
Answer string
|
||||
References []Reference
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestTurnHasAuditFields(t *testing.T) {
|
||||
// Verify Turn struct has all the new audit fields from B1.1
|
||||
turn := Turn{
|
||||
AgentID: "agent-1",
|
||||
ConversationType: ConversationDirect,
|
||||
ExternalChatID: "chat-1",
|
||||
ExternalUserID: "user-1",
|
||||
SenderName: "Alice",
|
||||
MessageType: "text",
|
||||
ActorID: "actor-1",
|
||||
ConversationID: "conv-1",
|
||||
RequestMessageID: "req-msg-1",
|
||||
AnswerMessageID: "ans-msg-1",
|
||||
}
|
||||
|
||||
if turn.AgentID != "agent-1" {
|
||||
t.Error("Turn must have AgentID field")
|
||||
}
|
||||
if turn.ConversationType != ConversationDirect {
|
||||
t.Error("Turn must have ConversationType field")
|
||||
}
|
||||
if turn.ExternalChatID != "chat-1" {
|
||||
t.Error("Turn must have ExternalChatID field")
|
||||
}
|
||||
if turn.ExternalUserID != "user-1" {
|
||||
t.Error("Turn must have ExternalUserID field")
|
||||
}
|
||||
if turn.SenderName != "Alice" {
|
||||
t.Error("Turn must have SenderName field")
|
||||
}
|
||||
if turn.MessageType != "text" {
|
||||
t.Error("Turn must have MessageType field")
|
||||
}
|
||||
if turn.ActorID != "actor-1" {
|
||||
t.Error("Turn must have ActorID field")
|
||||
}
|
||||
if turn.ConversationID != "conv-1" {
|
||||
t.Error("Turn must have ConversationID field")
|
||||
}
|
||||
if turn.RequestMessageID != "req-msg-1" {
|
||||
t.Error("Turn must have RequestMessageID field")
|
||||
}
|
||||
if turn.AnswerMessageID != "ans-msg-1" {
|
||||
t.Error("Turn must have AnswerMessageID field")
|
||||
}
|
||||
}
|
||||
|
||||
func TestQARequestHasMessageType(t *testing.T) {
|
||||
req := QARequest{
|
||||
TenantKey: "tenant",
|
||||
Channel: "dingtalk",
|
||||
ConversationType: ConversationDirect,
|
||||
ExternalUserID: "user-1",
|
||||
ExternalMessageID: "msg-1",
|
||||
Query: "hello",
|
||||
MessageType: "text",
|
||||
}
|
||||
|
||||
if req.MessageType != "text" {
|
||||
t.Error("QARequest must have MessageType field")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMessageTypeDefaults(t *testing.T) {
|
||||
// MessageType is optional; empty string should be valid
|
||||
req := QARequest{
|
||||
TenantKey: "tenant",
|
||||
Channel: "dingtalk",
|
||||
ConversationType: ConversationDirect,
|
||||
ExternalUserID: "user-1",
|
||||
ExternalMessageID: "msg-1",
|
||||
Query: "hello",
|
||||
}
|
||||
|
||||
if req.MessageType != "" {
|
||||
t.Error("QARequest.MessageType should default to empty string")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTurnNoDataURITags(t *testing.T) {
|
||||
// Verify Turn struct has no DataURI field or tag
|
||||
turn := Turn{}
|
||||
raw, err := json.Marshal(turn)
|
||||
if err != nil {
|
||||
t.Fatalf("marshal Turn: %v", err)
|
||||
}
|
||||
s := string(raw)
|
||||
for _, forbidden := range []string{"data_uri", "DataURI", "dataURI"} {
|
||||
if strings.Contains(s, forbidden) {
|
||||
t.Errorf("Turn JSON must not contain %q: %s", forbidden, s)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user