group verb: keep timeout/cap on a 301; --config left out is usage
Astra r1: a 301 whose body stalls or overruns the cap keeps the timeout or cap answer (P2); a missing --config prints usage, status 2, as argparse did, and an empty one is still refused (P3). Census re-proposed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5 files changed,
+33
−6
internal/grouprollaws/objects.go+6 −1internal/grouprollaws/objects_test.go+13 −0internal/provision/testdata/plan14-root-reads-group-bucket-region.tsv+2 −2system_group.go+3 −2system_group_test.go+9 −1
CI failed — run details
diff --git a/internal/grouprollaws/objects.go b/internal/grouprollaws/objects.go| index 33bf0cf68..80a880e8c 100644 |
| --- a/internal/grouprollaws/objects.go |
| +++ b/internal/grouprollaws/objects.go |
| @@ -3,6 +3,7 @@ package grouprollaws |
| import ( |
| "context" |
| "errors" |
| + "net" |
| "net/http" |
| "regexp" |
| @@ -149,7 +150,11 @@ func read[T any](ctx context.Context, r readStore, fn func(context.Context, *rel |
| 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) { |
| + // A 301 whose body stalled or overran the cap keeps call's |
| + // timeout or cap answer: only a whole 301 is a wrong region. |
| + var netErr net.Error |
| + if err != nil && movedBucket(err) && !errors.Is(err, errOutputTooLarge) && |
| + !errors.Is(err, context.DeadlineExceeded) && !(errors.As(err, &netErr) && netErr.Timeout()) { |
| return out, grouproll.Uncertain{Key: "bucket_region", Bucket: r.bucket} |
| } |
| return out, err |
diff --git a/internal/grouprollaws/objects_test.go b/internal/grouprollaws/objects_test.go| index 68f1b7938..87f9ae12b 100644 |
| --- a/internal/grouprollaws/objects_test.go |
| +++ b/internal/grouprollaws/objects_test.go |
| @@ -26,6 +26,8 @@ type s3Recorder struct { |
| region string |
| headStatus int |
| noRegion bool |
| + // redirectBody replaces the 301's body (default a PermanentRedirect). |
| + redirectBody string |
| } |
| func (r *s3Recorder) Do(req *http.Request) (*http.Response, error) { |
| @@ -53,6 +55,9 @@ func (r *s3Recorder) Do(req *http.Request) (*http.Response, error) { |
| 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>` |
| + if r.redirectBody != "" { |
| + body = r.redirectBody |
| + } |
| return &http.Response{StatusCode: 301, Status: http.StatusText(301), Header: header, |
| Body: io.NopCloser(bytes.NewReader([]byte(body))), Request: req}, nil |
| } |
| @@ -195,6 +200,14 @@ func TestBucketRegionNeverSilent(t *testing.T) { |
| a.bucketRegion = map[string]string{"carlos-flagship-store": "eu-central-1"} |
| want(t, name+" 301", fn(a.Bucket("carlos-flagship-store"))) |
| } |
| + // A 301 whose body overruns the output cap is the cap's answer, not a |
| + // wrong region (Astra r1 P2). |
| + big := &s3Recorder{status: 200, region: "eu-west-1", redirectBody: strings.Repeat("x", outputCap+1)} |
| + a := testAdapterIn(t, big, "us-east-1") |
| + a.bucketRegion = map[string]string{"carlos-flagship-store": "eu-central-1"} |
| + if _, _, err := a.Bucket("carlos-flagship-store").Get(ctx, "k"); !uncertainKey(t, err).OutputTooLarge { |
| + t.Fatalf("301 over the cap: %v", err) |
| + } |
| // 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} |
diff --git a/internal/provision/testdata/plan14-root-reads-group-bucket-region.tsv b/internal/provision/testdata/plan14-root-reads-group-bucket-region.tsv| index 8b77a9716..c0a9cb82e 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-group-bucket-region.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-group-bucket-region.tsv |
| @@ -1,5 +1,5 @@ |
| # Census overlay group-bucket-region, written by census-propose (#369). census-ruling-group-bucket-region, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-group-bucket-region.md. |
| # 0 body, 0 sites, 3 envelope: each changed unit re-frozen at its existing disposition with its claim appended. |
| -@coverage . 009bc471bb614c6b2ad8b4b287d75b784a906db7db76bdaad33c4ad9de30446a |
| +@coverage . 180b6b00ad6c25822a2474b30fc97e21116c88afa138d3af95ee4ff431f29889 |
| @coverage internal/grouproll 5dd9fe9aa86128357a02395a03d8e700e0b75f2edf1bacf55095531da1964cb0 |
| -@coverage internal/grouprollaws 34a0cb0b30066ec4770362b14f1f2aad9a0b2ed4825ac6abf62d4b739cdf4262 |
| +@coverage internal/grouprollaws 48da80615cbb5b2116dc5e85c31023c9c8a295a45e5e40643fb5daeed92406ef |
diff --git a/system_group.go b/system_group.go| index d4a79ae11..99ee4f914 100644 |
| --- a/system_group.go |
| +++ b/system_group.go |
| @@ -194,7 +194,7 @@ func parseGroupFlags(verb string, args []string) (f groupFlags, rc int, ok bool) |
| // the script refused it. |
| given := map[string]bool{} |
| fs.Visit(func(fl *flag.Flag) { given[fl.Name] = true }) |
| - for _, name := range requiredGroupFlags(verb) { |
| + for _, name := range append([]string{"config"}, requiredGroupFlags(verb)...) { |
| if !given[name] { |
| fs.Usage() |
| groupEnv.stderr.Write(out.Bytes()) |
| @@ -212,7 +212,8 @@ func parseGroupFlags(verb string, args []string) (f groupFlags, rc int, ok bool) |
| } |
| // requiredGroupFlags are verb's flags the script's argparse declared |
| -// required=True (the probe verbs follow their checkGroupArgs needs). |
| +// required=True besides --config, which every verb requires (the probe |
| +// verbs follow their checkGroupArgs needs). |
| func requiredGroupFlags(verb string) []string { |
| switch verb { |
| case "plan", "roll": |
diff --git a/system_group_test.go b/system_group_test.go| index 6b94b31d2..35b97cde9 100644 |
| --- a/system_group_test.go |
| +++ b/system_group_test.go |
| @@ -117,10 +117,18 @@ func TestCLIRefusesRootBoxWindows(t *testing.T) { |
| } |
| }) |
| t.Run("no config", func(t *testing.T) { |
| + // Left out: argparse's usage error (Astra r1 P3). |
| h := newGroupHarness(t) |
| - if rc := h.run("plan", plan[2:]...); rc != 1 || h.stderr.String() != h.refused("config_required") || len(h.steps) != 0 { |
| + if rc := h.run("plan", plan[2:]...); rc != 2 || !strings.Contains(h.stderr.String(), "-config") || |
| + strings.Contains(h.stderr.String(), grouproll.Text("refused", "reason", "")) || len(h.steps) != 0 { |
| t.Fatalf("rc %d stderr %q", rc, h.stderr.String()) |
| } |
| + // Given empty: refused, as before. |
| + h = newGroupHarness(t) |
| + if rc := h.run("plan", append([]string{"--config", ""}, plan[2:]...)...); rc != 1 || |
| + h.stderr.String() != h.refused("config_required") || len(h.steps) != 0 { |
| + t.Fatalf("empty: rc %d stderr %q", rc, h.stderr.String()) |
| + } |
| }) |
| t.Run("attended", func(t *testing.T) { |
| h := newGroupHarness(t) |