carlos / platform Public

region labels: REGION in apps list, instances list, sidecars ls and routes (plan 2 task 3)

The routes table's REGION cell uses the table's own dash (dashIfEmpty, an em
dash glyph) for an older console, as its other empty cells do; path rows
gain a dash in the new column.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 666c50f412519395273bc66c03bee4c133ca63be parent 36a0902
7 files changed, +147 −13
  • instances_cli.go +12 −1
  • region_labels_e2e_test.go +33 −0
  • region_labels_test.go +55 −0
  • routes_cli.go +11 −4
  • sidecars_cli.go +1 −1
  • temporary.go +32 −4
  • temporary_test.go +3 −3
diff --git a/instances_cli.go b/instances_cli.go
index 3a9ceb358..ee0a53cf9 100644
--- a/instances_cli.go
+++ b/instances_cli.go
@@ -376,6 +376,17 @@ func seedCopyingLine(source, host string) string {
// instanceCreatedLine is the text after "created instance" or "canary
// host": today's "host (channel X<env>)" byte for byte from an older
// console, C14 when the console names the place.
+// instanceRegionCell is the REGION column (region labels §5 row 16): the
+// console's label and its move phrase, else the record's code, which is
+// what the column printed before.
+func instanceRegionCell(r apiInstanceRecord) string {
+ cell := placeOr(r.RegionName, r.Region)
+ if p := cleanPlace(r.MovePhrase); p != "" && cleanPlace(r.RegionName) != "" {
+ cell += ", " + p
+ }
+ return cell
+}
+
func instanceCreatedLine(rec apiInstanceRecord, envSuffix string) string {
// The console's label when it sent one fit to print (region labels §5
// row 17), else the full place an older console sent.
@@ -587,7 +598,7 @@ func runInstancesList(args []string) {
if rowHealth == "" {
rowHealth = "—" // an old console: the field predates it, not "unhealthy"
}
- fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n", r.Host, r.Region, r.Channel, r.Pool,
+ fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n", r.Host, instanceRegionCell(r), r.Channel, r.Pool,
installedCell(r), servingCell(r), rowHealth, upstreamsCell(r.Upstreams), humanBytes(r.DBBytes),
r.CreatedAt, r.CreatedBy, reasonCell(r), seedCell(r))
}
diff --git a/region_labels_e2e_test.go b/region_labels_e2e_test.go
index ac2b560ea..bb2c09e96 100644
--- a/region_labels_e2e_test.go
+++ b/region_labels_e2e_test.go
@@ -13,6 +13,7 @@ import (
"github.com/carlosframework/platform/internal/console"
"github.com/carlosframework/platform/internal/edgesfile"
+ "github.com/carlosframework/platform/internal/registry"
"github.com/carlosframework/platform/internal/release"
"github.com/carlosframework/platform/internal/status"
)
@@ -130,3 +131,35 @@ func TestRegionLabelsCreateLinesThroughTheConsole(t *testing.T) {
t.Fatalf("apps create on a switch-off console:\n%s", got)
}
}
+
+func TestRegionLabelsListingsThroughTheConsole(t *testing.T) {
+ e := newLabelsE2E(t)
+ e.out(t, runInstancesEnable, "-app", "shop", "-account", "ops", "-channel", "beta")
+ e.out(t, runInstancesCreate, "-app", "shop", "-account", "ops", "-host", "uk1."+labelsDomain, "-region", "uk")
+ e.out(t, runInstancesCreate, "-app", "shop", "-account", "ops", "-host", "home1."+labelsDomain)
+
+ list := e.out(t, runInstancesList, "-app", "shop", "-account", "ops")
+ for _, want := range []string{"London (uk)", "Dublin (ie)"} {
+ if !strings.Contains(list, want) {
+ t.Fatalf("instances list lacks %q:\n%s", want, list)
+ }
+ }
+ apps := e.out(t, runAppsList, "--account", "ops")
+ if !strings.Contains(apps, "Dublin (ie)") {
+ t.Fatalf("apps list:\n%s", apps)
+ }
+
+ // A route on the console's box, in uk.
+ reg, err := registry.Open(e.regPath)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if err := reg.Upsert(registry.Route{Host: "www.shop.example.com", Kind: "instance", App: "shop",
+ Account: release.OpsAccount, Region: "uk"}); err != nil {
+ t.Fatal(err)
+ }
+ routes := e.out(t, runRoutes, "-app", "shop", "-account", "ops")
+ if !strings.Contains(routes, "REGION") || !strings.Contains(routes, "London (uk)") {
+ t.Fatalf("routes:\n%s", routes)
+ }
+}
diff --git a/region_labels_test.go b/region_labels_test.go
index a078b9e6e..35f6b1918 100644
--- a/region_labels_test.go
+++ b/region_labels_test.go
@@ -2,8 +2,10 @@ package main
import (
"encoding/json"
+ "fmt"
"strings"
"testing"
+ "time"
)
func TestCleanPlaceRefusesWhatATerminalWouldObey(t *testing.T) {
@@ -60,3 +62,56 @@ func TestAPITypesReadLabels(t *testing.T) {
t.Fatalf("move answer = %+v", ans)
}
}
+
+// Older consoles: today's bytes.
+func TestListingsAgainstAnOlderConsole(t *testing.T) {
+ now := time.Now()
+ old := apiAppLife{App: "shop"}
+ if appsListHasRegions([]apiAppLife{old}) {
+ t.Fatal("an older console's list has no region column")
+ }
+ if got, want := appLifeLine(old, now, false), strings.TrimRight(fmt.Sprintf("%-32s %-7s %s", "shop", "live", ""), " "); got != want {
+ t.Fatalf("older console line %q, want today's %q", got, want)
+ }
+ if got := instanceRegionCell(apiInstanceRecord{Region: "uk"}); got != "uk" {
+ t.Fatalf("older console REGION cell %q, want the code", got)
+ }
+ if got := instanceRegionCell(apiInstanceRecord{Region: ""}); got != "" {
+ t.Fatalf("older console home cell %q, want today's blank", got)
+ }
+ // carlos routes against a console without the fields (§10): the
+ // table's own dash, as its other empty cells print.
+ if got := routeRegionCell(apiRouteRow{Host: "www.shop.example.com"}); got != dashIfEmpty("") {
+ t.Fatalf("older console routes cell %q", got)
+ }
+ if got := routeRegionCell(apiRouteRow{Region: "uk", RegionName: "London (uk)"}); got != "London (uk)" {
+ t.Fatalf("routes cell %q", got)
+ }
+}
+
+func TestInstancesListRegionCell(t *testing.T) {
+ if got := instanceRegionCell(apiInstanceRecord{Region: "uk", RegionName: "London (uk)", MovePhrase: "moving to Sydney (au)"}); got != "London (uk), moving to Sydney (au)" {
+ t.Fatalf("cell %q", got)
+ }
+}
+
+// TestInstancesListDropsAnUnprintableLabel: Review Focus 2.
+func TestInstancesListDropsAnUnprintableLabel(t *testing.T) {
+ if got := instanceRegionCell(apiInstanceRecord{Region: "uk", RegionName: "London\x1b[2J (uk)", MovePhrase: "\x07"}); got != "uk" {
+ t.Fatalf("cell %q, want the code", got)
+ }
+}
+
+// TestAppsListLongLabel: Review Focus 5.
+func TestAppsListLongLabel(t *testing.T) {
+ name := "N. California (us-west)"
+ l := apiAppLife{App: "shop", Region: "us-west", RegionName: &name}
+ line := appLifeLine(l, time.Now(), true)
+ if !strings.Contains(line, "N. California (us-west)") || !strings.HasPrefix(line, "shop ") {
+ t.Fatalf("line %q", line)
+ }
+ empty := ""
+ if got := appLifeLine(apiAppLife{App: "shop", RegionName: &empty}, time.Now(), true); !strings.Contains(got, " -") {
+ t.Fatalf("an unknown region is a dash: %q", got)
+ }
+}
diff --git a/routes_cli.go b/routes_cli.go
index 4623fe8bf..527d521c5 100644
--- a/routes_cli.go
+++ b/routes_cli.go
@@ -58,14 +58,14 @@ func runRoutes(args []string) {
}
shown := 0
w := newTable(stdout)
- fmt.Fprintln(w, "HOST\tKIND\tUPSTREAM\tCHANNEL\tENVIRONMENT\tREPLICATION\tSTATUS\tHEALTH\tDB")
+ fmt.Fprintln(w, "HOST\tREGION\tKIND\tUPSTREAM\tCHANNEL\tENVIRONMENT\tREPLICATION\tSTATUS\tHEALTH\tDB")
for _, r := range rows {
if *match != "" && !strings.Contains(r.Host, *match) {
continue
}
shown++
- fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",
- r.Host, dashIfEmpty(r.Kind), dashIfEmpty(r.Upstream), dashIfEmpty(r.Channel),
+ fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",
+ r.Host, routeRegionCell(r), dashIfEmpty(r.Kind), dashIfEmpty(r.Upstream), dashIfEmpty(r.Channel),
// An empty ENVIRONMENT is a real answer — the route takes the
// app's default bundle — so it prints as a dash rather than a
// blank cell a reader would take for missing data.
@@ -98,7 +98,7 @@ func runRoutes(args []string) {
if p.Host != r.Host {
continue
}
- fmt.Fprintf(w, " /%s\tpath\t%s\t—\t—\t—\t—\t—\t—\n", p.Prefix, dashIfEmpty(p.Target))
+ fmt.Fprintf(w, " /%s\t—\tpath\t%s\t—\t—\t—\t—\t—\t—\n", p.Prefix, dashIfEmpty(p.Target))
}
}
w.Flush()
@@ -140,3 +140,10 @@ func dbCell(n *int64) string {
}
return humanBytes(n)
}
+
+// routeRegionCell is carlos routes' REGION column (region labels §5 row
+// 30): the console's label, else its code, else a dash (an older console
+// sends neither).
+func routeRegionCell(r apiRouteRow) string {
+ return dashIfEmpty(placeOr(r.RegionName, r.Region))
+}
diff --git a/sidecars_cli.go b/sidecars_cli.go
index 652528eb3..158089d8b 100644
--- a/sidecars_cli.go
+++ b/sidecars_cli.go
@@ -416,7 +416,7 @@ func runSidecarsList(args []string) {
id = r.Host
}
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",
- id, r.Region, r.Channel, r.Pool, sidecarPlacementCell(r.Placement),
+ id, placeOr(r.RegionName, r.Region), r.Channel, r.Pool, sidecarPlacementCell(r.Placement),
sidecarVersionCell(r.RunningVersion), r.CreatedAt, r.CreatedBy)
}
w.Flush()
diff --git a/temporary.go b/temporary.go
index b1251c004..f419a5e12 100644
--- a/temporary.go
+++ b/temporary.go
@@ -189,9 +189,24 @@ func printTemporaryExpiry(ctx context.Context, sess *apiSession, acct apiAcct, a
}
}
+// appsListHasRegions is whether the console sent each app's region (region
+// labels §4): a labels console sends region_name on every app, "" when it
+// could not read the placement. An older console sends none, and the list
+// prints as it always did.
+func appsListHasRegions(lives []apiAppLife) bool {
+ for _, l := range lives {
+ if l.RegionName != nil {
+ return true
+ }
+ }
+ return false
+}
+
// appLifeLine is one line of `carlos apps list` (spec §7): name, live or
-// trashed, and "expires in 3d", "purged in 2d" or nothing.
-func appLifeLine(l apiAppLife, now time.Time) string {
+// trashed, the app's region when the console sent regions (region labels
+// §5 row 15; a dash when it could not read one), and "expires in 3d",
+// "purged in 2d" or nothing.
+func appLifeLine(l apiAppLife, now time.Time, withRegion bool) string {
state, note := "live", "" // C11.8
switch {
case l.DeletedAt != nil:
@@ -202,7 +217,14 @@ func appLifeLine(l apiAppLife, now time.Time) string {
case l.ExpiresAt != nil:
note = "expires " + inDuration(l.ExpiresAt.Sub(now)) // C11.8
}
- return strings.TrimRight(fmt.Sprintf("%-32s %-7s %s", l.App, state, note), " ")
+ if !withRegion {
+ return strings.TrimRight(fmt.Sprintf("%-32s %-7s %s", l.App, state, note), " ")
+ }
+ region := "-"
+ if l.RegionName != nil {
+ region = placeOr(*l.RegionName, "-")
+ }
+ return strings.TrimRight(fmt.Sprintf("%-32s %-7s %-24s %s", l.App, state, region, note), " ")
}
// requireSignedInApps refuses direct mode by name for the apps verbs that
@@ -300,7 +322,13 @@ func runAppsList(args []string) {
return
}
now := time.Now()
+ withRegion := appsListHasRegions(lives)
+ if withRegion {
+ // The header comes with the REGION column, so an older console's
+ // list prints as it always did.
+ fmt.Fprintln(stdout, strings.TrimRight(fmt.Sprintf("%-32s %-7s %-24s %s", "APP", "STATE", "REGION", ""), " "))
+ }
for _, l := range lives {
- fmt.Fprintln(stdout, appLifeLine(l, now))
+ fmt.Fprintln(stdout, appLifeLine(l, now, withRegion))
}
}
diff --git a/temporary_test.go b/temporary_test.go
index dccc3fcef..302972b50 100644
--- a/temporary_test.go
+++ b/temporary_test.go
@@ -233,13 +233,13 @@ func TestAPISessionLifecycleDoors(t *testing.T) {
func TestAppLifeLine(t *testing.T) {
now := time.Date(2026, 9, 26, 12, 0, 0, 0, time.UTC)
at := func(d time.Duration) *time.Time { v := now.Add(d); return &v }
- if line := appLifeLine(apiAppLife{App: "tmp-a", ExpiresAt: at(72 * time.Hour)}, now); !strings.Contains(line, "live") || !strings.Contains(line, "expires in 3d") {
+ if line := appLifeLine(apiAppLife{App: "tmp-a", ExpiresAt: at(72 * time.Hour)}, now, false); !strings.Contains(line, "live") || !strings.Contains(line, "expires in 3d") {
t.Errorf("live temporary = %q", line)
}
- if line := appLifeLine(apiAppLife{App: "tmp-b", ExpiresAt: at(-time.Hour), DeletedAt: at(-time.Hour), PurgeAfter: at(49 * time.Hour)}, now); !strings.Contains(line, "trashed") || !strings.Contains(line, "purged in 2d") {
+ if line := appLifeLine(apiAppLife{App: "tmp-b", ExpiresAt: at(-time.Hour), DeletedAt: at(-time.Hour), PurgeAfter: at(49 * time.Hour)}, now, false); !strings.Contains(line, "trashed") || !strings.Contains(line, "purged in 2d") {
t.Errorf("trashed temporary = %q", line)
}
- if line := appLifeLine(apiAppLife{App: "kass"}, now); strings.Contains(line, "expires") || strings.Contains(line, "purged") {
+ if line := appLifeLine(apiAppLife{App: "kass"}, now, false); strings.Contains(line, "expires") || strings.Contains(line, "purged") {
t.Errorf("live permanent = %q, want no time", line)
}
}