carlos / platform Public

region labels: carlos move names regions by label; printed commands keep the codes (plan 2 task 6)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev c8473008889f32a84349673e78a24570ea96d241 parent 1d15259
3 files changed, +144 −28
  • move.go +35 −27
  • move_test.go +70 −0
  • offline_move_e2e_test.go +39 −1
diff --git a/move.go b/move.go
index b05b02388..13408ec10 100644
--- a/move.go
+++ b/move.go
@@ -618,7 +618,7 @@ func (m *mover) accepted(ctx context.Context, r moveReply, wait, request bool) i
return moveExitDone
}
w := newMoveWatch(m, view.ID)
- w.toRegion = view.Target
+ w.toRegion = placeOr(view.TargetName, view.Target)
a, code := m.readDetail(ctx)
if code >= 0 {
return code
@@ -692,11 +692,13 @@ func (w *moveWatch) learn(a moveAnswer) {
if a.ID != w.id {
return
}
- if a.Detail.From != "" {
- w.fromRegion = a.Detail.From
+ // Places for the sentences (region labels §5 row 25): the console's
+ // labels, else the codes it sent. Nothing here is ever a command.
+ if a.Detail != nil && (a.Detail.From != "" || a.Detail.FromName != "") {
+ w.fromRegion = placeOr(a.Detail.FromName, a.Detail.From)
}
if a.Target != "" {
- w.toRegion = a.Target
+ w.toRegion = placeOr(a.TargetName, a.Target)
}
}
@@ -1004,6 +1006,12 @@ var offlineVerbs = []string{"stage", "start", "seal", "flip", "open", "finish",
// offlineView is the offline status view (GET) and the 202 every mutating
// door answers with.
+// fromPlace and toPlace are the move's regions as a sentence names them
+// (region labels §5 row 26): the console's labels, else the codes. Every
+// command printed (--to) keeps v.To.
+func (v offlineView) fromPlace() string { return placeOr(v.FromName, v.From) }
+func (v offlineView) toPlace() string { return placeOr(v.ToName, v.To) }
+
type offlineView struct {
Host string `json:"host"`
State string `json:"state"`
@@ -1068,7 +1076,7 @@ func (w *offlineRun) sayStaged(v offlineView) {
return
}
at := time.Unix(c.RoundAt, 0).UTC().Format("2006-01-02 15:04 UTC")
- moveSay(w.m.out, fmt.Sprintf("Staged %d of %d objects for %s in %s (%s of %s MB) at %s.", c.Done, c.Total, host, v.To, megabytes(c.DoneBytes), megabytes(c.TotalBytes), at))
+ moveSay(w.m.out, fmt.Sprintf("Staged %d of %d objects for %s in %s (%s of %s MB) at %s.", c.Done, c.Total, host, v.toPlace(), megabytes(c.DoneBytes), megabytes(c.TotalBytes), at))
}
// sayStartWhenReady is MV-O184: what comes after a stage.
@@ -1244,7 +1252,7 @@ func (w *offlineRun) sayFailure(v offlineView) bool {
}
switch kind {
case failTarget:
- moveSay(w.m.out, fmt.Sprintf("%s could not take %s: %s. Run carlos move offline abort --host %s to move it back.", v.To, host, reason, host))
+ moveSay(w.m.out, fmt.Sprintf("%s could not take %s: %s. Run carlos move offline abort --host %s to move it back.", v.toPlace(), host, reason, host))
case failSource:
for _, r := range v.Reports {
if r.Role == moves.OfflineRoleSource && r.Phase == moves.OfflinePhaseFailed {
@@ -1269,7 +1277,7 @@ type offlineRun struct {
func (w *offlineRun) learn(v offlineView) {
if v.ID != "" && (w.id == "" || w.id == v.ID) {
- w.id, w.from, w.to = v.ID, v.From, v.To
+ w.id, w.from, w.to = v.ID, v.fromPlace(), v.toPlace()
}
}
@@ -1421,7 +1429,7 @@ func (w *offlineRun) served(v offlineView) bool {
func (w *offlineRun) sayServed(v offlineView) {
if w.once("served") {
host := w.m.host
- moveSay(w.m.out, fmt.Sprintf("%s is served from %s. Run carlos move offline finish --host %s once %s has cleaned up.", host, v.To, host, v.From))
+ moveSay(w.m.out, fmt.Sprintf("%s is served from %s. Run carlos move offline finish --host %s once %s has cleaned up.", host, v.toPlace(), host, v.fromPlace()))
}
}
@@ -1429,7 +1437,7 @@ func (w *offlineRun) sayServed(v offlineView) {
func (w *offlineRun) headline(r offlineReply) {
v, host := r.v, w.m.host
if v.State == provision.OfflineStaging {
- moveSay(w.m.out, fmt.Sprintf("Staging %s in %s. %s keeps serving while the data is copied.", host, v.To, host))
+ moveSay(w.m.out, fmt.Sprintf("Staging %s in %s. %s keeps serving while the data is copied.", host, v.toPlace(), host))
w.sayStaged(v)
if v.Next == "start" {
w.sayStartWhenReady(v)
@@ -1438,30 +1446,30 @@ func (w *offlineRun) headline(r offlineReply) {
w.sayWaiting(r)
return
}
- moveSay(w.m.out, moves.MoveStartingLine(host, v.From, v.To))
+ moveSay(w.m.out, moves.MoveStartingLine(host, v.fromPlace(), v.toPlace()))
if w.sayFailure(v) {
return
}
switch v.State {
case provision.OfflineStopping:
if v.Next == "seal" {
- moveSay(w.m.out, fmt.Sprintf("Every box in %s has stopped %s. Run carlos move offline seal --host %s to copy it.", v.From, host, host))
+ moveSay(w.m.out, fmt.Sprintf("Every box in %s has stopped %s. Run carlos move offline seal --host %s to copy it.", v.fromPlace(), host, host))
return
}
w.sayWaiting(r)
case provision.OfflineSealing:
- moveSay(w.m.out, fmt.Sprintf("Copying %s to %s.", host, v.To))
+ moveSay(w.m.out, fmt.Sprintf("Copying %s to %s.", host, v.toPlace()))
case provision.OfflineSealed:
if v.Next == "flip" {
- moveSay(w.m.out, fmt.Sprintf("Copied and checked. Run carlos move offline flip --host %s to start it in %s.", host, v.To))
+ moveSay(w.m.out, fmt.Sprintf("Copied and checked. Run carlos move offline flip --host %s to start it in %s.", host, v.toPlace()))
return
}
w.sayWaiting(r)
case provision.OfflineLanding:
- moveSay(w.m.out, moves.FlippedLine(v.From, v.To))
+ moveSay(w.m.out, moves.FlippedLine(v.fromPlace(), v.toPlace()))
case provision.OfflineLanded:
if v.Next == "open" {
- moveSay(w.m.out, fmt.Sprintf("%s holds everything %s needs. Nothing is served yet. Run carlos move offline open --host %s to serve it from %s.", v.To, host, host, v.To))
+ moveSay(w.m.out, fmt.Sprintf("%s holds everything %s needs. Nothing is served yet. Run carlos move offline open --host %s to serve it from %s.", v.toPlace(), host, host, v.toPlace()))
return
}
w.sayWaiting(r)
@@ -1473,10 +1481,10 @@ func (w *offlineRun) headline(r offlineReply) {
}
w.sayCleaning(v)
case provision.OfflineReverting:
- moveSay(w.m.out, fmt.Sprintf("Moving %s back to %s.", host, v.From))
+ moveSay(w.m.out, fmt.Sprintf("Moving %s back to %s.", host, v.fromPlace()))
w.sayCleaning(v)
if v.Next == "finish" {
- moveSay(w.m.out, fmt.Sprintf("Every box has put %s back in %s. Run carlos move offline finish --host %s to end the move.", host, v.From, host))
+ moveSay(w.m.out, fmt.Sprintf("Every box has put %s back in %s. Run carlos move offline finish --host %s to end the move.", host, v.fromPlace(), host))
}
}
}
@@ -1575,7 +1583,7 @@ func (w *offlineRun) runStage(ctx context.Context, to string) int {
if r.v.State != provision.OfflineStaging {
return w.stray(r)
}
- moveSay(w.m.out, fmt.Sprintf("Staging %s in %s. %s keeps serving while the data is copied.", host, r.v.To, host))
+ moveSay(w.m.out, fmt.Sprintf("Staging %s in %s. %s keeps serving while the data is copied.", host, r.v.toPlace(), host))
asked := r.v.StagedAt
return w.follow(ctx, r, func(r offlineReply) (int, bool) {
if r.v.State != provision.OfflineStaging {
@@ -1600,13 +1608,13 @@ func (w *offlineRun) runStart(ctx context.Context, to string) int {
return code
}
host := w.m.host
- moveSay(w.m.out, moves.MoveStartingLine(host, r.v.From, r.v.To))
+ moveSay(w.m.out, moves.MoveStartingLine(host, r.v.fromPlace(), r.v.toPlace()))
moveSay(w.m.out, fmt.Sprintf("%s is offline from now until the move opens or is aborted.", host))
return w.follow(ctx, r, func(r offlineReply) (int, bool) {
switch r.v.State {
case provision.OfflineStopping:
if r.v.Next == "seal" {
- moveSay(w.m.out, fmt.Sprintf("Every box in %s has stopped %s. Run carlos move offline seal --host %s to copy it.", r.v.From, host, host))
+ moveSay(w.m.out, fmt.Sprintf("Every box in %s has stopped %s. Run carlos move offline seal --host %s to copy it.", r.v.fromPlace(), host, host))
return moveExitDone, true
}
w.sayWaiting(r)
@@ -1622,7 +1630,7 @@ func (w *offlineRun) runSeal(ctx context.Context) int {
return code
}
host := w.m.host
- moveSay(w.m.out, fmt.Sprintf("Copying %s to %s.", host, r.v.To))
+ moveSay(w.m.out, fmt.Sprintf("Copying %s to %s.", host, r.v.toPlace()))
return w.follow(ctx, r, func(r offlineReply) (int, bool) {
switch r.v.State {
case provision.OfflineSealing, provision.OfflineSealed:
@@ -1631,7 +1639,7 @@ func (w *offlineRun) runSeal(ctx context.Context) int {
}
if r.v.State == provision.OfflineSealed {
if r.v.Next == "flip" {
- moveSay(w.m.out, fmt.Sprintf("Copied and checked. Run carlos move offline flip --host %s to start it in %s.", host, r.v.To))
+ moveSay(w.m.out, fmt.Sprintf("Copied and checked. Run carlos move offline flip --host %s to start it in %s.", host, r.v.toPlace()))
return moveExitDone, true
}
w.sayWaiting(r)
@@ -1648,7 +1656,7 @@ func (w *offlineRun) runFlip(ctx context.Context) int {
return code
}
host := w.m.host
- moveSay(w.m.out, moves.FlippedLine(r.v.From, r.v.To))
+ moveSay(w.m.out, moves.FlippedLine(r.v.fromPlace(), r.v.toPlace()))
return w.follow(ctx, r, func(r offlineReply) (int, bool) {
switch r.v.State {
case provision.OfflineLanding, provision.OfflineLanded:
@@ -1657,7 +1665,7 @@ func (w *offlineRun) runFlip(ctx context.Context) int {
}
if r.v.State == provision.OfflineLanded {
if r.v.Next == "open" {
- moveSay(w.m.out, fmt.Sprintf("%s holds everything %s needs. Nothing is served yet. Run carlos move offline open --host %s to serve it from %s.", r.v.To, host, host, r.v.To))
+ moveSay(w.m.out, fmt.Sprintf("%s holds everything %s needs. Nothing is served yet. Run carlos move offline open --host %s to serve it from %s.", r.v.toPlace(), host, host, r.v.toPlace()))
return moveExitDone, true
}
w.sayWaiting(r)
@@ -1761,11 +1769,11 @@ func (w *offlineRun) runAbort(ctx context.Context) int {
return w.abortStaged(ctx, r)
}
host := w.m.host
- moveSay(w.m.out, fmt.Sprintf("Moving %s back to %s.", host, r.v.From))
+ moveSay(w.m.out, fmt.Sprintf("Moving %s back to %s.", host, r.v.fromPlace()))
return w.follow(ctx, r, func(r offlineReply) (int, bool) {
if r.v.State == provision.OfflineReverting {
if r.v.Next == "finish" {
- moveSay(w.m.out, fmt.Sprintf("Every box has put %s back in %s. Run carlos move offline finish --host %s to end the move.", host, r.v.From, host))
+ moveSay(w.m.out, fmt.Sprintf("Every box has put %s back in %s. Run carlos move offline finish --host %s to end the move.", host, r.v.fromPlace(), host))
return moveExitRolled, true
}
w.sayCleaning(r.v)
@@ -1779,7 +1787,7 @@ func (w *offlineRun) runAbort(ctx context.Context) int {
// copy, every source box reports, and the operator runs finish.
func (w *offlineRun) abortStaged(ctx context.Context, r offlineReply) int {
host := w.m.host
- moveSay(w.m.out, fmt.Sprintf("Removing the staged copy of %s from %s.", host, r.v.To))
+ moveSay(w.m.out, fmt.Sprintf("Removing the staged copy of %s from %s.", host, r.v.toPlace()))
return w.follow(ctx, r, func(r offlineReply) (int, bool) {
if r.v.State == provision.OfflineReverting {
if r.v.Next == "finish" {
diff --git a/move_test.go b/move_test.go
index bff16ba4c..5cb4b6a81 100644
--- a/move_test.go
+++ b/move_test.go
@@ -20,6 +20,7 @@ import (
"net/http"
"net/http/httptest"
"os"
+ "regexp"
"strings"
"sync"
"testing"
@@ -1912,3 +1913,72 @@ func TestMoveOfflineAbortStaged(t *testing.T) {
t.Error("abort ran finish by itself")
}
}
+
+// TestMoveLinesNameRegionsByLabel: surface 25. Labels in every sentence,
+// the request still sends the code.
+func TestMoveLinesNameRegionsByLabel(t *testing.T) {
+ named := func(f frame) frame {
+ f["target_name"] = "London (uk)"
+ if d, ok := f["detail"].(frame); ok {
+ d["from_name"], d["to_name"] = "Dublin (ie)", "London (uk)"
+ }
+ return f
+ }
+ done := none(outcome(tMoveID, "done", 41.2))
+ done["detail"].(frame)["region"] = "uk"
+ c := &fakeMoveConsole{frames: []frame{
+ none(nil),
+ named(inFlight("preparing", nil, nil)),
+ named(inFlight("cutting", frame{"cut_phase": "stopping", "cut_budget_s": 45}, nil)),
+ named(inFlight("committed", frame{"cut_phase": "flipped"}, nil)),
+ done,
+ }}
+ code, out := runMoveAgainst(t, c, "--host", tHost, "--to", "uk")
+ if code != 0 {
+ t.Fatalf("exit %d:\n%s", code, out)
+ }
+ wantLines(t, out,
+ "Moving "+tHost+" from Dublin (ie) to London (uk).",
+ "London (uk) is ready. Starting the cut. "+tHost+" will be offline for about 45 seconds.",
+ "Stopped in Dublin (ie). Starting in London (uk).",
+ "Moved. "+tHost+" is served from London (uk). It was offline for 41 seconds.")
+ if m := c.mutations(); len(m) != 1 || m[0] != "POST "+tMovePth+` {"cut":"auto","region":"uk"}` {
+ t.Fatalf("the request must carry the code: %q", m)
+ }
+}
+
+// TestMoveOfflineLinesNameRegionsByLabel: surface 26, Review Focus 3.
+func TestMoveOfflineLinesNameRegionsByLabel(t *testing.T) {
+ named := func(f frame) frame { f["from_name"], f["to_name"] = "Dublin (ie)", "London (uk)"; return f }
+ c := &fakeOfflineConsole{gets: []frame{named(offView("offline-sealed", frame{"next": "flip"}))}}
+ if code, out := runOfflineAgainst(t, c, "status"); code != 0 || out != "Moving "+oHost+" from Dublin (ie) to London (uk).\n"+
+ "Copied and checked. Run carlos move offline flip --host "+oHost+" to start it in London (uk).\n" {
+ t.Fatalf("exit %d:\n%s", code, out)
+ }
+ // Staged, ready to start: the prose names the label, the command keeps
+ // the code an operator pastes.
+ c = &fakeOfflineConsole{gets: []frame{named(offView("offline-staging", frame{"next": "start"}))}}
+ _, out := runOfflineAgainst(t, c, "status")
+ wantLines(t, out,
+ "Staging "+oHost+" in London (uk). "+oHost+" keeps serving while the data is copied.",
+ oHost+" keeps serving. Run carlos move offline start --host "+oHost+" --to uk when you are ready to take it offline.")
+ // No bare code in prose, in any state: once the labels, the box name
+ // and --to's value are taken out, no "ie" or "uk" is left.
+ bare := regexp.MustCompile(`\b(ie|uk)\b`)
+ strip := strings.NewReplacer("Dublin (ie)", "", "London (uk)", "", "--to uk", "", "ie-box", "")
+ for _, state := range []string{"offline-stopping", "offline-sealing", "offline-landing", "offline-landed", "offline-reverting"} {
+ c = &fakeOfflineConsole{gets: []frame{named(offView(state, frame{"next": map[string]string{
+ "offline-stopping": "seal", "offline-landed": "open", "offline-reverting": "finish"}[state]}))}}
+ _, out := runOfflineAgainst(t, c, "status")
+ for _, line := range strings.Split(strings.TrimSpace(out), "\n") {
+ if m := bare.FindString(strip.Replace(line)); m != "" {
+ t.Errorf("%s: a bare code in prose: %q", state, line)
+ }
+ }
+ }
+ // An older console: today's bytes (TestMoveOfflineStatus's oStarting).
+ c = &fakeOfflineConsole{gets: []frame{offView("offline-sealed", frame{"next": "flip"})}}
+ if _, out := runOfflineAgainst(t, c, "status"); !strings.HasPrefix(out, oStarting+"\n"+oCopied+"\n") {
+ t.Fatalf("older console:\n%s", out)
+ }
+}
diff --git a/offline_move_e2e_test.go b/offline_move_e2e_test.go
index 5299341ab..b0b85ce36 100644
--- a/offline_move_e2e_test.go
+++ b/offline_move_e2e_test.go
@@ -30,6 +30,8 @@ type offlineE2E struct {
rel release.Store
run func(c context.Context, args ...string) (int, string)
put func(id, box, role, phase string, edit func(*moves.OfflineReport))
+ // srv is the real console, for a test that reads its region names.
+ srv *console.Server
}
func newOfflineE2E(t *testing.T, caps []string) *offlineE2E {
@@ -156,7 +158,7 @@ func newOfflineE2E(t *testing.T, caps []string) *offlineE2E {
}
}
- return &offlineE2E{host: host, rel: rel, run: run, put: put}
+ return &offlineE2E{host: host, rel: rel, run: run, put: put, srv: srv}
}
// TestMoveOfflineAgainstTheRealDoors drives `carlos move offline start` and
@@ -345,3 +347,39 @@ func TestMoveOfflineStageAgainstTheRealDoors(t *testing.T) {
t.Fatalf("after finish: %+v %+v", rec.Move, rec.LastMove)
}
}
+
+// TestMoveOfflineNamesRegionsThroughTheRealDoors (spec rev 5 §5 row 26;
+// Astra plan finding 4): with the real console's name map read, the CLI's
+// own sentence and the console's waiting sentence, which the CLI prints as
+// the console wrote it, both name the regions by label.
+func TestMoveOfflineNamesRegionsThroughTheRealDoors(t *testing.T) {
+ e := newOfflineE2E(t, []string{"region-ha-1", "offline-move-1"})
+ ctx := context.Background()
+ if !e.srv.LoadRegionNames(ctx) {
+ t.Fatal("the console did not read its region names")
+ }
+ ctxStart, cancel := context.WithTimeout(ctx, 30*time.Second)
+ defer cancel()
+ done := make(chan struct{})
+ go func() {
+ e.run(ctxStart, "start", "--to", "uk") // waits for the source box; stopped below
+ close(done)
+ }()
+ moved := false
+ for deadline := time.Now().Add(20 * time.Second); !moved && time.Now().Before(deadline); time.Sleep(10 * time.Millisecond) {
+ rec, err := provision.GetRecord(ctx, e.rel, release.OpsAccount, "shop", e.host)
+ moved = err == nil && rec.Move != nil
+ }
+ if !moved {
+ t.Fatal("start never moved the record")
+ }
+ code, out := e.run(ctx, "status")
+ if code != 0 {
+ t.Fatalf("status exit %d:\n%s", code, out)
+ }
+ wantLines(t, out,
+ "Moving "+e.host+" from Dublin (ie) to London (uk).",
+ "Waiting for ie-box in Dublin (ie) to confirm it has stopped "+e.host+". "+e.host+" is offline.")
+ cancel()
+ <-done
+}