instances: RUNTIME and WORKERS columns, and the rootfs line on create; worker states cross only under the rollout view's tenant check (rootfs spec §5.4, §5.6; Plan 4 Task 6)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
apimode.go+20 −0approved_rootfs_copy_test.go+2 −0docs/superpowers/plans/2026-10-24-rootfs-apps-copy.md+8 −8instances_cli.go+6 −3instances_rollout_test.go+2 −1instances_rootfs.go+73 −0instances_rootfs_test.go+95 −0internal/console/apiinstances.go+32 −3internal/console/rootfs_test.go+195 −0rootfs_instances_e2e_test.go+192 −0
Intent
<task-notification> <task-id>a88030f36e8884cca</task-id> <tool-use-id>toolu_01XbarAqfsLABhnLff8tpuKQ</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/18ea9266-acea-4f37-abab-b97c6a7faffa/tasks/a88030f36e8884cca.output</output-file> <status>completed</status> <summary>Agent "Implement rootfs Plan 4 Task 4" 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>DONE Commit: 3ad0d014. The merge of `origin/main` was a no-op, already up to date at a9536235. Tests: the 3 new witnesses and the 2 existing place tests pass (`go test ./internal/console/`). The copy gate (`TestRootfsCopy|TestRootfsBuilt`) passes. Build, vet and gofmt are clean, and the darwin, windows and linux/arm64 builds pass. Each witness failed under its mutation, applied to `fleets.go` and then restored (verified identical). - **Same target:** returning early when the app is already on the target made `TestPlaceRootfsSameTargetIsRefused` fail with 200 instead of 409. - **Before the claim:** moving the `EstablishedKind` switch below the `HostClaim` block made `TestPlaceRootfsRefusesBeforeTheClaim` fail with 503. A first attempt that moved it only below the record and route checks still passed. I redid it to match the brief. - **Browser flash:** replacing `back("err", msg)` with `back("err", "")` in `handleAppPlace` made `TestPlaceRootfsBrowserFlash` fail with no C24 flash on the page. Concerns: none. `assertPlacement` is hardcoded to the app `titogo`, so the browser test checks unchanged state with `readPlaceState` and `equal`. The Go cache was read-only in the sandbox, so I ran the go commands with the sandbox disabled. The stale packed-refs lock error showed on fetch and commit, but the commit landed. The full report, with output tails, is in `.superpowers/sdd/2026-10-28-rootfs-apps-4-console/task-4-report.md`.</result> <usage><subagent_tokens>78950</subagent_tokens><tool_uses>14</tool_uses><duration_ms>267609</duration_ms></usage> </task-notification>
<task-notification> <task-id>bz9t488aw</task-id> <tool-use-id>toolu_01AeCRDRCFBRoGxMQgw2cRnu</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/18ea9266-acea-4f37-abab-b97c6a7faffa/tasks/bz9t488aw.output</output-file> <status>completed</status> <summary>Background command "Wait for the copy review result" completed (exit code 0)</summary> </task-notification>
Attributed to this commit: 7.89 g CO₂e (981,862 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on rootfs-apps-4-console, 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 7617e9acd..4b3f49744 100644 |
| --- a/apimode.go |
| +++ b/apimode.go |
| @@ -3331,6 +3331,13 @@ type apiInstanceRecord struct { |
| // STATIC record (#82's attach writes one) from a real instance — a |
| // static record is a static-deploy target, not an instance to adopt. |
| Kind string `json:"kind"` |
| + // Runtime and Hibernate are the record's runtime ("" binary, |
| + // "rootfs-v1") and its hibernation, fixed when the create door minted |
| + // it (rootfs spec §5.0). Hibernate is nil on a binary record and from an |
| + // older console; the RUNTIME column and create's rootfs line read both |
| + // (instances_rootfs.go). |
| + Runtime string `json:"runtime"` |
| + Hibernate *bool `json:"hibernate"` |
| // StagedVersion is the console's additive staged_version join (Task 8, |
| // issue #78): whichever version a box's adopt pass last reported for |
| // this host, via status/boxes/<label>.json. Fresh-ish for as long as |
| @@ -3457,6 +3464,19 @@ type apiRollout struct { |
| // rollout scheduler. When set the box reports no per-host state: awake |
| // and scheduler_idle are meaningless false. |
| Unavailable string `json:"unavailable,omitempty"` |
| + // Workers is a rootfs instance's workers as its box reports them, |
| + // sorted by name; absent for a binary instance, an asleep one, one that |
| + // declares none, and from an older console. The WORKERS column reads it. |
| + Workers []apiWorker `json:"workers,omitempty"` |
| +} |
| + |
| +// apiWorker mirrors the console's workerView: one worker's name, its |
| +// box's state word (running, restarting, crash-loop or stopped) and its |
| +// restarts since it was last declared. |
| +type apiWorker struct { |
| + Name string `json:"name"` |
| + State string `json:"state"` |
| + Restarts int `json:"restarts,omitempty"` |
| } |
| // apiUpstreamState mirrors status.UpstreamState's wire shape (internal/status) |
diff --git a/approved_rootfs_copy_test.go b/approved_rootfs_copy_test.go| index 2ae9784a4..8626c0622 100644 |
| --- a/approved_rootfs_copy_test.go |
| +++ b/approved_rootfs_copy_test.go |
| @@ -218,6 +218,8 @@ var rootfsCopyBuilt = []string{ |
| // Plan 4 Task 5: the first rootfs release of an app with binary |
| // instances (internal/console/rootfs.go) |
| "RFS-4-C11", |
| + // Plan 4 Task 6: RUNTIME and WORKERS, and the create line (instances_rootfs.go) |
| + "RFS-4-C12", "RFS-4-C13", "RFS-4-C14", "RFS-4-C15", "RFS-4-C16", "RFS-4-C17", "RFS-4-C18", "RFS-4-C19", |
| // Whole-branch review round 2: a placement with a box below the |
| // rootfs floor (internal/console/rootfs.go) |
| "RFS-4-C139", "RFS-4-C140", |
diff --git a/docs/superpowers/plans/2026-10-24-rootfs-apps-copy.md b/docs/superpowers/plans/2026-10-24-rootfs-apps-copy.md| index 9658e8c34..15915082f 100644 |
| --- a/docs/superpowers/plans/2026-10-24-rootfs-apps-copy.md |
| +++ b/docs/superpowers/plans/2026-10-24-rootfs-apps-copy.md |
| @@ -231,14 +231,14 @@ From the plan: Placeholders: `<app>` an app; `<fleet>` a fleet name; `<region>` |
| | id | file | text | status | |
| |---|---|---|---| |
| -| RFS-4-C12 | instances_rootfs.go, instances_cli.go | RUNTIME | approved | |
| -| RFS-4-C13 | instances_rootfs.go, instances_cli.go | WORKERS | approved | |
| -| RFS-4-C14 | instances_rootfs.go, instances_cli.go | binary | approved | |
| -| RFS-4-C15 | instances_rootfs.go, instances_cli.go | rootfs | approved | |
| -| RFS-4-C16 | instances_rootfs.go, instances_cli.go | rootfs, hibernates | approved | |
| -| RFS-4-C17 | instances_rootfs.go, instances_cli.go | <running>/<total>, <name> restarting | approved | |
| -| RFS-4-C18 | instances_rootfs.go, instances_cli.go | rootfs, always on. it starts as soon as its box picks it up, and does not wait for a request | approved | |
| -| RFS-4-C19 | instances_rootfs.go, instances_cli.go | rootfs, hibernates when idle | approved | |
| +| RFS-4-C12 | instances_rootfs.go | RUNTIME | approved | |
| +| RFS-4-C13 | instances_rootfs.go | WORKERS | approved | |
| +| RFS-4-C14 | instances_rootfs.go | binary | approved | |
| +| RFS-4-C15 | instances_rootfs.go | rootfs | approved | |
| +| RFS-4-C16 | instances_rootfs.go | rootfs, hibernates | approved | |
| +| RFS-4-C17 | instances_rootfs.go | <running>/<total>, <name> restarting | approved | |
| +| RFS-4-C18 | instances_rootfs.go | rootfs, always on. it starts as soon as its box picks it up, and does not wait for a request | approved | |
| +| RFS-4-C19 | instances_rootfs.go | rootfs, hibernates when idle | approved | |
| ### The sample app (examples/rails-shop) |
diff --git a/instances_cli.go b/instances_cli.go| index 9c1bbf6ce..a1bfcf210 100644 |
| --- a/instances_cli.go |
| +++ b/instances_cli.go |
| @@ -367,6 +367,9 @@ func runInstancesCreate(args []string) { |
| if rec.PrivateStoreBucket != "" { |
| mutedf(stdout, " private storage: bucket %s\n", rec.PrivateStoreBucket) |
| } |
| + if line := instanceRuntimeLine(rec); line != "" { |
| + mutedf(stdout, " %s", line) |
| + } |
| mutedf(stdout, " the host comes live on the next reconcile pass on its box") |
| } |
| @@ -666,7 +669,7 @@ func anyHeld(recs []apiInstanceRecord) bool { |
| // printInstancesList is `carlos instances list`'s table. |
| func printInstancesList(out io.Writer, recs []apiInstanceRecord) { |
| w := newTable(out) |
| - fmt.Fprintln(w, instancesListHeader+"\t"+"SEED") |
| + fmt.Fprintln(w, instancesListHeader+"\tSEED\t"+instancesColRuntime+"\t"+instancesColWorkers) |
| for _, r := range recs { |
| rowHealth := r.Health |
| if rowHealth == "" { |
| @@ -679,9 +682,9 @@ func printInstancesList(out io.Writer, recs []apiInstanceRecord) { |
| } |
| reason += er |
| } |
| - fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n", r.Host, instanceRegionCell(r), r.Channel, r.Pool, |
| + fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n", r.Host, instanceRegionCell(r), r.Channel, r.Pool, |
| installedCell(r), servingCell(r), rowHealth, upstreamsCell(r.Upstreams), humanBytes(r.DBBytes), |
| - egressCell(r.Egress), r.CreatedAt, r.CreatedBy, reason, seedCell(r)) |
| + egressCell(r.Egress), r.CreatedAt, r.CreatedBy, reason, seedCell(r), runtimeCell(r), workersCell(r)) |
| } |
| w.Flush() |
| } |
diff --git a/instances_rollout_test.go b/instances_rollout_test.go| index ab4fb7683..d444f554a 100644 |
| --- a/instances_rollout_test.go |
| +++ b/instances_rollout_test.go |
| @@ -5,6 +5,7 @@ import ( |
| "fmt" |
| "net/http" |
| "net/http/httptest" |
| + "reflect" |
| "strings" |
| "testing" |
| @@ -87,7 +88,7 @@ func TestRolloutWireShape(t *testing.T) { |
| t.Fatalf("instanceList: %v", err) |
| } |
| want := &apiRollout{Box: "b1", Installed: "v2", Serving: "v1", Good: "v1", Awake: true, HeldBy: "v2", Reason: "health", ConfigPending: true, SchedulerIdle: true} |
| - if len(recs) != 3 || recs[0].Rollout == nil || *recs[0].Rollout != *want { |
| + if len(recs) != 3 || recs[0].Rollout == nil || !reflect.DeepEqual(*recs[0].Rollout, *want) { |
| t.Fatalf("rollout decoded as %+v", recs) |
| } |
| if recs[1].Rollout == nil || recs[1].Rollout.Unavailable != "no-release-key" { |
diff --git a/instances_rootfs.go b/instances_rootfs.go| new file mode 100644 |
| index 000000000..c0b2b30d6 |
| --- /dev/null |
| +++ b/instances_rootfs.go |
| @@ -0,0 +1,73 @@ |
| +package main |
| + |
| +import ( |
| + "fmt" |
| + "slices" |
| + "strings" |
| +) |
| + |
| +// The RUNTIME and WORKERS columns of `carlos instances list`, and the line |
| +// `carlos instances create` prints for a rootfs instance (rootfs apps spec |
| +// §5.4, §5.6). Every word here is a row of the rootfs copy deck |
| +// (RFS-4-C12 to C19); the list appends the two columns after SEED, so each |
| +// column a script already reads stays where it was. |
| + |
| +const ( |
| + instancesColRuntime = "RUNTIME" // RFS-4-C12 |
| + instancesColWorkers = "WORKERS" // RFS-4-C13 |
| +) |
| + |
| +// runtimeCell is the RUNTIME column. A rootfs instance says rootfs, and |
| +// whether it hibernates; a static or service route has no runtime of its |
| +// own, and a runtime this client does not know is inert, so both show a |
| +// dash rather than claim binary. |
| +func runtimeCell(r apiInstanceRecord) string { |
| + switch { |
| + case r.Runtime == "rootfs-v1": |
| + if r.Hibernate != nil && *r.Hibernate { |
| + return "rootfs, hibernates" // RFS-4-C16 |
| + } |
| + return "rootfs" // RFS-4-C15 |
| + case r.Kind == "static" || r.Kind == "service", r.Runtime != "": |
| + return "-" |
| + } |
| + return "binary" // RFS-4-C14 |
| +} |
| + |
| +// workersCell is the WORKERS column: the workers running out of the ones |
| +// the box reports, and the first crash-looping one by name. A worker the |
| +// box has registered but not started yet reports restarting with no |
| +// restarts, so it counts as not running and is never named: only a worker |
| +// at the backoff's cap (crash-loop) is. A dash when the box reports none. |
| +func workersCell(r apiInstanceRecord) string { |
| + if r.Rollout == nil || len(r.Rollout.Workers) == 0 { |
| + return "-" |
| + } |
| + ws := slices.Clone(r.Rollout.Workers) |
| + slices.SortFunc(ws, func(a, b apiWorker) int { return strings.Compare(a.Name, b.Name) }) |
| + running, looping := 0, "" |
| + for _, w := range ws { |
| + switch { |
| + case w.State == "running": |
| + running++ |
| + case w.State == "crash-loop" && looping == "": |
| + looping = w.Name |
| + } |
| + } |
| + if looping != "" { |
| + return fmt.Sprintf("%d/%d, %s restarting", running, len(ws), looping) // RFS-4-C17 |
| + } |
| + return fmt.Sprintf("%d/%d", running, len(ws)) |
| +} |
| + |
| +// instanceRuntimeLine is what create says under "created instance" for a |
| +// rootfs instance: whether it is always on or hibernates. "" otherwise. |
| +func instanceRuntimeLine(rec apiInstanceRecord) string { |
| + if rec.Runtime != "rootfs-v1" { |
| + return "" |
| + } |
| + if rec.Hibernate != nil && *rec.Hibernate { |
| + return "rootfs, hibernates when idle" // RFS-4-C19 |
| + } |
| + return "rootfs, always on. it starts as soon as its box picks it up, and does not wait for a request" // RFS-4-C18 |
| +} |
diff --git a/instances_rootfs_test.go b/instances_rootfs_test.go| new file mode 100644 |
| index 000000000..603cb3cb2 |
| --- /dev/null |
| +++ b/instances_rootfs_test.go |
| @@ -0,0 +1,95 @@ |
| +package main |
| + |
| +import ( |
| + "bytes" |
| + "strings" |
| + "testing" |
| +) |
| + |
| +func TestRuntimeAndWorkersCells(t *testing.T) { |
| + yes, no := true, false |
| + for _, tc := range []struct { |
| + r apiInstanceRecord |
| + runtime, workers string |
| + }{ |
| + {apiInstanceRecord{}, "binary", "-"}, |
| + {apiInstanceRecord{Kind: "static"}, "-", "-"}, |
| + {apiInstanceRecord{Runtime: "rootfs-v2"}, "-", "-"}, |
| + {apiInstanceRecord{Runtime: "rootfs-v1", Hibernate: &no}, "rootfs", "-"}, |
| + {apiInstanceRecord{Runtime: "rootfs-v1", Hibernate: &yes}, "rootfs, hibernates", "-"}, |
| + {apiInstanceRecord{Runtime: "rootfs-v1", Hibernate: &no, Rollout: &apiRollout{Workers: []apiWorker{ |
| + {Name: "worker", State: "running"}, {Name: "mailer", State: "running"}}}}, "rootfs", "2/2"}, |
| + {apiInstanceRecord{Runtime: "rootfs-v1", Hibernate: &no, Rollout: &apiRollout{Workers: []apiWorker{ |
| + {Name: "worker", State: "restarting"}}}}, "rootfs", "0/1"}, |
| + {apiInstanceRecord{Runtime: "rootfs-v1", Hibernate: &no, Rollout: &apiRollout{Workers: []apiWorker{ |
| + {Name: "a", State: "running"}, {Name: "b", State: "restarting", Restarts: 3}}}}, "rootfs", "1/2"}, |
| + {apiInstanceRecord{Runtime: "rootfs-v1", Hibernate: &no, Rollout: &apiRollout{Workers: []apiWorker{ |
| + {Name: "worker", State: "crash-loop", Restarts: 9}, {Name: "mailer", State: "crash-loop", Restarts: 7}}}}, "rootfs", "0/2, mailer restarting"}, |
| + {apiInstanceRecord{Runtime: "rootfs-v1", Hibernate: &no, Rollout: &apiRollout{Workers: []apiWorker{ |
| + {Name: "worker", State: "running"}, {Name: "mailer", State: "crash-loop", Restarts: 7}}}}, "rootfs", "1/2, mailer restarting"}, |
| + } { |
| + if got := runtimeCell(tc.r); got != tc.runtime { |
| + t.Errorf("runtimeCell(%+v) = %q, want %q", tc.r, got, tc.runtime) |
| + } |
| + if got := workersCell(tc.r); got != tc.workers { |
| + t.Errorf("workersCell(%+v) = %q, want %q", tc.r, got, tc.workers) |
| + } |
| + } |
| +} |
| + |
| +func TestInstanceRuntimeLine(t *testing.T) { |
| + yes, no := true, false |
| + for _, tc := range []struct { |
| + r apiInstanceRecord |
| + want string |
| + }{ |
| + {apiInstanceRecord{Runtime: "rootfs-v1", Hibernate: &no}, "rootfs, always on. it starts as soon as its box picks it up, and does not wait for a request"}, |
| + {apiInstanceRecord{Runtime: "rootfs-v1"}, "rootfs, always on. it starts as soon as its box picks it up, and does not wait for a request"}, |
| + {apiInstanceRecord{Runtime: "rootfs-v1", Hibernate: &yes}, "rootfs, hibernates when idle"}, |
| + {apiInstanceRecord{}, ""}, |
| + {apiInstanceRecord{Kind: "static"}, ""}, |
| + } { |
| + if got := instanceRuntimeLine(tc.r); got != tc.want { |
| + t.Errorf("instanceRuntimeLine(%+v) = %q, want %q", tc.r, got, tc.want) |
| + } |
| + } |
| +} |
| + |
| +// The two columns are appended after SEED, so every column a script reads |
| +// stays where it was; the cells are read through the table's own padding. |
| +func TestInstancesListShowsRuntimeAndWorkers(t *testing.T) { |
| + no := false |
| + recs := []apiInstanceRecord{ |
| + {Host: "shop.example.com", Channel: "edge", Health: "running", Runtime: "rootfs-v1", Hibernate: &no, |
| + Rollout: &apiRollout{Box: "pi-1", Installed: "r1", Workers: []apiWorker{{Name: "worker", State: "running"}}}}, |
| + {Host: "bin.example.com", Channel: "edge", Health: "running"}, |
| + } |
| + var buf bytes.Buffer |
| + printInstancesList(&buf, recs) |
| + lines := strings.Split(strings.TrimRight(buf.String(), "\n"), "\n") |
| + if head := strings.Join(strings.Fields(lines[0]), "\t"); !strings.HasSuffix(head, "\tREASON\tSEED\tRUNTIME\tWORKERS") { |
| + t.Fatalf("heading = %q, want it to end SEED, RUNTIME, WORKERS", lines[0]) |
| + } |
| + from, to := strings.Index(lines[0], "RUNTIME"), strings.Index(lines[0], "WORKERS") |
| + for _, c := range []struct{ host, runtime, workers string }{ |
| + {"shop.example.com", "rootfs", "1/1"}, |
| + {"bin.example.com", "binary", "-"}, |
| + } { |
| + found := false |
| + for _, l := range lines[1:] { |
| + if !strings.HasPrefix(l, c.host+" ") { |
| + continue |
| + } |
| + found = true |
| + if got := strings.TrimSpace(l[from:to]); got != c.runtime { |
| + t.Errorf("%s RUNTIME = %q, want %q\n%s", c.host, got, c.runtime, buf.String()) |
| + } |
| + if got := strings.TrimSpace(l[to:]); got != c.workers { |
| + t.Errorf("%s WORKERS = %q, want %q\n%s", c.host, got, c.workers, buf.String()) |
| + } |
| + } |
| + if !found { |
| + t.Fatalf("no row for %s:\n%s", c.host, buf.String()) |
| + } |
| + } |
| +} |
diff --git a/internal/console/apiinstances.go b/internal/console/apiinstances.go| index bbba6063a..62197c5b8 100644 |
| --- a/internal/console/apiinstances.go |
| +++ b/internal/console/apiinstances.go |
| @@ -580,7 +580,12 @@ type rolloutView struct { |
| // one exception is a host a box that declined the flag reports held by |
| // the failure book it honours (Task 10), whose view also carries Good, |
| // the attempt, HeldBy and its epoch. |
| - Unavailable string `json:"unavailable,omitempty"` |
| + Unavailable string `json:"unavailable,omitempty"` |
| + // Workers is a rootfs instance's workers as its box reports them |
| + // (status.HostRollout.Workers, sorted by name). Copied only into a view |
| + // that carries the report's account and app, so rollout's tenant check |
| + // guards it; a refused view never has any. |
| + Workers []workerView `json:"workers,omitempty"` |
| account, app string |
| // heldEpoch is the box's epoch for HeldBy's restriction |
| // (status.HostRollout.HeldEpoch), and heldBook the failure book it |
| @@ -597,6 +602,26 @@ type rolloutView struct { |
| refused bool |
| } |
| +// workerView is one worker of a rootfs instance as a member sees it |
| +// (status.WorkerState): its name, the box's state word and its restarts. |
| +type workerView struct { |
| + Name string `json:"name"` |
| + State string `json:"state"` |
| + Restarts int `json:"restarts,omitempty"` |
| +} |
| + |
| +// workerViews copies a host's reported workers, nil for none. |
| +func workerViews(ws []status.WorkerState) []workerView { |
| + if len(ws) == 0 { |
| + return nil |
| + } |
| + out := make([]workerView, len(ws)) |
| + for i, w := range ws { |
| + out[i] = workerView{Name: w.Name, State: w.State, Restarts: w.Restarts} |
| + } |
| + return out |
| +} |
| + |
| // rollout is the join's answer for host, or nil unless the report is this |
| // account's and this app's: a report is the box's word about a route, and a |
| // route stamped to another app is not this record's (instanceHealth's rule). |
| @@ -895,7 +920,9 @@ func (j *boxJoin) foldRollout(b status.Box, override bool) { |
| // the flag but honours its failure book also reports the hosts the |
| // book holds (Task 10, plan review #5): those keep the code, and |
| // carry the hold and its epoch so a retry can be signed for them |
| - // (retryHostBuild), under the report's own account and app. |
| + // (retryHostBuild), under the report's own account and app. A |
| + // refused view has no account or app for rollout to check, so it |
| + // never carries workers; only the tenant-tagged views below do. |
| for host, v := range b.Metrics.RouteVersions { |
| if _, held := ro.Hosts[host]; held { |
| continue |
| @@ -904,7 +931,8 @@ func (j *boxJoin) foldRollout(b status.Box, override bool) { |
| } |
| for host, hr := range ro.Hosts { |
| put(host, rolloutView{Box: b.Label, Installed: hr.Installed, Good: hr.Good, Attempt: hr.Attempt, AttemptBuild: hr.AttemptBuild, |
| - HeldBy: hr.HeldBy, Reason: hr.Reason, Unavailable: ro.Unavailable, account: hr.Account, app: hr.App, heldEpoch: hr.HeldEpoch, heldBook: hr.HeldBook, retryV: hr.RetryV}) |
| + HeldBy: hr.HeldBy, Reason: hr.Reason, Unavailable: ro.Unavailable, Workers: workerViews(hr.Workers), |
| + account: hr.Account, app: hr.App, heldEpoch: hr.HeldEpoch, heldBook: hr.HeldBook, retryV: hr.RetryV}) |
| } |
| return |
| } |
| @@ -925,6 +953,7 @@ func (j *boxJoin) foldRollout(b status.Box, override bool) { |
| Box: b.Label, Installed: hr.Installed, Serving: hr.Serving, Good: hr.Good, Awake: hr.Awake, |
| Attempt: hr.Attempt, AttemptBuild: hr.AttemptBuild, HeldBy: hr.HeldBy, Reason: hr.Reason, |
| ConfigPending: hr.ConfigPending, Transient: hr.Transient, SchedulerIdle: a.Queued == 0 && a.Running == 0 && a.Settling == 0, |
| + Workers: workerViews(hr.Workers), |
| account: hr.Account, app: hr.App, heldEpoch: hr.HeldEpoch, heldBook: hr.HeldBook, retryV: hr.RetryV, |
| }) |
| } |
diff --git a/internal/console/rootfs_test.go b/internal/console/rootfs_test.go| index cfe2877d1..a3752f1d1 100644 |
| --- a/internal/console/rootfs_test.go |
| +++ b/internal/console/rootfs_test.go |
| @@ -1374,3 +1374,198 @@ func TestFirstRootfsShipRefusesOnAnAllocationThatDoesNotRead(t *testing.T) { |
| } |
| shopFirstShipLeftNothing(t, l.fx, "r1") |
| } |
| + |
| +// ---- Plan 4 Task 6: the list carries runtime and workers ---- |
| + |
| +// rootfsSecondHost is a second shop instance: the control row a tenant arm |
| +// checks its workers do arrive for, so an arm cannot pass on a list that |
| +// carries no workers at all. |
| +const rootfsSecondHost = "two.example.com" |
| + |
| +// writeFleetBoxReport writes a fresh, ready heartbeat for label on fleet, |
| +// on the rootfs floor, carrying ro as its rollout report. |
| +func writeFleetBoxReport(t *testing.T, fx *consoleFixture, fleet, label string, ro *status.RolloutReport) { |
| + 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(), Rollout: ro}} |
| + if err := status.WriteBox(context.Background(), release.NewPrefixStore(fx.rel, "fleets/"+fleet+"/"), b); err != nil { |
| + t.Fatal(err) |
| + } |
| +} |
| + |
| +// rootfsListedRows lists shop's instances through the list door: each |
| +// record's raw keys, by host. |
| +func rootfsListedRows(t *testing.T, fx *consoleFixture, token string) map[string]map[string]json.RawMessage { |
| + t.Helper() |
| + code, _, raw := rawReq(t, http.MethodGet, instancesURL(fx, fx.sqid, "shop"), token, "") |
| + if code != http.StatusOK { |
| + t.Fatalf("list = %d %s", code, raw) |
| + } |
| + var out struct { |
| + Instances []map[string]json.RawMessage `json:"instances"` |
| + } |
| + if err := json.Unmarshal([]byte(raw), &out); err != nil { |
| + t.Fatalf("list body %s: %v", raw, err) |
| + } |
| + rows := map[string]map[string]json.RawMessage{} |
| + for _, r := range out.Instances { |
| + var host string |
| + if err := json.Unmarshal(r["host"], &host); err != nil { |
| + t.Fatalf("row %v: %v", r, err) |
| + } |
| + rows[host] = r |
| + } |
| + return rows |
| +} |
| + |
| +// rootfsRowRollout is a listed row's rollout object's raw keys, nil when the |
| +// row has none. |
| +func rootfsRowRollout(t *testing.T, rows map[string]map[string]json.RawMessage, host string) map[string]json.RawMessage { |
| + t.Helper() |
| + row, ok := rows[host] |
| + if !ok { |
| + t.Fatalf("no listed row for %s in %v", host, rows) |
| + } |
| + raw, ok := row["rollout"] |
| + if !ok { |
| + return nil |
| + } |
| + var ro map[string]json.RawMessage |
| + if err := json.Unmarshal(raw, &ro); err != nil { |
| + t.Fatalf("%s rollout %s: %v", host, raw, err) |
| + } |
| + return ro |
| +} |
| + |
| +// createShops creates shop's instances hosts through the door. |
| +func createShops(t *testing.T, fx *consoleFixture, token string, hosts ...string) { |
| + t.Helper() |
| + for _, h := range hosts { |
| + if code, out := createShop(t, fx, token, `{"host":"`+h+`"}`); code != http.StatusCreated { |
| + t.Fatalf("create %s = %d %s", h, code, out) |
| + } |
| + } |
| +} |
| + |
| +const rootfsBothWorkers = `[{"name":"mailer","state":"running"},{"name":"worker","state":"restarting"}]` |
| + |
| +func TestInstanceListCarriesRuntimeAndWorkers(t *testing.T) { |
| + fx, token := rootfsReadyFleetApp(t, "code-rfs-list-workers", false) |
| + createShops(t, fx, token, rootfsShopHost) |
| + writeFleetBoxReport(t, fx, "home", "pi-1", &status.RolloutReport{Hosts: map[string]status.HostRollout{ |
| + rootfsShopHost: {Account: fx.sqid, App: "shop", Installed: "r1", Awake: true, Workers: []status.WorkerState{ |
| + {Name: "mailer", State: "running"}, {Name: "worker", State: "restarting", Restarts: 0}}}, |
| + }}) |
| + rows := rootfsListedRows(t, fx, token) |
| + row := rows[rootfsShopHost] |
| + if got := string(row["runtime"]); got != `"rootfs-v1"` { |
| + t.Errorf("runtime = %s, want \"rootfs-v1\"", got) |
| + } |
| + if got := string(row["hibernate"]); got != `false` { |
| + t.Errorf("hibernate = %s, want false", got) |
| + } |
| + ro := rootfsRowRollout(t, rows, rootfsShopHost) |
| + if ro == nil { |
| + t.Fatalf("no rollout on %s: %v", rootfsShopHost, row) |
| + } |
| + if got := string(ro["workers"]); got != rootfsBothWorkers { |
| + t.Fatalf("rollout.workers = %s, want %s", got, rootfsBothWorkers) |
| + } |
| +} |
| + |
| +// Review Focus 4 [pf 4.18]: a worker report crosses into this app's list |
| +// only under the rollout view's tenant check. Every arm also has the control |
| +// host two.example.com, reported for this account and app with a worker, so |
| +// each arm proves the workers do reach the list where they belong. |
| +func TestInstanceListWorkersStayInTheirTenant(t *testing.T) { |
| + control := func(fx *consoleFixture) status.HostRollout { |
| + return status.HostRollout{Account: fx.sqid, App: "shop", Installed: "r1", Awake: true, |
| + Workers: []status.WorkerState{{Name: "worker", State: "running"}}} |
| + } |
| + const controlWorkers = `[{"name":"worker","state":"running"}]` |
| + hostile := []status.WorkerState{{Name: "mailer", State: "running"}, {Name: "worker", State: "running"}} |
| + checkControl := func(t *testing.T, rows map[string]map[string]json.RawMessage) { |
| + t.Helper() |
| + ro := rootfsRowRollout(t, rows, rootfsSecondHost) |
| + if ro == nil || string(ro["workers"]) != controlWorkers { |
| + t.Fatalf("control %s rollout = %s, want workers %s", rootfsSecondHost, rows[rootfsSecondHost]["rollout"], controlWorkers) |
| + } |
| + } |
| + noRollout := func(t *testing.T, rows map[string]map[string]json.RawMessage) { |
| + t.Helper() |
| + if ro := rootfsRowRollout(t, rows, rootfsShopHost); ro != nil { |
| + t.Fatalf("%s carries another tenant's rollout: %s", rootfsShopHost, rows[rootfsShopHost]["rollout"]) |
| + } |
| + } |
| + |
| + // (i) This account's own fleet box tags this host with another app, or |
| + // another account: not this record's report. |
| + for _, c := range []struct{ name, code, acct, app string }{ |
| + {"another app", "code-rfs-tenant-app", "", "other"}, |
| + {"another account", "code-rfs-tenant-acct", "zzz", "shop"}, |
| + } { |
| + t.Run("tags/"+c.name, func(t *testing.T) { |
| + fx, token := rootfsReadyFleetApp(t, c.code, false) |
| + createShops(t, fx, token, rootfsShopHost, rootfsSecondHost) |
| + acct := c.acct |
| + if acct == "" { |
| + acct = fx.sqid |
| + } |
| + writeFleetBoxReport(t, fx, "home", "pi-1", &status.RolloutReport{Hosts: map[string]status.HostRollout{ |
| + rootfsShopHost: {Account: acct, App: c.app, Installed: "r1", Awake: true, Workers: hostile}, |
| + rootfsSecondHost: control(fx), |
| + }}) |
| + rows := rootfsListedRows(t, fx, token) |
| + noRollout(t, rows) |
| + checkControl(t, rows) |
| + }) |
| + } |
| + |
| + // (ii) Another account's fleet has a fresh box whose report tags this |
| + // host with this account and app: a fleet this account does not own is |
| + // never read, whatever its reports say. |
| + t.Run("foreign fleet", func(t *testing.T) { |
| + fx, token := rootfsReadyFleetApp(t, "code-rfs-tenant-fleet", false) |
| + createShops(t, fx, token, rootfsShopHost, rootfsSecondHost) |
| + reg := openTestReg(t, fx) |
| + t.Cleanup(func() { reg.Close() }) |
| + registerFleetBox(t, reg, "theirs", "theirs-1") |
| + writeFleetBoxReport(t, fx, "theirs", "theirs-1", &status.RolloutReport{Hosts: map[string]status.HostRollout{ |
| + rootfsShopHost: {Account: fx.sqid, App: "shop", Installed: "r1", Awake: true, Workers: hostile}, |
| + }}) |
| + writeFleetBoxReport(t, fx, "home", "pi-1", &status.RolloutReport{Hosts: map[string]status.HostRollout{ |
| + rootfsSecondHost: control(fx), |
| + }}) |
| + rows := rootfsListedRows(t, fx, token) |
| + noRollout(t, rows) |
| + checkControl(t, rows) |
| + }) |
| + |
| + // (iii) This account's fleet box cannot arm its scheduler: the hosts it |
| + // serves get the refused view, which has no tenant to check, so it never |
| + // carries workers; the held host it reports keeps its tenant-tagged view |
| + // and its workers. |
| + t.Run("refused view", func(t *testing.T) { |
| + fx, token := rootfsReadyFleetApp(t, "code-rfs-tenant-refused", false) |
| + createShops(t, fx, token, rootfsShopHost, rootfsSecondHost) |
| + b := status.Box{GeneratedAt: time.Now(), Label: "pi-1", |
| + Metrics: &status.BoxMetrics{Layout: &status.LayoutReport{Mode: "nested"}, RootfsReady: true, |
| + Release: "v" + release.RootfsLifecycleFloor.String(), |
| + RouteVersions: map[string]string{rootfsShopHost: "r1", rootfsSecondHost: "r1"}, |
| + Rollout: &status.RolloutReport{Unavailable: "no-cgroup-delegation", FailureBook: "honoured", |
| + Hosts: map[string]status.HostRollout{rootfsSecondHost: control(fx)}}}} |
| + if err := status.WriteBox(context.Background(), release.NewPrefixStore(fx.rel, "fleets/home/"), b); err != nil { |
| + t.Fatal(err) |
| + } |
| + rows := rootfsListedRows(t, fx, token) |
| + ro := rootfsRowRollout(t, rows, rootfsShopHost) |
| + if ro == nil || string(ro["unavailable"]) != `"no-cgroup-delegation"` || string(ro["box"]) != `"pi-1"` { |
| + t.Fatalf("%s rollout = %s, want the refused view from pi-1", rootfsShopHost, rows[rootfsShopHost]["rollout"]) |
| + } |
| + if w, ok := ro["workers"]; ok { |
| + t.Fatalf("the refused view of %s carries workers %s", rootfsShopHost, w) |
| + } |
| + checkControl(t, rows) |
| + }) |
| +} |
diff --git a/rootfs_instances_e2e_test.go b/rootfs_instances_e2e_test.go| new file mode 100644 |
| index 000000000..af62503ed |
| --- /dev/null |
| +++ b/rootfs_instances_e2e_test.go |
| @@ -0,0 +1,192 @@ |
| +// End-to-end acceptance for rootfs apps Plan 4 Task 6: `carlos instances |
| +// create` says a rootfs instance is always on, and `carlos instances list` |
| +// shows its RUNTIME and WORKERS, through a real console with `carlos auth |
| +// login` alone. TestE2EInstancesThroughConsole's shape, but a rootfs create |
| +// needs a fleet in the registry, so this test registers its box there and |
| +// does not guard against registry use [pf 4.23]. |
| +package main |
| + |
| +import ( |
| + "context" |
| + "net/http" |
| + "net/http/httptest" |
| + "path/filepath" |
| + "strings" |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/console" |
| + "github.com/carlosframework/platform/internal/provision" |
| + "github.com/carlosframework/platform/internal/registry" |
| + "github.com/carlosframework/platform/internal/release" |
| + "github.com/carlosframework/platform/internal/status" |
| +) |
| + |
| +func TestE2ERootfsInstanceThroughConsole(t *testing.T) { |
| + useTempCredentials(t) |
| + clearDeploymentEnv(t) |
| + |
| + tmp := t.TempDir() |
| + relStore := release.NewDirStore(filepath.Join(tmp, "store")) |
| + seed, pubB64, err := release.GenerateKey() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + priv, err := release.ParseSigningKey(seed, "e2e") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + pub, err := release.ParsePublicKey(pubB64, "e2e") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + cst, err := console.Open(filepath.Join(tmp, "console.db")) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + t.Cleanup(func() { cst.Close() }) |
| + |
| + regPath := filepath.Join(tmp, "registry.db") |
| + var srv *console.Server |
| + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| + srv.ServeHTTP(w, r) |
| + })) |
| + t.Cleanup(ts.Close) |
| + srv, err = console.NewServer(console.Config{ |
| + Origin: ts.URL, |
| + Keymail: "http://keymail.invalid", // never dialled: see e2eDeviceLogin |
| + Registry: regPath, |
| + Releases: relStore, |
| + ReleasePub: pub, |
| + Key: priv, |
| + AppScheme: "http", |
| + AppsDomain: "oncarlos.test", |
| + }, cst) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + |
| + const addr = "paul@keymail.dev" |
| + if err := cst.AddMember(console.OpsAccountID, addr, console.RoleOwner, time.Now()); err != nil { |
| + t.Fatal(err) |
| + } |
| + token, expiresAt := e2eDeviceLogin(t, ts.URL, cst, addr, "e2e@laptop") |
| + credFile, err := loadCredentials() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + credFile.put(credential{Console: ts.URL, Address: addr, Token: token, ExpiresAt: expiresAt}) |
| + if err := credFile.save(); err != nil { |
| + t.Fatal(err) |
| + } |
| + buf := captureStdout(t) |
| + |
| + // --- fleet home through the console, and its box in the registry ------ |
| + runFleetsCreate([]string{"-bucket", "home-fleet-data", "-account", "ops", "home"}) |
| + if want := "created fleet home"; !strings.Contains(buf.String(), want) { |
| + t.Fatalf("fleets create stdout = %q, want %q", buf.String(), want) |
| + } |
| + reg, err := registry.Open(regPath) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + t.Cleanup(func() { reg.Close() }) |
| + if err := reg.AddFleetBox(registry.FleetBox{Fleet: "home", Label: "pi-1", |
| + TokenHash: strings.Repeat("a", 64), Status: "active", AddedAt: time.Now().Unix()}); err != nil { |
| + t.Fatal(err) |
| + } |
| + |
| + // --- shop, placed on home at create, with instances on edge ----------- |
| + buf.Reset() |
| + runAppsCreate([]string{"-app", "shop", "-place", "fleet/home", "-account", "ops"}) |
| + if want := "placed on fleet/home"; !strings.Contains(buf.String(), want) { |
| + t.Fatalf("apps create stdout = %q, want %q", buf.String(), want) |
| + } |
| + buf.Reset() |
| + runInstancesEnable([]string{"-app", "shop", "-account", "ops", "-channel", "edge"}) |
| + const domain = "bab.oncarlos.test" |
| + if want := "enabled instances for shop under " + domain; !strings.Contains(buf.String(), want) { |
| + t.Fatalf("enable stdout = %q, want %q", buf.String(), want) |
| + } |
| + |
| + // --- a rootfs release r1, always on, promoted onto edge ---------------- |
| + m := release.Manifest{ |
| + Schema: 1, App: "shop", Version: "r1", Kind: release.KindRootfs, BuiltAt: "2026-10-24T10:00:00Z", |
| + Artifacts: map[string]release.Artifact{release.RootfsArtifactKey: {File: release.RootfsArtifactFile}}, |
| + Processes: map[string]release.Process{release.ProcessWeb: {Command: []string{"/rails/bin/web"}}}, |
| + } |
| + if err := release.Ship(context.Background(), relStore, release.OpsAccount, m, |
| + map[string][]byte{release.RootfsArtifactKey: []byte("hsqsr1")}); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := release.Promote(context.Background(), relStore, priv, release.OpsAccount, "shop", "edge", "r1"); err != nil { |
| + t.Fatal(err) |
| + } |
| + |
| + // --- one heartbeat from pi-1: ready, on the floor, and reporting the |
| + // host about to be created with one running worker ----------------------- |
| + host := "shop." + domain |
| + box := status.Box{GeneratedAt: time.Now(), Label: "pi-1", |
| + Metrics: &status.BoxMetrics{Layout: &status.LayoutReport{Mode: "nested"}, RootfsReady: true, |
| + Release: "v" + release.RootfsLifecycleFloor.String(), |
| + Rollout: &status.RolloutReport{Hosts: map[string]status.HostRollout{ |
| + host: {Account: release.OpsAccount, App: "shop", Installed: "r1", Serving: "r1", Awake: true, |
| + Workers: []status.WorkerState{{Name: "worker", State: "running"}}}, |
| + }}}} |
| + if err := status.WriteBox(context.Background(), release.NewPrefixStore(relStore, "fleets/home/"), box); err != nil { |
| + t.Fatal(err) |
| + } |
| + |
| + // --- create: the rootfs line (RFS-4-C18) ------------------------------- |
| + buf.Reset() |
| + runInstancesCreate([]string{"-app", "shop", "-account", "ops", "-host", host}) |
| + out := buf.String() |
| + if !strings.Contains(out, "created instance "+host) { |
| + t.Fatalf("create stdout = %q, want created instance %s", out, host) |
| + } |
| + if want := " rootfs, always on. it starts as soon as its box picks it up, and does not wait for a request\n"; !strings.Contains(out, want) { |
| + t.Fatalf("create stdout = %q, want the line %q", out, want) |
| + } |
| + rec, err := provision.GetRecord(context.Background(), relStore, release.OpsAccount, "shop", host) |
| + if err != nil { |
| + t.Fatalf("record after create: %v", err) |
| + } |
| + if rec.Runtime != provision.RuntimeRootfsV1 || rec.Hibernate == nil || *rec.Hibernate || rec.Region != "fleet/home" { |
| + t.Fatalf("record = %+v, want rootfs-v1, always on, on fleet/home", rec) |
| + } |
| + |
| + // --- list: RUNTIME rootfs, WORKERS 1/1 --------------------------------- |
| + buf.Reset() |
| + runInstancesList([]string{"-app", "shop", "-account", "ops"}) |
| + lines := strings.Split(strings.TrimRight(buf.String(), "\n"), "\n") |
| + head := -1 |
| + for i, l := range lines { |
| + if strings.HasPrefix(l, "HOST ") { |
| + head = i |
| + break |
| + } |
| + } |
| + if head < 0 { |
| + t.Fatalf("list stdout = %q, want the table", buf.String()) |
| + } |
| + from, to := strings.Index(lines[head], "RUNTIME"), strings.Index(lines[head], "WORKERS") |
| + if from < 0 || to < from { |
| + t.Fatalf("list heading = %q, want RUNTIME then WORKERS", lines[head]) |
| + } |
| + found := false |
| + for _, l := range lines[head+1:] { |
| + if !strings.HasPrefix(l, host+" ") { |
| + continue |
| + } |
| + found = true |
| + if got := strings.TrimSpace(l[from:to]); got != "rootfs" { |
| + t.Errorf("RUNTIME = %q, want rootfs\n%s", got, buf.String()) |
| + } |
| + if got := strings.TrimSpace(l[to:]); got != "1/1" { |
| + t.Errorf("WORKERS = %q, want 1/1\n%s", got, buf.String()) |
| + } |
| + } |
| + if !found { |
| + t.Fatalf("list stdout = %q, want a row for %s", buf.String(), host) |
| + } |
| +} |