package tui import ( "fmt" "strings" "testing" "git.a-wan.net/alan/pipelines/internal/pipeline" "git.a-wan.net/alan/pipelines/internal/protocol" "github.com/charmbracelet/x/ansi" ) func TestCompactGraphDimensions(t *testing.T) { linear, err := pipeline.Parse(pipeline.Template([]string{"plan", "implement_with_a_long_stage_name", "review", "publish"}, true)) if err != nil { t.Fatal(err) } for name, graph := range map[string]protocol.Graph{"linear": linear, "nested": nestedForkGraph(t)} { layout := layoutGraph(graph) t.Logf("%s: %d columns × %d rows", name, layout.width, layout.height) // Before compaction: linear 175×15; nested forks 147×48. Sharing input // and outcome rows trades a little width for substantially less height. if name == "linear" && (layout.width > 108 || layout.height > 12) { t.Fatal("linear graph grew", layout.width, layout.height) } if name == "nested" && (layout.width > 134 || layout.height > 32) { t.Fatal("fork graph grew", layout.width, layout.height) } assertForkRouteClearance(t, layout) view := ansi.Strip(strings.Join(renderGraph(graph), "\n")) for _, stage := range graph.Stages { if !strings.Contains(view, stage.Key) { t.Fatal("compaction lost stage", stage.Key) } } for _, edge := range layout.edges { if !strings.Contains(view, fmt.Sprintf("%s [%d]", edge.label, edge.id)) { t.Fatal("compaction lost outcome", edge) } if !edge.topEntry { for _, node := range layout.nodes { if node.key == edge.target { line := renderGraph(graph)[edge.to] input := ansi.Strip(ansi.Cut(line, node.x+2, node.x+2+len(fmt.Sprintf("[%d]", edge.id)))) if input != fmt.Sprintf("[%d]", edge.id) { t.Fatal("paired outcome overwrote input ID", edge, input) } } } } } } }