Show full audited run graphs and scope searchable run history
This commit is contained in:
@@ -2,14 +2,87 @@ package tui
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/charmbracelet/x/ansi"
|
||||
"github.com/muesli/termenv"
|
||||
)
|
||||
|
||||
func TestRunFullGraphDimsUnexecutedBranchesAndRoutes(t *testing.T) {
|
||||
previous := lipgloss.ColorProfile()
|
||||
lipgloss.SetColorProfile(termenv.ANSI)
|
||||
defer lipgloss.SetColorProfile(previous)
|
||||
m := New(context.Background(), "")
|
||||
m.width = 120
|
||||
graph := protocol.Graph{Stages: []protocol.Stage{
|
||||
{Key: "parity", Edges: map[string]string{"odd": "add_one", "even": "halve", "error": protocol.FailureEnd}},
|
||||
{Key: "add_one", Edges: map[string]string{"success": "report", "revise": "parity"}},
|
||||
{Key: "halve", Edges: map[string]string{"success": "report"}},
|
||||
{Key: "report", Edges: map[string]string{"success": protocol.SuccessEnd}},
|
||||
}}
|
||||
m.runDetail = &protocol.RunDetail{Graph: graph, Steps: []protocol.RunStep{
|
||||
{Sequence: 1, Stage: "parity", Outcome: "odd", Target: "add_one"},
|
||||
{Sequence: 2, Stage: "add_one", Outcome: "revise", Target: "parity"},
|
||||
{Sequence: 3, Stage: "parity", Outcome: "odd", Target: "add_one"},
|
||||
{Sequence: 4, Stage: "add_one", Outcome: "success", Target: "report"},
|
||||
{Sequence: 5, Stage: "report", Outcome: "success", Target: protocol.SuccessEnd},
|
||||
}}
|
||||
// An unrelated/open latest definition must not replace this run's graph.
|
||||
m.detail = &protocol.PipelineDetail{Graph: protocol.Graph{Stages: []protocol.Stage{{Key: "latest"}}}}
|
||||
full, selected, appearance := m.runGraphState()
|
||||
if len(full.Stages) != 4 || selected != "report" || appearance.nodes["halve"] || !appearance.nodes["parity"] {
|
||||
t.Fatal("full graph or visitation state lost", full, selected, appearance)
|
||||
}
|
||||
rows := m.runGraphLines(116)
|
||||
view := strings.Join(rows, "\n")
|
||||
for _, key := range []string{"parity", "add_one", "halve", "report", "SUCCESS", "FAILURE"} {
|
||||
if !strings.Contains(ansi.Strip(view), key) {
|
||||
t.Fatal("missing graph node", key)
|
||||
}
|
||||
}
|
||||
if foregroundAt(t, view, "halve") != 8 || foregroundAt(t, view, "FAILURE") != 8 || foregroundAt(t, view, "SUCCESS") != 2 {
|
||||
t.Fatal("unexecuted nodes/terminals not dimmed", view)
|
||||
}
|
||||
for _, edge := range layoutGraph(full).edges {
|
||||
color := foregroundAt(t, rows[edge.from], fmt.Sprintf("%s [%d]", edge.label, edge.id))
|
||||
taken := appearance.routes[graphRoute{edge.source, edge.outcome, edge.target}]
|
||||
if (color == 8) == taken {
|
||||
t.Fatal("route dimming does not match audited traversal", edge, color, taken)
|
||||
}
|
||||
}
|
||||
m.runStepIndex = 3
|
||||
_, selected, _ = m.runGraphState()
|
||||
if selected != "parity" {
|
||||
t.Fatal("repeated visit selection lost", selected)
|
||||
}
|
||||
// Queued runs still display every node, all dimmed, before the first visit.
|
||||
m.runDetail.Steps = nil
|
||||
_, _, appearance = m.runGraphState()
|
||||
if len(appearance.nodes) != 0 || !strings.Contains(ansi.Strip(strings.Join(m.runGraphLines(116), "\n")), "halve") {
|
||||
t.Fatal("queued graph hidden or marked executed")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCompactRunGraphRetainsDimmedNodes(t *testing.T) {
|
||||
previous := lipgloss.ColorProfile()
|
||||
lipgloss.SetColorProfile(termenv.ANSI)
|
||||
defer lipgloss.SetColorProfile(previous)
|
||||
m := New(context.Background(), "")
|
||||
m.runDetail = &protocol.RunDetail{Steps: []protocol.RunStep{{Stage: "stage_000"}}}
|
||||
for i := 0; i < 201; i++ {
|
||||
m.runDetail.Graph.Stages = append(m.runDetail.Graph.Stages, protocol.Stage{Key: fmt.Sprintf("stage_%03d", i), Edges: map[string]string{"success": protocol.SuccessEnd}})
|
||||
}
|
||||
view := strings.Join(m.runGraphLines(80), "\n")
|
||||
if foregroundAt(t, view, "stage_200") != 8 || foregroundAt(t, view, "stage_000") == 8 {
|
||||
t.Fatal("compact run graph lost dimming")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunPathUsesSharedRendererAndRecordedRoutesWithRepeatedVisits(t *testing.T) {
|
||||
m := New(context.Background(), "")
|
||||
m.width = 120
|
||||
@@ -30,7 +103,7 @@ func TestRunPathUsesSharedRendererAndRecordedRoutesWithRepeatedVisits(t *testing
|
||||
t.Fatal("run graph diverged from common renderer")
|
||||
}
|
||||
view := ansi.Strip(m.runsView(36))
|
||||
if strings.Index(view, "Run path") < 0 || strings.Index(view, "Run path") > strings.Index(view, "Run overview") || !strings.Contains(view, "3. plan (running)") {
|
||||
if strings.Index(view, "Run graph") < 0 || strings.Index(view, "Run graph") > strings.Index(view, "Run overview") || !strings.Contains(view, "3. plan (running)") {
|
||||
t.Fatal("run graph missing above details or current visit not visible", view)
|
||||
}
|
||||
refreshed := *m.runDetail
|
||||
|
||||
Reference in New Issue
Block a user