okami.mom/albedo
git clone https://git.nkp.pet/okami.mom/albedo
5b3f8be
main
1package e2e 2 3import ( 4"encoding/json" 5"fmt" 6"strings" 7"testing" 8 9"albedo/cli/internal/daemon" 10"albedo/cli/internal/tui" 11 tea"charm.land/bubbletea/v2" 12) 13 14func pastedLines (label string ,count int )string { 15lines := make ([]string ,count ) 16for i := range lines { 17lines [i ]= fmt .Sprintf ("%s line %d" ,label ,i ) 18 } 19return strings .Join (lines ,"\n" ) 20} 21 22func TestTUIPastesAndImagesBecomeMarkersTheModelReceivesInPlace (t * testing.T ) { 23profile := providerRoute (t ,echoReply ) 24t .Parallel () 25driver := newTUIDriver (t ) 26t .Cleanup (func () {driver .App .Chat .Close () }) 27driver .connected () 28chat := func ()* tui.ChatModel {return & driver .App .Chat } 29 30logs := pastedLines ("log" ,30 ) 31driver .Type ("first " ) 32driver .Update (tea.PasteMsg {Content :logs }) 33driver .Update (tea.PasteMsg {Content :pastedLines ("dropped" ,12 )}) 34if got := chat ().TextArea .Value ();got != "first [Paste #1, +30 lines][Paste #2, +12 lines]" { 35t .Fatalf ("pastes did not collapse into markers: %q" ,got ) 36 } 37driver .Update (tea.KeyPressMsg {Code :tea .KeyBackspace }) 38if got := chat ().TextArea .Value ();got != "first [Paste #1, +30 lines]" { 39t .Fatalf ("one backspace did not remove the whole marker: %q" ,got ) 40 } 41driver .pasteImage (& daemon.ImageAttachment {Data :"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAADElEQVR4nGP4z8AAAAMBAQDJ/pLvAAAAAElFTkSuQmCC" ,ImageMetadata : daemon.ImageMetadata {MimeType :daemon .ImagePNG ,Width :1 ,Height :1 ,Bytes :69 }}) 42driver .Type (" end" ) 43view := driver .View () 44for _ ,want := range []string {"paste #1" ,"+30 lines" ,"log line 0" ,"image #1" ,"1×1" } { 45if ! strings .Contains (view ,want ) { 46t .Fatalf ("the attachment strip lacks %q:\n%s" ,want ,view ) 47 } 48 } 49 50var sent tui.ChatTurnSentMsg 51for _ ,message := range driver .results (driver .Update (tea.KeyPressMsg {Code :tea .KeyEnter })) { 52if result ,ok := message .(tui.ChatTurnSentMsg );ok { 53sent = result 54 } 55driver .Update (message ) 56 } 57if sent .Err != nil || sent .Prompt != "first [Paste #1, +30 lines][Image #1] end" || len (sent .Pastes )!= 1 || len (sent .Images )!= 1 { 58t .Fatalf ("submission lost its attachments: %+v" ,sent ) 59 } 60waitIdle (t ,chat ().SessionID ,profile ,1 ) 61requests := suite .provider .requests (profile ) 62body ,_ := json .Marshal (requests [len (requests )- 1 ]) 63want ,_ := json .Marshal ("first " + logs + "[Image #1] end" ) 64if ! strings .Contains (string (body ),string (want )) { 65t .Fatalf ("the model did not receive the paste in place:\n%s" ,body ) 66 } 67}