cli: a demo box's disk numbers in carlos status --live
Under a demo box's line: free bytes and inodes on /data and /run, the demo builds kept, a retention backlog with its start, and a line of its own once the backlog is more than 24 hours old. Other boxes print as before.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 files changed,
+97
−0
cli.go+36 −0statuslive_demodisk_test.go+61 −0
diff --git a/cli.go b/cli.go| index a3666090c..8194b6303 100644 |
| --- a/cli.go |
| +++ b/cli.go |
| @@ -4177,6 +4177,7 @@ func printLiveBoxesWith(w io.Writer, boxes []status.Box, now time.Time, places l |
| b.Label, orDash(liveRegion(b, places)), orDash(m.Release), orDash(m.Tunnel), |
| humanBytes(m.MemAvailBytes), humanBytes(m.MemTotalBytes), |
| humanFloat(m.Load1), humanBytes(m.DiskFreeBytes), alertsWord(m.Alerts), engineBeatWord(m.Alerts)) |
| + printDemoDisk(w, m.DemoDisk, now) |
| for _, r := range m.ReleaseRefusals { |
| if r.Kind == release.RefusalWrongProgram { |
| fmt.Fprintf(w, " refused %s %s since %s: wrong program (%s)\n", r.Host, r.Version, r.RefusedAt.UTC().Format(time.RFC3339), strings.TrimPrefix(r.Reason, "wrong program: ")) |
| @@ -4215,6 +4216,41 @@ func printLiveBoxesWith(w io.Writer, boxes []status.Box, now time.Time, places l |
| } |
| } |
| +// printDemoDisk is a demo box's disk numbers under its line (demo disk |
| +// bound, slice 1): the room on /data and /run, the demo builds root keeps, |
| +// and its retention backlog, with a line of its own once that is a day old. |
| +// Only what the box read; nothing at all for any other box. |
| +func printDemoDisk(w io.Writer, d *status.DemoDisk, now time.Time) { |
| + if d == nil { |
| + return |
| + } |
| + var rooms []string |
| + for _, fs := range []struct { |
| + name string |
| + room *status.FilesystemRoom |
| + }{{"/data", d.Data}, {"/run", d.Run}} { |
| + if fs.room != nil { |
| + free := fs.room.FreeBytes |
| + rooms = append(rooms, fmt.Sprintf("%s %s and %d inodes", fs.name, humanBytes(&free), fs.room.FreeInodes)) |
| + } |
| + } |
| + if len(rooms) > 0 { |
| + fmt.Fprintf(w, " free: %s\n", strings.Join(rooms, "; ")) |
| + } |
| + b := d.Builds |
| + if b == nil { |
| + return |
| + } |
| + held := b.OutputBytes |
| + fmt.Fprintf(w, " demo builds kept: %d (%s) as of %s\n", b.Outputs, humanBytes(&held), b.At.UTC().Format(time.RFC3339)) |
| + if b.Backlog > 0 { |
| + fmt.Fprintf(w, " demo builds over the limit: %d since %s; the next adopt pass tries again\n", b.Backlog, b.BacklogSince.UTC().Format(time.RFC3339)) |
| + if !b.BacklogSince.IsZero() && now.Sub(b.BacklogSince) > status.DemoBacklogStale { |
| + fmt.Fprintln(w, " demo build cleanup has been behind for over 24 hours: check the adopt pass log on this box") |
| + } |
| + } |
| +} |
| + |
| // alertsWord renders a box's alert-sink answer for the live listing. "not |
| // delivered" is spelled out because it is the state discussion #192 found |
| // silent for weeks: a box whose own disk, memory and cpu rules have nowhere |
diff --git a/statuslive_demodisk_test.go b/statuslive_demodisk_test.go| new file mode 100644 |
| index 000000000..1bd101742 |
| --- /dev/null |
| +++ b/statuslive_demodisk_test.go |
| @@ -0,0 +1,61 @@ |
| +package main |
| + |
| +import ( |
| + "bytes" |
| + "strings" |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/status" |
| +) |
| + |
| +// A demo box's disk numbers read as lines under the box: the room on /data |
| +// and /run in bytes and inodes, the demo builds kept, a backlog with its |
| +// start, and a line of its own once the backlog is a day old. A box without |
| +// them prints exactly what it did before. |
| +func TestPrintLiveBoxesShowsADemoBoxsDisk(t *testing.T) { |
| + now := time.Date(2026, 11, 30, 12, 0, 0, 0, time.UTC) |
| + box := func(d *status.DemoDisk) string { |
| + var buf bytes.Buffer |
| + printLiveBoxes(&buf, []status.Box{{GeneratedAt: now, Label: "demo-box", Metrics: &status.BoxMetrics{Tunnel: "connected", DemoDisk: d}}}, now) |
| + return buf.String() |
| + } |
| + plain := box(nil) |
| + if strings.Count(plain, "\n") != 1 { |
| + t.Fatalf("a box without demo disk numbers printed more than its line:\n%s", plain) |
| + } |
| + at := time.Date(2026, 11, 30, 11, 0, 0, 0, time.UTC) |
| + d := &status.DemoDisk{ |
| + Data: &status.FilesystemRoom{FreeBytes: 3 << 30, Bytes: 30 << 30, FreeInodes: 1200000, Inodes: 1900000}, |
| + Run: &status.FilesystemRoom{FreeBytes: 180 << 20, Bytes: 190 << 20, FreeInodes: 230000, Inodes: 237937}, |
| + Builds: &status.DemoBuilds{Outputs: 12, OutputBytes: 380 << 20, At: at}, |
| + } |
| + got := box(d) |
| + for _, want := range []string{ |
| + " free: /data 3.0GB and 1200000 inodes; /run 180.0MB and 230000 inodes\n", |
| + " demo builds kept: 12 (380.0MB) as of 2026-11-30T11:00:00Z\n", |
| + } { |
| + if !strings.Contains(got, want) { |
| + t.Fatalf("missing %q in:\n%s", want, got) |
| + } |
| + } |
| + if strings.Contains(got, "over the limit") { |
| + t.Fatalf("a backlog line with no backlog:\n%s", got) |
| + } |
| + d.Builds.Backlog, d.Builds.BacklogSince = 3, now.Add(-2*time.Hour) |
| + got = box(d) |
| + if want := " demo builds over the limit: 3 since 2026-11-30T10:00:00Z; the next adopt pass tries again\n"; !strings.Contains(got, want) { |
| + t.Fatalf("missing %q in:\n%s", want, got) |
| + } |
| + if strings.Contains(got, "24 hours") { |
| + t.Fatalf("a fresh backlog got the stale line:\n%s", got) |
| + } |
| + d.Builds.BacklogSince = now.Add(-25 * time.Hour) |
| + if want := " demo build cleanup has been behind for over 24 hours: check the adopt pass log on this box\n"; !strings.Contains(box(d), want) { |
| + t.Fatalf("missing %q in:\n%s", want, box(d)) |
| + } |
| + // Only what was read. |
| + if got := box(&status.DemoDisk{Run: d.Run}); !strings.Contains(got, " free: /run 180.0MB and 230000 inodes\n") || strings.Contains(got, "demo builds") { |
| + t.Fatalf("partial reading:\n%s", got) |
| + } |
| +} |