Some checks failed
Tests / unit-tests (push) Failing after 43s
- Dodat creack/pty za pseudo-terminal podršku - Claude CLI se pokreće u pravom PTY-ju (puni TUI, boje, Shift+Tab) - xterm.js u browseru renderuje terminal identično konzoli - WebSocket bridge: tastatura → PTY stdin, PTY stdout → terminal - Ring buffer (128KB) za replay pri reconnect-u - Automatski reconnect nakon 2 sekunde - PTY sesije žive nezavisno od browsera (60min idle timeout) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
75 lines
1.6 KiB
Go
75 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestRingBuffer(t *testing.T) {
|
|
t.Run("write and read", func(t *testing.T) {
|
|
rb := NewRingBuffer(10)
|
|
rb.Write([]byte("hello"))
|
|
got := rb.Bytes()
|
|
if string(got) != "hello" {
|
|
t.Errorf("got %q, want %q", got, "hello")
|
|
}
|
|
})
|
|
|
|
t.Run("wrap around", func(t *testing.T) {
|
|
rb := NewRingBuffer(5)
|
|
rb.Write([]byte("abcdefgh")) // wraps around
|
|
got := rb.Bytes()
|
|
if string(got) != "defgh" {
|
|
t.Errorf("got %q, want %q", got, "defgh")
|
|
}
|
|
})
|
|
|
|
t.Run("exact size", func(t *testing.T) {
|
|
rb := NewRingBuffer(5)
|
|
rb.Write([]byte("abcde"))
|
|
got := rb.Bytes()
|
|
if string(got) != "abcde" {
|
|
t.Errorf("got %q, want %q", got, "abcde")
|
|
}
|
|
})
|
|
|
|
t.Run("empty", func(t *testing.T) {
|
|
rb := NewRingBuffer(10)
|
|
got := rb.Bytes()
|
|
if len(got) != 0 {
|
|
t.Errorf("expected empty, got %q", got)
|
|
}
|
|
})
|
|
|
|
t.Run("multiple writes", func(t *testing.T) {
|
|
rb := NewRingBuffer(8)
|
|
rb.Write([]byte("abc"))
|
|
rb.Write([]byte("def"))
|
|
got := rb.Bytes()
|
|
if string(got) != "abcdef" {
|
|
t.Errorf("got %q, want %q", got, "abcdef")
|
|
}
|
|
})
|
|
|
|
t.Run("overflow multiple writes", func(t *testing.T) {
|
|
rb := NewRingBuffer(5)
|
|
rb.Write([]byte("abc"))
|
|
rb.Write([]byte("defgh")) // total 8, buffer 5
|
|
got := rb.Bytes()
|
|
if string(got) != "defgh" {
|
|
t.Errorf("got %q, want %q", got, "defgh")
|
|
}
|
|
})
|
|
}
|
|
|
|
func TestPTYSessionManager(t *testing.T) {
|
|
t.Run("new manager has no sessions", func(t *testing.T) {
|
|
m := &PTYSessionManager{
|
|
sessions: make(map[string]*PTYSession),
|
|
stopCh: make(chan struct{}),
|
|
}
|
|
if len(m.sessions) != 0 {
|
|
t.Error("expected empty sessions")
|
|
}
|
|
})
|
|
}
|