okami.mom/albedo
git clone https://git.nkp.pet/okami.mom/albedo
2ce1ecd
main
1// Queued and failed continue events must not corrupt the TUI transcript. 2package tui 3 4import ( 5"errors" 6"strings" 7"testing" 8"time" 9 10"albedo/cli/internal/daemon" 11 tea"charm.land/bubbletea/v2" 12"github.com/charmbracelet/x/ansi" 13) 14 15func TestDotContinueDoesNotAppearInUI (t * testing.T ) { 16m := newTestChatModel (t ,& daemon.Session {ID :"s" }) 17m .SetSize (80 ,30 ) 18m .appendSettledEntry (HistoryEntry {Kind :EntryAssistant ,Speaker :"albedo" ,Text :"ready" ,Timestamp :time .Now ().UnixMilli ()- 1000 }) 19 20var cmds []tea.Cmd 21m .submitInput ("." ,& cmds ) 22 23if len (m .pendingUsers )!= 0 { 24t .Fatalf ("expected 0 pending users for dot continue, got %d" ,len (m .pendingUsers )) 25 } 26if len (m .pendingRows ())!= 0 { 27t .Fatalf ("expected 0 pending rows for dot continue, got %d" ,len (m .pendingRows ())) 28 } 29afterView := ansi .Strip (m .Viewport .View ()) 30if strings .Contains (afterView ,"│ ." )|| strings .Contains (afterView ,"│ continue" )|| strings .Contains (afterView ,"│ you" ) { 31t .Fatalf ("transcript should not contain dot or continue prompt:\n%s" ,afterView ) 32 } 33if ! m .isSending { 34t .Fatal ("expected isSending to be true" ) 35 } 36if len (cmds )== 0 { 37t .Fatal ("expected cmds to be returned for continue submission" ) 38 } 39} 40 41func TestDotContinueErrorDoesNotCorruptPendingUsers (t * testing.T ) { 42m := newTestChatModel (t ,& daemon.Session {ID :"s" }) 43m .pendingUsers = []PendingUserTurn {{Text :"real user prompt" ,At :time .Now ().UnixMilli ()}} 44m .TextArea .SetValue ("" ) 45 46errMsg := ChatTurnSentMsg { 47SessionID :"s" , 48Generation :m .Generation , 49Prompt :"." , 50Continue :true , 51Err :errors .New ("network failure" ), 52 } 53 54um ,_ := m .Update (errMsg ) 55 56if len (um .pendingUsers )!= 1 || um .pendingUsers [0 ].Text != "real user prompt" { 57t .Fatalf ("pending user turn was corrupted or popped: %+v" ,um .pendingUsers ) 58 } 59if um .TextArea .Value ()== "." { 60t .Fatalf ("text area was overwritten with dot: %q" ,um .TextArea .Value ()) 61 } 62} 63 64func TestMessageSubmitClearsTurnFailed (t * testing.T ) { 65m := newTestChatModel (t ,& daemon.Session {ID :"s" }) 66m .SetSize (80 ,30 ) 67m .TurnFailed = true 68m .Stopped = true 69 70var cmds []tea.Cmd 71m .submitInput ("retry prompt" ,& cmds ) 72 73if m .TurnFailed { 74t .Fatal ("expected TurnFailed to be false after submitting input" ) 75 } 76if m .Stopped { 77t .Fatal ("expected Stopped to be false after submitting input" ) 78 } 79if ! m .isSending || len (m .pendingUsers )!= 1 || m .pendingUsers [0 ].Text != "retry prompt" || len (cmds )== 0 { 80t .Fatal ("retry did not start a new submission" ) 81 } 82} 83 84func TestDotContinueClearsTurnFailed (t * testing.T ) { 85m := newTestChatModel (t ,& daemon.Session {ID :"s" }) 86m .SetSize (80 ,30 ) 87m .TurnFailed = true 88m .Stopped = true 89 90var cmds []tea.Cmd 91m .submitInput ("." ,& cmds ) 92 93if m .TurnFailed { 94t .Fatal ("expected TurnFailed to be false after submitting dot continue" ) 95 } 96if m .Stopped { 97t .Fatal ("expected Stopped to be false after submitting dot continue" ) 98 } 99if ! m .isSending || len (cmds )== 0 { 100t .Fatal ("continue did not start a new submission" ) 101 } 102}