carlos / platform Public

Regional domains (#447) Task 9: regional readiness and the CLI write

carlos domains placements --set region=instance (repeatable, sent in
order and as typed), --wildcard and --catchall (sent only when named,
fs.Visit, a usage error without --set). With --set: the PUT, then RD-15
and the same view as the read. domainSetPlacements reads a bare 404 as
a console without the door (RD-16) and the 409 that carries "verify"
(proof pending, nothing written) as placementsProofError (RD-43), which
the verb prints with the TXT record to publish. Usage gains RD-1 and the
placements verb; flag help RD-2 to RD-4. New draft deck rows RD-42 (a
--set without "=") and RD-43.

Tests: TestRunDomainsPlacementsSendsTheWholeSet,
TestRunDomainsPlacementsCapabilityFlagsSentOnlyWhenNamed,
TestRunDomainsPlacementsPrintsRegionalView,
TestAPISessionDomainPlacementsSet, TestRunDomainsPlacementsAgainstAnOlderConsole
(subprocess: RD-16, and proof pending), usage-error rows.
Mutation: without the bare-404 branch the older-console tests fail.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev b892cd42447a12406bdec735e5e3835dae12e11f parent 9ef198a
4 files changed, +410 −4
  • apimode.go +61 −0
  • docs/superpowers/plans/2026-10-28-regional-domains-447-copy.md +2 −0
  • domains_cli.go +83 −4
  • domains_cli_test.go +264 −0
diff --git a/apimode.go b/apimode.go
index 68d21cd71..57428bb44 100644
--- a/apimode.go
+++ b/apimode.go
@@ -4705,6 +4705,67 @@ func (s *apiSession) domainPlacements(ctx context.Context, a apiAcct, app, host
return res, nil
}
+// apiPlacementIn is one binding the placements PUT sends: a region as the
+// member named it and the instance hostname that serves the domain there.
+type apiPlacementIn struct {
+ Region string `json:"region"`
+ Host string `json:"host"`
+}
+
+// placementsOldConsoleMsg (RD-16, draft) is the placements PUT's answer from
+// a console without the door: the mux's bare 404, no JSON error.
+const placementsOldConsoleMsg = "this console does not support regional domains yet."
+
+// placementsProofError is the placements PUT's 409 when the hostname's
+// proof of control is pending: the console wrote nothing and sent the TXT
+// record to publish (Verify) instead of an error sentence.
+type placementsProofError struct {
+ Host string
+ Verify *apiDomainDNSRecord
+}
+
+// Error is RD-43 (draft); the CLI prints the record after it.
+func (e *placementsProofError) Error() string {
+ return fmt.Sprintf("prove you control %s first. add this TXT record, then run the same command again.", e.Host)
+}
+
+// domainSetPlacements is the placements PUT (#447): the whole set, in the
+// order given and as typed, and the two capabilities only when named
+// (nil is not sent). The answer is the placements GET's body. A bare 404 is
+// a console that predates the door (RD-16); a 409 carrying "verify" is
+// proof pending, as *placementsProofError.
+func (s *apiSession) domainSetPlacements(ctx context.Context, a apiAcct, app, host string, set []apiPlacementIn, wildcard, catchall *bool) (apiPlacements, error) {
+ in := struct {
+ Placements []apiPlacementIn `json:"placements"`
+ Wildcard *bool `json:"wildcard,omitempty"`
+ Catchall *bool `json:"catchall,omitempty"`
+ }{set, wildcard, catchall}
+ status, body, err := s.putJSON(ctx, apiPath(a, app, "/domains/"+url.PathEscape(host)+"/placements"), in)
+ if err != nil {
+ return apiPlacements{}, err
+ }
+ switch {
+ case status == http.StatusNotFound && !hasJSONError(body):
+ return apiPlacements{}, errors.New(placementsOldConsoleMsg)
+ case status == http.StatusConflict && !hasJSONError(body):
+ var proof struct {
+ Verified *bool `json:"verified"`
+ Verify *apiDomainDNSRecord `json:"verify"`
+ }
+ if json.Unmarshal(body, &proof) == nil && proof.Verified != nil && !*proof.Verified && proof.Verify != nil {
+ return apiPlacements{}, &placementsProofError{Host: host, Verify: proof.Verify}
+ }
+ return apiPlacements{}, apiErrorFromBody(status, body)
+ case status != http.StatusOK:
+ return apiPlacements{}, apiErrorFromBody(status, body)
+ }
+ var res apiPlacements
+ if err := json.Unmarshal(body, &res); err != nil {
+ return apiPlacements{}, fmt.Errorf("domains placements: unreadable response: %w", err)
+ }
+ return res, nil
+}
+
// shipTimeout bounds ship's own context — generous on purpose. The console
// gives itself up to 10 minutes to read the request body and 2 minutes to
// store it (internal/console/apicli.go), well past the 30s absolute Timeout
diff --git a/docs/superpowers/plans/2026-10-28-regional-domains-447-copy.md b/docs/superpowers/plans/2026-10-28-regional-domains-447-copy.md
index 7fbbdb99a..4e10a4ed1 100644
--- a/docs/superpowers/plans/2026-10-28-regional-domains-447-copy.md
+++ b/docs/superpowers/plans/2026-10-28-regional-domains-447-copy.md
@@ -63,6 +63,8 @@ count.
| RD-14 | domains_cli.go | another route uses this hostname, so no region is ready. | draft |
| RD-15 | domains_cli.go | <host> now serves from one instance in each of <n> regions. | draft |
| RD-16 | domains_cli.go | this console does not support regional domains yet. | draft |
+| RD-42 | domains_cli.go | write each --set as region=instance, like uk=shop-uk.example.net | draft |
+| RD-43 | apimode.go | prove you control <host> first. add this TXT record, then run the same command again. | draft |
## Console refusals a member sees
diff --git a/domains_cli.go b/domains_cli.go
index c488d7ede..2d14e56e8 100644
--- a/domains_cli.go
+++ b/domains_cli.go
@@ -9,6 +9,7 @@ package main
import (
"context"
+ "errors"
"flag"
"fmt"
"log"
@@ -18,7 +19,7 @@ import (
"time"
)
-const domainsUsage = `usage: carlos domains <attach|verify|detach|list|paths> [flags]
+const domainsUsage = `usage: carlos domains <attach|verify|detach|list|paths|placements> [flags]
attach --app <a> [--route <r>] [--wildcard] [--catchall] [--platform] [flags] <hostname>
claim a customer's hostname for the app, pointed at
@@ -51,6 +52,14 @@ const domainsUsage = `usage: carlos domains <attach|verify|detach|list|paths> [f
by, as PUBLISHED. Read-only: the platform that owns the
hostname republishes the whole map, so there is no verb
here that writes one.
+ placements --app <a> [--set <region>=<instance>]... [--wildcard] [--catchall] [flags] <hostname>
+ without --set, shows which instance serves the hostname in
+ each region, whether it is ready, and the addresses to
+ point DNS at. with --set, makes the hostname a regional
+ domain: each region serves it from the instance named for
+ it, and never sends it to another region. give the whole
+ set every time. --wildcard and --catchall take effect only
+ when the domain is created.
--account <a> account (sqid or name; default "ops")
--account-id <id> account sqid, matched as a sqid ONLY
@@ -77,7 +86,7 @@ const domainsListUsage = `usage: carlos domains list --app <a> [--account <a>] [
const domainsPathsUsage = `usage: carlos domains paths --app <a> [--account <a>] [--account-id <id>] [--console <origin>] <hostname>
`
-const domainsPlacementsUsage = `usage: carlos domains placements --app <a> [--account <a>] [--account-id <id>] [--console <origin>] <hostname>
+const domainsPlacementsUsage = `usage: carlos domains placements --app <a> [--set <region>=<instance>]... [--wildcard] [--catchall] [--account <a>] [--account-id <id>] [--console <origin>] <hostname>
`
// runDomains dispatches the domains sub-verbs. attach/detach/list are
@@ -468,10 +477,16 @@ func runDomainsPaths(args []string) {
// runDomainsPlacements prints one hostname's placements (#447): per region,
// the instance that serves it, whether the region is ready, and the
// addresses of the boxes that count toward that, which are the addresses to
-// point DNS at. Read only; --set comes with the regional claim.
+// point DNS at. With --set it first replaces the whole set (the PUT), and
+// creates the regional domain if there is none, then prints the view the
+// console answers with.
func runDomainsPlacements(args []string) {
fs := flag.NewFlagSet("domains placements", flag.ExitOnError)
app := appFlag(fs, "app the hostname belongs to")
+ var set placementSet
+ fs.Var(&set, "set", "a region and the instance that serves the hostname there, as region=instance. repeat it for each region")
+ wildcard := fs.Bool("wildcard", false, "use one wildcard certificate for the domain. set only when the domain is created, and needs a CNAME. the message says which if it is missing")
+ catchall := fs.Bool("catchall", false, "also serve every one-label name under the domain from the same instances. set only when the domain is created, and needs --wildcard")
consoleFlag := consoleOption(fs, "console to read through (default: the only logged-in one)")
acctRaw := fs.String("account", "", "account (sqid or name) the app belongs to (default: your only account, or the configured/chosen one)")
acctIDRaw := fs.String("account-id", "", "account sqid, matched as a sqid ONLY — supersedes --account")
@@ -481,17 +496,81 @@ func runDomainsPlacements(args []string) {
if host == "" || fs.NArg() > 1 {
log.Fatal(domainsPlacementsUsage)
}
+ // Sent only when named, as attach sends them (fs.Visit sees only the
+ // flags on the command line), so an explicit false is a real false.
+ var wildcardArg, catchallArg *bool
+ fs.Visit(func(f *flag.Flag) {
+ switch f.Name {
+ case "wildcard":
+ v := *wildcard
+ wildcardArg = &v
+ case "catchall":
+ v := *catchall
+ catchallArg = &v
+ }
+ })
+ // The capabilities belong to the write; a read would ignore them.
+ if len(set) == 0 && (wildcardArg != nil || catchallArg != nil) {
+ log.Fatal(domainsPlacementsUsage)
+ }
sess := requireAPISession("placements", *consoleFlag)
printUsing(stdout, sess)
acct := resolvedAccount(sess, acctRaw, acctIDRaw)
app2 := resolvedApp(sess, acct, *app, domainsPlacementsUsage)
- pl, err := sess.domainPlacements(context.Background(), acct, app2, host)
+ ctx := context.Background()
+ if len(set) == 0 {
+ pl, err := sess.domainPlacements(ctx, acct, app2, host)
+ if err != nil {
+ log.Fatalf("domains placements: %v", err)
+ }
+ printPlacements(pl)
+ return
+ }
+ pl, err := sess.domainSetPlacements(ctx, acct, app2, host, set, wildcardArg, catchallArg)
+ var proof *placementsProofError
+ if errors.As(err, &proof) {
+ // Nothing was written: the PUT never stores a claim unproven, so
+ // the next step is this command again, not domains verify.
+ fmt.Fprintln(stdout, proof.Error())
+ if proof.Verify.Name != "" {
+ fmt.Fprintf(stdout, "Add: TXT %s -> %s\n", proof.Verify.Name, proof.Verify.Value)
+ }
+ os.Exit(1)
+ }
if err != nil {
log.Fatalf("domains placements: %v", err)
}
+ fmt.Fprintln(stdout, fmt.Sprintf("%s now serves from one instance in each of %d regions.", pl.Host, len(pl.Placements)))
printPlacements(pl)
}
+// placementSet is --set: each value a region=instance pair, kept in the
+// order given and exactly as typed. The console normalises and judges
+// them (a region named twice is its refusal, RD-18), so the CLI only
+// splits; a value with no "=" is a usage error.
+type placementSet []apiPlacementIn
+
+func (p *placementSet) String() string {
+ if p == nil {
+ return ""
+ }
+ pairs := make([]string, 0, len(*p))
+ for _, b := range *p {
+ pairs = append(pairs, b.Region+"="+b.Host)
+ }
+ return strings.Join(pairs, ",")
+}
+
+func (p *placementSet) Set(v string) error {
+ region, host, ok := strings.Cut(v, "=")
+ if !ok {
+ // RD-42 (draft).
+ return errors.New("write each --set as region=instance, like uk=shop-uk.example.net")
+ }
+ *p = append(*p, apiPlacementIn{Region: region, Host: host})
+ return nil
+}
+
// printPlacements prints the placements GET: the claim's mode line (RD-6 or
// RD-7), the table (RD-5), each region that is not ready with its reason
// (RD-9 to RD-14), then the DNS line (RD-8) when any region is ready.
diff --git a/domains_cli_test.go b/domains_cli_test.go
index b842db0a4..b7505cd20 100644
--- a/domains_cli_test.go
+++ b/domains_cli_test.go
@@ -12,6 +12,7 @@ package main
import (
"context"
"encoding/json"
+ "errors"
"net/http"
"net/http/httptest"
"os/exec"
@@ -282,6 +283,12 @@ type fakeDomainsConsole struct {
// lastPlacementsPath records the URL it was asked for.
placements map[string]any
lastPlacementsPath string
+ // The placements PUT: the body it was sent, raw by key so a test can
+ // tell an absent key from a false one, and its answer. putStatus 0 is
+ // 200 with placements; putBody, when set, is written verbatim.
+ lastPlacementsPut map[string]json.RawMessage
+ putStatus int
+ putBody string
}
func newFakeDomainsConsole(t *testing.T) *fakeDomainsConsole {
@@ -310,6 +317,18 @@ func newFakeDomainsConsole(t *testing.T) *fakeDomainsConsole {
case r.Method == http.MethodDelete:
fc.lastDetachPath = r.URL.Path
json.NewEncoder(w).Encode(map[string]any{"host": "x", "removed": fc.detachRemoved})
+ case r.Method == http.MethodPut && strings.HasSuffix(r.URL.Path, "/placements"):
+ fc.lastPlacementsPath = r.URL.Path
+ fc.lastPlacementsPut = nil
+ json.NewDecoder(r.Body).Decode(&fc.lastPlacementsPut)
+ if fc.putStatus != 0 {
+ w.WriteHeader(fc.putStatus)
+ }
+ if fc.putBody != "" {
+ w.Write([]byte(fc.putBody))
+ return
+ }
+ json.NewEncoder(w).Encode(fc.placements)
case r.Method == http.MethodGet && strings.HasSuffix(r.URL.Path, "/placements"):
fc.lastPlacementsPath = r.URL.Path
json.NewEncoder(w).Encode(fc.placements)
@@ -731,6 +750,15 @@ func TestDomainsCLIUsageErrors(t *testing.T) {
{"list no app", []string{"domains", "list"}, "no deployment target configured"},
{"paths no app", []string{"domains", "paths", "ti.to"}, "no deployment target configured"},
{"paths no positional host", []string{"domains", "paths", "-app", "tito"}, "usage: carlos domains paths"},
+ {"placements no positional host", []string{"domains", "placements", "-app", "tito"}, "usage: carlos domains placements"},
+ // A --set value is region=instance; without the "=" it is refused
+ // before anything is sent (RD-42).
+ {"placements set without =", []string{"domains", "placements", "-app", "tito", "-set", "shop-uk.example.net", "shop.example.com"},
+ "write each --set as region=instance, like uk=shop-uk.example.net"},
+ // The capabilities take effect only with --set: on a read they
+ // would be ignored, so naming one there is a usage error.
+ {"placements wildcard without set", []string{"domains", "placements", "-app", "tito", "-wildcard", "shop.example.com"},
+ "usage: carlos domains placements"},
} {
t.Run(tc.name, func(t *testing.T) {
out, err := run(tc.args...)
@@ -908,3 +936,239 @@ func TestRunDomainsPlacementsPrintsTheReason(t *testing.T) {
t.Fatalf("stdout tells the member to point DNS with no ready region:\n%s", out)
}
}
+
+// regionalPlacementsAnswer is a regional claim's placements body: ie ready
+// from annie, uk not ready with no serving box.
+func regionalPlacementsAnswer() map[string]any {
+ return map[string]any{
+ "host": "shop.example.com", "mode": "regional", "route": "shop-ie.example.net",
+ "placements": []map[string]any{
+ {"region": "ie", "target": "shop-ie.example.net", "ready": true,
+ "boxes": []map[string]any{{"box": "annie", "eip": "203.0.113.10", "aws_region": "eu-west-1", "release": "v0.31.0", "counted": true}}},
+ {"region": "uk", "target": "shop-uk.example.net", "ready": false, "reason": "no-serving-box", "boxes": []any{}},
+ },
+ }
+}
+
+// TestRunDomainsPlacementsSendsTheWholeSet (Review Focus 3): every --set is
+// sent in the order given and exactly as typed, the same region twice
+// included (the console refuses that, RD-18, not the CLI); no capability
+// key is sent when no flag is named. The answer prints RD-15 and the view.
+func TestRunDomainsPlacementsSendsTheWholeSet(t *testing.T) {
+ fc := domainsCLIFixture(t)
+ fc.placements = regionalPlacementsAnswer()
+ buf := captureStdout(t)
+
+ runDomains([]string{"placements", "-app", "tito", "-account", "bab",
+ "-set", "uk=shop-uk.example.net", "-set", "IE=Shop-IE.example.net", "-set", "uk=other.example.net", "shop.example.com"})
+
+ if fc.lastPlacementsPath != "/api/cli/apps/bab/tito/domains/shop.example.com/placements" {
+ t.Fatalf("PUT path = %q", fc.lastPlacementsPath)
+ }
+ var set []map[string]string
+ if err := json.Unmarshal(fc.lastPlacementsPut["placements"], &set); err != nil {
+ t.Fatalf("placements %s: %v", fc.lastPlacementsPut["placements"], err)
+ }
+ want := []map[string]string{
+ {"region": "uk", "host": "shop-uk.example.net"},
+ {"region": "IE", "host": "Shop-IE.example.net"},
+ {"region": "uk", "host": "other.example.net"},
+ }
+ if len(set) != len(want) {
+ t.Fatalf("placements sent = %v, want %v", set, want)
+ }
+ for i := range want {
+ if set[i]["region"] != want[i]["region"] || set[i]["host"] != want[i]["host"] || len(set[i]) != 2 {
+ t.Fatalf("placements sent = %v, want %v", set, want)
+ }
+ }
+ if _, ok := fc.lastPlacementsPut["wildcard"]; ok {
+ t.Fatalf("body = %v, want no wildcard key", fc.lastPlacementsPut)
+ }
+ if _, ok := fc.lastPlacementsPut["catchall"]; ok {
+ t.Fatalf("body = %v, want no catchall key", fc.lastPlacementsPut)
+ }
+ out := buf.String()
+ for _, line := range []string{
+ "shop.example.com now serves from one instance in each of 2 regions.",
+ "shop.example.com is a regional domain. each region serves it from its own instance.",
+ } {
+ if !strings.Contains(out, line) {
+ t.Fatalf("stdout missing %q:\n%s", line, out)
+ }
+ }
+ if strings.Index(out, "now serves") > strings.Index(out, "is a regional domain") {
+ t.Fatalf("RD-15 comes after the view:\n%s", out)
+ }
+}
+
+// TestRunDomainsPlacementsCapabilityFlagsSentOnlyWhenNamed: --wildcard and
+// --catchall are sent only when named, an explicit false as false, as
+// attach sends them.
+func TestRunDomainsPlacementsCapabilityFlagsSentOnlyWhenNamed(t *testing.T) {
+ fc := domainsCLIFixture(t)
+ fc.placements = regionalPlacementsAnswer()
+ captureStdout(t)
+ base := []string{"placements", "-app", "tito", "-account", "bab", "-set", "ie=shop-ie.example.net"}
+ for _, c := range []struct {
+ name string
+ flags []string
+ wildcard, catchall string // "" absent
+ }{
+ {"neither", nil, "", ""},
+ {"wildcard", []string{"-wildcard"}, "true", ""},
+ {"wildcard false", []string{"-wildcard=false"}, "false", ""},
+ {"catchall", []string{"-catchall"}, "", "true"},
+ {"both", []string{"-wildcard", "-catchall"}, "true", "true"},
+ } {
+ runDomains(append(append(append([]string{}, base...), c.flags...), "shop.example.com"))
+ for key, want := range map[string]string{"wildcard": c.wildcard, "catchall": c.catchall} {
+ got, ok := fc.lastPlacementsPut[key]
+ if (want == "") == ok || (ok && string(got) != want) {
+ t.Errorf("%s: %s = %s (present %v), want %q", c.name, key, got, ok, want)
+ }
+ }
+ }
+}
+
+// TestRunDomainsPlacementsPrintsRegionalView: the read of a regional claim
+// prints RD-6, a row per region, the reason line of the region that is not
+// ready, and RD-8 because one is.
+func TestRunDomainsPlacementsPrintsRegionalView(t *testing.T) {
+ fc := domainsCLIFixture(t)
+ fc.placements = regionalPlacementsAnswer()
+ buf := captureStdout(t)
+
+ runDomains([]string{"placements", "-app", "tito", "-account", "bab", "shop.example.com"})
+
+ if fc.lastPlacementsPut != nil {
+ t.Fatalf("a read sent a PUT: %v", fc.lastPlacementsPut)
+ }
+ out := buf.String()
+ for _, want := range []string{
+ "shop.example.com is a regional domain. each region serves it from its own instance.",
+ "uk: no server in this region serves shop-uk.example.net yet.",
+ "point DNS for shop.example.com at the addresses of the ready regions, with latency-based routing.",
+ } {
+ if !strings.Contains(out, want) {
+ t.Fatalf("stdout missing %q:\n%s", want, out)
+ }
+ }
+ rows := map[string]string{}
+ for _, line := range strings.Split(out, "\n") {
+ if f := strings.Fields(line); len(f) == 4 {
+ rows[f[0]] = strings.Join(f, " ")
+ }
+ }
+ if rows["ie"] != "ie shop-ie.example.net yes 203.0.113.10" || rows["uk"] != "uk shop-uk.example.net no -" {
+ t.Fatalf("rows = %v:\n%s", rows, out)
+ }
+ if strings.Contains(out, "now serves") {
+ t.Fatalf("a read printed RD-15:\n%s", out)
+ }
+}
+
+// TestAPISessionDomainPlacementsSet: the PUT's wire shape, its answer, and
+// the two refusals the CLI reads itself: a bare 404 (a console without the
+// door, Review Focus 5) is RD-16, and the 409 that carries "verify" (proof
+// pending, no claim written) comes back with the record to publish.
+func TestAPISessionDomainPlacementsSet(t *testing.T) {
+ var (
+ status int
+ body string
+ got map[string]json.RawMessage
+ method string
+ )
+ ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ method = r.Method
+ got = nil
+ json.NewDecoder(r.Body).Decode(&got)
+ if status != 0 {
+ w.WriteHeader(status)
+ }
+ w.Write([]byte(body))
+ }))
+ defer ts.Close()
+ s := newTestSession(ts.URL)
+ ctx := context.Background()
+ tru := true
+ set := []apiPlacementIn{{Region: "ie", Host: "shop-ie.example.net"}}
+
+ body = `{"host":"shop.example.com","mode":"regional","route":"shop-ie.example.net","placements":[{"region":"ie","target":"shop-ie.example.net","ready":false,"reason":"settling","boxes":[]}]}`
+ pl, err := s.domainSetPlacements(ctx, apiAcct{Seg: "bab"}, "shop", "shop.example.com", set, &tru, nil)
+ if err != nil || method != http.MethodPut || pl.Mode != "regional" || len(pl.Placements) != 1 || pl.Placements[0].Reason != "settling" {
+ t.Fatalf("PUT = %s %+v, %v", method, pl, err)
+ }
+ if string(got["wildcard"]) != "true" || got["catchall"] != nil || string(got["placements"]) != `[{"region":"ie","host":"shop-ie.example.net"}]` {
+ t.Fatalf("body = %v", got)
+ }
+
+ status, body = http.StatusNotFound, "404 page not found\n"
+ if _, err := s.domainSetPlacements(ctx, apiAcct{Seg: "bab"}, "shop", "shop.example.com", set, nil, nil); err == nil ||
+ err.Error() != "this console does not support regional domains yet." {
+ t.Fatalf("bare 404 = %v, want RD-16", err)
+ }
+ // A 404 the console wrote itself is its own diagnosis.
+ status, body = http.StatusNotFound, `{"error":"no such app"}`
+ if _, err := s.domainSetPlacements(ctx, apiAcct{Seg: "bab"}, "shop", "shop.example.com", set, nil, nil); err == nil || err.Error() != "no such app" {
+ t.Fatalf("JSON 404 = %v, want the console's own error", err)
+ }
+
+ status, body = http.StatusConflict, `{"host":"shop.example.com","route":"shop-ie.example.net","created":false,"verified":false,`+
+ `"verify":{"type":"TXT","name":"_carlos-challenge.shop.example.com","value":"proof-123","ttl":300,"set":"verify"}}`
+ _, err = s.domainSetPlacements(ctx, apiAcct{Seg: "bab"}, "shop", "shop.example.com", set, nil, nil)
+ var proof *placementsProofError
+ if !errors.As(err, &proof) || proof.Verify == nil || proof.Verify.Name != "_carlos-challenge.shop.example.com" || proof.Verify.Value != "proof-123" {
+ t.Fatalf("proof 409 = %v, want the record to publish", err)
+ }
+ // Any other 409 is the console's sentence.
+ status, body = http.StatusConflict, `{"error":"hostname unavailable"}`
+ if _, err := s.domainSetPlacements(ctx, apiAcct{Seg: "bab"}, "shop", "shop.example.com", set, nil, nil); err == nil ||
+ errors.As(err, &proof) || err.Error() != "hostname unavailable" {
+ t.Fatalf("plain 409 = %v", err)
+ }
+}
+
+// TestRunDomainsPlacementsAgainstAnOlderConsole (Review Focus 5): a console
+// that predates the door answers the PUT with the mux's bare 404; the
+// member reads RD-16, not a decode error. Through the real binary, since
+// the verb exits.
+func TestRunDomainsPlacementsAgainstAnOlderConsole(t *testing.T) {
+ bin := buildCarlos(t)
+ fc := newFakeDomainsConsole(t)
+ home := t.TempDir()
+ creds := filepath.Join(home, "credentials")
+ writeTestCredential(t, creds, fc.ts.URL)
+ run := func() (string, error) {
+ cmd := exec.Command(bin, "domains", "placements", "-app", "tito", "-account", "bab",
+ "-set", "ie=shop-ie.example.net", "shop.example.com")
+ cmd.Env = carlosTestEnv(t, "CARLOS_CREDENTIALS="+creds, "CARLOS_DEPLOYMENT_BUCKET=", "CARLOS_DEPLOYMENT_DIR=")
+ cmd.Dir = home
+ out, err := cmd.CombinedOutput()
+ return string(out), err
+ }
+
+ fc.putStatus, fc.putBody = http.StatusNotFound, "404 page not found\n"
+ out, err := run()
+ if err == nil || !strings.Contains(out, "this console does not support regional domains yet.") {
+ t.Fatalf("against an older console: %v\n%s", err, out)
+ }
+
+ // Proof pending: nothing was written, and the member is told which
+ // record to publish and to run the command again.
+ fc.putStatus = http.StatusConflict
+ fc.putBody = `{"host":"shop.example.com","route":"shop-ie.example.net","created":false,"verified":false,` +
+ `"verify":{"type":"TXT","name":"_carlos-challenge.shop.example.com","value":"proof-123","ttl":300,"set":"verify"}}`
+ out, err = run()
+ for _, want := range []string{
+ "prove you control shop.example.com first. add this TXT record, then run the same command again.",
+ "Add: TXT _carlos-challenge.shop.example.com -> proof-123",
+ } {
+ if err == nil || !strings.Contains(out, want) {
+ t.Fatalf("proof pending: %v, output missing %q:\n%s", err, want, out)
+ }
+ }
+ if strings.Contains(out, "carlos domains verify") {
+ t.Fatalf("proof pending points at domains verify, which has no claim to verify:\n%s", out)
+ }
+}