|
| 1 | +package chat |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/charmbracelet/x/ansi" |
| 7 | + "github.com/stretchr/testify/assert" |
| 8 | + "github.com/stretchr/testify/require" |
| 9 | + |
| 10 | + "github.com/docker/docker-agent/pkg/runtime" |
| 11 | + "github.com/docker/docker-agent/pkg/tui/components/messages" |
| 12 | + "github.com/docker/docker-agent/pkg/tui/components/sidebar" |
| 13 | + "github.com/docker/docker-agent/pkg/tui/service" |
| 14 | +) |
| 15 | + |
| 16 | +func newDelegationMarkerTestPage() *chatPage { |
| 17 | + sessionState := &service.SessionState{} |
| 18 | + msgs := messages.NewScrollableView(80, 24, sessionState) |
| 19 | + msgs.SetSize(80, 24) |
| 20 | + return &chatPage{ |
| 21 | + sidebar: sidebar.New(sessionState), |
| 22 | + messages: msgs, |
| 23 | + sessionState: sessionState, |
| 24 | + } |
| 25 | +} |
| 26 | + |
| 27 | +// TestAgentSwitchingInsertsReturnMarker covers the Phase 2 design decision to |
| 28 | +// bracket only the EXIT of a forwarded sub-agent. AgentSwitching(false, child, |
| 29 | +// parent) — emitted when a transfer_task/run_skill sub-session returns — inserts |
| 30 | +// a "↩ child → parent" marker, while the entry event AgentSwitching(true, ...) |
| 31 | +// inserts nothing (the transfer_task card is the visible entry). |
| 32 | +func TestAgentSwitchingInsertsReturnMarker(t *testing.T) { |
| 33 | + t.Parallel() |
| 34 | + |
| 35 | + t.Run("return (Switching=false) inserts a marker", func(t *testing.T) { |
| 36 | + t.Parallel() |
| 37 | + p := newDelegationMarkerTestPage() |
| 38 | + |
| 39 | + handled, cmd := p.handleRuntimeEvent(&runtime.AgentSwitchingEvent{ |
| 40 | + Switching: false, |
| 41 | + FromAgent: "librarian", |
| 42 | + ToAgent: "root", |
| 43 | + }) |
| 44 | + |
| 45 | + require.True(t, handled) |
| 46 | + require.NotNil(t, cmd, "a returning sub-agent should insert a marker") |
| 47 | + assert.Contains(t, ansi.Strip(p.messages.View()), "↩ librarian → root") |
| 48 | + }) |
| 49 | + |
| 50 | + t.Run("entry (Switching=true) inserts nothing", func(t *testing.T) { |
| 51 | + t.Parallel() |
| 52 | + p := newDelegationMarkerTestPage() |
| 53 | + |
| 54 | + handled, cmd := p.handleRuntimeEvent(&runtime.AgentSwitchingEvent{ |
| 55 | + Switching: true, |
| 56 | + FromAgent: "root", |
| 57 | + ToAgent: "librarian", |
| 58 | + }) |
| 59 | + |
| 60 | + require.True(t, handled) |
| 61 | + assert.Nil(t, cmd, "entering a delegation must not insert a return marker") |
| 62 | + assert.NotContains(t, ansi.Strip(p.messages.View()), "↩") |
| 63 | + }) |
| 64 | + |
| 65 | + t.Run("missing agent names insert nothing", func(t *testing.T) { |
| 66 | + t.Parallel() |
| 67 | + p := newDelegationMarkerTestPage() |
| 68 | + |
| 69 | + handled, cmd := p.handleRuntimeEvent(&runtime.AgentSwitchingEvent{ |
| 70 | + Switching: false, |
| 71 | + FromAgent: "", |
| 72 | + ToAgent: "root", |
| 73 | + }) |
| 74 | + |
| 75 | + require.True(t, handled) |
| 76 | + assert.Nil(t, cmd) |
| 77 | + assert.NotContains(t, ansi.Strip(p.messages.View()), "↩") |
| 78 | + }) |
| 79 | +} |
0 commit comments