Files
pipelines/internal/tui/results_test.go
T
alan c42a19f7d3 Improve workflow UI, retain stage diffs, and add portable pipeline transfers
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.
2026-10-10 20:55:42 +01:00

78 lines
3.6 KiB
Go

package tui
import (
"context"
"strings"
"testing"
"git.a-wan.net/alan/pipelines/internal/protocol"
"github.com/charmbracelet/x/ansi"
)
func TestHomeAndPipelineShowRecordedResultsForExactVersion(t *testing.T) {
m := New(context.Background(), "")
m.width, m.height = 140, 48
m.loaded = true
m.pipelines = []protocol.PipelineSummary{{ID: 1, Name: "Maintenance", Version: 2, Stages: 2}}
m.runs = []protocol.RunSummary{
{ID: 12, PipelineID: 1, Version: 2, Name: "Maintenance", Status: "succeeded", ResultPreview: "Added regression coverage", CompletedSteps: 2},
{ID: 11, PipelineID: 1, Version: 1, Status: "succeeded", ResultPreview: "Created the initial report", CompletedSteps: 1},
}
view := ansi.Strip(m.View())
for _, want := range []string{"Result: Added regression coverage", "2 completed visits", "Last run #12"} {
if !strings.Contains(view, want) {
t.Fatal("home missing result", want, view)
}
}
m.detail = &protocol.PipelineDetail{PipelineSummary: m.pipelines[0], LatestVersion: 2, Graph: protocol.Graph{Stages: []protocol.Stage{{Key: "worker", Edges: map[string]string{"success": protocol.SuccessEnd}}}}}
view = ansi.Strip(m.pipelineView(40))
if !strings.Contains(view, "Added regression coverage") || strings.Index(view, "Results") > strings.Index(view, "Graph") {
t.Fatal("pipeline does not lead with results", view)
}
m.detail.Version = 1
view = ansi.Strip(m.pipelineView(40))
if !strings.Contains(view, "Created the initial report") || strings.Contains(view, "Added regression coverage") {
t.Fatal("pipeline mixed version results", view)
}
m.detail.Version = 3
if view = ansi.Strip(m.pipelineView(40)); !strings.Contains(view, "has not run yet") || strings.Contains(view, "Added regression coverage") {
t.Fatal("unexecuted version invented results", view)
}
}
func TestRunLeadsWithResultAndPreservesPartialAccomplishments(t *testing.T) {
m := New(context.Background(), "")
m.width, m.height = 120, 48
m.runDetailFocus = true
r := &protocol.RunDetail{RunSummary: protocol.RunSummary{ID: 1, Name: "Maintenance", Status: "failed", Diagnostic: "Verification timed out"}, Steps: []protocol.RunStep{
{Sequence: 1, Stage: "implement", Status: "completed", Outcome: "success", Output: map[string]any{"summary": "Updated the layout", "artifacts": []string{"screen.go"}}},
{Sequence: 2, Stage: "verify", Status: "failed", Diagnostic: "Verification timed out"},
}}
m.runDetail = r
view := ansi.Strip(m.runsView(44))
for _, want := range []string{"Stopped: Verification timed out", "Updated the layout", "Partial result", "screen.go"} {
if !strings.Contains(view, want) {
t.Fatal("partial result hidden", want, view)
}
}
if strings.Index(view, "Updated the layout") > strings.Index(view, "Run graph") {
t.Fatal("graph precedes result")
}
m.toggleRunSection(0)
lines := ansi.Strip(strings.Join(m.runSectionLines(100), "\n"))
if !strings.Contains(lines, "1. implement · success — Updated the layout") || strings.Index(lines, "[o]") > strings.Index(lines, "[i]") {
t.Fatal("recorded accomplishments hidden behind inputs", lines)
}
r.Status = "succeeded"
r.Diagnostic = ""
r.Output = map[string]any{"summary": "Layout verified", "report": "Checks passed", "artifacts": []string{"screen.go"}}
if lines = ansi.Strip(strings.Join(m.runSectionLines(100), "\n")); !strings.Contains(lines, "Layout verified") {
t.Fatal("final result not prominent", lines)
}
r.Output = nil
r.Steps = nil
if lines = ansi.Strip(strings.Join(m.runSectionLines(100), "\n")); !strings.Contains(lines, "no result recorded") || strings.Contains(lines, "Layout verified") {
t.Fatal("empty success fabricated work", lines)
}
}