From 95292aff8eec2ba8f4c97effa560e49ebc3a8d4e Mon Sep 17 00:00:00 2001 From: JianFeeeee Date: Sat, 19 Sep 2026 13:53:56 +0800 Subject: [PATCH] =?UTF-8?q?test(llm):=20=E9=92=89=E6=AD=BB=E6=88=AA?= =?UTF-8?q?=E6=96=AD=E5=BF=85=E9=A1=BB=E7=9F=AD=E8=B7=AF=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E5=88=86=E6=B4=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 补一条端到端断言:截断的 tool call 绝不能拿着空 map 走到 files_write (那会回 'path is required',模型据此原样重试)。断言 executeToolCallInner 的短路 + 指引可执行。 --- internal/agent/core/stream_accumulate_test.go | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/internal/agent/core/stream_accumulate_test.go b/internal/agent/core/stream_accumulate_test.go index 9684f2a..eb41fcc 100644 --- a/internal/agent/core/stream_accumulate_test.go +++ b/internal/agent/core/stream_accumulate_test.go @@ -134,3 +134,27 @@ func TestAccumulateStreamInvalidArgsNotFlaggedAsTruncated(t *testing.T) { t.Error("finish_reason=tool_calls 时不应标记为截断") } } + +// 截断必须**真的拦住工具调用**,而不是只改错误文案: +// 旧实现拿着空 map 去调 files_write,工具回 "path is required", +// 模型据此原样重试(实测连续 4 次)。这里断言 executeToolCallInner 的短路。 +func TestTruncatedToolCallIsShortCircuited(t *testing.T) { + tc := agentAPI.ToolCall{ + ID: "call_1", + Name: "files_write", + Arguments: map[string]interface{}{ + "__truncated_error": truncatedArgsError("files_write", 259, 4096), + }, + } + a := &Agent{} + got := a.executeToolCallInner(tc, "webui", nil) + + if strings.Contains(got, "path is required") { + t.Errorf("截断后仍走了工具分派(模型会原样重试):%s", got) + } + for _, want := range []string{"截断", "max_tokens=4096", "拆成多次调用"} { + if !strings.Contains(got, want) { + t.Errorf("指引缺少 %q:%s", want, got) + } + } +}