feat: add FAQ uncovered workflow

This commit is contained in:
姚章浩
2026-07-27 11:54:34 +08:00
parent e582d851a4
commit aa0513eb59
28 changed files with 1319 additions and 274 deletions
+8 -8
View File
@@ -99,14 +99,14 @@ func (b *blockingNotifier) Send(ctx context.Context, notif SupportNotification)
func makePendingCase(id string, attempts int) PendingSupportCase {
return PendingSupportCase{
SupportNotification: SupportNotification{
CaseID: id,
Question: "test question " + id,
Answer: "test answer " + id,
SenderName: "Sender " + id,
Channel: "dingtalk",
ConversationType: core.ConversationGroup,
ReferenceCount: 1,
TopScore: 0.5,
CaseID: id,
Question: "test question " + id,
SenderName: "Sender " + id,
Channel: "dingtalk",
ConversationType: core.ConversationGroup,
AskedAt: time.Unix(1, 0),
PreviousQuestions: []string{"previous question"},
FAQRecordID: "record-" + id,
},
Attempts: attempts,
}
+8 -8
View File
@@ -14,14 +14,14 @@ import (
// notification. It must never contain tokens, webhooks, raw API responses,
// raw error text, reference bodies, or group IDs.
type SupportNotification struct {
CaseID string
Question string
Answer string
SenderName string
Channel string
ConversationType core.ConversationType
ReferenceCount int
TopScore float64
CaseID string
Question string
SenderName string
Channel string
ConversationType core.ConversationType
AskedAt time.Time
PreviousQuestions []string
FAQRecordID string
}
// PendingSupportCase holds the data needed to send a notification for a
+31 -41
View File
@@ -2,68 +2,58 @@
package coverage
import (
"reflect"
"testing"
"time"
"gitea.zheromiku.top/Weknora/dobotai-platform/internal/core"
)
func TestSupportNotificationFields(t *testing.T) {
// Verify that SupportNotification is a plain data struct with only the
// safe fields listed in the spec. Token, webhook, raw IDs, raw responses,
// and reference bodies must NOT be present.
func TestSupportNotificationCarriesCustomerQuestionContext(t *testing.T) {
askedAt := time.Date(2026, 7, 24, 10, 16, 35, 0, time.FixedZone("CST", 8*60*60))
notif := SupportNotification{
CaseID: "case-001",
Question: "怎么配置钉钉机器人?",
Answer: "进入钉钉开放平台...",
Question: "Nova5I具体支持哪些通信协议?",
SenderName: "张三",
Channel: "dingtalk",
ConversationType: core.ConversationGroup,
ReferenceCount: 3,
TopScore: 0.95,
AskedAt: askedAt,
PreviousQuestions: []string{
"Nova5I如何配置Modbus TCP?",
"Nova5I是否支持EtherCAT?",
},
FAQRecordID: "record-001",
}
if notif.CaseID != "case-001" {
t.Fatalf("CaseID = %q, want case-001", notif.CaseID)
if notif.Question != "Nova5I具体支持哪些通信协议?" || notif.SenderName != "张三" {
t.Fatalf("current question context mismatch: %+v", notif)
}
if notif.Question != "怎么配置钉钉机器人?" {
t.Fatalf("Question = %q", notif.Question)
if !notif.AskedAt.Equal(askedAt) {
t.Fatalf("AskedAt = %v, want %v", notif.AskedAt, askedAt)
}
if notif.Answer != "进入钉钉开放平台..." {
t.Fatalf("Answer = %q", notif.Answer)
if len(notif.PreviousQuestions) != 2 || notif.PreviousQuestions[0] != "Nova5I如何配置Modbus TCP?" {
t.Fatalf("PreviousQuestions = %#v", notif.PreviousQuestions)
}
if notif.SenderName != "张三" {
t.Fatalf("SenderName = %q", notif.SenderName)
if notif.FAQRecordID != "record-001" {
t.Fatalf("FAQRecordID = %q", notif.FAQRecordID)
}
if notif.Channel != "dingtalk" {
t.Fatalf("Channel = %q", notif.Channel)
}
if notif.ConversationType != core.ConversationGroup {
t.Fatalf("ConversationType = %q", notif.ConversationType)
}
if notif.ReferenceCount != 3 {
t.Fatalf("ReferenceCount = %d", notif.ReferenceCount)
}
if notif.TopScore != 0.95 {
t.Fatalf("TopScore = %f", notif.TopScore)
}
func TestSupportNotificationExcludesAnswerAndRetrievalDiagnostics(t *testing.T) {
typ := reflect.TypeOf(SupportNotification{})
for _, forbidden := range []string{"Answer", "ReferenceCount", "TopScore", "References", "Confidence"} {
if _, ok := typ.FieldByName(forbidden); ok {
t.Errorf("SupportNotification must not expose %s", forbidden)
}
}
}
func TestSupportNotificationEmptyValues(t *testing.T) {
// Zero-value notification should be safe to render (no panic).
notif := SupportNotification{}
if notif.CaseID != "" {
t.Fatalf("expected empty CaseID")
if notif.CaseID != "" || notif.Question != "" || notif.FAQRecordID != "" {
t.Fatalf("expected safe zero value: %+v", notif)
}
if notif.Question != "" {
t.Fatalf("expected empty Question")
}
if notif.Answer != "" {
t.Fatalf("expected empty Answer")
}
if notif.ReferenceCount != 0 {
t.Fatalf("expected zero ReferenceCount")
}
if notif.TopScore != 0 {
t.Fatalf("expected zero TopScore")
if len(notif.PreviousQuestions) != 0 || !notif.AskedAt.IsZero() {
t.Fatalf("expected empty history and time: %+v", notif)
}
}