-
Notifications
You must be signed in to change notification settings - Fork 394
feat(tui): live status + labeled spinner for delegation (#3101) #3115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
aheritier
wants to merge
3
commits into
main
Choose a base branch
from
feat/tui-delegation-spinner-readability
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| package transfertask | ||
|
|
||
| import ( | ||
| "regexp" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
|
|
||
| "github.com/docker/docker-agent/pkg/tools" | ||
| "github.com/docker/docker-agent/pkg/tui/types" | ||
| ) | ||
|
|
||
| var ansiEscape = regexp.MustCompile("\x1b\\[[0-9;]*m") | ||
|
|
||
| func stripANSI(s string) string { | ||
| return ansiEscape.ReplaceAllString(s, "") | ||
| } | ||
|
|
||
| // spinnerGlyph is the first frame of the shared braille spinner. An in-flight | ||
| // delegation must show it instead of a success/error glyph. | ||
| const spinnerGlyph = "⠋" | ||
|
|
||
| func transferMessage(status types.ToolStatus) *types.Message { | ||
| return &types.Message{ | ||
| Type: types.MessageTypeToolCall, | ||
| Sender: "root", | ||
| ToolStatus: status, | ||
| ToolCall: tools.ToolCall{ | ||
| Function: tools.FunctionCall{ | ||
| Arguments: `{"agent":"researcher","task":"Investigate the flaky test"}`, | ||
| }, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func renderCard(status types.ToolStatus) string { | ||
| view := New(transferMessage(status), nil) | ||
| view.SetSize(80, 1) | ||
| return stripANSI(view.View()) | ||
| } | ||
|
|
||
| // TestTransferTaskCard_StatusIcon locks in the status-aware icon: a running or | ||
| // pending delegation animates the spinner (never showing a premature ✓), while | ||
| // completed/error terminal states show ✓/✗. The parent→child header and the | ||
| // task text must render in every state. | ||
| func TestTransferTaskCard_StatusIcon(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| status types.ToolStatus | ||
| want string // glyph that must be present | ||
| notWant []string // glyphs that must be absent | ||
| }{ | ||
| {"running animates spinner", types.ToolStatusRunning, spinnerGlyph, []string{"✓", "✗"}}, | ||
| {"pending animates spinner", types.ToolStatusPending, spinnerGlyph, []string{"✓", "✗"}}, | ||
| {"completed shows check", types.ToolStatusCompleted, "✓", []string{spinnerGlyph, "✗"}}, | ||
| {"error shows cross", types.ToolStatusError, "✗", []string{spinnerGlyph, "✓"}}, | ||
| } | ||
|
|
||
| for _, tc := range tests { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| out := renderCard(tc.status) | ||
|
|
||
| assert.Regexp(t, `root\s+calls\s+researcher`, out, "header should name parent and child agents") | ||
| assert.Contains(t, out, "Investigate the flaky test", "task text should always render") | ||
| assert.Contains(t, out, tc.want, "expected status glyph missing") | ||
| for _, n := range tc.notWant { | ||
| assert.NotContains(t, out, n, "unexpected glyph %q present for %s", n, tc.name) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| // TestTransferTaskCard_IconWidthIsStable guards the A.1 fixed-width contract: | ||
| // the icon stays a single glyph with no elapsed-time suffix, so the wrapped | ||
| // task text keeps the same indent across statuses. Swapping in an elapsed-time | ||
| // icon (e.g. toolcommon.Icon) would shift the running task column and regress. | ||
| func TestTransferTaskCard_IconWidthIsStable(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| taskColumn := func(status types.ToolStatus) int { | ||
| // Layout is "header\n\n<icon> task", so the task block is the 3rd part. | ||
| parts := strings.SplitN(renderCard(status), "\n", 3) | ||
| return strings.Index(parts[len(parts)-1], "Investigate") | ||
| } | ||
|
|
||
| running := taskColumn(types.ToolStatusRunning) | ||
| assert.Positive(t, running, "task text should be indented past the icon") | ||
| assert.Equal(t, running, taskColumn(types.ToolStatusPending)) | ||
| assert.Equal(t, running, taskColumn(types.ToolStatusCompleted)) | ||
| assert.Equal(t, running, taskColumn(types.ToolStatusError)) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package chat | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| // TestPendingSpinnerContext verifies the waiting-spinner label is scoped to | ||
| // delegated streams: depth < 2 keeps the default playful spinner (empty | ||
| // sender/label), while nested streams name the nearest parent → child pair and | ||
| // expose the child as the accent-color sender. | ||
| func TestPendingSpinnerContext(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| stack []string | ||
| wantSender string | ||
| wantLabel string | ||
| }{ | ||
| {"depth 0 - no stream", nil, "", ""}, | ||
| {"depth 1 - top-level turn", []string{"root"}, "", ""}, | ||
| {"depth 2 - single delegation", []string{"root", "researcher"}, "researcher", "root → researcher"}, | ||
| {"depth 3 - nested delegation", []string{"root", "researcher", "librarian"}, "librarian", "researcher → librarian"}, | ||
| } | ||
|
|
||
| for _, tc := range tests { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| p := &chatPage{agentStack: tc.stack} | ||
| sender, label := p.pendingSpinnerContext() | ||
|
|
||
| assert.Equal(t, tc.wantSender, sender, "sender (accent agent)") | ||
| assert.Equal(t, tc.wantLabel, label, "parent → child label") | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.