diff --git a/changelog.d/added-16064-hub-activity-display-mode.md b/changelog.d/added-16064-hub-activity-display-mode.md new file mode 100644 index 0000000000..334aacd6a8 --- /dev/null +++ b/changelog.d/added-16064-hub-activity-display-mode.md @@ -0,0 +1 @@ +- The hub **Fleet activity** page (`/activity`) takes the spoke Activity Monitor's display parameters, read by the spoke's own code: `?kiosk=1` hides the chrome and cursor for an unattended screen, `?display=1` gives an attended chrome-less wall view that **Esc** or **d** leaves, `am.*` describes the board's view with the spoke's keys (kind, repo, q, author, sort, dir and `am.group=none`), and in display mode `am.view` + `interval` rotate `hub-activity` views with the spoke's wall-clock dwell. `am.*` keys the activity digest has no data for stay in the URL and are named on the board as not applied. A copy of the spoke's URL-view and playlist helpers is served byte-identical from `/activity/assets/` (`pkg/webassets/trackerview`), and a compatibility test fails if it drifts. The spoke tracker's display mode is unchanged ([#16064](https://github.com/hivecommons/hive/issues/16064), part of [#15965](https://github.com/hivecommons/hive/issues/15965), RFC [#15861](https://github.com/hivecommons/hive/issues/15861)). diff --git a/src/docs/api-reference/hub-server.md b/src/docs/api-reference/hub-server.md index c089c4fc07..00f8fd4bb2 100644 --- a/src/docs/api-reference/hub-server.md +++ b/src/docs/api-reference/hub-server.md @@ -36,7 +36,7 @@ Part of the [Dashboard REST API reference](../api-reference.md); see that page f | `GET` | `/fleet` | Hub handler-specific | My-Hives Fleet Page (static; data via `/api/saas/my-hives`) | `pkg/hub/server.go:1773` | | `GET` | `/my-hives` | Hub handler-specific | 301 redirect to `/fleet` (query preserved) | `pkg/hub/server.go:1774` | | `GET` | `/activity` | Signed-in user | Fleet activity page ([#16063](https://github.com/hivecommons/hive/issues/16063)): read-only, data-free shell that polls `/api/hub/activity` every 15 s with `If-None-Match`. No session → `307` to `/login`; blocked user → `403`. Own Content-Security-Policy (scripts and styles from `'self'` only, `script-src-attr`/`style-src-attr` `'none'`), `Cache-Control: no-cache` + content `ETag`. See [Hub Fleet activity page](../hub-fleet-activity.md) | `pkg/hub/activity_page.go` | -| `GET` | `/activity/assets/{name}` | Public | The shared tracker row asset (`pkg/webassets/trackerrow`, [#16062](https://github.com/hivecommons/hive/issues/16062)) the Fleet activity page draws rows with, byte-identical; only names in `trackerrow.Files`, else `404`. `Cache-Control: no-cache` + content `ETag` | `pkg/hub/activity_page.go` | +| `GET` | `/activity/assets/{name}` | Public | The shared tracker assets the Fleet activity page loads, byte-identical: the row asset (`pkg/webassets/trackerrow`, [#16062](https://github.com/hivecommons/hive/issues/16062)) and the `am.*` URL-view and display-playlist helpers (`pkg/webassets/trackerview`, [#16064](https://github.com/hivecommons/hive/issues/16064)); only names in `trackerrow.Files` or `trackerview.Files`, else `404`. `Cache-Control: no-cache` + content `ETag` | `pkg/hub/activity_page.go` | | `POST` | `/api/shared-agent-pool/leases` | Hub handler-specific | Acquire or renew a shared CLI session lease | `pkg/hub/server.go:1708` | | `PUT` | `/api/shared-agent-pool/leases` | Hub handler-specific | Renew an active shared CLI session lease | `pkg/hub/server.go:1709` | | `DELETE` | `/api/shared-agent-pool/leases` | Hub handler-specific | Release a shared CLI session lease | `pkg/hub/server.go:1710` | diff --git a/src/docs/dashboard-source-layout.md b/src/docs/dashboard-source-layout.md index 0546e8186a..c54ab8dec2 100644 --- a/src/docs/dashboard-source-layout.md +++ b/src/docs/dashboard-source-layout.md @@ -112,6 +112,19 @@ code without importing `pkg/dashboard`. The generator only reads `TestTrackerRowSharedAssetRendersSpokeFixtures` renders the same fixtures through both. Edit both copies in the same PR. +The same rule applies to the Activity Monitor URL-view and display-playlist +helpers: `stageTrackerDefaultFilter` (`js/tracker-words-stage.js`), +`stageTrackerNormalizeFilter` (`js/tracker-filter.js`) and the +`tracker url view helpers` and `tracker display playlist helpers` blocks of +`js/tracker-filter-state.js`. `src/pkg/webassets/trackerview/tracker-view.js` +carries a verbatim copy so the hub Fleet activity page reads `am.*`, `am.view` +and `interval` as a spoke display does +([#16064](https://github.com/hivecommons/hive/issues/16064)). +`TestTrackerViewSharedAssetCompat` (in `pkg/dashboard`) compares that copy +with the declarations in the committed `static/index.html` and fails when they +drift: after editing one of these spoke helpers, run `make dashboard-gen` and +re-copy them into `tracker-view.js` in the same PR. + ## Working with it ```sh diff --git a/src/docs/documentation-map.md b/src/docs/documentation-map.md index b2a27e120e..891e87c3cc 100644 --- a/src/docs/documentation-map.md +++ b/src/docs/documentation-map.md @@ -17,7 +17,7 @@ Documentation for the current Hive line (branch `v5`; the code and docs live und ### First installation - [Hosted Hive Hub onboarding](hosted-hub.md) — signing in at `https://hive.hivecommons.dev`, requesting a hosted hive, installing the GitHub App, configuring model gateways and Copilot login, reading `/fleet`, and fixing common setup problems. -- [Hub Fleet activity page](hub-fleet-activity.md) — the read-only `/activity` board of open issues and PRs across the hives you can see: per-viewer scoping, hive chips, group-by-hive freshness headers, always-visible truncation and stale-source disclosures, and 15-second ETag polling. +- [Hub Fleet activity page](hub-fleet-activity.md) — the read-only `/activity` board of open issues and PRs across the hives you can see: per-viewer scoping, hive chips, group-by-hive freshness headers, always-visible truncation and stale-source disclosures, 15-second ETag polling, and display mode (`?kiosk=1`, `?display=1`, `am.*` views and `hub-activity` playlists). - [Docker Compose quick start](quickstart-docker-compose.md) — default standalone installation, prerequisites, and verification. - [Podman quick start](quickstart-podman.md) — standalone Quadlet/systemd installation, with rootless/rootful prerequisites. - [Kubernetes deployment](kubernetes-deployment.md) — standalone cluster installation, storage, authentication, and dashboard access. Related: [health checks](health-checks.md). diff --git a/src/docs/hub-fleet-activity.md b/src/docs/hub-fleet-activity.md index 4132d198cf..ea8724cce1 100644 --- a/src/docs/hub-fleet-activity.md +++ b/src/docs/hub-fleet-activity.md @@ -12,7 +12,8 @@ signed in; a browser without a hub session is sent to `/login`. The design is RFC [#15861](https://github.com/hivecommons/hive/issues/15861) by @hanthor, delivered in [#15965](https://github.com/hivecommons/hive/issues/15965) -and its children. The page itself is [#16063](https://github.com/hivecommons/hive/issues/16063). +and its children. The page itself is [#16063](https://github.com/hivecommons/hive/issues/16063); +its display mode is [#16064](https://github.com/hivecommons/hive/issues/16064). ## Who sees what @@ -40,7 +41,10 @@ Each row is one open issue or PR: | **Stage** | The strip column the spoke tracker would light (Open, Actionable, Claimed, PR in progress, CI / Review, Merge gate, Merged) and the stage slug. | | **Author** | `human`, `clanker` or `hive` when the spoke knows it. | -Rows come in the endpoint's order: most urgent first, then furthest stage. +Rows are ordered like the spoke tracker's default sort: furthest strip column +first; within a column, rows with a modifier or parked on a person first and +held or draft rows last; then longest in stage. `am.sort` and `am.dir` change +the order (see [Display mode and URL views](#display-mode-and-url-views)). **Group by hive** is on by default. It draws one header row per hive, even when the hive has no open items. The header shows: @@ -77,13 +81,59 @@ hidden and resumes, with an immediate refresh, when you come back. The status line shows when the data last changed and when it was last checked. If your session expires, the page sends you to `/login`. +## Display mode and URL views + +The page takes the same display parameters as the spoke Activity Monitor +(see [Display mode and URL views](streaming-the-activity-monitor.md#display-mode-and-url-views)). +They are the spoke's own parameters, read by the spoke's own code: the hub +serves a byte-identical copy of the spoke's URL-view and playlist helpers +(`src/pkg/webassets/trackerview`). There are no hub-only display parameters. + +| Parameter | On `/activity` | +|---|---| +| `kiosk=1` | Unattended screen: hides the hub header, the description and the **Group by hive** toggle, and hides the cursor. The status line and the coverage list stay. A kiosk never rotates a playlist. | +| `display=1` | Attended wall screen: the same chrome-less board, with the cursor. **Esc** (unless the browser is in full screen) or **d** leaves display mode and keeps the rest of the URL. `kiosk=1` wins when both are set. | +| `am.*` | The board's view, with the spoke's keys and values. See the table below. | +| `am.view`, `interval` | A playlist, in display mode only. Each `am.view` is a URL-encoded `am.*` query string, and every entry is a `hub-activity` view: this board under that entry's `am.*` state. `interval` is `Ns` or `Nm`, clamped to 10 s – 1 h, default 60 s. With fewer than two valid entries the board does not rotate. | + +How each `am.*` key applies here: + +| Key | Effect on the hub board | +|---|---| +| `am.kind` | `pr` or `issue` only. | +| `am.repo` | One `owner/repo`, exact match. | +| `am.q` | Title text, or the item number (`123` or `#123`). | +| `am.author` | `human`, `clanker` or `hive`. | +| `am.sort`, `am.dir` | `furthest` (default), `waiting` (longest in stage) or `number`; `asc` / `desc`. `newest` needs an opening time the digest does not carry, so it sorts as `furthest`. | +| `am.group` | `none` turns grouping off. Grouping by hive is the default and is never written into the URL. A spoke value the hub board has no grouping for (`repo`) falls back to the default, as an unknown value does on the spoke. | +| `am.labels`, `am.needsHuman`, `am.onHold`, `am.attention`, `am.age`, `am.acted` | Not applied: the activity digest carries no labels or verdicts for them. They stay in the URL, so the link still works on a spoke, and the coverage list names them under *Not applied on the hub*. | + +A link copied from a spoke display therefore opens on the hub with the same +view where the hub has the data for it, and says which parts it could not +apply. Turning **Group by hive** on or off rewrites `am.group` in the address +bar, so the address is always a link to the current view; credentials in the +URL never survive that rewrite. + +The playlist follows the spoke's rules: + +- The current view follows the wall clock, so a reload resumes on the same + view. Rotation happens in memory: it does not navigate, refetch or change + the URL. +- A thin bar at the top shows the time until the next view. With reduced + motion it is a static *N/M · next in Ns* label instead. + +```text +/activity?display=1&am.view=am.kind%3Dpr&am.view=am.group%3Dnone%26am.repo%3Dhivecommons%2Fhive&interval=2m +``` + +The spoke-only wall options `density=tv` and `shift=1` are ignored here. + ## What the page does not do - It has no action menus. The hub is visibility-only: act on an item on GitHub, or from the hive's own tracker. -- Display mode (`?kiosk=1`, `am.*` URL state, `?display=1` and a - `hub-activity` playlist view) is not part of this page yet; it is tracked in - [#16064](https://github.com/hivecommons/hive/issues/16064). +- It is not a broadcast source. Display mode only changes how the signed-in + page looks; the page still needs a hub session and shows only your hives. ## Security @@ -93,7 +143,7 @@ session expires, the page sends you to `/login`. from other origins. - Titles and every other value from a spoke are written as text, never parsed as HTML. -- The page, its script and the shared row-presentation asset are revalidated +- The page, its script and the shared row-presentation and view assets are revalidated on every load (`Cache-Control: no-cache` with a content ETag), so a hub upgrade is picked up on the next visit. - `/activity` is marked `noindex` and is disallowed in `robots.txt`. diff --git a/src/pkg/dashboard/tracker_view_shared_asset_test.go b/src/pkg/dashboard/tracker_view_shared_asset_test.go new file mode 100644 index 0000000000..401fe9440e --- /dev/null +++ b/src/pkg/dashboard/tracker_view_shared_asset_test.go @@ -0,0 +1,78 @@ +package dashboard + +import ( + "io/fs" + "regexp" + "strings" + "testing" + + "github.com/hivecommons/hive/pkg/webassets/trackerview" +) + +// TestTrackerViewSharedAssetCompat pins the hub's copy of the Activity +// Monitor URL-view and display-playlist helpers (hivecommons/hive#16064) to +// the spoke: past its header comment, pkg/webassets/trackerview/tracker-view.js +// must be exactly these spoke declarations, in this order, as the committed +// static/index.html serves them. The spoke side is only read, never changed: +// a drift fails here and is fixed by re-copying from the spoke. +func TestTrackerViewSharedAssetCompat(t *testing.T) { + html := indexHTML(t) + want := spokeFuncSource(t, html, "stageTrackerDefaultFilter") + + spokeFuncSource(t, html, "stageTrackerNormalizeFilter") + + spokeMarkedBlock(t, html, "tracker url view helpers begin", "tracker url view helpers end") + + spokeMarkedBlock(t, html, "tracker display playlist helpers begin", "tracker display playlist helpers end") + + b, err := fs.ReadFile(trackerview.FS, "tracker-view.js") + if err != nil { + t.Fatal(err) + } + got := sharedAssetBody(string(b)) + if got != want { + t.Errorf("pkg/webassets/trackerview/tracker-view.js differs from the spoke's declarations; re-copy them verbatim from static/index.html\n--- got ---\n%s\n--- want ---\n%s", got, want) + } +} + +// sharedAssetBody drops the leading block of column-0 `//` header lines. +func sharedAssetBody(src string) string { + lines := strings.SplitAfter(src, "\n") + i := 0 + for i < len(lines) && strings.HasPrefix(lines[i], "//") { + i++ + } + return strings.Join(lines[i:], "") +} + +// spokeFuncSource is one function declaration from the spoke page, from the +// start of its line (indentation included) to its closing brace and newline. +func spokeFuncSource(t *testing.T, html, name string) string { + t.Helper() + start := strings.Index(html, "function "+name+"(") + if start < 0 { + t.Fatalf("spoke page does not define %s", name) + } + lineStart := strings.LastIndex(html[:start], "\n") + 1 + depth := 0 + for i := start + strings.Index(html[start:], "{"); i < len(html); i++ { + switch html[i] { + case '{': + depth++ + case '}': + depth-- + if depth == 0 { + return html[lineStart:i+1] + "\n" + } + } + } + t.Fatalf("unbalanced braces in %s", name) + return "" +} + +// spokeMarkedBlock is a `// begin` … `// end` block, both marker lines included. +func spokeMarkedBlock(t *testing.T, html, begin, end string) string { + t.Helper() + m := regexp.MustCompile(`( *// ` + regexp.QuoteMeta(begin) + `\n[\s\S]*?// ` + regexp.QuoteMeta(end) + `\n)`).FindStringSubmatch(html) + if m == nil { + t.Fatalf("spoke page has no %q … %q block", begin, end) + } + return m[1] +} diff --git a/src/pkg/hub/activity_display_ui_test.go b/src/pkg/hub/activity_display_ui_test.go new file mode 100644 index 0000000000..92c87d9e89 --- /dev/null +++ b/src/pkg/hub/activity_display_ui_test.go @@ -0,0 +1,399 @@ +package hub + +import ( + "encoding/json" + "io/fs" + "net/http" + "net/http/httptest" + "os" + "path/filepath" + "regexp" + "strings" + "testing" + + "github.com/hivecommons/hive/pkg/dashboard/webstatic" + "github.com/hivecommons/hive/pkg/webassets/trackerrow" + "github.com/hivecommons/hive/pkg/webassets/trackerview" +) + +// Display mode on the hub Fleet activity page (#16064, part of #15965 / RFC +// #15861 by @hanthor). The page reuses #15860 Part A unchanged: `?kiosk=1`, +// `am.*` URL state and `?display=1` with `am.view` + `interval` playlists, +// read by the spoke's own helpers (pkg/webassets/trackerview). These tests +// run the SHIPPED page script under node with the shared assets loaded first, +// exactly as activity.html loads them. + +// activityDisplayHarness is every script activity.html loads, in its order. +func activityDisplayHarness(t *testing.T) string { + t.Helper() + var parts []string + for _, set := range []struct { + fsys fs.FS + files []string + }{{trackerrow.FS, trackerrow.Files}, {trackerview.FS, trackerview.Files}} { + for _, name := range set.files { + b, err := fs.ReadFile(set.fsys, name) + if err != nil { + t.Fatal(err) + } + parts = append(parts, string(b)) + } + } + return strings.Join(append(parts, readActivityScript(t)), "\n") +} + +func TestActivityDisplay_PageLoadsTheSharedViewAssetBeforeThePageScript(t *testing.T) { + page, err := fs.ReadFile(staticFS, "static/activity.html") + if err != nil { + t.Fatal(err) + } + html := string(page) + view := strings.Index(html, ``) + pageJS := strings.Index(html, ``) + if view < 0 || pageJS < 0 || view > pageJS { + t.Fatalf("activity.html must load %stracker-view.js before /static/activity.js (view at %d, page at %d)", activityAssetPrefix, view, pageJS) + } + if !strings.Contains(html, `id="activity-playlist"`) { + t.Errorf("activity.html has no #activity-playlist element for the display playlist bar") + } + + t.Setenv("HUB_DATA_DIR", t.TempDir()) + srv := newHubServerForTest(t, withHubIdentity("test", "v5")) + want, err := fs.ReadFile(trackerview.FS, "tracker-view.js") + if err != nil { + t.Fatal(err) + } + rec := httptest.NewRecorder() + srv.mux.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, activityAssetPrefix+"tracker-view.js", nil)) + if rec.Code != http.StatusOK || rec.Body.String() != string(want) { + t.Fatalf("GET %stracker-view.js = %d; want 200 and the bytes of pkg/webassets/trackerview", activityAssetPrefix, rec.Code) + } + if rec.Header().Get("Cache-Control") != "no-cache" || rec.Header().Get("ETag") != webstatic.ETagFor(want) { + t.Errorf("tracker-view.js cache headers = %q / %q, want the static no-cache + content ETag", rec.Header().Get("Cache-Control"), rec.Header().Get("ETag")) + } + for _, bad := range []string{"trackerview.go", "trackerview_test.go"} { + rec := httptest.NewRecorder() + srv.mux.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, activityAssetPrefix+bad, nil)) + if rec.Code != http.StatusNotFound { + t.Errorf("GET %s%s = %d, want 404", activityAssetPrefix, bad, rec.Code) + } + } +} + +// ?kiosk=1 and ?display=1 resolve exactly as the spoke's boot.js does: kiosk +// wins when both are present, and only the value "1" turns either on. +func TestActivityDisplay_KioskAndDisplayFlags(t *testing.T) { + src := activityDisplayHarness(t) + "\n" + `result = [ + activityDisplayFlags('https://hub.example/activity'), + activityDisplayFlags('https://hub.example/activity?kiosk=1'), + activityDisplayFlags('https://hub.example/activity?display=1'), + activityDisplayFlags('https://hub.example/activity?kiosk=1&display=1'), + activityDisplayFlags('https://hub.example/activity?kiosk=true&display=yes'), + activityDisplayFlags('not a url'), +];` + var got []struct{ Kiosk, Display bool } + runEvidenceJS(t, src, &got) + want := []struct{ Kiosk, Display bool }{{false, false}, {true, false}, {false, true}, {true, false}, {false, false}, {false, false}} + if len(got) != len(want) { + t.Fatalf("flags = %+v", got) + } + for i := range want { + if got[i] != want[i] { + t.Errorf("case %d flags = %+v, want %+v", i, got[i], want[i]) + } + } + + css, err := fs.ReadFile(staticFS, "static/activity.css") + if err != nil { + t.Fatal(err) + } + for _, rule := range []string{ + "body.kiosk-mode .activity-header", "body.display-mode .activity-header", + "body.kiosk-mode .activity-toggle", "body.display-mode .activity-toggle", + "body.kiosk-mode { cursor: none; }", "body.kiosk-mode .activity-playlist", + } { + if !strings.Contains(string(css), rule) { + t.Errorf("activity.css has no %q rule; kiosk/display must hide the chrome like the spoke", rule) + } + } +} + +// am.* state round-trips with the spoke's keys: a URL copied from a spoke +// display applies on the hub where the state applies (kind, repo, q, author, +// sort, dir, group), keeps the keys that do not apply, and says so. +func TestActivityDisplay_AmStateRoundTripsAndFiltersTheBoard(t *testing.T) { + view := map[string]any{ + "hives": []map[string]any{{"hive_id": "hive-a", "status": "ok"}, {"hive_id": "hive-b", "status": "ok"}}, + "items": []map[string]any{ + {"hive_id": "hive-a", "repo": "o/a", "n": 7, "kind": "pr", "title": "Fix the parser", "author_kind": "hive", "stage": "ci_review", "stage_n": 50, "since": "2026-10-31T08:00:00Z"}, + {"hive_id": "hive-b", "repo": "o/b", "n": 9, "kind": "pr", "title": "Parser docs", "author_kind": "human", "stage": "pr_open", "stage_n": 30, "since": "2026-10-31T07:00:00Z"}, + {"hive_id": "hive-a", "repo": "o/a", "n": 3, "kind": "issue", "title": "Parser crash", "author_kind": "hive", "stage": "open"}, + {"hive_id": "hive-b", "repo": "o/a", "n": 12, "kind": "pr", "title": "Unrelated", "author_kind": "hive", "stage": "merge_gate", "stage_n": 80, "since": "2026-10-31T06:00:00Z"}, + }, + "events": []any{}, + } + vb, err := json.Marshal(view) + if err != nil { + t.Fatal(err) + } + src := activityDisplayHarness(t) + "\nvar view = " + string(vb) + ";\n" + ` +var nums = function (v) { return v.items.map(function (it) { return it.repo + '#' + it.n; }); }; +var spoke = 'https://spoke.example/?display=1&am.kind=pr&am.q=parser&am.author=hive&am.labels=bug&am.group=repo#section-activity-monitor-section'; +var s = activityUrlView(spoke); +var hub = 'https://hub.example/activity?display=1&am.sort=number&am.dir=asc&am.group=none&token=secret'; +var h = activityUrlView(hub); +result = { + defaults: activityUrlView('https://hub.example/activity'), + spokeGroup: s.group, + spokeItems: nums(activityVisibleView(view, s.filter)), + unapplied: activityUnappliedKeys(s.filter), + hubGroup: h.group, + hubItems: nums(activityVisibleView(view, h.filter)), + furthest: nums(activityVisibleView(view, activityUrlView('https://hub.example/activity').filter)), + repo: nums(activityVisibleView(view, activityUrlView('https://hub.example/activity?am.repo=o/b').filter)), + untouched: nums(view), + back: activityViewHref(hub, h.filter, h.group), + regroup: activityViewHref(hub, h.filter, 'hive'), + keepsSpokeKeys: activityViewHref('https://hub.example/activity', s.filter, s.group), + newest: activityUnappliedKeys(activityUrlView('https://hub.example/activity?am.sort=newest').filter), +};` + var got struct { + Defaults struct { + Group string + Filter struct{ Kind, Sort, Dir string } + } + SpokeGroup, HubGroup string + SpokeItems, HubItems, Furthest, Untouched []string + Repo []string + Unapplied, Newest []string + Back, Regroup, KeepsSpokeKeys string + } + runEvidenceJS(t, src, &got) + + if got.Defaults.Group != "hive" || got.Defaults.Filter.Kind != "all" || got.Defaults.Filter.Sort != "furthest" || got.Defaults.Filter.Dir != "desc" { + t.Errorf("no am.* = %+v, want the spoke defaults with the board grouped by hive", got.Defaults) + } + // am.group=repo is a spoke grouping the hub board does not have: it falls + // back to the hub default exactly as an unknown value does on the spoke. + if got.SpokeGroup != "hive" { + t.Errorf("spoke am.group=repo on the hub = %q, want the default 'hive'", got.SpokeGroup) + } + if strings.Join(got.SpokeItems, ",") != "o/a#7" { + t.Errorf("am.kind=pr&am.q=parser&am.author=hive kept %v, want only o/a#7", got.SpokeItems) + } + if strings.Join(got.Unapplied, ",") != "am.labels" { + t.Errorf("unapplied keys = %v, want [am.labels]", got.Unapplied) + } + if strings.Join(got.Newest, ",") != "am.sort" { + t.Errorf("am.sort=newest needs created_at, which the digest lacks; unapplied = %v, want [am.sort]", got.Newest) + } + if got.HubGroup != "none" || strings.Join(got.HubItems, ",") != "o/a#3,o/a#7,o/a#12,o/b#9" { + t.Errorf("am.sort=number&am.dir=asc&am.group=none = %q %v", got.HubGroup, got.HubItems) + } + if strings.Join(got.Furthest, ",") != "o/a#12,o/a#7,o/b#9,o/a#3" { + t.Errorf("default furthest sort = %v, want the furthest strip column first", got.Furthest) + } + if strings.Join(got.Repo, ",") != "o/b#9" { + t.Errorf("am.repo=o/b kept %v", got.Repo) + } + if strings.Join(got.Untouched, ",") != "o/a#7,o/b#9,o/a#3,o/a#12" { + t.Errorf("activityVisibleView must not mutate the polled view; items now %v", got.Untouched) + } + if got.Back != "https://hub.example/activity?display=1&am.sort=number&am.dir=asc&am.group=none" { + t.Errorf("round trip = %q; want the same am.* keys back and no credential", got.Back) + } + if got.Regroup != "https://hub.example/activity?display=1&am.sort=number&am.dir=asc" { + t.Errorf("grouping by hive again = %q; the default must be omitted", got.Regroup) + } + if got.KeepsSpokeKeys != "https://hub.example/activity?am.kind=pr&am.q=parser&am.author=hive&am.labels=bug" { + t.Errorf("a spoke view re-serialised on the hub = %q; the spoke keys must survive", got.KeepsSpokeKeys) + } +} + +// ?display=1 turns `am.view` + `interval` into the display playlist with the +// spoke's dwell and wall-clock rotation, and every entry is a hub-activity +// view. Kiosk and the plain page never rotate, and one view is not a playlist. +func TestActivityDisplay_PlaylistListsHubActivityViews(t *testing.T) { + src := activityDisplayHarness(t) + "\n" + ` +var two = 'https://hub.example/activity?display=1&am.view=' + encodeURIComponent('am.kind=pr') + '&am.view=' + encodeURIComponent('am.group=none&am.repo=o/a') + '&am.view=bogus&interval=2m'; +var pl = activityPlaylist(two); +result = { + kind: ACTIVITY_DISPLAY_VIEW, + views: pl.views.map(function (v) { return { kind: v.kind, filterKind: v.filter.kind, repo: v.filter.repo, group: v.group }; }), + intervalMs: pl.intervalMs, + at0: activityPlaylistAt(pl, 0), + at1: activityPlaylistAt(pl, 120000 + 30000), + at2: activityPlaylistAt(pl, 240000), + kiosk: activityPlaylist(two.replace('display=1', 'kiosk=1')), + plain: activityPlaylist(two.replace('display=1&', '')), + one: activityPlaylist('https://hub.example/activity?display=1&am.view=' + encodeURIComponent('am.kind=pr')), +};` + var got struct { + Kind string + Views []struct{ Kind, FilterKind, Repo, Group string } + IntervalMs int + At0, At1, At2 struct { + Index int + RemainingMs int + Label string + } + Kiosk, Plain, One *struct{} + } + runEvidenceJS(t, src, &got) + + if got.Kind != "hub-activity" { + t.Errorf("ACTIVITY_DISPLAY_VIEW = %q, want hub-activity", got.Kind) + } + if len(got.Views) != 2 { + t.Fatalf("playlist views = %+v, want the two valid am.view entries (bogus skipped)", got.Views) + } + if got.Views[0].Kind != "hub-activity" || got.Views[0].FilterKind != "pr" || got.Views[0].Group != "hive" { + t.Errorf("view 0 = %+v", got.Views[0]) + } + if got.Views[1].Kind != "hub-activity" || got.Views[1].Repo != "o/a" || got.Views[1].Group != "none" { + t.Errorf("view 1 = %+v", got.Views[1]) + } + if got.IntervalMs != 120000 { + t.Errorf("interval=2m = %d ms", got.IntervalMs) + } + if got.At0.Index != 0 || got.At0.RemainingMs != 120000 || got.At0.Label != "1/2 · next in 120s" { + t.Errorf("at t=0: %+v", got.At0) + } + if got.At1.Index != 1 || got.At1.RemainingMs != 90000 || got.At1.Label != "2/2 · next in 90s" { + t.Errorf("at t=150s: %+v", got.At1) + } + if got.At2.Index != 0 { + t.Errorf("at t=240s the playlist wraps to view 0, got %+v", got.At2) + } + if got.Kiosk != nil || got.Plain != nil || got.One != nil { + t.Errorf("only ?display=1 with two or more views rotates: kiosk=%v plain=%v one=%v", got.Kiosk, got.Plain, got.One) + } +} + +// Within one strip column the furthest sort keeps the spoke's attention tier: +// rows with a modifier first, held or draft rows last, whatever am.dir says. +// The tier's vocabulary is the spoke's. +func TestActivityDisplay_FurthestSortKeepsTheSpokeAttentionTier(t *testing.T) { + src := activityDisplayHarness(t) + "\n" + ` +var view = { hives: [], items: [ + { repo: 'o/a', n: 1, kind: 'pr', stage_n: 50, since: '2026-10-31T06:00:00Z', mods: ['hold'] }, + { repo: 'o/a', n: 2, kind: 'pr', stage_n: 50, since: '2026-10-31T07:00:00Z' }, + { repo: 'o/a', n: 3, kind: 'pr', stage_n: 50, since: '2026-10-31T08:00:00Z', mods: ['stalled'] }, +] }; +var order = function (q) { return activityVisibleView(view, activityUrlView('https://hub.example/activity' + q).filter).items.map(function (it) { return it.n; }); }; +result = { desc: order(''), asc: order('?am.dir=asc') };` + var got struct{ Desc, Asc []int } + runEvidenceJS(t, src, &got) + if len(got.Desc) != 3 || got.Desc[0] != 3 || got.Desc[1] != 2 || got.Desc[2] != 1 { + t.Errorf("furthest desc = %v, want [3 2 1] (stalled, normal, held)", got.Desc) + } + if len(got.Asc) != 3 || got.Asc[0] != 3 || got.Asc[2] != 1 { + t.Errorf("furthest asc = %v; am.dir must never flip the tier", got.Asc) + } + + spoke, err := os.ReadFile(filepath.Join("..", "dashboard", "static-src", "js", "tracker-words-stage.js")) + if err != nil { + t.Fatal(err) + } + js := readActivityScript(t) + for hub, name := range map[string]string{"ACTIVITY_SUNK_MODS": "STAGE_TRACKER_SUNK_MODS", "ACTIVITY_ATTENTION_STAGES": "STAGE_TRACKER_ATTENTION_STAGES"} { + want := regexp.MustCompile(`(?m)^\s*const ` + name + ` = (.+?);`).FindStringSubmatch(string(spoke)) + have := regexp.MustCompile(`(?m)^\s*const ` + hub + ` = (.+?);`).FindStringSubmatch(js) + if want == nil || have == nil || want[1] != have[1] { + t.Errorf("activity.js %s = %v, want the spoke's %s = %v", hub, have, name, want) + } + } +} + +// Leaving display mode (Esc or d, like the spoke) keeps the view and drops +// only display=1; typing, modified keys and browser full screen never leave it. +func TestActivityDisplay_ExitKeysAndHref(t *testing.T) { + src := activityDisplayHarness(t) + "\n" + `result = { + href: activityDisplayExitHref('https://hub.example/activity?display=1&am.kind=pr&interval=2m'), + esc: activityDisplayExitKey({ key: 'Escape' }, false, false), + d: activityDisplayExitKey({ key: 'd' }, false, false), + fullscreen: activityDisplayExitKey({ key: 'Escape' }, false, true), + typing: activityDisplayExitKey({ key: 'd' }, true, false), + ctrl: activityDisplayExitKey({ key: 'd', ctrlKey: true }, false, false), + other: activityDisplayExitKey({ key: 'x' }, false, false), +};` + var got struct { + Href string + Esc, D, Fullscreen, Typing, Ctrl, Other bool + } + runEvidenceJS(t, src, &got) + if got.Href != "https://hub.example/activity?am.kind=pr&interval=2m" { + t.Errorf("exit href = %q", got.Href) + } + if !got.Esc || !got.D || got.Fullscreen || got.Typing || got.Ctrl || got.Other { + t.Errorf("exit keys = %+v", got) + } +} + +// The shared view asset reads the spoke's STAGE_TRACKER_* vocabulary as free +// globals. activity.js must define each with the spoke's value, so am.* +// normalises identically, except the group vocabulary: the hub board groups +// by hive (default) or not at all, never by repo. +func TestActivityDisplay_DefinesTrackerViewGlobalsWithSpokeValues(t *testing.T) { + globalRe := regexp.MustCompile(`\bSTAGE_TRACKER_[A-Z_]+\b`) + b, err := fs.ReadFile(trackerview.FS, "tracker-view.js") + if err != nil { + t.Fatal(err) + } + declared := map[string]bool{} + for _, m := range regexp.MustCompile(`(?m)^\s*const (STAGE_TRACKER_[A-Z_]+) =`).FindAllStringSubmatch(string(b), -1) { + declared[m[1]] = true + } + required := map[string]bool{} + for _, g := range globalRe.FindAllString(string(b), -1) { + if !declared[g] { + required[g] = true + } + } + if len(required) == 0 { + t.Fatal("found no host-supplied STAGE_TRACKER_* globals in tracker-view.js; the scan is broken") + } + spokeFiles, err := filepath.Glob(filepath.Join("..", "dashboard", "static-src", "js", "*.js")) + if err != nil || len(spokeFiles) == 0 { + t.Fatalf("spoke static-src not found (%v)", err) + } + var spoke strings.Builder + for _, f := range spokeFiles { + b, err := os.ReadFile(f) + if err != nil { + t.Fatal(err) + } + spoke.Write(b) + spoke.WriteByte('\n') + } + js := readActivityScript(t) + decl := func(src, name string) string { + m := regexp.MustCompile(`(?m)^\s*const ` + name + ` = (.+?);`).FindStringSubmatch(src) + if m == nil { + return "" + } + return strings.TrimSpace(m[1]) + } + hubOnly := map[string]string{ + "STAGE_TRACKER_GROUPS": "['hive', 'none']", + "STAGE_TRACKER_GROUP_DEFAULT": "'hive'", + } + for name := range required { + want, ok := hubOnly[name] + if !ok { + want = decl(spoke.String(), name) + if want == "" { + t.Errorf("the spoke no longer defines %s; update the shared view asset contract", name) + continue + } + } + if got := decl(js, name); got != want { + t.Errorf("activity.js %s = %q, want %q", name, got, want) + } + } + for name := range hubOnly { + if !required[name] { + t.Errorf("%s is no longer read by tracker-view.js; drop it from the hub-only list", name) + } + } +} diff --git a/src/pkg/hub/activity_page.go b/src/pkg/hub/activity_page.go index 1e30d2287c..5617935ef2 100644 --- a/src/pkg/hub/activity_page.go +++ b/src/pkg/hub/activity_page.go @@ -7,6 +7,7 @@ import ( "github.com/hivecommons/hive/pkg/dashboard/webstatic" "github.com/hivecommons/hive/pkg/webassets/trackerrow" + "github.com/hivecommons/hive/pkg/webassets/trackerview" ) // Fleet activity page (#16063, part of #15965 / RFC #15861 by @hanthor). @@ -66,18 +67,32 @@ func (s *HubServer) serveActivityShell(w http.ResponseWriter, r *http.Request) { _, _ = w.Write(page) } -// handleActivityAsset serves one file of the shared tracker row asset, -// byte-identical to pkg/webassets/trackerrow, with the static no-cache + -// content ETag headers. Only names listed in trackerrow.Files are served. -// The files are pure presentation code the spoke dashboard also ships, so -// they need no session. +// activityAssetFS is the shared asset package that lists name: the tracker +// row asset (pkg/webassets/trackerrow) or the am.* URL view and display +// playlist helpers (pkg/webassets/trackerview, #16064). Anything else is nil. +func activityAssetFS(name string) fs.FS { + switch { + case slices.Contains(trackerrow.Files, name): + return trackerrow.FS + case slices.Contains(trackerview.Files, name): + return trackerview.FS + } + return nil +} + +// handleActivityAsset serves one file of a shared tracker asset, +// byte-identical to its pkg/webassets package, with the static no-cache + +// content ETag headers. Only names listed in trackerrow.Files or +// trackerview.Files are served. The files are pure code the spoke dashboard +// also ships, so they need no session. func (s *HubServer) handleActivityAsset(w http.ResponseWriter, r *http.Request) { name := r.PathValue("name") - if !slices.Contains(trackerrow.Files, name) { + fsys := activityAssetFS(name) + if fsys == nil { s.writeHubErrorPage(w, http.StatusNotFound) return } - body, err := fs.ReadFile(trackerrow.FS, name) + body, err := fs.ReadFile(fsys, name) if err != nil { s.writeHubErrorPage(w, http.StatusNotFound) return diff --git a/src/pkg/hub/static/activity.css b/src/pkg/hub/static/activity.css index 3fcdb3e0cc..58c64ec7c0 100644 --- a/src/pkg/hub/static/activity.css +++ b/src/pkg/hub/static/activity.css @@ -91,3 +91,22 @@ a.activity-chip:hover, a.activity-chip:focus-visible { background: hsl(var(--hiv .activity-board tr { display: block; padding: var(--sp-3) 0; } .activity-board td, .activity-board th { display: block; border: 0; padding: var(--sp-1) var(--sp-4); } } + +/* Display mode (#16064), the spoke's #15860 Part A on this page. + ?kiosk=1: an unattended stream, no chrome and no cursor; it never rotates. + ?display=1: an attended wall screen, no chrome (Esc or d leaves it). The + status line and the coverage list stay visible in both. */ +body.kiosk-mode { cursor: none; } +body.kiosk-mode .activity-header, body.display-mode .activity-header, +body.kiosk-mode .activity-sub, body.display-mode .activity-sub, +body.kiosk-mode .activity-toggle, body.display-mode .activity-toggle { display: none !important; } +body.kiosk-mode .activity-playlist { display: none !important; } +.activity-playlist[hidden] { display: none; } +.activity-playlist { position: fixed; top: 0; left: 0; right: 0; z-index: 20; pointer-events: none; } +.activity-playlist-track { height: 3px; background: var(--line-subtle); } +.activity-playlist-bar { --activity-playlist-left: 1; display: block; height: 100%; width: calc(var(--activity-playlist-left) * 100%); background: var(--accent); transition: width 1s linear; } +.activity-playlist-next { display: none; position: absolute; top: var(--sp-2); right: var(--sp-4); color: var(--text-muted); font-size: var(--fs-sm); font-variant-numeric: tabular-nums; } +@media (prefers-reduced-motion: reduce) { + .activity-playlist-track { display: none; } + .activity-playlist-next { display: inline-block; } +} diff --git a/src/pkg/hub/static/activity.html b/src/pkg/hub/static/activity.html index 722972aa3d..9548c0a6bc 100644 --- a/src/pkg/hub/static/activity.html +++ b/src/pkg/hub/static/activity.html @@ -15,9 +15,13 @@ script: the page's CSP allows script files from 'self' only. --> + + + +
🐝 Hive