Operator activity grouping, so one person's burst no longer hides everyone else (Paul, 2026-10-31). The /fleet dashboard's Latest activity is one row per person (newest 200 audit rows, up to 10 people): last active, action count, latest action and apps. /fleet/activity folds consecutive rows by the same actor on the same account and app within 10 minutes of each other into one expandable row, '{n} actions on {app}', with paging and filters unchanged. A CLI ship followed by the promote of the same build within 10 minutes shows as one 'shipped and promoted {build} to {channel} (cli)' row on the dashboard, Activity and person pages; stored audit rows are unchanged. Copy: 11 strings approved by Paul in copy review (internal/console/opactivity_copy.go); OPS-60 and OPS-62 now name the Activity template. Review: Astra whole-branch round 1 READY AFTER FIXES, its one P2 (a merged row timed only at the promote could split a burst) fixed with a regression test. Not released.
Squashed from fleet-activity-grouping into main.
14 files changed,
+932
−66
docs/superpowers/plans/2026-10-25-operator-pages-copy.md+2 −2internal/console/auditdetail_test.go+8 −5internal/console/opactivity.go+9 −4internal/console/opactivity_copy.go+37 −0internal/console/opactivity_group.go+260 −0internal/console/opactivity_group_test.go+523 −0internal/console/opactivity_test.go+4 −2internal/console/opdashboard.go+20 −5internal/console/opdashboard_test.go+17 −35internal/console/opperson.go+2 −2internal/console/opshots_test.go+12 −0internal/console/static/ops.css+19 −3internal/console/templates/ops_activity.html+13 −3internal/console/templates/ops_dashboard.html+6 −5
CI passed — run details
diff --git a/docs/superpowers/plans/2026-10-25-operator-pages-copy.md b/docs/superpowers/plans/2026-10-25-operator-pages-copy.md| index 9a595cb51..077fc5320 100644 |
| --- a/docs/superpowers/plans/2026-10-25-operator-pages-copy.md |
| +++ b/docs/superpowers/plans/2026-10-25-operator-pages-copy.md |
| @@ -143,9 +143,9 @@ The bar and rail on every operator page. |
| | OPS-57 | templates/ops_dashboard.html | No one has signed up yet. | approved | |
| | OPS-58 | templates/ops_dashboard.html | Latest activity | approved | |
| | OPS-59 | templates/ops_dashboard.html | All activity | approved | |
| -| OPS-60 | templates/ops_dashboard.html (Activity reuses it) | When | approved | |
| +| OPS-60 | templates/ops_activity.html (the dashboard's Latest activity used it until fleet-activity-grouping) | When | approved | |
| | OPS-61 | templates/ops_dashboard.html (Activity reuses it) | Who | approved | |
| -| OPS-62 | templates/ops_dashboard.html (Activity reuses it) | What | approved | |
| +| OPS-62 | templates/ops_activity.html (the dashboard's Latest activity used it until fleet-activity-grouping) | What | approved | |
| | OPS-63 | templates/ops_dashboard.html (Activity reuses it) | App | approved | |
| | OPS-64 | templates/ops_dashboard.html | Nothing has happened yet. | approved | |
| | OPS-65 | templates/ops_dashboard.html | All boxes | approved | |
diff --git a/internal/console/auditdetail_test.go b/internal/console/auditdetail_test.go| index 721a71e77..b813ca252 100644 |
| --- a/internal/console/auditdetail_test.go |
| +++ b/internal/console/auditdetail_test.go |
| @@ -141,19 +141,22 @@ func TestAuditWhatOfOtherRows(t *testing.T) { |
| // TestOperatorFeedsShowWhat: on Activity, the dashboard and a person page, |
| // a JSON row is its summary over the escaped, indented data in a native |
| -// <details>, and long text is one line with its whole in title. |
| +// <details>, and long text is one line with its whole in title. The |
| +// dashboard shows each person's latest row alone, so ben's latest is the |
| +// JSON row and ann's the long one. |
| func TestOperatorFeedsShowWhat(t *testing.T) { |
| fx := newConsoleFixture(t) |
| w := seedOperatorWorld(t, fx) |
| long := strings.Repeat("Changed a long setting ", 4) |
| - for _, r := range []Activity{ |
| - {Action: "store-apply", Detail: `{"note":"<script>alert(1)</script>"}`}, |
| - {Action: "env-set", Detail: long}, |
| - } { |
| + jsonRow := Activity{Action: "store-apply", Detail: `{"note":"<script>alert(1)</script>"}`} |
| + for _, r := range []Activity{jsonRow, {Action: "env-set", Detail: long}} { |
| if err := fx.st.RecordActivity(w.shop.ID, "shop", "ann@example.com", r, w.now); err != nil { |
| t.Fatal(err) |
| } |
| } |
| + if err := fx.st.RecordActivity(w.notes.ID, "notes", "ben@example.com", jsonRow, w.now); err != nil { |
| + t.Fatal(err) |
| + } |
| for path, body := range map[string]string{ |
| "/fleet/activity": peopleGet(t, fx, w.c, "/fleet/activity"), |
| "/fleet": dashGet(t, fx, w.c), |
diff --git a/internal/console/opactivity.go b/internal/console/opactivity.go| index 0e3deae2c..6f870db9a 100644 |
| --- a/internal/console/opactivity.go |
| +++ b/internal/console/opactivity.go |
| @@ -138,8 +138,10 @@ type feedView struct { |
| AccountName string |
| AccountDeleted bool |
| Who, WhoHref string |
| - Rows []FeedRow |
| - Pager opPager |
| + // Entries is the page's rows as lines: ship and promote merged, then |
| + // bursts folded (opactivity_group.go), in the rows' order. |
| + Entries []activityEntry |
| + Pager opPager |
| } |
| // feedDropdown is the kind filter: the current kind as its label, each |
| @@ -155,7 +157,8 @@ func feedDropdown(q feedQuery) opDropdown { |
| // handleActivity serves Activity, for signed-in operators only, behind |
| // operatorOnly's 404-to-everyone gate. It reads one row past the page to |
| -// know whether Older exists. The account filter is resolved whatever the |
| +// know whether Older exists. The filters narrow the rows read; the page's |
| +// rows are then merged and folded for display (opactivity_group.go). The account filter is resolved whatever the |
| // account's deleted_at (OperatorAccountBySqid), so a deleted account's |
| // history stays reachable from its links; a sqid with no row shows nothing. |
| // The person filter is resolved as the person page resolves its address |
| @@ -214,7 +217,9 @@ func (s *Server) handleActivity(w http.ResponseWriter, r *http.Request) { |
| if older { |
| rows = rows[:feedPageSize] |
| } |
| - v.Rows = rows |
| + // Merging and folding work within the page; the cursor below is the |
| + // last stored row read, so paging is the same whatever they fold. |
| + v.Entries = foldBursts(mergeShipPromote(rows)) |
| if q.Before > 0 { |
| v.Pager.Items = append(v.Pager.Items, opPageItem{Label: "Newest", Href: q.first().href()}) |
| } |
diff --git a/internal/console/opactivity_copy.go b/internal/console/opactivity_copy.go| new file mode 100644 |
| index 000000000..8b63efb76 |
| --- /dev/null |
| +++ b/internal/console/opactivity_copy.go |
| @@ -0,0 +1,37 @@ |
| +package console |
| + |
| +// The words of the grouped activity views (opactivity_group.go): the |
| +// dashboard's one row per person, Activity's folded bursts and the merged |
| +// ship and promote row. Every human-facing string those views add lives |
| +// here and nowhere else. Copy review: Paul approved every string below |
| +// unchanged on 2026-10-31. |
| +const ( |
| + // The dashboard's Latest activity columns, in order. |
| + activityHeadLastActive = "Last active" |
| + activityHeadWho = "Who" |
| + activityHeadActions = "Actions" |
| + activityHeadLatest = "Latest" |
| + activityHeadApps = "Apps" |
| + |
| + // A person's count of actions on the dashboard. |
| + activityActionsOne = "1 action" |
| + activityActionsMany = "%d actions" |
| + |
| + // A person's apps on the dashboard: the most recent app's name and how |
| + // many other apps they touched. |
| + activityAppsMore = "%s and %d more" |
| + |
| + // A folded burst on Activity: how many actions, on which app, or with |
| + // no app. |
| + activityFoldOnApp = "%d actions on %s" |
| + activityFoldBare = "%d actions" |
| + |
| + // A ship and the promote of the same build, shown as one row: the |
| + // build, the channel and the ship's source marker, such as "(cli)". |
| + activityShippedPromoted = "shipped and promoted %s to %s %s" |
| +) |
| + |
| +// activityDashHead is the dashboard's Latest activity head row. |
| +var activityDashHead = []string{ |
| + activityHeadLastActive, activityHeadWho, activityHeadActions, activityHeadLatest, activityHeadApps, |
| +} |
diff --git a/internal/console/opactivity_group.go b/internal/console/opactivity_group.go| new file mode 100644 |
| index 000000000..e756e813c |
| --- /dev/null |
| +++ b/internal/console/opactivity_group.go |
| @@ -0,0 +1,260 @@ |
| +package console |
| + |
| +import ( |
| + "fmt" |
| + "strings" |
| + "time" |
| +) |
| + |
| +// How the operator pages group audit rows for display (Paul, 2026-10-31): |
| +// one person's burst of actions should not hide everyone else's. Three |
| +// display-only rules, none of which changes a stored row: |
| +// |
| +// - a ship followed by the promote of the same build, by the same actor |
| +// on the same app within activityBurstGap, shows as one row |
| +// (mergeShipPromote): the dashboard, Activity and the person page; |
| +// - on Activity, a run of rows by the same actor on the same app (or |
| +// with no app), each within activityBurstGap of the row above it, |
| +// folds into one row that opens onto them (foldBursts); |
| +// - the dashboard's Latest activity is one row per person (dashActors). |
| +// |
| +// Everything works on rows already read, newest first by id: nothing here |
| +// reads the store. |
| + |
| +// activityBurstGap is the longest gap between two rows of one burst, and |
| +// between a ship and the promote it merges with. |
| +const activityBurstGap = 10 * time.Minute |
| + |
| +// activityRow is one row as an operator list shows it: a stored audit row, |
| +// or a ship and the promote of its build merged into one (Detail then |
| +// holds the merged sentence, and the row is the promote's: its id, time |
| +// and action). N is how many stored rows it stands for, 1 or 2. |
| +type activityRow struct { |
| + FeedRow |
| + N int |
| + // Oldest is the time of the oldest stored row the line stands for: |
| + // a merged ship and promote is timed at the promote (At) but began at |
| + // the ship, and a burst is judged on the gap from there. |
| + Oldest time.Time |
| +} |
| + |
| +// oldest is when the line's first stored row happened (At for a line of |
| +// one row). |
| +func (r activityRow) oldest() time.Time { |
| + if r.Oldest.IsZero() { |
| + return r.At |
| + } |
| + return r.Oldest |
| +} |
| + |
| +// The source markers a merged row accepts: the ship's (apicli.go's ship, |
| +// apiship_rootfs.go's rootfs ship) and the promote's (apicli.go's promote). |
| +// A console promote (no marker) or a confirmed proposal ("(proposed by |
| +// ...)") is never merged: the merged sentence could not say both sources. |
| +var ( |
| + activityShipSources = map[string]bool{"(cli)": true, "(cli, rootfs)": true} |
| + activityPromoteSource = "(cli)" |
| +) |
| + |
| +// activityParseShip reads a ship row's stored Detail, "shipped <build> |
| +// <marker>": ok only for that exact shape with a known marker. |
| +func activityParseShip(r FeedRow) (build, marker string, ok bool) { |
| + if r.Action != "ship" { |
| + return "", "", false |
| + } |
| + rest, ok := strings.CutPrefix(r.Detail, "shipped ") |
| + if !ok { |
| + return "", "", false |
| + } |
| + build, marker, ok = strings.Cut(rest, " ") |
| + if !ok || build == "" || !activityShipSources[marker] { |
| + return "", "", false |
| + } |
| + return build, marker, true |
| +} |
| + |
| +// activityParsePromote reads a promote row's stored Detail, "promoted |
| +// <build> to <channel> (cli)": ok only for that exact shape. |
| +func activityParsePromote(r FeedRow) (build, channel string, ok bool) { |
| + if r.Action != "promote" { |
| + return "", "", false |
| + } |
| + rest, ok := strings.CutPrefix(r.Detail, "promoted ") |
| + if !ok { |
| + return "", "", false |
| + } |
| + build, rest, ok = strings.Cut(rest, " to ") |
| + if !ok || build == "" || strings.ContainsAny(build, " \t\n") { |
| + return "", "", false |
| + } |
| + channel, marker, ok := strings.Cut(rest, " ") |
| + if !ok || channel == "" || marker != activityPromoteSource { |
| + return "", "", false |
| + } |
| + return build, channel, true |
| +} |
| + |
| +// activityMerge is the one row a promote and the row below it (older) |
| +// show as, when that row is the ship of the same build by the same actor |
| +// on the same app of the same account, no more than activityBurstGap |
| +// before it. |
| +func activityMerge(promote, ship FeedRow) (activityRow, bool) { |
| + build, channel, ok := activityParsePromote(promote) |
| + if !ok { |
| + return activityRow{}, false |
| + } |
| + shipped, marker, ok := activityParseShip(ship) |
| + if !ok || shipped != build { |
| + return activityRow{}, false |
| + } |
| + if promote.Address != ship.Address || promote.AccountSqid != ship.AccountSqid || promote.App != ship.App || promote.App == "" { |
| + return activityRow{}, false |
| + } |
| + if gap := promote.At.Sub(ship.At); gap < 0 || gap > activityBurstGap { |
| + return activityRow{}, false |
| + } |
| + merged := promote |
| + merged.Detail = fmt.Sprintf(activityShippedPromoted, build, channel, marker) |
| + return activityRow{FeedRow: merged, N: 2, Oldest: ship.At}, true |
| +} |
| + |
| +// mergeShipPromote is rows (newest first) as a list shows them: each |
| +// promote directly above the ship it merges with (activityMerge) becomes |
| +// one row, timed at the promote; every other row stands as it is. |
| +func mergeShipPromote(rows []FeedRow) []activityRow { |
| + out := make([]activityRow, 0, len(rows)) |
| + for i := 0; i < len(rows); i++ { |
| + if i+1 < len(rows) { |
| + if m, ok := activityMerge(rows[i], rows[i+1]); ok { |
| + out = append(out, m) |
| + i++ |
| + continue |
| + } |
| + } |
| + out = append(out, activityRow{FeedRow: rows[i], N: 1}) |
| + } |
| + return out |
| +} |
| + |
| +// activityEntry is one line of Activity: a row, or a burst folded into |
| +// one (Rows holds the burst's rows, newest first, and the line is its |
| +// newest). Actions is the stored rows the line stands for. |
| +type activityEntry struct { |
| + activityRow |
| + Rows []activityRow |
| + Actions int |
| +} |
| + |
| +// Folded is whether the line is a burst of two rows or more. |
| +func (e activityEntry) Folded() bool { return len(e.Rows) > 1 } |
| + |
| +// FoldText is a burst's What: how many actions, and on which app. |
| +func (e activityEntry) FoldText() string { |
| + if e.App != "" { |
| + return fmt.Sprintf(activityFoldOnApp, e.Actions, e.App) |
| + } |
| + return fmt.Sprintf(activityFoldBare, e.Actions) |
| +} |
| + |
| +// activitySameBurst is whether b, the row below a, continues a's burst: |
| +// the same actor, account and app (or both with no app), no more than |
| +// activityBurstGap apart. The gap is between consecutive stored rows: from |
| +// a's oldest (a merged line's ship) to b's newest (a merged line's |
| +// promote), so merging never splits a burst the stored rows make. |
| +func activitySameBurst(a, b activityRow) bool { |
| + if a.Address != b.Address || a.AccountSqid != b.AccountSqid || a.App != b.App { |
| + return false |
| + } |
| + gap := a.oldest().Sub(b.At) |
| + if gap < 0 { |
| + gap = -gap |
| + } |
| + return gap <= activityBurstGap |
| +} |
| + |
| +// foldBursts is rows (newest first) as Activity's lines, in the same |
| +// order: each run of rows where every row continues the burst of the one |
| +// above it (activitySameBurst) is one line; a run of one is a plain line. |
| +func foldBursts(rows []activityRow) []activityEntry { |
| + var out []activityEntry |
| + for i := 0; i < len(rows); { |
| + j := i + 1 |
| + for j < len(rows) && activitySameBurst(rows[j-1], rows[j]) { |
| + j++ |
| + } |
| + e := activityEntry{activityRow: rows[i]} |
| + for _, r := range rows[i:j] { |
| + e.Actions += r.N |
| + } |
| + if j-i > 1 { |
| + e.Rows = rows[i:j] |
| + } |
| + out = append(out, e) |
| + i = j |
| + } |
| + return out |
| +} |
| + |
| +// dashActor is one person on the dashboard's Latest activity: their newest |
| +// row's time, how many actions they made in the window, their latest |
| +// action (ship and promote merged) and the apps they touched. |
| +type dashActor struct { |
| + Address string |
| + At time.Time |
| + Actions int |
| + Latest activityRow |
| + // Apps is the most recent app's name, with how many other apps they |
| + // touched; "" when no row of theirs names an app. |
| + Apps string |
| +} |
| + |
| +// ActionsText is the Actions cell. |
| +func (a dashActor) ActionsText() string { |
| + if a.Actions == 1 { |
| + return activityActionsOne |
| + } |
| + return fmt.Sprintf(activityActionsMany, a.Actions) |
| +} |
| + |
| +// dashActors is up to limit people from rows (newest first), one each, |
| +// in the order of their newest row. An app is its account and name: two |
| +// accounts' apps of one name are two apps. |
| +func dashActors(rows []FeedRow, limit int) []dashActor { |
| + var order []string |
| + byActor := map[string][]FeedRow{} |
| + for _, r := range rows { |
| + if _, ok := byActor[r.Address]; !ok { |
| + order = append(order, r.Address) |
| + } |
| + byActor[r.Address] = append(byActor[r.Address], r) |
| + } |
| + if len(order) > limit { |
| + order = order[:limit] |
| + } |
| + out := make([]dashActor, 0, len(order)) |
| + for _, who := range order { |
| + mine := byActor[who] |
| + a := dashActor{Address: who, At: mine[0].At, Actions: len(mine), Latest: mergeShipPromote(mine)[0]} |
| + type appKey struct{ acct, app string } |
| + seen := map[appKey]bool{} |
| + var recent string |
| + for _, r := range mine { |
| + if r.App == "" { |
| + continue |
| + } |
| + k := appKey{r.AccountSqid, r.App} |
| + if len(seen) == 0 { |
| + recent = r.App |
| + } |
| + seen[k] = true |
| + } |
| + switch { |
| + case len(seen) == 1: |
| + a.Apps = recent |
| + case len(seen) > 1: |
| + a.Apps = fmt.Sprintf(activityAppsMore, recent, len(seen)-1) |
| + } |
| + out = append(out, a) |
| + } |
| + return out |
| +} |
diff --git a/internal/console/opactivity_group_test.go b/internal/console/opactivity_group_test.go| new file mode 100644 |
| index 000000000..3e18e09b4 |
| --- /dev/null |
| +++ b/internal/console/opactivity_group_test.go |
| @@ -0,0 +1,523 @@ |
| +package console |
| + |
| +import ( |
| + "fmt" |
| + "html" |
| + "net/http" |
| + "regexp" |
| + "slices" |
| + "strconv" |
| + "strings" |
| + "testing" |
| + "time" |
| +) |
| + |
| +// The grouped activity views (opactivity_group.go): the dashboard's one row |
| +// per person, Activity's folded bursts, and ship and promote merged on |
| +// every operator list. Every test here reads the pages through the real |
| +// handlers and templates. |
| + |
| +// dashActorCells is one row of the dashboard's Latest activity: who, the |
| +// Actions cell, the Latest cell's text and the Apps cell's markup. |
| +type dashActorCells struct{ Who, Actions, Latest, Apps string } |
| + |
| +var dashActorRow = regexp.MustCompile(`^><span class="rst-cell-mut" title="[^"]*">[^<]*</span>` + |
| + `(?:<a href="[^"]*">([^<]*)</a>|<span>([^<]*)</span>)<span>([^<]*)</span>` + |
| + `<span co-clip(?: title="[^"]*")?>([^<]*)</span>(<span>[^<]*</span>|<span class="rst-cell-mut">none</span>)</div>`) |
| + |
| +// dashActorRows is the dashboard's Latest activity: its head row and each |
| +// row parsed to its cells. |
| +func dashActorRows(t *testing.T, body string) (head string, rows []dashActorCells) { |
| + t.Helper() |
| + parts := dashRows(dashSection(t, body, "Latest activity")) |
| + if len(parts) == 0 { |
| + return "", nil |
| + } |
| + for _, r := range parts[1:] { |
| + m := dashActorRow.FindStringSubmatch(r) |
| + if m == nil { |
| + t.Fatalf("a Latest activity row is not Last active, Who, Actions, Latest, Apps: %s", r) |
| + } |
| + rows = append(rows, dashActorCells{Who: html.UnescapeString(m[1] + m[2]), Actions: m[3], |
| + Latest: html.UnescapeString(m[4]), Apps: html.UnescapeString(m[5])}) |
| + } |
| + return parts[0], rows |
| +} |
| + |
| +// feedLine is one line of Activity: a row, or a folded burst whose What is |
| +// its fold text, whose When title is Title and whose rows are Inner. |
| +type feedLine struct { |
| + feedRow |
| + Fold bool |
| + Title string |
| + Inner []feedRow |
| +} |
| + |
| +var feedFoldSummary = regexp.MustCompile(`^<details co-fold><summary rst-lrow><span class="rst-cell-mut" title="([^"]*)">[^<]*</span>` + |
| + `(?:<a href="([^"]*)">([^<]*)</a>|<span>([^<]*)</span>)(<a href="[^"]*">[^<]*</a>|<span class="rst-cell-mut">none</span>)` + |
| + `<span co-clip>([^<]*)<span rst-caret aria-hidden="true"><svg[^>]*>.*?</svg></span></span>` + |
| + `(<span>[^<]*</span>|<span class="rst-cell-mut">none</span>)</summary>$`) |
| + |
| +// feedLines is Activity's lines, newest first. It reads the template's |
| +// layout of one row per source line, so it is for rows with no stored |
| +// JSON (whose <pre> spans lines). |
| +func feedLines(t *testing.T, body string) []feedLine { |
| + t.Helper() |
| + list := dashCut(t, body, `<div rst-card co-cols="feed">`, "</main>") |
| + var out []feedLine |
| + var open *feedLine |
| + row := func(line string) feedRow { |
| + m := feedRowCells.FindStringSubmatch(strings.TrimPrefix(line, "<div rst-lrow")) |
| + if m == nil { |
| + t.Fatalf("a feed row is not When, Who, Account, What, App: %s", line) |
| + } |
| + return feedRow{Who: html.UnescapeString(m[2] + m[3]), WhoHref: html.UnescapeString(m[1]), |
| + Account: m[4], What: html.UnescapeString(m[5]), App: m[6]} |
| + } |
| + for _, line := range strings.Split(list, "\n") { |
| + line = strings.TrimSpace(line) |
| + switch { |
| + case strings.HasPrefix(line, "<details co-fold>"): |
| + m := feedFoldSummary.FindStringSubmatch(line) |
| + if m == nil { |
| + t.Fatalf("a fold's summary is not When, Who, Account, its count, App: %s", line) |
| + } |
| + open = &feedLine{Fold: true, Title: m[1], feedRow: feedRow{Who: html.UnescapeString(m[3] + m[4]), |
| + WhoHref: html.UnescapeString(m[2]), Account: m[5], What: html.UnescapeString(m[6]), App: m[7]}} |
| + case line == "</details>" && open != nil: // the toolbar's dropdown closes its own |
| + out = append(out, *open) |
| + open = nil |
| + case strings.HasPrefix(line, "<div rst-lrow>"): |
| + if open != nil { |
| + open.Inner = append(open.Inner, row(line)) |
| + } else { |
| + out = append(out, feedLine{feedRow: row(line)}) |
| + } |
| + } |
| + } |
| + if open != nil { |
| + t.Fatal("a fold is never closed") |
| + } |
| + return out |
| +} |
| + |
| +// lineWhats is each inner row's What. |
| +func lineWhats(rows []feedRow) []string { |
| + var out []string |
| + for _, r := range rows { |
| + out = append(out, r.What) |
| + } |
| + return out |
| +} |
| + |
| +// lineSummary is a line as "who: what [inner whats]", for comparing pages. |
| +func lineSummary(lines []feedLine) []string { |
| + var out []string |
| + for _, l := range lines { |
| + s := l.Who + ": " + l.What |
| + if l.Fold { |
| + s += " [" + strings.Join(lineWhats(l.Inner), ", ") + "]" |
| + } |
| + out = append(out, s) |
| + } |
| + return out |
| +} |
| + |
| +// groupTitle is a row's When title for at. |
| +func groupTitle(at time.Time) string { return at.UTC().Format("2006-01-02 15:04 UTC") } |
| + |
| +// groupActions is the Actions cell for who's audit rows, every one of |
| +// them (the tests' worlds are smaller than the dashboard's window). |
| +func groupActions(t *testing.T, fx *consoleFixture, who string) string { |
| + t.Helper() |
| + ids, _ := feedAudit(t, fx, "address = ?", who) |
| + if len(ids) == 1 { |
| + return "1 action" |
| + } |
| + return fmt.Sprintf("%d actions", len(ids)) |
| +} |
| + |
| +// groupRecord records one audit row at at, failing the test on an error. |
| +func groupRecord(t *testing.T, fx *consoleFixture, acct int64, app, who, action, detail string, at time.Time) { |
| + t.Helper() |
| + if err := fx.st.RecordActivity(acct, app, who, Activity{Action: action, Detail: detail}, at); err != nil { |
| + t.Fatal(err) |
| + } |
| +} |
| + |
| +// groupCart gives shop's account a second app, cart. |
| +func groupCart(t *testing.T, fx *consoleFixture, w operatorWorld) { |
| + t.Helper() |
| + if _, err := fx.st.CreateAppIn(w.shop.ID, "cart", "ann@example.com", w.now); err != nil { |
| + t.Fatal(err) |
| + } |
| +} |
| + |
| +// TestDashboardLatestActivityIsOnePersonPerRow: ann's ten-minute burst of |
| +// ten actions (create, config, ship and promote) no longer hides ben and |
| +// cat; her row counts the burst, shows her latest action with the |
| +// ship and promote merged, and names her most recent app and the other. |
| +// At most ten people show, newest first. |
| +func TestDashboardLatestActivityIsOnePersonPerRow(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + w := seedOperatorWorld(t, fx) |
| + groupCart(t, fx, w) |
| + t0 := w.now.Add(time.Minute) |
| + groupRecord(t, fx, w.notes.ID, "notes", "ben@example.com", "rename", "Renamed notes", t0) |
| + burst := []struct{ app, action, detail string }{ |
| + {"cart", "instance-create", "Created instance eu"}, |
| + {"shop", "instance-create", "Created instance uk"}, |
| + } |
| + for i := 0; i < 6; i++ { |
| + burst = append(burst, struct{ app, action, detail string }{"shop", "env-set", fmt.Sprintf("Set FOO_%d", i)}) |
| + } |
| + burst = append(burst, struct{ app, action, detail string }{"shop", "ship", "shipped v7 (cli)"}, |
| + struct{ app, action, detail string }{"shop", "promote", "promoted v7 to canary/eu (cli)"}) |
| + for i, b := range burst { |
| + groupRecord(t, fx, w.shop.ID, b.app, "ann@example.com", b.action, b.detail, t0.Add(time.Duration(i+1)*time.Minute)) |
| + } |
| + |
| + head, rows := dashActorRows(t, dashGet(t, fx, w.c)) |
| + if want := "<span>Last active</span><span>Who</span><span>Actions</span><span>Latest</span><span>Apps</span>"; !strings.Contains(head, want) { |
| + t.Errorf("Latest activity head: %s", head) |
| + } |
| + none := `<span class="rst-cell-mut">none</span>` |
| + want := []dashActorCells{ |
| + {Who: "ann@example.com", Actions: groupActions(t, fx, "ann@example.com"), Latest: "shipped and promoted v7 to canary/eu (cli)", Apps: "<span>shop and 1 more</span>"}, |
| + {Who: "ben@example.com", Actions: groupActions(t, fx, "ben@example.com"), Latest: "Renamed notes", Apps: "<span>notes</span>"}, |
| + {Who: "cat@example.com", Actions: "1 action", Latest: "Signed in", Apps: none}, |
| + {Who: "paul@keymail.dev", Actions: "1 action", Latest: "Signed in for the first time", Apps: none}, |
| + } |
| + if want[0].Actions != "13 actions" { |
| + t.Errorf("ann has %s, want the burst's ten and the world's three", want[0].Actions) |
| + } |
| + if !slices.Equal(rows, want) { |
| + t.Errorf("Latest activity =\n%+v\nwant\n%+v", rows, want) |
| + } |
| + |
| + // Eleven more people, each newer than ann: the ten newest show. |
| + for i := 0; i < 11; i++ { |
| + groupRecord(t, fx, 0, "", fmt.Sprintf("p%02d@example.com", i), "signin", "Signed in", t0.Add(time.Hour)) |
| + } |
| + _, rows = dashActorRows(t, dashGet(t, fx, w.c)) |
| + if len(rows) != dashActivityPeople { |
| + t.Fatalf("%d people in Latest activity, want %d", len(rows), dashActivityPeople) |
| + } |
| + for i, r := range rows { |
| + if want := fmt.Sprintf("p%02d@example.com", 10-i); r.Who != want { |
| + t.Errorf("row %d is %s, want %s", i, r.Who, want) |
| + } |
| + } |
| +} |
| + |
| +// TestActivityFoldsBursts: on Activity, ann's run of rows on shop, each |
| +// within ten minutes of the one above it, is one line timed at its newest, |
| +// opening onto the rows; her row eleven minutes before the run stays its |
| +// own line. Ben and cat, interleaved, never fold together. Two sign-ins in |
| +// a row with no app fold with no app named. Filters apply first: ben's |
| +// rows fold once cat's are filtered away, and cat's on shop once the |
| +// account filter drops ben's. |
| +func TestActivityFoldsBursts(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + w := seedOperatorWorld(t, fx) |
| + t0 := w.now.Add(time.Minute) |
| + ann := func(what string, at time.Duration) { |
| + groupRecord(t, fx, w.shop.ID, "shop", "ann@example.com", "env-set", what, t0.Add(at)) |
| + } |
| + ann("Early", 0) |
| + ann("Burst 1", 11*time.Minute) |
| + ann("Burst 2", 16*time.Minute) |
| + ann("Burst 3", 21*time.Minute) |
| + ann("Burst 4", 26*time.Minute) |
| + groupRecord(t, fx, w.notes.ID, "notes", "ben@example.com", "rename", "Ben 1", t0.Add(27*time.Minute)) |
| + groupRecord(t, fx, w.shop.ID, "shop", "cat@example.com", "rename", "Cat 1", t0.Add(27*time.Minute)) |
| + groupRecord(t, fx, w.notes.ID, "notes", "ben@example.com", "rename", "Ben 2", t0.Add(28*time.Minute)) |
| + groupRecord(t, fx, w.shop.ID, "shop", "cat@example.com", "rename", "Cat 2", t0.Add(28*time.Minute)) |
| + groupRecord(t, fx, 0, "", "cat@example.com", "signin", "Signed in", t0.Add(30*time.Minute)) |
| + groupRecord(t, fx, 0, "", "cat@example.com", "signin", "Signed in", t0.Add(31*time.Minute)) |
| + |
| + lines := feedLines(t, peopleGet(t, fx, w.c, "/fleet/activity")) |
| + want := []string{ |
| + "cat@example.com: 2 actions [Signed in, Signed in]", |
| + "cat@example.com: Cat 2", |
| + "ben@example.com: Ben 2", |
| + "cat@example.com: Cat 1", |
| + "ben@example.com: Ben 1", |
| + "ann@example.com: 4 actions on shop [Burst 4, Burst 3, Burst 2, Burst 1]", |
| + "ann@example.com: Early", |
| + "ann@example.com: Invited dan@example.com", |
| + } |
| + if got := lineSummary(lines); len(got) < len(want) || !slices.Equal(got[:len(want)], want) { |
| + t.Fatalf("Activity =\n%s\nwant it to start\n%s", strings.Join(got, "\n"), strings.Join(want, "\n")) |
| + } |
| + none := `<span class="rst-cell-mut">none</span>` |
| + if l := lines[0]; l.App != none || l.Account != none || l.Title != groupTitle(t0.Add(31*time.Minute)) { |
| + t.Errorf("the sign-ins' fold = %+v, want no app or account, timed at the newest", l) |
| + } |
| + shopLink := `<a href="/fleet/activity?account=` + w.shop.Sqid + `">shop</a>` |
| + if l := lines[5]; l.App != "<span>shop</span>" || l.Account != shopLink || l.WhoHref != "/fleet/people/ann@example.com" || |
| + l.Title != groupTitle(t0.Add(26*time.Minute)) { |
| + t.Errorf("ann's fold = %+v, want shop's, linking ann, timed at Burst 4", l) |
| + } |
| + |
| + // A person filter: ben's two rows are now a run. |
| + got := lineSummary(feedLines(t, peopleGet(t, fx, w.c, "/fleet/activity?who=ben@example.com"))) |
| + if want := []string{"ben@example.com: 2 actions on notes [Ben 2, Ben 1]", "ben@example.com: Made v1 live"}; len(got) < 2 || !slices.Equal(got[:2], want) { |
| + t.Errorf("ben's Activity = %q, want %q", got, want) |
| + } |
| + // An account filter: cat's two on shop are now a run, and ann's burst |
| + // still folds. |
| + got = lineSummary(feedLines(t, peopleGet(t, fx, w.c, "/fleet/activity?account="+w.shop.Sqid))) |
| + want = []string{ |
| + "cat@example.com: 2 actions on shop [Cat 2, Cat 1]", |
| + "ann@example.com: 4 actions on shop [Burst 4, Burst 3, Burst 2, Burst 1]", |
| + "ann@example.com: Early", |
| + } |
| + if len(got) < len(want) || !slices.Equal(got[:len(want)], want) { |
| + t.Errorf("shop's Activity =\n%s\nwant it to start\n%s", strings.Join(got, "\n"), strings.Join(want, "\n")) |
| + } |
| + // A kind filter: the sign-ins alone, cat's two folded. |
| + got = lineSummary(feedLines(t, peopleGet(t, fx, w.c, "/fleet/activity?kind=signins"))) |
| + if len(got) == 0 || got[0] != "cat@example.com: 2 actions [Signed in, Signed in]" { |
| + t.Errorf("the sign-ins = %q, want cat's two folded first", got) |
| + } |
| + for _, l := range got { |
| + if strings.Contains(l, "Burst") || strings.Contains(l, "Ben") { |
| + t.Errorf("the sign-ins kind shows %q", l) |
| + } |
| + } |
| +} |
| + |
| +// TestActivityFoldsWithinThePage: a burst longer than a page folds within |
| +// each page, and paging stays on the stored rows' ids: page one is one |
| +// line of fifty, Older starts after its fiftieth row, and page two folds |
| +// the burst's other five. |
| +func TestActivityFoldsWithinThePage(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + w := seedOperatorWorld(t, fx) |
| + t0 := w.now.Add(time.Minute) |
| + for i := 0; i < 55; i++ { |
| + groupRecord(t, fx, w.shop.ID, "shop", "ann@example.com", "env-set", fmt.Sprintf("Set variable %02d", i), t0.Add(time.Duration(i)*time.Minute)) |
| + } |
| + ids, details := feedAudit(t, fx, "") |
| + |
| + body := peopleGet(t, fx, w.c, "/fleet/activity") |
| + lines := feedLines(t, body) |
| + if len(lines) != 1 || !lines[0].Fold || lines[0].What != "50 actions on shop" { |
| + t.Fatalf("page one = %q, want one fold of fifty", lineSummary(lines)) |
| + } |
| + if got := strings.Join(lineWhats(lines[0].Inner), "|"); got != strings.Join(details[:feedPageSize], "|") { |
| + t.Errorf("page one's fold is not the newest fifty rows:\n got %s", got) |
| + } |
| + older := feedPagerLink(body, "Older") |
| + if want := "/fleet/activity?before=" + strconv.FormatInt(ids[feedPageSize-1], 10); older != want { |
| + t.Fatalf("Older = %q, want %q", older, want) |
| + } |
| + body = peopleGet(t, fx, w.c, older) |
| + lines = feedLines(t, body) |
| + if len(lines) == 0 || !lines[0].Fold || lines[0].What != "5 actions on shop" || |
| + strings.Join(lineWhats(lines[0].Inner), "|") != strings.Join(details[feedPageSize:feedPageSize+5], "|") { |
| + t.Fatalf("page two = %q, want the burst's other five folded first", lineSummary(lines)) |
| + } |
| + if got := feedPagerLink(body, "Newest"); got != "/fleet/activity" { |
| + t.Errorf("page two's Newest = %q", got) |
| + } |
| +} |
| + |
| +// TestShipAndPromoteMergeThroughTheDoors: a ship and a promote made |
| +// through the real CLI doors show as one row on Activity, the dashboard |
| +// and the person page, and neither stored row shows on its own. The |
| +// stored rows are unchanged. |
| +func TestShipAndPromoteMergeThroughTheDoors(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + liftShipBudget(fx) |
| + c := signInOperator(t, fx) |
| + if _, err := fx.st.CreateAppIn(OpsAccountID, "titogo", "paul@keymail.dev", time.Now()); err != nil { |
| + t.Fatal(err) |
| + } |
| + token := cliToken(t, fx, "paul@keymail.dev", "code-group-merge") |
| + if status, out := postShip(t, fx.ts.URL+"/api/cli/apps/bab/titogo/releases", token, |
| + []shipPart{metaPart(t, "abc1234", "binary"), {name: "linux-arm64", body: randomBytes(t, 256)}}); status != http.StatusCreated { |
| + t.Fatalf("ship = %d %v", status, out) |
| + } |
| + if status, out := postJSON(t, fx.ts.URL+"/api/cli/apps/bab/titogo/promote", |
| + map[string]string{"version": "abc1234", "channel": "canary/x"}, token); status != http.StatusOK { |
| + t.Fatalf("promote = %d %v", status, out) |
| + } |
| + _, stored := feedAudit(t, fx, "action IN ('ship', 'promote')") |
| + if want := []string{"promoted abc1234 to canary/x (cli)", "shipped abc1234 (cli)"}; !slices.Equal(stored, want) { |
| + t.Fatalf("stored rows = %q, want %q", stored, want) |
| + } |
| + |
| + merged := "<span co-clip>shipped and promoted abc1234 to canary/x (cli)</span>" |
| + for path, body := range map[string]string{ |
| + "/fleet/activity": peopleGet(t, fx, c, "/fleet/activity"), |
| + "/fleet": dashGet(t, fx, c), |
| + "/fleet/people/paul@keymail.dev": personGet(t, fx, c, "paul@keymail.dev"), |
| + } { |
| + if strings.Count(body, merged) != 1 { |
| + t.Errorf("%s does not show the ship and promote as one row", path) |
| + } |
| + for _, s := range stored { |
| + if strings.Contains(body, ">"+s+"<") { |
| + t.Errorf("%s shows %q on its own", path, s) |
| + } |
| + } |
| + } |
| + _, rows := dashActorRows(t, dashGet(t, fx, c)) |
| + if len(rows) == 0 || rows[0].Who != "paul@keymail.dev" || rows[0].Latest != "shipped and promoted abc1234 to canary/x (cli)" { |
| + t.Errorf("the dashboard's first row = %+v, want paul's merged deploy", rows) |
| + } |
| +} |
| + |
| +// TestShipAndPromoteMergeOnlyTheSameBuild: the merge needs the same |
| +// build, actor, account and app, the ship no more than ten minutes before |
| +// the promote, and both rows in the shape the CLI doors store. Each case |
| +// is thirty minutes from the next, so none merges or folds with another. |
| +func TestShipAndPromoteMergeOnlyTheSameBuild(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + w := seedOperatorWorld(t, fx) |
| + groupCart(t, fx, w) |
| + type row struct{ app, who, action, detail string } |
| + ann := "ann@example.com" |
| + // The cases that merge come last, so that they are among the twenty |
| + // rows of ann's the person page shows. |
| + cases := []struct { |
| + name string |
| + ship, prom row |
| + gap time.Duration |
| + merged string // "" when the two stay apart |
| + }{ |
| + {"another build", row{"shop", ann, "ship", "shipped v4 (cli)"}, row{"shop", ann, "promote", "promoted v5 to canary/x (cli)"}, |
| + time.Minute, ""}, |
| + {"another actor", row{"shop", "cat@example.com", "ship", "shipped v6 (cli)"}, row{"shop", ann, "promote", "promoted v6 to canary/x (cli)"}, |
| + time.Minute, ""}, |
| + {"another app", row{"cart", ann, "ship", "shipped v7 (cli)"}, row{"shop", ann, "promote", "promoted v7 to canary/x (cli)"}, |
| + time.Minute, ""}, |
| + {"eleven minutes", row{"shop", ann, "ship", "shipped v8 (cli)"}, row{"shop", ann, "promote", "promoted v8 to canary/x (cli)"}, |
| + 11 * time.Minute, ""}, |
| + {"no source on the ship", row{"shop", ann, "ship", "shipped v9"}, row{"shop", ann, "promote", "promoted v9 to canary/x (cli)"}, |
| + time.Minute, ""}, |
| + {"a console promote", row{"shop", ann, "ship", "shipped v10 (cli)"}, row{"shop", ann, "promote", "promoted v10 to canary/x"}, |
| + time.Minute, ""}, |
| + {"a confirmed proposal", row{"shop", ann, "ship", "shipped v11 (cli)"}, row{"shop", ann, "promote", "promoted v11 to production (proposed by cat@example.com, 2 confirmations)"}, |
| + time.Minute, ""}, |
| + {"no channel", row{"shop", ann, "ship", "shipped v12 (cli)"}, row{"shop", ann, "promote", "promoted v12 to (cli)"}, |
| + time.Minute, ""}, |
| + {"an unclosed source", row{"shop", ann, "ship", "shipped v13 (cli"}, row{"shop", ann, "promote", "promoted v13 to canary/x (cli)"}, |
| + time.Minute, ""}, |
| + {"same build", row{"shop", ann, "ship", "shipped v1 (cli)"}, row{"shop", ann, "promote", "promoted v1 to canary/x (cli)"}, |
| + 9 * time.Minute, "shipped and promoted v1 to canary/x (cli)"}, |
| + {"ten minutes exactly", row{"shop", ann, "ship", "shipped v2 (cli)"}, row{"shop", ann, "promote", "promoted v2 to canary/x (cli)"}, |
| + 10 * time.Minute, "shipped and promoted v2 to canary/x (cli)"}, |
| + {"rootfs", row{"shop", ann, "ship", "shipped v3 (cli, rootfs)"}, row{"shop", ann, "promote", "promoted v3 to stable (cli)"}, |
| + time.Minute, "shipped and promoted v3 to stable (cli, rootfs)"}, |
| + } |
| + base := w.now.Add(time.Hour) |
| + for i, c := range cases { |
| + at := base.Add(time.Duration(i) * 30 * time.Minute) |
| + groupRecord(t, fx, w.shop.ID, c.ship.app, c.ship.who, c.ship.action, c.ship.detail, at) |
| + groupRecord(t, fx, w.shop.ID, c.prom.app, c.prom.who, c.prom.action, c.prom.detail, at.Add(c.gap)) |
| + } |
| + pages := map[string]string{ |
| + "/fleet/activity": peopleGet(t, fx, w.c, "/fleet/activity"), |
| + "/fleet/people/ann@example.com": personGet(t, fx, w.c, "ann@example.com"), |
| + } |
| + for _, c := range cases { |
| + for path, body := range pages { |
| + if path != "/fleet/activity" && c.merged == "" { |
| + continue // the person page holds only ann's newest twenty |
| + } |
| + shows := func(what string) bool { |
| + return strings.Contains(body, ">"+html.EscapeString(what)+"<") || strings.Contains(body, `title="`+html.EscapeString(what)+`"`) |
| + } |
| + if c.merged != "" { |
| + if !shows(c.merged) || shows(c.ship.detail) || shows(c.prom.detail) { |
| + t.Errorf("%s, %s: want one row %q in place of both", c.name, path, c.merged) |
| + } |
| + continue |
| + } |
| + if !shows(c.prom.detail) { |
| + t.Errorf("%s, %s: the promote %q does not show on its own", c.name, path, c.prom.detail) |
| + } |
| + if !shows(c.ship.detail) { |
| + t.Errorf("%s, %s: the ship %q does not show on its own", c.name, path, c.ship.detail) |
| + } |
| + if strings.Contains(body, "shipped and promoted "+strings.Fields(strings.TrimPrefix(c.prom.detail, "promoted "))[0]+" ") { |
| + t.Errorf("%s, %s: the two merged", c.name, path) |
| + } |
| + } |
| + } |
| + // The dashboard's Latest reads the same rule: ann's latest is the |
| + // last case's merged row. |
| + _, rows := dashActorRows(t, dashGet(t, fx, w.c)) |
| + if len(rows) == 0 || rows[0].Who != ann || rows[0].Latest != "shipped and promoted v3 to stable (cli, rootfs)" { |
| + t.Errorf("the dashboard's first row = %+v, want ann's merged rootfs deploy", rows) |
| + } |
| + |
| + // A merged row counts as two actions in a burst: a config change, then |
| + // the ship and promote, a minute apart each. |
| + at := base.Add(time.Duration(len(cases)) * 30 * time.Minute) |
| + groupRecord(t, fx, w.shop.ID, "shop", ann, "env-set", "Set FOO", at) |
| + groupRecord(t, fx, w.shop.ID, "shop", ann, "ship", "shipped v20 (cli)", at.Add(time.Minute)) |
| + groupRecord(t, fx, w.shop.ID, "shop", ann, "promote", "promoted v20 to canary/x (cli)", at.Add(2*time.Minute)) |
| + lines := feedLines(t, peopleGet(t, fx, w.c, "/fleet/activity")) |
| + want := "ann@example.com: 3 actions on shop [shipped and promoted v20 to canary/x (cli), Set FOO]" |
| + if got := lineSummary(lines); len(got) == 0 || got[0] != want { |
| + t.Errorf("Activity starts %q, want %q", got, want) |
| + } |
| + |
| + // The burst is judged on the stored rows' gaps, not the merged line's |
| + // time (Astra, whole-branch round 1, P2): a config change, a ship nine |
| + // minutes later and its promote nine minutes after that are one burst, |
| + // although the promote is 18 minutes after the config change. |
| + at = at.Add(30 * time.Minute) |
| + groupRecord(t, fx, w.shop.ID, "shop", ann, "env-set", "Set BAR", at) |
| + groupRecord(t, fx, w.shop.ID, "shop", ann, "ship", "shipped v21 (cli)", at.Add(9*time.Minute)) |
| + groupRecord(t, fx, w.shop.ID, "shop", ann, "promote", "promoted v21 to canary/x (cli)", at.Add(18*time.Minute)) |
| + lines = feedLines(t, peopleGet(t, fx, w.c, "/fleet/activity")) |
| + want = "ann@example.com: 3 actions on shop [shipped and promoted v21 to canary/x (cli), Set BAR]" |
| + if got := lineSummary(lines); len(got) == 0 || got[0] != want { |
| + t.Errorf("nine-minute gaps around a merge: Activity starts %q, want %q", got, want) |
| + } |
| +} |
| + |
| +// TestActivityMergeReadsOnlyTheStoredShapes: not acceptance, the parsers' |
| +// edges. |
| +func TestActivityMergeReadsOnlyTheStoredShapes(t *testing.T) { |
| + for _, c := range []struct { |
| + detail string |
| + ok bool |
| + }{ |
| + {"shipped v1 (cli)", true}, |
| + {"shipped v1 (cli, rootfs)", true}, |
| + {"shipped v1", false}, |
| + {"shipped (cli)", false}, |
| + {"shipped v1 (web)", false}, |
| + {"shipped v1 v2 (cli)", false}, |
| + {"Shipped v1 (cli)", false}, |
| + } { |
| + if _, _, ok := activityParseShip(FeedRow{Action: "ship", Detail: c.detail}); ok != c.ok { |
| + t.Errorf("ship %q: ok = %v, want %v", c.detail, ok, c.ok) |
| + } |
| + } |
| + if _, _, ok := activityParseShip(FeedRow{Action: "promote", Detail: "shipped v1 (cli)"}); ok { |
| + t.Error("a ship sentence on another action reads as a ship") |
| + } |
| + for _, c := range []struct { |
| + detail string |
| + ok bool |
| + }{ |
| + {"promoted v1 to canary/x (cli)", true}, |
| + {"promoted v1 to canary/x", false}, |
| + {"promoted v1 to canary/x (cli) again", false}, |
| + {"promoted v1 v2 to canary/x (cli)", false}, |
| + {"promoted to canary/x (cli)", false}, |
| + {"promoted v1 to production (proposed by a@example.com, 2 confirmations)", false}, |
| + {"Made v1 live", false}, |
| + } { |
| + if _, _, ok := activityParsePromote(FeedRow{Action: "promote", Detail: c.detail}); ok != c.ok { |
| + t.Errorf("promote %q: ok = %v, want %v", c.detail, ok, c.ok) |
| + } |
| + } |
| +} |
diff --git a/internal/console/opactivity_test.go b/internal/console/opactivity_test.go| index 83c13c1b3..381d29a1d 100644 |
| --- a/internal/console/opactivity_test.go |
| +++ b/internal/console/opactivity_test.go |
| @@ -104,12 +104,14 @@ func feedFilterLine(body string) string { |
| } |
| // feedSeedMore records n more rows on shop's app, each with its own detail, |
| -// a second apart after the world's. |
| +// written after the world's but timed eleven minutes apart from a day |
| +// before it, so that no two of them fold into one burst (foldBursts). |
| func feedSeedMore(t *testing.T, fx *consoleFixture, w operatorWorld, n int) { |
| t.Helper() |
| for i := 0; i < n; i++ { |
| + at := w.now.Add(-24*time.Hour + time.Duration(i)*(activityBurstGap+time.Minute)) |
| if err := fx.st.RecordActivity(w.shop.ID, "shop", "ann@example.com", |
| - Activity{Action: "env-set", Detail: fmt.Sprintf("Set variable %03d", i)}, w.now.Add(time.Duration(i)*time.Second)); err != nil { |
| + Activity{Action: "env-set", Detail: fmt.Sprintf("Set variable %03d", i)}, at); err != nil { |
| t.Fatal(err) |
| } |
| } |
diff --git a/internal/console/opdashboard.go b/internal/console/opdashboard.go| index 49703b9c4..f6151f6d2 100644 |
| --- a/internal/console/opdashboard.go |
| +++ b/internal/console/opdashboard.go |
| @@ -22,6 +22,17 @@ import ( |
| // boxes: three missed snapshot periods, the boxes' own staleness rule. |
| const dashSummaryOld = 3 * status.SnapshotPeriod |
| +// Latest activity is one row per person (dashActors) among the newest |
| +// dashActivityWindow audit rows, up to dashActivityPeople of them. A |
| +// window of rows rather than of time: one indexed read of a bounded size |
| +// however busy the platform is, and never empty while anything has |
| +// happened; at twenty times the people shown, one person's burst (a |
| +// deploy is about ten rows) cannot crowd out the rest. |
| +const ( |
| + dashActivityWindow = 200 |
| + dashActivityPeople = 10 |
| +) |
| + |
| // The words the dashboard computes (copy record OPS-21 to OPS-76). |
| const ( |
| dashAllClear = "Everything is running." |
| @@ -307,9 +318,10 @@ type dashView struct { |
| Stats []opStat |
| Bars []dashBar |
| Newest []PersonRow |
| - Activity []FeedRow |
| - Boxes []dashBox |
| - HasFleet bool |
| + // Actors is Latest activity: one row per person (dashActors). |
| + Actors []dashActor |
| + Boxes []dashBox |
| + HasFleet bool |
| // HostsUnread is OPS-154 when the box reports could not be listed, |
| // shown in place of the Boxes rows, or when some could not be read, |
| // shown above the rows that were; "" otherwise. |
| @@ -317,6 +329,9 @@ type dashView struct { |
| Jobs []opJobRow |
| } |
| +// ActorsHead is Latest activity's head row. |
| +func (d *dashView) ActorsHead() []string { return activityDashHead } |
| + |
| // Title is the callout's heading. |
| func (d *dashView) Title() string { |
| switch len(d.Attention) { |
| @@ -371,10 +386,10 @@ func (s *Server) handleDashboard(w http.ResponseWriter, r *http.Request) { |
| } else { |
| d.Newest = people |
| } |
| - if feed, err := s.store.ActivityFeed(ActivityFilter{}, 0, 10); err != nil { |
| + if feed, err := s.store.ActivityFeed(ActivityFilter{}, 0, dashActivityWindow); err != nil { |
| log.Printf("console: dashboard activity: %v", err) |
| } else { |
| - d.Activity = feed |
| + d.Actors = dashActors(feed, dashActivityPeople) |
| } |
| // The dashboard's three bucket reads are independent and run at once: |
diff --git a/internal/console/opdashboard_test.go b/internal/console/opdashboard_test.go| index 731617eba..5ade445f2 100644 |
| --- a/internal/console/opdashboard_test.go |
| +++ b/internal/console/opdashboard_test.go |
| @@ -587,13 +587,13 @@ func TestDashboardBoxStatuses(t *testing.T) { |
| } |
| } |
| -// TestDashboardLatestActivityAndNewestPeople: the newest ten activity rows, |
| -// newest first, and the newest five people with their first account. |
| +// TestDashboardLatestActivityAndNewestPeople: Latest activity is one row |
| +// per person, newest first, with their count, latest action and apps; and |
| +// the newest five people with their first account. |
| func TestDashboardLatestActivityAndNewestPeople(t *testing.T) { |
| fx := newConsoleFixture(t) |
| w := seedOperatorWorld(t, fx) |
| - // More rows than the dashboard shows: the newest ten are these six and |
| - // four of the seeded ones. |
| + // Six more of ann's: with the world's promote and invite, eight. |
| for i := 0; i < 6; i++ { |
| if err := fx.st.RecordActivity(w.shop.ID, "shop", "ann@example.com", Activity{Action: "rename", Detail: fmt.Sprintf("Change %d", i)}, time.Now()); err != nil { |
| t.Fatal(err) |
| @@ -601,40 +601,22 @@ func TestDashboardLatestActivityAndNewestPeople(t *testing.T) { |
| } |
| body := dashGet(t, fx, w.c) |
| - feed, err := fx.st.ActivityFeed(ActivityFilter{}, 0, 10) |
| - if err != nil { |
| - t.Fatal(err) |
| - } |
| - rows := dashRows(dashSection(t, body, "Latest activity")) |
| - if len(rows) != len(feed)+1 || len(feed) != 10 { |
| - t.Fatalf("%d activity rows for a feed of %d (want 10):\n%s", len(rows)-1, len(feed), dashSection(t, body, "Latest activity")) |
| + head, rows := dashActorRows(t, body) |
| + if want := "<span>Last active</span><span>Who</span><span>Actions</span><span>Latest</span><span>Apps</span>"; !strings.Contains(head, want) { |
| + t.Errorf("activity head: %s", head) |
| } |
| - if !strings.Contains(rows[0], "<span>When</span><span>Who</span><span>What</span><span>App</span>") { |
| - t.Errorf("activity head: %s", rows[0]) |
| - } |
| - for i, f := range feed { |
| - r := rows[i+1] |
| - if !strings.Contains(r, `<a href="/fleet/people/`+f.Address+`">`+f.Address+"</a>") || !strings.Contains(r, "<span co-clip>"+f.Detail+"</span>") { |
| - t.Errorf("activity row %d is not feed row %d (%s %s): %s", i+1, f.ID, f.Address, f.Detail, r) |
| - } |
| - } |
| - if !strings.Contains(rows[1], "Change 5") { |
| - t.Errorf("the newest row is not the last written: %s", rows[1]) |
| - } |
| - var signin, promotes string |
| - for _, r := range rows[1:] { |
| - if strings.Contains(r, "<span co-clip>Signed in</span>") { |
| - signin = r |
| - } |
| - if strings.Contains(r, " live</span>") { |
| - promotes += r |
| - } |
| + none := `<span class="rst-cell-mut">none</span>` |
| + actors := []dashActorCells{ |
| + {Who: "ann@example.com", Actions: groupActions(t, fx, "ann@example.com"), Latest: "Change 5", Apps: "<span>shop</span>"}, |
| + {Who: "cat@example.com", Actions: "1 action", Latest: "Signed in", Apps: none}, |
| + {Who: "ben@example.com", Actions: groupActions(t, fx, "ben@example.com"), Latest: "Made v1 live", Apps: "<span>notes</span>"}, |
| + {Who: "paul@keymail.dev", Actions: "1 action", Latest: "Signed in for the first time", Apps: none}, |
| } |
| - if !strings.Contains(signin, "cat@example.com") || !strings.Contains(signin, `<span class="rst-cell-mut">none</span>`) { |
| - t.Errorf("the sign-in row has no none for its app: %q", signin) |
| + if actors[0].Actions != "9 actions" { |
| + t.Errorf("ann has %s, want these six and the world's three", actors[0].Actions) |
| } |
| - if !strings.Contains(promotes, "<span>notes</span>") || !strings.Contains(promotes, "<span>shop</span>") { |
| - t.Errorf("the promote rows do not name their apps: %s", promotes) |
| + if !slices.Equal(rows, actors) { |
| + t.Errorf("Latest activity =\n%+v\nwant\n%+v", rows, actors) |
| } |
| people := dashRows(dashSection(t, body, "Newest people")) |
diff --git a/internal/console/opperson.go b/internal/console/opperson.go| index e0fd45ce6..882d6777f 100644 |
| --- a/internal/console/opperson.go |
| +++ b/internal/console/opperson.go |
| @@ -78,7 +78,7 @@ func opAgo(t time.Time) string { return humanAge(time.Since(t)) + " ago" } |
| type personView struct { |
| Person *PersonDetail |
| Stats []opStat |
| - Feed []FeedRow |
| + Feed []activityRow |
| ActivityRef string |
| } |
| @@ -128,7 +128,7 @@ func (s *Server) handlePerson(w http.ResponseWriter, r *http.Request) { |
| p.Person = &personView{ |
| Person: person, |
| Stats: personStats(person), |
| - Feed: feed, |
| + Feed: mergeShipPromote(feed), |
| ActivityRef: feedQuery{Who: person.Address}.href(), |
| } |
| s.render(w, http.StatusOK, "ops_person", p) |
diff --git a/internal/console/opshots_test.go b/internal/console/opshots_test.go| index d414a296e..8340ccbae 100644 |
| --- a/internal/console/opshots_test.go |
| +++ b/internal/console/opshots_test.go |
| @@ -88,6 +88,18 @@ func TestOperatorScreenshots(t *testing.T) { |
| fx := newConsoleFixture(t) |
| w := seedOperatorWorld(t, fx) |
| seedOperatorShotExtras(t, fx) |
| + // A deploy burst of ann's on shop, so Activity shows a fold and the |
| + // dashboard her merged ship and promote. |
| + for i, r := range []Activity{ |
| + {Action: "env-set", Detail: "Set API_URL"}, |
| + {Action: "env-set", Detail: "Set FEATURE_FLAGS"}, |
| + {Action: "ship", Detail: "shipped v42 (cli)"}, |
| + {Action: "promote", Detail: "promoted v42 to canary/eu (cli)"}, |
| + } { |
| + if err := fx.st.RecordActivity(w.shop.ID, "shop", "ann@example.com", r, w.now.Add(time.Duration(i)*time.Minute)); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| target, err := url.Parse(fx.ts.URL) |
| if err != nil { |
| t.Fatal(err) |
diff --git a/internal/console/static/ops.css b/internal/console/static/ops.css| index ffab9a27c..6ba6babb4 100644 |
| --- a/internal/console/static/ops.css |
| +++ b/internal/console/static/ops.css |
| @@ -23,7 +23,7 @@ |
| /* List grids: Rastrillo's [rst-lrow] lays each row out from --rst-cols, |
| which a list card names once. One template per operator list. */ |
| [co-cols="people"] { --rst-cols: minmax(12rem, 2fr) minmax(8rem, 1fr) 7rem 7rem; } |
| -[co-cols="activity"] { --rst-cols: 6rem minmax(10rem, 1.2fr) minmax(12rem, 2fr) minmax(7rem, 1fr); } |
| +[co-cols="activity"] { --rst-cols: 6rem minmax(10rem, 1.2fr) 6rem minmax(12rem, 2fr) minmax(7rem, 1fr); } |
| [co-cols="boxes"] { --rst-cols: minmax(8rem, 1fr) 7rem 6rem minmax(9rem, 1.4fr) 8rem; } |
| [co-cols="jobs"] { --rst-cols: minmax(10rem, 1.5fr) 9rem 8rem 7rem 6rem minmax(10rem, 2fr); } |
| [co-cols="persons"] { --rst-cols: minmax(12rem, 2fr) 7rem 7rem 6rem; } |
| @@ -37,17 +37,21 @@ |
| kebab, so each keeps two cells on two columns and hides the others, |
| head row included: one row per line, never a cell wrapped below. The |
| activity lists lead with When at the desktop's fixed width, so "0m ago" |
| - and "21h47m ago" rows keep What in one column. */ |
| + and "21h47m ago" rows keep What in one column. The dashboard's latest |
| + activity is one row per person, so it keeps Who beside Last active. |
| + Activity's folded bursts (co-fold) lay out like its rows. */ |
| @media (max-width: 800px) { |
| [co-cols] > [rst-lrow] { grid-template-columns: minmax(0, 1fr) auto; } |
| [co-cols="activity"] > [rst-lrow], |
| [co-cols="feed"] > [rst-lrow], |
| + [co-cols="feed"] > [co-fold] > [rst-lrow], |
| [co-cols="personfeed"] > [rst-lrow] { grid-template-columns: 6rem minmax(0, 1fr); } |
| [co-cols="people"] > [rst-lrow] > :is(:nth-child(2), :nth-child(4)), |
| [co-cols="persons"] > [rst-lrow] > :is(:nth-child(2), :nth-child(4)), |
| [co-cols="accounts"] > [rst-lrow] > :is(:nth-child(2), :nth-child(n+4)), |
| - [co-cols="activity"] > [rst-lrow] > :is(:nth-child(2), :nth-child(4)), |
| + [co-cols="activity"] > [rst-lrow] > :nth-child(n+3), |
| [co-cols="feed"] > [rst-lrow] > :is(:nth-child(2), :nth-child(3), :nth-child(5)), |
| + [co-cols="feed"] > [co-fold] > [rst-lrow] > :is(:nth-child(2), :nth-child(3), :nth-child(5)), |
| [co-cols="personfeed"] > [rst-lrow] > :is(:nth-child(2), :nth-child(4)), |
| [co-cols="personaccts"] > [rst-lrow] > :nth-child(n+3), |
| [co-cols="boxes"] > [rst-lrow] > :nth-child(n+3), |
| @@ -84,6 +88,18 @@ |
| browser's default blue. */ |
| [co-cols="feed"] a, [co-cols="activity"] a, [co-cols="personfeed"] a { color: var(--rst-accent); } |
| +/* A burst on Activity (co-fold): one row, the details' summary, that |
| + opens onto the burst's rows, tinted so they read as its own. The rows |
| + keep the list's lines between them, and the card's last line has none |
| + whether the burst is open or not. */ |
| +[co-fold] > summary { cursor: pointer; list-style: none; } |
| +[co-fold] > summary::-webkit-details-marker { display: none; } |
| +[co-fold] > summary [rst-caret] { display: inline-flex; margin-inline-start: 0.3rem; vertical-align: middle; } |
| +[co-fold][open] > summary [rst-caret] { transform: rotate(180deg); } |
| +[co-fold] > div[rst-lrow] { background: var(--rst-surface-2); } |
| +[co-fold]:not(:last-child) > [rst-lrow]:last-child { border-bottom: 1px solid var(--rst-line); } |
| +[co-fold]:last-child:not([open]) > summary { border-bottom: 0; } |
| + |
| /* An audit row's What (op_what): one line, cut with an ellipsis, its |
| whole text in the cell's title. A row that stored data opens onto it, |
| indented, wrapped and scrolling within the cell rather than widening the |
diff --git a/internal/console/templates/ops_activity.html b/internal/console/templates/ops_activity.html| index 9b1d704ba..904d1b589 100644 |
| --- a/internal/console/templates/ops_activity.html |
| +++ b/internal/console/templates/ops_activity.html |
| @@ -1,8 +1,10 @@ |
| {{/* Activity (/fleet/activity, opactivity.go): one card of audit rows, |
| newest first, under a toolbar holding the kind filter and, when an |
| account or a person filter is on, the line naming each with its clear |
| - link; Newest and Older below. Everything computed in Go arrives in |
| - .Feed. */}} |
| + link; Newest and Older below. A burst by one person on one app is one |
| + line that opens onto its rows (a details, no script), and a ship |
| + merged with its promote is one row (opactivity_group.go). Everything |
| + computed in Go arrives in .Feed. */}} |
| {{define "ops_activity"}}{{template "op_top" .}} |
| {{template "op_page_header" (opHeader .Title "All activity across every account, newest first.")}} |
| {{with .Feed}} |
| @@ -16,11 +18,19 @@ |
| <p co-filter>Showing only {{if .WhoHref}}<a href="{{.WhoHref}}">{{.Who}}</a>{{else}}{{.Who}}{{end}}. <a href="{{.Query.ClearWhoHref}}">Show all people</a></p> |
| {{- end}} |
| </div> |
| - {{- if .Rows}} |
| + {{- if .Entries}} |
| <div rst-lrow="head"><span>When</span><span>Who</span><span>Account</span><span>What</span><span>App</span></div> |
| + {{- range .Entries}} |
| + {{- if .Folded}} |
| + <details co-fold><summary rst-lrow><span class="rst-cell-mut" title="{{fmtTime .At}}">{{ago .At}}</span>{{template "op_who" .Address}}{{if .AccountSqid}}<a href="{{$.Feed.Query.AccountHref .AccountSqid}}">{{.AccountName}}</a>{{else}}<span class="rst-cell-mut">none</span>{{end}}<span co-clip>{{.FoldText}}<span rst-caret aria-hidden="true">{{icon "chevron-down"}}</span></span>{{if .App}}<span>{{.App}}</span>{{else}}<span class="rst-cell-mut">none</span>{{end}}</summary> |
| {{- range .Rows}} |
| <div rst-lrow><span class="rst-cell-mut" title="{{fmtTime .At}}">{{ago .At}}</span>{{template "op_who" .Address}}{{if .AccountSqid}}<a href="{{$.Feed.Query.AccountHref .AccountSqid}}">{{.AccountName}}</a>{{else}}<span class="rst-cell-mut">none</span>{{end}}{{template "op_what" .}}{{if .App}}<span>{{.App}}</span>{{else}}<span class="rst-cell-mut">none</span>{{end}}</div> |
| {{- end}} |
| + </details> |
| + {{- else}} |
| + <div rst-lrow><span class="rst-cell-mut" title="{{fmtTime .At}}">{{ago .At}}</span>{{template "op_who" .Address}}{{if .AccountSqid}}<a href="{{$.Feed.Query.AccountHref .AccountSqid}}">{{.AccountName}}</a>{{else}}<span class="rst-cell-mut">none</span>{{end}}{{template "op_what" .}}{{if .App}}<span>{{.App}}</span>{{else}}<span class="rst-cell-mut">none</span>{{end}}</div> |
| + {{- end}} |
| + {{- end}} |
| {{- else}} |
| {{template "op_empty" (opEmpty "" "No activity matches these filters.")}} |
| {{- end}} |
diff --git a/internal/console/templates/ops_dashboard.html b/internal/console/templates/ops_dashboard.html| index e3ab99cf3..5652573a6 100644 |
| --- a/internal/console/templates/ops_dashboard.html |
| +++ b/internal/console/templates/ops_dashboard.html |
| @@ -1,6 +1,7 @@ |
| {{/* The dashboard (/fleet, opdashboard.go): the approved mockup top to |
| bottom. The callout, the headline band, the new-people chart, newest |
| - people, latest activity, boxes and background jobs. Every number and |
| + people, latest activity (one row per person), boxes and background |
| + jobs. Every number and |
| word computed in Go arrives in .Dash. */}} |
| {{define "ops_dashboard"}}{{template "op_top" .}} |
| {{template "op_page_header" (opHeader .Title (printf "Who uses %s, what they do, and whether everything is running." .Brand))}} |
| @@ -53,11 +54,11 @@ |
| {{else}}{{template "op_empty" (opEmpty "" "No one has signed up yet.")}}{{end}} |
| <div rst-box-head><h2>Latest activity</h2><a rst-btn="ghost" href="/fleet/activity">All activity</a></div> |
| -{{if .Activity}} |
| +{{if .Actors}} |
| <div rst-card co-cols="activity"> |
| - <div rst-lrow="head"><span>When</span><span>Who</span><span>What</span><span>App</span></div> |
| - {{- range .Activity}} |
| - <div rst-lrow><span class="rst-cell-mut" title="{{fmtTime .At}}">{{ago .At}}</span>{{template "op_who" .Address}}{{template "op_what" .}}{{if .App}}<span>{{.App}}</span>{{else}}<span class="rst-cell-mut">none</span>{{end}}</div> |
| + <div rst-lrow="head">{{range .ActorsHead}}<span>{{.}}</span>{{end}}</div> |
| + {{- range .Actors}} |
| + <div rst-lrow><span class="rst-cell-mut" title="{{fmtTime .At}}">{{ago .At}}</span>{{template "op_who" .Address}}<span>{{.ActionsText}}</span>{{template "op_what" .Latest}}{{if .Apps}}<span>{{.Apps}}</span>{{else}}<span class="rst-cell-mut">none</span>{{end}}</div> |
| {{- end}} |
| </div> |
| {{else}}{{template "op_empty" (opEmpty "" "Nothing has happened yet.")}}{{end}} |