carlos / platform Public

instances list shows a box's config refusal as the REASON with its fix, on the caller's own row matched by host, from platform and own-fleet boxes, with a capped report (Task 9)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 652447492f8fc8ce47d44e9c907fee13b2e4347e parent 1b90be1
6 files changed, +444 −5
  • apimode.go +13 −0
  • approved_fleet_secrets_copy_test.go +2 −1
  • instances_cli.go +38 −2
  • instances_cli_refusals_test.go +57 −0
  • internal/console/apiinstances.go +103 −2
  • internal/console/instances_config_refusals_test.go +231 −0

Intent

Human

<task-notification> <task-id>ad048a943bd097b90</task-id> <tool-use-id>toolu_01NN61fGydyX9yrZH7NENGnd</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/2d812478-ae68-44f2-8075-b2330abd5939/tasks/ad048a943bd097b90.output</output-file> <status>completed</status> <summary>Agent "Implement Task 8: direct-bucket mode" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>Status: DONE Commit: 1b90be19. The hook printed a `packed-refs.lock` error, but `git log -1` shows the commit. Tests: - RED was a build failure, `undefined: directSealRefusal`. - The six new `TestDirectSecretsSet*` tests pass. - The seal guard, the `TestFleetSecretsCopy*` tests and the existing runSecretsSet tests pass (`TestSecretsSetSendsSealedTo`, `TestSecretsSetOnKeylessFleetNamesTheFleet`, `TestConfigE2EThroughConsole`). - Mutation: with the fingerprint comparison skipped, `TestDirectSecretsSetRefusesAnotherFleetsKey` fails. I reverted it. - Build, vet, gofmt and the darwin, windows and linux-arm64 builds are clean. - I ran the tests with the sandbox off and `TMPDIR=/tmp/g`, because TestMain refuses the sandbox temp directory. Concerns: - The FSK-C48 row contains a literal `&lt;app&gt;`. The refusal function keeps the brief's signature, so `runSecretsSet` fills in the app name at the call site. - The guard allowlist for `runSecretsSet` now allows `NewSealer` only. It no longer allows `Seal`. - The check lists and reads every fleet record under `accounts/`, which is slow on a very large bucket. - A fleet created between the check and the write is not caught. Report: /home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-secrets-key/.superpowers/sdd/2026-10-29-fleet-secrets-key/task-8-report.md</result> <usage><subagent_tokens>84472</subagent_tokens><tool_uses>24</tool_uses><duration_ms>246737</duration_ms></usage> </task-notification>

Human

<task-notification> <task-id>a63b3908f379169fd</task-id> <tool-use-id>toolu_01UGvAYZe5FmzdhU1KPUPHri</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/2d812478-ae68-44f2-8075-b2330abd5939/tasks/a63b3908f379169fd.output</output-file> <status>completed</status> <summary>Agent "Review Task 8 (spec + quality)" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>**Spec compliance:** ✅ Compliant. I couldn't confirm one thing from the diff: whether direct mode's new bucket reads (listing `accounts/` plus one read per fleet record) need a census or request-budget line. The ledger sends census changes to Task 11, so that's where to check. **Task quality:** Approved. **Critical:** none. **Important:** none. There are five Minor findings in the review file, for example a fleet record whose body is `null` reads cleanly as empty and passes. Review: /home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-secrets-key/.superpowers/sdd/2026-10-29-fleet-secrets-key/task-8-review.md</result> <usage><subagent_tokens>76327</subagent_tokens><tool_uses>17</tool_uses><duration_ms>165114</duration_ms></usage> </task-notification>

