branch review P2 and CI fixes
Astra whole-branch round 1: READY AFTER FIXES, census approved for every unit and envelope (findings committed unedited). Its P2: the CLI witness now runs the built binary through runSystem's dispatch and the operator's saved session against a fake console (path, bearer token, output, refusal exit). CI: the claim route census names the new status door; two browser updates tests that changed a record's kind in place now recreate the record as a service (an in-place write cannot change kind).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4 files changed,
+130
−2
docs/superpowers/notes/reviews/ASTRA-FINDINGS-nearest-region-a-branch-r1.md+26 −0internal/console/browserupdates_test.go+22 −2internal/console/testdata/claim-routes.txt+1 −0system_hostsused_test.go+81 −0
CI failed — run details
diff --git a/docs/superpowers/notes/reviews/ASTRA-FINDINGS-nearest-region-a-branch-r1.md b/docs/superpowers/notes/reviews/ASTRA-FINDINGS-nearest-region-a-branch-r1.md| new file mode 100644 |
| index 000000000..6dba71f51 |
| --- /dev/null |
| +++ b/docs/superpowers/notes/reviews/ASTRA-FINDINGS-nearest-region-a-branch-r1.md |
| @@ -0,0 +1,26 @@ |
| +No P1 findings. |
| + |
| +**P2 — Task 4: the CLI witness bypasses command execution.** |
| +[system_hostsused_test.go:12](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/nearest-region-a-review/system_hostsused_test.go:12) tests `systemVerb`, then calls the request and printing helpers directly with a fake getter. It never exercises `runSystem` or `runSystemHostsUsedVerb`. |
| + |
| +Removing the dispatch at [system.go:97](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/nearest-region-a-review/system.go:97), or breaking session wiring, would leave this witness passing while the command fails. |
| + |
| +**Fix:** invoke the real command against a local HTTP fixture using isolated operator credentials. Assert the GET path, bearer token, output and failure exit. For a subprocess, use `carlosTestEnv` and a scratch working directory. |
| + |
| +**Fault family:** entry-point witness coverage; brief check 4 requires the CLI witness to exercise the real entry point. |
| + |
| +**Census approvals** |
| + |
| +For commit `7eb8354c2d23523c545cb10f34255f57b7c2472a`: |
| + |
| +- **APPROVE — `system.go:runSystem`.** The [new dispatch](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/nearest-region-a-review/system.go:97) retains explicit operator invocation and leaves existing branches unchanged. No direct root read added. |
| +- **APPROVE — `system.go:systemVerb`.** The [verb addition](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/nearest-region-a-review/system.go:54) only selects dispatch; its recorded authority basis remains intact. |
| +- **APPROVE — envelope `.`.** The [new command](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/nearest-region-a-review/system_hostsused.go:79) uses existing session resolution and performs a GET to a fixed endpoint. Response decoding and formatting introduce no additional root authority. |
| +- **APPROVE — envelope `internal/console`.** The [marking helpers](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/nearest-region-a-review/internal/console/hostsused.go:93) preserve existing create checks and record destinations. The [status handler](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/nearest-region-a-review/internal/console/hostsused.go:204) uses `apiSystemRoller`, lists a fixed prefix and reads existing SQLite tables. Its [route registration](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/nearest-region-a-review/internal/console/authcli.go:1072) excludes every service role. No root trust boundary is widened. |
| +- **APPROVE — envelope `internal/provision`.** [History keys](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/nearest-region-a-review/internal/provision/hostsused.go:61) validate hostnames or use fixed metadata names. The [kind guard](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/nearest-region-a-review/internal/provision/record_sequence.go:163) checks supplied bytes without adding reads or weakening existing checks. |
| + |
| +`gofmt -l .` is clean. Targeted tests could not start because the read-only sandbox denied Go’s temporary build directory; builds, vet and executable census checks remain unverified. `git diff --check` reports whitespace in review Markdown. No files changed; `GOCACHE` remained unset. |
| + |
| +Fix the P2 without reopening this review, under the brief’s stopping rule. |
| + |
| +**READY AFTER FIXES** |
| \ No newline at end of file |
diff --git a/internal/console/browserupdates_test.go b/internal/console/browserupdates_test.go| index 336da6022..35781904a 100644 |
| --- a/internal/console/browserupdates_test.go |
| +++ b/internal/console/browserupdates_test.go |
| @@ -153,6 +153,26 @@ func (fx *pageFx) setRecordSettings(host string, edit func(*provision.Record)) { |
| } |
| } |
| +// recreateRecord replaces host's record with an edited copy created afresh, |
| +// for a fixture whose record must be born another kind: an in-place write |
| +// cannot change a record's kind (provision.ErrKindChange). |
| +func (fx *pageFx) recreateRecord(host string, edit func(*provision.Record)) { |
| + fx.t.Helper() |
| + ctx := context.Background() |
| + rec, _, err := provision.GetRecordETag(ctx, fx.rel, fx.sqid, "kass", host) |
| + if err != nil { |
| + fx.t.Fatal(err) |
| + } |
| + edit(rec) |
| + rec.RecordSeq = 0 |
| + if err := fx.rel.Delete(ctx, provision.RecordKey(fx.sqid, "kass", host)); err != nil { |
| + fx.t.Fatal(err) |
| + } |
| + if err := provision.CreateRecord(ctx, fx.rel, *rec); err != nil { |
| + fx.t.Fatal(err) |
| + } |
| +} |
| + |
| func (fx *pageFx) setRecordUpdates(host, updates string) { |
| fx.setRecordSettings(host, func(r *provision.Record) { r.Updates = updates }) |
| } |
| @@ -296,7 +316,7 @@ func TestUpdatesSectionForANamedUnit(t *testing.T) { |
| func TestUpdatesSectionForANamedUnitService(t *testing.T) { |
| fx := updatesPageFixture(t) |
| fx.grant("updates", "major", "pin") |
| - fx.setRecordSettings(heldHost, func(r *provision.Record) { r.Kind, r.Unit, r.Addr = "service", "console.service", "127.0.0.1:8080" }) |
| + fx.recreateRecord(heldHost, func(r *provision.Record) { r.Kind, r.Unit, r.Addr = "service", "console.service", "127.0.0.1:8080" }) |
| c := signInPaul(t, fx.consoleFixture) |
| code, body := fx.getPage(c, fx.u("/apps/kass/instances/"+heldHost)) |
| sec := updatesSection(body) |
| @@ -309,7 +329,7 @@ func TestUpdatesSectionForANamedUnitService(t *testing.T) { |
| // R12: a record of another kind shows no Updates section at all. |
| func TestUpdatesSectionIsAbsentForOtherKinds(t *testing.T) { |
| fx := updatesPageFixture(t) |
| - fx.setRecordSettings(heldHost, func(r *provision.Record) { r.Kind, r.Addr = "service", "127.0.0.1:8080" }) |
| + fx.recreateRecord(heldHost, func(r *provision.Record) { r.Kind, r.Addr = "service", "127.0.0.1:8080" }) |
| c := signInPaul(t, fx.consoleFixture) |
| code, body := fx.getPage(c, fx.u("/apps/kass/instances/"+heldHost)) |
| if code != http.StatusOK || updatesSection(body) != "" { |
diff --git a/internal/console/testdata/claim-routes.txt b/internal/console/testdata/claim-routes.txt| index 416a0401e..041f2515d 100644 |
| --- a/internal/console/testdata/claim-routes.txt |
| +++ b/internal/console/testdata/claim-routes.txt |
| @@ -95,6 +95,7 @@ route GET /api/cli/status/layout |
| route GET /api/cli/store/approvals |
| route GET /api/cli/system/antivirus |
| route GET /api/cli/system/geoip |
| +route GET /api/cli/system/hosts-used/status |
| route GET /api/cli/system/jobs/{id} |
| route GET /api/cli/system/layout |
| route GET /api/cli/system/pointer-digests |
diff --git a/system_hostsused_test.go b/system_hostsused_test.go| index e6fdb7a99..1a3610138 100644 |
| --- a/system_hostsused_test.go |
| +++ b/system_hostsused_test.go |
| @@ -4,6 +4,12 @@ import ( |
| "bytes" |
| "context" |
| "net/http" |
| + "net/http/httptest" |
| + "os" |
| + "os/exec" |
| + "path/filepath" |
| + "strings" |
| + "sync" |
| "testing" |
| ) |
| @@ -55,3 +61,78 @@ func TestSystemHostsUsedStatusCLI(t *testing.T) { |
| t.Fatal("a refusal was not an error") |
| } |
| } |
| + |
| +// TestSystemHostsUsedStatusThroughTheBinary (Astra branch review r1, P2): |
| +// the built command, through runSystem's dispatch and the operator's own |
| +// session, against a fake console. It asks the one door with the saved |
| +// token, prints the door's answer, and exits non-zero on a refusal. |
| +func TestSystemHostsUsedStatusThroughTheBinary(t *testing.T) { |
| + bin := buildCarlos(t) |
| + var mu sync.Mutex |
| + var asked []string |
| + refuse := false |
| + mux := http.NewServeMux() |
| + mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { |
| + mu.Lock() |
| + asked = append(asked, r.Method+" "+r.URL.Path+" "+r.Header.Get("Authorization")) |
| + no := refuse |
| + mu.Unlock() |
| + if r.Method != http.MethodGet || r.URL.Path != "/api/cli/system/hosts-used/status" { |
| + http.NotFound(w, r) |
| + return |
| + } |
| + if no { |
| + w.Header().Set("Content-Type", "application/json") |
| + w.WriteHeader(http.StatusNotFound) |
| + w.Write([]byte(`{"error":"404 page not found"}`)) |
| + return |
| + } |
| + w.Header().Set("Content-Type", "application/json") |
| + w.Write([]byte(`{"mode":"incomplete","marks":7,"inflight_creates":null,"pending_allocations":0,"pending_retirements":2,"unfinished_moves":null}`)) |
| + }) |
| + ts := httptest.NewServer(mux) |
| + t.Cleanup(ts.Close) |
| + credPath := filepath.Join(t.TempDir(), "credentials") |
| + creds := `{"version":1,"credentials":[{"console":"` + ts.URL + `","address":"paul@keymail.dev","token":"tok-operator"}]}` |
| + if err := os.WriteFile(credPath, []byte(creds), 0o600); err != nil { |
| + t.Fatal(err) |
| + } |
| + run := func() (string, error) { |
| + cmd := exec.Command(bin, "system", "hosts-used", "status") |
| + cmd.Env = carlosTestEnv(t, "CARLOS_CREDENTIALS="+credPath) |
| + cmd.Dir = t.TempDir() |
| + out, err := cmd.CombinedOutput() |
| + return string(out), err |
| + } |
| + out, err := run() |
| + if err != nil { |
| + t.Fatalf("status: %v\n%s", err, out) |
| + } |
| + for _, line := range []string{ |
| + "mode: incomplete. new hostnames are recorded, and a hostname that held data is not refused yet\n", |
| + "hostnames recorded: 7\n", |
| + "instance deletes still settling: 2\n", |
| + } { |
| + if !strings.Contains(out, line) { |
| + t.Fatalf("output lacks %q:\n%s", line, out) |
| + } |
| + } |
| + mu.Lock() |
| + door := 0 |
| + for _, a := range asked { |
| + if strings.HasPrefix(a, "GET /api/cli/system/hosts-used/status ") { |
| + door++ |
| + if a != "GET /api/cli/system/hosts-used/status Bearer tok-operator" { |
| + t.Errorf("the door was asked as %q, want the saved token", a) |
| + } |
| + } |
| + } |
| + refuse = true |
| + mu.Unlock() |
| + if door != 1 { |
| + t.Fatalf("the door was asked %d times (%v), want once", door, asked) |
| + } |
| + if out, err := run(); err == nil || !strings.Contains(out, "carlos system hosts-used status:") { |
| + t.Fatalf("a refused status exited %v:\n%s", err, out) |
| + } |
| +} |