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") // Height chosen so artifactsViewHeight() is 50, keeping the view's page size // and the model's scroll page size identical (as they are in the app). m.width, m.height = 120, 54 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 m.artifactsOpen = true m.artifactIndex, m.artifactTop = 0, 0 top := ansi.Strip(m.artifactsView(m.artifactsViewHeight())) t.Logf("capture %s (run #%d executing=%t) top:\n%s", path, detail.ID, detail.Executing, top) rendered.WriteString(top) // Scroll to the tail so a trailing running visit's capture summary is // rendered regardless of how many artifacts precede it; a fixed top // page used to clip it once a run accumulated enough artifacts. m = artifactKey(m, 'G') tail := ansi.Strip(m.artifactsView(m.artifactsViewHeight())) t.Logf("capture %s (run #%d executing=%t) tail:\n%s", path, detail.ID, detail.Executing, tail) rendered.WriteString(tail) } 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) } } }