okami.mom/albedo

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

nekomimi.pettest(e2e): run session-scoped Go scenarios in parallel5b3f8be

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