feat: wire coverage support notifications
This commit is contained in:
@@ -25,6 +25,14 @@ func NewService(repo Repository) (*Service, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ObserveSucceededTurn adapts Service to the QA succeeded-turn observer.
|
||||
// The decision is persisted durably before QA returns; callers decide how to
|
||||
// report the error without changing the successful QA result.
|
||||
func (s *Service) ObserveSucceededTurn(ctx context.Context, turn core.Turn) error {
|
||||
_, err := s.EvaluateAndPersist(ctx, turn)
|
||||
return err
|
||||
}
|
||||
|
||||
// EvaluateAndPersist evaluates a turn and persists the resulting decision.
|
||||
// For uncovered verdicts the Repository atomically creates a pending
|
||||
// support case. The operation is idempotent — replaying the same
|
||||
|
||||
@@ -162,6 +162,30 @@ func TestService_EvaluateAndPersist_PropagatesRepoError(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestService_ObserveSucceededTurnPersistsDecision(t *testing.T) {
|
||||
repo := &mockRepo{}
|
||||
s, err := NewService(repo)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
turn := core.Turn{
|
||||
ID: "turn-observed",
|
||||
TenantKey: "tenant",
|
||||
Channel: "dingtalk",
|
||||
Status: "succeeded",
|
||||
Answer: "正常回答",
|
||||
References: []core.Reference{
|
||||
{ID: "r1", Score: 0.5},
|
||||
},
|
||||
}
|
||||
if err := s.ObserveSucceededTurn(context.Background(), turn); err != nil {
|
||||
t.Fatalf("ObserveSucceededTurn: %v", err)
|
||||
}
|
||||
if len(repo.saved) != 1 || repo.saved[0].TurnID != "turn-observed" {
|
||||
t.Fatalf("saved=%+v, want turn-observed", repo.saved)
|
||||
}
|
||||
}
|
||||
|
||||
func TestService_EvaluateAndPersist_DecisionHasEvaluatorVersion(t *testing.T) {
|
||||
repo := &mockRepo{}
|
||||
s, _ := NewService(repo)
|
||||
|
||||
Reference in New Issue
Block a user