okami.mom/albedo
git clone https://git.nkp.pet/okami.mom/albedo
647d18b
main
1// TUI routing and in-flight save rendering cannot be exercised by daemon E2E 2// tests. These checks keep display text from controlling either state machine. 3package tui 4 5import ( 6"albedo/cli/internal/daemon" 7"errors" 8"fmt" 9"strings" 10"testing" 11 12 tea"charm.land/bubbletea/v2" 13"github.com/charmbracelet/x/ansi" 14) 15 16func TestCatalogFailureUsesErrorIdentity (t * testing.T ) { 17for _ ,tc := range []struct { 18err error 19show bool 20 }{ 21 {fmt .Errorf ("catalog: %w" ,& daemon.UpgradeRequiredError {Feature :"for commands" }),true }, 22 {errors .New ("unrelated service needs an update" ),false }, 23 } { 24m := & AppModel {} 25next ,_ := m .Update (commandCatalogLoadedMsg {Err :tc .err }) 26if next .(* AppModel ).Notices .HasError ()!= tc .show { 27t .Fatalf ("catalog failure was routed using its wording: %v" ,tc .err ) 28 } 29 } 30} 31 32func TestExtensionSaveHidesConfirmationUntilFailure (t * testing.T ) { 33m := NewExtensionPickerModel (nil ,"session" ) 34m .Loading = false 35m .SetSize (80 ,20 ) 36m .setExtensions ([]ExtensionItem {{Name :"webhooks" }}) 37m ,_ = m .Update (tea.KeyPressMsg {Code :tea .KeyEnter ,Mod :tea .ModShift }) 38m ,cmd := m .Update (tea.KeyPressMsg {Code :tea .KeyEnter }) 39if ! m .Saving || cmd == nil { 40t .Fatal ("confirmation did not start the save" ) 41 } 42view := ansi .Strip (m .View ()) 43if ! strings .Contains (view ,"saving" )|| strings .Contains (view ,"cancel" )|| strings .Contains (view ,"confirm" ) { 44t .Fatalf ("in-flight save still offers confirmation: %s" ,view ) 45 } 46m ,_ = m .Update (extensionToggledMsg {Gen :m .Generation ,Err :errors .New ("save failed" )}) 47if m .Saving || ! m .Confirming ()|| ! strings .Contains (ansi .Strip (m .View ()),"retry" ) { 48t .Fatal ("failed save did not restore the retry prompt" ) 49 } 50}