| 1 | package cmd |
| 2 | |
| 3 | import ( |
| 4 | "strings" |
| 5 | "testing" |
| 6 | "time" |
| 7 | |
| 8 | tea "github.com/charmbracelet/bubbletea" |
| 9 | "github.com/charmbracelet/x/ansi" |
| 10 | "the-valley/flow/internal/integration" |
| 11 | "the-valley/flow/internal/restack" |
| 12 | "the-valley/flow/internal/run" |
| 13 | ) |
| 14 | |
| 15 | // TestChangeRowShowsRestackConflict: a change row says where a restack |
| 16 | // conflict on it stands, and one klaus stopped short of resolving is the |
| 17 | // operator's. |
| 18 | func TestChangeRowShowsRestackConflict(t *testing.T) { |
| 19 | now := time.Now() |
| 20 | results := map[string]integration.Result{} |
| 21 | changes := map[integration.ChangeKey]integration.Result{} |
| 22 | var states []*run.State |
| 23 | pushed := func(id, prompt string, c byte) string { |
| 24 | changeID, sha := strings.Repeat(string(c), 32), strings.Repeat(string(c-'k'+'1'), 40) |
| 25 | s := &run.State{ID: id, Prompt: prompt, Type: "launch", ChangeID: changeID, TargetRepo: strPtr("o/r"), |
| 26 | CreatedAt: now.Add(-time.Hour).Format(time.RFC3339), CostUSD: float64Ptr(1), |
| 27 | PushedBranch: strPtr("agent/" + prompt), PushedSHA: &sha} |
| 28 | states = append(states, s) |
| 29 | r := integration.Result{Verdict: integration.Ready, Change: &integration.Change{ |
| 30 | Repo: "r", ChangeID: changeID, Handle: changeID[:4], Version: 1, Head: sha, Active: true}} |
| 31 | results[id], changes[integration.ChangeKey{Repo: "r", ChangeID: changeID}] = r, r |
| 32 | return changeID |
| 33 | } |
| 34 | resolving := pushed("20261027-1200-0001", "resolving", 'k') |
| 35 | stopped := pushed("20261027-1200-0002", "stopped", 'l') |
| 36 | quiet := pushed("20261027-1200-0003", "quiet", 'm') |
| 37 | |
| 38 | m := dashboardModel{ |
| 39 | states: states, tmuxDeps: testDashboardTmuxDeps(), ghStatus: map[string]*prStatus{}, |
| 40 | integration: results, changes: changes, hideAfter: defaultHideFinishedAfter, |
| 41 | restacks: map[integration.ChangeKey]restack.View{ |
| 42 | {Repo: "r", ChangeID: resolving}: {Key: restack.Key{Repo: "r", ChangeID: resolving}, State: restack.StateDispatched, RunID: "20261027-1300-0009", Attempts: 1}, |
| 43 | {Repo: "r", ChangeID: stopped}: {Key: restack.Key{Repo: "r", ChangeID: stopped}, State: restack.StateStopped, Attempts: 3}, |
| 44 | }, |
| 45 | } |
| 46 | m = send(m, tea.WindowSizeMsg{Width: 220, Height: 40}) |
| 47 | plain := ansi.Strip(m.View()) |
| 48 | |
| 49 | for _, tc := range []struct{ prompt, want string }{ |
| 50 | {"resolving", "READY restack conflict resolution run 20261027-1300-0009 dispatched (attempt 1 of 3)"}, |
| 51 | {"stopped", "ATTN restack conflict stopped after 3 resolution runs"}, |
| 52 | } { |
| 53 | if line := lineWith(plain, tc.prompt); !strings.Contains(line, tc.want) { |
| 54 | t.Errorf("%s row should read %q: %q", tc.prompt, tc.want, line) |
| 55 | } |
| 56 | } |
| 57 | if line := lineWith(plain, "quiet"); strings.Contains(line, "restack") { |
| 58 | t.Errorf("a change with no conflict shows one: %q", line) |
| 59 | } |
| 60 | for _, r := range m.buildRows() { |
| 61 | if r.changeID == stopped && (!r.attention || r.category != catYours) { |
| 62 | t.Errorf("a conflict klaus stopped on should be the operator's: attention %v, %s", r.attention, categoryNames[r.category]) |
| 63 | } |
| 64 | if r.changeID == quiet && r.restack != nil { |
| 65 | t.Errorf("a change with no conflict has a restack view: %+v", r.restack) |
| 66 | } |
| 67 | } |
| 68 | } |