dify/dify-agent-runtime/internal/server/tmux_test.go
Yunlu Wen 302d7b1e1b
feat(agent): shellctl rewritten in go (#38841)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-07-15 01:58:36 +00:00

60 lines
1.2 KiB
Go

package server
import (
"testing"
)
func TestShellQuote(t *testing.T) {
tests := []struct {
input string
expected string
}{
{"hello", "'hello'"},
{"", "''"},
{"a b c", "'a b c'"},
{"it's", "'it'\\''s'"},
{"/path/to/file", "'/path/to/file'"},
}
for _, tc := range tests {
got := shellQuote(tc.input)
if got != tc.expected {
t.Errorf("shellQuote(%q) = %q, want %q", tc.input, got, tc.expected)
}
}
}
func TestShellJoin(t *testing.T) {
got := shellJoin([]string{"echo", "hello world", "it's"})
expected := "'echo' 'hello world' 'it'\\''s'"
if got != expected {
t.Errorf("shellJoin = %q, want %q", got, expected)
}
}
func TestIsTmuxTargetMissing(t *testing.T) {
missingMsgs := []string{
"can't find pane: shellctl-abc",
"can't find session: shellctl-abc",
"no server running on /tmp/tmux.sock",
"failed to connect to server",
"server exited unexpectedly",
}
for _, msg := range missingMsgs {
if !isTmuxTargetMissing(msg) {
t.Errorf("expected %q to be detected as target missing", msg)
}
}
validMsgs := []string{
"some other error",
"permission denied",
"",
}
for _, msg := range validMsgs {
if isTmuxTargetMissing(msg) {
t.Errorf("expected %q to NOT be detected as target missing", msg)
}
}
}