nearest-region-b: whole-branch r2 READY AFTER FIXES, census APPROVE; the two P2s
The coverage refusal names the place from the snapshot it read (one edges read per refused create, with a counting witness), and the built carlos refuses a mixed plan with data before copying anything, with the identical-destination case through the same command.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4 files changed,
+198
−5
accounts_record_sequence_test.go+86 −0docs/superpowers/notes/reviews/ASTRA-FINDINGS-nearest-region-b-branch-r2.md+49 −0internal/console/hostsused.go+18 −5internal/console/hostsused_coverage_test.go+45 −0
CI passed — run details
diff --git a/accounts_record_sequence_test.go b/accounts_record_sequence_test.go| index a1696343a..f3b6634a8 100644 |
| --- a/accounts_record_sequence_test.go |
| +++ b/accounts_record_sequence_test.go |
| @@ -5,7 +5,9 @@ import ( |
| "context" |
| "errors" |
| "os" |
| + "os/exec" |
| "path/filepath" |
| + "regexp" |
| "strings" |
| "testing" |
| @@ -262,6 +264,90 @@ func TestMigrateFloorPrecedesTheRegistry(t *testing.T) { |
| } |
| } |
| +// TestMigrateCommandRefusesDataBeforeCopying (Astra branch r2, P2 2): the |
| +// built carlos, with a real destination account and a mixed plan (release |
| +// objects, a channel pointer, a static record and an instance that holds |
| +// data), refuses with S6 and copies nothing. With the instance's identical |
| +// copy already at the destination, the same command migrates the rest. |
| +func TestMigrateCommandRefusesDataBeforeCopying(t *testing.T) { |
| + tmp := t.TempDir() |
| + carlosBin := sharedCarlos(t) |
| + storeDir := filepath.Join(tmp, "store") |
| + regPath := filepath.Join(tmp, "registry.db") |
| + store := release.NewDirStore(storeDir) |
| + ctx := context.Background() |
| + seed, pubB64, err := release.GenerateKey() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + priv, err := release.ParseSigningKey(seed, "e2e") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + m := release.Manifest{Schema: 1, App: "demo", Version: "v1", Kind: "binary", |
| + Artifacts: map[string]release.Artifact{"linux-amd64": {File: "demo"}}} |
| + if err := release.Ship(ctx, store, release.OpsAccount, m, map[string][]byte{"linux-amd64": []byte("v1 bytes")}); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := release.Promote(ctx, store, priv, release.OpsAccount, "demo", "stable", "v1"); err != nil { |
| + t.Fatal(err) |
| + } |
| + dataKey := provision.RecordKey(release.OpsAccount, "demo", "shop.example.com") |
| + dataBody := []byte(`{"schema":1,"host":"shop.example.com","slug":"shop","app":"demo","account":"` + release.OpsAccount + `","channel":"stable","created_at":"2026-10-26T09:00:00Z"}`) |
| + for key, body := range map[string][]byte{ |
| + dataKey: dataBody, |
| + provision.RecordKey(release.OpsAccount, "demo", "site.example.com"): []byte(`{"schema":1,"host":"site.example.com","slug":"site","app":"demo","account":"` + release.OpsAccount + `","channel":"stable","kind":"static","created_at":"2026-10-26T09:00:00Z"}`), |
| + } { |
| + if _, err := store.Put(ctx, key, body, ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + env := carlosTestEnv(t, "CARLOS_DEPLOYMENT_DIR="+storeDir, "CARLOS_RELEASE_PUBKEY="+pubB64, |
| + "CARLOS_RELEASE_KEY="+seed, "HOME="+tmp, "CARLOS_CONSOLE=", "CARLOS_DESTINATION=") |
| + run := func(args ...string) (string, error) { |
| + t.Helper() |
| + cmd := exec.Command(carlosBin, args...) |
| + cmd.Env = env |
| + cmd.Dir = tmp |
| + out, err := cmd.CombinedOutput() |
| + return string(out), err |
| + } |
| + out, err := run("accounts", "create", "-registry", regPath, "-name", "kass", "-owner", "paul@keymail.dev") |
| + if err != nil { |
| + t.Fatalf("accounts create: %v\n%s", err, out) |
| + } |
| + sqid := regexp.MustCompile(`(?m)^\s*sqid:\s*(\S+)`).FindStringSubmatch(out)[1] |
| + dst := release.AppPrefix(sqid, "demo") |
| + for _, dry := range []bool{true, false} { |
| + args := []string{"accounts", "migrate", "-registry", regPath, "-app", "demo", "-to", sqid} |
| + if dry { |
| + args = append(args, "-dry-run") |
| + } |
| + out, err = run(args...) |
| + if err == nil || !strings.Contains(out, "shop.example.com: not migrated. carlos accounts migrate doesn't move an instance that holds data.") { |
| + t.Fatalf("migrate (dry run %v) of an app with data: %v\n%s", dry, err, out) |
| + } |
| + if keys, err := store.List(ctx, dst); err != nil || len(keys) != 0 { |
| + t.Fatalf("destination after the refusal = %v %v, want nothing copied", keys, err) |
| + } |
| + } |
| + // The instance's identical copy is already there: the rest migrates and |
| + // the instance is left as it is. |
| + destData := provision.RecordKey(sqid, "demo", "shop.example.com") |
| + if _, err := store.Put(ctx, destData, dataBody, ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + if out, err := run("accounts", "migrate", "-registry", regPath, "-app", "demo", "-to", sqid); err != nil { |
| + t.Fatalf("migrate with the instance already copied: %v\n%s", err, out) |
| + } |
| + if _, _, err := store.Get(ctx, provision.RecordKey(sqid, "demo", "site.example.com")); err != nil { |
| + t.Fatalf("the static record was not migrated: %v", err) |
| + } |
| + if got, _, err := store.Get(ctx, destData); err != nil || string(got) != string(dataBody) { |
| + t.Fatalf("the instance record changed: %s %v", got, err) |
| + } |
| +} |
| + |
| type orderStore struct { |
| release.Store |
| puts []string |
diff --git a/docs/superpowers/notes/reviews/ASTRA-FINDINGS-nearest-region-b-branch-r2.md b/docs/superpowers/notes/reviews/ASTRA-FINDINGS-nearest-region-b-branch-r2.md| new file mode 100644 |
| index 000000000..d076d3c0c |
| --- /dev/null |
| +++ b/docs/superpowers/notes/reviews/ASTRA-FINDINGS-nearest-region-b-branch-r2.md |
| @@ -0,0 +1,49 @@ |
| +- **R1 P1-1 — Resolved:** serve creates the lock directory and refuses every lock error; Windows refuses too. |
| +- **R1 P1-2 — Resolved:** migration never writes data-kind records, regardless of mode; identical destinations return without writing. |
| +- **R1 P1-3 — Resolved:** recorded fleets refuse additions/reactivations, and create writers check current target coverage. |
| +- **R1 P1-4 — Resolved:** placement refuses an unreadable history before registry access. |
| +- **R1 P1-5 — Resolved:** suffix parsing retains the reported auxiliary file’s possible owners; an activation-to-create witness covers it. |
| +- **R1 P2-6 — Resolved:** `roster` holds the serve lock. |
| +- **R1 P2-7 — Resolved:** subprocess tests exercise all offline verbs; seed/import requests exercise admission with lifetimes off and on. |
| +- **R1 P2-8 — Resolved:** status help describes the retained fields. |
| + |
| +No P1 found. Two P2s remain: |
| + |
| +1. **P2 — Coverage refusal exceeds the stated request budget.** Brief check 2. |
| + |
| + [hostsused.go:251](internal/console/hostsused.go:251) reads an edges snapshot. When it finds an unrecorded region target, [line 261](internal/console/hostsused.go:261) calls `candsOrHome` to format S4. That function reads another live snapshot at [regioncandidates.go:224](internal/console/regioncandidates.go:224). |
| + |
| + **Failure scenario:** a create in a region with a newly joined box performs two edges listings and two sets of edges GETs, plus liveness reads, before refusing. The promised one-snapshot budget therefore does not hold. |
| + |
| + **Fix:** derive the display name from the snapshot already read; add a counting-store witness for the refusal path. |
| + |
| + **Fault family:** history admission must stay within its declared request budget. |
| + |
| +2. **P2 — Migration command integration remains unwitnessed.** Task 10 r1 finding 4, **partly resolved**. |
| + |
| + The tests now exercise the shared copy helper, but [TestMigratePlanWithDataRefusesBeforeWriting](accounts_record_sequence_test.go:212) invokes `refuseDataRecords` directly. The subprocess witness at [line 248](accounts_record_sequence_test.go:248) stops at the floor check, before reaching either migration enforcement call. |
| + |
| + **Failure scenario:** removing the preflight at [accounts.go:374](accounts.go:374) would let an earlier pointer or static object copy before the later data record refuses. These tests would still pass. |
| + |
| + **Fix:** run an isolated CLI migration with a valid destination account and a mixed plan; assert S6 and no destination copies. Include identical-destination behavior through that command. |
| + |
| + **Fault family:** regression witnesses must exercise the production enforcement path. |
| + |
| +The coverage check uses activation’s same target-name helpers, including home region `""`, and refuses unreadable edges or fleet state. Fleet coverage performs `GetFleet` plus `ListFleetBoxes` through one registry handle. The merged born-HA path still reaches the history gate; I found no additional console path that activates a fleet box. |
| + |
| +Targeted tests could not start because the read-only sandbox blocked Go’s work directory. Changed Go files passed formatting inspection. No files changed, no subagents ran, and `GOCACHE` remained unset. Apply the P2 fixes without reopening the branch review, subject to the brief’s census/security checks. |
| + |
| +**READY AFTER FIXES** |
| + |
| +Census verdicts for `c8ef8d9eedd79e1a20daa472eb1511e47832b9a4`: |
| + |
| +- **APPROVE — `runAccountsMigrate`:** [accounts.go:341](accounts.go:341) adds a fixed-key floor read and restrictive migration checks. Existing registry authority remains unchanged; its recorded fingerprint matches. |
| +- **APPROVE — `.` envelope:** migration changes above and [system_hostsused.go:38](system_hostsused.go:38) introduce no new tenant-selected root input. |
| +- **APPROVE — `internal/layout` envelope:** [hostsused.go:33](internal/layout/hostsused.go:33) maps supplied names without filesystem access. |
| +- **APPROVE — `internal/provision` envelope:** [hostsused.go:157](internal/provision/hostsused.go:157) retains fixed control-key access; [hostsused_map.go:25](internal/provision/hostsused_map.go:25) is pure mapping. |
| +- **APPROVE — record-write overlay:** [nearest_region_b_census_test.go:35](internal/provision/nearest_region_b_census_test.go:35) layers on P1a. All 13 replacement fingerprints match, including the three create writers, placement, `beforeRecord`, and `refuseDataRecords`; their classifications remain appropriate. |
| +- **APPROVE — console authority site:** [hostsused.go:127](cmd/console/hostsused.go:127) opens the operator-selected listings file after acquiring the serve lock. No tenant request selects it. |
| + |
| +All three envelope hashes match the committed overlay. |
| + |
| +**APPROVE (all)** |
| \ No newline at end of file |
diff --git a/internal/console/hostsused.go b/internal/console/hostsused.go| index 7baf41f65..98da5834f 100644 |
| --- a/internal/console/hostsused.go |
| +++ b/internal/console/hostsused.go |
| @@ -11,6 +11,7 @@ import ( |
| "time" |
| "github.com/carlosframework/platform/internal/alerting" |
| + "github.com/carlosframework/platform/internal/geo" |
| "github.com/carlosframework/platform/internal/provision" |
| "github.com/carlosframework/platform/internal/registry" |
| "github.com/carlosframework/platform/internal/release" |
| @@ -220,8 +221,9 @@ func (s *Server) hostsTargetRefusal(ctx context.Context, region string) *doorRef |
| // since is refused at its own door (fleetGrowthRefusal); a box that joins |
| // a region does so from infra, so a create there is refused here until |
| // the history is completed again. Targets that cannot be read refuse (S5). |
| -// It reads the edges files, or the registry for a fleet, once per |
| -// data-kind create while the history is active. |
| +// It reads the edges files (one snapshot, which also names the place), or |
| +// the registry for a fleet, once per data-kind create while the history is |
| +// active. |
| func (s *Server) hostsCoverageRefusal(ctx context.Context, region string) *doorRefusal { |
| st, err := s.hostsState(ctx) |
| if err != nil || st.Mode != provision.HostsModeActive { |
| @@ -254,12 +256,10 @@ func (s *Server) hostsCoverageRefusal(ctx context.Context, region string) *doorR |
| return &doorRefusal{http.StatusServiceUnavailable, msgHostsInvalidated} |
| } |
| now, recorded = rosterRegions(snap)["region:"+region], st.RegionTargets |
| + place = snapshotPlaceName(snap, region, s.homeRegionOut(region)) |
| } |
| for _, t := range now { |
| if !slices.Contains(recorded, t) { |
| - if place == "" { |
| - place = s.placeOf(region, s.candsOrHome(ctx)) |
| - } |
| if place == "" { |
| place = "the home region" |
| } |
| @@ -270,6 +270,19 @@ func (s *Server) hostsCoverageRefusal(ctx context.Context, region string) *doorR |
| return nil |
| } |
| +// snapshotPlaceName is a region's place name from the snapshot already |
| +// read (placeOf's rule: the AWS region its boxes publish, else fallback), |
| +// so the refusal costs no second read. |
| +func snapshotPlaceName(snap edgesSnapshot, code, fallback string) string { |
| + regions := map[string]int{} |
| + for _, f := range snap.Files { |
| + if f.Placement == code && f.Region != "" { |
| + regions[f.Region]++ |
| + } |
| + } |
| + return geo.PlaceName(majority(code, regions), fallback) |
| +} |
| + |
| // gateDataCreate is every data-kind create's whole admission, at the one |
| // place each create writer passes before its mark (createRecordMarked, |
| // createSidecarMarked, the lifetime create): S5 (admitDataCreate), then S4 |
diff --git a/internal/console/hostsused_coverage_test.go b/internal/console/hostsused_coverage_test.go| index 13c0de844..6dc47d00e 100644 |
| --- a/internal/console/hostsused_coverage_test.go |
| +++ b/internal/console/hostsused_coverage_test.go |
| @@ -14,6 +14,7 @@ import ( |
| "github.com/carlosframework/platform/internal/provision" |
| "github.com/carlosframework/platform/internal/registry" |
| + "github.com/carlosframework/platform/internal/release" |
| ) |
| // activeAsNow makes the history active as activation would at this point: |
| @@ -206,3 +207,47 @@ func TestUnreadableEdgesRefuseCreates(t *testing.T) { |
| }) |
| } |
| } |
| + |
| +// edgesReadCounter counts the reads a check makes. |
| +type edgesReadCounter struct { |
| + release.Store |
| + lists, gets int |
| +} |
| + |
| +func (c *edgesReadCounter) List(ctx context.Context, prefix string) ([]string, error) { |
| + c.lists++ |
| + return c.Store.List(ctx, prefix) |
| +} |
| + |
| +func (c *edgesReadCounter) Get(ctx context.Context, key string) ([]byte, string, error) { |
| + c.gets++ |
| + return c.Store.Get(ctx, key) |
| +} |
| + |
| +// TestCoverageRefusalReadsOneSnapshot (Astra branch r2, P2 1): refusing a |
| +// create in a region whose targets grew costs one edges snapshot (one list, |
| +// a GET per edges file), and names the place as placeOf does. |
| +func TestCoverageRefusalReadsOneSnapshot(t *testing.T) { |
| + fx, _, _ := fillFixture(t, "uk") |
| + activeAsNow(t, fx.srv) |
| + st, err := fx.srv.hostsState(context.Background()) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + st.RegionTargets = []string{} |
| + forceHostsState(t, fx.srv, st) |
| + want := msgHostsTargetUnexamined(fx.srv.placeOf("uk", fx.srv.candsOrHome(context.Background()))) |
| + files, err := fx.srv.cfg.Releases.List(context.Background(), "control/edges/") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + counter := &edgesReadCounter{Store: fx.srv.cfg.Releases} |
| + fx.srv.cfg.Releases = counter |
| + ref := fx.srv.hostsCoverageRefusal(context.Background(), "uk") |
| + if ref == nil || ref.Msg != want { |
| + t.Fatalf("coverage refusal = %+v, want %q", ref, want) |
| + } |
| + if counter.lists != 1 || counter.gets > len(files) { |
| + t.Fatalf("reads = %d lists, %d gets, want 1 list and at most %d gets", counter.lists, counter.gets, len(files)) |
| + } |
| +} |