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) } }