okami.mom/albedo
git clone https://git.nkp.pet/okami.mom/albedo
bb7b485
main
1package tui 2 3import ( 4"strings" 5"testing" 6"time" 7 8"albedo/cli/internal/daemon" 9 tea"charm.land/bubbletea/v2" 10) 11 12func TestEscapeStoppingCompactionReconcilesWhenIdle (t * testing.T ) { 13m := newTestChatModel (t ,& daemon.Session {ID :"s" }) 14m .SetSize (80 ,30 ) 15 16phaseCompacting := daemon .PhaseCompacting 17m .Status .Running ,m .Status .Idle ,m .Status .Phase = true ,false ,& phaseCompacting 18 19// Press esc to stop compaction 20var cmd tea.Cmd 21m ,cmd = m .Update (tea.KeyPressMsg {Code :tea .KeyEscape }) 22if cmd == nil { 23t .Fatal ("expected interrupt command on esc" ) 24 } 25if ! m .Stopping { 26t .Fatal ("expected Stopping to be true after pressing esc" ) 27 } 28if ! strings .Contains (m .statusLine (),"stopping…" ) { 29t .Fatalf ("expected statusLine to show stopping…, got %q" ,m .statusLine ()) 30 } 31 32// Daemon finishes interrupting compaction and emits status idle 33phaseIdle := daemon .PhaseIdle 34m .handleStreamEvent (daemon.StreamEvent { 35Type :"status" , 36Status :& daemon.AgentStatus { 37Running :false , 38Idle :true , 39Phase :& phaseIdle , 40 }, 41 }) 42 43if m .Stopping { 44t .Fatal ("expected Stopping to be false after status became idle" ) 45 } 46if ! m .Stopped { 47t .Fatal ("expected Stopped to be true after stopping was reconciled" ) 48 } 49if strings .Contains (m .statusLine (),"stopping…" ) { 50t .Fatalf ("statusLine still shows stopping… after idle: %q" ,m .statusLine ()) 51 } 52if m .animating () { 53t .Fatal ("expected animating to be false after stopping completed and session is idle" ) 54 } 55} 56 57func TestEscapeStoppingPendingUsersReconcilesWhenSettled (t * testing.T ) { 58m := newTestChatModel (t ,& daemon.Session {ID :"s" }) 59m .SetSize (80 ,30 ) 60m .Status .Running ,m .Status .Idle = false ,true 61m .pendingUsers = []PendingUserTurn { 62 {OperationID :"op-1" ,Text :"queued message" ,At :time .Now ().UnixMilli ()}, 63 } 64 65// Press esc to cancel queued input 66m ,_ = m .Update (tea.KeyPressMsg {Code :tea .KeyEscape }) 67if ! m .Stopping { 68t .Fatal ("expected Stopping to be true after pressing esc with pending users" ) 69 } 70 71// Status event arrives while input is still pending: Stopping remains true 72phaseIdle := daemon .PhaseIdle 73m .handleStreamEvent (daemon.StreamEvent { 74Type :"status" , 75Status :& daemon.AgentStatus { 76Running :false , 77Idle :true , 78Phase :& phaseIdle , 79 }, 80 }) 81if ! m .Stopping { 82t .Fatal ("expected Stopping to stay true while pendingUsers still contains items" ) 83 } 84 85// Receipt settles the input turn 86cancelled := "cancelled" 87m .handleStreamEvent (daemon.StreamEvent { 88Type :"input" , 89Receipt :& daemon.InputReceipt { 90ID :"op-1" , 91Delivery :& cancelled , 92 }, 93 }) 94 95if m .Stopping { 96t .Fatal ("expected Stopping to be false once pending input is settled" ) 97 } 98if ! m .Stopped { 99t .Fatal ("expected Stopped to be true after pending input is settled" ) 100 } 101if m .animating () { 102t .Fatal ("expected animating to be false" ) 103 } 104} 105 106func TestChatStatusPollReconcilesStopping (t * testing.T ) { 107m := newTestChatModel (t ,& daemon.Session {ID :"s" }) 108m .SetSize (80 ,30 ) 109m .Stopping = true 110m .Status .Running ,m .Status .Idle = true ,false 111 112phaseIdle := daemon .PhaseIdle 113status := daemon.AgentStatus { 114Running :false , 115Idle :true , 116Phase :& phaseIdle , 117 } 118m ,_ = m .Update (ChatStatusMsg { 119SessionID :m .SessionID , 120Generation :m .Generation , 121Revision :m .statusRevision , 122Status :& status , 123 }) 124 125if m .Stopping { 126t .Fatal ("expected Stopping to be false after ChatStatusMsg reported idle" ) 127 } 128if ! m .Stopped { 129t .Fatal ("expected Stopped to be true" ) 130 } 131}