cli: carlos domains check --country
Co-Authored-By: Astra (gpt-6-astra) via Codex <noreply@openai.com>
7 files changed,
+144
−13
approved_domains_buy_copy_test.go+6 −3docs/superpowers/notes/census-proposal-domains-check-country.md+11 −0domains_buy_cli.go+19 −6domains_buy_cli_test.go+94 −1domains_buy_copy.go+10 −3internal/provision/testdata/plan14-root-reads-chain.tsv+1 −0internal/provision/testdata/plan14-root-reads-domains-check-country.tsv+3 −0
diff --git a/approved_domains_buy_copy_test.go b/approved_domains_buy_copy_test.go| index 7905454a7..08857340f 100644 |
| --- a/approved_domains_buy_copy_test.go |
| +++ b/approved_domains_buy_copy_test.go |
| @@ -66,9 +66,12 @@ func TestApprovedDomainsBuyCopy(t *testing.T) { |
| {"door.hostUnavailable", "internal/console/apidomains.go", "hostname unavailable"}, |
| {"door.customDomain", "internal/console/plancaps_copy.go", "custom domains need a paid plan. on this plan the app keeps its platform address"}, |
| {"door.planCheckFailed", "internal/console/plancaps_copy.go", "could not check this account's plan. Try again"}, |
| - {"cli.help", "domains_buy_copy.go", " check <name> [flags]\n check availability and the price for one year\n buy <name> --app <a> [--contact-file contact.json] [--yes] [--no-wait] [flags]\n buy a domain and wait for it to serve the app\n\n"}, |
| - {"cli.checkUsage", "domains_buy_copy.go", "usage: carlos domains check <name> [--account <a>] [--account-id <id>] [--console <origin>]\n"}, |
| - {"cli.buyUsage", "domains_buy_copy.go", "usage: carlos domains buy <name> --app <a> [--contact-file contact.json] [--yes] [--no-wait] [--account <a>] [--account-id <id>] [--console <origin>]\n"}, |
| + // approved by delegation (reviewer, 2026-11-03) |
| + {"cli.countryFlag", "domains_buy_copy.go", "country for the price check when no billing currency is set (two letters; overrides the contact file for the check only)"}, |
| + {"cli.countryInvalid", "domains_buy_copy.go", "--country must be two letters a-z"}, |
| + {"cli.help", "domains_buy_copy.go", " check <name> [--country <cc>] [flags]\n check availability and the price for one year\n buy <name> --app <a> [--country <cc>] [--contact-file contact.json] [--yes] [--no-wait] [flags]\n buy a domain and wait for it to serve the app\n\n"}, |
| + {"cli.checkUsage", "domains_buy_copy.go", "usage: carlos domains check <name> [--country <cc>] [--account <a>] [--account-id <id>] [--console <origin>]\n"}, |
| + {"cli.buyUsage", "domains_buy_copy.go", "usage: carlos domains buy <name> --app <a> [--country <cc>] [--contact-file contact.json] [--yes] [--no-wait] [--account <a>] [--account-id <id>] [--console <origin>]\n"}, |
| {"cli.appFlag", "domains_buy_copy.go", "app the domain will serve"}, |
| {"cli.accountFlag", "domains_buy_copy.go", "account (sqid or name)"}, |
| {"cli.accountIDFlag", "domains_buy_copy.go", "account sqid, matched as a sqid only"}, |
diff --git a/docs/superpowers/notes/census-proposal-domains-check-country.md b/docs/superpowers/notes/census-proposal-domains-check-country.md| new file mode 100644 |
| index 000000000..f10edac87 |
| --- /dev/null |
| +++ b/docs/superpowers/notes/census-proposal-domains-check-country.md |
| @@ -0,0 +1,11 @@ |
| +# Census approval: domains-check-country |
| + |
| +Ruling `census-ruling-domains-check-country`. The independent reviewer approves or rejects every change below, 0 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26). |
| + |
| +Envelopes re-pinned: `.`. |
| + |
| +Review: a model from the other family than the author reads the branch's diff against main on the amadan.net remote (`origin` or `amadan`, whichever points at amadan.net) and gives a verdict for every unit and every re-pinned envelope above. For a unit, compare the change with its recorded disposition and basis below; for an envelope, read every changed function in the package and what it reaches. Reject if the change lets root open, run, query or follow anything it did not before from a path or input a tenant, an app or a box agent can create, write or name; if it weakens a check, refusal, validation, argument or environment the basis relies on; or if the diff cannot settle either. Otherwise approve. Record each verdict on #280 with the tip. A rejected unit goes back to the author to correct; nothing escalates to the census owner. |
| + |
| +Seal: `09ad1d7267b9598c64e89ec0faa7b18839c785c5c63905b398afe681cf9777c6` → `09ad1d7267b9598c64e89ec0faa7b18839c785c5c63905b398afe681cf9777c6`. |
| + |
| +Overlay: `internal/provision/testdata/plan14-root-reads-domains-check-country.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`. |
diff --git a/domains_buy_cli.go b/domains_buy_cli.go| index 1b899a0f0..8a9fec61a 100644 |
| --- a/domains_buy_cli.go |
| +++ b/domains_buy_cli.go |
| @@ -33,6 +33,7 @@ func runDomainBuyVerb(args []string, buy bool) { |
| acctRaw := fs.String("account", "", domainsBuyCopy["accountFlag"]) |
| acctID := fs.String("account-id", "", domainsBuyCopy["accountIDFlag"]) |
| console := consoleOption(fs, domainsBuyCopy["consoleFlag"]) |
| + country := fs.String("country", "", domainsBuyCopy["countryFlag"]) |
| var app, contactFile string |
| var yes, noWait bool |
| if buy { |
| @@ -49,18 +50,29 @@ func runDomainBuyVerb(args []string, buy bool) { |
| if len(pos) != 1 || strings.TrimSpace(pos[0]) == "" || (buy && strings.TrimSpace(app) == "") { |
| log.Fatal(usage) |
| } |
| + fs.Visit(func(f *flag.Flag) { |
| + if f.Name == "country" { |
| + if len(*country) != 2 { |
| + log.Fatal(domainsBuyCopy["countryInvalid"]) |
| + } |
| + *country = strings.ToUpper(*country) |
| + if len(*country) != 2 || (*country)[0] < 'A' || (*country)[0] > 'Z' || (*country)[1] < 'A' || (*country)[1] > 'Z' { |
| + log.Fatal(domainsBuyCopy["countryInvalid"]) |
| + } |
| + } |
| + }) |
| sess := requireAPISession(verb, *console) |
| printUsing(stdout, sess) |
| acct := resolvedAccount(sess, acctRaw, acctID) |
| ctx := context.Background() |
| if buy { |
| err = domainsBuy(ctx, sess, acct, strings.TrimSpace(pos[0]), strings.TrimSpace(app), domainBuyOptions{ |
| - yes: yes, noWait: noWait, contactFile: contactFile, |
| + yes: yes, noWait: noWait, contactFile: contactFile, country: *country, |
| in: os.Stdin, out: stdout, terminal: isatty.IsTerminal(os.Stdin.Fd()), |
| now: time.Now, wait: waitDomainBuy, |
| }) |
| } else { |
| - err = domainsCheck(ctx, sess, acct, strings.TrimSpace(pos[0]), stdout) |
| + err = domainsCheck(ctx, sess, acct, strings.TrimSpace(pos[0]), *country, stdout) |
| } |
| if err != nil { |
| log.Fatal(err) |
| @@ -75,8 +87,8 @@ func printDomainQuote(out io.Writer, q domainQuoteResp) { |
| fmt.Fprintf(out, domainsBuyCopy["quote"], q.Domain, availability, plans.FormatMinor(q.Currency, q.Price), strings.ToUpper(q.Currency)) |
| } |
| -func domainsCheck(ctx context.Context, s *apiSession, acct apiAcct, name string, out io.Writer) error { |
| - q, err := s.postDomainCheck(ctx, acct, name, "") |
| +func domainsCheck(ctx context.Context, s *apiSession, acct apiAcct, name, country string, out io.Writer) error { |
| + q, err := s.postDomainCheck(ctx, acct, name, country) |
| if err != nil { |
| return err |
| } |
| @@ -87,6 +99,7 @@ func domainsCheck(ctx context.Context, s *apiSession, acct apiAcct, name string, |
| type domainBuyOptions struct { |
| yes, noWait, terminal bool |
| contactFile string |
| + country string |
| in io.Reader |
| out io.Writer |
| now func() time.Time |
| @@ -102,8 +115,8 @@ func domainsBuy(ctx context.Context, s *apiSession, acct apiAcct, name, app stri |
| return err |
| } |
| } |
| - country := "" |
| - if contact != nil { |
| + country := o.country |
| + if country == "" && contact != nil { |
| country = contact.Country |
| } |
| q, err := s.postDomainCheck(ctx, acct, name, country) |
diff --git a/domains_buy_cli_test.go b/domains_buy_cli_test.go| index bd3ea55e2..057e18be8 100644 |
| --- a/domains_buy_cli_test.go |
| +++ b/domains_buy_cli_test.go |
| @@ -54,7 +54,7 @@ func buyTestOptions(out *bytes.Buffer) domainBuyOptions { |
| func TestDomainsCheckPrintsPrice(t *testing.T) { |
| ts := buyTestServer(t, nil, nil) |
| var out bytes.Buffer |
| - if err := domainsCheck(context.Background(), newTestSession(ts.URL), apiAcct{Seg: "bab"}, "shop.com", &out); err != nil { |
| + if err := domainsCheck(context.Background(), newTestSession(ts.URL), apiAcct{Seg: "bab"}, "shop.com", "", &out); err != nil { |
| t.Fatal(err) |
| } |
| for _, want := range []string{"shop.com", "available", "12.99", "EUR"} { |
| @@ -397,6 +397,99 @@ func TestDomainsCheckCommand(t *testing.T) { |
| } |
| } |
| +func runCheckTestCommand(t *testing.T, base string, args ...string) (string, error) { |
| + t.Helper() |
| + scratch := t.TempDir() |
| + creds := filepath.Join(scratch, "credentials") |
| + writeTestCredential(t, creds, base) |
| + argv := append([]string{"domains", "check", "shop.com", "--account", "bab", "--console", base}, args...) |
| + cmd := exec.Command(buildCarlos(t), argv...) |
| + cmd.Dir = scratch |
| + cmd.Env = carlosTestEnv(t, "CARLOS_CREDENTIALS="+creds, "CARLOS_DEPLOYMENT_BUCKET=", "CARLOS_DEPLOYMENT_DIR=", "CARLOS_CONFIG=") |
| + out, err := cmd.CombinedOutput() |
| + return string(out), err |
| +} |
| + |
| +func TestDomainsCheckCountryFlag(t *testing.T) { |
| + for _, country := range []string{"IE", "ie", "iE"} { |
| + t.Run(country, func(t *testing.T) { |
| + checks := 0 |
| + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| + checks++ |
| + var in struct{ Name, Country string } |
| + if err := json.NewDecoder(r.Body).Decode(&in); err != nil { |
| + t.Error(err) |
| + } |
| + if r.Method != "POST" || r.URL.Path != buyTestPath+"/check" || in.Name != "shop.com" || in.Country != "IE" { |
| + t.Errorf("unexpected request: %s %s %+v", r.Method, r.URL.Path, in) |
| + } |
| + fmt.Fprint(w, `{"domain":"shop.com","available":true,"price":1299,"currency":"eur"}`) |
| + })) |
| + defer ts.Close() |
| + out, err := runCheckTestCommand(t, ts.URL, "--country", country) |
| + if err != nil || checks != 1 || !strings.Contains(out, "EUR") { |
| + t.Fatalf("checks=%d err=%v output=%s", checks, err, out) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +func TestDomainsCountryFlagInvalidBeforeRequest(t *testing.T) { |
| + for _, verb := range []string{"check", "buy"} { |
| + for _, country := range []string{"", "I", "IRL", "I1", "1E", "I-", " IE", "IE ", "É", "ıe"} { |
| + t.Run(verb+"/"+country, func(t *testing.T) { |
| + requests := 0 |
| + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| + requests++ |
| + http.Error(w, "unexpected request", http.StatusInternalServerError) |
| + })) |
| + defer ts.Close() |
| + run := runCheckTestCommand |
| + if verb == "buy" { |
| + run = runBuyTestCommand |
| + } |
| + out, err := run(t, ts.URL, "--country", country) |
| + if err == nil || requests != 0 || !strings.Contains(out, "--country must be two letters a-z") { |
| + t.Fatalf("requests=%d err=%v output=%s", requests, err, out) |
| + } |
| + }) |
| + } |
| + } |
| +} |
| + |
| +func TestDomainsBuyCountryFlagOverridesContactCheckOnly(t *testing.T) { |
| + checks, purchases := 0, 0 |
| + mux := http.NewServeMux() |
| + mux.HandleFunc("POST "+buyTestPath+"/check", func(w http.ResponseWriter, r *http.Request) { |
| + checks++ |
| + var in struct{ Name, Country string } |
| + if err := json.NewDecoder(r.Body).Decode(&in); err != nil || in.Country != "IE" { |
| + t.Errorf("check body: %+v, %v", in, err) |
| + } |
| + fmt.Fprint(w, `{"domain":"shop.com","available":true,"price":1299,"currency":"eur"}`) |
| + }) |
| + mux.HandleFunc("POST "+buyTestPath+"/purchases", func(w http.ResponseWriter, r *http.Request) { |
| + purchases++ |
| + var in struct { |
| + Contact struct{ Country string } |
| + } |
| + if err := json.NewDecoder(r.Body).Decode(&in); err != nil || in.Contact.Country != "GB" { |
| + t.Errorf("purchase contact changed: %+v, %v", in, err) |
| + } |
| + fmt.Fprint(w, `{"id":"p1","state":"awaiting_payment"}`) |
| + }) |
| + ts := httptest.NewServer(mux) |
| + defer ts.Close() |
| + contactFile := filepath.Join(t.TempDir(), "contact.json") |
| + if err := os.WriteFile(contactFile, []byte(`{"country":"GB"}`), 0600); err != nil { |
| + t.Fatal(err) |
| + } |
| + out, err := runBuyTestCommand(t, ts.URL, "--country", "ie", "--contact-file", contactFile, "--no-wait") |
| + if err != nil || checks != 1 || purchases != 1 { |
| + t.Fatalf("checks=%d purchases=%d err=%v output=%s", checks, purchases, err, out) |
| + } |
| +} |
| + |
| type domainBuyRoundTrip func(*http.Request) (*http.Response, error) |
| func (f domainBuyRoundTrip) RoundTrip(r *http.Request) (*http.Response, error) { return f(r) } |
diff --git a/domains_buy_copy.go b/domains_buy_copy.go| index a1b310ddd..1ee788f98 100644 |
| --- a/domains_buy_copy.go |
| +++ b/domains_buy_copy.go |
| @@ -3,12 +3,19 @@ package main |
| // Approved by delegation (Luna), 2026-11-02: |
| // docs/superpowers/specs/LUNA-COPY-RESULT-DOMAINS-1.md, plus controller rulings |
| // on four flags. Apply later edits through a copy pass. |
| -const domainsBuyHelp = " check <name> [flags]\n check availability and the price for one year\n buy <name> --app <a> [--contact-file contact.json] [--yes] [--no-wait] [flags]\n buy a domain and wait for it to serve the app\n\n" |
| +// approved by delegation (reviewer, 2026-11-03) |
| +const domainsBuyHelp = " check <name> [--country <cc>] [flags]\n check availability and the price for one year\n buy <name> --app <a> [--country <cc>] [--contact-file contact.json] [--yes] [--no-wait] [flags]\n buy a domain and wait for it to serve the app\n\n" |
| -const domainsCheckUsage = "usage: carlos domains check <name> [--account <a>] [--account-id <id>] [--console <origin>]\n" |
| -const domainsBuyUsage = "usage: carlos domains buy <name> --app <a> [--contact-file contact.json] [--yes] [--no-wait] [--account <a>] [--account-id <id>] [--console <origin>]\n" |
| +// approved by delegation (reviewer, 2026-11-03) |
| +const domainsCheckUsage = "usage: carlos domains check <name> [--country <cc>] [--account <a>] [--account-id <id>] [--console <origin>]\n" |
| + |
| +// approved by delegation (reviewer, 2026-11-03) |
| +const domainsBuyUsage = "usage: carlos domains buy <name> --app <a> [--country <cc>] [--contact-file contact.json] [--yes] [--no-wait] [--account <a>] [--account-id <id>] [--console <origin>]\n" |
| var domainsBuyCopy = map[string]string{ |
| + // approved by delegation (reviewer, 2026-11-03) |
| + "countryFlag": "country for the price check when no billing currency is set (two letters; overrides the contact file for the check only)", |
| + "countryInvalid": "--country must be two letters a-z", |
| // Approved by delegation (reviewer), 2026-11-03. |
| "confirmChanged": "buy this domain at the new price? [y/N] ", |
| // Draft for the Luna pass: domain registration Plan 2, slice 1. |
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv| index eae19e409..14a7e3ecc 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-chain.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-chain.tsv |
| @@ -70,3 +70,4 @@ plan14-root-reads-storedoor-stream-get.tsv 7e30dee4fb52370555ad173512d7f03782f0f |
| plan14-root-reads-design-pdf-service.tsv 09ad1d7267b9598c64e89ec0faa7b18839c785c5c63905b398afe681cf9777c6 |
| plan14-root-reads-region-ha-placement-survivor.tsv 09ad1d7267b9598c64e89ec0faa7b18839c785c5c63905b398afe681cf9777c6 |
| plan14-root-reads-domains-buy-nosub.tsv 09ad1d7267b9598c64e89ec0faa7b18839c785c5c63905b398afe681cf9777c6 |
| +plan14-root-reads-domains-check-country.tsv 09ad1d7267b9598c64e89ec0faa7b18839c785c5c63905b398afe681cf9777c6 |
diff --git a/internal/provision/testdata/plan14-root-reads-domains-check-country.tsv b/internal/provision/testdata/plan14-root-reads-domains-check-country.tsv| new file mode 100644 |
| index 000000000..024589a9a |
| --- /dev/null |
| +++ b/internal/provision/testdata/plan14-root-reads-domains-check-country.tsv |
| @@ -0,0 +1,3 @@ |
| +# Census overlay domains-check-country, written by census-propose (#369). census-ruling-domains-check-country, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-domains-check-country.md. |
| +# 0 body, 0 sites, 1 envelope: each changed unit re-frozen at its existing disposition with its claim appended. |
| +@coverage . 3124ee3ac77f8fe76bd1f2735869446d799294bf8a888c576c6ab963c4f8cfe2 |