Pin Agent-Native as a submodule so the module builds without the multi-repo sibling path. Co-authored-by: Cursor <cursoragent@cursor.com>
36 lines
1.2 KiB
Go
36 lines
1.2 KiB
Go
package squad
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// stripThinkBlocks/parseLLMPlan 处理 MiniMax 等模型把思考内嵌为 content 中的
|
|
// <think>…</think>(而非 reasoning_content 字段)的行为。
|
|
|
|
func TestStripThinkBlocks(t *testing.T) {
|
|
in := "<think>计划:\n先输出 {\"a\":1} 试试\n</think>{\"a\":1,\"agents\":[]}"
|
|
out := stripThinkBlocks(in)
|
|
if strings.Contains(out, "think") || strings.Contains(out, "计划") {
|
|
t.Errorf("think block not stripped: %q", out)
|
|
}
|
|
if !strings.HasPrefix(out, "{\"a\"") {
|
|
t.Errorf("json broken: %q", out)
|
|
}
|
|
// 未闭合:丢弃思考余段。
|
|
if got := stripThinkBlocks("<think>未写完"); got != "" {
|
|
t.Errorf("unclosed think want dropped, got %q", got)
|
|
}
|
|
}
|
|
|
|
func TestParseLLMPlanWithThinkAndFence(t *testing.T) {
|
|
raw := "<think>用户要报告,我需要拆步骤 {\"fake\":true}</think>\n```json\n{\"agents\":[{\"action\":\"use\",\"role\":\"writer\"}],\"steps\":[{\"id\":\"s1\",\"role\":\"writer\",\"title\":\"成文\"}]}\n```"
|
|
out, err := parseLLMPlan(raw)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(out.Agents) != 1 || out.Agents[0].Role != "writer" || len(out.Steps) != 1 {
|
|
t.Fatalf("parse wrong: %+v", out)
|
|
}
|
|
}
|