fleet-routes-followups: console deferred minors (#457 1a, Task 11)
- fleetFromRoutes and legacyFleetFromRoutes share one loop, firstFleetPlacement; the only difference, skipping forward rows, is a parameter. fleetFromRoutes' doc comment no longer calls it appPlacement's fallback (that is legacyFleetFromRoutes since 1a); the same stale phrase on view.go's routeFleet is corrected. - TestFleetFromRoutesSplitOnForwardRows pins the split: the display fold reads a forward row, the legacy fold skips it. Before this only the legacy side was pinned (TestUnplaceLeavesNoFleetBehind); a mutation making the display fold skip forward rows passed every console test. - backfillAppPlacements' doc comment rewrapped (sealkey.go:201).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4 files changed,
+50
−26
internal/console/regionfacts.go+21 −20internal/console/regionfacts_test.go+22 −0internal/console/sealkey.go+5 −4internal/console/view.go+2 −2
diff --git a/internal/console/regionfacts.go b/internal/console/regionfacts.go| index fd02869aa..9bedc4f54 100644 |
| --- a/internal/console/regionfacts.go |
| +++ b/internal/console/regionfacts.go |
| @@ -108,31 +108,32 @@ func (f appRegionFacts) SourceSentence() string { |
| } |
| // legacyFleetFromRoutes is the placement an app placed by an older build |
| -// carries only in its rows: fleetFromRoutes over the rows that can carry |
| -// one. A forward row is skipped (fleet public routes, controller ruling 1): |
| -// the hub mints it from a record already placed, and retires it only on its |
| -// next pass after the record leaves the fleet, so it is never a legacy |
| -// placement, and reading it after an unplace would hand the app its old |
| -// fleet back. appPlacement, the startup backfill and fleetPlacedApps read |
| -// this; the display readers keep fleetFromRoutes. |
| +// carries only in its rows: the first fleet placement among sqid/app's rows |
| +// that can carry one. A forward row is skipped (fleet public routes, |
| +// controller ruling 1): the hub mints it from a record already placed, and |
| +// retires it only on its next pass after the record leaves the fleet, so it |
| +// is never a legacy placement, and reading it after an unplace would hand |
| +// the app its old fleet back. appPlacement, the startup backfill and |
| +// fleetPlacedApps read this; the display readers keep fleetFromRoutes. |
| func legacyFleetFromRoutes(routes []registry.Route, sqid, app string) string { |
| - for _, rt := range routes { |
| - if rt.IsForward() || rt.Account != sqid || rt.App != app { |
| - continue |
| - } |
| - if _, ok := registry.FleetPlacement(rt.Region); ok { |
| - return rt.Region |
| - } |
| - } |
| - return "" |
| + return firstFleetPlacement(routes, sqid, app, true) |
| } |
| -// fleetFromRoutes is appPlacement's legacy fallback over rows already |
| -// listed: the first fleet placement among sqid/app's rows, compared on the |
| -// raw account column exactly as appPlacement always has (fleets.go). |
| +// fleetFromRoutes is the display readers' fold over rows already listed |
| +// (the app view, the temporary-apps list, region facts): the first fleet |
| +// placement among sqid/app's rows, a forward row's included. appPlacement's |
| +// own fallback is legacyFleetFromRoutes, which skips forward rows. |
| func fleetFromRoutes(routes []registry.Route, sqid, app string) string { |
| + return firstFleetPlacement(routes, sqid, app, false) |
| +} |
| + |
| +// firstFleetPlacement is the one loop behind both folds: the first fleet |
| +// placement among sqid/app's rows, compared on the raw account column |
| +// exactly as appPlacement always has (fleets.go), forward rows skipped when |
| +// skipForward is set. |
| +func firstFleetPlacement(routes []registry.Route, sqid, app string, skipForward bool) string { |
| for _, rt := range routes { |
| - if rt.Account != sqid || rt.App != app { |
| + if (skipForward && rt.IsForward()) || rt.Account != sqid || rt.App != app { |
| continue |
| } |
| if _, ok := registry.FleetPlacement(rt.Region); ok { |
diff --git a/internal/console/regionfacts_test.go b/internal/console/regionfacts_test.go| index 3c7fe1011..d6fd70db7 100644 |
| --- a/internal/console/regionfacts_test.go |
| +++ b/internal/console/regionfacts_test.go |
| @@ -91,6 +91,28 @@ func TestFleetFromRoutesIsAppPlacementsFallback(t *testing.T) { |
| } |
| } |
| +// TestFleetFromRoutesSplitOnForwardRows pins the one difference between the |
| +// two folds over listed rows (fleet public routes, controller ruling 1): the |
| +// display fold, fleetFromRoutes, reads a forward row's placement like any |
| +// row's; appPlacement's legacy fold, legacyFleetFromRoutes, skips it, since |
| +// a forward row is never a legacy placement. Both read only sqid/app's rows. |
| +func TestFleetFromRoutesSplitOnForwardRows(t *testing.T) { |
| + routes := []registry.Route{ |
| + {Host: "other.example.com", Kind: "instance", App: "shop", Account: "baj", Region: "fleet/theirs"}, |
| + {Host: "shop.example.com", Kind: registry.KindForward, App: "shop", Account: "bah", Region: "fleet/home"}, |
| + } |
| + if got := fleetFromRoutes(routes, "bah", "shop"); got != "fleet/home" { |
| + t.Errorf("fleetFromRoutes = %q, want fleet/home from the forward row", got) |
| + } |
| + if got := legacyFleetFromRoutes(routes, "bah", "shop"); got != "" { |
| + t.Errorf("legacyFleetFromRoutes = %q, want empty: a forward row is not a legacy placement", got) |
| + } |
| + routes = append(routes, registry.Route{Host: "legacy.example.com", Kind: "instance", App: "shop", Account: "bah", Region: "fleet/private"}) |
| + if got := legacyFleetFromRoutes(routes, "bah", "shop"); got != "fleet/private" { |
| + t.Errorf("legacyFleetFromRoutes = %q, want fleet/private from the instance row", got) |
| + } |
| +} |
| + |
| func TestRegistryRoutesSeamAndFailure(t *testing.T) { |
| fx := newConsoleFixture(t) |
| fx.srv.listRoutes = func() ([]registry.Route, error) { return nil, errors.New("registry unreadable") } |
diff --git a/internal/console/sealkey.go b/internal/console/sealkey.go| index 26bf69a1a..c02575d0a 100644 |
| --- a/internal/console/sealkey.go |
| +++ b/internal/console/sealkey.go |
| @@ -198,10 +198,11 @@ func (s *Server) deploymentSealKey() (*ecdh.PublicKey, error) { |
| // backfillAppPlacements writes the placement column from routes for every |
| // live app whose column is empty and whose routes say fleet/<f> |
| -// (legacyFleetFromRoutes, which skips forward rows), so the column becomes the one authority (spec §5.2 step |
| -// 2). It does not change any answer appPlacement gives: appPlacement already |
| -// falls back to the same routes for those apps. That is why it need not |
| -// finish before the first seal (plan ruling R-1). |
| +// (legacyFleetFromRoutes, which skips forward rows), so the column becomes |
| +// the one authority (spec §5.2 step 2). It does not change any answer |
| +// appPlacement gives: appPlacement already falls back to the same routes |
| +// for those apps. That is why it need not finish before the first seal |
| +// (plan ruling R-1). |
| // |
| // One route listing picks the candidates. Each candidate is then decided |
| // again under the account lock and its app lock, the lock placeAppTarget |
diff --git a/internal/console/view.go b/internal/console/view.go| index 233b9986d..b74dd8b42 100644 |
| --- a/internal/console/view.go |
| +++ b/internal/console/view.go |
| @@ -42,8 +42,8 @@ type AppView struct { |
| // as the console shows it — see ProductionView. |
| Production ProductionView |
| // routeFleet is the first fleet placement among this app's rows in the |
| - // console box's registry (fleetFromRoutes): appPlacement's legacy |
| - // fallback, folded from the listing Assemble already made. |
| + // console box's registry (fleetFromRoutes, the display fold, forward |
| + // rows included), folded from the listing Assemble already made. |
| routeFleet string |
| // RouteAccount is the account the app's ROUTES say it belongs to, when |
| // that disagrees with the account whose page this is; "" when they agree |