mirror of
https://github.com/YspCoder/clawgo.git
synced 2026-04-28 02:37:28 +08:00
fix auto
This commit is contained in:
@@ -15,16 +15,6 @@ func TestParseTaskExecutionDirectives_RunCommand(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseTaskExecutionDirectives_NaturalLanguage(t *testing.T) {
|
||||
d := parseTaskExecutionDirectives("你可以自动运行任务:整理日志,但是每到一个阶段给我报告一下任务完成情况")
|
||||
if d.task != "整理日志" {
|
||||
t.Fatalf("unexpected task: %q", d.task)
|
||||
}
|
||||
if !d.stageReport {
|
||||
t.Fatalf("expected stage report enabled")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseTaskExecutionDirectives_Default(t *testing.T) {
|
||||
d := parseTaskExecutionDirectives("帮我看看今天的日志异常")
|
||||
if d.task != "帮我看看今天的日志异常" {
|
||||
@@ -59,8 +49,8 @@ func TestParseAutoLearnInterval_Invalid(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseAutoLearnIntent_StartNaturalLanguage(t *testing.T) {
|
||||
intent, ok := parseAutoLearnIntent("请开始自动学习,每5分钟执行一轮")
|
||||
func TestParseAutoLearnIntent_FallbackCommand(t *testing.T) {
|
||||
intent, ok := parseAutoLearnIntent("autolearn start 5m")
|
||||
if !ok {
|
||||
t.Fatalf("expected intent")
|
||||
}
|
||||
@@ -72,8 +62,8 @@ func TestParseAutoLearnIntent_StartNaturalLanguage(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseAutoLearnIntent_StopNaturalLanguage(t *testing.T) {
|
||||
intent, ok := parseAutoLearnIntent("先暂停自动学习")
|
||||
func TestParseAutoLearnIntent_StopFallbackCommand(t *testing.T) {
|
||||
intent, ok := parseAutoLearnIntent("autolearn stop")
|
||||
if !ok {
|
||||
t.Fatalf("expected intent")
|
||||
}
|
||||
@@ -82,18 +72,14 @@ func TestParseAutoLearnIntent_StopNaturalLanguage(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseAutoLearnIntent_StatusNaturalLanguage(t *testing.T) {
|
||||
intent, ok := parseAutoLearnIntent("帮我看下自动学习状态")
|
||||
if !ok {
|
||||
t.Fatalf("expected intent")
|
||||
}
|
||||
if intent.action != "status" {
|
||||
t.Fatalf("unexpected action: %s", intent.action)
|
||||
func TestParseAutoLearnIntent_NoNaturalLanguageFallback(t *testing.T) {
|
||||
if _, ok := parseAutoLearnIntent("请开始自动学习"); ok {
|
||||
t.Fatalf("expected no fallback match")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseAutonomyIntent_StartNaturalLanguage(t *testing.T) {
|
||||
intent, ok := parseAutonomyIntent("以后你自动拆解并自动执行任务,每15分钟主动找我汇报一次,研究方向是日志异常聚类")
|
||||
func TestParseAutonomyIntent_FallbackCommand(t *testing.T) {
|
||||
intent, ok := parseAutonomyIntent("autonomy start 15m log clustering")
|
||||
if !ok {
|
||||
t.Fatalf("expected intent")
|
||||
}
|
||||
@@ -103,13 +89,13 @@ func TestParseAutonomyIntent_StartNaturalLanguage(t *testing.T) {
|
||||
if intent.idleInterval == nil || *intent.idleInterval != 15*time.Minute {
|
||||
t.Fatalf("unexpected interval: %v", intent.idleInterval)
|
||||
}
|
||||
if intent.focus != "日志异常聚类" {
|
||||
if intent.focus != "log clustering" {
|
||||
t.Fatalf("unexpected focus: %q", intent.focus)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseAutonomyIntent_StopNaturalLanguage(t *testing.T) {
|
||||
intent, ok := parseAutonomyIntent("先不要主动找我,关闭自主模式")
|
||||
func TestParseAutonomyIntent_StopFallbackCommand(t *testing.T) {
|
||||
intent, ok := parseAutonomyIntent("autonomy stop")
|
||||
if !ok {
|
||||
t.Fatalf("expected intent")
|
||||
}
|
||||
@@ -118,8 +104,8 @@ func TestParseAutonomyIntent_StopNaturalLanguage(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseAutonomyIntent_StatusNaturalLanguage(t *testing.T) {
|
||||
intent, ok := parseAutonomyIntent("帮我看下自主模式状态")
|
||||
func TestParseAutonomyIntent_StatusFallbackCommand(t *testing.T) {
|
||||
intent, ok := parseAutonomyIntent("autonomy status")
|
||||
if !ok {
|
||||
t.Fatalf("expected intent")
|
||||
}
|
||||
@@ -138,28 +124,14 @@ func TestParseAutonomyIdleInterval(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseAutonomyIntent_NoFalsePositiveOnSingleTask(t *testing.T) {
|
||||
func TestParseAutonomyIntent_NoNaturalLanguageFallback(t *testing.T) {
|
||||
if intent, ok := parseAutonomyIntent("请自动执行这个任务"); ok {
|
||||
t.Fatalf("expected no intent, got: %+v", intent)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractAutonomyFocus_EmptyWhenNotProvided(t *testing.T) {
|
||||
focus := extractAutonomyFocus("开启自主模式,每30分钟主动汇报")
|
||||
if focus != "" {
|
||||
t.Fatalf("expected empty focus, got: %q", focus)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractAutonomyFocus_KeepInnerBing(t *testing.T) {
|
||||
focus := extractAutonomyFocus("开启自主模式,研究方向是日志聚类并关联异常根因,并且每30分钟主动汇报")
|
||||
if focus != "日志聚类并关联异常根因" {
|
||||
t.Fatalf("unexpected focus: %q", focus)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseAutonomyIntent_ClearFocusNaturalLanguage(t *testing.T) {
|
||||
intent, ok := parseAutonomyIntent("自主附带的方向执行完成了,可以去执行别的")
|
||||
func TestParseAutonomyIntent_ClearFocusFallbackCommand(t *testing.T) {
|
||||
intent, ok := parseAutonomyIntent("autonomy clear_focus")
|
||||
if !ok {
|
||||
t.Fatalf("expected intent")
|
||||
}
|
||||
@@ -167,3 +139,16 @@ func TestParseAutonomyIntent_ClearFocusNaturalLanguage(t *testing.T) {
|
||||
t.Fatalf("unexpected action: %s", intent.action)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractJSONObject_FromCodeFence(t *testing.T) {
|
||||
raw := extractJSONObject("```json\n{\"action\":\"start\",\"confidence\":0.95}\n```")
|
||||
if raw != "{\"action\":\"start\",\"confidence\":0.95}" {
|
||||
t.Fatalf("unexpected json: %q", raw)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractJSONObject_Invalid(t *testing.T) {
|
||||
if raw := extractJSONObject("no json here"); raw != "" {
|
||||
t.Fatalf("expected empty json, got: %q", raw)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user