okami.mom/albedo

git clone https://git.nkp.pet/okami.mom/albedo

Aly Raffaufrefactor(cli): apply Go modernize simplifications02d2013

main
1.8 KiB47 linesraw
1// These regressions exercise card layout and repeated delivery inside the TUI.
2package tui
3
4import (
5	"strings"
6	"testing"
7
8	"albedo/cli/internal/daemon"
9	"albedo/cli/internal/daemon/protocol"
10	"github.com/charmbracelet/x/ansi"
11)
12
13func TestAgentCardReplacesProgressAndDeduplicatesMailAnimation(t *testing.T) {
14	model := NewAgentsViewModel(nil, "parent")
15	model.Width, model.Height = 80, 30
16	child := model.node("child", "scout 界")
17	child.parent = "parent"
18	model.selected = child.id
19	model.layout()
20	activity := daemon.Activity{CurrentRequest: &protocol.AgentRequest{InputID: "task", Text: "map wake paths"}, LatestProgress: new("tracing delivery")}
21	model.apply(daemon.AgentEvent{Type: "activity", Session: child.id, Activity: &activity})
22	activity.LatestProgress = new("checking replay")
23	model.apply(daemon.AgentEvent{Type: "activity", Session: child.id, Activity: &activity})
24	view := ansi.Strip(model.View())
25	if !strings.Contains(view, "map wake paths") || !strings.Contains(view, "checking replay") || strings.Contains(view, "tracing delivery") {
26		t.Fatalf("narrow card did not show current request and progress: %s", view)
27	}
28	for row := range strings.SplitSeq(model.View(), "\n") {
29		if ansi.StringWidth(row) > model.Width {
30			t.Fatalf("card overflowed terminal width: %q", row)
31		}
32	}
33	mail := daemon.AgentEvent{Type: "mail", MailID: "letter", From: "parent", To: "child", Kind: "task", Bytes: 20}
34	model.apply(mail)
35	packets, letters := len(model.packets), len(child.mail)
36	model.apply(mail)
37	if len(model.packets) != packets || len(child.mail) != letters {
38		t.Fatal("a repeated letter produced another animation or mail row")
39	}
40	for range 300 {
41		mail.MailID += "x"
42		model.apply(mail)
43	}
44	if len(model.seenMail) != 256 {
45		t.Fatal("mail identity cache grew past its bound")
46	}
47}