15f2a11162
- reasoningmode: 新增正文边界识别(结构行 + 前置空行)与流式 PartialFeed: 分步叙述按行拼接显示,正文开始时只输出正文,卡片更新即刷新清掉推理区 - dingtalk: 事件流与流式回调统一改走 PartialFeed - qa: 推理执行的最终答案在入库/投递前去掉步骤叙述(快速模式行为不变) 语料回归:生产 118 条内建智能推理答案中 106 条识别出正文边界(被隐藏的 均为 59-164 字过渡句),12 条无推理的问候类答案保持原样;go vet 与 go test ./... 全绿。
88 lines
3.0 KiB
Go
88 lines
3.0 KiB
Go
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)
|
|
}
|
|
}
|