carlos / platform Public

code health: bring the branch back under the ratchet

runSystemUpdate's status read moves to systemUpdateStatus (one exit
site, same messages); the digest report types move from apimode.go to
channels_digests.go; the H6-M11 test no longer sleeps to a second
boundary. Records lowered where the code is now below them.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev ecb5397caf26f198e38eb474d99295310c5b872e parent 3859caf
5 files changed, +51 −39
  • .amadan/code-health.tsv +3 −3
  • apimode.go +0 −19
  • channels_digests.go +22 −0
  • internal/host/hunt_H6-M11_test.go +5 −6
  • system.go +21 −11
diff --git a/.amadan/code-health.tsv b/.amadan/code-health.tsv
index fece09da2..7a9e4a421 100644
--- a/.amadan/code-health.tsv
+++ b/.amadan/code-health.tsv
@@ -485,7 +485,7 @@ fatal . runSystemSeedsFloorPublish log.Fatalf 2
fatal . runSystemSeedsFloorPublish os.Exit 1
fatal . runSystemStatus log.Fatalf 3
fatal . runSystemUpdate log.Fatal 4 # raised: fdc912b (batch 2, #1123) landed before the ratchet; carlos system update now refuses unreadable answers
-fatal . runSystemUpdate log.Fatalf 7 # raised: fdc912b (batch 2, #1123) landed before the ratchet; carlos system update now refuses unreadable answers
+fatal . runSystemUpdate log.Fatalf 6 # raised: fdc912b (batch 2, #1123) landed before the ratchet; carlos system update now refuses unreadable answers
fatal . runUpdate log.Fatal 3
fatal . runUpdate log.Fatalf 5
fatal . runVersionTarget log.Fatal 7
@@ -2218,11 +2218,11 @@ func-lines internal/registry (*Registry).haJournal - 402 # raised: ha-departure-
func-lines internal/release PassFilter - 399
func-lines internal/release adoptHost - 494
func-lines internal/team TestFixture - 421
-file-lines . apimode.go - 4175
+file-lines . apimode.go - 4172
file-lines . apimode_test.go - 3530 # raised: fdc912b (batch 2, #1123) landed before the ratchet; tests for the system update refusals
file-lines internal/activator activator.go - 3785 # raised: the Service.ConfigBeforeWake field and doWakeOnce's one call to it (the body lives in configbeforewake.go); before it, #1290 step 2c
file-lines internal/activator activator_test.go - 5471
-file-lines internal/console server.go - 4210 # raised: domain transfers Task 6, Config.LookupNS, LookupDS and DNSServer (the brief puts them on Config) and the transfer engine clock seam on Server
+file-lines internal/console server.go - 4200 # raised: domain transfers Task 6, Config.LookupNS, LookupDS and DNSServer (the brief puts them on Config) and the transfer engine clock seam on Server
file-lines internal/host agent.go - 3209
file-lines internal/provision reconcile_test.go - 3094
file-lines internal/registry registry_test.go - 3261
diff --git a/apimode.go b/apimode.go
index 527ce5ea7..8f7810402 100644
--- a/apimode.go
+++ b/apimode.go
@@ -1713,25 +1713,6 @@ type apiDigestChannel struct {
Straggler bool `json:"straggler"`
}
-// apiDigestRepair is a channel whose head a fresh or replaced box would
-// refuse: Unbound (signed before the account binding) or NoRecord (no digest
-// and no promotion record to bind it).
-type apiDigestRepair struct {
- Account string `json:"account"`
- App string `json:"app"`
- Channel string `json:"channel"`
- Version string `json:"version"`
- Unbound bool `json:"unbound"`
- NoRecord bool `json:"no_record"`
-}
-type apiPointerDigests struct {
- Accounts []apiDigestAccount `json:"accounts"`
- Channels []apiDigestChannel `json:"channels"`
- // Repairs is nil when the console predates the listing, never empty
- // for that reason: an empty list is a clean answer.
- Repairs *[]apiDigestRepair `json:"repairs"`
-}
-
// pointerDigests reads the pointer-digest report (verb ""), or turns the
// marker on or off for the named accounts (every account when none) and
// reads the report back.
diff --git a/channels_digests.go b/channels_digests.go
index f7d6e2471..fd168fd65 100644
--- a/channels_digests.go
+++ b/channels_digests.go
@@ -51,6 +51,28 @@ const (
textRepairUnknown = "this console does not list repairs: upgrade it, or ask the bucket directly"
)
+// apiDigestRepair is a channel whose head a fresh or replaced box would
+// refuse: Unbound (signed before the account binding) or NoRecord (no digest
+// and no promotion record to bind it).
+type apiDigestRepair struct {
+ Account string `json:"account"`
+ App string `json:"app"`
+ Channel string `json:"channel"`
+ Version string `json:"version"`
+ Unbound bool `json:"unbound"`
+ NoRecord bool `json:"no_record"`
+}
+
+// apiPointerDigests is the pointer-digest report: the console's, or one
+// built from the bucket when no console session is in use.
+type apiPointerDigests struct {
+ Accounts []apiDigestAccount `json:"accounts"`
+ Channels []apiDigestChannel `json:"channels"`
+ // Repairs is nil when the console predates the listing, never empty
+ // for that reason: an empty list is a clean answer.
+ Repairs *[]apiDigestRepair `json:"repairs"`
+}
+
// repairCell is the repair a channel needs. A head can need both: the
// account first, since an unbound pointer is refused before its bytes are.
func repairCell(r apiDigestRepair) string {
diff --git a/internal/host/hunt_H6-M11_test.go b/internal/host/hunt_H6-M11_test.go
index 841f45b53..87c623d8e 100644
--- a/internal/host/hunt_H6-M11_test.go
+++ b/internal/host/hunt_H6-M11_test.go
@@ -55,9 +55,11 @@ func huntScriptCandidate(f *applyFixture, version string) {
// refused as a superseded promotion, by the agent and by root.
//
// Since fix round 1 the publisher cannot sign them in one second: B waits
-// past A's stamp (waitPastPromotedAt), which this test asserts as it starts
-// both inside one second. The box-side rule at an equal stamp (only the
-// admitted pointer itself) is TestSystemSeenAdmitsOnlyANewerStampOrTheAdmittedPointer's.
+// past A's stamp (waitPastSystemStamp), which this test asserts. The two
+// promotes run back to back, so they almost always ask in one second and B
+// waits; when they straddle a boundary B is later anyway, and the assertion
+// holds either way. The box-side rule at an equal stamp (only the admitted
+// pointer itself) is TestSystemSeenAdmitsOnlyANewerStampOrTheAdmittedPointer's.
func TestHunt_H6_M11_SameSecondSupersededPromotionIsRefused(t *testing.T) {
var (
f *applyFixture
@@ -66,9 +68,6 @@ func TestHunt_H6_M11_SameSecondSupersededPromotionIsRefused(t *testing.T) {
bodyA = []byte("#!/bin/sh\necho carlos v2\n")
bodyB = []byte("#!/bin/sh\necho carlos v3\n")
)
- // Start just after a second boundary so both promotes are asked for in it.
- now := time.Now()
- time.Sleep(time.Until(now.Truncate(time.Second).Add(time.Second + 5*time.Millisecond)))
f = newApplyFixture(t, "stable", "v1")
pA, savedA = huntPromoteRaw(t, f, "v2", bodyA)
pB, _ = huntPromoteRaw(t, f, "v3", bodyB)
diff --git a/system.go b/system.go
index 1b9b57cf6..c9ac3494c 100644
--- a/system.go
+++ b/system.go
@@ -404,19 +404,10 @@ func runSystemUpdate(args []string) {
ctx := context.Background()
// What this reaches, before it is done.
- st, body, err := sess.getJSON(ctx, "/api/cli/system/status")
+ cur, err := systemUpdateStatus(ctx, sess)
if err != nil {
log.Fatalf("carlos system update: %v", err)
}
- if st != http.StatusOK {
- log.Fatalf("carlos system update: %s", apiErrorFromBody(st, body))
- }
- var cur systemStatusResponse
- if err := json.Unmarshal(body, &cur); err != nil {
- // Read on, and the preview below would say "0 box(es) will roll"
- // about a promote that may reach every box.
- log.Fatalf("carlos system update: could not read the console's system status, so there is no telling which boxes this would reach; nothing was promoted (%v)", err)
- }
var reach []string
for _, b := range cur.Boxes {
if b.Channel == *channel {
@@ -481,7 +472,7 @@ func runSystemUpdate(args []string) {
}
in["upload"] = handle
}
- st, body, err = sess.postJSON(ctx, "/api/cli/system/update", in)
+ st, body, err := sess.postJSON(ctx, "/api/cli/system/update", in)
if err != nil {
log.Fatalf("carlos system update: %v", err)
}
@@ -509,6 +500,25 @@ func runSystemUpdate(args []string) {
colorFor(stdout).ok("promoted"), *channel, *channel)
}
+// systemUpdateStatus is the console's system status, read before `carlos
+// system update` promotes anything, so the preview can name the boxes it
+// reaches. A body that does not parse is an error: read on, and the preview
+// would say "0 box(es) will roll" about a promote that may reach every box.
+func systemUpdateStatus(ctx context.Context, sess *apiSession) (systemStatusResponse, error) {
+ var cur systemStatusResponse
+ st, body, err := sess.getJSON(ctx, "/api/cli/system/status")
+ if err != nil {
+ return cur, err
+ }
+ if st != http.StatusOK {
+ return cur, apiErrorFromBody(st, body)
+ }
+ if err := json.Unmarshal(body, &cur); err != nil {
+ return cur, fmt.Errorf("could not read the console's system status, so there is no telling which boxes this would reach; nothing was promoted (%v)", err)
+ }
+ return cur, nil
+}
+
// systemUpdateTarget is what `carlos system update` is about to promote:
// the tag, how the prompt names it, and whether the operator typed it. A
// typed --version is itself. An empty one is resolved through resolve (the