carlos / platform Public

group verb: read each bucket in its own region

The flagship's deployment bucket is in eu-west-1 and its US group in
us-east-1. The adapter read every bucket through one client on the
config region, and S3 answers the wrong region with a 301 the SDK does
not follow, so plan refused every edges read with the generic "AWS
response unavailable". The script's aws CLI followed the redirect.

Bucket(name) now resolves each bucket's region once per process with an
unsigned HeadBucket (the x-amz-bucket-region header, as manager's
GetBucketRegion does) and reads through a client on that region's
endpoint. An unresolved or malformed region, and a 301 after resolution,
are Uncertain(bucket_region) naming the bucket, never Uncertain(api).
Edges files, locks, data-bucket listings and release pointers all go
through Bucket, so they are all covered.

Also: a required flag left out (bare "plan") prints the verb's usage and
exits 2, as argparse did; a required flag given empty is still refused.

New text bucket_region is not yet copy-reviewed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude pushed by paul@keymail.dev 1af30ff49a9cddbce55edb2c908308c60ffe5d39 parent a5225f7
9 files changed, +364 −39
  • internal/grouproll/box.go +12 −3
  • internal/grouproll/text.go +1 −0
  • internal/grouproll/text_test.go +4 −3
  • internal/grouprollaws/group.go +13 −1
  • internal/grouprollaws/objects.go +124 −6
  • internal/grouprollaws/objects_test.go +125 −5
  • internal/grouprollaws/recorder_test.go +7 −1
  • system_group.go +29 −0
  • system_group_test.go +49 −20

CI cancelled — superseded by a newer push — run details

