TUI: Closed column, legacy 30m stale window, filtered-view fix, header shown-count, toggle tests
This commit is contained in:
54
main_test.go
54
main_test.go
@@ -7,6 +7,8 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
|
||||
// Simulates the remote `cat *.json` output: several pretty-printed,
|
||||
@@ -117,4 +119,56 @@ func TestSortSmart(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// x toggles hiding of closed sessions both ways.
|
||||
func TestHideClosedToggle(t *testing.T) {
|
||||
now := time.Now().UTC().Format(time.RFC3339)
|
||||
live := AgentState{Session: "live", AgentStatus: "idle", SessionState: "open", LastSeenAt: &now, PID: 1}
|
||||
dead := AgentState{Session: "dead", AgentStatus: "idle", SessionState: "closed", LastSeenAt: &now, PID: 2}
|
||||
|
||||
m := initialModel(defaultConfig())
|
||||
m.agents = []AgentState{live, dead}
|
||||
m.updateTable()
|
||||
if len(m.view) != 2 {
|
||||
t.Fatalf("expected 2 shown initially, got %d", len(m.view))
|
||||
}
|
||||
|
||||
// press x → hide closed
|
||||
m2, _ := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("x")})
|
||||
mm := m2.(model)
|
||||
if !mm.hideClosed {
|
||||
t.Fatal("x should enable hideClosed")
|
||||
}
|
||||
if len(mm.view) != 1 || mm.view[0].Session != "live" {
|
||||
t.Fatalf("expected only live session after hide, got %v", mm.view)
|
||||
}
|
||||
|
||||
// press x again → unhide
|
||||
m3, _ := mm.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("x")})
|
||||
mmm := m3.(model)
|
||||
if mmm.hideClosed {
|
||||
t.Fatal("x should toggle hideClosed back off")
|
||||
}
|
||||
if len(mmm.view) != 2 {
|
||||
t.Fatalf("expected 2 shown after unhide, got %d", len(mmm.view))
|
||||
}
|
||||
}
|
||||
|
||||
// A legacy (pre-heartbeat) live session must not be marked lost within the
|
||||
// legacy window, even though it has no real heartbeat.
|
||||
func TestLegacyWindow(t *testing.T) {
|
||||
// mtime-based heartbeat, 5 minutes old: legacy window is 30m → live
|
||||
fiveMin := time.Now().UTC().Add(-5 * time.Minute).Format(time.RFC3339)
|
||||
legacyLive := AgentState{Session: "old-ext-session", Status: "running", LastSeenAt: &fiveMin}
|
||||
if legacyLive.IsClosed(45 * time.Second) {
|
||||
t.Fatal("legacy session with 5m-old mtime should be live (30m window)")
|
||||
}
|
||||
|
||||
// 2 hours old → closed
|
||||
twoHours := time.Now().UTC().Add(-2 * time.Hour).Format(time.RFC3339)
|
||||
legacyDead := AgentState{Session: "old-dead", Status: "running", LastSeenAt: &twoHours}
|
||||
if !legacyDead.IsClosed(45 * time.Second) {
|
||||
t.Fatal("legacy session with 2h-old mtime should be closed")
|
||||
}
|
||||
}
|
||||
|
||||
func strptr(s string) *string { return &s }
|
||||
|
||||
Reference in New Issue
Block a user