grouproll: the Standby observation probe
Port scripts/region-group-probe.py as carlos system group probe start|resume|status|abandon|close-lost: the roll engine in probe mode, with status-only sessions, the group read reconciled with the member's own membership row, and probe journals only (the roll verbs keep refusing them). Every region_group_probe_test.py test is ported, with the five probe mutations. Registry branch, parity rows, golden skip line and the census re-proposed with Engine.Probe.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs/parity.md+1 −1docs/superpowers/notes/census-proposal-group-roll-verb.md+3 −2internal/grouproll/engine.go+23 −1internal/grouproll/probe.go+357 −0internal/grouproll/probe_test.go+1,494 −0internal/grouproll/roll.go+22 −1internal/grouproll/status.go+17 −0internal/provision/testdata/plan14-root-reads-chain.tsv+1 −1internal/provision/testdata/plan14-root-reads-group-roll-verb.tsv+7 −5parity/cli.tsv+5 −0parity/parity.tsv+1 −1region_ha_boundary_test.go+1 −0system_group.go+59 −10system_group_test.go+129 −0system_roles.go+19 −0testdata/clireg-golden.jsonl+1 −0
CI failed — run details
Intent
<task-notification> <task-id>a4599f79b6d38e3e1</task-id> <tool-use-id>toolu_01F15zHHEXF8rSarUQ2c5796</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/669506ff-23ec-45f1-9035-1d29593f2c37/tasks/a4599f79b6d38e3e1.output</output-file> <status>completed</status> <summary>Agent "Implement Task 9: replace/remove" 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. Review findings 1, 2 and 3 are fixed in `ff64cdca` (on `group-roll-verb`, not pushed); finding 4 (cli.md) stays with Task 12 as ruled. Fixes: - **V10 (P1), changed replacement:** once a replacement is admitted, the new member must stay exactly that instance, checked from the journal so it also holds after a resume. Any other set is a failed probe with `members`: the divergence flag is written, there is no done row, and it is never re-admitted silently. - **V11 (P1), restored capacity:** desired and minimum are each recorded as restored the first time a fresh group read shows N. A restore not yet seen at N is sent again, whether it was unsent or its answer was lost. A value below N after that is a failed probe with `desired_changed`, never a second raise. - **Fence audit (P2):** at every terminate, the simulation now requires that the last edge-stop record names this transaction's fence and that the box's current fence is this transaction's. Two negative controls (fence removed, fence swapped just before the terminate) are each caught at seed 0. Tests: - New tests: `TestDepartChangedReplacementAfterAdmissionFails`, `TestDepartCapacityReducedAfterRestoreFails`, and `TestDepartUnansweredRestoreRecovers` (four cases). - On the pre-fix engine, the first two tests' scenarios finished as a normal completion, and the third found no restore records. All three pass now. - The covering tests pass, and all eight mutation rows are caught. - The 200-seed depart simulation passes in 63.7 s; `go test ./internal/grouproll/... ./internal/grouprollaws/...` passes; the darwin and windows builds pass. - The census was re-proposed with the same 23 claims (only the grouproll package's fingerprint changed), and the census test passes. Concerns: - I did not repeat the 3000-seed run; the figures in the report are from `b5c7bf6e`. These fixes only add new stop conditions, and the 200 seeds hit none of them. - The grouproll package still takes about 2 minutes in CI. The fix report is appended to `/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-group-roll-verb/.superpowers/sdd/2026-11-09-group-roll-verb/task-9-report.md`.</result> <usage><subagent_tokens>471664</subagent_tokens><tool_uses>8</tool_uses><duration_ms>369897</duration_ms></usage> </task-notification>
<task-notification> <task-id>bn82le53q</task-id> <tool-use-id>toolu_01V2L7TeexikaEjDRv7yx6o6</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/669506ff-23ec-45f1-9035-1d29593f2c37/tasks/bn82le53q.output</output-file> <status>completed</status> <summary>Background command "Wait for Task 9 re-review" completed (exit code 0)</summary> </task-notification>
Attributed to this commit: 19.7 g CO₂e (2,475,920 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on group-roll-verb, 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/docs/parity.md b/docs/parity.md| index eedba86fc..77e721ee9 100644 |
| --- a/docs/parity.md |
| +++ b/docs/parity.md |
| @@ -409,7 +409,7 @@ Discussion #742. |
| | op-system-geoip | operator | `system geoip publish`<br>`system geoip status`<br>`system geoip off` | | The platform GeoIP database. | |
| | op-system-cutovers | operator | `system seeds-floor publish`<br>`system legacy-routes assign`<br>`system lifetimes cutover`<br>`system hosts-used status` | | One-off cutovers and floors. | |
| | op-system-roles | operator | `system box role`<br>`system group role` | | Box and group roles. | |
| -| op-system-group-roll | operator | `system group plan`<br>`system group status`<br>`system group roll`<br>`system group resume`<br>`system group rollback`<br>`system group return`<br>`system group abandon`<br>`system group close-lost`<br>`system group replace`<br>`system group remove`<br>`system group cancel-drain` | | Group maintenance from an operator machine. | |
| +| op-system-group-roll | operator | `system group plan`<br>`system group status`<br>`system group roll`<br>`system group resume`<br>`system group rollback`<br>`system group return`<br>`system group abandon`<br>`system group close-lost`<br>`system group replace`<br>`system group remove`<br>`system group cancel-drain`<br>`system group probe start`<br>`system group probe resume`<br>`system group probe status`<br>`system group probe abandon`<br>`system group probe close-lost` | | Group maintenance from an operator machine. | |
| | op-system-demos | operator | `system demos status`<br>`system demos serving`<br>`system demos takedown`<br>`system demos takedown-status`<br>`system demos reports`<br>`system demos reports resolve` | | Demo serving, takedowns and reports. | |
| | op-system-managed-fleets | operator | `system managed-fleets show`<br>`system managed-fleets set` | | The managed-fleet catalog. | |
diff --git a/docs/superpowers/notes/census-proposal-group-roll-verb.md b/docs/superpowers/notes/census-proposal-group-roll-verb.md| index e5e6eaf8b..d67f98b51 100644 |
| --- a/docs/superpowers/notes/census-proposal-group-roll-verb.md |
| +++ b/docs/superpowers/notes/census-proposal-group-roll-verb.md |
| @@ -1,6 +1,6 @@ |
| # Census approval: group-roll-verb |
| -Ruling `census-ruling-group-roll-verb`. The independent reviewer approves or rejects every change below, 23 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26). |
| +Ruling `census-ruling-group-roll-verb`. The independent reviewer approves or rejects every change below, 24 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26). |
| Envelopes re-pinned: `.`, `internal/grouproll`, `internal/grouprollaws`, `internal/release`. |
| @@ -14,6 +14,7 @@ New dispositions, which census-propose wrote and the reviewer checks against the |
| - new `internal/grouproll/engine.go:Engine.preflight`: reads +file:Read; written legacy, accepted-legacy, frozen |
| - new `internal/grouproll/journal.go:Journal.read`: reads +file:ReadAll; written legacy, accepted-legacy, frozen |
| - new `internal/grouproll/plan.go:Engine.Plan`: reads +file:Read; written legacy, accepted-legacy, frozen |
| +- new `internal/grouproll/probe.go:Engine.Probe`: reads +file:Create; written legacy, accepted-legacy, frozen |
| - new `internal/grouproll/roll.go:Engine.Roll`: reads +file:Create, +file:Lstat; written legacy, accepted-legacy, frozen |
| - new `internal/grouproll/roll.go:Engine.closeLost`: reads +file:Lstat; written legacy, accepted-legacy, frozen |
| - new `internal/grouproll/state.go:State.ActiveID`: reads +file:Lstat ×2, +file:Read, +file:ReadDir; written legacy, accepted-legacy, frozen |
| @@ -32,6 +33,6 @@ New dispositions, which census-propose wrote and the reviewer checks against the |
| - new `internal/grouprollaws/transport.go:boundedBody.Read`: reads +file:Read ×2; written legacy, accepted-legacy, frozen |
| - new `system_group.go:runSystemGroup`: reads +file:Lstat; written legacy, accepted-legacy, frozen |
| -Seal: `8924fafc5b6083858a72f45c764081abe3bcad6a6de71901470586c076c64bb6` → `430e9b4958b72e1498b118b6b8cd16514534f0766ca6392f27c141c227076e7b`. |
| +Seal: `8924fafc5b6083858a72f45c764081abe3bcad6a6de71901470586c076c64bb6` → `615f4396bf5e1fe0046c4366b953d68793ecf83db44ec24564d003ca3a2e6631`. |
| Overlay: `internal/provision/testdata/plan14-root-reads-group-roll-verb.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`. |
diff --git a/internal/grouproll/engine.go b/internal/grouproll/engine.go| index 22a290a35..e9fe510cd 100644 |
| --- a/internal/grouproll/engine.go |
| +++ b/internal/grouproll/engine.go |
| @@ -58,6 +58,12 @@ type Engine struct { |
| // seams are the required mutations' executor hooks (tests); the zero |
| // value is production. |
| seams seams |
| + |
| + // probe is the Standby observation probe's mode (probe.go, the |
| + // script's Probe subclass): status sessions only, the group read |
| + // reconciled with the member's own membership row, the probe's |
| + // identity checks, and only probe journals. |
| + probe bool |
| } |
| // Caller is the provider's "who am I": the user id the provider's own |
| @@ -206,7 +212,7 @@ func (e *Engine) call(ctx context.Context, op string, args map[string]any, fresh |
| if !fresh.IsZero() { |
| age := e.clock().Sub(fresh) |
| evidence["exit_observation_age"] = age.Milliseconds() |
| - if age < 0 || age > exitFreshness { |
| + if (age < 0 || age > exitFreshness) && !e.seams.skipFreshness { |
| expired = true |
| return nil, refuse("admission") |
| } |
| @@ -272,6 +278,10 @@ func reasonOf(err error) string { |
| // box is the script's Operator.box: one framed verb on one member. The |
| // response row holds the verb's value, as the script journals it. |
| func (e *Engine) box(ctx context.Context, iid, verb string, a BoxArgs) (BoxResult, error) { |
| + if e.probe && verb != "status" { |
| + // The script's Probe.box and Probe.call: refused before the intent. |
| + return BoxResult{}, refuse("probe_read_only") |
| + } |
| args := map[string]any{"iid": iid, "verb": verb} |
| if a.SHA256 != "" { |
| args["sha256"] = a.SHA256 |
| @@ -361,6 +371,11 @@ func (e *Engine) snapshot(ctx context.Context) (snapshotView, error) { |
| if err != nil { |
| return snapshotView{}, err |
| } |
| + if e.probe { |
| + if g, err = e.reconcile(ctx, g); err != nil { |
| + return snapshotView{}, err |
| + } |
| + } |
| if g.Name != e.c.Group || g.ARN != e.c.GroupARN || g.Deployment != e.c.Deployment || |
| g.Region != e.c.Region || !sameSet(g.TargetGroups, e.c.TargetGroups) { |
| return snapshotView{}, refuse("scope") |
| @@ -558,6 +573,9 @@ func (e *Engine) identity(s map[string]any, iid string) error { |
| } |
| } |
| } |
| + if e.probe { |
| + return e.probeIdentity(s, iid) |
| + } |
| return nil |
| } |
| @@ -665,6 +683,10 @@ func (e *Engine) readiness(ctx context.Context, iid string) (readiness, error) { |
| // artifact its action left (the old one after a failed drain), as a new |
| // process, under this transaction's consumed permit. |
| func (e *Engine) readinessFor(ctx context.Context, iid string, maintenance bool) (readiness, error) { |
| + if e.probe { |
| + // The probe runs no action: never the maintenance checks. |
| + maintenance = false |
| + } |
| s, err := e.status(ctx, iid) |
| if err != nil { |
| return readiness{}, err |
diff --git a/internal/grouproll/probe.go b/internal/grouproll/probe.go| new file mode 100644 |
| index 000000000..6939cb4f4 |
| --- /dev/null |
| +++ b/internal/grouproll/probe.go |
| @@ -0,0 +1,357 @@ |
| +package grouproll |
| + |
| +import ( |
| + "context" |
| + "errors" |
| + "io" |
| + "time" |
| +) |
| + |
| +// The Standby observation probe (scripts/region-group-probe.py, spec §3 |
| +// and V7): park an unchanged member through Standby and return it, under |
| +// the group lock, to record that the group has no return hook. It is the |
| +// roll engine in probe mode (Engine.probe), as the script's Probe is a |
| +// subclass of its Operator: |
| +// |
| +// - box sessions are status only; any other verb is refused |
| +// probe_read_only before it is journaled (box); |
| +// - every group read the probe makes is reconciled with the member's own |
| +// membership row (reconcile), and the member's scaling activities are |
| +// read beside it; |
| +// - the member must keep its permit absent and, once validated, its |
| +// original binary and edge process (probeIdentity); |
| +// - readiness never runs the maintenance checks (readinessFor); |
| +// - there is no artifact to prepare and no action to run or verify |
| +// (probeFacts); |
| +// - the probe verbs accept only probe journals, and the roll verbs |
| +// refuse them (checkJournalKind). |
| +// |
| +// A pass prints the no-hook observation record. The probe never writes |
| +// provider-observation.json: the controller places it by hand. |
| + |
| +// probeCompletions are the lifecycle completion intents a passing probe's |
| +// journal must not hold. |
| +var probeCompletions = map[string]bool{"complete": true, "complete_lifecycle_action": true, "abandon": true} |
| + |
| +// Probe is the script's Probe.probe: open a probe transaction for member |
| +// iid and run it. The caller holds the group lock. A preflight refusal |
| +// closes the transaction preflight-refused. |
| +func (e *Engine) Probe(ctx context.Context, iid string) error { |
| + e.probe = true |
| + if !e.s.Held() { |
| + return refuse("busy") |
| + } |
| + if active, err := e.s.ActiveID(); err != nil { |
| + return err |
| + } else if active != "" { |
| + return refuse("active") |
| + } |
| + if e.Caller == nil { |
| + return refuse("unsupported") |
| + } |
| + user, _, err := e.Caller.CallerIdentity(ctx) |
| + if err != nil { |
| + return err |
| + } |
| + j, err := e.s.Create(Header{Kind: "probe", Transaction: "probe-" + randomHex(), IID: iid, |
| + AttendedBy: e.attended, CallerUserID: user}) |
| + if err != nil { |
| + return err |
| + } |
| + e.open(j) |
| + defer e.close() |
| + e.say("journal", j.Path()) |
| + return e.probeResume(ctx) |
| +} |
| + |
| +// ProbeResume is the probe's resume verb: continue probe transaction tx. |
| +func (e *Engine) ProbeResume(ctx context.Context, tx string) error { |
| + e.probe = true |
| + if err := e.load(tx); err != nil { |
| + return err |
| + } |
| + defer e.close() |
| + return e.probeResume(ctx) |
| +} |
| + |
| +// ProbeAbandon is the probe's abandon verb: the roll's abandon, on probe |
| +// journals only. |
| +func (e *Engine) ProbeAbandon(ctx context.Context, tx string) error { |
| + e.probe = true |
| + return e.Abandon(ctx, tx) |
| +} |
| + |
| +// ProbeCloseLost is the probe's close-lost verb: the roll's close-lost, on |
| +// probe journals only. Closure reads the group's own member list, never |
| +// the probe's reconciled one. |
| +func (e *Engine) ProbeCloseLost(ctx context.Context, tx string) error { |
| + e.probe = true |
| + return e.CloseLost(ctx, tx) |
| +} |
| + |
| +// probeResume is the script's Probe.resume: preflight a transaction that |
| +// was never validated (a refusal closes it preflight-refused; an |
| +// interrupt leaves it open), close a done one, else resume the engine. |
| +func (e *Engine) probeResume(ctx context.Context) error { |
| + if err := e.checkJournalKind(); err != nil { |
| + return err |
| + } |
| + if err := e.activeHere(); err != nil { |
| + return err |
| + } |
| + if !e.has("validated", nil) && !e.has("done", nil) { |
| + e.header = cloneRow(e.j.Rows()[0]) |
| + if err := e.probePreflight(ctx, e.hStr("iid")); err != nil { |
| + if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) { |
| + return err |
| + } |
| + if _, jerr := e.event("done", map[string]any{"outcome": "preflight-refused"}); jerr != nil { |
| + return jerr |
| + } |
| + if ferr := e.s.Finish(); ferr != nil { |
| + return ferr |
| + } |
| + return err |
| + } |
| + } |
| + if e.has("done", nil) { |
| + return e.s.Finish() |
| + } |
| + return e.resume(ctx) |
| +} |
| + |
| +// probePreflight is the script's Probe.preflight: the group's shape and |
| +// launch hook, every member online, serving and ready, then the validated |
| +// row naming the member's binary as both old and new. |
| +func (e *Engine) probePreflight(ctx context.Context, iid string) error { |
| + if !IID.MatchString(iid) { |
| + return refuse("config_invalid") |
| + } |
| + if blocked, err := e.blocked(); err != nil { |
| + return err |
| + } else if blocked { |
| + return refuse("blocked") |
| + } |
| + snap, err := e.snapshot(ctx) |
| + if err != nil { |
| + return err |
| + } |
| + if !shapeOK(snap.View, iid) { |
| + return refuse("shape") |
| + } |
| + h, err := e.hook(ctx) |
| + if err != nil { |
| + return err |
| + } |
| + if !e.hookOK(h) { |
| + return refuse("hook") |
| + } |
| + var status map[string]any |
| + for _, m := range sortedMembers(snap.View) { |
| + on, err := e.online(ctx, m) |
| + if err != nil { |
| + return err |
| + } |
| + if !on { |
| + return refuse("offline") |
| + } |
| + if !peerOK(snap, m) { |
| + return refuse("peer") |
| + } |
| + ready, err := e.readiness(ctx, m) |
| + if err != nil { |
| + return err |
| + } |
| + if m == iid { |
| + status = ready.Status |
| + } |
| + } |
| + identity := map[string]any{} |
| + for _, k := range []string{"iid", "boot_id", "account", "region", "group", "config_digest", "box_ref"} { |
| + v, ok := status[k] |
| + if !ok { |
| + return refuse("record") |
| + } |
| + identity[k] = v |
| + } |
| + edge, _ := status["edge"].(map[string]any) |
| + process, ok := edge["identity"] |
| + if !ok { |
| + return refuse("record") |
| + } |
| + members := []any{} |
| + for _, m := range sortedMembers(snap.View) { |
| + members = append(members, m) |
| + } |
| + details := map[string]any{"old": status["binary_sha256"], "new": status["binary_sha256"], |
| + "n": snap.View.Desired, "members": members, "template": snap.View.Template, |
| + "original_process": process, "identity": identity} |
| + row, err := e.event("validated", details) |
| + if err != nil { |
| + return err |
| + } |
| + // The header as the journal holds it, so later reads compare decoded |
| + // values with decoded values. |
| + for k, v := range row { |
| + switch k { |
| + case "seq", "previous", "hash", "kind", "at_ms": |
| + continue |
| + } |
| + e.header[k] = v |
| + } |
| + return nil |
| +} |
| + |
| +// reconcile is the script's Probe.call("group"): the member's own |
| +// membership row must name this group and the group's launch template; |
| +// its lifecycle state and health replace the group's, a missing row |
| +// removes the member, and the member's scaling activities are read. The |
| +// group's own answer is journaled unchanged by describe. |
| +func (e *Engine) reconcile(ctx context.Context, g GroupView) (GroupView, error) { |
| + iid := e.hStr("iid") |
| + var row MemberRow |
| + var found bool |
| + if _, err := e.call(ctx, "instance", map[string]any{"iid": iid}, time.Time{}, func(ctx context.Context, _ func(string)) (any, error) { |
| + var err error |
| + row, found, err = e.g.Membership(ctx, iid) |
| + if err != nil { |
| + return nil, err |
| + } |
| + return memberRows(row, found), nil |
| + }); err != nil { |
| + return GroupView{}, err |
| + } |
| + members := make(map[string]Member, len(g.Members)) |
| + for k, v := range g.Members { |
| + members[k] = v |
| + } |
| + if found { |
| + if row.IID != iid || row.Group != e.c.Group { |
| + return GroupView{}, refuse("scope") |
| + } |
| + if (row.Template == nil) != (g.Template == nil) || !pyEqual(row.Template, g.Template) { |
| + return GroupView{}, refuse("members") |
| + } |
| + // Preserve the group membership; use the member's own lifecycle. |
| + if _, ok := members[iid]; ok { |
| + members[iid] = Member{Phase: row.Phase, Raw: row.Raw, Healthy: row.Healthy} |
| + } |
| + } else { |
| + delete(members, iid) |
| + } |
| + g.Members = members |
| + if _, err := e.activities(ctx, iid); err != nil { |
| + return GroupView{}, err |
| + } |
| + return g, nil |
| +} |
| + |
| +// memberRows is the "instance" answer as the journal records it: the |
| +// member's own row, or none. |
| +func memberRows(row MemberRow, found bool) []any { |
| + if !found { |
| + return []any{} |
| + } |
| + var template any |
| + if row.Template != nil { |
| + template = row.Template |
| + } |
| + return []any{map[string]any{"iid": row.IID, "group": row.Group, "template": template, |
| + "state": row.Raw, "phase": string(row.Phase), "healthy": row.Healthy}} |
| +} |
| + |
| +// probeIdentity is the script's Probe.identity beyond the roll's: the |
| +// member keeps no permit and, once validated, its original binary and |
| +// edge process. |
| +func (e *Engine) probeIdentity(s map[string]any, iid string) error { |
| + if e.header == nil || iid != e.hStr("iid") { |
| + return nil |
| + } |
| + if permitState(s) != "absent" { |
| + return refuse("permit") |
| + } |
| + if old, ok := e.header["old"]; ok { |
| + edge, _ := s["edge"].(map[string]any) |
| + if !pyEqual(s["binary_sha256"], old) || !pyEqual(edge["identity"], e.header["original_process"]) { |
| + return refuse("probe_unchanged") |
| + } |
| + } |
| + return nil |
| +} |
| + |
| +// probeFacts is the script's Probe.decision_facts: nothing to prepare, |
| +// observe or verify, and a return hook seen in the member's own row is a |
| +// hook too. |
| +func (e *Engine) probeFacts(f *Facts) { |
| + f.Prepared, f.PendingChecked, f.ActionVerified = true, true, true |
| + if f.Hook || e.j == nil { |
| + return |
| + } |
| + iid := e.hStr("iid") |
| + for _, r := range e.j.Rows() { |
| + if r["kind"] != "response" || r["op"] != "instance" { |
| + continue |
| + } |
| + rows, _ := r["result"].([]any) |
| + for _, x := range rows { |
| + m, _ := x.(map[string]any) |
| + if m["iid"] == iid && m["group"] == e.c.Group && m["phase"] == string(ReturnHeld) { |
| + f.Hook = true |
| + return |
| + } |
| + } |
| + } |
| +} |
| + |
| +// probeFinish is the script's Probe.finish_return: the returned member is |
| +// unchanged, the journal holds no lifecycle completion and no return hook |
| +// evidence, and no divergence is flagged. It records and prints the |
| +// no-hook observation and closes the transaction probe-pass. |
| +func (e *Engine) probeFinish(ready *readiness) error { |
| + if ready == nil { |
| + return refuse("record") |
| + } |
| + iid := e.hStr("iid") |
| + if err := e.identity(ready.Status, iid); err != nil { |
| + return err |
| + } |
| + completions := 0 |
| + for _, r := range e.j.Rows() { |
| + if op, _ := r["op"].(string); r["kind"] == "intent" && probeCompletions[op] { |
| + completions++ |
| + } |
| + } |
| + f, err := e.decisionFacts("return", nil, false, observed{}) |
| + if err != nil { |
| + return err |
| + } |
| + if completions != 0 { |
| + return refuse("record") |
| + } |
| + blocked, err := e.blocked() |
| + if err != nil { |
| + return err |
| + } |
| + if f.Hook || blocked { |
| + return refuse("blocked") |
| + } |
| + record := map[string]any{"v": 1, "group_arn": e.c.GroupARN, "hook": e.c.Hook, |
| + "template": e.header["template"], "documented_no_hook": true} |
| + line, err := pythonDumps(record) |
| + if err != nil { |
| + return refuse("record") |
| + } |
| + if _, err := e.event("probe-pass", map[string]any{"record": record, "return_completions": completions, |
| + "return_hook_observed": f.Hook}); err != nil { |
| + return err |
| + } |
| + if _, err := e.event("done", map[string]any{"outcome": "probe-pass"}); err != nil { |
| + return err |
| + } |
| + if err := e.s.Finish(); err != nil { |
| + return err |
| + } |
| + io.WriteString(e.out, line+"\n") |
| + e.say("journal", e.j.Path()) |
| + return nil |
| +} |
diff --git a/internal/grouproll/probe_test.go b/internal/grouproll/probe_test.go| new file mode 100644 |
| index 000000000..81dd77552 |
| --- /dev/null |
| +++ b/internal/grouproll/probe_test.go |
| @@ -0,0 +1,1494 @@ |
| +//go:build linux || darwin |
| + |
| +package grouproll |
| + |
| +import ( |
| + "bytes" |
| + "errors" |
| + "fmt" |
| + "os" |
| + "path/filepath" |
| + "reflect" |
| + "regexp" |
| + "strings" |
| + "testing" |
| + "time" |
| +) |
| + |
| +// The Standby observation probe against the fake: ports of |
| +// scripts/region_group_probe_test.py (ProbeArgvTests, ProbeCloseLostArgvTests, |
| +// ProbeTests, ProbeMutationTests). The argv tests run at the engine; the |
| +// CLI's own refusals are in system_group_test.go. Scenarios the probe |
| +// mutations rerun return an error instead of failing the test. |
| + |
| +// newProbeHarness is ProbeTests.setUp: two members, targets healthy at |
| +// once after ExitStandby, and no provider observation (the probe never |
| +// reads or writes one; the controller places it by hand). |
| +func newProbeHarness(t *testing.T) *harness { |
| + t.Helper() |
| + h := newHarness(t, 2) |
| + h.f.targetWarmup = 0 |
| + must(t, os.Remove(h.state.ObservationPath())) |
| + return h |
| +} |
| + |
| +func (h *harness) runProbe() error { |
| + return h.locked(func(e *Engine) error { return e.Probe(bg, fakeIID) }) |
| +} |
| + |
| +// probeResume resumes the open probe transaction. |
| +func (h *harness) probeResume() error { |
| + return h.locked(func(e *Engine) error { |
| + tx, err := h.state.ActiveID() |
| + if err != nil { |
| + return err |
| + } |
| + return e.ProbeResume(bg, tx) |
| + }) |
| +} |
| + |
| +// probeTx is the one probe journal in the state directory. |
| +func (h *harness) probeTx() string { |
| + h.t.Helper() |
| + paths, _ := filepath.Glob(filepath.Join(h.state.Directory(), "probe-*"+journalSuffix)) |
| + if len(paths) != 1 { |
| + h.t.Fatalf("probe journals = %v, want one", paths) |
| + } |
| + return strings.TrimSuffix(filepath.Base(paths[0]), journalSuffix) |
| +} |
| + |
| +// probeRows are the probe journal's rows, read from disk. |
| +func (h *harness) probeRows() []Row { |
| + h.t.Helper() |
| + j, err := h.state.Load(h.probeTx(), true) |
| + if err != nil { |
| + h.t.Fatal(err) |
| + } |
| + defer j.Close() |
| + return j.Rows() |
| +} |
| + |
| +func kindRows(rows []Row, kind string) []Row { |
| + var out []Row |
| + for _, r := range rows { |
| + if r["kind"] == kind { |
| + out = append(out, r) |
| + } |
| + } |
| + return out |
| +} |
| + |
| +func hasKind(rows []Row, kind string) bool { return len(kindRows(rows, kind)) > 0 } |
| + |
| +// providerOps are the recorded operations after the caller identity call, |
| +// which the Go verbs make first (spec V9) and the script did not. |
| +func (h *harness) providerOps() []string { |
| + var out []string |
| + for _, op := range h.f.ops() { |
| + if op != "caller" { |
| + out = append(out, op) |
| + } |
| + } |
| + return out |
| +} |
| + |
| +// probeSafe is assert_no_forbidden_calls: no lifecycle completion, desired |
| +// write or terminate, only status sessions, no protocol breach, and no |
| +// provider observation written. |
| +func (h *harness) probeSafe() error { |
| + for _, c := range h.f.calls { |
| + switch c.Op { |
| + case "complete", "complete_lifecycle_action", "ABANDON", "desired", "terminate": |
| + return fmt.Errorf("forbidden call %s %v", c.Op, c.Args) |
| + case "session": |
| + if c.Args["verb"] != "status" { |
| + return fmt.Errorf("session verb %v", c.Args["verb"]) |
| + } |
| + } |
| + } |
| + if len(h.f.violations) > 0 { |
| + return fmt.Errorf("protocol breaches: %v", h.f.violations) |
| + } |
| + if _, err := os.Lstat(h.state.ObservationPath()); err == nil { |
| + return fmt.Errorf("the probe wrote %s", h.state.ObservationPath()) |
| + } |
| + return nil |
| +} |
| + |
| +func mustProbeSafe(t *testing.T, h *harness) { |
| + t.Helper() |
| + if err := h.probeSafe(); err != nil { |
| + t.Fatal(err) |
| + } |
| +} |
| + |
| +// interruptProbe is ProbeTests.interrupted: the probe dies at the Nth |
| +// write (before it is sent when before is set) and stays open. |
| +func (h *harness) interruptProbe(number int, before bool) { |
| + h.t.Helper() |
| + h.f.fault, h.f.faultAt, h.f.failBefore = "death", number, before |
| + if !expectDeath(h.t, func() { h.runProbe() }) { |
| + h.t.Fatalf("probe did not die at write %d", number) |
| + } |
| + if h.activeTx() != h.probeTx() { |
| + h.t.Fatalf("active %q, want %q", h.activeTx(), h.probeTx()) |
| + } |
| +} |
| + |
| +// createProbe opens a probe journal under the held lock and an engine in |
| +// probe mode on it, as the script tests' store.create(kind="probe") and |
| +// Probe(..., journal=j) do. |
| +func (h *harness) createProbe(e *Engine, tx string) error { |
| + j, err := h.state.Create(Header{Kind: "probe", Transaction: tx, IID: fakeIID, AttendedBy: "test operator"}) |
| + if err != nil { |
| + return err |
| + } |
| + e.probe = true |
| + e.open(j) |
| + return nil |
| +} |
| + |
| +// seedProbe is CLIHarness.seed(kind="probe"): a probe journal, validated |
| +// with new equal to old when validated is set. |
| +func (h *harness) seedProbe(validated bool) string { |
| + h.t.Helper() |
| + tx := "probe-argv-test" |
| + h.withLock(func() { |
| + j, err := h.state.Create(Header{Kind: "probe", Transaction: tx, IID: fakeIID, AttendedBy: "argv operator"}) |
| + must(h.t, err) |
| + defer j.Close() |
| + if validated { |
| + s := h.f.boxes[fakeIID] |
| + identity := map[string]any{} |
| + for _, k := range []string{"iid", "boot_id", "account", "region", "group", "config_digest", "box_ref"} { |
| + identity[k] = s[k] |
| + } |
| + _, err := j.Add("validated", map[string]any{"old": oldSHA, "new": oldSHA, "n": 2, |
| + "members": []any{fakeIID, fakePeer}, "template": copyArgs(fakeTemplate), |
| + "original_process": h.f.edge(fakeIID)["identity"], "identity": identity}) |
| + must(h.t, err) |
| + } |
| + }) |
| + return tx |
| +} |
| + |
| +func probeEngine(h *harness, fn func(e *Engine) error) error { |
| + return h.locked(func(e *Engine) error { return fn(e) }) |
| +} |
| + |
| +func expectedRecord(h *harness) map[string]any { |
| + return map[string]any{"v": 1, "group_arn": h.c.GroupARN, "hook": h.c.Hook, |
| + "template": copyArgs(fakeTemplate), "documented_no_hook": true} |
| +} |
| + |
| +// printedRecords are the output lines that are JSON objects. |
| +func printedRecords(out string) []any { |
| + var recs []any |
| + for _, line := range strings.Split(out, "\n") { |
| + if strings.HasPrefix(line, "{") { |
| + v, err := decodeStrict([]byte(line)) |
| + if err != nil { |
| + recs = append(recs, line) |
| + continue |
| + } |
| + recs = append(recs, v) |
| + } |
| + } |
| + return recs |
| +} |
| + |
| +// test_probe_pass_order. |
| +func scenarioProbePassOrder(h *harness) error { |
| + if err := h.runProbe(); err != nil { |
| + return err |
| + } |
| + f := h.f |
| + if want := []string{"minimum", "enter", "exit", "minimum"}; !reflect.DeepEqual(f.writes, want) { |
| + return fmt.Errorf("writes %v, want %v", f.writes, want) |
| + } |
| + if f.minimum != 2 || f.desired != 2 { |
| + return fmt.Errorf("shape %d %d", f.minimum, f.desired) |
| + } |
| + if h.activeTx() != "" { |
| + return fmt.Errorf("transaction still open") |
| + } |
| + tx := h.probeTx() |
| + if !regexp.MustCompile(`^probe-[0-9a-f]{32}$`).MatchString(tx) { |
| + return fmt.Errorf("transaction %q", tx) |
| + } |
| + path := h.state.journalPath(tx) |
| + if st, err := os.Stat(path); err != nil || st.Mode().Perm() != 0o600 { |
| + return fmt.Errorf("journal mode %v %v", st, err) |
| + } |
| + rows := h.probeRows() |
| + if hdr, _ := rows[0]["header"].(map[string]any); hdr["kind"] != "probe" { |
| + return fmt.Errorf("header %v", rows[0]) |
| + } |
| + if rows[0]["caller_user_id"] != h.f.userID { |
| + return fmt.Errorf("caller_user_id %v", rows[0]["caller_user_id"]) |
| + } |
| + passed := kindRows(rows, "probe-pass") |
| + if len(passed) != 1 || !pyEqual(passed[0]["record"], expectedRecord(h)) || |
| + !pyEqual(passed[0]["return_completions"], 0) || passed[0]["return_hook_observed"] != false { |
| + return fmt.Errorf("probe-pass %v", passed) |
| + } |
| + if done := kindRows(rows, "done"); len(done) != 1 || done[0]["outcome"] != "probe-pass" { |
| + return fmt.Errorf("done %v", done) |
| + } |
| + if recs := printedRecords(h.out.String()); len(recs) != 1 || !pyEqual(recs[0], expectedRecord(h)) { |
| + return fmt.Errorf("printed %v", recs) |
| + } |
| + if !strings.Contains(h.out.String(), path) { |
| + return fmt.Errorf("journal path not said: %q", h.out.String()) |
| + } |
| + var states []string |
| + for _, r := range rows { |
| + if r["kind"] == "response" && r["op"] == "instance" { |
| + list, _ := r["result"].([]any) |
| + if len(list) != 1 { |
| + return fmt.Errorf("instance response %v", r["result"]) |
| + } |
| + states = append(states, list[0].(map[string]any)["state"].(string)) |
| + } |
| + } |
| + if len(states) == 0 || states[0] != "InService" || states[len(states)-1] != "InService" || |
| + countOf(states, "Standby") == 0 { |
| + return fmt.Errorf("instance states %v", states) |
| + } |
| + exitIntent := kindRows(rows, "exit-intent") |
| + var exitCall, exitResp Row |
| + for _, r := range rows { |
| + if r["op"] == "exit" && r["kind"] == "intent" && exitCall == nil { |
| + exitCall = r |
| + } |
| + if r["op"] == "exit" && r["kind"] == "response" && exitResp == nil { |
| + exitResp = r |
| + } |
| + } |
| + if len(exitIntent) != 1 || exitCall == nil || rowSeq(exitIntent[0]) >= rowSeq(exitCall) { |
| + return fmt.Errorf("exit intent order") |
| + } |
| + if age := pyNumber(exitResp["exit_observation_age"]); age == nil || *age > 5000 || *age < 0 { |
| + return fmt.Errorf("exit observation age %v", exitResp["exit_observation_age"]) |
| + } |
| + ops := h.providerOps() |
| + if len(ops) < 2 || ops[0] != "group" || ops[1] != "instance" { |
| + return fmt.Errorf("first calls %v", ops) |
| + } |
| + for _, c := range f.calls { |
| + if c.Op == "enter" && c.Args["decrement"] != true { |
| + return fmt.Errorf("enter without decrement: %v", c.Args) |
| + } |
| + } |
| + // The same indices over every call, caller included. |
| + all := f.ops() |
| + enter, exit := indexOf(all, "enter", 0), indexOf(all, "exit", 0) |
| + if exit < 3 || !reflect.DeepEqual(all[exit-3:exit], []string{"session", "edges", "session"}) { |
| + return fmt.Errorf("before exit %v", all[max(0, exit-3):exit]) |
| + } |
| + for _, c := range []fakeCall{f.calls[exit-3], f.calls[exit-1]} { |
| + if !reflect.DeepEqual(c.Args, map[string]any{"iid": fakeIID, "verb": "status"}) { |
| + return fmt.Errorf("readiness session %v", c.Args) |
| + } |
| + } |
| + if !reflect.DeepEqual(all[enter+1:enter+3], []string{"group", "instance"}) || |
| + !reflect.DeepEqual(all[exit+1:exit+3], []string{"group", "instance"}) { |
| + return fmt.Errorf("after the writes %v %v", all[enter+1:enter+3], all[exit+1:exit+3]) |
| + } |
| + for _, m := range []string{fakeIID, fakePeer} { |
| + found := false |
| + for _, c := range f.calls[:enter] { |
| + if c.Op == "online" && c.Args["iid"] == m { |
| + found = true |
| + } |
| + } |
| + if !found { |
| + return fmt.Errorf("%s not checked online before enter", m) |
| + } |
| + } |
| + var drained []Row |
| + for _, r := range kindRows(rows, "snapshot") { |
| + g := r["group"].(map[string]any) |
| + if g["members"].(map[string]any)[fakeIID] == "Standby" && rowSeq(r) < rowSeq(exitIntent[0]) { |
| + drained = append(drained, r) |
| + } |
| + } |
| + if len(drained) == 0 { |
| + return fmt.Errorf("no Standby snapshot before the exit intent") |
| + } |
| + for _, tg := range drained[len(drained)-1]["group"].(map[string]any)["targets"].([]any) { |
| + if s, ok := tg.(map[string]any)[fakeIID]; ok && s != "unused" { |
| + return fmt.Errorf("not deregistered: %v", tg) |
| + } |
| + } |
| + valid := kindRows(rows, "validated") |
| + if len(valid) != 1 || valid[0]["old"] != oldSHA || valid[0]["new"] != oldSHA { |
| + return fmt.Errorf("validated %v", valid) |
| + } |
| + return h.probeSafe() |
| +} |
| + |
| +func TestProbePassOrder(t *testing.T) { |
| + h := newProbeHarness(t) |
| + if err := scenarioProbePassOrder(h); err != nil { |
| + t.Fatal(err) |
| + } |
| +} |
| + |
| +// ProbeArgvTests (test_probe, test_resume, test_status, test_abandon), at |
| +// the engine: the minimum write is refused api. |
| +func TestProbeArgv(t *testing.T) { |
| + refuseMinimum := func(h *harness) { |
| + h.f.before = func(op string, _ map[string]any) error { |
| + if op == "minimum" { |
| + return Refusal{Key: "api"} |
| + } |
| + return nil |
| + } |
| + } |
| + minimumRefused := func(t *testing.T, h *harness, tx string, err error) { |
| + t.Helper() |
| + if refusalKey(err) != "api" { |
| + t.Fatalf("err = %v", err) |
| + } |
| + if ops := h.providerOps(); ops[0] != "group" || ops[len(ops)-1] != "minimum" { |
| + t.Fatalf("ops %v", ops) |
| + } |
| + j := h.txJournal(tx) |
| + rows := j.Rows() |
| + if hdr, _ := rows[0]["header"].(map[string]any); rows[0]["iid"] != fakeIID || hdr["kind"] != "probe" { |
| + t.Fatalf("begin %v", rows[0]) |
| + } |
| + intent, _ := j.Last("intent", nil) |
| + if !pyEqual(intent["args"], map[string]any{"value": 1}) { |
| + t.Fatalf("last intent %v", intent) |
| + } |
| + if v, _ := j.Last("validated", nil); v["old"] != oldSHA { |
| + t.Fatalf("validated %v", v) |
| + } |
| + } |
| + t.Run("probe", func(t *testing.T) { |
| + h := newProbeHarness(t) |
| + refuseMinimum(h) |
| + err := h.runProbe() |
| + tx := h.activeTx() |
| + if !regexp.MustCompile(`^probe-[0-9a-f]{32}$`).MatchString(tx) { |
| + t.Fatalf("tx %q", tx) |
| + } |
| + minimumRefused(t, h, tx, err) |
| + if a := h.txJournal(tx).Rows()[0]["attended_by"]; a != "test operator" { |
| + t.Fatalf("attended_by %v", a) |
| + } |
| + }) |
| + t.Run("resume", func(t *testing.T) { |
| + h := newProbeHarness(t) |
| + tx := h.seedProbe(true) |
| + refuseMinimum(h) |
| + minimumRefused(t, h, tx, h.probeResume()) |
| + }) |
| + t.Run("status", func(t *testing.T) { |
| + h := newProbeHarness(t) |
| + tx := h.seedProbe(true) |
| + before := snapshotFiles(t, h.state.Directory()) |
| + var out bytes.Buffer |
| + h.withLock(func() { must(t, ProbeStatus(h.root, h.c, tx, &out)) }) |
| + if len(h.f.calls) != 0 { |
| + t.Fatalf("calls %v", h.f.ops()) |
| + } |
| + v, err := decodeStrict(out.Bytes()) |
| + must(t, err) |
| + s := v.(map[string]any) |
| + if s["transaction"] != tx || s["iid"] != fakeIID || s["new_sha256"] != oldSHA { |
| + t.Fatalf("status %v", s) |
| + } |
| + if !reflect.DeepEqual(before, snapshotFiles(t, h.state.Directory())) { |
| + t.Fatal("status changed the state directory") |
| + } |
| + }) |
| + t.Run("abandon", func(t *testing.T) { |
| + h := newProbeHarness(t) |
| + tx := h.seedProbe(false) |
| + must(t, h.locked(func(e *Engine) error { return e.ProbeAbandon(bg, tx) })) |
| + if len(h.f.calls) != 0 || h.activeTx() != "" { |
| + t.Fatalf("calls %v active %q", h.f.ops(), h.activeTx()) |
| + } |
| + j := h.txJournal(tx) |
| + done, _ := j.Last("done", nil) |
| + abandoned, _ := j.Last("abandoned", nil) |
| + if done["outcome"] != "abandoned" || abandoned["attended_by"] != "test operator" { |
| + t.Fatalf("done %v abandoned %v", done, abandoned) |
| + } |
| + if !strings.Contains(h.out.String(), Text("abandoned")) { |
| + t.Fatal("not said") |
| + } |
| + }) |
| +} |
| + |
| +// ProbeCloseLostArgvTests: CloseLostArgvChecks on a probe journal. Closure |
| +// reads the group's own member list, never the probe's reconciled one: its |
| +// calls are exactly the group and EC2 reads. |
| +func TestProbeCloseLost(t *testing.T) { |
| + seedLost := func(h *harness) string { |
| + tx := h.seedProbe(true) |
| + h.f.states[fakeIID], h.f.ec2State = "Terminated", "terminated" |
| + h.appendRow(tx, "intent", map[string]any{"op": "exit", "args": map[string]any{"iid": fakeIID}}) |
| + return tx |
| + } |
| + closeLost := func(h *harness, tx string) error { |
| + return h.locked(func(e *Engine) error { return e.ProbeCloseLost(bg, tx) }) |
| + } |
| + checkClosed := func(t *testing.T, h *harness, tx string) { |
| + t.Helper() |
| + must(t, closeLost(h, tx)) |
| + if h.activeTx() != "" || !reflect.DeepEqual(h.f.ops(), []string{"group", "ec2_instance"}) { |
| + t.Fatalf("calls %v", h.f.ops()) |
| + } |
| + j := h.txJournal(tx) |
| + rows := j.Rows() |
| + var kinds []string |
| + for _, r := range rows[len(rows)-6:] { |
| + kinds = append(kinds, r["kind"].(string)) |
| + } |
| + if !reflect.DeepEqual(kinds, []string{"intent", "response", "intent", "response", "lost-member-closed", "done"}) { |
| + t.Fatalf("rows %v", kinds) |
| + } |
| + closed, _ := j.Last("lost-member-closed", nil) |
| + resp, _ := j.Last("response", map[string]any{"op": "ec2_instance"}) |
| + if closed["iid"] != fakeIID || !sameValue(closed["describe"], resp["result"]) { |
| + t.Fatalf("closed %v", closed) |
| + } |
| + if done, _ := j.Last("done", nil); done["outcome"] != "failed-member-lost" { |
| + t.Fatalf("done %v", done) |
| + } |
| + if !strings.Contains(h.out.String(), Text("lost_closed")) { |
| + t.Fatal("not said") |
| + } |
| + } |
| + t.Run("terminated preserves flags and status", func(t *testing.T) { |
| + h := newProbeHarness(t) |
| + tx := seedLost(h) |
| + h.withLock(func() { |
| + must(t, h.state.Write(h.state.DivergencePath(), map[string]any{"transaction": tx, "phase": "Pending:Wait"})) |
| + must(t, h.state.Write(h.state.ObservationPath(), map[string]any{"evidence": "preserve exactly"})) |
| + }) |
| + before := snapshotFiles(t, h.state.Directory()) |
| + checkClosed(t, h, tx) |
| + after := snapshotFiles(t, h.state.Directory()) |
| + for _, name := range []string{divergenceFile, observationFile} { |
| + if before[name] != after[name] { |
| + t.Fatalf("%s changed", name) |
| + } |
| + } |
| + if !strings.Contains(h.out.String(), h.state.DivergencePath()) { |
| + t.Fatal("retained flag not named") |
| + } |
| + var status bytes.Buffer |
| + must(t, ProbeStatus(h.root, h.c, tx, &status)) |
| + if !strings.Contains(status.String(), `"outcome": "failed-member-lost"`) { |
| + t.Fatalf("status %s", status.String()) |
| + } |
| + h.f.calls = nil |
| + if err := closeLost(h, tx); err == nil || len(h.f.calls) != 0 { |
| + t.Fatalf("second close-lost = %v, calls %v", err, h.f.ops()) |
| + } |
| + }) |
| + t.Run("not found", func(t *testing.T) { |
| + h := newProbeHarness(t) |
| + tx := seedLost(h) |
| + h.f.ec2State = "" |
| + checkClosed(t, h, tx) |
| + }) |
| + t.Run("present group states", func(t *testing.T) { |
| + for _, state := range []string{"Standby", "InService", "Pending", "Pending:Wait", "Terminating", "Terminated"} { |
| + h := newProbeHarness(t) |
| + tx := seedLost(h) |
| + h.f.wrap = func(op string, args map[string]any, r any, err error) (any, error) { |
| + if op == "group" && err == nil { |
| + g := r.(GroupView) |
| + g.Members[fakeIID] = Member{Phase: fakePhase(state), Raw: state} |
| + return g, nil |
| + } |
| + return r, err |
| + } |
| + if err := closeLost(h, tx); refusalKey(err) != "close_lost_refused" { |
| + t.Fatalf("%s: close-lost = %v", state, err) |
| + } |
| + h.stillActive(t, tx) |
| + } |
| + }) |
| + t.Run("nonterminal EC2 states", func(t *testing.T) { |
| + for _, state := range []string{"pending", "running", "shutting-down", "stopping", "stopped", "unknown"} { |
| + h := newProbeHarness(t) |
| + tx := seedLost(h) |
| + h.f.ec2State = state |
| + if err := closeLost(h, tx); refusalKey(err) != "close_lost_refused" { |
| + t.Fatalf("%s: close-lost = %v", state, err) |
| + } |
| + h.stillActive(t, tx) |
| + } |
| + }) |
| + t.Run("read errors", func(t *testing.T) { |
| + for _, op := range []string{"group", "ec2_instance"} { |
| + h := newProbeHarness(t) |
| + tx := seedLost(h) |
| + h.f.before = func(called string, _ map[string]any) error { |
| + if called == op { |
| + return Uncertain{Key: "api"} |
| + } |
| + return nil |
| + } |
| + if err := closeLost(h, tx); !isUncertain(err) { |
| + t.Fatalf("%s: close-lost = %v", op, err) |
| + } |
| + h.stillActive(t, tx) |
| + } |
| + }) |
| + t.Run("wrong group identity", func(t *testing.T) { |
| + h := newProbeHarness(t) |
| + tx := seedLost(h) |
| + h.f.wrap = func(op string, args map[string]any, r any, err error) (any, error) { |
| + if op == "group" && err == nil { |
| + g := r.(GroupView) |
| + g.ARN += "-recreated" |
| + return g, nil |
| + } |
| + return r, err |
| + } |
| + if err := closeLost(h, tx); refusalKey(err) != "scope" { |
| + t.Fatalf("close-lost = %v", err) |
| + } |
| + h.stillActive(t, tx) |
| + }) |
| + t.Run("no journal", func(t *testing.T) { |
| + h := newProbeHarness(t) |
| + if err := closeLost(h, "missing"); refusalKey(err) != "record" || len(h.f.calls) != 0 { |
| + t.Fatalf("close-lost = %v", err) |
| + } |
| + }) |
| + t.Run("finished", func(t *testing.T) { |
| + h := newProbeHarness(t) |
| + tx := seedLost(h) |
| + h.appendRow(tx, "done", map[string]any{"outcome": "failed-member-lost"}) |
| + if err := closeLost(h, tx); refusalKey(err) != "record" || len(h.f.calls) != 0 || h.activeTx() != tx { |
| + t.Fatalf("close-lost = %v", err) |
| + } |
| + }) |
| + t.Run("wrong kind", func(t *testing.T) { |
| + h := newProbeHarness(t) |
| + tx := h.seed(true) |
| + if err := closeLost(h, tx); refusalKey(err) != "journal_kind" || len(h.f.calls) != 0 { |
| + t.Fatalf("close-lost = %v", err) |
| + } |
| + h.stillActive(t, tx) |
| + }) |
| + t.Run("no active pointer", func(t *testing.T) { |
| + h := newProbeHarness(t) |
| + tx := seedLost(h) |
| + must(t, os.Remove(filepath.Join(h.state.Directory(), activeFile))) |
| + if err := closeLost(h, tx); refusalKey(err) != "record" || len(h.f.calls) != 0 { |
| + t.Fatalf("close-lost = %v", err) |
| + } |
| + }) |
| + t.Run("lock", func(t *testing.T) { |
| + h := newProbeHarness(t) |
| + tx := seedLost(h) |
| + other, err := OpenState(h.root, h.c, false) |
| + must(t, err) |
| + unlock, err := other.Lock() |
| + must(t, err) |
| + defer unlock() |
| + if err := closeLost(h, tx); refusalKey(err) != "busy" || len(h.f.calls) != 0 { |
| + t.Fatalf("close-lost = %v", err) |
| + } |
| + }) |
| +} |
| + |
| +// test_instance_health_casing_preflight: the member's own row decides its |
| +// health (the adapter reads DescribeAutoScalingInstances' HEALTHY; |
| +// TestMembership in grouprollaws pins the casing). |
| +func TestProbeInstanceHealthCasing(t *testing.T) { |
| + for _, healthy := range []bool{true, false} { |
| + h := newProbeHarness(t) |
| + h.f.wrap = func(op string, args map[string]any, r any, err error) (any, error) { |
| + if op == "instance" && err == nil { |
| + row := r.(MemberRow) |
| + row.Healthy = healthy |
| + return row, nil |
| + } |
| + return r, err |
| + } |
| + must(t, probeEngine(h, func(e *Engine) error { |
| + must(t, h.createProbe(e, "probe-"+strings.Repeat("d", 32))) |
| + defer e.close() |
| + err := e.probePreflight(bg, fakeIID) |
| + _, validated := e.last("validated", nil) |
| + if healthy && (err != nil || !validated) { |
| + t.Errorf("healthy: %v", err) |
| + } |
| + if !healthy && (refusalKey(err) != "peer" || validated) { |
| + t.Errorf("unhealthy: %v", err) |
| + } |
| + if len(h.f.writes) != 0 { |
| + t.Errorf("writes %v", h.f.writes) |
| + } |
| + return nil |
| + })) |
| + } |
| +} |
| + |
| +// test_probe_lost_exit_response. |
| +func TestProbeLostExitResponse(t *testing.T) { |
| + h := newProbeHarness(t) |
| + h.f.fault, h.f.faultAt = "uncertain", 3 |
| + lost := false |
| + h.f.after = func(name string) { |
| + if name == "exit" { |
| + lost = true |
| + } |
| + } |
| + h.f.before = func(op string, _ map[string]any) error { |
| + if lost { |
| + lost = false |
| + if op != "group" { |
| + t.Errorf("the call after the lost exit is %s", op) |
| + } |
| + return Uncertain{Key: "api"} |
| + } |
| + return nil |
| + } |
| + if err := h.runProbe(); !isUncertain(err) { |
| + t.Fatalf("probe = %v", err) |
| + } |
| + if h.f.exits != 1 { |
| + t.Fatalf("exits %d", h.f.exits) |
| + } |
| + start := len(h.f.calls) |
| + must(t, h.probeResume()) |
| + if ops := h.f.ops()[start:]; ops[0] != "group" || ops[1] != "instance" { |
| + t.Fatalf("resume ops %v", ops) |
| + } |
| + rows := h.probeRows() |
| + exitError := false |
| + for _, r := range kindRows(rows, "error") { |
| + exitError = exitError || r["op"] == "exit" |
| + } |
| + if h.f.exits != 1 || !exitError || !hasKind(rows, "probe-pass") { |
| + t.Fatalf("exits %d exit error %v", h.f.exits, exitError) |
| + } |
| + mustProbeSafe(t, h) |
| +} |
| + |
| +// test_probe_pending_wait: a return hook blocks the probe; a resume reads |
| +// the group and refuses again without a write. |
| +func TestProbePendingWait(t *testing.T) { |
| + h := newProbeHarness(t) |
| + h.f.hook = true |
| + if err := h.runProbe(); refusalKey(err) != "return_hook" { |
| + t.Fatalf("probe = %v", err) |
| + } |
| + if !blockedFlag(h) || !strings.Contains(h.out.String(), "ALERT") { |
| + t.Fatal("not blocked or not alerted") |
| + } |
| + hooks := kindRows(h.probeRows(), "return-hook") |
| + if len(hooks) != 1 || hooks[0]["iid"] != fakeIID || hooks[0]["hook"] != h.c.Hook || |
| + !pyEqual(hooks[0]["deadline"], h.f.deadline.UnixMilli()) { |
| + t.Fatalf("return-hook %v (deadline %d)", hooks, h.f.deadline.UnixMilli()) |
| + } |
| + before := append([]string{}, h.f.writes...) |
| + start := len(h.f.calls) |
| + if err := h.probeResume(); err == nil { |
| + t.Fatal("resume passed") |
| + } |
| + if !reflect.DeepEqual(h.f.writes, before) { |
| + t.Fatalf("writes %v", h.f.writes) |
| + } |
| + if ops := h.f.ops()[start:]; ops[0] != "group" || ops[1] != "instance" { |
| + t.Fatalf("resume ops %v", ops) |
| + } |
| + if hasKind(h.probeRows(), "probe-pass") { |
| + t.Fatal("passed") |
| + } |
| + mustProbeSafe(t, h) |
| +} |
| + |
| +// test_probe_provider_inservice_after_hook. |
| +func scenarioProbeInServiceAfterHook(h *harness) error { |
| + h.f.hook = true |
| + if err := h.runProbe(); err == nil { |
| + return fmt.Errorf("probe passed with a hook") |
| + } |
| + h.f.states[fakeIID], h.f.tg[fakeIID] = "InService", "healthy" |
| + if err := h.probeResume(); !isStop(err, "divergence-held") { |
| + return fmt.Errorf("resume = %v", err) |
| + } |
| + if want := []string{"minimum", "enter", "exit", "enter"}; !reflect.DeepEqual(h.f.writes, want) { |
| + return fmt.Errorf("writes %v", h.f.writes) |
| + } |
| + if h.f.minimum != 1 || h.f.desired != 1 || h.f.states[fakeIID] != "Standby" || h.f.tg[fakeIID] != "unused" { |
| + return fmt.Errorf("not held: %d %d %s %s", h.f.minimum, h.f.desired, h.f.states[fakeIID], h.f.tg[fakeIID]) |
| + } |
| + if !hasKind(h.probeRows(), "divergence-held") { |
| + return fmt.Errorf("no divergence-held row") |
| + } |
| + before := append([]string{}, h.f.writes...) |
| + if err := h.probeResume(); !isStop(err, "divergence-held") { |
| + return fmt.Errorf("second resume = %v", err) |
| + } |
| + if !reflect.DeepEqual(h.f.writes, before) { |
| + return fmt.Errorf("second resume wrote %v", h.f.writes) |
| + } |
| + return h.probeSafe() |
| +} |
| + |
| +func TestProbeProviderInServiceAfterHook(t *testing.T) { |
| + if err := scenarioProbeInServiceAfterHook(newProbeHarness(t)); err != nil { |
| + t.Fatal(err) |
| + } |
| +} |
| + |
| +// test_probe_default_abandon_fail: the provider's ABANDON default |
| +// terminates the held member; every resume is a failed probe. |
| +func TestProbeDefaultAbandonFail(t *testing.T) { |
| + h := newProbeHarness(t) |
| + h.f.hook = true |
| + if err := h.runProbe(); err == nil { |
| + t.Fatal("probe passed with a hook") |
| + } |
| + h.f.sleep(901 * time.Second) |
| + before := append([]string{}, h.f.writes...) |
| + for i := 0; i < 2; i++ { |
| + if err := h.probeResume(); !isStop(err, "failed-probe") { |
| + t.Fatalf("resume %d = %v", i, err) |
| + } |
| + } |
| + if h.f.abandons != 1 || h.f.launches != 1 || !reflect.DeepEqual(h.f.writes, before) { |
| + t.Fatalf("abandons %d launches %d writes %v", h.f.abandons, h.f.launches, h.f.writes) |
| + } |
| + if !blockedFlag(h) || !strings.Contains(h.out.String(), "FAIL") { |
| + t.Fatal("not failed") |
| + } |
| + if n := len(kindRows(h.probeRows(), "failed-probe")); n != 2 { |
| + t.Fatalf("failed-probe rows %d", n) |
| + } |
| + mustProbeSafe(t, h) |
| +} |
| + |
| +// test_probe_stale_observation. |
| +func scenarioProbeStaleObservation(h *harness) error { |
| + h.afterEvent = func(kind string, row Row) { |
| + if kind == "intent" && row["op"] == "exit" { |
| + h.f.now = h.f.now.Add(6 * time.Second) |
| + } |
| + } |
| + if err := h.runProbe(); refusalKey(err) != "admission" { |
| + return fmt.Errorf("probe = %v", err) |
| + } |
| + h.afterEvent = nil |
| + if h.f.exits != 0 || h.f.states[fakeIID] != "Standby" { |
| + return fmt.Errorf("exits %d state %s", h.f.exits, h.f.states[fakeIID]) |
| + } |
| + var exitErr Row |
| + for _, r := range kindRows(h.probeRows(), "error") { |
| + if r["op"] == "exit" { |
| + exitErr = r |
| + } |
| + } |
| + age := pyNumber(exitErr["exit_observation_age"]) |
| + if exitErr == nil || exitErr["dispatched"] != false || exitErr["error"] != "ObservationExpired" || age == nil || *age <= 5000 { |
| + return fmt.Errorf("exit error %v", exitErr) |
| + } |
| + if err := h.probeResume(); err != nil { |
| + return err |
| + } |
| + if h.f.exits != 1 { |
| + return fmt.Errorf("exits %d after resume", h.f.exits) |
| + } |
| + return h.probeSafe() |
| +} |
| + |
| +func TestProbeStaleObservation(t *testing.T) { |
| + if err := scenarioProbeStaleObservation(newProbeHarness(t)); err != nil { |
| + t.Fatal(err) |
| + } |
| +} |
| + |
| +// test_probe_lock_and_active. |
| +func TestProbeLockAndActive(t *testing.T) { |
| + h := newProbeHarness(t) |
| + if err := h.engine().Probe(bg, fakeIID); refusalKey(err) != "busy" { |
| + t.Fatalf("unlocked probe = %v", err) |
| + } |
| + if len(h.f.calls) != 0 || h.activeTx() != "" { |
| + t.Fatalf("calls %v", h.f.ops()) |
| + } |
| + other, err := OpenState(h.root, h.c, false) |
| + must(t, err) |
| + unlock, err := other.Lock() |
| + must(t, err) |
| + if err := h.runProbe(); refusalKey(err) != "busy" { |
| + t.Fatalf("probe beside another lock = %v", err) |
| + } |
| + unlock() |
| + if len(h.f.calls) != 0 { |
| + t.Fatalf("calls %v", h.f.ops()) |
| + } |
| + h.withLock(func() { |
| + j, err := h.state.Create(Header{Transaction: "roll-active", IID: fakeIID, New: newSHA}) |
| + must(t, err) |
| + j.Close() |
| + }) |
| + if err := h.runProbe(); refusalKey(err) != "active" { |
| + t.Fatalf("probe beside a roll = %v", err) |
| + } |
| + if len(h.f.calls) != 0 { |
| + t.Fatalf("calls %v", h.f.ops()) |
| + } |
| + h.appendRow("roll-active", "done", map[string]any{"outcome": "test"}) |
| + h.withLock(func() { must(t, h.state.Finish()) }) |
| + h.interruptProbe(2, false) |
| + before := append([]string{}, h.f.writes...) |
| + ok, err := h.plan(fakeIID, newSHA) |
| + if ok || err != nil { |
| + t.Fatalf("plan = %v %v", ok, err) |
| + } |
| + done, _ := h.planLog().Last("done", nil) |
| + found := false |
| + for _, r := range done["refusals"].([]any) { |
| + found = found || r == Text("active") |
| + } |
| + if !found { |
| + t.Fatalf("plan refusals %v", done["refusals"]) |
| + } |
| + if err := h.runRoll(); refusalKey(err) != "active" { |
| + t.Fatalf("roll = %v", err) |
| + } |
| + if !reflect.DeepEqual(h.f.writes, before) { |
| + t.Fatalf("writes %v", h.f.writes) |
| + } |
| +} |
| + |
| +// test_probe_abandon_before_group_write. |
| +func TestProbeAbandonBeforeGroupWrite(t *testing.T) { |
| + h := newProbeHarness(t) |
| + tx := "probe-" + strings.Repeat("a", 32) |
| + must(t, probeEngine(h, func(e *Engine) error { |
| + must(t, h.createProbe(e, tx)) |
| + defer e.close() |
| + must(t, e.probePreflight(bg, fakeIID)) |
| + h.f.tg[fakePeer] = "unhealthy" |
| + if err := e.probeResume(bg); err == nil { |
| + t.Fatal("resume passed with an unhealthy peer") |
| + } |
| + if e.has("done", nil) { |
| + t.Fatal("done recorded") |
| + } |
| + return nil |
| + })) |
| + if len(h.f.writes) != 0 { |
| + t.Fatalf("writes %v", h.f.writes) |
| + } |
| + calls := len(h.f.calls) |
| + must(t, h.locked(func(e *Engine) error { return e.ProbeAbandon(bg, tx) })) |
| + if len(h.f.calls) != calls || h.activeTx() != "" { |
| + t.Fatalf("abandon called %v", h.f.ops()[calls:]) |
| + } |
| + rows := h.probeRows() |
| + last := rows[len(rows)-2:] |
| + if last[0]["kind"] != "abandoned" || last[1]["kind"] != "done" || last[1]["outcome"] != "abandoned" || |
| + last[0]["attended_by"] != "test operator" { |
| + t.Fatalf("rows %v", last) |
| + } |
| + h.f.tg[fakePeer] = "healthy" |
| + if err := h.runProbe(); err != nil { |
| + t.Fatalf("probe after abandon = %v", err) |
| + } |
| +} |
| + |
| +// test_probe_abandon_refuses_group_intent. |
| +func TestProbeAbandonRefusesGroupIntent(t *testing.T) { |
| + for _, intent := range []string{"minimum", "enter", "exit", "exit-intent"} { |
| + h := newProbeHarness(t) |
| + tx := "probe-" + strings.Repeat("b", 32) |
| + h.withLock(func() { |
| + j, err := h.state.Create(Header{Kind: "probe", Transaction: tx, IID: fakeIID}) |
| + must(t, err) |
| + defer j.Close() |
| + if intent == "exit-intent" { |
| + _, err = j.Add(intent, map[string]any{}) |
| + } else { |
| + _, err = j.Add("intent", map[string]any{"op": intent, "args": map[string]any{}}) |
| + } |
| + must(t, err) |
| + }) |
| + before, _ := os.ReadFile(h.state.journalPath(tx)) |
| + if err := h.locked(func(e *Engine) error { return e.ProbeAbandon(bg, tx) }); refusalKey(err) != "abandon_refused" { |
| + t.Fatalf("%s: abandon = %v", intent, err) |
| + } |
| + after, _ := os.ReadFile(h.state.journalPath(tx)) |
| + if h.activeTx() != tx || !bytes.Equal(before, after) || len(h.f.calls) != 0 { |
| + t.Fatalf("%s: journal or calls changed", intent) |
| + } |
| + } |
| +} |
| + |
| +// test_probe_pass_refuses_journal_evidence: any return hook evidence or |
| +// lifecycle completion intent in the journal refuses the pass record. |
| +func TestProbePassRefusesJournalEvidence(t *testing.T) { |
| + for _, evidence := range []string{"group", "instance", "return-hook", "complete", "complete_lifecycle_action", "abandon"} { |
| + t.Run(evidence, func(t *testing.T) { |
| + h := newProbeHarness(t) |
| + must(t, probeEngine(h, func(e *Engine) error { |
| + tx := "probe-" + strings.Repeat("c", 32) |
| + must(t, h.createProbe(e, tx)) |
| + defer e.close() |
| + must(t, e.probePreflight(bg, fakeIID)) |
| + ready, err := e.readiness(bg, fakeIID) |
| + must(t, err) |
| + switch evidence { |
| + case "group": |
| + g := h.f.view() |
| + g.Members[fakeIID] = Member{Phase: ReturnHeld, Raw: "Pending:Wait", Healthy: true} |
| + _, err = e.j.Add("response", map[string]any{"op": "group", "result": groupMap(g)}) |
| + case "instance": |
| + _, err = e.j.Add("response", map[string]any{"op": "instance", "result": memberRows(MemberRow{ |
| + IID: fakeIID, Group: h.c.Group, Template: copyArgs(fakeTemplate), Raw: "Pending:Wait", |
| + Phase: ReturnHeld, Healthy: true}, true)}) |
| + case "return-hook": |
| + _, err = e.j.Add("return-hook", map[string]any{"iid": fakeIID}) |
| + default: |
| + _, err = e.j.Add("intent", map[string]any{"op": evidence, "args": map[string]any{}}) |
| + } |
| + must(t, err) |
| + f, err := e.decisionFacts("return", nil, false, observed{}) |
| + must(t, err) |
| + if want := evidence == "group" || evidence == "instance" || evidence == "return-hook"; f.Hook != want { |
| + t.Fatalf("hook = %v, want %v", f.Hook, want) |
| + } |
| + if blockedFlag(h) { |
| + t.Fatal("blocked before the pass") |
| + } |
| + calls := len(h.f.calls) |
| + if err := e.probeFinish(&ready); err == nil { |
| + t.Fatal("pass recorded") |
| + } |
| + if len(h.f.calls) != calls || e.has("probe-pass", nil) || e.has("done", nil) || h.activeTx() != tx { |
| + t.Fatalf("calls %v", h.f.ops()[calls:]) |
| + } |
| + if recs := printedRecords(h.out.String()); len(recs) != 0 { |
| + t.Fatalf("printed %v", recs) |
| + } |
| + return nil |
| + })) |
| + }) |
| + } |
| +} |
| + |
| +// test_probe_journal_isolation and the brief's kind isolation: each probe |
| +// leaf refuses a roll or depart journal, and each roll leaf refuses a |
| +// probe journal, with journal_kind and no provider call. The roll status |
| +// reads any journal, as the script's did. |
| +func scenarioProbeJournalIsolation(h *harness) error { |
| + h.interruptProbe(2, false) |
| + tx := h.probeTx() |
| + h.f.calls = nil |
| + roll := map[string]func(e *Engine) error{ |
| + "resume": func(e *Engine) error { return e.Resume(bg, tx) }, |
| + "return": func(e *Engine) error { return e.Return(bg, tx) }, |
| + "rollback": func(e *Engine) error { return e.Rollback(bg, fakeIID, tx) }, |
| + "abandon": func(e *Engine) error { return e.Abandon(bg, tx) }, |
| + "close-lost": func(e *Engine) error { return e.CloseLost(bg, tx) }, |
| + "cancel-drain": func(e *Engine) error { return e.CancelDrain(bg, fakeIID, tx) }, |
| + } |
| + for name, fn := range roll { |
| + want := "journal_kind" |
| + if name == "cancel-drain" { |
| + want = "cancel_refused" |
| + } |
| + if err := h.locked(fn); refusalKey(err) != want { |
| + return fmt.Errorf("roll %s on a probe journal = %v", name, err) |
| + } |
| + } |
| + var out bytes.Buffer |
| + if err := Status(h.root, h.c, tx, &out); err != nil { |
| + return fmt.Errorf("roll status of a probe journal = %v", err) |
| + } |
| + if len(h.f.calls) != 0 { |
| + return fmt.Errorf("roll leaves called %v", h.f.ops()) |
| + } |
| + |
| + for _, kind := range []string{"", "replace"} { |
| + other := newHarness(h.t, 2) |
| + other.seams, other.classify = h.seams, h.classify |
| + otx := "argv-test" |
| + other.withLock(func() { |
| + j, err := other.state.Create(Header{Kind: kind, Transaction: otx, IID: fakeIID, New: newSHA}) |
| + must(h.t, err) |
| + j.Close() |
| + }) |
| + probe := map[string]func(e *Engine) error{ |
| + "resume": func(e *Engine) error { return e.ProbeResume(bg, otx) }, |
| + "abandon": func(e *Engine) error { return e.ProbeAbandon(bg, otx) }, |
| + "close-lost": func(e *Engine) error { return e.ProbeCloseLost(bg, otx) }, |
| + } |
| + for name, fn := range probe { |
| + if err := other.locked(fn); refusalKey(err) != "journal_kind" { |
| + return fmt.Errorf("probe %s on a %q journal = %v", name, kind, err) |
| + } |
| + } |
| + if err := ProbeStatus(other.root, other.c, otx, &out); refusalKey(err) != "journal_kind" { |
| + return fmt.Errorf("probe status on a %q journal = %v", kind, err) |
| + } |
| + if len(other.f.calls) != 0 { |
| + return fmt.Errorf("probe leaves called %v", other.f.ops()) |
| + } |
| + } |
| + return nil |
| +} |
| + |
| +func TestProbeLeavesKindIsolation(t *testing.T) { |
| + if err := scenarioProbeJournalIsolation(newProbeHarness(t)); err != nil { |
| + t.Fatal(err) |
| + } |
| +} |
| + |
| +// test_probe_death_at_every_write: a death before or after each of the |
| +// four writes resumes to the same pass, reading the group first. |
| +func TestProbeDeathAtEveryWrite(t *testing.T) { |
| + for _, before := range []bool{true, false} { |
| + for boundary := 1; boundary <= 4; boundary++ { |
| + t.Run(fmt.Sprintf("before=%v/%d", before, boundary), func(t *testing.T) { |
| + h := newProbeHarness(t) |
| + h.interruptProbe(boundary, before) |
| + start := len(h.f.calls) |
| + must(t, h.probeResume()) |
| + if ops := h.f.ops()[start:]; ops[0] != "group" || ops[1] != "instance" { |
| + t.Fatalf("resume ops %v", ops) |
| + } |
| + if want := []string{"minimum", "enter", "exit", "minimum"}; h.f.exits != 1 || !reflect.DeepEqual(h.f.writes, want) { |
| + t.Fatalf("exits %d writes %v", h.f.exits, h.f.writes) |
| + } |
| + if h.f.minimum != 2 || h.f.desired != 2 || !hasKind(h.probeRows(), "probe-pass") { |
| + t.Fatal("not passed") |
| + } |
| + mustProbeSafe(t, h) |
| + }) |
| + } |
| + } |
| +} |
| + |
| +// test_probe_changed_process: a changed binary or edge process after |
| +// either write refuses the pass, keeping the member. |
| +func TestProbeChangedProcess(t *testing.T) { |
| + for _, changed := range []string{"identity", "binary"} { |
| + for _, boundary := range []string{"enter", "exit"} { |
| + t.Run(changed+"/"+boundary, func(t *testing.T) { |
| + h := newProbeHarness(t) |
| + h.f.after = func(name string) { |
| + if name != boundary { |
| + return |
| + } |
| + if changed == "identity" { |
| + h.f.edge(fakeIID)["identity"] = "changed" |
| + } else { |
| + h.f.boxes[fakeIID]["binary_sha256"] = newSHA |
| + } |
| + } |
| + var r Refusal |
| + if err := h.runProbe(); err == nil || !errors.As(err, &r) { |
| + t.Fatalf("probe = %v", err) |
| + } |
| + exits, state := 0, "Standby" |
| + if boundary == "exit" { |
| + exits, state = 1, "InService" |
| + } |
| + if h.f.minimum != 1 || h.f.exits != exits || h.f.states[fakeIID] != state { |
| + t.Fatalf("minimum %d exits %d state %s", h.f.minimum, h.f.exits, h.f.states[fakeIID]) |
| + } |
| + rows := h.probeRows() |
| + if !hasKind(rows, "alert") || hasKind(rows, "probe-pass") { |
| + t.Fatal("no alert, or passed") |
| + } |
| + mustProbeSafe(t, h) |
| + }) |
| + } |
| + } |
| +} |
| + |
| +// test_probe_waits_for_both_deregistrations. |
| +func scenarioProbeWaitsForDeregistration(h *harness) error { |
| + h.f.wrap = func(op string, args map[string]any, r any, err error) (any, error) { |
| + if op == "targets" && err == nil && h.f.states[fakeIID] == "Standby" && args["arn"] == h.c.TargetGroups[1] { |
| + t := map[string]string{} |
| + for k, v := range r.(map[string]string) { |
| + t[k] = v |
| + } |
| + t[fakeIID] = "draining" |
| + return t, nil |
| + } |
| + return r, err |
| + } |
| + if err := h.runProbe(); err == nil { |
| + return fmt.Errorf("probe passed while draining") |
| + } |
| + if want := []string{"minimum", "enter"}; h.f.exits != 0 || !reflect.DeepEqual(h.f.writes, want) { |
| + return fmt.Errorf("exits %d writes %v", h.f.exits, h.f.writes) |
| + } |
| + if !hasKind(h.probeRows(), "alert") { |
| + return fmt.Errorf("no alert") |
| + } |
| + h.f.wrap = nil |
| + if err := h.probeResume(); err != nil { |
| + return err |
| + } |
| + if h.f.exits != 1 { |
| + return fmt.Errorf("exits %d after resume", h.f.exits) |
| + } |
| + return nil |
| +} |
| + |
| +func TestProbeWaitsForBothDeregistrations(t *testing.T) { |
| + if err := scenarioProbeWaitsForDeregistration(newProbeHarness(t)); err != nil { |
| + t.Fatal(err) |
| + } |
| +} |
| + |
| +// test_probe_instance_hook_survives_target_error: the member's own row |
| +// showing a return hook is journaled before a target read fails, and |
| +// blocks. |
| +func TestProbeInstanceHookSurvivesTargetError(t *testing.T) { |
| + h := newProbeHarness(t) |
| + h.f.wrap = func(op string, args map[string]any, r any, err error) (any, error) { |
| + if h.f.exits > 0 && op == "instance" && err == nil { |
| + row := r.(MemberRow) |
| + row.Raw, row.Phase = "Pending:Wait", ReturnHeld |
| + return row, nil |
| + } |
| + if h.f.exits > 0 && op == "targets" { |
| + return nil, Uncertain{Key: "api"} |
| + } |
| + return r, err |
| + } |
| + if err := h.runProbe(); err == nil { |
| + t.Fatal("probe passed") |
| + } |
| + if !blockedFlag(h) || !hasKind(h.probeRows(), "return-hook") || h.f.minimum != 1 { |
| + t.Fatalf("blocked %v minimum %d", blockedFlag(h), h.f.minimum) |
| + } |
| + mustProbeSafe(t, h) |
| +} |
| + |
| +// test_probe_no_revoke_when_permit_appears. |
| +func TestProbeNoRevokeWhenPermitAppears(t *testing.T) { |
| + h := newProbeHarness(t) |
| + h.f.after = func(name string) { |
| + if name == "exit" { |
| + tx, _ := h.state.ActiveID() |
| + h.f.presentPermit(fakeIID, tx, "apply") |
| + } |
| + } |
| + if err := h.runProbe(); err == nil { |
| + t.Fatal("probe passed") |
| + } |
| + if h.f.minimum != 1 || hasKind(h.probeRows(), "probe-pass") { |
| + t.Fatalf("minimum %d", h.f.minimum) |
| + } |
| + mustProbeSafe(t, h) |
| +} |
| + |
| +// test_probe_preflight_refusals. |
| +func TestProbePreflightRefusals(t *testing.T) { |
| + for change, key := range map[string]string{"offline": "offline", "hook": "hook", "template": "scope", |
| + "permit": "permit", "health": "peer", "blocked": "blocked", "shape": "shape"} { |
| + t.Run(change, func(t *testing.T) { |
| + h := newProbeHarness(t) |
| + switch change { |
| + case "offline": |
| + h.f.online = false |
| + case "permit": |
| + h.f.presentPermit(fakeIID, "other", "apply") |
| + case "health": |
| + h.f.tg[fakePeer] = "unhealthy" |
| + case "blocked": |
| + h.withLock(func() { must(t, h.state.Write(h.state.DivergencePath(), map[string]any{"reason": "test"})) }) |
| + case "shape": |
| + h.f.minimum = 1 |
| + } |
| + h.f.wrap = func(op string, args map[string]any, r any, err error) (any, error) { |
| + if err != nil { |
| + return r, err |
| + } |
| + switch { |
| + case change == "hook" && op == "hooks": |
| + hk := r.(Hook) |
| + hk.Timeout = 901 |
| + return hk, nil |
| + case change == "template" && op == "group": |
| + g := r.(GroupView) |
| + g.Template["Version"] = "$Latest" |
| + return g, nil |
| + case change == "template" && op == "instance": |
| + row := r.(MemberRow) |
| + row.Template["Version"] = "$Latest" |
| + return row, nil |
| + } |
| + return r, err |
| + } |
| + if err := h.runProbe(); refusalKey(err) != key { |
| + t.Fatalf("probe = %v, want %s", err, key) |
| + } |
| + rows := h.probeRows() |
| + if len(h.f.writes) != 0 || h.activeTx() != "" || rows[len(rows)-1]["outcome"] != "preflight-refused" { |
| + t.Fatalf("writes %v last %v", h.f.writes, rows[len(rows)-1]) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// test_probe_cli_and_status, at the engine: a probe stopped by a return |
| +// hook; both status verbs read it; every roll verb refuses it without a |
| +// call; the probe resume refuses again. |
| +func TestProbeCLIAndStatus(t *testing.T) { |
| + h := newProbeHarness(t) |
| + h.f.hook = true |
| + if err := h.runProbe(); err == nil { |
| + t.Fatal("probe passed with a hook") |
| + } |
| + tx := h.activeTx() |
| + before := len(h.f.calls) |
| + var out bytes.Buffer |
| + must(t, ProbeStatus(h.root, h.c, tx, &out)) |
| + must(t, Status(h.root, h.c, tx, &out)) |
| + for name, fn := range map[string]func(e *Engine) error{ |
| + "resume": func(e *Engine) error { return e.Resume(bg, tx) }, |
| + "return": func(e *Engine) error { return e.Return(bg, tx) }, |
| + "rollback": func(e *Engine) error { return e.Rollback(bg, fakeIID, tx) }, |
| + "abandon": func(e *Engine) error { return e.Abandon(bg, tx) }, |
| + } { |
| + if err := h.locked(fn); err == nil { |
| + t.Fatalf("roll %s passed", name) |
| + } |
| + } |
| + if len(h.f.calls) != before { |
| + t.Fatalf("calls %v", h.f.ops()[before:]) |
| + } |
| + if err := h.probeResume(); err == nil { |
| + t.Fatal("probe resume passed") |
| + } |
| +} |
| + |
| +// test_probe_actual_member_transitions: the group view alone says |
| +// InService; the member's own row does not, and the probe waits for it. |
| +func TestProbeActualMemberTransitions(t *testing.T) { |
| + h := newProbeHarness(t) |
| + phases := []string{"Pending", "PreInService", "InService"} |
| + type seen struct { |
| + phase string |
| + minimum int |
| + } |
| + var got []seen |
| + h.f.wrap = func(op string, args map[string]any, r any, err error) (any, error) { |
| + if op == "instance" && err == nil && h.f.exits > 0 { |
| + phase := "InService" |
| + if len(phases) > 0 { |
| + phase, phases = phases[0], phases[1:] |
| + } |
| + row := r.(MemberRow) |
| + row.Raw, row.Phase = phase, fakePhase(phase) |
| + got = append(got, seen{phase, h.f.minimum}) |
| + return row, nil |
| + } |
| + return r, err |
| + } |
| + must(t, h.runProbe()) |
| + if want := []seen{{"Pending", 1}, {"PreInService", 1}, {"InService", 1}}; len(got) < 3 || !reflect.DeepEqual(got[:3], want) { |
| + t.Fatalf("seen %v", got) |
| + } |
| + var states []string |
| + for _, r := range kindRows(h.probeRows(), "response") { |
| + if r["op"] == "instance" { |
| + states = append(states, r["result"].([]any)[0].(map[string]any)["state"].(string)) |
| + } |
| + } |
| + if h.f.exits != 1 || countOf(states, "Pending") == 0 || countOf(states, "PreInService") == 0 { |
| + t.Fatalf("exits %d states %v", h.f.exits, states) |
| + } |
| + mustProbeSafe(t, h) |
| +} |
| + |
| +// test_probe_lost_hold_response: the hold's EnterStandby answer is lost; |
| +// the next step reads the group, and the hold is recognised. |
| +func TestProbeLostHoldResponse(t *testing.T) { |
| + h := newProbeHarness(t) |
| + h.f.hook = true |
| + if err := h.runProbe(); err == nil { |
| + t.Fatal("probe passed with a hook") |
| + } |
| + h.f.states[fakeIID], h.f.tg[fakeIID] = "InService", "healthy" |
| + h.f.fault, h.f.faultAt = "uncertain", 4 |
| + if err := h.probeResume(); !isStop(err, "divergence-held") { |
| + t.Fatalf("resume = %v", err) |
| + } |
| + if want := []string{"minimum", "enter", "exit", "enter"}; h.f.minimum != 1 || h.f.desired != 1 || !reflect.DeepEqual(h.f.writes, want) { |
| + t.Fatalf("shape %d %d writes %v", h.f.minimum, h.f.desired, h.f.writes) |
| + } |
| + rows := h.probeRows() |
| + var errRow Row |
| + for _, r := range kindRows(rows, "error") { |
| + if r["op"] == "enter" { |
| + errRow = r |
| + } |
| + } |
| + if errRow == nil { |
| + t.Fatal("no enter error row") |
| + } |
| + for _, r := range rows { |
| + if rowSeq(r) > rowSeq(errRow) && r["kind"] == "intent" { |
| + if r["op"] != "group" { |
| + t.Fatalf("next intent %v", r["op"]) |
| + } |
| + break |
| + } |
| + } |
| + mustProbeSafe(t, h) |
| +} |
| + |
| +// The probe's box sessions are status only: any other verb is refused |
| +// before it is journaled or sent (the script's Probe.box and Probe.call). |
| +func TestProbeReadOnlySessions(t *testing.T) { |
| + h := newProbeHarness(t) |
| + must(t, probeEngine(h, func(e *Engine) error { |
| + must(t, h.createProbe(e, "probe-"+strings.Repeat("e", 32))) |
| + defer e.close() |
| + for _, verb := range []string{"prepare", "permit", "revoke", "apply", "rollback", "drain", "edge-stop", |
| + "fence-clear", "drain-cancel"} { |
| + if _, err := e.box(bg, fakeIID, verb, BoxArgs{}); refusalKey(err) != "probe_read_only" { |
| + t.Errorf("%s = %v", verb, err) |
| + } |
| + } |
| + if len(h.f.calls) != 0 || e.has("intent", nil) { |
| + t.Fatalf("calls %v", h.f.ops()) |
| + } |
| + if _, err := e.box(bg, fakeIID, "status", BoxArgs{}); err != nil { |
| + t.Fatalf("status = %v", err) |
| + } |
| + return nil |
| + })) |
| +} |
| + |
| +// The member's own membership row reconciles the group read: its state and |
| +// health replace the group's, a missing row removes the member, and a row |
| +// for another group or template refuses. |
| +func TestProbeMembershipReconciles(t *testing.T) { |
| + cases := map[string]struct { |
| + edit func(row *MemberRow) (found bool) |
| + key string |
| + }{ |
| + "missing": {func(*MemberRow) bool { return false }, "shape"}, |
| + "other group": {func(r *MemberRow) bool { r.Group = "other"; return true }, "scope"}, |
| + "other instance": {func(r *MemberRow) bool { r.IID = fakePeer; return true }, "scope"}, |
| + "other template": {func(r *MemberRow) bool { r.Template["Version"] = "2"; return true }, "members"}, |
| + "not serving": {func(r *MemberRow) bool { r.Raw, r.Phase = "Standby", Parked; return true }, "peer"}, |
| + } |
| + for name, c := range cases { |
| + t.Run(name, func(t *testing.T) { |
| + h := newProbeHarness(t) |
| + h.f.wrap = func(op string, args map[string]any, r any, err error) (any, error) { |
| + if op == "instance" && err == nil { |
| + row := r.(MemberRow) |
| + if !c.edit(&row) { |
| + return MemberRow{}, nil |
| + } |
| + return row, nil |
| + } |
| + return r, err |
| + } |
| + // The fake reports found from its own state; a missing row is |
| + // modelled by Membership's answer below. |
| + if name == "missing" { |
| + h.f.wrap = nil |
| + h.f.before = func(op string, _ map[string]any) error { |
| + if op == "instance" { |
| + h.f.states[fakeIID] = "Terminated" |
| + } |
| + return nil |
| + } |
| + h.f.wrap = func(op string, args map[string]any, r any, err error) (any, error) { |
| + if op == "instance" { |
| + h.f.states[fakeIID] = "InService" |
| + } |
| + return r, err |
| + } |
| + } |
| + if err := h.runProbe(); refusalKey(err) != c.key { |
| + t.Fatalf("probe = %v, want %s", err, c.key) |
| + } |
| + if len(h.f.writes) != 0 { |
| + t.Fatalf("writes %v", h.f.writes) |
| + } |
| + // The group response row is the provider's own; the snapshot |
| + // row is the reconciled view. |
| + rows := h.probeRows() |
| + resp := kindRows(rows, "response")[0] |
| + if resp["op"] != "group" || resp["result"].(map[string]any)["members"].(map[string]any)[fakeIID] != "InService" { |
| + t.Fatalf("group response %v", resp) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// test_five_probe_mutations: each mutant, as an executor seam or an |
| +// injected decider, fails the probe scenario the script names. |
| +func TestProbeMutations(t *testing.T) { |
| + cases := []struct { |
| + name string |
| + mutate func(h *harness) |
| + scenario func(h *harness) error |
| + }{ |
| + {"drop decrement", func(h *harness) { h.seams.noDecrement = true }, scenarioProbePassOrder}, |
| + {"skip freshness", func(h *harness) { h.seams.skipFreshness = true }, scenarioProbeStaleObservation}, |
| + {"skip deregistration", func(h *harness) { |
| + h.classify = func(f Facts) Decision { |
| + f.Deregistered = true |
| + return Classify(f) |
| + } |
| + }, scenarioProbeWaitsForDeregistration}, |
| + {"restore minimum in hold", func(h *harness) { |
| + // The script's mutant disables classify's hold branch |
| + // (`if False and context == "return" and (hook or |
| + // hold_started)`): the same decider with neither fact set |
| + // there, where the other branches that read hook agree. |
| + h.classify = func(f Facts) Decision { |
| + sent := f.ExitState != "" && f.ExitState != "none" |
| + if (f.Context == "" || f.Context == "return") && (!f.Hook || (f.DivergenceRecorded && sent)) { |
| + f.Hook, f.HoldStarted = false, false |
| + } |
| + return Classify(f) |
| + } |
| + }, scenarioProbeInServiceAfterHook}, |
| + {"allow roll resume of probe", func(h *harness) { h.seams.anyJournalKind = true }, scenarioProbeJournalIsolation}, |
| + } |
| + for _, c := range cases { |
| + t.Run(c.name, func(t *testing.T) { |
| + clean := newProbeHarness(t) |
| + clean.f.collect = true |
| + if err := c.scenario(clean); err != nil { |
| + t.Fatalf("scenario fails without the mutation: %v", err) |
| + } |
| + h := newProbeHarness(t) |
| + h.f.collect = true |
| + c.mutate(h) |
| + err := func() (err error) { |
| + defer func() { |
| + if r := recover(); r != nil { |
| + err = fmt.Errorf("panicked: %v", r) |
| + } |
| + }() |
| + return c.scenario(h) |
| + }() |
| + if err == nil { |
| + t.Fatalf("%s survived", c.name) |
| + } |
| + t.Logf("probe mutation caught: %s: %v", c.name, err) |
| + }) |
| + } |
| +} |
diff --git a/internal/grouproll/roll.go b/internal/grouproll/roll.go| index 877e5244a..38d1a02a5 100644 |
| --- a/internal/grouproll/roll.go |
| +++ b/internal/grouproll/roll.go |
| @@ -64,6 +64,10 @@ type seams struct { |
| skipSecondSweep bool // no lock sweep after the stop |
| unparkUnknownDrain bool // unknown drain status passes the return |
| restoreDesiredEarly bool // desired restored before the terminate check |
| + |
| + // The probe's mutants (probe.go). |
| + skipFreshness bool // ExitStandby on an observation of any age |
| + anyJournalKind bool // every verb accepts every journal kind |
| } |
| // observed are the loop observations classify reads beside the journal |
| @@ -308,9 +312,19 @@ func (e *Engine) kind() string { |
| // checkJournalKind: the roll verbs own roll journals and the planned |
| // handovers' (script check_journal_kind). |
| func (e *Engine) checkJournalKind() error { |
| + if e.seams.anyJournalKind { |
| + return nil |
| + } |
| if e.j == nil { |
| return refuse("journal_kind") |
| } |
| + if e.probe { |
| + // The probe owns only its own kind (the script's Probe.journal_kind). |
| + if e.kind() != "probe" { |
| + return refuse("journal_kind") |
| + } |
| + return nil |
| + } |
| if k := e.kind(); k != "roll" && !departKinds[k] { |
| return refuse("journal_kind") |
| } |
| @@ -678,6 +692,9 @@ func (e *Engine) decisionFacts(context string, group *snapshotView, timedOut boo |
| } |
| } |
| } |
| + if e.probe { |
| + e.probeFacts(&f) |
| + } |
| return f, nil |
| } |
| @@ -1283,7 +1300,11 @@ func (e *Engine) returnMember(ctx context.Context) error { |
| case "finish-return": |
| // Its refusals stop the loop as any operation's do (the |
| // script's finish_return runs inside the loop's try). |
| - if err := e.finishReturn(ctx, ready); err != nil { |
| + finish := e.finishReturn |
| + if e.probe { |
| + finish = func(_ context.Context, r *readiness) error { return e.probeFinish(r) } |
| + } |
| + if err := finish(ctx, ready); err != nil { |
| return err |
| } |
| return errFinished{} |
diff --git a/internal/grouproll/status.go b/internal/grouproll/status.go| index f9ba07302..58c9251c3 100644 |
| --- a/internal/grouproll/status.go |
| +++ b/internal/grouproll/status.go |
| @@ -49,6 +49,17 @@ func SavedStatus(j *Journal) map[string]any { |
| // SavedStatus as one line of json.dumps(sort_keys=True). It takes no lock |
| // and contacts no provider. |
| func Status(stateDir string, c Config, tx string, w io.Writer) error { |
| + return printStatus(stateDir, c, tx, w, false) |
| +} |
| + |
| +// ProbeStatus is the probe's status verb: Status, for probe journals only |
| +// (the script's Probe.check_journal_kind before saved_status). The roll's |
| +// Status reads a probe journal too, as the script's did. |
| +func ProbeStatus(stateDir string, c Config, tx string, w io.Writer) error { |
| + return printStatus(stateDir, c, tx, w, true) |
| +} |
| + |
| +func printStatus(stateDir string, c Config, tx string, w io.Writer, probe bool) error { |
| s, err := OpenState(stateDir, c, true) |
| if err != nil { |
| return err |
| @@ -58,6 +69,12 @@ func Status(stateDir string, c Config, tx string, w io.Writer) error { |
| return err |
| } |
| defer j.Close() |
| + if probe { |
| + e := &Engine{j: j, probe: true} |
| + if err := e.checkJournalKind(); err != nil { |
| + return err |
| + } |
| + } |
| line, err := pythonDumps(SavedStatus(j)) |
| if err != nil { |
| return refuse("record") |
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv| index 49e1b0539..a9f75e6df 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-chain.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-chain.tsv |
| @@ -146,4 +146,4 @@ plan14-root-reads-security-review-mitigations.tsv a6f3f9eec4aac5ea88f20d0e52eaa0 |
| plan14-root-reads-cli-registry-words.tsv 8924fafc5b6083858a72f45c764081abe3bcad6a6de71901470586c076c64bb6 |
| plan14-root-reads-billing-dashboard-1.tsv 8924fafc5b6083858a72f45c764081abe3bcad6a6de71901470586c076c64bb6 |
| plan14-root-reads-billing-dash-3-cost.tsv 8924fafc5b6083858a72f45c764081abe3bcad6a6de71901470586c076c64bb6 |
| -plan14-root-reads-group-roll-verb.tsv 430e9b4958b72e1498b118b6b8cd16514534f0766ca6392f27c141c227076e7b |
| +plan14-root-reads-group-roll-verb.tsv 615f4396bf5e1fe0046c4366b953d68793ecf83db44ec24564d003ca3a2e6631 |
diff --git a/internal/provision/testdata/plan14-root-reads-group-roll-verb.tsv b/internal/provision/testdata/plan14-root-reads-group-roll-verb.tsv| index 52f5da82a..67d8e5ede 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-group-roll-verb.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-group-roll-verb.tsv |
| @@ -1,12 +1,13 @@ |
| # Census overlay group-roll-verb, written by census-propose (#369). census-ruling-group-roll-verb, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-group-roll-verb.md. |
| # 0 body, 0 sites, 4 envelope: each changed unit re-frozen at its existing disposition with its claim appended. |
| -# 23 new dispositions: 0 reads re-frozen at their disposition with the claim, 23 new units frozen accepted-legacy, 0 quiet units retired while they read nothing, 0 other. |
| +# 24 new dispositions: 0 reads re-frozen at their disposition with the claim, 24 new units frozen accepted-legacy, 0 quiet units retired while they read nothing, 0 other. |
| @legacy 4777f6d8b9e2da6def3258060eaab9340548a61f595e62e67e410df1cd040fd5 internal/grouproll/config.go LoadConfig legacy accepted-legacy accepted-legacy;rev3=census-ruling-group-roll-verb;basis=reads the operator's group config file named by --config (operator CLI only; refuses root) file:ReadFile@60 104fe171b8ce675aec5b764f43b1151bc9e9fba27d47c11b51b0bc7ea4065661 |
| @legacy 1031512d2c0d690dbb2d3a9a96358b25efbb7f443876a2b5eef38c4fe92c50de internal/grouproll/depart.go Engine.Depart legacy accepted-legacy accepted-legacy;rev3=census-ruling-group-roll-verb;basis=lstats a chosen replace or remove transaction's journal name in the operator's own 0700 state directory (an existing one refuses before any call), then creates the journal through State.Create (O_NOFOLLOW, 0600); the same reads as Engine.Roll file:Create@803,file:Lstat@529 c66f4bc96c6ffbb424a847297a8179867fac14442ae104ba5fd9e3ab42fed4cd |
| @legacy 9a38d288a899bddbd997d70ef2d5f1c710f0cda9f7c2282e68653e49800a9e99 internal/grouproll/engine.go Engine.blocked legacy accepted-legacy accepted-legacy;rev3=census-ruling-group-roll-verb;basis=lstats provider-divergence.json in the operator's own 0700 state directory (no symlink follow); any answer but not-found refuses as a damaged record file:Lstat@54 5eab2f9c41b12a03746b294a25a18a7fa5c4d6abc2196b59f05ba055daca0583 |
| @legacy 5c4850672a60472a3ecde4bd0975d4f9f49986b4a062564bd3a1d02cf53f84a2 internal/grouproll/engine.go Engine.preflight legacy accepted-legacy accepted-legacy;rev3=census-ruling-group-roll-verb;basis=reads provider-observation.json from the operator's own 0700 state directory file:Read@713 20d6aa0e018217e8354c2f0dcf8ff82db2701b76ab22e669ccb692d714ccce7a |
| @legacy bddcf0d42f620aeb6ae7c83250f0018e7b06955458196f0495039a1283c72e42 internal/grouproll/journal.go Journal.read legacy accepted-legacy accepted-legacy;rev3=census-ruling-group-roll-verb;basis=reads a format 2 journal from the operator's own 0700 state directory, capped at 64 MiB file:ReadAll@57 adb440d005959966ae0182557065f55ad8f4c3d223828f9ac290bda6e584e87f |
| @legacy 84944d21a82ac46654dc689bb67e17afa397016318ea2d00976cd51723a48482 internal/grouproll/plan.go Engine.Plan legacy accepted-legacy accepted-legacy;rev3=census-ruling-group-roll-verb;basis=reads provider-observation.json from the operator's own 0700 state directory file:Read@2173 a9e81e1f0b1d88b56ba5181caa85b7a194faf1945fd8dbf501ee65b4a2d63444 |
| +@legacy f88234b7deab2794c9a6a9cf33719bde41b6990eb19b5ee82b5868a23c5b6580 internal/grouproll/probe.go Engine.Probe legacy accepted-legacy accepted-legacy;rev3=census-ruling-group-roll-verb;basis=creates the probe transaction's journal through State.Create (O_NOFOLLOW, 0600) in the operator's own 0700 state directory under the group lock, after refusing an open transaction; the same read as Engine.Roll, with a generated probe- id file:Create@387 a23575a7688bc6a7bc95a947ec29da9b957bc0a0b15007f240de51cb678943dc |
| @legacy 7ee538f985320a0d4ff4574d3be4bafc20ae2a04da5ffc7c1b472eb092e5bae4 internal/grouproll/roll.go Engine.Roll legacy accepted-legacy accepted-legacy;rev3=census-ruling-group-roll-verb;basis=lstats a chosen transaction's journal name in the operator's own 0700 state directory (an existing one refuses before any call), then creates the journal through State.Create (O_NOFOLLOW, 0600) file:Create@936,file:Lstat@526 4cdb2e5e210d8b53bc012d952a351cc9abbb50ea1ebe80f96240a401004e65c5 |
| @legacy 692c22a90518e761faacebc98f36130ed3a6738d97cbf5ccca9782895e9ab97e internal/grouproll/roll.go Engine.closeLost legacy accepted-legacy accepted-legacy;rev3=census-ruling-group-roll-verb;basis=lstats provider-divergence.json in the operator's own 0700 state directory to say it is kept file:Lstat@1182 96e6fdd05d2d1679cdf6cca8f8ca19ad1594ed03b750785e4d33894d8b7e2a55 |
| @legacy 186c867d7252903227d8fe85c23ef4c9d6fcccb69044007d0662701aa8ef0209 internal/grouproll/state.go State.ActiveID legacy accepted-legacy accepted-legacy;rev3=census-ruling-group-roll-verb;basis=lists and reads active-v2.json and journals in the operator's own state directory file:Lstat@1138,file:Lstat@74,file:Read@125,file:ReadDir@434 9d44b2accce767cd6b36f813e2b429f36b0a54201603bb9c23d62ae557af1784 |
| @@ -23,13 +24,14 @@ |
| @legacy 04fe12d1b6361d680ee74f64c9aaab1a3861f158be69c2e60aeecb944c1912da internal/grouprollaws/session.go newNonce legacy accepted-legacy accepted-legacy;rev3=census-ruling-group-roll-verb;basis=reads crypto/rand for the frame nonce file:Read@49 7bba200ea8c254001d09c73841b2b454d95ea5015fb75840187c4612f28edb6e |
| @legacy 4dc65f2a87ac20b4bbfb3b57bcdcd630e5e648ddee3571ac78981f4a76248fb1 internal/grouprollaws/transport.go boundBody.HandleDeserialize legacy accepted-legacy accepted-legacy;rev3=census-ruling-group-roll-verb;basis=reads an AWS API answer body under the 4 MiB cap file:ReadAll@436 020d98263efa2c56f212b20f4d3e3d9497ebc1a86d737c0ffc481cb1c48d38e8 |
| @legacy 50ca60690b026dffe9bfdce05939612f8ea2fc96361639106943a5756e354601 internal/grouprollaws/transport.go boundedBody.Read legacy accepted-legacy accepted-legacy;rev3=census-ruling-group-roll-verb;basis=reads an AWS API answer body under the 4 MiB cap and the read timeout file:Read@22,file:Read@448 7ff90cef635efcf75d046d9113cb6a0dcddd8dfb3570c73984bc5565b637e872 |
| -@legacy a27e903ddd9b191f27e9501f35e586a5b6abb8c4a8c622ee34ffe070ba12a132 system_group.go runSystemGroup legacy accepted-legacy accepted-legacy;rev3=census-ruling-group-roll-verb;basis=lstats /etc/carlos/host.env to refuse running on a carlos box (euid 0 is refused first); routes the roll, replace, remove and cancel-drain verbs to the engine after refusing missing arguments file:Lstat@245 4582ac431a27dcd463bb78496dad6311dd9c487b75dfc759d067c286bb10d79c |
| +@legacy f53d354b6e75982f63dc1311b4092efa90348ffe7450f02e4f9eb193e9d532e9 system_group.go runSystemGroup legacy accepted-legacy accepted-legacy;rev3=census-ruling-group-roll-verb;basis=lstats /etc/carlos/host.env to refuse running on a carlos box (euid 0 is refused first); routes the roll, replace, remove, cancel-drain and probe verbs to the engine after refusing missing arguments file:Lstat@245 fc02f153643366e3407e177cf6950b163a93c1965c4a450597b0674c61007bec |
| internal/grouproll/config.go LoadConfig legacy accepted-legacy accepted-legacy;rev3=census-ruling-group-roll-verb;basis=reads the operator's group config file named by --config (operator CLI only; refuses root) file:ReadFile@60 104fe171b8ce675aec5b764f43b1151bc9e9fba27d47c11b51b0bc7ea4065661 |
| internal/grouproll/depart.go Engine.Depart legacy accepted-legacy accepted-legacy;rev3=census-ruling-group-roll-verb;basis=lstats a chosen replace or remove transaction's journal name in the operator's own 0700 state directory (an existing one refuses before any call), then creates the journal through State.Create (O_NOFOLLOW, 0600); the same reads as Engine.Roll file:Create@803,file:Lstat@529 c66f4bc96c6ffbb424a847297a8179867fac14442ae104ba5fd9e3ab42fed4cd |
| internal/grouproll/engine.go Engine.blocked legacy accepted-legacy accepted-legacy;rev3=census-ruling-group-roll-verb;basis=lstats provider-divergence.json in the operator's own 0700 state directory (no symlink follow); any answer but not-found refuses as a damaged record file:Lstat@54 5eab2f9c41b12a03746b294a25a18a7fa5c4d6abc2196b59f05ba055daca0583 |
| internal/grouproll/engine.go Engine.preflight legacy accepted-legacy accepted-legacy;rev3=census-ruling-group-roll-verb;basis=reads provider-observation.json from the operator's own 0700 state directory file:Read@713 20d6aa0e018217e8354c2f0dcf8ff82db2701b76ab22e669ccb692d714ccce7a |
| internal/grouproll/journal.go Journal.read legacy accepted-legacy accepted-legacy;rev3=census-ruling-group-roll-verb;basis=reads a format 2 journal from the operator's own 0700 state directory, capped at 64 MiB file:ReadAll@57 adb440d005959966ae0182557065f55ad8f4c3d223828f9ac290bda6e584e87f |
| internal/grouproll/plan.go Engine.Plan legacy accepted-legacy accepted-legacy;rev3=census-ruling-group-roll-verb;basis=reads provider-observation.json from the operator's own 0700 state directory file:Read@2173 a9e81e1f0b1d88b56ba5181caa85b7a194faf1945fd8dbf501ee65b4a2d63444 |
| +internal/grouproll/probe.go Engine.Probe legacy accepted-legacy accepted-legacy;rev3=census-ruling-group-roll-verb;basis=creates the probe transaction's journal through State.Create (O_NOFOLLOW, 0600) in the operator's own 0700 state directory under the group lock, after refusing an open transaction; the same read as Engine.Roll, with a generated probe- id file:Create@387 a23575a7688bc6a7bc95a947ec29da9b957bc0a0b15007f240de51cb678943dc |
| internal/grouproll/roll.go Engine.Roll legacy accepted-legacy accepted-legacy;rev3=census-ruling-group-roll-verb;basis=lstats a chosen transaction's journal name in the operator's own 0700 state directory (an existing one refuses before any call), then creates the journal through State.Create (O_NOFOLLOW, 0600) file:Create@936,file:Lstat@526 4cdb2e5e210d8b53bc012d952a351cc9abbb50ea1ebe80f96240a401004e65c5 |
| internal/grouproll/roll.go Engine.closeLost legacy accepted-legacy accepted-legacy;rev3=census-ruling-group-roll-verb;basis=lstats provider-divergence.json in the operator's own 0700 state directory to say it is kept file:Lstat@1182 96e6fdd05d2d1679cdf6cca8f8ca19ad1594ed03b750785e4d33894d8b7e2a55 |
| internal/grouproll/state.go State.ActiveID legacy accepted-legacy accepted-legacy;rev3=census-ruling-group-roll-verb;basis=lists and reads active-v2.json and journals in the operator's own state directory file:Lstat@1138,file:Lstat@74,file:Read@125,file:ReadDir@434 9d44b2accce767cd6b36f813e2b429f36b0a54201603bb9c23d62ae557af1784 |
| @@ -46,8 +48,8 @@ internal/grouprollaws/pty_unix.go runVersion legacy accepted-legacy accepted-leg |
| internal/grouprollaws/session.go newNonce legacy accepted-legacy accepted-legacy;rev3=census-ruling-group-roll-verb;basis=reads crypto/rand for the frame nonce file:Read@49 7bba200ea8c254001d09c73841b2b454d95ea5015fb75840187c4612f28edb6e |
| internal/grouprollaws/transport.go boundBody.HandleDeserialize legacy accepted-legacy accepted-legacy;rev3=census-ruling-group-roll-verb;basis=reads an AWS API answer body under the 4 MiB cap file:ReadAll@436 020d98263efa2c56f212b20f4d3e3d9497ebc1a86d737c0ffc481cb1c48d38e8 |
| internal/grouprollaws/transport.go boundedBody.Read legacy accepted-legacy accepted-legacy;rev3=census-ruling-group-roll-verb;basis=reads an AWS API answer body under the 4 MiB cap and the read timeout file:Read@22,file:Read@448 7ff90cef635efcf75d046d9113cb6a0dcddd8dfb3570c73984bc5565b637e872 |
| -system_group.go runSystemGroup legacy accepted-legacy accepted-legacy;rev3=census-ruling-group-roll-verb;basis=lstats /etc/carlos/host.env to refuse running on a carlos box (euid 0 is refused first); routes the roll, replace, remove and cancel-drain verbs to the engine after refusing missing arguments file:Lstat@245 4582ac431a27dcd463bb78496dad6311dd9c487b75dfc759d067c286bb10d79c |
| -@coverage . 324f3e9b1718abb0fe1f07c31f977e27ae50dc32a8c43e8977e636ba1793992a |
| -@coverage internal/grouproll 373305527c55ad2e12afe5435b6dc91030d4cb2449013c76b4c5e3e45399a8c3 |
| +system_group.go runSystemGroup legacy accepted-legacy accepted-legacy;rev3=census-ruling-group-roll-verb;basis=lstats /etc/carlos/host.env to refuse running on a carlos box (euid 0 is refused first); routes the roll, replace, remove, cancel-drain and probe verbs to the engine after refusing missing arguments file:Lstat@245 fc02f153643366e3407e177cf6950b163a93c1965c4a450597b0674c61007bec |
| +@coverage . 237724e495ec26f7c2521c55f09b6e3e0ed155550a2e32c15dfe1b623840572f |
| +@coverage internal/grouproll 0a391f8041e3f8c78c0ffacbc7abd5fb276aec8f11df05b1aa1bcc52dad3375b |
| @coverage internal/grouprollaws d9bc632b24975cd6e6434b0c23439871a68e4b4659041e6e110ba8b8b5e96ffc |
| @coverage internal/release e8d4983a8b37969c7d4ad9b99facf8332113f12f69c640b0b9624901184c9e54 |
diff --git a/parity/cli.tsv b/parity/cli.tsv| index b9ddb0484..b25509969 100644 |
| --- a/parity/cli.tsv |
| +++ b/parity/cli.tsv |
| @@ -253,6 +253,11 @@ system group abandon operator - - - - - |
| system group cancel-drain operator - - - - - |
| system group close-lost operator - - - - - |
| system group plan operator - - - - - |
| +system group probe abandon operator - - - - - |
| +system group probe close-lost operator - - - - - |
| +system group probe resume operator - - - - - |
| +system group probe start operator - - - - - |
| +system group probe status operator - - - - - |
| system group remove operator - - - - - |
| system group replace operator - - - - - |
| system group resume operator - - - - - |
diff --git a/parity/parity.tsv b/parity/parity.tsv| index 6f96e2f3d..44a67d125 100644 |
| --- a/parity/parity.tsv |
| +++ b/parity/parity.tsv |
| @@ -210,7 +210,7 @@ op-system-layout operator operator system layout status ; system layout migrate |
| op-system-geoip operator operator system geoip publish ; system geoip status ; system geoip off The platform GeoIP database. |
| op-system-cutovers operator operator system seeds-floor publish ; system legacy-routes assign ; system lifetimes cutover ; system hosts-used status One-off cutovers and floors. |
| op-system-roles operator operator system box role ; system group role Box and group roles. |
| -op-system-group-roll operator operator system group plan ; system group status ; system group roll ; system group resume ; system group rollback ; system group return ; system group abandon ; system group close-lost ; system group replace ; system group remove ; system group cancel-drain Group maintenance from an operator machine. |
| +op-system-group-roll operator operator system group plan ; system group status ; system group roll ; system group resume ; system group rollback ; system group return ; system group abandon ; system group close-lost ; system group replace ; system group remove ; system group cancel-drain ; system group probe start ; system group probe resume ; system group probe status ; system group probe abandon ; system group probe close-lost Group maintenance from an operator machine. |
| op-system-demos operator operator system demos status ; system demos serving ; system demos takedown ; system demos takedown-status ; system demos reports ; system demos reports resolve Demo serving, takedowns and reports. |
| op-system-managed-fleets operator operator system managed-fleets show ; system managed-fleets set The managed-fleet catalog. |
diff --git a/region_ha_boundary_test.go b/region_ha_boundary_test.go| index 6668df725..9a7cf2a05 100644 |
| --- a/region_ha_boundary_test.go |
| +++ b/region_ha_boundary_test.go |
| @@ -57,6 +57,7 @@ var regionHACoreFiles = []string{ |
| "internal/grouproll/floor.go", |
| "internal/grouproll/roll.go", |
| "internal/grouproll/depart.go", |
| + "internal/grouproll/probe.go", |
| "internal/release/systemlookup.go", |
| } |
diff --git a/system_group.go b/system_group.go| index 9c3db0711..72ac3f75a 100644 |
| --- a/system_group.go |
| +++ b/system_group.go |
| @@ -20,8 +20,11 @@ import ( |
| ) |
| // carlos system group plan|status|roll|resume|rollback|return|abandon| |
| -// close-lost|replace|remove|cancel-drain (group roll verb spec §3-§4): the |
| -// script scripts/region-group-roll.py's main, ported. It runs on an |
| +// close-lost|replace|remove|cancel-drain, and the Standby observation |
| +// probe's carlos system group probe start|resume|status|abandon|close-lost |
| +// (group roll verb spec §3-§4, V7): the scripts |
| +// scripts/region-group-roll.py's and scripts/region-group-probe.py's main, |
| +// ported. It runs on an |
| // operator machine as the deployment's operator account, takes flags only, |
| // and works from the group config file alone: it never opens a console |
| // session, reads the CLI's saved login or falls back to a default |
| @@ -83,6 +86,30 @@ func runSystemGroupCancelDrain(args []string) { |
| os.Exit(runSystemGroup("cancel-drain", args)) |
| } |
| +// The probe's leaves, and its branch with no leaf word. |
| +func runSystemGroupProbeStart(args []string) { os.Exit(runSystemGroup("probe start", args)) } |
| +func runSystemGroupProbeResume(args []string) { os.Exit(runSystemGroup("probe resume", args)) } |
| +func runSystemGroupProbeStatus(args []string) { os.Exit(runSystemGroup("probe status", args)) } |
| +func runSystemGroupProbeAbandon(args []string) { |
| + os.Exit(runSystemGroup("probe abandon", args)) |
| +} |
| +func runSystemGroupProbeCloseLost(args []string) { |
| + os.Exit(runSystemGroup("probe close-lost", args)) |
| +} |
| +func systemGroupProbeFallback(args, _ []string) { os.Exit(runSystemGroup("probe", args)) } |
| + |
| +// groupProbeHelp is the probe branch alone: its help on stdout for -h, |
| +// else on stderr with the usage status. |
| +func groupProbeHelp(args []string) int { |
| + line := grouproll.Text("help_probe") + "\n" |
| + if len(args) == 1 && (args[0] == "-h" || args[0] == "-help" || args[0] == "--help") { |
| + fmt.Fprint(groupEnv.stdout, line) |
| + return 0 |
| + } |
| + fmt.Fprint(groupEnv.stderr, line) |
| + return 2 |
| +} |
| + |
| // groupFlags are one verb's flags, as the script's argparse declares them. |
| type groupFlags struct { |
| config, attendedBy, member, sha, transaction string |
| @@ -121,9 +148,12 @@ func parseGroupFlags(verb string, args []string) (f groupFlags, rc int, ok bool) |
| fs := flag.NewFlagSet("carlos system group "+verb, flag.ContinueOnError) |
| var out bytes.Buffer |
| fs.SetOutput(&out) |
| - help := verb |
| - if verb == "cancel-drain" { |
| + help := strings.TrimPrefix(verb, "probe ") |
| + switch verb { |
| + case "cancel-drain": |
| help = "cancel_drain" |
| + case "probe start": |
| + help = "probe_probe" |
| } |
| fs.Usage = func() { |
| fmt.Fprintln(&out, grouproll.Text(help)) |
| @@ -132,7 +162,7 @@ func parseGroupFlags(verb string, args []string) (f groupFlags, rc int, ok bool) |
| fs.StringVar(&f.config, "config", "", grouproll.Text("config")) |
| fs.StringVar(&f.attendedBy, "attended-by", "", grouproll.Text("attended")) |
| switch verb { |
| - case "plan", "roll", "rollback", "replace", "remove", "cancel-drain": |
| + case "plan", "roll", "rollback", "replace", "remove", "cancel-drain", "probe start": |
| fs.StringVar(&f.member, "member", "", grouproll.Text("member")) |
| } |
| switch verb { |
| @@ -144,7 +174,8 @@ func parseGroupFlags(verb string, args []string) (f groupFlags, rc int, ok bool) |
| fs.StringVar(&f.transaction, "transaction", "", grouproll.Text("roll_transaction")) |
| case "replace", "remove": |
| fs.StringVar(&f.transaction, "transaction", "", grouproll.Text("depart_transaction")) |
| - case "rollback", "resume", "status", "return", "abandon", "close-lost", "cancel-drain": |
| + case "rollback", "resume", "status", "return", "abandon", "close-lost", "cancel-drain", |
| + "probe resume", "probe status", "probe abandon", "probe close-lost": |
| fs.StringVar(&f.transaction, "transaction", "", grouproll.Text("transaction")) |
| } |
| if err := fs.Parse(args); err != nil { |
| @@ -180,7 +211,7 @@ func checkGroupArgs(verb string, f groupFlags) error { |
| return grouproll.Refusal{Key: "record"} |
| } |
| switch verb { |
| - case "plan", "roll", "rollback", "replace", "remove", "cancel-drain": |
| + case "plan", "roll", "rollback", "replace", "remove", "cancel-drain", "probe start": |
| if f.member == "" { |
| return grouproll.Refusal{Key: "config_invalid"} |
| } |
| @@ -192,7 +223,8 @@ func checkGroupArgs(verb string, f groupFlags) error { |
| } |
| } |
| switch verb { |
| - case "rollback", "resume", "status", "return", "abandon", "close-lost", "cancel-drain": |
| + case "rollback", "resume", "status", "return", "abandon", "close-lost", "cancel-drain", |
| + "probe resume", "probe status", "probe abandon", "probe close-lost": |
| if f.transaction == "" { |
| return grouproll.Refusal{Key: "record"} |
| } |
| @@ -228,6 +260,9 @@ func runSystemGroup(verb string, args []string) int { |
| if _, err := os.Lstat(groupEnv.hostEnv); err == nil || groupEnv.username() == "carlos" { |
| return groupRefused(grouproll.Refusal{Key: "on_box"}) |
| } |
| + if verb == "probe" { |
| + return groupProbeHelp(args) |
| + } |
| f, rc, ok := parseGroupFlags(verb, args) |
| if !ok { |
| return rc |
| @@ -251,8 +286,14 @@ func runSystemGroup(verb string, args []string) int { |
| ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM) |
| defer stop() |
| - if verb == "status" { |
| - if err := grouproll.Status(dir, c, f.transaction, groupEnv.stdout); err != nil { |
| + if verb == "status" || verb == "probe status" { |
| + var err error |
| + if verb == "probe status" { |
| + err = grouproll.ProbeStatus(dir, c, f.transaction, groupEnv.stdout) |
| + } else { |
| + err = grouproll.Status(dir, c, f.transaction, groupEnv.stdout) |
| + } |
| + if err != nil { |
| return groupRefused(err) |
| } |
| return 0 |
| @@ -293,6 +334,14 @@ func runSystemGroup(verb string, args []string) int { |
| err = e.Depart(ctx, f.member, verb, f.transaction) |
| case "cancel-drain": |
| err = e.CancelDrain(ctx, f.member, f.transaction) |
| + case "probe start": |
| + err = e.Probe(ctx, f.member) |
| + case "probe resume": |
| + err = e.ProbeResume(ctx, f.transaction) |
| + case "probe abandon": |
| + err = e.ProbeAbandon(ctx, f.transaction) |
| + case "probe close-lost": |
| + err = e.ProbeCloseLost(ctx, f.transaction) |
| default: |
| err = grouproll.Refusal{Key: "unsupported"} |
| } |
diff --git a/system_group_test.go b/system_group_test.go| index 890d13e9e..c2ec4d625 100644 |
| --- a/system_group_test.go |
| +++ b/system_group_test.go |
| @@ -14,6 +14,7 @@ import ( |
| "strings" |
| "testing" |
| + "github.com/carlosframework/platform/internal/clireg" |
| "github.com/carlosframework/platform/internal/grouproll" |
| "github.com/carlosframework/platform/internal/grouprollaws" |
| ) |
| @@ -394,3 +395,131 @@ func TestCLIAttendedByFallback(t *testing.T) { |
| t.Fatalf("flag: %q", got) |
| } |
| } |
| + |
| +// The probe leaves (region_group_probe_test.py's argv checks and |
| +// test_probe_root_and_attendance_required): root and an unattended run |
| +// are refused first; probe start needs --member and the others |
| +// --transaction (refused before any state, config or provider); with |
| +// their arguments every leaf but status reaches the provider after the |
| +// shared files and isolation, and status builds none. Help names each |
| +// leaf's approved text; the branch alone prints the probe's help. |
| +func TestCLIProbeLeaves(t *testing.T) { |
| + h := newGroupHarness(t) |
| + groupEnv.geteuid = func() int { return 0 } |
| + if rc := h.run("probe start", "--config", h.config, "--member", "i-0123456789abcdef0"); rc != 1 || |
| + h.stderr.String() != h.refused("root_refused") || len(h.steps) != 0 { |
| + t.Fatalf("root: rc %d stderr %q", rc, h.stderr.String()) |
| + } |
| + h = newGroupHarness(t) |
| + if rc := h.run("probe start", "--config", h.config, "--member", "i-0123456789abcdef0"); rc != 1 || |
| + h.stderr.String() != h.refused("attended_required") || len(h.steps) != 0 { |
| + t.Fatalf("attended: rc %d stderr %q", rc, h.stderr.String()) |
| + } |
| + refusals := []struct { |
| + verb string |
| + args []string |
| + key string |
| + }{ |
| + {"probe start", nil, "config_invalid"}, |
| + {"probe start", []string{"--transaction", "t"}, ""}, |
| + {"probe resume", nil, "record"}, |
| + {"probe status", nil, "record"}, |
| + {"probe abandon", nil, "record"}, |
| + {"probe close-lost", nil, "record"}, |
| + {"probe resume", []string{"--member", "i-0123456789abcdef0"}, ""}, |
| + } |
| + for _, c := range refusals { |
| + h := newGroupHarness(t) |
| + args := append([]string{"--config", h.config, "--attended-by", "op"}, c.args...) |
| + rc := h.run(c.verb, args...) |
| + if c.key == "" { |
| + // A flag the leaf does not take is a usage error. |
| + if rc != 2 || len(h.steps) != 0 { |
| + t.Errorf("%s %v: rc %d stderr %q", c.verb, c.args, rc, h.stderr.String()) |
| + } |
| + continue |
| + } |
| + if rc != 1 || h.stderr.String() != h.refused(c.key) || len(h.steps) != 0 { |
| + t.Errorf("%s %v: rc %d stderr %q steps %v", c.verb, c.args, rc, h.stderr.String(), h.steps) |
| + } |
| + } |
| + for verb, args := range map[string][]string{ |
| + "probe start": {"--member", "i-0123456789abcdef0"}, "probe resume": {"--transaction", "probe-t"}, |
| + "probe abandon": {"--transaction", "probe-t"}, "probe close-lost": {"--transaction", "probe-t"}, |
| + } { |
| + h := newGroupHarness(t) |
| + if err := os.MkdirAll(filepath.Join(groupEnv.getenv("HOME"), ".local", "state", "carlos", "group"), 0o700); err != nil { |
| + t.Fatal(err) |
| + } |
| + rc := h.run(verb, append([]string{"--config", h.config, "--attended-by", "op"}, args...)...) |
| + want := []string{"shared-files", "isolate example"} |
| + if rc != 1 || len(h.steps) < 2 || !reflect.DeepEqual(h.steps[:2], want) { |
| + t.Errorf("%s: rc %d steps %v stderr %q", verb, rc, h.steps, h.stderr.String()) |
| + continue |
| + } |
| + if len(h.steps) == 3 && h.stderr.String() != h.refused("api") { |
| + t.Errorf("%s: stderr %q", verb, h.stderr.String()) |
| + } |
| + } |
| + h = newGroupHarness(t) |
| + if rc := h.run("probe status", "--config", h.config, "--attended-by", "op", "--transaction", "absent"); rc != 1 { |
| + t.Fatalf("status: rc %d", rc) |
| + } |
| + for _, s := range h.steps { |
| + if s == "provider" { |
| + t.Fatalf("probe status built a provider: %v", h.steps) |
| + } |
| + } |
| + for verb, key := range map[string]string{"probe start": "probe_probe", "probe resume": "resume", |
| + "probe status": "status", "probe abandon": "abandon", "probe close-lost": "close-lost"} { |
| + h := newGroupHarness(t) |
| + out := "" |
| + if rc := h.run(verb, "-h"); rc == 0 { |
| + out = h.stdout.String() |
| + } |
| + flag := "-transaction" |
| + if verb == "probe start" { |
| + flag = "-member" |
| + } |
| + if !strings.HasPrefix(out, grouproll.Text(key)+"\n") || !strings.Contains(out, flag) || |
| + strings.Contains(out, "-to-sha256") { |
| + t.Errorf("%s help: %q", verb, out) |
| + } |
| + } |
| + h = newGroupHarness(t) |
| + if rc := h.run("probe"); rc != 2 || h.stderr.String() != grouproll.Text("help_probe")+"\n" || len(h.steps) != 0 { |
| + t.Fatalf("branch: rc %d stderr %q", rc, h.stderr.String()) |
| + } |
| + h = newGroupHarness(t) |
| + if rc := h.run("probe", "-h"); rc != 0 || h.stdout.String() != grouproll.Text("help_probe")+"\n" { |
| + t.Fatalf("branch help: rc %d stdout %q", rc, h.stdout.String()) |
| + } |
| + h = newGroupHarness(t) |
| + groupEnv.geteuid = func() int { return 0 } |
| + if rc := h.run("probe"); rc != 1 || h.stderr.String() != h.refused("root_refused") { |
| + t.Fatalf("branch as root: rc %d stderr %q", rc, h.stderr.String()) |
| + } |
| +} |
| + |
| +// The registry routes system group probe's five leaves. |
| +func TestCLIProbeRegistry(t *testing.T) { |
| + var probe *clireg.Node |
| + for _, n := range systemGroupCommand().Children { |
| + if n.Name == "probe" { |
| + probe = n |
| + } |
| + } |
| + if probe == nil || probe.Fallback == nil || probe.Golden.Skip == "" { |
| + t.Fatalf("probe branch %+v", probe) |
| + } |
| + var names []string |
| + for _, n := range probe.Children { |
| + if n.Run == nil || n.Audience != clireg.Operator || n.Golden.Skip == "" { |
| + t.Errorf("leaf %+v", n) |
| + } |
| + names = append(names, n.Name) |
| + } |
| + if want := []string{"start", "resume", "status", "abandon", "close-lost"}; !reflect.DeepEqual(names, want) { |
| + t.Fatalf("leaves %v", names) |
| + } |
| +} |
diff --git a/system_roles.go b/system_roles.go| index eb0dd66f1..7a2c9128c 100644 |
| --- a/system_roles.go |
| +++ b/system_roles.go |
| @@ -143,11 +143,30 @@ func systemGroupCommand() *clireg.Node { |
| noHint(skipGolden(raw("replace", clireg.Operator, runSystemGroupReplace), groupVerbGolden)), |
| noHint(skipGolden(raw("remove", clireg.Operator, runSystemGroupRemove), groupVerbGolden)), |
| noHint(skipGolden(raw("cancel-drain", clireg.Operator, runSystemGroupCancelDrain), groupVerbGolden)), |
| + systemGroupProbeCommand(), |
| }, |
| Fallback: systemRolesFallback, |
| } |
| } |
| +// systemGroupProbeCommand is `carlos system group probe`, the Standby |
| +// observation probe (system_group.go). Its branch alone refuses root and |
| +// carlos boxes first too, then prints the probe's help. |
| +func systemGroupProbeCommand() *clireg.Node { |
| + return noHint(skipGolden(&clireg.Node{ |
| + Name: "probe", |
| + Audience: clireg.Operator, |
| + Children: []*clireg.Node{ |
| + noHint(skipGolden(raw("start", clireg.Operator, runSystemGroupProbeStart), groupVerbGolden)), |
| + noHint(skipGolden(raw("resume", clireg.Operator, runSystemGroupProbeResume), groupVerbGolden)), |
| + noHint(skipGolden(raw("status", clireg.Operator, runSystemGroupProbeStatus), groupVerbGolden)), |
| + noHint(skipGolden(raw("abandon", clireg.Operator, runSystemGroupProbeAbandon), groupVerbGolden)), |
| + noHint(skipGolden(raw("close-lost", clireg.Operator, runSystemGroupProbeCloseLost), groupVerbGolden)), |
| + }, |
| + Fallback: systemGroupProbeFallback, |
| + }, groupVerbGolden)) |
| +} |
| + |
| func runSystemBoxRole(rest []string) { |
| box, role, consoleFlag := roleArgs(rest) |
| sess := requireDeployAPISession(consoleFlag) |
diff --git a/testdata/clireg-golden.jsonl b/testdata/clireg-golden.jsonl| index e93d9f294..81fd0258c 100644 |
| --- a/testdata/clireg-golden.jsonl |
| +++ b/testdata/clireg-golden.jsonl |
| @@ -807,6 +807,7 @@ |
| {"case":"system group cancel-drain | skipped","skipped":"refuses root and carlos boxes before it reads its arguments, -h included"} |
| {"case":"system group close-lost | skipped","skipped":"refuses root and carlos boxes before it reads its arguments, -h included"} |
| {"case":"system group plan | skipped","skipped":"refuses root and carlos boxes before it reads its arguments, -h included"} |
| +{"case":"system group probe | skipped","skipped":"refuses root and carlos boxes before it reads its arguments, -h included"} |
| {"case":"system group remove | skipped","skipped":"refuses root and carlos boxes before it reads its arguments, -h included"} |
| {"case":"system group replace | skipped","skipped":"refuses root and carlos boxes before it reads its arguments, -h included"} |
| {"case":"system group resume | skipped","skipped":"refuses root and carlos boxes before it reads its arguments, -h included"} |