diff --git a/internal/grouproll/box.go b/internal/grouproll/box.go
index 8da092302..679f1315f 100644
--- a/internal/grouproll/box.go
+++ b/internal/grouproll/box.go
@@ -93,11 +93,17 @@ type Box interface {
type Uncertain struct {
Key string
Timeout bool
- ExitCode *int // set for a failed provider process (the script's api case)
- OutputTooLarge bool // the provider's answer exceeded the 4 MiB output cap
+ ExitCode *int // set for a failed provider process (the script's api case)
+ OutputTooLarge bool // the provider's answer exceeded the 4 MiB output cap
+ Bucket string // bucket_region: the bucket whose region is unknown
}
-func (u Uncertain) Error() string { return Text(u.Key) }
+func (u Uncertain) Error() string {
+ if u.Key == "bucket_region" {
+ return Text(u.Key, "bucket", u.Bucket)
+ }
+ return Text(u.Key)
+}
// Details is the script's exc.details, as the error row records it.
func (u Uncertain) Details() map[string]any {
@@ -112,6 +118,9 @@ func (u Uncertain) Details() map[string]any {
// An SDK adapter has no process exit code, only the cap.
d["output_too_large"] = true
}
+ if u.Bucket != "" {
+ d["bucket"] = u.Bucket
+ }
return d
}
diff --git a/internal/grouproll/text.go b/internal/grouproll/text.go
index c9a1b8e54..73f35af1e 100644
--- a/internal/grouproll/text.go
+++ b/internal/grouproll/text.go
@@ -73,6 +73,7 @@ var text = map[string]string{
"hook": "The immutable launch hook must have a 900-second ABANDON default",
"remote": "The command on the member returned no complete result",
"api": "An AWS response is unavailable or invalid",
+ "bucket_region": "The AWS region of bucket {bucket} is unknown or has changed",
"rollback_refused": "Rollback requires this transaction's consumed apply in Standby",
"rollback_digest": "The installed artifact does not match the recorded old or new digest",
"unsupported": "Unsupported operation",
diff --git a/internal/grouproll/text_test.go b/internal/grouproll/text_test.go
index e82abd1c3..389429b8d 100644
--- a/internal/grouproll/text_test.go
+++ b/internal/grouproll/text_test.go
@@ -14,9 +14,10 @@ var placeholderPattern = regexp.MustCompile(`\{([a-z_]+)\}`)
func TestTextRendersEveryKey(t *testing.T) {
// 139 approved, plus floor_fixed_missing, floor_fixed_boxes,
// floor_fixed_both, drain_peers_many, floor_legacy and floor_population
- // (held floor capability, 2026-11-10), not yet copy-reviewed.
- if len(text) != 145 {
- t.Fatalf("text has %d keys, want the 139 approved plus 6", len(text))
+ // (held floor capability, 2026-11-10), and bucket_region (a bucket in
+ // another region than the group, 2026-11-10), not yet copy-reviewed.
+ if len(text) != 146 {
+ t.Fatalf("text has %d keys, want the 139 approved plus 7", len(text))
}
for key, raw := range text {
var args []string
diff --git a/internal/grouprollaws/group.go b/internal/grouprollaws/group.go
index bff9a5e13..78c6791b5 100644
--- a/internal/grouprollaws/group.go
+++ b/internal/grouprollaws/group.go
@@ -12,6 +12,7 @@ import (
"regexp"
"strconv"
"strings"
+ "sync"
"time"
"unicode/utf8"
@@ -53,8 +54,14 @@ type Adapter struct {
ec2 ec2Ops
ssm ssmOps
sts *sts.Client
- s3 *s3.Client // objects.go: edges files, locks, release pointers
+ s3 *s3.Client // objects.go: the config region's client; it resolves bucket regions
plugin pluginCheck // session.go: the plugin's path and version, once
+
+ // objects.go: each bucket's resolved region, and a client per other
+ // region (edges files, locks, release pointers).
+ bucketsMu sync.Mutex
+ bucketRegion map[string]string
+ regionS3 map[string]*s3.Client
}
func newAdapter(cfg aws.Config, c grouproll.Config) *Adapter {
@@ -154,6 +161,11 @@ func call[T any](parent context.Context, fn func(context.Context) (T, error)) (T
if parent.Err() != nil {
return zero, parent.Err()
}
+ // The adapter's own answer (objects.go's bucket_region) stands.
+ var own grouproll.Uncertain
+ if errors.As(err, &own) {
+ return zero, own
+ }
if errors.Is(err, errOutputTooLarge) {
return zero, grouproll.Uncertain{Key: "api", OutputTooLarge: true}
}
diff --git a/internal/grouprollaws/objects.go b/internal/grouprollaws/objects.go
index 5927954c4..33bf0cf68 100644
--- a/internal/grouprollaws/objects.go
+++ b/internal/grouprollaws/objects.go
@@ -2,9 +2,14 @@ package grouprollaws
import (
"context"
+ "errors"
+ "net/http"
+ "regexp"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/s3"
+ "github.com/aws/smithy-go/middleware"
+ smithyhttp "github.com/aws/smithy-go/transport/http"
"github.com/carlosframework/platform/internal/grouproll"
"github.com/carlosframework/platform/internal/release"
@@ -27,31 +32,144 @@ func newS3(cfg aws.Config) *s3.Client {
// pointers), the script's s3api get-object and list-objects-v2: each read
// is bounded as every provider call is, every failure (a missing object
// too) is Uncertain(api), and the store has no write path.
+//
+// A bucket may live in another region than the group: the flagship's
+// deployment bucket is in eu-west-1 and its US group in us-east-1. S3
+// answers a request sent to the wrong region's endpoint with a 301 that the
+// SDK does not follow (the script's aws CLI did). So each bucket is read
+// through a client on its own region's endpoint, the region resolved once
+// per process from HeadBucket's x-amz-bucket-region header. A region that
+// cannot be resolved, and a 301 after resolution, are Uncertain(bucket_region)
+// naming the bucket, never the generic api answer.
func (a *Adapter) Bucket(name string) release.Store {
- return readStore{s: &release.S3Store{Client: a.s3, Bucket: name}}
+ return readStore{a: a, bucket: name}
}
-type readStore struct{ s *release.S3Store }
+// bucketRegionHeader is S3's own region answer, on a 200, a 301 and a 403
+// alike.
+const bucketRegionHeader = "X-Amz-Bucket-Region"
+
+// awsRegion is the config's region shape (grouproll configRegion).
+var awsRegion = regexp.MustCompile(`^[a-z]{2}(?:-[a-z]+)+-[0-9]$`)
+
+// bucketClient is the client for bucket's region, resolving the region on
+// the first read of that bucket.
+func (a *Adapter) bucketClient(ctx context.Context, bucket string) (*s3.Client, error) {
+ a.bucketsMu.Lock()
+ defer a.bucketsMu.Unlock()
+ region, ok := a.bucketRegion[bucket]
+ if !ok {
+ got, err := call(ctx, func(ctx context.Context) (string, error) { return headBucketRegion(ctx, a.s3, bucket) })
+ if err != nil {
+ var u grouproll.Uncertain
+ if ctx.Err() != nil || (errors.As(err, &u) && (u.Timeout || u.OutputTooLarge)) {
+ return nil, err
+ }
+ return nil, grouproll.Uncertain{Key: "bucket_region", Bucket: bucket}
+ }
+ if !awsRegion.MatchString(got) {
+ return nil, grouproll.Uncertain{Key: "bucket_region", Bucket: bucket}
+ }
+ if a.bucketRegion == nil {
+ a.bucketRegion = map[string]string{}
+ }
+ region = got
+ a.bucketRegion[bucket] = region
+ }
+ if region == a.cfg.Region {
+ return a.s3, nil
+ }
+ if c, ok := a.regionS3[region]; ok {
+ return c, nil
+ }
+ cfg := a.cfg.Copy()
+ cfg.Region = region
+ c := newS3(cfg)
+ if a.regionS3 == nil {
+ a.regionS3 = map[string]*s3.Client{}
+ }
+ a.regionS3[region] = c
+ return c, nil
+}
+
+// headBucketRegion is the feature/s3/manager GetBucketRegion recipe: an
+// unsigned HeadBucket (no IAM grant is needed, and a signature for the
+// wrong region could not be checked) whose answer, whatever its status,
+// carries the bucket's region in a header.
+func headBucketRegion(ctx context.Context, client *s3.Client, bucket string) (string, error) {
+ var region string
+ capture := middleware.DeserializeMiddlewareFunc("CarlosBucketRegion", func(ctx context.Context,
+ in middleware.DeserializeInput, next middleware.DeserializeHandler) (middleware.DeserializeOutput, middleware.Metadata, error) {
+ out, md, err := next.HandleDeserialize(ctx, in)
+ if r, ok := out.RawResponse.(*smithyhttp.Response); ok && r != nil && r.Response != nil {
+ region = r.Header.Get(bucketRegionHeader)
+ }
+ return out, md, err
+ })
+ _, err := client.HeadBucket(ctx, &s3.HeadBucketInput{Bucket: aws.String(bucket)}, func(o *s3.Options) {
+ o.Credentials = nil
+ o.APIOptions = append(o.APIOptions, func(st *middleware.Stack) error {
+ return st.Deserialize.Add(capture, middleware.After)
+ })
+ })
+ if region != "" {
+ return region, nil
+ }
+ if err == nil {
+ err = errNoBucketRegion
+ }
+ return "", err
+}
+
+var errNoBucketRegion = errors.New("grouprollaws: no bucket region in the answer")
+
+// movedBucket reports S3's wrong-region answer: a 301 (PermanentRedirect).
+func movedBucket(err error) bool {
+ var status interface{ HTTPStatusCode() int }
+ return errors.As(err, &status) && status.HTTPStatusCode() == http.StatusMovedPermanently
+}
+
+type readStore struct {
+ a *Adapter
+ bucket string
+}
type object struct {
body []byte
etag string
}
+// read runs fn on bucket's regional store, as one bounded provider call.
+func read[T any](ctx context.Context, r readStore, fn func(context.Context, *release.S3Store) (T, error)) (T, error) {
+ var zero T
+ c, err := r.a.bucketClient(ctx, r.bucket)
+ if err != nil {
+ return zero, err
+ }
+ store := &release.S3Store{Client: c, Bucket: r.bucket}
+ return call(ctx, func(ctx context.Context) (T, error) {
+ out, err := fn(ctx, store)
+ if err != nil && movedBucket(err) {
+ return out, grouproll.Uncertain{Key: "bucket_region", Bucket: r.bucket}
+ }
+ return out, err
+ })
+}
+
func (r readStore) Get(ctx context.Context, key string) ([]byte, string, error) {
- out, err := call(ctx, func(ctx context.Context) (object, error) {
- b, etag, err := r.s.Get(ctx, key)
+ out, err := read(ctx, r, func(ctx context.Context, s *release.S3Store) (object, error) {
+ b, etag, err := s.Get(ctx, key)
return object{b, etag}, err
})
return out.body, out.etag, err
}
func (r readStore) List(ctx context.Context, prefix string) ([]string, error) {
- return call(ctx, func(ctx context.Context) ([]string, error) { return r.s.List(ctx, prefix) })
+ return read(ctx, r, func(ctx context.Context, s *release.S3Store) ([]string, error) { return s.List(ctx, prefix) })
}
func (r readStore) ListDirs(ctx context.Context, prefix string) ([]string, error) {
- return call(ctx, func(ctx context.Context) ([]string, error) { return r.s.ListDirs(ctx, prefix) })
+ return read(ctx, r, func(ctx context.Context, s *release.S3Store) ([]string, error) { return s.ListDirs(ctx, prefix) })
}
func (readStore) Put(context.Context, string, []byte, string) (string, error) {
diff --git a/internal/grouprollaws/objects_test.go b/internal/grouprollaws/objects_test.go
index ab6dcaee5..68f1b7938 100644
--- a/internal/grouprollaws/objects_test.go
+++ b/internal/grouprollaws/objects_test.go
@@ -9,20 +9,53 @@ import (
"testing"
"github.com/carlosframework/platform/internal/grouproll"
+ "github.com/carlosframework/platform/internal/release"
)
-// s3Recorder answers S3 REST requests: GETs of objects, nothing else.
+// s3Recorder answers S3 REST requests as S3 does: an unsigned HeadBucket
+// on any region's endpoint gets a 403 naming the bucket's region (region,
+// default the test config's eu-west-1; headStatus and noRegion vary it),
+// a request on another region's endpoint gets the 301 PermanentRedirect
+// the SDK does not follow, and GETs of objects get status and body.
type s3Recorder struct {
- mu sync.Mutex
- reqs []*http.Request
- status int
- body string
+ mu sync.Mutex
+ reqs []*http.Request // every request but the HeadBuckets
+ heads []*http.Request
+ status int
+ body string
+ region string
+ headStatus int
+ noRegion bool
}
func (r *s3Recorder) Do(req *http.Request) (*http.Response, error) {
+ region := r.region
+ if region == "" {
+ region = "eu-west-1"
+ }
+ header := http.Header{"Content-Type": []string{"application/xml"}}
+ if !r.noRegion {
+ header.Set("X-Amz-Bucket-Region", region)
+ }
+ if req.Method == http.MethodHead {
+ r.mu.Lock()
+ r.heads = append(r.heads, req)
+ r.mu.Unlock()
+ status := r.headStatus
+ if status == 0 {
+ status = 403
+ }
+ return &http.Response{StatusCode: status, Status: http.StatusText(status), Header: header,
+ Body: io.NopCloser(bytes.NewReader(nil)), Request: req}, nil
+ }
r.mu.Lock()
r.reqs = append(r.reqs, req)
r.mu.Unlock()
+ if !strings.Contains(req.URL.Host, "s3."+region+".amazonaws.com") {
+ body := `<Error><Code>PermanentRedirect</Code><Message>x</Message><Endpoint>b.s3.` + region + `.amazonaws.com</Endpoint></Error>`
+ return &http.Response{StatusCode: 301, Status: http.StatusText(301), Header: header,
+ Body: io.NopCloser(bytes.NewReader([]byte(body))), Request: req}, nil
+ }
status, body := r.status, r.body
if status != 200 && body == "" {
body = `<Error><Code>NoSuchKey</Code><Message>x</Message></Error>`
@@ -81,3 +114,90 @@ func TestBucketReadsOnly(t *testing.T) {
}
var _ grouproll.Objects = testAdapterWith(t, rec)
}
+
+// The flagship's shape: the group in us-east-1, its deployment bucket in
+// eu-west-1. The bucket's region is resolved once, by one unsigned
+// HeadBucket, and every read of it goes to the eu-west-1 endpoint signed
+// for eu-west-1; a bucket in the config's own region uses the config's
+// client.
+func TestBucketReadsCrossRegion(t *testing.T) {
+ rec := &s3Recorder{status: 200, body: `{"v":1}`, region: "eu-west-1"}
+ a := testAdapterIn(t, rec, "us-east-1")
+ store := a.Bucket("carlos-flagship-store")
+ for _, key := range []string{"control/edges/g-1.json", "control/edges/g-2.json"} {
+ body, _, err := store.Get(ctx, key)
+ if err != nil || string(body) != `{"v":1}` {
+ t.Fatalf("Get %s = %q, %v", key, body, err)
+ }
+ }
+ if _, err := a.Bucket("carlos-flagship-store").List(ctx, "control/edges/"); err != nil {
+ t.Fatalf("List: %v", err)
+ }
+ if len(rec.heads) != 1 {
+ t.Fatalf("HeadBuckets = %d, want one per bucket per process", len(rec.heads))
+ }
+ h := rec.heads[0]
+ if !strings.HasPrefix(h.URL.Host, "carlos-flagship-store.s3.us-east-1.amazonaws.com") || h.Header.Get("Authorization") != "" {
+ t.Fatalf("HeadBucket = %s (Authorization %q), want unsigned on the config region",
+ h.URL.Host, h.Header.Get("Authorization"))
+ }
+ for _, q := range rec.reqs {
+ if !strings.HasPrefix(q.URL.Host, "carlos-flagship-store.s3.eu-west-1.amazonaws.com") ||
+ !strings.Contains(q.Header.Get("Authorization"), "/eu-west-1/s3/aws4_request") {
+ t.Fatalf("read %s %s signed %q, want the bucket's region", q.Method, q.URL.Host, q.Header.Get("Authorization"))
+ }
+ }
+ // A bucket in the config's region: resolved the same way, read there.
+ same := &s3Recorder{status: 200, body: `{}`, region: "us-east-1"}
+ if _, _, err := testAdapterIn(t, same, "us-east-1").Bucket("carlos-data-us").Get(ctx, "k"); err != nil {
+ t.Fatalf("same-region Get: %v", err)
+ }
+ if q := same.reqs[0]; !strings.HasPrefix(q.URL.Host, "carlos-data-us.s3.us-east-1.amazonaws.com") {
+ t.Fatalf("same-region read went to %s", q.URL.Host)
+ }
+}
+
+// A 301 is never the generic api answer: an unresolvable region and a
+// wrong-region answer after resolution are Uncertain(bucket_region) naming
+// the bucket, for Get, List and ListDirs alike.
+func TestBucketRegionNeverSilent(t *testing.T) {
+ reads := map[string]func(release.Store) error{
+ "Get": func(s release.Store) error { _, _, err := s.Get(ctx, "k"); return err },
+ "List": func(s release.Store) error { _, err := s.List(ctx, "p/"); return err },
+ "ListDirs": func(s release.Store) error { _, err := s.ListDirs(ctx, "p/"); return err },
+ }
+ want := func(t *testing.T, what string, err error) {
+ t.Helper()
+ u := uncertainKey(t, err)
+ if u.Key != "bucket_region" || u.Bucket != "carlos-flagship-store" || u.Timeout {
+ t.Fatalf("%s: %+v, want bucket_region naming the bucket", what, u)
+ }
+ if got := err.Error(); !strings.Contains(got, "carlos-flagship-store") {
+ t.Fatalf("%s: text %q does not name the bucket", what, got)
+ }
+ if d := u.Details(); d["bucket"] != "carlos-flagship-store" {
+ t.Fatalf("%s: details %v", what, d)
+ }
+ }
+ for name, fn := range reads {
+ // No region in the HeadBucket answer: refused before any read.
+ rec := &s3Recorder{status: 200, noRegion: true}
+ want(t, name+" unresolved", fn(testAdapterIn(t, rec, "us-east-1").Bucket("carlos-flagship-store")))
+ if len(rec.reqs) != 0 {
+ t.Fatalf("%s: %d reads sent with no region", name, len(rec.reqs))
+ }
+ // A malformed region is not trusted either.
+ rec = &s3Recorder{status: 200, region: "eu-west-1/../x"}
+ want(t, name+" malformed", fn(testAdapterIn(t, rec, "us-east-1").Bucket("carlos-flagship-store")))
+ // Resolved, then S3 answers 301 (the region moved or was wrong).
+ rec = &s3Recorder{status: 200, region: "eu-west-1"}
+ a := testAdapterIn(t, rec, "us-east-1")
+ a.bucketRegion = map[string]string{"carlos-flagship-store": "eu-central-1"}
+ want(t, name+" 301", fn(a.Bucket("carlos-flagship-store")))
+ }
+ // The resolution's other failures keep their meaning: a HeadBucket
+ // that answers 500 with no region is bucket_region, not api.
+ rec := &s3Recorder{headStatus: 500, noRegion: true}
+ _, _, err := testAdapterIn(t, rec, "us-east-1").Bucket("carlos-flagship-store").Get(ctx, "k")
+ want(t, "head 500", err)
+}
diff --git a/internal/grouprollaws/recorder_test.go b/internal/grouprollaws/recorder_test.go
index 2258087d2..d10eea93f 100644
--- a/internal/grouprollaws/recorder_test.go
+++ b/internal/grouprollaws/recorder_test.go
@@ -147,9 +147,15 @@ func testAdapter(t *testing.T, rec *recorder) *Adapter {
}
func testAdapterWith(t *testing.T, h aws.HTTPClient) *Adapter {
+ t.Helper()
+ return testAdapterIn(t, h, "eu-west-1")
+}
+
+// testAdapterIn is testAdapterWith with the config's region.
+func testAdapterIn(t *testing.T, h aws.HTTPClient, region string) *Adapter {
t.Helper()
cfg := aws.Config{
- Region: "eu-west-1",
+ Region: region,
Credentials: credentials.NewStaticCredentialsProvider("AKIATEST", "secret", ""),
HTTPClient: h,
RetryMaxAttempts: 1,
diff --git a/system_group.go b/system_group.go
index 72ac3f75a..d4a79ae11 100644
--- a/system_group.go
+++ b/system_group.go
@@ -189,6 +189,18 @@ func parseGroupFlags(verb string, args []string) (f groupFlags, rc int, ok bool)
if fs.NArg() > 0 {
return f, groupRefused(grouproll.Refusal{Key: "usage_positional", Args: map[string]string{"arg": fs.Arg(0)}}), false
}
+ // A required flag left out is argparse's usage error: the verb's usage
+ // on stderr, status 2. A required flag given empty is refused below, as
+ // the script refused it.
+ given := map[string]bool{}
+ fs.Visit(func(fl *flag.Flag) { given[fl.Name] = true })
+ for _, name := range requiredGroupFlags(verb) {
+ if !given[name] {
+ fs.Usage()
+ groupEnv.stderr.Write(out.Bytes())
+ return f, 2, false
+ }
+ }
if f.config == "" {
return f, groupRefused(grouproll.Refusal{Key: "config_required"}), false
}
@@ -199,6 +211,23 @@ func parseGroupFlags(verb string, args []string) (f groupFlags, rc int, ok bool)
return f, 0, true
}
+// requiredGroupFlags are verb's flags the script's argparse declared
+// required=True (the probe verbs follow their checkGroupArgs needs).
+func requiredGroupFlags(verb string) []string {
+ switch verb {
+ case "plan", "roll":
+ return []string{"member", "to-sha256"}
+ case "replace", "remove", "probe start":
+ return []string{"member"}
+ case "rollback", "cancel-drain":
+ return []string{"member", "transaction"}
+ case "resume", "status", "return", "abandon", "close-lost",
+ "probe resume", "probe status", "probe abandon", "probe close-lost":
+ return []string{"transaction"}
+ }
+ return nil
+}
+
// checkGroupArgs refuses a verb's missing or malformed arguments before
// any state, config or provider is touched: a chosen roll transaction id
// the drain and fence verbs could not take (the script's main checked it
diff --git a/system_group_test.go b/system_group_test.go
index c2ec4d625..6b94b31d2 100644
--- a/system_group_test.go
+++ b/system_group_test.go
@@ -303,35 +303,64 @@ func TestCLIGroupLeaves(t *testing.T) {
args []string
key string
}{
- {"roll", sha, "config_invalid"},
- {"roll", member, "config_invalid"},
- {"plan", member, "config_invalid"},
- {"rollback", tx, "config_invalid"},
- {"rollback", member, "record"},
- {"resume", nil, "record"},
- {"return", nil, "record"},
- {"abandon", nil, "record"},
- {"close-lost", nil, "record"},
+ {"roll", sha, "usage"},
+ {"roll", member, "usage"},
+ {"plan", member, "usage"},
+ {"rollback", tx, "usage"},
+ {"rollback", member, "usage"},
+ {"resume", nil, "usage"},
+ {"return", nil, "usage"},
+ {"abandon", nil, "usage"},
+ {"close-lost", nil, "usage"},
{"roll", join(member, sha, []string{"--transaction", ""}), "record"},
{"roll", join(member, sha, []string{"--transaction", "probe-x"}), "record"},
{"roll", join(member, sha, []string{"--transaction", "../escape"}), "record"},
{"roll", join(member, sha, []string{"--transaction", strings.Repeat("x", 81)}), "record"},
// replace, remove and cancel-drain (DepartArgvTests.test_transaction_ids).
- {"replace", nil, "config_invalid"},
- {"remove", tx, "config_invalid"},
+ {"replace", nil, "usage"},
+ {"remove", tx, "usage"},
{"replace", join(member, []string{"--transaction", "-leading"}), "record"},
{"replace", join(member, []string{"--transaction=probe-x"}), "record"},
{"remove", join(member, []string{"--transaction", ""}), "record"},
- {"cancel-drain", tx, "config_invalid"},
- {"cancel-drain", member, "record"},
+ {"cancel-drain", tx, "usage"},
+ {"cancel-drain", member, "usage"},
}
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 == "usage" {
+ // A required flag left out: the verb's usage, status 2.
+ if rc != 2 || !strings.Contains(h.stderr.String(), "-member") && !strings.Contains(h.stderr.String(), "-transaction") ||
+ strings.Contains(h.stderr.String(), grouproll.Text("refused", "reason", "")) || len(h.steps) != 0 {
+ t.Errorf("%s %v: rc %d stderr %q steps %v", c.verb, c.args, rc, h.stderr.String(), h.steps)
+ }
+ 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)
+ }
+ }
+ // A required flag given empty is still refused, as the script refused it.
+ for _, c := range []struct {
+ verb string
+ args []string
+ key string
+ }{
+ {"plan", join([]string{"--member", ""}, sha), "config_invalid"},
+ {"plan", join(member, []string{"--to-sha256", ""}), "config_invalid"},
+ {"resume", []string{"--transaction", ""}, "record"},
+ } {
h := newGroupHarness(t)
args := append([]string{"--config", h.config, "--attended-by", "op"}, c.args...)
if rc := h.run(c.verb, args...); 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)
}
}
+ // The bare verb (the operator's first try) prints its usage.
+ if h := newGroupHarness(t); h.run("plan") != 2 || !strings.Contains(h.stderr.String(), grouproll.Text("plan")) {
+ t.Errorf("bare plan: stderr %q", h.stderr.String())
+ }
state := func(h *groupHarness) {
if err := os.MkdirAll(filepath.Join(groupEnv.getenv("HOME"), ".local", "state", "carlos", "group"), 0o700); err != nil {
t.Fatal(err)
@@ -420,20 +449,20 @@ func TestCLIProbeLeaves(t *testing.T) {
args []string
key string
}{
- {"probe start", nil, "config_invalid"},
+ {"probe start", nil, "usage"},
{"probe start", []string{"--transaction", "t"}, ""},
- {"probe resume", nil, "record"},
- {"probe status", nil, "record"},
- {"probe abandon", nil, "record"},
- {"probe close-lost", nil, "record"},
+ {"probe resume", nil, "usage"},
+ {"probe status", nil, "usage"},
+ {"probe abandon", nil, "usage"},
+ {"probe close-lost", nil, "usage"},
{"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 c.key == "" || c.key == "usage" {
+ // A flag the leaf does not take, or a required one left out, 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())
}