status page and console fleet page show the regional display name
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
7 files changed,
+131
−4
internal/console/server_test.go+43 −0internal/console/templates/fleet.html+2 −2internal/console/view.go+5 −1internal/console/view_test.go+25 −0internal/status/assets/index.html+14 −1internal/status/assets/status.css+8 −0internal/status/displayname_test.go+34 −0
diff --git a/internal/console/server_test.go b/internal/console/server_test.go| index cfad24697..4cc6823c4 100644 |
| --- a/internal/console/server_test.go |
| +++ b/internal/console/server_test.go |
| @@ -2677,3 +2677,46 @@ func TestConsoleNameBrandsThePages(t *testing.T) { |
| t.Fatal("account home still names CARLOS") |
| } |
| } |
| + |
| +// TestFleetShowsDisplayNames: both tables on /fleet show a named box as its |
| +// name with the label muted beside it, an unnamed box exactly as before, and |
| +// a box-written name escaped like every other string a box supplies. |
| +func TestFleetShowsDisplayNames(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + ctx := context.Background() |
| + now := time.Now() |
| + for _, b := range []status.Box{ |
| + {GeneratedAt: now, Label: "zed-x", Name: "aoife-herding-ie"}, |
| + {GeneratedAt: now, Label: "abe-y"}, |
| + {GeneratedAt: now, Label: "evil-z", Name: "<b>bold</b>"}, |
| + } { |
| + if err := status.WriteBox(ctx, fx.rel, b); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + f, err := status.BuildFleet(ctx, fx.rel, nil, now, status.SnapshotPeriod) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := status.PublishFleet(ctx, fx.rel, f); err != nil { |
| + t.Fatal(err) |
| + } |
| + c := signInPaul(t, fx) |
| + if err := fx.st.SetOperator("paul@keymail.dev", true); err != nil { |
| + t.Fatal(err) |
| + } |
| + code, _, body := get(t, c, fx.ts.URL+"/fleet") |
| + if code != 200 { |
| + t.Fatalf("/fleet = %d: %s", code, body) |
| + } |
| + named := `<td>aoife-herding-ie <span class="small">zed-x</span></td>` |
| + if n := strings.Count(body, named); n != 2 { |
| + t.Errorf("named cell %q appears %d times, want 2 (Boxes and Hosts):\n%s", named, n, body) |
| + } |
| + if n := strings.Count(body, "<td>abe-y</td>"); n != 2 { |
| + t.Errorf("unnamed cell appears %d times, want 2:\n%s", n, body) |
| + } |
| + if strings.Contains(body, "<b>bold</b>") { |
| + t.Errorf("a box-written name rendered as markup:\n%s", body) |
| + } |
| +} |
diff --git a/internal/console/templates/fleet.html b/internal/console/templates/fleet.html| index c956f6f0a..956d1f467 100644 |
| --- a/internal/console/templates/fleet.html |
| +++ b/internal/console/templates/fleet.html |
| @@ -44,7 +44,7 @@ |
| </tr> |
| {{range .Fleet.Boxes}} |
| <tr> |
| - <td>{{.Label}}</td> |
| + <td>{{if .Name}}{{.Name}} <span class="small">{{.Label}}</span>{{else}}{{.Label}}{{end}}</td> |
| <td>{{emptyOrDash .Region}}</td> |
| <td>{{strOrDash .Load}}</td> |
| <td>{{.Routes.Static}}</td> |
| @@ -106,7 +106,7 @@ |
| </tr> |
| {{range .Hosts}} |
| <tr> |
| - <td>{{.Label}}</td> |
| + <td>{{if .Name}}{{.Name}} <span class="small">{{.Label}}</span>{{else}}{{.Label}}{{end}}</td> |
| <td>{{emptyOrDash .Region}}</td> |
| {{if .Metrics}} |
| <td>{{emptyOrDash .Metrics.Release}}</td> |
diff --git a/internal/console/view.go b/internal/console/view.go| index 47b09e3f4..943828205 100644 |
| --- a/internal/console/view.go |
| +++ b/internal/console/view.go |
| @@ -839,7 +839,10 @@ func FleetView(ctx context.Context, s release.Store) (*status.Fleet, error) { |
| // {{if}}-rearrangement away from printing a dead box's memory as a current |
| // figure. |
| type HostRow struct { |
| - Label string |
| + Label string |
| + // Name is the box's regional display name (status.Box.Name), or "". |
| + // Display only: rows sort and key by Label. |
| + Name string |
| Region string |
| // Stale is status.BoxStale — the fleet's one staleness rule, measured |
| // against status.SnapshotPeriod, so this table and the published boxes |
| @@ -874,6 +877,7 @@ func HostRows(ctx context.Context, s release.Store, now time.Time) ([]HostRow, e |
| for _, b := range boxes { |
| row := HostRow{ |
| Label: b.Label, |
| + Name: b.Name, |
| Region: b.Region, |
| Stale: status.BoxStale(b, now, status.SnapshotPeriod), |
| LastSeen: b.GeneratedAt, |
diff --git a/internal/console/view_test.go b/internal/console/view_test.go| index 06833ce5d..78904dbdc 100644 |
| --- a/internal/console/view_test.go |
| +++ b/internal/console/view_test.go |
| @@ -12,6 +12,7 @@ import ( |
| "github.com/carlosframework/platform/internal/registry" |
| "github.com/carlosframework/platform/internal/release" |
| + "github.com/carlosframework/platform/internal/status" |
| ) |
| // deletableStore adds the retirement primitive the console needs (Delete) on |
| @@ -611,3 +612,27 @@ func TestVersionsEmptyApp(t *testing.T) { |
| t.Fatalf("Versions(ghost) = %+v %v, want empty nil", vs, err) |
| } |
| } |
| + |
| +// TestHostRowsCarryName: the display name rides along on the host row, the |
| +// unnamed (old-shape) report keeps an empty one, and the rows still sort by |
| +// label, never by name, so a name clash can't reorder or merge them. |
| +func TestHostRowsCarryName(t *testing.T) { |
| + ctx := context.Background() |
| + s := release.NewDirStore(t.TempDir()) |
| + now := time.Now() |
| + for _, b := range []status.Box{ |
| + {GeneratedAt: now, Label: "zed-x", Name: "aoife-herding-ie"}, |
| + {GeneratedAt: now, Label: "abe-y"}, |
| + } { |
| + if err := status.WriteBox(ctx, s, b); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + rows, err := HostRows(ctx, s, now) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if len(rows) != 2 || rows[0].Label != "abe-y" || rows[0].Name != "" || rows[1].Label != "zed-x" || rows[1].Name != "aoife-herding-ie" { |
| + t.Fatalf("rows = %+v", rows) |
| + } |
| +} |
diff --git a/internal/status/assets/index.html b/internal/status/assets/index.html| index 318e792f6..f47fd36b4 100644 |
| --- a/internal/status/assets/index.html |
| +++ b/internal/status/assets/index.html |
| @@ -170,7 +170,20 @@ |
| var body = document.getElementById("boxes-body"); |
| (f.boxes || []).forEach(function (b) { |
| var tr = document.createElement("tr"); |
| - tr.appendChild(td(asText(b.label))); |
| + // A regional display name (b.name) leads, with the box's label |
| + // muted beneath it; a box without one shows its label as before. |
| + // The name is display only: nothing on this page keys on it. |
| + if (b.name) { |
| + var cell = document.createElement("td"); |
| + cell.appendChild(asText(b.name)); |
| + var sub = document.createElement("span"); |
| + sub.className = "box-label"; |
| + sub.appendChild(asText(b.label)); |
| + cell.appendChild(sub); |
| + tr.appendChild(cell); |
| + } else { |
| + tr.appendChild(td(asText(b.label))); |
| + } |
| tr.appendChild(td(asText(b.region))); |
| tr.appendChild(td(asText(b.load))); |
| var routes = b.routes || {}; |
diff --git a/internal/status/assets/status.css b/internal/status/assets/status.css| index d3dde40a0..370e85985 100644 |
| --- a/internal/status/assets/status.css |
| +++ b/internal/status/assets/status.css |
| @@ -106,3 +106,11 @@ footer { |
| color: var(--muted); |
| font-size: 0.85rem; |
| } |
| + |
| +/* A box's label, muted beneath its regional display name. */ |
| +.box-label { |
| + display: block; |
| + color: var(--muted); |
| + font-size: 0.85em; |
| + white-space: nowrap; |
| +} |
diff --git a/internal/status/displayname_test.go b/internal/status/displayname_test.go| index 7c83f6462..f0a523c8b 100644 |
| --- a/internal/status/displayname_test.go |
| +++ b/internal/status/displayname_test.go |
| @@ -5,6 +5,7 @@ import ( |
| "encoding/json" |
| "regexp" |
| "sort" |
| + "strings" |
| "testing" |
| "time" |
| @@ -150,3 +151,36 @@ func TestCollectBoxIgnoresNameRegion(t *testing.T) { |
| t.Errorf("CollectBox set Name %q", b.Name) |
| } |
| } |
| + |
| +// TestStatusPageRendersNameAsText: a box with a display name shows the name |
| +// with its label beneath in a muted .box-label element; both go through |
| +// asText, never innerHTML, because a report is box-written and the page must |
| +// not trust it. |
| +func TestStatusPageRendersNameAsText(t *testing.T) { |
| + html, err := assetsFS.ReadFile("assets/index.html") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + page := string(html) |
| + start := strings.Index(page, "function renderBoxes(") |
| + if start < 0 { |
| + t.Fatal("renderBoxes not found") |
| + } |
| + end := strings.Index(page[start:], "\n }\n") |
| + body := page[start : start+end] |
| + for _, want := range []string{"asText(b.name)", `"box-label"`, "asText(b.label)"} { |
| + if !strings.Contains(body, want) { |
| + t.Errorf("renderBoxes lacks %s", want) |
| + } |
| + } |
| + if strings.Contains(body, "innerHTML") { |
| + t.Error("renderBoxes uses innerHTML") |
| + } |
| + css, err := assetsFS.ReadFile("assets/status.css") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if !strings.Contains(string(css), ".box-label") { |
| + t.Error("status.css defines no .box-label") |
| + } |
| +} |