Files
ariandClaude Opus 5.5 4db99eaa2a Show shell tool calls as the trimmed full command
Goose's titles cut the command at ~40 characters, mostly spent on cd.
Use rawInput's command, strip cd/timeout/nix develop -c/env prefixes,
tag the directory and clip at 80 characters.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0119iKoN3fSvRGUAYHupPW4U
2026-11-01 22:40:15 -05:00

46 lines
1.8 KiB
Go

package bot
import (
"encoding/json"
"strings"
"testing"
"slackerbot/internal/acp"
)
func shell(cmd string) acp.Update {
in, _ := json.Marshal(map[string]string{"command": cmd})
return acp.Update{Kind: "tool_call", ToolName: "developer__shell", Title: "shell · " + cmd[:min(len(cmd), 40)] + "...", RawInput: in}
}
func TestToolLine(t *testing.T) {
for _, c := range []struct {
u acp.Update
want string
}{
{shell("cd /root/slacker-bot && ls -la && cat README.md"), "`ls -la && cat README.md` (slacker-bot)"},
{shell("cd /root && git clone https://gitea.skyg.ca/ari/slacker-bot"), "`git clone https://gitea.skyg.ca/ari/slacker-bot`"},
{shell("cd /root/slacker-bot && timeout 1800 nix build .#slackerbot"), "`nix build .#slackerbot` (slacker-bot)"},
{shell("cd /root/x; cd sub && nix develop .#go --impure -c go test ./..."), "`go test ./...` (sub)"},
{shell("timeout -k 5 300 env CGO_ENABLED=0 GOOS=linux go build"), "`go build`"},
{shell("ls -la /nix 2>&1; echo \"--- findmnt\"\nfindmnt"), "`ls -la /nix 2>&1; echo \"--- findmnt\" findmnt`"},
{shell("cd /tmp && "), "`cd /tmp &&`"},
{shell("echo `date`"), "`echo 'date'`"},
// No usable rawInput: goose's title as before.
{acp.Update{ToolName: "developer__shell", Title: "shell · ls"}, "shell · ls"},
{acp.Update{ToolName: "todo__todo_write", Title: "todo: todo write"}, "todo write"},
{acp.Update{Title: "slackerbot: send file"}, "slackerbot: send file"},
} {
if got := toolLine(c.u); got != c.want {
t.Errorf("toolLine(%q) = %q, want %q", c.u.RawInput, got, c.want)
}
}
}
func TestToolLineClips(t *testing.T) {
got := toolLine(shell("cd /root && echo " + strings.Repeat("é", 200)))
if r := []rune(got); len(r) != toolLineMax+2 || !strings.HasSuffix(got, "…`") {
t.Errorf("got %q (%d runes), want %d runes ending in …", got, len(r), toolLineMax+2)
}
}