355b722a1d
Commands start in a PTY (creack/pty; macOS and Linux) of the client's size with TERM=xterm-256color in their own session. chat_shell_input writes typed UTF-8 text in order through a bounded queue; chat_shell_resize sets the size. Output stays the raw terminal stream with byte offsets as sequence numbers, chat_shell_run_output resumes from an offset, and a plain-text rendering is persisted for Copy output and Send to agent. Input is never stored or logged.
37 lines
1.1 KiB
Go
37 lines
1.1 KiB
Go
package server
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.a-wan.net/alan/pipelines/internal/protocol"
|
|
)
|
|
|
|
func TestChatShellPlainTextRendersTerminalStream(t *testing.T) {
|
|
for _, tc := range []struct{ raw, want string }{
|
|
{"plain\nlines\n", "plain\nlines\n"},
|
|
{"\x1b[1;32mok\x1b[0m done\r\n", "ok done\n"},
|
|
{"10%\r50%\r100%\r\n", "100%\n"},
|
|
{"long line\rab\x1b[K\r\n", "ab\n"},
|
|
{"abc\b\bX\n", "aXc\n"},
|
|
{"\x1b]0;window title\x07shown\n", "shown\n"},
|
|
{"\x1b]8;;https://x.test\x1b\\link\x1b]8;;\x1b\\\n", "link\n"},
|
|
{"\x1b(Bcharset\x1b=\n", "charset\n"},
|
|
{"col\x1b[10Gx\n", "col x\n"},
|
|
{"bell\x07 and nul\x00\n", "bell and nul\n"},
|
|
{"\x1b[2Kgone\r\x1b[2Kkept", "kept"},
|
|
{"unterminated \x1b[31", "unterminated"},
|
|
} {
|
|
if got := chatShellPlainText(tc.raw); got != tc.want {
|
|
t.Errorf("plain(%q) = %q, want %q", tc.raw, got, tc.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestChatShellPlainTextIsBounded(t *testing.T) {
|
|
raw := strings.Repeat("\x1b[500Gx\n", protocol.ChatShellRunRetained/64)
|
|
if got := chatShellPlainText(raw); len(got) > protocol.ChatShellRunRetained || !strings.HasSuffix(got, "x\n") {
|
|
t.Fatalf("rendered %d bytes", len(got))
|
|
}
|
|
}
|