This commit is contained in:
lpf
2026-02-19 10:38:59 +08:00
parent abc6d1e4a6
commit ed72c6ac44
2 changed files with 304 additions and 318 deletions

View File

@@ -2,7 +2,6 @@ package agent
import (
"testing"
"time"
"clawgo/pkg/bus"
)
@@ -27,118 +26,15 @@ func TestParseTaskExecutionDirectives_Default(t *testing.T) {
}
}
func TestParseAutoLearnInterval(t *testing.T) {
d, err := parseAutoLearnInterval("5m")
if err != nil {
t.Fatalf("unexpected error: %v", err)
func TestClassifyConfirmationReply(t *testing.T) {
if ok, confident := classifyConfirmationReply("yes"); !confident || !ok {
t.Fatalf("expected yes to confirm")
}
if d != 5*time.Minute {
t.Fatalf("unexpected duration: %s", d)
if ok, confident := classifyConfirmationReply("取消"); !confident || ok {
t.Fatalf("expected cancel to reject")
}
d, err = parseAutoLearnInterval("2")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if d != 2*time.Minute {
t.Fatalf("unexpected duration: %s", d)
}
}
func TestParseAutoLearnInterval_Invalid(t *testing.T) {
if _, err := parseAutoLearnInterval("oops"); err == nil {
t.Fatalf("expected error")
}
}
func TestParseAutoLearnIntent_FallbackCommand(t *testing.T) {
intent, ok := parseAutoLearnIntent("autolearn start 5m")
if !ok {
t.Fatalf("expected intent")
}
if intent.action != "start" {
t.Fatalf("unexpected action: %s", intent.action)
}
if intent.interval == nil || *intent.interval != 5*time.Minute {
t.Fatalf("unexpected interval: %v", intent.interval)
}
}
func TestParseAutoLearnIntent_StopFallbackCommand(t *testing.T) {
intent, ok := parseAutoLearnIntent("autolearn stop")
if !ok {
t.Fatalf("expected intent")
}
if intent.action != "stop" {
t.Fatalf("unexpected action: %s", intent.action)
}
}
func TestParseAutoLearnIntent_NoNaturalLanguageFallback(t *testing.T) {
if _, ok := parseAutoLearnIntent("please start auto learning"); ok {
t.Fatalf("expected no fallback match")
}
}
func TestParseAutonomyIntent_FallbackCommand(t *testing.T) {
intent, ok := parseAutonomyIntent("autonomy start 15m log clustering")
if !ok {
t.Fatalf("expected intent")
}
if intent.action != "start" {
t.Fatalf("unexpected action: %s", intent.action)
}
if intent.idleInterval == nil || *intent.idleInterval != 15*time.Minute {
t.Fatalf("unexpected interval: %v", intent.idleInterval)
}
if intent.focus != "log clustering" {
t.Fatalf("unexpected focus: %q", intent.focus)
}
}
func TestParseAutonomyIntent_StopFallbackCommand(t *testing.T) {
intent, ok := parseAutonomyIntent("autonomy stop")
if !ok {
t.Fatalf("expected intent")
}
if intent.action != "stop" {
t.Fatalf("unexpected action: %s", intent.action)
}
}
func TestParseAutonomyIntent_StatusFallbackCommand(t *testing.T) {
intent, ok := parseAutonomyIntent("autonomy status")
if !ok {
t.Fatalf("expected intent")
}
if intent.action != "status" {
t.Fatalf("unexpected action: %s", intent.action)
}
}
func TestParseAutonomyIdleInterval(t *testing.T) {
d, err := parseAutonomyIdleInterval("45m")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if d != 45*time.Minute {
t.Fatalf("unexpected duration: %s", d)
}
}
func TestParseAutonomyIntent_NoNaturalLanguageFallback(t *testing.T) {
if intent, ok := parseAutonomyIntent("please run this task automatically"); ok {
t.Fatalf("expected no intent, got: %+v", intent)
}
}
func TestParseAutonomyIntent_ClearFocusFallbackCommand(t *testing.T) {
intent, ok := parseAutonomyIntent("autonomy clear_focus")
if !ok {
t.Fatalf("expected intent")
}
if intent.action != "clear_focus" {
t.Fatalf("unexpected action: %s", intent.action)
if _, confident := classifyConfirmationReply("继续处理日志问题,不是这个"); confident {
t.Fatalf("expected non-confirmation sentence to be non-confident")
}
}