MCPcopy Create free account
hub / github.com/docker/docker-agent / TestSteer_EmptySessionBootstrap

Function TestSteer_EmptySessionBootstrap

pkg/runtime/runtime_test.go:3469–3560  ·  view source on GitHub ↗

TestSteer_EmptySessionBootstrap verifies that when RunStream is started with zero messages in the session but one or more messages already queued via Steer, the model receives those messages as its initial context — i.e. the run completes normally rather than erroring or producing a vacuous response

(t *testing.T)

Source from the content-addressed store, hash-verified

3467// response. The behaviour must be identical to a session where those messages
3468// were added directly via session.WithUserMessage before the call.
3469func TestSteer_EmptySessionBootstrap(t *testing.T) {
3470 t.Parallel()
3471
3472 stream := newStreamBuilder().
3473 AddContent("Hello from the model").
3474 AddStopWithUsage(5, 3).
3475 Build()
3476
3477 prov := &messageRecordingProvider{
3478 id: "test/mock-model",
3479 streams: []*mockStream{stream},
3480 }
3481
3482 root := agent.New("root", "You are a test agent", agent.WithModel(prov))
3483 tm := team.New(team.WithAgents(root))
3484
3485 rt, err := NewLocalRuntime(t.Context(), tm, WithSessionCompaction(false), WithModelStore(mockModelStore{}))
3486 require.NoError(t, err)
3487
3488 // Enqueue before RunStream — zero messages in the session.
3489 err = rt.Steer(t.Context(), QueuedMessage{Content: "bootstrap message"})
3490 require.NoError(t, err)
3491
3492 // Fresh session with NO messages (SendUserMessage defaults to true but
3493 // there is nothing to send yet).
3494 sess := session.New()
3495 sess.Title = "steer bootstrap test"
3496
3497 evCh := rt.RunStream(t.Context(), sess)
3498 var events []Event
3499 for ev := range evCh {
3500 events = append(events, ev)
3501 }
3502
3503 // The run must complete normally.
3504 require.NotEmpty(t, events)
3505 assert.IsType(t, &StreamStoppedEvent{}, events[len(events)-1],
3506 "expected StreamStopped as the final event; got %T", events[len(events)-1])
3507
3508 // A UserMessageEvent must have been emitted for the steer message.
3509 var steerEventFound bool
3510 for _, ev := range events {
3511 if ue, ok := ev.(*UserMessageEvent); ok && strings.Contains(ue.Message, "bootstrap message") {
3512 steerEventFound = true
3513 break
3514 }
3515 }
3516 assert.True(t, steerEventFound,
3517 "expected a UserMessageEvent for the bootstrap steer message")
3518
3519 // --- Session-message assertions ---
3520 // The stored session message must be plain — no system-reminder envelope.
3521 var bootstrapMsg *session.Message
3522 for _, item := range sess.Messages {
3523 if item.IsMessage() &&
3524 item.Message.Message.Role == chat.MessageRoleUser &&
3525 strings.Contains(item.Message.Message.Content, "bootstrap message") {
3526 bootstrapMsg = item.Message

Callers

nothing calls this directly

Calls 15

SteerMethod · 0.95
RunStreamMethod · 0.95
NewFunction · 0.92
NewFunction · 0.92
WithAgentsFunction · 0.92
NewFunction · 0.92
newStreamBuilderFunction · 0.85
NewLocalRuntimeFunction · 0.85
WithSessionCompactionFunction · 0.85
WithModelStoreFunction · 0.85
AddStopWithUsageMethod · 0.80
ContextMethod · 0.80

Tested by

no test coverage detected