feat: complete Go port with go-te terminal emulator
Full Go implementation under go/ replacing Python pyte with go-te: - HTTP server with WebSocket protocol, SSE, screenshot SVG rendering - PTY terminal sessions and Docker exec sessions - Docker watcher (label-based container discovery + event stream) - CPU stats collection with sparkline SVG rendering - Session manager with TwoWayMap routing and replay buffers - C1 normalization, DA filtering, identity generation, theme palettes Audit fixes for 9 concurrency/correctness issues: - HTTP transport leak: shared client pool for Docker socket calls - WebSocket concurrent writes: all writes routed through send channel - Closed channel panic: atomic.Bool guard on enqueueWSData - GetFirstRunningSession: use UnsafeForward under SessionManager lock - NewSession TOCTOU: re-check routeKey after re-acquiring lock - waitErr data race: protect with mutex in both session types - Replay buffer fragmentation: copy to new slice on eviction - go-te dirty tracking: check screen.Dirty before incrementing counter - Identity modulo bias: rejection sampling for uniform distribution All Go tests pass (including -race). Python baseline unchanged (397 tests). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package terminalstate
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestTrackerSnapshotChangeTracking(t *testing.T) {
|
||||
tracker := NewTracker(10, 3)
|
||||
if err := tracker.Feed([]byte("hi")); err != nil {
|
||||
t.Fatalf("Feed() error = %v", err)
|
||||
}
|
||||
|
||||
snapshot := tracker.Snapshot()
|
||||
if !snapshot.HasChanges {
|
||||
t.Fatalf("expected first snapshot to report changes")
|
||||
}
|
||||
if got := snapshot.Buffer[0][0].Data; got != "h" {
|
||||
t.Fatalf("expected first cell to be h, got %q", got)
|
||||
}
|
||||
if got := snapshot.Buffer[0][1].Data; got != "i" {
|
||||
t.Fatalf("expected second cell to be i, got %q", got)
|
||||
}
|
||||
|
||||
again := tracker.Snapshot()
|
||||
if again.HasChanges {
|
||||
t.Fatalf("expected second snapshot without new input to report no changes")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTrackerAnsiStyles(t *testing.T) {
|
||||
tracker := NewTracker(10, 3)
|
||||
if err := tracker.Feed([]byte("\x1b[31;1mA\x1b[0m")); err != nil {
|
||||
t.Fatalf("Feed() error = %v", err)
|
||||
}
|
||||
snapshot := tracker.Snapshot()
|
||||
cell := snapshot.Buffer[0][0]
|
||||
if !cell.Bold {
|
||||
t.Fatalf("expected bold attribute to be true")
|
||||
}
|
||||
if cell.FG != "red" {
|
||||
t.Fatalf("expected red foreground, got %q", cell.FG)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTrackerResize(t *testing.T) {
|
||||
tracker := NewTracker(10, 3)
|
||||
tracker.Resize(20, 4)
|
||||
snapshot := tracker.Snapshot()
|
||||
if snapshot.Width != 20 || snapshot.Height != 4 {
|
||||
t.Fatalf("unexpected dimensions: got %dx%d", snapshot.Width, snapshot.Height)
|
||||
}
|
||||
if !snapshot.HasChanges {
|
||||
t.Fatalf("expected resize to mark snapshot as changed")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user