c42a19f7d3
Make OpenCode authoring responsive and expand the managed skill references. Add conflict-aware import/export, real-provider reference workflows, and tracked V2 generation for reliable budget accounting.
112 lines
4.2 KiB
Go
112 lines
4.2 KiB
Go
package tui
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.a-wan.net/alan/pipelines/internal/protocol"
|
|
"github.com/charmbracelet/x/ansi"
|
|
)
|
|
|
|
func TestRunGraphStageTitlesShowLatestVisitProgress(t *testing.T) {
|
|
m := New(context.Background(), "")
|
|
m.runDetail = &protocol.RunDetail{RunSummary: protocol.RunSummary{Status: "running"}, Graph: protocol.Graph{Stages: []protocol.Stage{
|
|
{Key: "plan", Edges: map[string]string{"success": "work"}},
|
|
{Key: "work", Edges: map[string]string{"revise": "plan", "success": "report"}},
|
|
{Key: "report", Edges: map[string]string{"success": protocol.SuccessEnd}},
|
|
}}, Steps: []protocol.RunStep{{Stage: "plan", Status: "completed"}, {Stage: "work", Status: "completed"}, {Stage: "plan", Status: "running"}}}
|
|
view := ansi.Strip(strings.Join(m.runGraphLines(120), "\n"))
|
|
for _, want := range []string{"plan ·", "running", "work · ✓ done", "report · ○ pending"} {
|
|
if !strings.Contains(view, want) {
|
|
t.Fatal("stage progress absent", want, view)
|
|
}
|
|
}
|
|
if strings.Contains(view, "plan · ✓ done") {
|
|
t.Fatal("earlier loop visit hid current progress")
|
|
}
|
|
m.runDetail.Steps[2].Status = "failed"
|
|
view = ansi.Strip(strings.Join(m.runGraphLines(120), "\n"))
|
|
if !strings.Contains(view, "plan · ✗ failed") || strings.Contains(view, "running") {
|
|
t.Fatal("progress did not refresh", view)
|
|
}
|
|
}
|
|
|
|
func TestRunGraphRetainsDiagramInsteadOfListWhenOversized(t *testing.T) {
|
|
m := New(context.Background(), "")
|
|
m.width, m.height = 120, 40
|
|
m.runDetail = &protocol.RunDetail{Graph: protocol.Graph{Stages: []protocol.Stage{
|
|
{Key: "sum", Edges: map[string]string{"success": "multiply", "error": protocol.FailureEnd}},
|
|
{Key: "multiply", Edges: map[string]string{"success": "parity"}},
|
|
{Key: "parity", Edges: map[string]string{"odd": "add_one", "even": "halve"}},
|
|
{Key: "halve", Edges: map[string]string{"success": "report"}},
|
|
{Key: "add_one", Edges: map[string]string{"success": "report"}},
|
|
{Key: "report", Edges: map[string]string{"success": protocol.SuccessEnd}},
|
|
}}}
|
|
view := ansi.Strip(strings.Join(m.runGraphLines(116), "\n"))
|
|
for _, want := range []string{"sum · ○ pending", "halve · ○ pending", "add_one · ○ pending", "SUCCESS", "FAILURE", "╭", "╰", "▶", "│"} {
|
|
if !strings.Contains(view, want) {
|
|
t.Fatal("graph lost diagram or stage", want, view)
|
|
}
|
|
}
|
|
if view != ansi.Strip(strings.Join(m.runGraphLines(30), "\n")) {
|
|
t.Fatal("small viewport replaced the diagram")
|
|
}
|
|
if !strings.Contains(ansi.Strip(m.runGraphPanel(20, 0, 0)), "h/j/k/l pan") {
|
|
t.Fatal("oversized diagram is not pannable")
|
|
}
|
|
}
|
|
|
|
func TestRunGraphCentersDiagramWhenItFits(t *testing.T) {
|
|
m := New(context.Background(), "")
|
|
m.width = 200
|
|
m.runDetail = &protocol.RunDetail{Graph: protocol.Graph{Stages: []protocol.Stage{{Key: "one", Edges: map[string]string{"success": protocol.SuccessEnd}}}}}
|
|
view := ansi.Strip(m.runGraphPanel(50, 999, 999))
|
|
if strings.Contains(view, "h/j/k/l pan") {
|
|
t.Fatal("fitting graph still requires panning")
|
|
}
|
|
for _, line := range strings.Split(view, "\n") {
|
|
if strings.Contains(line, "one ·") && strings.Index(line, "one ·") < 30 {
|
|
t.Fatal("diagram not centered", line)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestRunTabCycleAndGraphPanning(t *testing.T) {
|
|
m := runInspectionModel()
|
|
m.width, m.height = 40, 24
|
|
for i := 0; i < 30; i++ {
|
|
m.runDetail.Graph.Stages = append(m.runDetail.Graph.Stages, protocol.Stage{Key: fmt.Sprintf("node_%02d", i), Edges: map[string]string{"success": protocol.SuccessEnd}})
|
|
}
|
|
m = runKey(m, "tab")
|
|
if !m.runGraphFocus || m.runDetailFocus {
|
|
t.Fatal("Tab did not focus graph")
|
|
}
|
|
m = runKey(m, "j")
|
|
if m.runGraphTop == 0 {
|
|
t.Fatal("j did not pan graph vertically")
|
|
}
|
|
m = runKey(m, "l")
|
|
if m.runGraphPan == 0 {
|
|
t.Fatal("l did not pan graph horizontally")
|
|
}
|
|
m = runKey(m, "h")
|
|
m = runKey(m, "k")
|
|
if m.runGraphPan != 0 || m.runGraphTop != 0 {
|
|
t.Fatal("h/k did not pan back")
|
|
}
|
|
m = runKey(m, "tab")
|
|
if m.runGraphFocus || !m.runDetailFocus {
|
|
t.Fatal("Tab did not return directly to details")
|
|
}
|
|
m = runKey(m, "shift+tab")
|
|
if !m.runGraphFocus {
|
|
t.Fatal("reverse Tab cycle skipped graph")
|
|
}
|
|
view := ansi.Strip(m.runGraphPanel(10, 0, 0))
|
|
if !strings.Contains(view, "h/j/k/l") {
|
|
t.Fatal("oversized graph omitted pan hint", view)
|
|
}
|
|
}
|