cli: channels digests exits 1 when an account row carries an error
The report still prints in full; the exit status lets a scripted rollout gate fail closed (Fable R3 P3-1). No new message: the report names each account it could not read.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed,
+45
−18
channels_digests.go+15 −11channels_digests_test.go+29 −6commands.go+1 −1
diff --git a/channels_digests.go b/channels_digests.go| index fd168fd65..820827fc5 100644 |
| --- a/channels_digests.go |
| +++ b/channels_digests.go |
| @@ -207,8 +207,10 @@ func runChannelsResign(args []string) { |
| // runChannelsDigests is `carlos channels digests [on|off] [--account-id <sqid>]...`. |
| // Bare, it reports; on and off write or remove the emission marker. Through a |
| // console these are platform-operator doors; direct-store they need the root |
| -// key in CARLOS_RELEASE_KEY and name each account. |
| -func runChannelsDigests(args []string) { |
| +// key in CARLOS_RELEASE_KEY and name each account. An account it could not |
| +// read still prints, and ends the command with exit 1 so a scripted rollout |
| +// gate fails closed. |
| +func runChannelsDigests(args []string) error { |
| fs := flag.NewFlagSet("channels digests", flag.ExitOnError) |
| var ids multiFlag |
| fs.Var(&ids, "account-id", "an account sqid; repeat for several (direct-store: required)") |
| @@ -274,19 +276,21 @@ func runChannelsDigests(args []string) { |
| } |
| } |
| printRepairs(rep, failed) |
| - if len(rep.Channels) == 0 { |
| - if failed { |
| - return |
| + switch { |
| + case len(rep.Channels) > 0: |
| + w := newTable(stdout) |
| + fmt.Fprintln(w, textStatusHeader) |
| + for _, c := range rep.Channels { |
| + fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", c.Account, c.App, c.Channel, c.Version, digestCell(false, c.Straggler)) |
| } |
| + w.Flush() |
| + case !failed: |
| fmt.Fprintln(stdout, textStatusNoneLeft) |
| - return |
| } |
| - w := newTable(stdout) |
| - fmt.Fprintln(w, textStatusHeader) |
| - for _, c := range rep.Channels { |
| - fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", c.Account, c.App, c.Channel, c.Version, digestCell(false, c.Straggler)) |
| + if failed { |
| + return exitCode(1) // the report above names each account it could not read |
| } |
| - w.Flush() |
| + return nil |
| } |
| // checkNamedAccounts is the guard for an operator who named accounts: the |
diff --git a/channels_digests_test.go b/channels_digests_test.go| index 1441277cb..732b9e5ed 100644 |
| --- a/channels_digests_test.go |
| +++ b/channels_digests_test.go |
| @@ -5,6 +5,7 @@ import ( |
| "context" |
| "crypto/ed25519" |
| "encoding/json" |
| + "errors" |
| "fmt" |
| "net/http" |
| "net/http/httptest" |
| @@ -166,7 +167,9 @@ func TestChannelsDigestsAPIMode(t *testing.T) { |
| loginTo(t, ts.URL, "vicky@keymail.dev") |
| buf := captureStdout(t) |
| - runChannelsDigests(nil) |
| + if err := runChannelsDigests(nil); err != nil { |
| + t.Fatalf("a report with no account errors ended with %v", err) |
| + } |
| out := buf.String() |
| for _, want := range []string{ |
| fmt.Sprintf(textStatusOn, "bab", "2026-10-07T00:00:00Z"), |
| @@ -264,8 +267,10 @@ func TestChannelsDigestsAPIModeFailedAccount(t *testing.T) { |
| loginTo(t, ts.URL, "vicky@keymail.dev") |
| buf := captureStdout(t) |
| - runChannelsDigests(nil) |
| + err := runChannelsDigests(nil) |
| out := buf.String() |
| + // Fable R3 P3-1: the report still prints, and a scripted gate fails. |
| + wantExit1(t, err) |
| if want := fmt.Sprintf(textStatusError, "bah", "marker did not verify"); !strings.Contains(out, want) { |
| t.Fatalf("output lacks %q:\n%s", want, out) |
| } |
| @@ -299,10 +304,26 @@ func TestCheckNamedAccounts(t *testing.T) { |
| } |
| func runDigests(t *testing.T, args ...string) string { |
| + t.Helper() |
| + out, _ := runDigestsErr(t, args...) |
| + return out |
| +} |
| + |
| +func runDigestsErr(t *testing.T, args ...string) (string, error) { |
| t.Helper() |
| buf := captureStdout(t) |
| - runChannelsDigests(args) |
| - return buf.String() |
| + err := runChannelsDigests(args) |
| + return buf.String(), err |
| +} |
| + |
| +// wantExit1 is the end of a report with an account it could not read: |
| +// exit 1 and no further message, the report itself said why. |
| +func wantExit1(t *testing.T, err error) { |
| + t.Helper() |
| + var ee *exitError |
| + if !errors.As(err, &ee) || ee.code != 1 || ee.err != nil { |
| + t.Fatalf("an account row carries an error, but the command ended with %v; want exit 1 and no message", err) |
| + } |
| } |
| // Direct-store `channels digests`: bare lists, off removes the marker, on |
| @@ -359,7 +380,8 @@ func TestChannelsDigestsDirectStore(t *testing.T) { |
| if merr == nil { |
| t.Fatal("control: the junk marker verified") |
| } |
| - out = runDigests(t, "--account-id", "bai") |
| + out, err = runDigestsErr(t, "--account-id", "bai") |
| + wantExit1(t, err) |
| if want := fmt.Sprintf(textStatusError, "bai", merr); !strings.Contains(out, want) { |
| t.Fatalf("unverifiable marker (want %q):\n%s", want, out) |
| } |
| @@ -405,7 +427,8 @@ func TestChannelsDigestsDirectStoreUnreadableChannel(t *testing.T) { |
| if cause == "" { |
| t.Fatal("control: the junk pointer read as a channel state") |
| } |
| - out := runDigests(t, "--account-id", "bab") |
| + out, err := runDigestsErr(t, "--account-id", "bab") |
| + wantExit1(t, err) |
| if want := fmt.Sprintf(textStatusError, "bab", cause); !strings.Contains(out, want) { |
| t.Fatalf("output lacks %q:\n%s", want, out) |
| } |
diff --git a/commands.go b/commands.go| index 6e893d059..c1925bb83 100644 |
| --- a/commands.go |
| +++ b/commands.go |
| @@ -315,7 +315,7 @@ func channelsCommand() *clireg.Node { |
| noHint(raw("resign", cust, runChannelsResign)), |
| // digests' on|off counts only as its first argument |
| // (runChannelsDigests): an enum positional of this raw leaf. |
| - noHint(raw("digests", clireg.Operator, runChannelsDigests)), |
| + noHint(rawErr("digests", clireg.Operator, runChannelsDigests)), |
| }, |
| DefaultLeaf: &clireg.Node{Audience: cust, Run: clireg.RawArgs(runChannels)}, |
| DefaultOn: clireg.OnAbsent | clireg.OnFlag | clireg.OnWord, |