package reasoningmode import ( "strings" "testing" ) func TestPartialFeedJoinsReasoningSegmentsAndRefreshesToBody(t *testing.T) { feed := NewPartialFeed(string(ExecutionReasoning)) // Step 1: first narrative segment streams in. step1 := "我先查一下知识库。" if got := feed.OnAnswer(step1); got != step1 { t.Fatalf("first segment = %q, want %q", got, step1) } if !feed.Started() { t.Fatal("Started must be true after the first answer text") } // Step 1 ends with a tool call, step 2 starts with its own narrative. feed.StepBoundary() step2 := "找到了相关文档,我确认一下参数。" got := feed.OnAnswer(step1 + step2) want := step1 + "\n\n" + step2 if got != want { t.Fatalf("second segment = %q, want %q (segments must be line separated)", got, want) } // Step 2 ends, step 3 carries the final answer body. feed.StepBoundary() body := "## CR20V 关节电机最大旋转扭矩\n\n| 关节 | 扭矩 |" got = feed.OnAnswer(step1 + step2 + body) if got != body { t.Fatalf("body-only content = %q, want %q (reasoning must be hidden)", got, body) } // The body keeps streaming; the visible content stays body-only. grown := body + "\n| J1 | 100 N·m |" if got := feed.OnAnswer(step1 + step2 + grown); got != grown { t.Fatalf("grown body = %q, want %q", got, grown) } if strings.Contains(got, "我先查一下知识库") { t.Fatalf("reasoning leaked into the refreshed card: %q", got) } } func TestPartialFeedKeepsGluedNarrationReadable(t *testing.T) { // WeKnora concatenates step narratives without any separator; the feed must // not let the card show them as one run-on sentence. feed := NewPartialFeed(string(ExecutionReasoning)) first := "我正在理解问题。" feed.OnAnswer(first) feed.StepBoundary() second := "正在检索知识库。" if got := feed.OnAnswer(first + second); got != first+"\n\n"+second { t.Fatalf("glued narration = %q", got) } } func TestPartialFeedStartsANewSegmentWhenTheStreamRestarts(t *testing.T) { feed := NewPartialFeed(string(ExecutionReasoning)) feed.OnAnswer("第一段推理。") got := feed.OnAnswer("重新开始的一段推理。") if got != "第一段推理。\n\n重新开始的一段推理。" { t.Fatalf("restart segment = %q", got) } } func TestPartialFeedQuickExecutionIsPassThrough(t *testing.T) { feed := NewPartialFeed(string(ExecutionQuick)) narrativeAndBody := "我已收集信息。\n\n## 标题\n\n正文" if got := feed.OnAnswer(narrativeAndBody); got != narrativeAndBody { t.Fatalf("quick execution = %q, want the raw stream unchanged", got) } feed.StepBoundary() if got := feed.OnAnswer(narrativeAndBody); got != narrativeAndBody { t.Fatalf("quick execution after boundary = %q, want the raw stream unchanged", got) } } func TestPartialFeedWithoutBoundaryKeepsShowingReasoning(t *testing.T) { feed := NewPartialFeed(string(ExecutionReasoning)) greeting := "你好!我是越疆智能助手。" if got := feed.OnAnswer(greeting); got != greeting { t.Fatalf("greeting = %q, want unchanged", got) } }