package dingtalk import ( "strings" "testing" "gitea.zheromiku.top/Weknora/dobotai-platform/internal/reasoningmode" ) func TestDecorateReasoningPartialMarksReasoningFromFirstChunk(t *testing.T) { got := decorateReasoningPartial("部分答案", string(reasoningmode.ExecutionReasoning)) want := "【智能推理模式】\n\n部分答案" if got != want { t.Fatalf("got=%q want=%q", got, want) } } func TestDecorateReasoningPartialLeavesQuickAnswerUnchanged(t *testing.T) { if got := decorateReasoningPartial("快速答案", string(reasoningmode.ExecutionQuick)); got != "快速答案" { t.Fatalf("got=%q", got) } } func TestReasoningStreamingShowsStepsLineByLineThenDropsThemForBody(t *testing.T) { execution := string(reasoningmode.ExecutionReasoning) first := "我先确认一下设备的型号和手册。" second := "手册里有关节扭矩表,让我核对一下。" body := "## CR20V 关节电机最大旋转扭矩\n\n| 关节 | 扭矩 |" feed := reasoningmode.NewPartialFeed(execution) if got, want := decorateReasoningPartial(feed.OnAnswer(first), execution), "【智能推理模式】\n\n"+first; got != want { t.Fatalf("step1 got=%q want=%q", got, want) } feed.StepBoundary() if got, want := decorateReasoningPartial(feed.OnAnswer(first+second), execution), "【智能推理模式】\n\n"+first+"\n\n"+second; got != want { t.Fatalf("step2 got=%q want=%q", got, want) } answer := first + second + "\n\n" + body if got, want := decorateReasoningPartial(feed.OnAnswer(answer), execution), "【智能推理模式】\n\n"+body; got != want { t.Fatalf("refresh got=%q want=%q", got, want) } got := feed.OnAnswer(answer + "\n| J1 | 98 N·m |") if strings.Contains(got, first) || !strings.Contains(got, "J1") { t.Fatalf("reasoning must stay hidden while the body streams, got=%q", got) } } func TestQuickStreamingKeepsAccumulatedAnswer(t *testing.T) { feed := reasoningmode.NewPartialFeed(string(reasoningmode.ExecutionQuick)) if got := feed.OnAnswer("快速答案"); got != "快速答案" { t.Fatalf("got=%q", got) } feed.StepBoundary() if got := feed.OnAnswer("快速答案追加"); got != "快速答案追加" { t.Fatalf("got=%q", got) } }