feat: optimize WebUI stream output and sanitize user-facing answers

This commit is contained in:
2026-03-13 13:14:37 +08:00
parent 8dc5354fa4
commit 33c357a1de
8 changed files with 228 additions and 45 deletions

View File

@@ -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)
}
}