Attributed to this commit: 19.2 g CO₂e (2,455,198 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on design-fleet-secrets-key, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.

diff --git a/apimode.go b/apimode.go
index 97eb46ec9..eb8c8ca70 100644
--- a/apimode.go
+++ b/apimode.go
@@ -3435,6 +3435,19 @@ type apiInstanceRecord struct {
// older console and for a host no fresh box reports: the EGRESS column
// prints a dash.
Egress *apiEgress `json:"egress,omitempty"`
+ // ConfigRefusal is the box's config guard refusal of this host, and
+ // RefusalsCapped says a box this instance is on refused more hosts than
+ // it lists (the console's config_refusal and refusals_capped). Both are
+ // absent from an older console and for an instance no box refuses.
+ ConfigRefusal *apiConfigRefusal `json:"config_refusal,omitempty"`
+ RefusalsCapped bool `json:"refusals_capped,omitempty"`
+}
+
+// apiConfigRefusal mirrors the console's configRefusalView
+// (internal/console/apiinstances.go).
+type apiConfigRefusal struct {
+ Reason string `json:"reason"`
+ Count int `json:"count"`
}
// apiUpdatesJoin mirrors the console's updatesJoinView
diff --git a/approved_fleet_secrets_copy_test.go b/approved_fleet_secrets_copy_test.go
index 28f9c88a3..08113b2ec 100644
--- a/approved_fleet_secrets_copy_test.go
+++ b/approved_fleet_secrets_copy_test.go
@@ -56,7 +56,7 @@ var fleetSecretsCopyStatuses = []string{"pending", "approved", "struck"}
// task that writes a row's text adds its id here in the same commit, once the
// row is approved. Task 3 built the door, BYO page and fleet page rows; Task 4 the CLI rows;
// Task 5 sealKeyFor's refusals and the config door's; Task 6a the store and
-// email doors' keyless-fleet refusals; Task 6b the relay's; Task 7 the move refusal.
+// email doors' keyless-fleet refusals; Task 6b the relay's; Task 7 the move refusal; Task 9 the REASON cells.
var fleetSecretsCopyBuilt = []string{
"FSK-C01", "FSK-C02", "FSK-C03", "FSK-C04",
"FSK-C05", "FSK-C06", "FSK-C07", "FSK-C08",
@@ -70,6 +70,7 @@ var fleetSecretsCopyBuilt = []string{
"FSK-C37", "FSK-C38", "FSK-C39", "FSK-C40",
"FSK-C41", "FSK-C42", "FSK-C43", "FSK-C44",
"FSK-C45", "FSK-C46", "FSK-C47", "FSK-C48", "FSK-C49", "FSK-C50",
+ "FSK-C51", "FSK-C52", "FSK-C53", "FSK-C54", "FSK-C55",
}
func mustParseFleetSecretsRecord(t *testing.T) []copyRow {
diff --git a/instances_cli.go b/instances_cli.go
index 567b58f33..3f5ea5d8b 100644
--- a/instances_cli.go
+++ b/instances_cli.go
@@ -32,6 +32,7 @@ import (
"net/http"
"net/url"
"os"
+ "regexp"
"slices"
"strings"
@@ -648,9 +649,44 @@ func updatesReason(u *apiUpdatesJoin, settingsDefault bool) string {
return r
}
-// reasonCell is the REASON column: a rollout reason first (a failure hold
-// outranks a preference), else the settings reason.
+// configRefusalReason is the REASON cell for a box's config refusal of the
+// instance (fleet secrets key spec §5.7), or "" when there is none. A refusal
+// is why the instance is not running, so it leads. The reason word is the
+// box's, from a closed set; one that is not a plain word (a box a tenant runs
+// can write anything into its snapshot) prints as "unknown" rather than put
+// its bytes on a terminal.
+func configRefusalReason(r apiInstanceRecord) string {
+ if c := r.ConfigRefusal; c != nil {
+ switch c.Reason {
+ case "no_key":
+ return "config refused: the box has no secrets key. add the fleet's private key to the box's host.env as CARLOS_SECRETS_KEY, then run systemctl restart carlos-edge"
+ case "cannot_open":
+ return "config refused: the box cannot open this app's secrets. run carlos secrets fingerprint on the box and compare it with carlos fleets ls. if they differ, fix CARLOS_SECRETS_KEY in host.env and run systemctl restart carlos-edge. if they match, run carlos secrets set for the listed values and rotate any credential the console minted"
+ case "key_unparseable":
+ return "config refused: the box's CARLOS_SECRETS_KEY is not a valid secrets key. put the fleet's private key in host.env and run systemctl restart carlos-edge"
+ }
+ word := c.Reason
+ if !plainReasonWord.MatchString(word) {
+ word = "unknown"
+ }
+ return fmt.Sprintf("config refused: %s. run journalctl -u carlos-edge and check for config guard lines", word)
+ }
+ if r.RefusalsCapped {
+ return "this box refused more instances than it reports. run journalctl -u carlos-edge and check for config guard lines"
+ }
+ return ""
+}
+
+// plainReasonWord is what a config refusal's reason word may look like.
+var plainReasonWord = regexp.MustCompile(`^[a-z0-9_]{1,40}$`)
+
+// reasonCell is the REASON column: a config refusal first (it is why the
+// instance is not running), then a rollout reason (a failure hold outranks a
+// preference), else the settings reason.
func reasonCell(r apiInstanceRecord) string {
+ if s := configRefusalReason(r); s != "" {
+ return s
+ }
if s := rolloutReason(r.Rollout); s != "" {
return s
}
diff --git a/instances_cli_refusals_test.go b/instances_cli_refusals_test.go
new file mode 100644
index 000000000..b83c5691f
--- /dev/null
+++ b/instances_cli_refusals_test.go
@@ -0,0 +1,57 @@
+package main
+
+import (
+ "bytes"
+ "encoding/json"
+ "strings"
+ "testing"
+)
+
+// The REASON cell of a box's config refusal (fleet secrets key spec §5.7,
+// Task 9; copy FSK-C51 to FSK-C55). The records are decoded from the wire
+// the console writes, not built by hand.
+func TestReasonCellConfigRefusals(t *testing.T) {
+ const journal = "run journalctl -u carlos-edge and check for config guard lines"
+ for _, c := range []struct {
+ name, body, want string
+ }{
+ {"no_key", `{"host":"h","config_refusal":{"reason":"no_key","count":3}}`,
+ "config refused: the box has no secrets key. add the fleet's private key to the box's host.env as CARLOS_SECRETS_KEY, then run systemctl restart carlos-edge"},
+ {"cannot_open", `{"host":"h","config_refusal":{"reason":"cannot_open","count":1}}`,
+ "config refused: the box cannot open this app's secrets. run carlos secrets fingerprint on the box and compare it with carlos fleets ls. if they differ, fix CARLOS_SECRETS_KEY in host.env and run systemctl restart carlos-edge. if they match, run carlos secrets set for the listed values and rotate any credential the console minted"},
+ {"key_unparseable", `{"host":"h","config_refusal":{"reason":"key_unparseable"}}`,
+ "config refused: the box's CARLOS_SECRETS_KEY is not a valid secrets key. put the fleet's private key in host.env and run systemctl restart carlos-edge"},
+ {"another reason, by word", `{"host":"h","config_refusal":{"reason":"store_error"}}`,
+ "config refused: store_error. " + journal},
+ {"a reason that is not a word never reaches the terminal", "{\"host\":\"h\",\"config_refusal\":{\"reason\":\"x\\u001b[31m\"}}",
+ "config refused: unknown. " + journal},
+ {"capped", `{"host":"h","refusals_capped":true}`,
+ "this box refused more instances than it reports. " + journal},
+ {"a listed refusal outranks the capped report", `{"host":"h","refusals_capped":true,"config_refusal":{"reason":"store_error"}}`,
+ "config refused: store_error. " + journal},
+ {"a refusal outranks a rollout reason", `{"host":"h","config_refusal":{"reason":"store_error"},"rollout":{"installed":"v2","serving":"v1","awake":true,"held_by":"v2"}}`,
+ "config refused: store_error. " + journal},
+ {"no refusal", `{"host":"h"}`, ""},
+ } {
+ var r apiInstanceRecord
+ if err := json.Unmarshal([]byte(c.body), &r); err != nil {
+ t.Fatalf("%s: decode %s: %v", c.name, c.body, err)
+ }
+ if got := reasonCell(r); got != c.want {
+ t.Errorf("%s: reasonCell = %q, want %q", c.name, got, c.want)
+ }
+ }
+}
+
+// The refusal reaches the table: the list prints the cell on the row.
+func TestInstancesListPrintsTheRefusalReason(t *testing.T) {
+ var r apiInstanceRecord
+ if err := json.Unmarshal([]byte(`{"host":"a.example.com","config_refusal":{"reason":"no_key"}}`), &r); err != nil {
+ t.Fatal(err)
+ }
+ var out bytes.Buffer
+ printInstancesList(&out, []apiInstanceRecord{r})
+ if !strings.Contains(out.String(), "config refused: the box has no secrets key.") {
+ t.Fatalf("the list lacks the refusal:\n%s", out.String())
+ }
+}
diff --git a/internal/console/apiinstances.go b/internal/console/apiinstances.go
index 62197c5b8..4b09f39ce 100644
--- a/internal/console/apiinstances.go
+++ b/internal/console/apiinstances.go
@@ -212,6 +212,17 @@ type instanceListRecord struct {
// staleness and tenant rules as Rollout. It is named update_report
// because the embedded record already owns "updates" (its own setting).
UpdateReport *updatesJoinView `json:"update_report,omitempty"`
+ // ConfigRefusal is the config guard's refusal of this host as a box
+ // reports it (status.BoxMetrics.ConfigRefusals; fleet secrets key spec
+ // §5.7): why a box will not take the instance. A refusal names only a
+ // host, so it is set only here, on the caller's own row, matched by host
+ // (plan ruling R-3), and never from a box of a fleet the caller does not
+ // own. Absent when no fresh box reports one.
+ ConfigRefusal *configRefusalView `json:"config_refusal,omitempty"`
+ // RefusalsCapped is true when a box this row is on reported more refused
+ // hosts than its snapshot lists and this host is not among those listed:
+ // the refusal, if there is one, is out of sight (refusalFor).
+ RefusalsCapped bool `json:"refusals_capped,omitempty"`
// SettingsDefault says the record and the app's policy together ask for
// today's behaviour (provision.EffectiveUpdates(...).Default()), so the
// CLI can tell an instance on a box that ignores settings from one that
@@ -507,6 +518,82 @@ type boxJoin struct {
egress map[string]status.HostEgress
rollouts map[string]rolloutView
updates map[string]updatesJoinView
+ // refusals is each host's config refusal as the freshest box reporting
+ // one gave it. capped is the labels of the boxes whose refusal list was
+ // shorter than their total (status.BoxMetrics.ConfigRefusalsTotal), and
+ // cappedFleets the customer fleets of the account that has such a box.
+ refusals map[string]status.ConfigRefusal
+ capped map[string]bool
+ cappedFleets map[string]bool
+}
+
+// configRefusalView is one host's config refusal as a member sees it: the
+// box's closed reason word, when the stretch began and how many wakes or
+// admissions it refused. The box's Last and Host stay out: the host is the
+// row's own.
+type configRefusalView struct {
+ Reason string `json:"reason"`
+ Since time.Time `json:"since"`
+ Count int `json:"count"`
+}
+
+// foldRefusals adds box b's config refusals to the join. fleet names the
+// customer fleet b belongs to, "" for a platform box. A host two boxes both
+// refuse keeps the most recent refusal.
+func (j *boxJoin) foldRefusals(b status.Box, fleet string) {
+ m := b.Metrics
+ if j.refusals == nil {
+ j.refusals = map[string]status.ConfigRefusal{}
+ }
+ for _, r := range m.ConfigRefusals {
+ if had, ok := j.refusals[r.Host]; ok && had.Last.After(r.Last) {
+ continue
+ }
+ j.refusals[r.Host] = r
+ }
+ if m.ConfigRefusalsTotal > len(m.ConfigRefusals) {
+ if j.capped == nil {
+ j.capped = map[string]bool{}
+ j.cappedFleets = map[string]bool{}
+ }
+ j.capped[b.Label] = true
+ if fleet != "" {
+ j.cappedFleets[fleet] = true
+ }
+ }
+}
+
+// refusalFor is the join's config refusal for the caller's own row, matched
+// by host and by nothing else (R-3): a refusal names only a host, so a host
+// the caller has no row for is never shown. When the row has none listed,
+// capped says a box the row is on reported a longer list than it published.
+// A box is the row's when it reports the host (its rollout view, the edges
+// join's boxes), or, for a row nothing reports and placed on a fleet, when
+// that fleet has such a box: a refused instance is the one a box does not
+// report. ro is the row's tenant-checked rollout view.
+func (j boxJoin) refusalFor(rec provision.Record, ro *rolloutView, served []servedBy) (v *configRefusalView, capped bool) {
+ if r, ok := j.refusals[rec.Host]; ok {
+ return &configRefusalView{Reason: r.Reason, Since: r.Since, Count: r.Count}, false
+ }
+ if len(j.capped) == 0 {
+ return nil, false
+ }
+ if ro != nil && j.capped[ro.Box] {
+ return nil, true
+ }
+ for _, sb := range served {
+ if j.capped[sb.Box] {
+ return nil, true
+ }
+ }
+ if ro == nil {
+ for f := range recordFleets([]provision.Record{rec}) {
+ if j.cappedFleets[f] {
+ return nil, true
+ }
+ }
+ }
+ return nil, false
}
// updatesJoinView is one host's update report as a member sees it. account
@@ -777,7 +864,7 @@ func (s *Server) loadRolloutJoin(ctx context.Context, acct string, now time.Time
continue
}
complete = complete && (fleetComplete || !counts(f.Name))
- j.joinFleetRollouts(boxes, now)
+ j.joinFleet(f.Name, boxes, now)
}
return j, complete
}
@@ -854,6 +941,7 @@ func joinBoxes(boxes []status.Box, now time.Time) boxJoin {
}
j.foldRollout(b, true)
j.foldUpdates(b, true)
+ j.foldRefusals(b, "")
}
return j
}
@@ -965,12 +1053,22 @@ func (j *boxJoin) foldRollout(b status.Box, override bool) {
// columns are the platform join's, as before. Staleness is the platform's
// rule (status.BoxStale).
func (j *boxJoin) joinFleetRollouts(boxes []status.Box, now time.Time) {
+ j.joinFleet("", boxes, now)
+}
+
+// joinFleet is joinFleetRollouts for the boxes of the named customer fleet,
+// which is what lets a capped refusal list be pinned to its fleet. The
+// refusals are the fleet box's own word about hosts, folded by host, and
+// shown only on the rows of the account that owns the fleet (loadRolloutJoin
+// reads no other).
+func (j *boxJoin) joinFleet(fleet string, boxes []status.Box, now time.Time) {
for _, b := range boxes {
if b.Metrics == nil || status.BoxStale(b, now, status.SnapshotPeriod) {
continue
}
j.foldRollout(b, false)
j.foldUpdates(b, false)
+ j.foldRefusals(b, fleet)
}
}
@@ -1081,10 +1179,13 @@ func (s *Server) handleAPIInstanceList(w http.ResponseWriter, r *http.Request) {
if q.Health != "" && h != q.Health {
continue
}
+ ro := join.rollout(rec.Host, acct.Sqid, app)
+ refusal, refusalsCapped := join.refusalFor(rec, ro, served[rec.Host])
matched = append(matched, instanceListRecord{Record: rec,
+ ConfigRefusal: refusal, RefusalsCapped: refusalsCapped,
StagedVersion: join.versions[rec.Host], Health: h, Upstreams: join.upstreams[rec.Host],
ServedBy: served[rec.Host], Gated: rec.Gate != "", DBBytes: join.dbSize(rec.Host),
- Rollout: join.rollout(rec.Host, acct.Sqid, app),
+ Rollout: ro,
UpdateReport: join.update(rec.Host, acct.Sqid, app),
SettingsDefault: provision.EffectiveUpdates(rec, policy).Default(),
RegionName: regionlabel.ForRecord(rec, home, names).Text,
diff --git a/internal/console/instances_config_refusals_test.go b/internal/console/instances_config_refusals_test.go
new file mode 100644
index 000000000..624a7249e
--- /dev/null
+++ b/internal/console/instances_config_refusals_test.go
@@ -0,0 +1,231 @@
+package console
+
+import (
+ "context"
+ "encoding/json"
+ "fmt"
+ "strings"
+ "testing"
+ "time"
+
+ "github.com/carlosframework/platform/internal/provision"
+ "github.com/carlosframework/platform/internal/registry"
+ "github.com/carlosframework/platform/internal/release"
+ "github.com/carlosframework/platform/internal/status"
+)
+
+// Fleet secrets key spec §5.7, Task 9, plan ruling R-3: a box's config
+// refusals reach `instances list` as a config_refusal on the caller's own row,
+// matched by host, from platform boxes and from the account's own fleets'
+// boxes, and never as another tenant's.
+
+// refusalBoxStore is the store a box named fleet writes its snapshot to: the
+// platform's own for "", else the fleet's prefix.
+func refusalBoxStore(fx *consoleFixture, fleet string) release.Store {
+ if fleet == "" {
+ return fx.rel
+ }
+ return release.NewPrefixStore(fx.rel, "fleets/"+fleet+"/")
+}
+
+// writeRefusingBox writes a fresh snapshot for label under fleet ("" is a
+// platform box) that lists refusals and says total hosts are refused.
+func writeRefusingBox(t *testing.T, fx *consoleFixture, fleet, label string, refusals []status.ConfigRefusal, total int) {
+ t.Helper()
+ b := status.Box{GeneratedAt: time.Now(), Label: label,
+ Metrics: &status.BoxMetrics{Layout: &status.LayoutReport{Mode: "nested"}, RootfsReady: true,
+ Release: "v" + release.RootfsLifecycleFloor.String(), ConfigRefusals: refusals, ConfigRefusalsTotal: total}}
+ if err := status.WriteBox(context.Background(), refusalBoxStore(fx, fleet), b); err != nil {
+ t.Fatal(err)
+ }
+}
+
+// refusedAt is a refusal of host for reason.
+func refusedAt(host, reason string, count int) status.ConfigRefusal {
+ at := time.Now().Add(-time.Hour).UTC().Truncate(time.Second)
+ return status.ConfigRefusal{Host: host, Reason: reason, Since: at, Last: at.Add(time.Minute), Count: count}
+}
+
+// refusalRow is what a listed row says about the config guard.
+type refusalRow struct {
+ Refusal *struct {
+ Reason string `json:"reason"`
+ Since time.Time `json:"since"`
+ Count int `json:"count"`
+ Host string `json:"host"`
+ Last time.Time `json:"last"`
+ }
+ Capped bool
+ Raw string
+}
+
+// listedRefusals lists shop's instances through the list door and returns
+// each row's refusal state by host.
+func listedRefusals(t *testing.T, fx *consoleFixture, token string) map[string]refusalRow {
+ t.Helper()
+ rows := rootfsListedRows(t, fx, token)
+ out := map[string]refusalRow{}
+ for host, row := range rows {
+ var r refusalRow
+ r.Raw = string(row["config_refusal"])
+ if raw, ok := row["config_refusal"]; ok {
+ if err := json.Unmarshal(raw, &r.Refusal); err != nil {
+ t.Fatalf("%s config_refusal %s: %v", host, raw, err)
+ }
+ }
+ if raw, ok := row["refusals_capped"]; ok {
+ if err := json.Unmarshal(raw, &r.Capped); err != nil {
+ t.Fatalf("%s refusals_capped %s: %v", host, raw, err)
+ }
+ }
+ out[host] = r
+ }
+ return out
+}
+
+func TestInstanceListShowsFleetBoxRefusal(t *testing.T) {
+ fx, token := rootfsReadyFleetApp(t, "code-refusal-fleet", false)
+ createShops(t, fx, token, rootfsShopHost, rootfsSecondHost)
+ want := refusedAt(rootfsShopHost, "no_key", 4)
+ writeRefusingBox(t, fx, "home", "pi-1", []status.ConfigRefusal{want}, 1)
+
+ rows := listedRefusals(t, fx, token)
+ got := rows[rootfsShopHost]
+ if got.Refusal == nil || got.Refusal.Reason != "no_key" || got.Refusal.Count != 4 || !got.Refusal.Since.Equal(want.Since) {
+ t.Fatalf("%s config_refusal = %s, want no_key x4 since %v", rootfsShopHost, got.Raw, want.Since)
+ }
+ if got.Capped {
+ t.Errorf("%s says refusals_capped with a complete list", rootfsShopHost)
+ }
+ // The wire carries the reason, when it began and how often; the box's
+ // own host and last time stay behind.
+ if got.Refusal.Host != "" || !got.Refusal.Last.IsZero() {
+ t.Errorf("config_refusal leaks the box's fields: %s", got.Raw)
+ }
+ if other := rows[rootfsSecondHost]; other.Refusal != nil || other.Capped {
+ t.Errorf("%s, which no box refuses, carries %s capped=%v", rootfsSecondHost, other.Raw, other.Capped)
+ }
+}
+
+func TestInstanceListShowsPlatformBoxRefusal(t *testing.T) {
+ fx, token := rootfsReadyFleetApp(t, "code-refusal-platform", false)
+ createShops(t, fx, token, rootfsShopHost, rootfsSecondHost)
+ // An I2 miss can leave a fleet-key value on a platform instance (spec
+ // §5.7): the platform box refuses it with cannot_open.
+ writeRefusingBox(t, fx, "", "ie-1", []status.ConfigRefusal{refusedAt(rootfsSecondHost, "cannot_open", 2)}, 1)
+
+ rows := listedRefusals(t, fx, token)
+ if got := rows[rootfsSecondHost]; got.Refusal == nil || got.Refusal.Reason != "cannot_open" || got.Refusal.Count != 2 {
+ t.Fatalf("%s config_refusal = %s, want cannot_open x2", rootfsSecondHost, got.Raw)
+ }
+ if got := rows[rootfsShopHost]; got.Refusal != nil {
+ t.Errorf("%s carries %s: the refusal was for %s", rootfsShopHost, got.Raw, rootfsSecondHost)
+ }
+}
+
+// R-3: a refusal names only a host, so a refusal for a host the caller has no
+// row for is never shown, on this caller's rows or anywhere in the list. The
+// box that lists it is the caller's own fleet box (and a platform box), and
+// the host is another account's own instance of the same app name.
+func TestInstanceListNeverShowsAnotherTenantsRefusal(t *testing.T) {
+ const theirs = "theirs.example.com"
+ fx, token := rootfsReadyFleetApp(t, "code-refusal-tenant", false)
+ createShops(t, fx, token, rootfsShopHost, rootfsSecondHost)
+ if err := provision.CreateRecord(context.Background(), fx.rel, provision.Record{
+ Schema: 1, Host: theirs, Slug: "theirs", App: "shop", Account: "other",
+ Region: registry.PlacementTarget("home"), Channel: "stable", CreatedAt: time.Now().UTC(), CreatedBy: "x@example.com",
+ }); err != nil {
+ t.Fatal(err)
+ }
+ // Own box and a platform box both refuse the other account's host, and
+ // the caller's second host is refused so the join is known to read.
+ writeRefusingBox(t, fx, "home", "pi-1", []status.ConfigRefusal{
+ refusedAt(theirs, "cannot_open", 9), refusedAt(rootfsSecondHost, "no_key", 1)}, 2)
+ writeRefusingBox(t, fx, "", "ie-1", []status.ConfigRefusal{refusedAt(theirs, "no_key", 5)}, 1)
+
+ rows := listedRefusals(t, fx, token)
+ if got := rows[rootfsSecondHost]; got.Refusal == nil || got.Refusal.Reason != "no_key" {
+ t.Fatalf("the control %s = %s: the join did not read the box", rootfsSecondHost, got.Raw)
+ }
+ if got := rows[rootfsShopHost]; got.Refusal != nil || got.Capped {
+ t.Fatalf("%s carries another tenant's refusal %s capped=%v", rootfsShopHost, got.Raw, got.Capped)
+ }
+ if _, ok := rows[theirs]; ok {
+ t.Fatalf("the list names another account's host %s", theirs)
+ }
+ _, _, body := rawReq(t, "GET", instancesURL(fx, fx.sqid, "shop"), token, "")
+ if strings.Contains(body, theirs) || strings.Contains(body, `"cannot_open"`) {
+ t.Fatalf("the list body carries another tenant's refusal: %s", body)
+ }
+}
+
+// A fleet this account does not own is never read, whatever its box says
+// about this account's host.
+func TestInstanceListNeverReadsAnotherAccountsFleetRefusals(t *testing.T) {
+ fx, token := rootfsReadyFleetApp(t, "code-refusal-foreign", false)
+ createShops(t, fx, token, rootfsShopHost)
+ reg := openTestReg(t, fx)
+ t.Cleanup(func() { reg.Close() })
+ registerFleetBox(t, reg, "theirs", "theirs-1")
+ writeRefusingBox(t, fx, "theirs", "theirs-1", []status.ConfigRefusal{refusedAt(rootfsShopHost, "no_key", 1)}, 101)
+
+ if got := listedRefusals(t, fx, token)[rootfsShopHost]; got.Refusal != nil || got.Capped {
+ t.Fatalf("%s carries a foreign fleet box's refusal %s capped=%v", rootfsShopHost, got.Raw, got.Capped)
+ }
+}
+
+// A box publishes at most 100 refusals and their total beside them. Past the
+// cap a host with no listed refusal on that box reads as refused out of sight.
+func TestInstanceListShowsCappedReport(t *testing.T) {
+ fx, token := rootfsReadyFleetApp(t, "code-refusal-capped", false)
+ createShops(t, fx, token, rootfsShopHost, rootfsSecondHost)
+ var list []status.ConfigRefusal
+ for i := 0; i < 99; i++ {
+ list = append(list, refusedAt(fmt.Sprintf("n%d.other.example.net", i), "no_key", 1))
+ }
+ list = append(list, refusedAt(rootfsSecondHost, "no_key", 1)) // 100 listed
+ writeRefusingBox(t, fx, "home", "pi-1", list, 101)
+
+ rows := listedRefusals(t, fx, token)
+ if got := rows[rootfsShopHost]; got.Refusal != nil || !got.Capped {
+ t.Fatalf("%s = %s capped=%v, want refusals_capped and no refusal", rootfsShopHost, got.Raw, got.Capped)
+ }
+ if got := rows[rootfsSecondHost]; got.Refusal == nil || got.Capped {
+ t.Fatalf("%s = %s capped=%v, want its own refusal and no capped report", rootfsSecondHost, got.Raw, got.Capped)
+ }
+
+ // A list that is not cut says nothing: total equals what is listed.
+ writeRefusingBox(t, fx, "home", "pi-1", list, 100)
+ if got := listedRefusals(t, fx, token)[rootfsShopHost]; got.Capped {
+ t.Fatalf("%s says refusals_capped for a complete list", rootfsShopHost)
+ }
+}
+
+// The capped report is the row's box's: a capped box that is not the row's
+// (a platform box the row is not on) says nothing about it, and a row a box
+// does report is judged by that box.
+func TestInstanceListCappedReportIsTheRowsBoxs(t *testing.T) {
+ fx, token := rootfsReadyFleetApp(t, "code-refusal-capped-box", false)
+ createShops(t, fx, token, rootfsShopHost, rootfsSecondHost)
+ writeRefusingBox(t, fx, "", "ie-1", []status.ConfigRefusal{refusedAt("n.other.example.net", "no_key", 1)}, 101)
+ if got := listedRefusals(t, fx, token)[rootfsShopHost]; got.Capped {
+ t.Fatalf("a capped platform box the row is not on marked %s", rootfsShopHost)
+ }
+ // pi-1 reports shop's host in its rollout and is capped: its row.
+ b := status.Box{GeneratedAt: time.Now(), Label: "pi-1", Metrics: &status.BoxMetrics{
+ ConfigRefusalsTotal: 101, ConfigRefusals: []status.ConfigRefusal{refusedAt("n.other.example.net", "no_key", 1)},
+ Rollout: &status.RolloutReport{Hosts: map[string]status.HostRollout{
+ rootfsShopHost: {Account: fx.sqid, App: "shop", Installed: "r1", Awake: true}}}}}
+ if err := status.WriteBox(context.Background(), refusalBoxStore(fx, "home"), b); err != nil {
+ t.Fatal(err)
+ }
+ rows := listedRefusals(t, fx, token)
+ if !rows[rootfsShopHost].Capped {
+ t.Fatalf("%s is reported by the capped box pi-1 and is not marked", rootfsShopHost)
+ }
+ // Unreported by any box, on fleet home, which has a capped box: a refused
+ // instance is the one a box does not report, so it is marked too.
+ if !rows[rootfsSecondHost].Capped {
+ t.Fatalf("%s is unreported on a fleet with a capped box and is not marked", rootfsSecondHost)
+ }
+}