package reasoningmode import ( "strings" "testing" ) func TestBodyStartOffsetRecognizesStructuralBodyLines(t *testing.T) { leadIn := "根据检索到的资料,关于 CR20V 各关节电机最大旋转扭矩的说明如下:" heading := "## CR20V 关节电机最大旋转扭矩" tableBody := "**Magician 传感器套件(Magician Sensor Kit)重量如下:**\n\n| 项目 | 重量 |\n| --- | --- |\n| 整机 | 1.2 kg |" rowBody := "| 关节 | 扭矩 |\n| --- | --- |" quoteBody := "> 提示:以下参数来自产品手册。" tests := []struct { name string answer string want string ok bool }{ { name: "narration then heading", answer: "我已经收集了充分的信息。现在我可以明确回答用户的问题了。\n\n关键发现:\n1. 手册给出额定扭矩\n\n需要向用户说明\n\n" + heading + "\n\n各关节参数如下。", want: heading + "\n\n各关节参数如下。", ok: true, }, { name: "lead-in then bold body line", answer: "我已经获取到完整且明确的信息,可以给出准确答案了。\n\n" + tableBody, want: tableBody, ok: true, }, { name: "short lead-in then table", answer: leadIn + "\n\n" + rowBody, want: rowBody, ok: true, }, { name: "narration then blockquote", answer: "我需要先确认使用场景。\n\n" + quoteBody, want: quoteBody, ok: true, }, { name: "greeting has no body boundary", answer: "你好!我是越疆智能助手,可以帮你查询机械臂资料。", want: "你好!我是越疆智能助手,可以帮你查询机械臂资料。", ok: false, }, { name: "answer opens with its body: nothing is hidden", answer: heading + "\n\n各关节参数如下。", want: heading + "\n\n各关节参数如下。", ok: true, }, { name: "title and opening paragraph survive finalize", answer: "# 200万高职具身智能实训室搭配方案\n\n结合越疆现有的一体化实训平台,围绕具身智能教学场景,我们从教具、软件、课程三方面给出搭配建议。\n\n## 一、先明确三条搭配原则\n\n- 匹配课程大纲\n- 控制预算\n", want: "# 200万高职具身智能实训室搭配方案\n\n结合越疆现有的一体化实训平台,围绕具身智能教学场景,我们从教具、软件、课程三方面给出搭配建议。\n\n## 一、先明确三条搭配原则\n\n- 匹配课程大纲\n- 控制预算\n", ok: true, }, { name: "leading blank lines before the title", answer: "\n\n# 标题\n\n正文。", want: "# 标题\n\n正文。", ok: true, }, { name: "structural line inside a fence is ignored", answer: "我先确认一下配置项。\n\n```\n## 这是代码里的注释\n| a | b |\n```\n\n参考上面的写法。", want: "我先确认一下配置项。\n\n```\n## 这是代码里的注释\n| a | b |\n```\n\n参考上面的写法。", ok: false, }, { name: "structural line glued to narration is not a boundary", answer: "需要向用户说明" + heading, want: "需要向用户说明" + heading, ok: false, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { body, ok := SplitReasoningAnswer(tt.answer) if ok != tt.ok { t.Fatalf("ok = %v, want %v", ok, tt.ok) } if body != tt.want { t.Fatalf("body = %q, want %q", body, tt.want) } if !strings.HasSuffix(tt.answer, body) { t.Fatalf("body %q is not a suffix of the answer: the rule ate content", body) } if trimmed := TrimReasoningNarration(tt.answer); trimmed != tt.want { t.Fatalf("TrimReasoningNarration = %q, want %q", trimmed, tt.want) } }) } } func TestIsReasoningExecution(t *testing.T) { tests := map[string]bool{ "reasoning": true, " reasoning ": true, "reasoning_single": true, "quick": false, "": false, "something": false, } for execution, want := range tests { if got := IsReasoningExecution(execution); got != want { t.Fatalf("IsReasoningExecution(%q) = %v, want %v", execution, got, want) } } }