cli: --country on check only
5 files changed,
+44
−69
approved_domains_buy_copy_test.go+3 −3domains_buy_cli.go+10 −10domains_buy_cli_test.go+27 −52domains_buy_copy.go+3 −3internal/provision/testdata/plan14-root-reads-domains-check-country.tsv+1 −1
CI cancelled — superseded by a newer push — run details
diff --git a/approved_domains_buy_copy_test.go b/approved_domains_buy_copy_test.go| index 08857340f..bb2bc0518 100644 |
| --- a/approved_domains_buy_copy_test.go |
| +++ b/approved_domains_buy_copy_test.go |
| @@ -67,11 +67,11 @@ func TestApprovedDomainsBuyCopy(t *testing.T) { |
| {"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"}, |
| // 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.countryFlag", "domains_buy_copy.go", "country for the price check when no billing currency is set (two letters)"}, |
| {"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.help", "domains_buy_copy.go", " check <name> [--country <cc>] [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> [--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.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"}, |
| {"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/domains_buy_cli.go b/domains_buy_cli.go| index 8a9fec61a..94d9c61c8 100644 |
| --- a/domains_buy_cli.go |
| +++ b/domains_buy_cli.go |
| @@ -33,14 +33,15 @@ 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 app, contactFile, country string |
| var yes, noWait bool |
| if buy { |
| fs.StringVar(&app, "app", "", domainsBuyCopy["appFlag"]) |
| fs.StringVar(&contactFile, "contact-file", "", domainsBuyCopy["contactFileFlag"]) |
| fs.BoolVar(&yes, "yes", false, domainsBuyCopy["yesFlag"]) |
| fs.BoolVar(&noWait, "no-wait", false, domainsBuyCopy["noWaitFlag"]) |
| + } else { |
| + fs.StringVar(&country, "country", "", domainsBuyCopy["countryFlag"]) |
| } |
| fs.Usage = flagUsage(fs, usage) |
| pos, err := parseInterspersed(fs, args) |
| @@ -52,11 +53,11 @@ func runDomainBuyVerb(args []string, buy bool) { |
| } |
| fs.Visit(func(f *flag.Flag) { |
| if f.Name == "country" { |
| - if len(*country) != 2 { |
| + 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' { |
| + country = strings.ToUpper(country) |
| + if len(country) != 2 || country[0] < 'A' || country[0] > 'Z' || country[1] < 'A' || country[1] > 'Z' { |
| log.Fatal(domainsBuyCopy["countryInvalid"]) |
| } |
| } |
| @@ -67,12 +68,12 @@ func runDomainBuyVerb(args []string, buy bool) { |
| ctx := context.Background() |
| if buy { |
| err = domainsBuy(ctx, sess, acct, strings.TrimSpace(pos[0]), strings.TrimSpace(app), domainBuyOptions{ |
| - yes: yes, noWait: noWait, contactFile: contactFile, country: *country, |
| + yes: yes, noWait: noWait, contactFile: contactFile, |
| 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]), *country, stdout) |
| + err = domainsCheck(ctx, sess, acct, strings.TrimSpace(pos[0]), country, stdout) |
| } |
| if err != nil { |
| log.Fatal(err) |
| @@ -99,7 +100,6 @@ func domainsCheck(ctx context.Context, s *apiSession, acct apiAcct, name, countr |
| type domainBuyOptions struct { |
| yes, noWait, terminal bool |
| contactFile string |
| - country string |
| in io.Reader |
| out io.Writer |
| now func() time.Time |
| @@ -115,8 +115,8 @@ func domainsBuy(ctx context.Context, s *apiSession, acct apiAcct, name, app stri |
| return err |
| } |
| } |
| - country := o.country |
| - if country == "" && contact != nil { |
| + country := "" |
| + if 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 057e18be8..ea044ecd8 100644 |
| --- a/domains_buy_cli_test.go |
| +++ b/domains_buy_cli_test.go |
| @@ -14,6 +14,7 @@ import ( |
| "path/filepath" |
| "reflect" |
| "strings" |
| + "sync/atomic" |
| "testing" |
| "time" |
| ) |
| @@ -413,9 +414,9 @@ func runCheckTestCommand(t *testing.T, base string, args ...string) (string, err |
| func TestDomainsCheckCountryFlag(t *testing.T) { |
| for _, country := range []string{"IE", "ie", "iE"} { |
| t.Run(country, func(t *testing.T) { |
| - checks := 0 |
| + var checks atomic.Int32 |
| ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| - checks++ |
| + checks.Add(1) |
| var in struct{ Name, Country string } |
| if err := json.NewDecoder(r.Body).Decode(&in); err != nil { |
| t.Error(err) |
| @@ -427,66 +428,40 @@ func TestDomainsCheckCountryFlag(t *testing.T) { |
| })) |
| 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) |
| + if err != nil || checks.Load() != 1 || !strings.Contains(out, "EUR") { |
| + t.Fatalf("checks=%d err=%v output=%s", checks.Load(), 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) |
| - } |
| - }) |
| - } |
| + for _, country := range []string{"", "I", "IRL", "I1", "1E", "I-", " IE", "IE ", "É", "ıe"} { |
| + t.Run(country, func(t *testing.T) { |
| + var requests atomic.Int32 |
| + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| + requests.Add(1) |
| + http.Error(w, "unexpected request", http.StatusInternalServerError) |
| + })) |
| + defer ts.Close() |
| + out, err := runCheckTestCommand(t, ts.URL, "--country", country) |
| + if err == nil || requests.Load() != 0 || !strings.Contains(out, "--country must be two letters a-z") { |
| + t.Fatalf("requests=%d err=%v output=%s", requests.Load(), 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) |
| +func TestDomainsBuyRejectsCountryFlagBeforeRequest(t *testing.T) { |
| + var requests atomic.Int32 |
| + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| + requests.Add(1) |
| + http.Error(w, "unexpected request", http.StatusInternalServerError) |
| + })) |
| 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) |
| + out, err := runBuyTestCommand(t, ts.URL, "--country", "IE") |
| + if err == nil || requests.Load() != 0 || !strings.Contains(out, "flag provided but not defined") { |
| + t.Fatalf("requests=%d err=%v output=%s", requests.Load(), err, out) |
| } |
| } |
diff --git a/domains_buy_copy.go b/domains_buy_copy.go| index 1ee788f98..8d928368e 100644 |
| --- a/domains_buy_copy.go |
| +++ b/domains_buy_copy.go |
| @@ -4,17 +4,17 @@ package main |
| // docs/superpowers/specs/LUNA-COPY-RESULT-DOMAINS-1.md, plus controller rulings |
| // on four flags. Apply later edits through a copy pass. |
| // 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 domainsBuyHelp = " check <name> [--country <cc>] [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 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" |
| +const domainsBuyUsage = "usage: carlos domains buy <name> --app <a> [--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)", |
| + "countryFlag": "country for the price check when no billing currency is set (two letters)", |
| "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] ", |
diff --git a/internal/provision/testdata/plan14-root-reads-domains-check-country.tsv b/internal/provision/testdata/plan14-root-reads-domains-check-country.tsv| index 024589a9a..2c1fc5210 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-domains-check-country.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-domains-check-country.tsv |
| @@ -1,3 +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 |
| +@coverage . a60ca048c2e1fd41a4569a2e8419b1ab62c4d0687a7b0e8b7336ae05db85fcba |