package tui import ( "context" "encoding/json" "os" "strings" "testing" "git.a-wan.net/alan/pipelines/internal/protocol" "github.com/charmbracelet/x/ansi" ) // TestLiveArtifactsFromCapture renders the artifacts view from real // `pipelines inspect RUN_ID --json` captures. It is env-gated and skips unless // PIPELINES_ARTIFACT_CAPTURES names one or more capture files, so it never // depends on a running server in CI; the operator points it at real captures to // re-confirm that mixed artifact types, a partial capture, a running visit and // a finished visit with none all render. func TestLiveArtifactsFromCapture(t *testing.T) { list := os.Getenv("PIPELINES_ARTIFACT_CAPTURES") if strings.TrimSpace(list) == "" { t.Skip("set PIPELINES_ARTIFACT_CAPTURES to comma-separated `pipelines inspect RUN_ID --json` files") } m := New(context.Background(), "ws://127.0.0.1:8080/connect") m.width, m.height = 120, 60 var rendered strings.Builder for _, path := range strings.Split(list, ",") { path = strings.TrimSpace(path) if path == "" { continue } data, err := os.ReadFile(path) if err != nil { t.Fatal(err) } var detail protocol.RunDetail if err := json.Unmarshal(data, &detail); err != nil { t.Fatal(err) } m.runDetail = &detail view := ansi.Strip(m.artifactsView(50)) t.Logf("capture %s (run #%d executing=%t):\n%s", path, detail.ID, detail.Executing, view) rendered.WriteString(view) } text := rendered.String() for _, want := range []string{"[img]", "partial capture", "capture pending", "not recorded for this visit", "image/png", "KiB"} { if !strings.Contains(text, want) { t.Errorf("live captures did not render %q", want) } } }