MCPcopy Index your code
hub / github.com/docker/docker-agent / TestReprobe_NoChangeMeansNoExtraEvents

Function TestReprobe_NoChangeMeansNoExtraEvents

pkg/runtime/runtime_test.go:3268–3319  ·  view source on GitHub ↗

TestReprobe_NoChangeMeansNoExtraEvents verifies that reprobe is a no-op (no extra ToolsetInfo events, no panics) when no new tools appear after a tool call.

(t *testing.T)

Source from the content-addressed store, hash-verified

3266// (no extra ToolsetInfo events, no panics) when no new tools appear after
3267// a tool call.
3268func TestReprobe_NoChangeMeansNoExtraEvents(t *testing.T) {
3269 t.Parallel()
3270
3271 staticTool := tools.Tool{
3272 Name: "do_thing",
3273 Parameters: map[string]any{},
3274 Handler: func(_ context.Context, _ tools.ToolCall) (*tools.ToolCallResult, error) {
3275 return tools.ResultSuccess("done"), nil
3276 },
3277 }
3278
3279 stream1 := newStreamBuilder().
3280 AddToolCallName("c1", "do_thing").
3281 AddToolCallArguments("c1", `{}`).
3282 AddStopWithUsage(5, 5).
3283 Build()
3284
3285 prov := &recordingProvider{
3286 id: "test/mock-model",
3287 streams: []*mockStream{stream1},
3288 }
3289
3290 ts := newStubToolSet(nil, []tools.Tool{staticTool}, nil)
3291 root := agent.New("root", "test", agent.WithModel(prov), agent.WithToolSets(ts))
3292 tm := team.New(team.WithAgents(root))
3293
3294 rt, err := NewLocalRuntime(t.Context(), tm, WithSessionCompaction(false), WithModelStore(mockModelStore{}))
3295 require.NoError(t, err)
3296 rt.registerDefaultTools()
3297
3298 sess := session.New(session.WithUserMessage("Do the thing"))
3299 sess.Title = "no-change reprobe test"
3300 sess.ToolsApproved = true
3301
3302 evCh := rt.RunStream(t.Context(), sess)
3303 var events []Event
3304 for ev := range evCh {
3305 events = append(events, ev)
3306 }
3307
3308 // Count ToolsetInfo events — reprobe should NOT emit an extra one.
3309 var counts []int
3310 for _, ev := range events {
3311 if ti, ok := ev.(*ToolsetInfoEvent); ok {
3312 counts = append(counts, ti.AvailableTools)
3313 }
3314 }
3315 // All counts should be 1 (the static tool).
3316 for _, c := range counts {
3317 assert.Equal(t, 1, c, "unexpected ToolsetInfo count — reprobe emitted extra event when tools unchanged")
3318 }
3319}
3320
3321func toolNames(ts []tools.Tool) []string {
3322 names := make([]string, len(ts))

Callers

nothing calls this directly

Calls 15

registerDefaultToolsMethod · 0.95
RunStreamMethod · 0.95
ResultSuccessFunction · 0.92
NewFunction · 0.92
NewFunction · 0.92
WithAgentsFunction · 0.92
NewFunction · 0.92
WithUserMessageFunction · 0.92
newStreamBuilderFunction · 0.85
NewLocalRuntimeFunction · 0.85
WithSessionCompactionFunction · 0.85
WithModelStoreFunction · 0.85

Tested by

no test coverage detected