Files
Agent-Native/runtime/loop_callid_test.go
T
weichen 6ddd3da8df Enable canonical versioned Go module consumption
Why: Allow consumers to download an immutable module revision without nested source checkouts or local path replacements.

Evidence: SELF package tests and the prior canonical-path rejection are recorded in the Dev dependency-workspace task card; remote consumption is replayed against the committed candidate.

Impact: Change the module identity and its Go imports while preserving API behavior. Existing historical submodule revisions remain buildable.

Refs: Versioned dependencies U1/U3; feature/dependency-workspace
2026-10-13 15:36:10 +00:00

50 lines
1.5 KiB
Go

package runtime
import (
"context"
"testing"
"git-ssh.u1680832.nyat.app/weichen/Agent-Native.git/runtime/llm"
"git-ssh.u1680832.nyat.app/weichen/Agent-Native.git/runtime/tools"
)
// TestLoopToolEventsCarryCallID 验证 tool_execution_start/end 事件带工具调用
// ID:并行执行下消费方按 ID 配对(回归锚点,防止字段被删后顺序假设回归)。
func TestLoopToolEventsCarryCallID(t *testing.T) {
hits := 0
reg := tools.NewRegistry(t.TempDir())
reg.Register(hitTool{hits: &hits})
var starts, ends []Event
res, err := Run(context.Background(), Config{
Model: "fake",
Tools: reg,
Stream: script(
llm.Message{Role: llm.RoleAssistant, StopReason: llm.StopToolCalls, ToolCalls: []llm.ToolCall{{
ID: "call-7", Name: "echo", Arguments: `{}`,
}}},
llm.Message{Role: llm.RoleAssistant, Content: "done", StopReason: llm.StopEnd},
),
OnEvent: func(ev Event) {
switch ev.Type {
case "tool_execution_start":
starts = append(starts, ev)
case "tool_execution_end":
ends = append(ends, ev)
}
},
}, llm.Message{Role: llm.RoleUser, Content: "go"})
if err != nil {
t.Fatal(err)
}
if hits != 1 || len(starts) != 1 || len(ends) != 1 {
t.Fatalf("hits=%d starts=%d ends=%d", hits, len(starts), len(ends))
}
if starts[0].CallID != "call-7" || starts[0].Tool != "echo" {
t.Fatalf("start = %+v", starts[0])
}
if ends[0].CallID != "call-7" || ends[0].Tool != "echo" {
t.Fatalf("end = %+v", ends[0])
}
_ = res
}