Rework omni search onto a typed search contract and add a TUI artifacts view
Protocol: replace the loose Query/Kind/Matches/Limit search fields with a Search request object and a SearchResults response, and have the server answer search from Store.Search over the shared run projections (runFrom/runStamps).
CLI: add the read-only 'pipelines search QUERY [--type KIND] [--limit N] [--json]' command with usage/help, and document the typed targets, ranking and bounds in docs/cli.md.
TUI: the '/' popup keeps type-to-search, up/down, Enter and Esc, renders one ranked list with kind badges and a bracketed (non-colour) match snippet, and Enter opens the matched pipeline, run, step, artifact or field; footer text updated to match.
TUI: add a dedicated run artifacts view ('A') with open/copy of recorded files, and move artifacts out of the run-detail File changes section (artifactCaptureNotes).
Tests: add Store.OpenReadOnly for read-only inspection of a live database plus pipeline/server/TUI search tests and artifacts tests, including env-gated live checks.
This commit is contained in:
@@ -0,0 +1,424 @@
|
||||
package tui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"github.com/atotto/clipboard"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/charmbracelet/x/ansi"
|
||||
)
|
||||
|
||||
// artifactVisit is one recorded stage visit and the artifacts the server
|
||||
// observed for it. A visit is kept even when it recorded none, so the view can
|
||||
// say plainly that nothing was captured rather than omitting it.
|
||||
type artifactVisit struct {
|
||||
stage string
|
||||
visit int
|
||||
step protocol.RunStep
|
||||
artifacts []protocol.StageArtifact
|
||||
}
|
||||
|
||||
// runArtifactVisits groups a run's recorded steps by stage and visit in the
|
||||
// order the run produced them: stages in first-appearance order and each
|
||||
// stage's visits by sequence. The display visit number is the recorded control
|
||||
// visit when present, else the position within the stage (mirroring the app's
|
||||
// runTimeline/runArtifactGroups). Pure, O(n), and it never dedupes steps, so a
|
||||
// repeated stage's visits stay distinct.
|
||||
func runArtifactVisits(steps []protocol.RunStep) []artifactVisit {
|
||||
order := make([]string, 0)
|
||||
index := map[string]int{}
|
||||
byStage := make([][]protocol.RunStep, 0)
|
||||
for _, step := range steps {
|
||||
at, ok := index[step.Stage]
|
||||
if !ok {
|
||||
at = len(order)
|
||||
index[step.Stage] = at
|
||||
order = append(order, step.Stage)
|
||||
byStage = append(byStage, nil)
|
||||
}
|
||||
byStage[at] = append(byStage[at], step)
|
||||
}
|
||||
visits := make([]artifactVisit, 0, len(steps))
|
||||
for i, stage := range order {
|
||||
stageSteps := byStage[i]
|
||||
sort.SliceStable(stageSteps, func(a, b int) bool { return stageSteps[a].Sequence < stageSteps[b].Sequence })
|
||||
for j, step := range stageSteps {
|
||||
visit := j + 1
|
||||
if step.Control != nil && step.Control.Visit > 0 {
|
||||
visit = step.Control.Visit
|
||||
}
|
||||
visits = append(visits, artifactVisit{stage: stage, visit: visit, step: step, artifacts: step.Artifacts})
|
||||
}
|
||||
}
|
||||
return visits
|
||||
}
|
||||
|
||||
// artifactRef addresses one artifact row in the flat selection order the view
|
||||
// uses (group order, then recorded order within the group).
|
||||
type artifactRef struct {
|
||||
visit int
|
||||
artifact protocol.StageArtifact
|
||||
}
|
||||
|
||||
func artifactRefs(visits []artifactVisit) []artifactRef {
|
||||
var refs []artifactRef
|
||||
for i, visit := range visits {
|
||||
for _, artifact := range visit.artifacts {
|
||||
refs = append(refs, artifactRef{visit: i, artifact: artifact})
|
||||
}
|
||||
}
|
||||
return refs
|
||||
}
|
||||
|
||||
// isImageContentType mirrors the app's isImageContentType: an image the
|
||||
// terminal cannot render and therefore marks distinctly.
|
||||
func isImageContentType(contentType string) bool {
|
||||
return strings.HasPrefix(contentType, "image/")
|
||||
}
|
||||
|
||||
// Column geometry for one aligned artifact row. The name and type widths are
|
||||
// clamped so one very long value cannot widen every other row; the size column
|
||||
// is right-aligned.
|
||||
const (
|
||||
artifactCursorWidth = 2
|
||||
artifactMarkerWidth = 5 // "[img]" or five spaces
|
||||
artifactColumnGap = 2
|
||||
artifactMinName = 8
|
||||
artifactMinURLWidth = 12
|
||||
artifactMaxName = 40
|
||||
artifactMaxType = 28
|
||||
)
|
||||
|
||||
type artifactWidths struct{ name, typ, size int }
|
||||
|
||||
func artifactWidthsFor(visits []artifactVisit) artifactWidths {
|
||||
widths := artifactWidths{}
|
||||
for _, visit := range visits {
|
||||
for _, artifact := range visit.artifacts {
|
||||
widths.name = min(artifactMaxName, max(widths.name, lipgloss.Width(ansi.Strip(artifact.Name))))
|
||||
widths.typ = min(artifactMaxType, max(widths.typ, lipgloss.Width(ansi.Strip(artifact.ContentType))))
|
||||
widths.size = max(widths.size, lipgloss.Width(humanBytes(artifact.SizeBytes)))
|
||||
}
|
||||
}
|
||||
return widths
|
||||
}
|
||||
|
||||
func padRight(text string, width int) string {
|
||||
if deficit := width - lipgloss.Width(text); deficit > 0 {
|
||||
return text + strings.Repeat(" ", deficit)
|
||||
}
|
||||
return text
|
||||
}
|
||||
|
||||
func padLeft(text string, width int) string {
|
||||
if deficit := width - lipgloss.Width(text); deficit > 0 {
|
||||
return strings.Repeat(" ", deficit) + text
|
||||
}
|
||||
return text
|
||||
}
|
||||
|
||||
// artifactScrollTop returns the offset that keeps the selected row visible in a
|
||||
// window of page rows, given the current offset and the total line count. It
|
||||
// scrolls by the minimum needed, so a one-row move shifts the window by one
|
||||
// rather than recentring it, and it never leaves the viewport past the end.
|
||||
// Both the selection clamp and the renderer use it, so they can never disagree
|
||||
// about which row is on screen.
|
||||
func artifactScrollTop(from, row, page, total int) int {
|
||||
if page <= 0 {
|
||||
return 0
|
||||
}
|
||||
maxTop := max(0, total-page)
|
||||
from = max(0, min(from, maxTop))
|
||||
if row < from {
|
||||
from = row
|
||||
} else if row >= from+page {
|
||||
from = row - page + 1
|
||||
}
|
||||
return max(0, min(from, maxTop))
|
||||
}
|
||||
|
||||
// artifactsViewHeight is the frame body height the artifacts panel is rendered
|
||||
// at, matching View: a one-line header and a one-line footer, each followed by
|
||||
// a separating row.
|
||||
func (m Model) artifactsViewHeight() int { return max(0, m.height-4) }
|
||||
|
||||
// artifactsPageSize is the number of artifact body rows the panel shows: the
|
||||
// frame body less the panel's own bar and border, matching artifactsView.
|
||||
func (m Model) artifactsPageSize() int { return max(0, m.artifactsViewHeight()-4) }
|
||||
|
||||
// artifactRowText renders one artifact as an aligned row: the image marker, the
|
||||
// name, the content type and the human-readable size, with the URL appended
|
||||
// when the terminal is wide enough. Optional columns drop as width shrinks and
|
||||
// every cell is truncated, so the row never exceeds width.
|
||||
func artifactRowText(artifact protocol.StageArtifact, widths artifactWidths, width int, selected bool) string {
|
||||
prefix := strings.Repeat(" ", artifactCursorWidth)
|
||||
if selected {
|
||||
prefix = "› "
|
||||
}
|
||||
marker := strings.Repeat(" ", artifactMarkerWidth)
|
||||
if isImageContentType(artifact.ContentType) {
|
||||
marker = "[img]"
|
||||
}
|
||||
prefix += marker + " "
|
||||
available := width - lipgloss.Width(prefix)
|
||||
if available <= 0 {
|
||||
return ansi.Truncate(prefix, max(1, width), "")
|
||||
}
|
||||
name := ansi.Strip(artifact.Name)
|
||||
contentType := ansi.Strip(artifact.ContentType)
|
||||
if strings.TrimSpace(contentType) == "" {
|
||||
contentType = "unknown type"
|
||||
}
|
||||
size := humanBytes(artifact.SizeBytes)
|
||||
gap := strings.Repeat(" ", artifactColumnGap)
|
||||
nameCell := func(w int) string { return padRight(ansi.Truncate(name, max(1, w), "…"), w) }
|
||||
typeCell := padRight(ansi.Truncate(contentType, max(1, widths.typ), "…"), widths.typ)
|
||||
sizeCell := padLeft(size, widths.size)
|
||||
switch {
|
||||
case available >= widths.name+artifactColumnGap+widths.typ+artifactColumnGap+widths.size+artifactColumnGap+artifactMinURLWidth:
|
||||
urlWidth := available - (widths.name + artifactColumnGap + widths.typ + artifactColumnGap + widths.size + artifactColumnGap)
|
||||
return prefix + nameCell(widths.name) + gap + typeCell + gap + sizeCell + gap + ansi.Truncate(artifact.URL, max(1, urlWidth), "…")
|
||||
case available >= widths.name+artifactColumnGap+widths.typ+artifactColumnGap+widths.size:
|
||||
return prefix + nameCell(widths.name) + gap + typeCell + gap + sizeCell
|
||||
case available >= artifactMinName+artifactColumnGap+widths.size:
|
||||
nameWidth := min(widths.name, available-artifactColumnGap-widths.size)
|
||||
return prefix + nameCell(nameWidth) + gap + sizeCell
|
||||
default:
|
||||
return prefix + ansi.Truncate(name, max(1, available), "…")
|
||||
}
|
||||
}
|
||||
|
||||
// artifactViewContent renders the grouped artifact lines for one content width
|
||||
// and returns the line index of each flat artifact ref, so selection can scroll
|
||||
// it into view. Group headers, the shared capture summary and the partial
|
||||
// capture notes precede each visit's aligned rows.
|
||||
func artifactViewContent(visits []artifactVisit, widths artifactWidths, width, selected int) ([]string, []int) {
|
||||
if len(visits) == 0 {
|
||||
return []string{"No recorded visits yet."}, nil
|
||||
}
|
||||
var lines []string
|
||||
var refLines []int
|
||||
ref := 0
|
||||
for i, visit := range visits {
|
||||
if i > 0 {
|
||||
lines = append(lines, "")
|
||||
}
|
||||
lines = append(lines, lipgloss.NewStyle().Bold(true).Foreground(themeAccent).Render(fmt.Sprintf("%s · visit %d", ansi.Strip(visit.stage), visit.visit)))
|
||||
lines = append(lines, lipgloss.NewStyle().Foreground(themePrimary).Render(artifactsSummary(visit.step)))
|
||||
for _, note := range artifactCaptureNotes(visit.step) {
|
||||
lines = append(lines, lipgloss.NewStyle().Foreground(themeMuted).Render(note))
|
||||
}
|
||||
for _, artifact := range visit.artifacts {
|
||||
lines = append(lines, artifactRowText(artifact, widths, width, ref == selected))
|
||||
refLines = append(refLines, len(lines)-1)
|
||||
ref++
|
||||
}
|
||||
}
|
||||
return lines, refLines
|
||||
}
|
||||
|
||||
func (m Model) artifactViewVisits() ([]artifactVisit, []artifactRef) {
|
||||
if m.runDetail == nil {
|
||||
return nil, nil
|
||||
}
|
||||
visits := runArtifactVisits(m.runDetail.Steps)
|
||||
return visits, artifactRefs(visits)
|
||||
}
|
||||
|
||||
func (m *Model) openArtifacts() {
|
||||
if m.runDetail == nil {
|
||||
m.runError = "Open a run to inspect its artifacts."
|
||||
return
|
||||
}
|
||||
m.artifactsOpen = true
|
||||
m.artifactIndex = 0
|
||||
m.artifactTop = 0
|
||||
}
|
||||
|
||||
func (m *Model) selectArtifactByName(name string) {
|
||||
_, refs := m.artifactViewVisits()
|
||||
for i, ref := range refs {
|
||||
if ref.artifact.Name == name {
|
||||
m.artifactIndex = i
|
||||
break
|
||||
}
|
||||
}
|
||||
m.clampArtifactScroll()
|
||||
}
|
||||
|
||||
// clampArtifactScroll keeps the selected artifact row inside the visible page
|
||||
// after a selection move, using the same page size as the renderer.
|
||||
func (m *Model) clampArtifactScroll() {
|
||||
if m.runDetail == nil {
|
||||
m.artifactIndex, m.artifactTop = 0, 0
|
||||
return
|
||||
}
|
||||
visits, refs := m.artifactViewVisits()
|
||||
m.artifactIndex = max(0, min(m.artifactIndex, max(0, len(refs)-1)))
|
||||
if len(refs) == 0 {
|
||||
m.artifactTop = 0
|
||||
return
|
||||
}
|
||||
widths := artifactWidthsFor(visits)
|
||||
inner := max(1, m.width-4)
|
||||
lines, refLines := artifactViewContent(visits, widths, inner, m.artifactIndex)
|
||||
if m.artifactIndex >= len(refLines) {
|
||||
return
|
||||
}
|
||||
m.artifactTop = artifactScrollTop(m.artifactTop, refLines[m.artifactIndex], m.artifactsPageSize(), len(lines))
|
||||
}
|
||||
|
||||
func (m Model) updateArtifacts(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
_, refs := m.artifactViewVisits()
|
||||
count := len(refs)
|
||||
switch msg.String() {
|
||||
case "esc":
|
||||
m.artifactsOpen = false
|
||||
return m, nil
|
||||
case "j", "down":
|
||||
m.artifactIndex = min(m.artifactIndex+1, max(0, count-1))
|
||||
case "k", "up":
|
||||
m.artifactIndex = max(0, m.artifactIndex-1)
|
||||
case "g", "home":
|
||||
m.artifactIndex = 0
|
||||
case "G", "end":
|
||||
m.artifactIndex = max(0, count-1)
|
||||
case "enter", "o":
|
||||
if count == 0 {
|
||||
return m, nil
|
||||
}
|
||||
return m, openArtifactCmd(m.url, refs[m.artifactIndex].artifact)
|
||||
case "y":
|
||||
if count == 0 {
|
||||
return m, nil
|
||||
}
|
||||
return m, copyArtifactCmd(m.url, refs[m.artifactIndex].artifact)
|
||||
}
|
||||
m.clampArtifactScroll()
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (m Model) artifactsView(height int) string {
|
||||
if m.runDetail == nil {
|
||||
return fitBlock([]string{"Open a run to inspect its artifacts."}, m.width, height)
|
||||
}
|
||||
if height <= 0 || m.width <= 0 {
|
||||
return ""
|
||||
}
|
||||
visits, refs := m.artifactViewVisits()
|
||||
widths := artifactWidthsFor(visits)
|
||||
selected := max(0, min(m.artifactIndex, max(0, len(refs)-1)))
|
||||
inner := max(1, m.width-4)
|
||||
lines, refLines := artifactViewContent(visits, widths, inner, selected)
|
||||
page := max(0, height-4)
|
||||
top := max(0, min(m.artifactTop, max(0, len(lines)-page)))
|
||||
if selected < len(refLines) {
|
||||
// Keep the selected row on screen even if a slightly different page
|
||||
// size left the stored offset behind.
|
||||
top = artifactScrollTop(top, refLines[selected], page, len(lines))
|
||||
}
|
||||
body := lines[top:min(len(lines), top+page)]
|
||||
title := fmt.Sprintf("Artifacts · run #%d", m.runDetail.ID)
|
||||
if len(visits) > 0 {
|
||||
title = fmt.Sprintf("Artifacts · run #%d · %d recorded · %d visits", m.runDetail.ID, len(refs), len(visits))
|
||||
}
|
||||
right := ""
|
||||
if len(refs) > 0 {
|
||||
right = fmt.Sprintf("%d/%d", selected+1, len(refs))
|
||||
}
|
||||
footer := "No artifacts recorded"
|
||||
if len(refs) > 0 {
|
||||
// Keep the selected entry's URL available even when the row is too
|
||||
// narrow to carry its own URL column.
|
||||
footer = refs[selected].artifact.URL
|
||||
}
|
||||
return panel(m.width, height, []string{bar(title, right, inner, true)}, body, footer, true)
|
||||
}
|
||||
|
||||
// artifactActionMsg reports the outcome of handing a URL to the opener or the
|
||||
// clipboard, so a failure is surfaced instead of silently dropped.
|
||||
type artifactActionMsg struct {
|
||||
verb string
|
||||
url string
|
||||
err error
|
||||
}
|
||||
|
||||
// openExternal and copyText are seams so tests can observe the resolved URL
|
||||
// without launching a process or touching the system clipboard.
|
||||
var (
|
||||
openExternal = func(target string) error { return openerCommand(target).Run() }
|
||||
copyText = clipboard.WriteAll
|
||||
)
|
||||
|
||||
// openerCommand is the platform command that hands target to the system opener.
|
||||
func openerCommand(target string) *exec.Cmd {
|
||||
switch runtime.GOOS {
|
||||
case "darwin":
|
||||
return exec.Command("open", target)
|
||||
case "windows":
|
||||
return exec.Command("rundll32", "url.dll,FileProtocolHandler", target)
|
||||
default:
|
||||
return exec.Command("xdg-open", target)
|
||||
}
|
||||
}
|
||||
|
||||
// resolveArtifactURL resolves a server-relative artifact URL against the
|
||||
// configured websocket server URL by mapping ws/wss to http/https and keeping
|
||||
// host:port, mirroring the app's ServerUrl.resolveArtifactUrl; it never
|
||||
// hardcodes a host. An already-absolute http(s) URL is returned unchanged, and
|
||||
// a blank or invalid configuration fails.
|
||||
func resolveArtifactURL(serverURL, artifactURL string) (string, bool) {
|
||||
target := strings.TrimSpace(artifactURL)
|
||||
if target == "" {
|
||||
return "", false
|
||||
}
|
||||
if strings.HasPrefix(target, "http://") || strings.HasPrefix(target, "https://") {
|
||||
return target, true
|
||||
}
|
||||
parsed, err := url.Parse(strings.TrimSpace(serverURL))
|
||||
if err != nil || (parsed.Scheme != "ws" && parsed.Scheme != "wss") || parsed.Hostname() == "" {
|
||||
return "", false
|
||||
}
|
||||
scheme := "http"
|
||||
if parsed.Scheme == "wss" {
|
||||
scheme = "https"
|
||||
}
|
||||
if !strings.HasPrefix(target, "/") {
|
||||
target = "/" + target
|
||||
}
|
||||
return scheme + "://" + parsed.Host + target, true
|
||||
}
|
||||
|
||||
func artifactURLAction(verb, serverURL string, artifact protocol.StageArtifact) tea.Cmd {
|
||||
resolved, ok := resolveArtifactURL(serverURL, artifact.URL)
|
||||
if !ok {
|
||||
return func() tea.Msg {
|
||||
return artifactActionMsg{verb: verb, err: fmt.Errorf("no server URL to resolve %q", artifact.Name)}
|
||||
}
|
||||
}
|
||||
action := openExternal
|
||||
if verb == "copy" {
|
||||
action = copyText
|
||||
}
|
||||
return func() tea.Msg {
|
||||
if err := action(resolved); err != nil {
|
||||
return artifactActionMsg{verb: verb, url: resolved, err: err}
|
||||
}
|
||||
return artifactActionMsg{verb: verb, url: resolved}
|
||||
}
|
||||
}
|
||||
|
||||
func openArtifactCmd(serverURL string, artifact protocol.StageArtifact) tea.Cmd {
|
||||
return artifactURLAction("open", serverURL, artifact)
|
||||
}
|
||||
|
||||
func copyArtifactCmd(serverURL string, artifact protocol.StageArtifact) tea.Cmd {
|
||||
return artifactURLAction("copy", serverURL, artifact)
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,274 @@
|
||||
package tui
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/x/ansi"
|
||||
)
|
||||
|
||||
func artifactsFixtureModel() Model {
|
||||
m := New(context.Background(), "ws://127.0.0.1:8080/connect")
|
||||
m.width, m.height = 100, 30
|
||||
m.runOpen = true
|
||||
m.keys.runs = true
|
||||
m.runDetailFocus = true
|
||||
m.requestedRunID = 169
|
||||
m.runDetail = &protocol.RunDetail{
|
||||
RunSummary: protocol.RunSummary{ID: 169, Name: "demo", Version: 3, Status: "succeeded"},
|
||||
Steps: []protocol.RunStep{
|
||||
{Sequence: 1, Stage: "implementer", Status: "completed", Artifacts: []protocol.StageArtifact{
|
||||
{Name: "build.log", SizeBytes: 2337, ContentType: "text/plain; charset=utf-8", URL: "/artifacts/169/1/build.log"},
|
||||
}, ArtifactsSkipped: 1},
|
||||
{Sequence: 2, Stage: "ui_reviewer", Status: "completed", Artifacts: []protocol.StageArtifact{
|
||||
{Name: "01-pill.png", SizeBytes: 80544, ContentType: "image/png", URL: "/artifacts/169/2/01-pill.png"},
|
||||
{Name: "morph.mp4", SizeBytes: 645782, ContentType: "video/mp4", URL: "/artifacts/169/2/morph.mp4"},
|
||||
}},
|
||||
{Sequence: 3, Stage: "committer", Status: "completed"},
|
||||
{Sequence: 4, Stage: "reviewer", Status: "running"},
|
||||
},
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
func artifactKey(m Model, key rune) Model {
|
||||
updated, _ := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{key}})
|
||||
return updated.(Model)
|
||||
}
|
||||
|
||||
func TestRunArtifactVisitsGroupAndOrder(t *testing.T) {
|
||||
steps := []protocol.RunStep{
|
||||
{Sequence: 3, Stage: "build"},
|
||||
{Sequence: 2, Stage: "plan"},
|
||||
{Sequence: 1, Stage: "plan", Control: &protocol.ControlEvidence{Visit: 1}, Artifacts: []protocol.StageArtifact{{Name: "plan.md"}}},
|
||||
}
|
||||
visits := runArtifactVisits(steps)
|
||||
want := []struct {
|
||||
stage string
|
||||
visit int
|
||||
}{{"build", 1}, {"plan", 1}, {"plan", 2}}
|
||||
if len(visits) != len(want) {
|
||||
t.Fatalf("visits = %d, want %d", len(visits), len(want))
|
||||
}
|
||||
for i, w := range want {
|
||||
if visits[i].stage != w.stage || visits[i].visit != w.visit {
|
||||
t.Fatalf("visit %d = %s/%d, want %s/%d", i, visits[i].stage, visits[i].visit, w.stage, w.visit)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestArtifactsViewGroupsMarkersAndWording(t *testing.T) {
|
||||
m := artifactsFixtureModel()
|
||||
m.width = 120
|
||||
view := ansi.Strip(m.artifactsView(24))
|
||||
for _, want := range []string{
|
||||
"implementer · visit 1",
|
||||
"ui_reviewer · visit 1",
|
||||
"committer · visit 1",
|
||||
"reviewer · visit 1",
|
||||
"Artifacts · 1 recorded · partial capture",
|
||||
"1 files excluded from artifact capture.",
|
||||
"Artifacts · 2 recorded",
|
||||
"Artifacts · not recorded for this visit",
|
||||
"Artifacts · capture pending",
|
||||
"[img]",
|
||||
"01-pill.png",
|
||||
"morph.mp4",
|
||||
"video/mp4",
|
||||
"78.7 KiB",
|
||||
"630.6 KiB",
|
||||
"/artifacts/169/2/01-pill.png",
|
||||
} {
|
||||
if !strings.Contains(view, want) {
|
||||
t.Fatalf("artifacts view missing %q:\n%s", want, view)
|
||||
}
|
||||
}
|
||||
for _, line := range strings.Split(view, "\n") {
|
||||
if strings.Contains(line, "morph.mp4") && strings.Contains(line, "[img]") {
|
||||
t.Fatalf("non-image artifact marked as an image: %q", line)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestArtifactsViewColumnsAlign(t *testing.T) {
|
||||
m := artifactsFixtureModel()
|
||||
m.width = 120
|
||||
lines := strings.Split(ansi.Strip(m.artifactsView(24)), "\n")
|
||||
var image, video string
|
||||
for _, line := range lines {
|
||||
if strings.Contains(line, "01-pill.png") {
|
||||
image = line
|
||||
}
|
||||
if strings.Contains(line, "morph.mp4") {
|
||||
video = line
|
||||
}
|
||||
}
|
||||
if image == "" || video == "" {
|
||||
t.Fatalf("artifact rows not both rendered:\n%s", strings.Join(lines, "\n"))
|
||||
}
|
||||
name := strings.Index(image, "01-pill.png")
|
||||
typeStart := strings.Index(image, "image/png")
|
||||
sizeStart := strings.Index(image, "78.7 KiB")
|
||||
if name != strings.Index(video, "morph.mp4") || name < 0 {
|
||||
t.Fatalf("name column misaligned:\n%q\n%q", image, video)
|
||||
}
|
||||
if typeStart != strings.Index(video, "video/mp4") || typeStart < 0 {
|
||||
t.Fatalf("type column misaligned:\n%q\n%q", image, video)
|
||||
}
|
||||
if sizeStart+len("78.7 KiB") != strings.Index(video, "630.6 KiB")+len("630.6 KiB") || sizeStart < 0 {
|
||||
t.Fatalf("size column misaligned:\n%q\n%q", image, video)
|
||||
}
|
||||
}
|
||||
|
||||
func TestArtifactsViewNeverOverflows(t *testing.T) {
|
||||
for _, width := range []int{160, 120, 80, 63, 40, 24, 12} {
|
||||
m := artifactsFixtureModel()
|
||||
m.width = width
|
||||
for _, line := range strings.Split(m.artifactsView(24), "\n") {
|
||||
if got := ansi.StringWidth(line); got > width {
|
||||
t.Fatalf("width %d: line width %d: %q", width, got, line)
|
||||
}
|
||||
}
|
||||
}
|
||||
m := artifactsFixtureModel()
|
||||
m.width = 40
|
||||
view := ansi.Strip(m.artifactsView(24))
|
||||
if !strings.Contains(view, "/artifacts/169/1/build.log") {
|
||||
t.Fatalf("narrow view must keep the selected URL available:\n%s", view)
|
||||
}
|
||||
}
|
||||
|
||||
func TestArtifactsViewEmptyRun(t *testing.T) {
|
||||
m := New(context.Background(), "ws://127.0.0.1:8080/connect")
|
||||
m.width, m.height = 100, 24
|
||||
m.runDetail = &protocol.RunDetail{RunSummary: protocol.RunSummary{ID: 5}}
|
||||
view := ansi.Strip(m.artifactsView(20))
|
||||
for _, want := range []string{"Artifacts · run #5", "No recorded visits yet.", "No artifacts recorded"} {
|
||||
if !strings.Contains(view, want) {
|
||||
t.Fatalf("empty artifacts view missing %q:\n%s", want, view)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func artifactsScrollFixture() (Model, []string) {
|
||||
m := New(context.Background(), "ws://127.0.0.1:8080/connect")
|
||||
m.width, m.height = 80, 14
|
||||
m.runOpen = true
|
||||
m.keys.runs = true
|
||||
m.runDetailFocus = true
|
||||
m.requestedRunID = 7
|
||||
var steps []protocol.RunStep
|
||||
names := make([]string, 0, 12)
|
||||
for i := 0; i < 12; i++ {
|
||||
name := fmt.Sprintf("shot-%02d.png", i)
|
||||
names = append(names, name)
|
||||
steps = append(steps, protocol.RunStep{Sequence: i + 1, Stage: "ui_reviewer", Status: "completed",
|
||||
Artifacts: []protocol.StageArtifact{{Name: name, SizeBytes: 1024, ContentType: "image/png", URL: "/artifacts/7/" + name}}})
|
||||
}
|
||||
m.runDetail = &protocol.RunDetail{RunSummary: protocol.RunSummary{ID: 7}, Steps: steps}
|
||||
m.artifactsOpen = true
|
||||
return m, names
|
||||
}
|
||||
|
||||
func TestArtifactsViewKeepsSelectionVisible(t *testing.T) {
|
||||
m, names := artifactsScrollFixture()
|
||||
for i := 0; i < len(names)-1; i++ {
|
||||
m = artifactKey(m, 'j')
|
||||
}
|
||||
if view := ansi.Strip(m.View()); !strings.Contains(view, names[len(names)-1]) {
|
||||
t.Fatalf("last artifact scrolled out of view:\n%s", view)
|
||||
}
|
||||
for i := 0; i < len(names)-1; i++ {
|
||||
m = artifactKey(m, 'k')
|
||||
}
|
||||
if view := ansi.Strip(m.View()); !strings.Contains(view, names[0]) {
|
||||
t.Fatalf("first artifact not visible after scrolling back:\n%s", view)
|
||||
}
|
||||
}
|
||||
|
||||
func TestArtifactsSelectByNameScrollsIntoView(t *testing.T) {
|
||||
m, names := artifactsScrollFixture()
|
||||
m.selectArtifactByName(names[len(names)-1])
|
||||
if view := ansi.Strip(m.View()); !strings.Contains(view, names[len(names)-1]) {
|
||||
t.Fatalf("selectArtifactByName did not scroll the match into view:\n%s", view)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveArtifactURL(t *testing.T) {
|
||||
cases := []struct {
|
||||
server, artifact, want string
|
||||
ok bool
|
||||
}{
|
||||
{"ws://127.0.0.1:8080/connect", "/artifacts/1/2/a.png", "http://127.0.0.1:8080/artifacts/1/2/a.png", true},
|
||||
{"wss://host/connect", "/artifacts/1/2/a.png", "https://host/artifacts/1/2/a.png", true},
|
||||
{"ws://host/connect", "artifacts/1/2/a.png", "http://host/artifacts/1/2/a.png", true},
|
||||
{"ws://host/connect", "https://cdn.example/a.png", "https://cdn.example/a.png", true},
|
||||
{"", "/artifacts/1/2/a.png", "", false},
|
||||
{"http://host/connect", "/artifacts/1/2/a.png", "", false},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
got, ok := resolveArtifactURL(tc.server, tc.artifact)
|
||||
if ok != tc.ok || got != tc.want {
|
||||
t.Fatalf("resolveArtifactURL(%q, %q) = %q,%t want %q,%t", tc.server, tc.artifact, got, ok, tc.want, tc.ok)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestArtifactsViewOpenAndCopyKeys(t *testing.T) {
|
||||
previousOpen, previousCopy := openExternal, copyText
|
||||
defer func() { openExternal, copyText = previousOpen, previousCopy }()
|
||||
var opened, copied string
|
||||
openExternal = func(target string) error { opened = target; return nil }
|
||||
copyText = func(text string) error { copied = text; return nil }
|
||||
|
||||
m := artifactsFixtureModel()
|
||||
m = artifactKey(m, 'A')
|
||||
if !m.artifactsOpen {
|
||||
t.Fatal("A did not open the artifacts view")
|
||||
}
|
||||
if m.artifactIndex != 0 {
|
||||
t.Fatalf("selection = %d, want the first artifact", m.artifactIndex)
|
||||
}
|
||||
|
||||
updated, cmd := m.Update(tea.KeyMsg{Type: tea.KeyEnter})
|
||||
m = updated.(Model)
|
||||
if cmd == nil {
|
||||
t.Fatal("Enter did not produce an open command")
|
||||
}
|
||||
updated, _ = m.Update(cmd())
|
||||
m = updated.(Model)
|
||||
if opened != "http://127.0.0.1:8080/artifacts/169/1/build.log" {
|
||||
t.Fatalf("opened %q", opened)
|
||||
}
|
||||
|
||||
m = artifactKey(m, 'j')
|
||||
updated, cmd = m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'y'}})
|
||||
m = updated.(Model)
|
||||
if cmd == nil {
|
||||
t.Fatal("y did not produce a copy command")
|
||||
}
|
||||
updated, _ = m.Update(cmd())
|
||||
m = updated.(Model)
|
||||
if copied != "http://127.0.0.1:8080/artifacts/169/2/01-pill.png" {
|
||||
t.Fatalf("copied %q", copied)
|
||||
}
|
||||
if !strings.Contains(strings.Join(m.lines, "\n"), "Copied artifact URL") {
|
||||
t.Fatalf("copy outcome not surfaced: %v", m.lines)
|
||||
}
|
||||
}
|
||||
|
||||
func TestArtifactsViewRenderedInRunDetail(t *testing.T) {
|
||||
m := artifactsFixtureModel()
|
||||
m.artifactsOpen = true
|
||||
view := ansi.Strip(m.View())
|
||||
if !strings.Contains(view, "Artifacts · run #169") {
|
||||
t.Fatalf("run view did not render the artifacts view:\n%s", view)
|
||||
}
|
||||
if !strings.Contains(m.activeFooter(), "y copy URL") {
|
||||
t.Fatalf("footer does not advertise the artifact controls: %q", m.activeFooter())
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,8 @@ func (m Model) activeFooter() string {
|
||||
text = "Refreshing published state · draft retained"
|
||||
case m.decisionOpen:
|
||||
text = "↑/↓ choose · Tab feedback · Enter decide · Esc cancel"
|
||||
case m.artifactsOpen:
|
||||
text = "j/k select · Enter open · y copy URL · Esc back"
|
||||
case m.actionConfirm != nil || m.mutationCommand != nil:
|
||||
text = "y confirm · n/Esc cancel · j/k read"
|
||||
case m.draftDeletingPath != "":
|
||||
@@ -35,7 +37,7 @@ func (m Model) activeFooter() string {
|
||||
case m.versionsOpen:
|
||||
text = "↑/↓ choose · Enter view version · Esc back"
|
||||
case m.paletteOpen && m.searchOpen:
|
||||
text = "Type to search · ↑/↓ choose · Enter open · Esc cancel"
|
||||
text = "Search pipelines, runs, steps, artifacts and text · ↑/↓ choose · Enter open · Esc cancel"
|
||||
case m.paletteOpen:
|
||||
text = "Type a command · ↑/↓ choose · Enter execute · Esc cancel"
|
||||
case m.logOpen:
|
||||
@@ -63,6 +65,8 @@ func (m Model) activeFooter() string {
|
||||
text = "Refreshing · draft retained"
|
||||
case m.decisionOpen:
|
||||
text = "Esc cancel · Enter decide · ↑↓ select"
|
||||
case m.artifactsOpen:
|
||||
text = "Esc back · Enter open · y copy"
|
||||
case m.actionConfirm != nil || m.mutationCommand != nil:
|
||||
text = "Esc cancel · y confirm · j/k read"
|
||||
case m.draftDeletingPath != "":
|
||||
@@ -83,7 +87,7 @@ func (m Model) activeFooter() string {
|
||||
case m.versionsOpen:
|
||||
text = "Esc back · Enter view · ↑↓ select"
|
||||
case m.paletteOpen && m.searchOpen:
|
||||
text = "Esc back · Enter open · ↑↓ select"
|
||||
text = "Esc cancel · Enter open · ↑↓ select"
|
||||
case m.paletteOpen:
|
||||
text = "Esc back · Enter run · ↑↓ select"
|
||||
case m.logOpen:
|
||||
|
||||
@@ -374,6 +374,11 @@ func (m Model) updateLogs(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// popup centres a dialog of at most preferredWidth (clamped to width-6) and
|
||||
// truncates every line to that width so a modal cannot break the layout. Below
|
||||
// roughly 20 columns the boxed dialog no longer fits, so popup falls back to the
|
||||
// bare truncated lines without chrome; the TUI is designed for terminals at
|
||||
// least 20 columns wide.
|
||||
func popup(width, height, preferredWidth int, lines []string) string {
|
||||
inner := min(preferredWidth, max(1, width-6))
|
||||
for i := range lines {
|
||||
|
||||
@@ -143,7 +143,7 @@ func TestHomeOnlyAdvertisesSearchAndCommands(t *testing.T) {
|
||||
m.usage = &protocol.UsageStats{}
|
||||
}
|
||||
view := ansi.Strip(m.View())
|
||||
for _, hint := range []string{"/ search", ": commands"} {
|
||||
for _, hint := range []string{"/ omni search", ": commands"} {
|
||||
if !strings.Contains(view, hint) {
|
||||
t.Fatal("missing home hint", hint, view)
|
||||
}
|
||||
|
||||
@@ -57,23 +57,22 @@ func humanBytes(size int64) string {
|
||||
return fmt.Sprintf("%.1f %ciB", float64(size)/float64(div), "KMGTPE"[exp])
|
||||
}
|
||||
|
||||
// artifactLines lists one step's recorded artifacts (name and size) for the
|
||||
// retained-evidence view, matching the file-changes style.
|
||||
func artifactLines(step protocol.RunStep) []string {
|
||||
// artifactCaptureNotes lists the partial-capture notes for one visit: one line
|
||||
// per non-zero excluded/omitted count, and nothing when the capture was
|
||||
// complete. A visit with no recorded artifacts yields no notes, mirroring the
|
||||
// app's artifactCaptureNotes, so notes never accompany an empty-state summary.
|
||||
func artifactCaptureNotes(step protocol.RunStep) []string {
|
||||
if len(step.Artifacts) == 0 {
|
||||
return nil
|
||||
}
|
||||
lines := []string{artifactsSummary(step)}
|
||||
for _, artifact := range step.Artifacts {
|
||||
lines = append(lines, fmt.Sprintf("%s · %s · %s", ansi.Strip(artifact.Name), humanBytes(artifact.SizeBytes), ansi.Strip(artifact.ContentType)))
|
||||
}
|
||||
var notes []string
|
||||
if step.ArtifactsSkipped > 0 {
|
||||
lines = append(lines, fmt.Sprintf("%d files excluded from artifact capture.", step.ArtifactsSkipped))
|
||||
notes = append(notes, fmt.Sprintf("%d files excluded from artifact capture.", step.ArtifactsSkipped))
|
||||
}
|
||||
if step.ArtifactsTruncated > 0 {
|
||||
lines = append(lines, fmt.Sprintf("%d files omitted by artifact capture limits.", step.ArtifactsTruncated))
|
||||
notes = append(notes, fmt.Sprintf("%d files omitted by artifact capture limits.", step.ArtifactsTruncated))
|
||||
}
|
||||
return lines
|
||||
return notes
|
||||
}
|
||||
|
||||
func diffHighlight(line string) string {
|
||||
|
||||
+28
-4
@@ -134,7 +134,8 @@ type Model struct {
|
||||
commandIndex int
|
||||
homeTop int
|
||||
searchOpen bool
|
||||
searchResults []protocol.SearchMatch
|
||||
searchResults []protocol.SearchResult
|
||||
searchText string
|
||||
searchRequest string
|
||||
searchInFlight bool
|
||||
searchQueued bool
|
||||
@@ -203,6 +204,9 @@ type Model struct {
|
||||
decisionIndex int
|
||||
decisionFeedback textinput.Model
|
||||
decisionFeedbackFocus bool
|
||||
artifactsOpen bool
|
||||
artifactIndex int
|
||||
artifactTop int
|
||||
editorOpen bool
|
||||
editorInput textinput.Model
|
||||
editorIndex int
|
||||
@@ -275,6 +279,17 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
m.appendLine("Harness debug: " + msg.err.Error())
|
||||
}
|
||||
return m, nil
|
||||
case artifactActionMsg:
|
||||
if msg.err != nil {
|
||||
m.appendLine("Artifact " + msg.verb + ": " + msg.err.Error())
|
||||
return m, nil
|
||||
}
|
||||
if msg.verb == "copy" {
|
||||
m.appendLine("Copied artifact URL: " + msg.url)
|
||||
} else {
|
||||
m.appendLine("Opened artifact URL: " + msg.url)
|
||||
}
|
||||
return m, nil
|
||||
case spinner.TickMsg:
|
||||
var cmd tea.Cmd
|
||||
m.runSpinner, cmd = m.runSpinner.Update(msg)
|
||||
@@ -360,11 +375,12 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
m.statusRequest = ""
|
||||
}
|
||||
if msg.Type == protocol.SearchResults {
|
||||
if msg.ID == m.searchRequest {
|
||||
if msg.ID == m.searchRequest && msg.SearchResults != nil {
|
||||
m.searchInFlight = false
|
||||
m.searchResults = msg.Matches
|
||||
m.searchResults = msg.SearchResults.Results
|
||||
m.searchText = msg.SearchResults.Query
|
||||
m.searchError = ""
|
||||
m.commandIndex = min(m.commandIndex, max(0, len(msg.Matches)-1))
|
||||
m.commandIndex = min(m.commandIndex, max(0, len(msg.SearchResults.Results)-1))
|
||||
if m.searchQueued {
|
||||
m.searchQueued = false
|
||||
updated, cmd := m.requestSearch()
|
||||
@@ -442,6 +458,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
m.searchInFlight = false
|
||||
m.searchQueued = false
|
||||
m.searchResults = nil
|
||||
m.searchText = ""
|
||||
m.searchError = msg.Error
|
||||
}
|
||||
} else if msg.Type == protocol.Submitted {
|
||||
@@ -638,6 +655,9 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
if m.decisionOpen {
|
||||
return m.updateDecision(msg)
|
||||
}
|
||||
if m.artifactsOpen {
|
||||
return m.updateArtifacts(msg)
|
||||
}
|
||||
if m.runOpen && (msg.String() != ":" || m.runSearchOpen) {
|
||||
return m.updateRuns(msg)
|
||||
}
|
||||
@@ -667,6 +687,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
m.commandInput = newInput()
|
||||
if m.searchOpen {
|
||||
m.searchResults = nil
|
||||
m.searchText = ""
|
||||
m.searchError = ""
|
||||
m.commandInput.Placeholder = "Type to search…"
|
||||
return m, m.commandInput.Focus()
|
||||
@@ -845,6 +866,9 @@ func (m Model) View() string {
|
||||
if m.decisionOpen {
|
||||
content = m.decisionView(bodyHeight)
|
||||
}
|
||||
if m.artifactsOpen {
|
||||
content = m.artifactsView(bodyHeight)
|
||||
}
|
||||
if m.mutationCommand != nil {
|
||||
paragraphs := []string{"This opens a new session/editor and may modify a retained draft.", "Published definitions and previous run history are unchanged."}
|
||||
if strings.Contains(m.mutationTitle, "debugging") {
|
||||
|
||||
@@ -87,7 +87,7 @@ func TestLayoutResizes(t *testing.T) {
|
||||
if !strings.HasPrefix(lines[0], "Pipelines ") || !strings.HasSuffix(lines[0], "127.0.0.1:8080") || lipgloss.Width(lines[0]) != size.Width {
|
||||
t.Fatalf("invalid header: %q", lines[0])
|
||||
}
|
||||
if !strings.HasPrefix(lines[len(lines)-1], "/ search") || !strings.Contains(lines[len(lines)-1], ": commands") || !strings.Contains(lines[len(lines)-1], "● 20 NEW") {
|
||||
if !strings.HasPrefix(lines[len(lines)-1], "/ omni search") || !strings.Contains(lines[len(lines)-1], ": commands") || !strings.Contains(lines[len(lines)-1], "● 20 NEW") {
|
||||
t.Fatalf("invalid footer: %q", lines[len(lines)-1])
|
||||
}
|
||||
if strings.TrimSpace(lines[len(lines)-2]) != "" {
|
||||
|
||||
@@ -17,6 +17,28 @@ import (
|
||||
"git.a-wan.net/alan/pipelines/internal/server"
|
||||
)
|
||||
|
||||
// typeSearch types into the omni popup, flushes the outgoing search request and
|
||||
// reads the server response, so a test observes real server-side matches.
|
||||
func typeSearch(t *testing.T, m Model, text string) Model {
|
||||
t.Helper()
|
||||
for _, r := range text {
|
||||
updated, cmd := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{r}})
|
||||
m = updated.(Model)
|
||||
if cmd != nil {
|
||||
if batch, ok := cmd().(tea.BatchMsg); ok {
|
||||
for _, c := range batch {
|
||||
if c != nil {
|
||||
c()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
updated, _ = m.Update(m.read()())
|
||||
m = updated.(Model)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
func TestSearchVersionsAndEditSubmission(t *testing.T) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
@@ -44,9 +66,9 @@ func TestSearchVersionsAndEditSubmission(t *testing.T) {
|
||||
updated, read = m.Update(read())
|
||||
m = updated.(Model)
|
||||
m = press(m, "/")
|
||||
m = press(m, "dmo")
|
||||
if !m.searchOpen || !m.paletteOpen || len(m.searchMatches()) != 1 {
|
||||
t.Fatal("omnisearch failed")
|
||||
m = typeSearch(t, m, "demo")
|
||||
if !m.searchOpen || !m.paletteOpen || len(m.searchResults) != 1 || m.searchResults[0].Kind != protocol.SearchKindPipeline {
|
||||
t.Fatalf("omnisearch failed: %+v", m.searchResults)
|
||||
}
|
||||
updated, send := m.Update(tea.KeyMsg{Type: tea.KeyEnter})
|
||||
m = updated.(Model)
|
||||
|
||||
@@ -101,6 +101,9 @@ func (m *Model) closeRuns() {
|
||||
m.runGraphFocus = false
|
||||
m.runGraphTop = 0
|
||||
m.runGraphPan = 0
|
||||
m.artifactsOpen = false
|
||||
m.artifactIndex = 0
|
||||
m.artifactTop = 0
|
||||
m.closeDecision()
|
||||
}
|
||||
|
||||
@@ -552,7 +555,9 @@ func (m Model) runSectionLines(width int) []string {
|
||||
}
|
||||
var diff []string
|
||||
if !m.runSectionClosed(runSectionFiles) {
|
||||
diff = append(stageDiffLines(step), artifactLines(step)...)
|
||||
// Artifacts have their own grouped view (A); this section is the
|
||||
// observed workspace diff only.
|
||||
diff = stageDiffLines(step)
|
||||
}
|
||||
content = append(content, diff)
|
||||
for _, receipt := range step.Notifications {
|
||||
@@ -646,7 +651,7 @@ func (m Model) runActions() string {
|
||||
text += " · D debug"
|
||||
}
|
||||
if m.runDetail != nil {
|
||||
text += " · a evidence"
|
||||
text += " · a evidence · A artifacts"
|
||||
}
|
||||
if m.runDetail != nil && m.runDetail.Status == protocol.RunStatusWaiting {
|
||||
text += " · c decide"
|
||||
@@ -729,7 +734,7 @@ func (m Model) runsDetailsView(height int) string {
|
||||
lines := m.runSectionLines(m.runDetailWidth())
|
||||
page := max(0, innerHeight-5)
|
||||
top := max(0, min(m.runTop, max(0, len(lines)-page)))
|
||||
footerHint := "o result · d diff · s progress · i input · t evidence · m details"
|
||||
footerHint := "o result · d diff · s progress · i input · t evidence · m details · A artifacts"
|
||||
if r.Status == protocol.RunStatusWaiting {
|
||||
footerHint += " · c decide"
|
||||
}
|
||||
|
||||
@@ -193,7 +193,7 @@ func TestRunningDurationAndOpenCodeEvidenceShortcut(t *testing.T) {
|
||||
m := runInspectionModel()
|
||||
m.runDetail.Steps[1].AgentActive = true
|
||||
m = runKey(m, "a")
|
||||
if m.runStepIndex != 2 || !m.runDetailFocus || m.runSectionClosed(3) || !m.runSectionClosed(0) {
|
||||
if m.runStepIndex != 2 || !m.runDetailFocus || m.runSectionClosed(runSectionEvidence) || !m.runSectionClosed(runSectionProgress) {
|
||||
t.Fatal("OpenCode evidence shortcut did not select active session")
|
||||
}
|
||||
view := ansi.Strip(strings.Join(m.runSectionLines(90), "\n"))
|
||||
|
||||
+13
-4
@@ -322,10 +322,16 @@ func (m Model) updateRuns(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
return m.debugRun()
|
||||
case "a":
|
||||
return m.openOpenCodeEvidence()
|
||||
case "A":
|
||||
if m.runDetail != nil {
|
||||
m.openArtifacts()
|
||||
}
|
||||
return m, nil
|
||||
case "r":
|
||||
return m.retrySelectedRun()
|
||||
case "esc":
|
||||
m.runGraphFocus = false
|
||||
m.artifactsOpen = false
|
||||
if m.runDetail != nil || m.requestedRunID > 0 || m.runStartRequest != "" {
|
||||
m.runDetail = nil
|
||||
m.requestedRunID = 0
|
||||
@@ -400,18 +406,21 @@ func (m Model) updateRuns(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
}
|
||||
case "s", "i", "o", "t", "m":
|
||||
if m.runDetail != nil {
|
||||
m.toggleRunSection(strings.Index("siotm", msg.String()))
|
||||
if index, ok := runSectionForShortcut(msg.String()); ok {
|
||||
m.toggleRunSection(index)
|
||||
}
|
||||
}
|
||||
case "d":
|
||||
if m.runDetail != nil {
|
||||
m.runGraphFocus = false
|
||||
m.runDetailFocus = true
|
||||
_, focused := runFocusedSection(m.runSectionLines(m.runDetailWidth()), m.runTop)
|
||||
if m.runSectionClosed(5) || focused == "File changes" {
|
||||
m.toggleRunSection(5)
|
||||
if m.runSectionClosed(runSectionFiles) || focused == runSections[runSectionFiles].Title {
|
||||
m.toggleRunSection(runSectionFiles)
|
||||
}
|
||||
marker := "[" + runSections[runSectionFiles].Shortcut + "]"
|
||||
for i, line := range m.runSectionLines(m.runDetailWidth()) {
|
||||
if strings.HasPrefix(ansi.Strip(line), "[d]") {
|
||||
if strings.HasPrefix(ansi.Strip(line), marker) {
|
||||
m.runTop = i
|
||||
break
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user