Capture trigger_user HITL expectations from dialogue adjudication (previously dropped at the bizdev call site), project them as chat confirmation cards via taskrun OnTerminal (exactly-once), arm the session PendingExpectation, and handle confirm_context_fact hits through the supplement-info blackboard path. Decline (纠正) guides the user to state the correct fact.
61 lines
2.0 KiB
Go
61 lines
2.0 KiB
Go
package bizdev
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"chat-agent-system/internal/intent"
|
|
)
|
|
|
|
func TestAppendContextConflictCards_CapsAndDedupes(t *testing.T) {
|
|
mk := func(id, key string) *intent.PendingExpectation {
|
|
return &intent.PendingExpectation{
|
|
ExpectationID: id,
|
|
TargetAction: "confirm_context_fact",
|
|
Payload: map[string]string{"fact_key": key, "winning_value": "v-" + key},
|
|
Prompt: "p-" + key,
|
|
ContextSnippet: "s-" + key,
|
|
}
|
|
}
|
|
out := &TaskRunResult{}
|
|
appendContextConflictCards(out, TaskRunRequest{}, []*intent.PendingExpectation{
|
|
mk("e1", "device_type"),
|
|
mk("e2", "device_type"), // duplicate fact key
|
|
mk("e3", "budget"),
|
|
nil,
|
|
{ExpectationID: "other", TargetAction: "other_action"}, // non-conflict expectation
|
|
})
|
|
if len(out.PendingContextConflicts) != 2 {
|
|
t.Fatalf("expected 2 cards after dedupe, got %d", len(out.PendingContextConflicts))
|
|
}
|
|
if out.PendingContextConflicts[0].FactKey != "device_type" || out.PendingContextConflicts[1].FactKey != "budget" {
|
|
t.Fatalf("unexpected cards: %+v", out.PendingContextConflicts)
|
|
}
|
|
}
|
|
|
|
func TestContextConflictExpectation_Roundtrip(t *testing.T) {
|
|
card := ContextConflictCard{
|
|
ExpectationID: "ctx_conflict_run1_device_type",
|
|
FactKey: "device_type",
|
|
WinningValue: "一次性使用采血管",
|
|
Prompt: "对话与现有事实对「device_type」说法不一致。",
|
|
Snippet: "同级时间相近且无明确证据,需人工确认",
|
|
}
|
|
exp := ContextConflictExpectation(card)
|
|
if exp == nil {
|
|
t.Fatal("expected expectation")
|
|
}
|
|
if exp.TargetAction != "confirm_context_fact" || exp.AffirmativeWord != "确认" || exp.DeclineWord != "纠正" {
|
|
t.Fatalf("unexpected expectation shape: %+v", exp)
|
|
}
|
|
if exp.Payload["fact_key"] != "device_type" || exp.Payload["winning_value"] != "一次性使用采血管" {
|
|
t.Fatalf("payload mismatch: %+v", exp.Payload)
|
|
}
|
|
if exp.ExpiresAt.Before(time.Now()) {
|
|
t.Fatal("expectation must not be expired at creation")
|
|
}
|
|
if ContextConflictExpectation(ContextConflictCard{}) != nil {
|
|
t.Fatal("empty card must return nil")
|
|
}
|
|
}
|