Files
Agent-System/internal/intent/plan_builder_test.go
weichenandCursor 9005766b62 test(intent): lock legacy multi-intent plan routing
Keep write combos and internal-chain summaries on the current TopIntent path so U2 shadow proposals cannot silently change production.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-15 23:07:46 +00:00

90 lines
2.9 KiB
Go

package intent_test
import (
"context"
"testing"
"chat-agent-system/internal/intent"
)
func TestLegacyIntentPlan_WriteComboStillDropped(t *testing.T) {
rec := intent.NewRecognizer()
res, err := rec.Recognize(context.Background(), "查一下相关法规,然后帮我生成报价单", nil)
if err != nil {
t.Fatalf("recognize: %v", err)
}
if res.IntentPlan != nil {
t.Fatalf("legacy production plan must stay nil for write combos, got %+v", res.IntentPlan)
}
if res.TopIntent == nil || res.TopIntent.Intent != intent.IntentQueryRegulations {
t.Fatalf("legacy TopIntent must remain the query, got %+v", res.TopIntent)
}
}
func TestLegacyIntentPlan_NoConnectorStaysSingle(t *testing.T) {
rec := intent.NewRecognizer()
res, err := rec.Recognize(context.Background(), "请查询相关法规并总结要点", nil)
if err != nil {
t.Fatalf("recognize: %v", err)
}
if res.IntentPlan != nil {
t.Fatalf("internal chain must not create a legacy multi-intent plan, got %+v", res.IntentPlan)
}
}
func TestLimitedIntentPlan_QueryThenQuery(t *testing.T) {
rec := intent.NewRecognizer()
res, err := rec.Recognize(context.Background(), "查一下项目风险,然后查相关法规", nil)
if err != nil {
t.Fatalf("recognize: %v", err)
}
if res.IntentPlan == nil {
t.Fatal("expected intent_plan for query+query combination")
}
if len(res.IntentPlan.Steps) != 2 {
t.Fatalf("expected 2 steps, got %d", len(res.IntentPlan.Steps))
}
if res.IntentPlan.Steps[0].Frame.Goal != intent.GoalQuery {
t.Errorf("step1 goal want query got %s", res.IntentPlan.Steps[0].Frame.Goal)
}
if res.IntentPlan.Steps[1].Frame.Goal != intent.GoalQuery {
t.Errorf("step2 goal want query got %s", res.IntentPlan.Steps[1].Frame.Goal)
}
}
func TestSupplementSubtype_InV2Frame(t *testing.T) {
rec := intent.NewRecognizer()
res, err := rec.Recognize(context.Background(), "客户反馈附件已上传,请入库", nil)
if err != nil {
t.Fatalf("recognize: %v", err)
}
if res.IntentFrameV2 == nil || res.IntentFrameV2.Subtype != "attach" {
t.Errorf("expected subtype attach, got %+v", res.IntentFrameV2)
}
}
func TestRunMatcher_ResumeRequiresClarification(t *testing.T) {
rec := intent.NewRecognizer()
res, err := rec.Recognize(context.Background(), "继续上次失败的任务", nil)
if err != nil {
t.Fatalf("recognize: %v", err)
}
if res.TopIntent.Intent != intent.IntentRunResume {
t.Fatalf("expected RUN_RESUME, got %s", res.TopIntent.Intent)
}
if !res.RequiresClarifying && res.TopIntent.ClarificationQuestion == "" {
t.Error("expected clarification when work_dir missing")
}
}
func TestRunMatcher_StatusQuery(t *testing.T) {
rec := intent.NewRecognizer()
res, err := rec.Recognize(context.Background(), "上次任务运行状态怎么样了?", nil)
if err != nil {
t.Fatalf("recognize: %v", err)
}
if res.TopIntent.Intent != intent.IntentRunStatusQuery {
t.Fatalf("expected RUN_STATUS_QUERY, got %s", res.TopIntent.Intent)
}
}