bd09c55c47
Integrates nine commits of reviewed work from the lane-go branch after the automated resolver failed on this merge five times (each attempt dying on the malformed-result defect whose fix is contained in this same merge). Integration decisions: - Search: kept main's shipped design (Store.Search + SearchResponse.Results) and dropped lane-go's parallel, older attempt (an unused Message.Matches field, an absent runs.search, and two partial TUI plumbing blocks). lane-go itself did not compile: protocol.SearchMatch was undefined and model.go referenced searchNav, requestSearch and applyRunNav, which exist nowhere. Those partial TUI blocks are removed; the queued TUI omni-search item will implement the surface properly on main's design. - Both sides' additions are kept where they are independent: run titles and provenance, the human decision stage and its CLI/TUI surface, the derived stage verdict, the stale-client guard, the line-oriented result format, and main's search command. - The search key's help label is now "/ omni search"; the two tests asserting the old label are updated rather than the label reverted. - docs/cli.md and the packaged operations reference carry both sides' text. Verified: go build ./... , go vet ./... and the full go test ./... suite pass.
102 lines
3.2 KiB
Go
102 lines
3.2 KiB
Go
package tui
|
|
|
|
import (
|
|
"context"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
tea "github.com/charmbracelet/bubbletea"
|
|
"github.com/charmbracelet/lipgloss"
|
|
"github.com/charmbracelet/x/ansi"
|
|
|
|
"git.a-wan.net/alan/pipelines/internal/server"
|
|
)
|
|
|
|
func TestTKeyPingRoundTrip(t *testing.T) {
|
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
|
defer cancel()
|
|
srv := httptest.NewServer(server.Handler(ctx))
|
|
defer srv.Close()
|
|
m := New(ctx, "ws"+strings.TrimPrefix(srv.URL, "http")+"/connect")
|
|
connected := m.connect()()
|
|
if _, ok := connected.(connectedMsg); !ok {
|
|
t.Fatalf("connect: %#v", connected)
|
|
}
|
|
defer connected.(connectedMsg).conn.CloseNow()
|
|
updated, read := m.Update(connected)
|
|
m = updated.(Model)
|
|
if m.status != strings.TrimPrefix(srv.URL, "http://") {
|
|
t.Fatalf("connected status = %q, want server host and port", m.status)
|
|
}
|
|
for i := 0; i < 2; i++ {
|
|
updated, send := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'t'}})
|
|
m = updated.(Model)
|
|
if _, ok := send().(sentMsg); !ok {
|
|
t.Fatal("ping command failed")
|
|
}
|
|
response := read()
|
|
if _, ok := response.(socketMsg); !ok {
|
|
t.Fatalf("read: %#v", response)
|
|
}
|
|
updated, read = m.Update(response)
|
|
m = updated.(Model)
|
|
}
|
|
if text := strings.Join(m.lines, "\n"); !strings.Contains(text, "pong #1:") || !strings.Contains(text, "pong #2:") {
|
|
t.Fatalf("missing responses: %s", text)
|
|
}
|
|
_, quit := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'q'}})
|
|
if quit != nil {
|
|
t.Fatal("q should not quit")
|
|
}
|
|
}
|
|
|
|
func TestPingBeforeConnection(t *testing.T) {
|
|
m := New(context.Background(), "ws://localhost/connect")
|
|
updated, cmd := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'t'}})
|
|
if cmd != nil || !strings.Contains(strings.Join(updated.(Model).lines, "\n"), "not connected") {
|
|
t.Fatal("expected disconnected message without sending")
|
|
}
|
|
}
|
|
|
|
func TestLayoutResizes(t *testing.T) {
|
|
for _, size := range []tea.WindowSizeMsg{
|
|
{Width: 80, Height: 24},
|
|
{Width: 40, Height: 8},
|
|
{Width: 12, Height: 4},
|
|
{Width: 1, Height: 1},
|
|
} {
|
|
m := New(context.Background(), "ws://localhost/connect")
|
|
m.status = "127.0.0.1:8080"
|
|
for i := 0; i < 20; i++ {
|
|
m.appendLine(strings.Repeat("x", 100))
|
|
}
|
|
updated, _ := m.Update(size)
|
|
view := ansi.Strip(updated.View())
|
|
lines := strings.Split(view, "\n")
|
|
if len(lines) != size.Height {
|
|
t.Fatalf("%+v: height = %d, view = %q", size, len(lines), view)
|
|
}
|
|
for _, line := range lines {
|
|
if lipgloss.Width(line) > size.Width {
|
|
t.Fatalf("%+v: line too wide: %q", size, line)
|
|
}
|
|
}
|
|
if size.Width >= 40 {
|
|
if !strings.HasPrefix(lines[0], "Pipelines ") || !strings.HasSuffix(lines[0], "127.0.0.1:8080") || lipgloss.Width(lines[0]) != size.Width {
|
|
t.Fatalf("invalid header: %q", lines[0])
|
|
}
|
|
if !strings.HasPrefix(lines[len(lines)-1], "/ omni search") || !strings.Contains(lines[len(lines)-1], ": commands") || !strings.Contains(lines[len(lines)-1], "● 20 NEW") {
|
|
t.Fatalf("invalid footer: %q", lines[len(lines)-1])
|
|
}
|
|
if strings.TrimSpace(lines[len(lines)-2]) != "" {
|
|
t.Fatal("footer should have breathing room rather than a rule")
|
|
}
|
|
if strings.TrimSpace(lines[1]) != "" {
|
|
t.Fatal("header should have breathing room rather than a rule")
|
|
}
|
|
}
|
|
}
|
|
}
|