diff --git a/README.md b/README.md index 2e86a8dc..1b4bbc5b 100644 --- a/README.md +++ b/README.md @@ -127,5 +127,6 @@ From a run, press **p** / **:pipeline** to open the pipeline version it used. Initial run input also records `pwd`. Press **r** / **:retry** on a failed run (or `pipelines retry `) to start a new attempt with the same original input, directory, and pipeline version. Completed side effects are not undone. +On Home, **r** opens the failed-only runs list; both Home panels show the shortcut. More: [CLI](docs/cli.md) · [installation](docs/install.md) · [pipeline format](internal/author/skill/references/format.md). diff --git a/internal/tui/dashboard.go b/internal/tui/dashboard.go index 4c846dae..4dd75ac1 100644 --- a/internal/tui/dashboard.go +++ b/internal/tui/dashboard.go @@ -38,6 +38,7 @@ func (m Model) footerContent() string { func (m Model) homeLines() []string { runs := []string{bar("Latest runs", fmt.Sprint(len(m.runs)), max(1, m.width-4), true), + "r failed runs", lipgloss.NewStyle().Foreground(themeMuted).Render("Pipeline · Version · Outcome · Finished"), "Inspect with :runs; open a pipeline then :run to start."} if len(m.runs) == 0 { @@ -46,7 +47,7 @@ func (m Model) homeLines() []string { for _, r := range m.runs { runs = append(runs, fmt.Sprintf("#%d %s · v%d · %s · %s", r.ID, r.Name, r.Version, m.progress(r.Status), r.FinishedAt)) } - lines := []string{bar("Existing pipelines", fmt.Sprintf("%d", len(m.pipelines)), max(1, m.width-4), true), ""} + lines := []string{bar("Existing pipelines", fmt.Sprintf("%d", len(m.pipelines)), max(1, m.width-4), true), "r failed runs", ""} if !m.loaded { lines = append(lines, "Waiting for pipeline data…") } else if len(m.pipelines) == 0 { @@ -160,6 +161,7 @@ func (m Model) updatePalette(msg tea.KeyMsg) (tea.Model, tea.Cmd) { case ":run": return m.beginRun() case ":runs": + m.runFailedOnly = false m.runPipelineID = 0 m.runOpen = true m.keys.runs = true diff --git a/internal/tui/home_failed_runs_test.go b/internal/tui/home_failed_runs_test.go new file mode 100644 index 00000000..19955f8b --- /dev/null +++ b/internal/tui/home_failed_runs_test.go @@ -0,0 +1,95 @@ +package tui + +import ( + "context" + "net/http/httptest" + "strings" + "testing" + "time" + + "git.a-wan.net/alan/pipelines/internal/protocol" + "git.a-wan.net/alan/pipelines/internal/server" + tea "github.com/charmbracelet/bubbletea" + "github.com/charmbracelet/x/ansi" +) + +func TestHomeShortcutOpensFailedRunsAndDisplaysHintInBothPanels(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()().(connectedMsg) + defer connected.conn.CloseNow() + updated, _ := m.Update(connected) + m = updated.(Model) + m.width = 120 + m.height = 40 + m.runs = []protocol.RunSummary{{ID: 1, Status: "succeeded", Name: "passed"}, {ID: 2, Status: "failed", Name: "broken"}, {ID: 3, Status: "running", Name: "active"}, {ID: 4, Status: "canceled", Name: "canceled"}, {ID: 5, Status: "failed", Name: "also broken"}} + view := ansi.Strip(strings.Join(m.homeLines(), "\n")) + if strings.Count(view, "r failed runs") != 2 { + t.Fatal("missing shortcut in both panels", view) + } + updated, send := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'r'}}) + m = updated.(Model) + if send == nil || !m.runOpen || !m.keys.runs || !m.runFailedOnly || m.runIndex != 0 { + t.Fatal("home shortcut did not open failed list") + } + if _, ok := send().(sentMsg); !ok { + t.Fatal("failed list refresh request failed") + } + visible := m.visibleRuns() + if len(visible) != 2 || visible[0].ID != 2 || visible[1].ID != 5 { + t.Fatal("nonfailed runs leaked into list", visible) + } + view = ansi.Strip(m.runsView(30)) + if !strings.Contains(view, "Failed runs") || strings.Contains(view, "passed") || strings.Contains(view, "active") { + t.Fatal("failed list view is incorrect", view) + } + updated, cmd := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'r'}}) + m = updated.(Model) + if cmd == nil || m.runStartRequest == "" { + t.Fatal("r on failed list no longer retries") + } + m.closeRuns() + if m.runFailedOnly { + t.Fatal("failed filter leaked after closing list") + } + updated, _ = m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'r'}}) + m = updated.(Model) + m.commandInput = newInput() + m.commandInput.SetValue(":runs") + updated, _ = m.updatePalette(tea.KeyMsg{Type: tea.KeyEnter}) + m = updated.(Model) + if m.runFailedOnly || len(m.visibleRuns()) != 5 { + t.Fatal("normal runs command retained failed filter") + } +} + +func TestFailedRunsEmptyAndRefreshRemainFiltered(t *testing.T) { + m := New(context.Background(), "") + m.width = 100 + m.runOpen = true + m.keys.runs = true + m.runFailedOnly = true + if !strings.Contains(ansi.Strip(m.runsView(20)), "No failed runs.") { + t.Fatal("missing failed-only empty state") + } + updated, _ := m.Update(receivedMsg(protocol.Message{Type: protocol.Runs, Runs: []protocol.RunSummary{{ID: 1, Status: "running"}, {ID: 2, Status: "failed"}}})) + m = updated.(Model) + if visible := m.visibleRuns(); len(visible) != 1 || visible[0].ID != 2 { + t.Fatal("refresh lost failed filter", visible) + } + m.runDetail = &protocol.RunDetail{RunSummary: m.visibleRuns()[0]} + m.requestedRunID = 2 + updated, _ = m.Update(tea.KeyMsg{Type: tea.KeyEsc}) + m = updated.(Model) + if !m.runOpen || !m.runFailedOnly || m.runDetail != nil { + t.Fatal("back from inspector lost failed list") + } + updated, _ = m.Update(tea.KeyMsg{Type: tea.KeyEsc}) + m = updated.(Model) + if !m.homePage() || m.runFailedOnly { + t.Fatal("failed list did not return home") + } +} diff --git a/internal/tui/model.go b/internal/tui/model.go index 593418ae..f817ecdb 100644 --- a/internal/tui/model.go +++ b/internal/tui/model.go @@ -80,7 +80,7 @@ func (k keyMap) ShortHelp() []key.Binding { if k.detail { return []key.Binding{k.commands, k.search, key.NewBinding(key.WithKeys("n", "p"), key.WithHelp("n/p", "next/prev stage")), key.NewBinding(key.WithKeys("tab"), key.WithHelp("Tab", "pane")), key.NewBinding(key.WithKeys("r"), key.WithHelp("r", "runs")), key.NewBinding(key.WithKeys("j", "k"), key.WithHelp("j/k", "scroll")), key.NewBinding(key.WithKeys("esc"), key.WithHelp("esc", "home"))} } - return []key.Binding{k.commands, k.search, k.create, key.NewBinding(key.WithKeys("d"), key.WithHelp("d", "drafts")), key.NewBinding(key.WithKeys("b"), key.WithHelp("b", "templates")), k.ping, k.quit} + return []key.Binding{k.commands, k.search, k.create, key.NewBinding(key.WithKeys("r"), key.WithHelp("r", "failed runs")), key.NewBinding(key.WithKeys("d"), key.WithHelp("d", "drafts")), key.NewBinding(key.WithKeys("b"), key.WithHelp("b", "templates")), k.ping, k.quit} } func (k keyMap) FullHelp() [][]key.Binding { return [][]key.Binding{k.ShortHelp()} } @@ -150,6 +150,7 @@ type Model struct { runCollapsed map[string]bool runError string runPipelineID int64 + runFailedOnly bool runSpinner spinner.Model templates []protocol.Template templateOpen, templateRaw bool @@ -463,6 +464,13 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m.updateTemplates(msg) } switch { + case m.homePage() && msg.String() == "r": + m.closeRuns() + m.runFailedOnly = true + m.runOpen = true + m.keys.runs = true + m.runIndex = 0 + return m.runRequest(protocol.Message{Type: protocol.ListRuns}) case m.homePage() && msg.String() == "d": return m.openDrafts() case m.homePage() && msg.String() == "b": diff --git a/internal/tui/pipeline.go b/internal/tui/pipeline.go index ec20685b..acc75471 100644 --- a/internal/tui/pipeline.go +++ b/internal/tui/pipeline.go @@ -204,6 +204,7 @@ func (m Model) updatePipeline(msg tea.KeyMsg) (tea.Model, tea.Cmd) { case "v": return m.openVersions() case "r": + m.runFailedOnly = false m.runOpen = true m.keys.runs = true m.runPipelineID = m.requestedPipelineID diff --git a/internal/tui/run_detail.go b/internal/tui/run_detail.go index 1c423a24..9a34cfa8 100644 --- a/internal/tui/run_detail.go +++ b/internal/tui/run_detail.go @@ -88,15 +88,16 @@ func (m *Model) closeRuns() { m.runTop = 0 m.runDetailFocus = false m.runPipelineID = 0 + m.runFailedOnly = false } func (m Model) visibleRuns() []protocol.RunSummary { - if m.runPipelineID == 0 { + if m.runPipelineID == 0 && !m.runFailedOnly { return m.runs } var runs []protocol.RunSummary for _, run := range m.runs { - if run.PipelineID == m.runPipelineID { + if (m.runPipelineID == 0 || run.PipelineID == m.runPipelineID) && (!m.runFailedOnly || run.Status == "failed") { runs = append(runs, run) } } @@ -371,6 +372,9 @@ func (m Model) runsView(height int) string { if m.runPipelineID > 0 && m.detail != nil { title = "Runs · " + m.detail.Name + " · Esc back" } + if m.runFailedOnly { + title = "Failed runs · Esc back" + } if m.requestedRunID > 0 || m.runStartRequest != "" { return fitBlock([]string{"Loading run…", m.runError, "Esc returns to runs"}, m.width, height) } @@ -384,6 +388,9 @@ func (m Model) runsView(height int) string { } if len(rows) == 0 { rows = append(rows, "No runs yet.") + if m.runFailedOnly { + rows[0] = "No failed runs." + } } if m.runError != "" { rows = append(rows, m.runError)