feat: optimize WebUI stream output and sanitize user-facing answers
This commit is contained in:
@@ -93,3 +93,32 @@ func TestMatchSkillsByNameEmpty(t *testing.T) {
|
||||
t.Fatalf("expected 0 matches, got %d", len(matched))
|
||||
}
|
||||
}
|
||||
|
||||
func TestSanitizeUserFacingAnswerExtractsFinalAnswer(t *testing.T) {
|
||||
raw := "Thought: 先分析用户问题\nObservation: 已经有足够信息\nFinal Answer: 这是给用户的结果"
|
||||
got := sanitizeUserFacingAnswer(raw)
|
||||
if got != "这是给用户的结果" {
|
||||
t.Fatalf("expected final answer only, got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSanitizeUserFacingAnswerDropsTraceLines(t *testing.T) {
|
||||
raw := strings.Join([]string{
|
||||
"Step 1 Thought: 检查上下文",
|
||||
"Action: shell",
|
||||
"Observation: ok",
|
||||
"请执行以下变更。",
|
||||
}, "\n")
|
||||
got := sanitizeUserFacingAnswer(raw)
|
||||
if got != "请执行以下变更。" {
|
||||
t.Fatalf("expected user-facing text only, got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSanitizeUserFacingAnswerKeepsNormalAnswer(t *testing.T) {
|
||||
raw := "1. 先打开配置文件\n2. 修改端口后重启服务"
|
||||
got := sanitizeUserFacingAnswer(raw)
|
||||
if got != raw {
|
||||
t.Fatalf("expected answer unchanged, got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user