console: region refusals name the home by its code, not an empty name
Branch review R1, Astra P2. The instance and sidecar doors' "region X is not one this app runs in" refusal now renders the requested region and the allowed list through homeRegionOut, so a home-region HA app's Regions [""] reads as the home's code. No wording changes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4 files changed,
+21
−5
internal/console/apiinstancemove.go+11 −0internal/console/apiinstances.go+1 −1internal/console/apiinstances_haenable_test.go+8 −3internal/console/apisidecars.go+1 −1
diff --git a/internal/console/apiinstancemove.go b/internal/console/apiinstancemove.go| index ef30dfb67..8850ee38c 100644 |
| --- a/internal/console/apiinstancemove.go |
| +++ b/internal/console/apiinstancemove.go |
| @@ -346,6 +346,17 @@ func (s *Server) homeRegionOut(region string) string { |
| return region |
| } |
| +// homeRegionsOut is homeRegionOut over a list (a manifest's Regions, in |
| +// record vocabulary), for a refusal that names them: the home's "" reads |
| +// as the home's code, never as an empty name. |
| +func (s *Server) homeRegionsOut(regions []string) []string { |
| + out := make([]string, len(regions)) |
| + for i, r := range regions { |
| + out[i] = s.homeRegionOut(r) |
| + } |
| + return out |
| +} |
| + |
| // moveTransition applies one guarded transition and maps its outcomes: |
| // ErrMoveConflict → 409 with the transition's own sentence, success → the |
| // flat move view + a serial bump so the source box notices in seconds. |
diff --git a/internal/console/apiinstances.go b/internal/console/apiinstances.go| index 4d2ecc753..9d7c392a1 100644 |
| --- a/internal/console/apiinstances.go |
| +++ b/internal/console/apiinstances.go |
| @@ -2044,7 +2044,7 @@ func (s *Server) handleAPIInstanceCreate(w http.ResponseWriter, r *http.Request) |
| } else if !provision.ValidRegion(region) || !instanceRegionAllowed(m.Regions, region) { |
| msg := "invalid region" |
| if len(m.Regions) > 0 { |
| - msg = "region " + region + " is not one this app runs in — allowed: " + strings.Join(m.Regions, ", ") |
| + msg = "region " + s.homeRegionOut(region) + " is not one this app runs in — allowed: " + strings.Join(s.homeRegionsOut(m.Regions), ", ") |
| } |
| jsonError(w, http.StatusBadRequest, msg) |
| return |
diff --git a/internal/console/apiinstances_haenable_test.go b/internal/console/apiinstances_haenable_test.go| index 43b03e92c..38e822f4f 100644 |
| --- a/internal/console/apiinstances_haenable_test.go |
| +++ b/internal/console/apiinstances_haenable_test.go |
| @@ -227,8 +227,13 @@ func TestEnableHAHomeRegion(t *testing.T) { |
| return code, out |
| } |
| w.refused(t, "an instance in us", haAllow{Ops: haInstanceRegionOps()}, func() { |
| - if code, out := post("us"); code != http.StatusBadRequest { |
| - t.Errorf("instance in us = %d %s, want 400", code, out) |
| + // The refusal names the home by its code, never as an empty name |
| + // (branch review R1, Astra P2). |
| + code, out := post("us") |
| + var res map[string]any |
| + _ = json.Unmarshal([]byte(out), &res) |
| + if want := "region us is not one this app runs in — allowed: ie"; code != http.StatusBadRequest || errOf(res) != want { |
| + t.Errorf("instance in us = %d %s, want 400 %q", code, out, want) |
| } |
| }) |
| // Control: the same create naming the home. |
| @@ -255,7 +260,7 @@ func TestEnableHAInstanceOtherRegionRefused(t *testing.T) { |
| fmt.Sprintf(`{"host":%q,"region":"ie"}`, host)) |
| var res map[string]any |
| _ = json.Unmarshal([]byte(out), &res) |
| - if want := "region is not one this app runs in — allowed: us"; code != http.StatusBadRequest || errOf(res) != want { |
| + if want := "region ie is not one this app runs in — allowed: us"; code != http.StatusBadRequest || errOf(res) != want { |
| t.Errorf("instance in ie = %d %s, want 400 %q", code, out, want) |
| } |
| }) |
diff --git a/internal/console/apisidecars.go b/internal/console/apisidecars.go| index 5f3f6d7b5..a3589647a 100644 |
| --- a/internal/console/apisidecars.go |
| +++ b/internal/console/apisidecars.go |
| @@ -330,7 +330,7 @@ func (s *Server) handleAPISidecarCreate(w http.ResponseWriter, r *http.Request) |
| } else if !provision.ValidRegion(region) || !instanceRegionAllowed(m.Regions, region) { |
| msg := "invalid region" |
| if len(m.Regions) > 0 { |
| - msg = "region " + s.homeRegionOut(region) + " is not one this app's sidecars run in — allowed: " + strings.Join(m.Regions, ", ") |
| + msg = "region " + s.homeRegionOut(region) + " is not one this app's sidecars run in — allowed: " + strings.Join(s.homeRegionsOut(m.Regions), ", ") |
| } |
| jsonError(w, http.StatusBadRequest, msg) |
| return |