carlos / platform Public

Regional domains (#447) Task 6 fix: canonical claim host for add, isolate deployment env in the binary test

Astra T6 R1 P2s: regionalClaimHost normalizes through NormalizeAliasHost so
trailing-dot spellings reach the regional claim; the binary test clears
CARLOS_DEPLOYMENT_BUCKET, CARLOS_DEPLOYMENT_DIR and CARLOS_RELEASE_PUBKEY
before each case.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev e856dc311d0b4f0d05cea93722419aae28b75c86 parent 10a8db2
2 files changed, +70 −4
  • cli.go +9 −2
  • cli_add_regional_test.go +61 −2
diff --git a/cli.go b/cli.go
index 9e80c6662..7370efaff 100644
--- a/cli.go
+++ b/cli.go
@@ -177,9 +177,16 @@ func addRegionalCheck(ctx context.Context, store release.Store, host string) (re
}
// regionalClaimHost is the host whose claim decides whether `carlos add
-// <host>` is allowed: the host itself, or the parent of a "*." wildcard.
+// <host>` is allowed: the host itself, or the parent of a "*." wildcard, in
+// the canonical spelling claims are written under (NormalizeAliasHost:
+// lower-case, one trailing dot dropped). A host that does not normalize keeps
+// its lower-cased spelling, so it reads as not-found exactly as it always did.
func regionalClaimHost(host string) string {
- return strings.ToLower(strings.TrimPrefix(host, "*."))
+ h := strings.ToLower(strings.TrimPrefix(host, "*."))
+ if n, ok := domains.NormalizeAliasHost(h); ok {
+ return n
+ }
+ return h
}
// boxLabelForAdd is the label this box's status publishes under, which is
diff --git a/cli_add_regional_test.go b/cli_add_regional_test.go
index 7517afbd2..e87f5f430 100644
--- a/cli_add_regional_test.go
+++ b/cli_add_regional_test.go
@@ -44,7 +44,11 @@ func TestAddRefusesARegionalHost(t *testing.T) {
run := func(extraEnv []string, host string) (string, error) {
t.Helper()
cmd := exec.Command(bin, "add", "-registry", regPath, "-app", "shop", host)
- cmd.Env = carlosTestEnv(t, extraEnv...)
+ // carlosTestEnv inherits the operator's shell; clear every deployment
+ // variable first so each case sees only what it sets (later entries win).
+ cmd.Env = carlosTestEnv(t, append([]string{
+ "CARLOS_DEPLOYMENT_BUCKET=", "CARLOS_DEPLOYMENT_DIR=", "CARLOS_RELEASE_PUBKEY=",
+ }, extraEnv...)...)
// pick() walks cwd ancestors for .carlos/config, so the subprocess must not run from the real checkout.
cmd.Dir = scratch
out, err := cmd.CombinedOutput()
@@ -68,7 +72,7 @@ func TestAddRefusesARegionalHost(t *testing.T) {
return got != nil
}
- for _, h := range []string{claimed, "*." + claimed} {
+ for _, h := range []string{claimed, "*." + claimed, claimed + ".", "*." + claimed + ".", "Shop.Example.COM.", "*.SHOP.example.com."} {
out, err := run(withStore, h)
if err == nil {
t.Fatalf("add %s under a regional claim: want non-zero exit, got 0\n%s", h, out)
@@ -82,6 +86,9 @@ func TestAddRefusesARegionalHost(t *testing.T) {
if has(h) {
t.Errorf("add %s: refused, yet the registry has a row", h)
}
+ if has(strings.TrimSuffix(strings.ToLower(h), ".")) {
+ t.Errorf("add %s: refused, yet the registry has its canonical row", h)
+ }
}
// Neighbours the claim does not hold: a sub-host (no wildcard claim of its
@@ -156,3 +163,55 @@ func TestAddRegionalCheckPassesAPlainClaim(t *testing.T) {
t.Errorf("addRegionalCheck with no store = refused %v, skipped %v, want skipped only", refused, skipped)
}
}
+
+// The claim key is the canonical host (NormalizeAliasHost: lower-cased, one
+// trailing dot dropped), the same identity the claim writer uses. A host that
+// does not normalize keeps the old lower-cased spelling, so it reads as
+// not-found exactly as before.
+func TestRegionalClaimHostIsCanonical(t *testing.T) {
+ for in, want := range map[string]string{
+ "shop.example.com": "shop.example.com",
+ "shop.example.com.": "shop.example.com",
+ "Shop.Example.COM.": "shop.example.com",
+ "*.shop.example.com": "shop.example.com",
+ "*.shop.example.com.": "shop.example.com",
+ "*.SHOP.example.com.": "shop.example.com",
+ "localhost": "localhost",
+ "localhost.": "localhost.",
+ "*.localhost.": "localhost.",
+ "bad_host.example.com.": "bad_host.example.com.",
+ "shop.example.com..": "shop.example.com..",
+ "*.": "",
+ "": "",
+ } {
+ if got := regionalClaimHost(in); got != want {
+ t.Errorf("regionalClaimHost(%q) = %q, want %q", in, got, want)
+ }
+ }
+}
+
+// The trailing-dot spellings of a regional claim's host are refused by the
+// check itself, not only through the binary.
+func TestAddRegionalCheckRefusesTrailingDot(t *testing.T) {
+ store := release.NewDirStore(t.TempDir())
+ ctx := context.Background()
+ if _, err := domains.SetClaimPlacements(ctx, store, domains.Claim{
+ Schema: 2, Host: "shop.example.com", Account: "bab", App: "shop",
+ Route: "shop-ie.example.net",
+ CreatedAt: "2026-10-29T00:00:00Z", CreatedBy: "owner@example.com",
+ Placements: []domains.Placement{{Region: "", Host: "shop-ie.example.net"}, {Region: "uk", Host: "shop-uk.example.net"}},
+ }, nil, ""); err != nil {
+ t.Fatal(err)
+ }
+ for _, h := range []string{"shop.example.com.", "Shop.Example.COM.", "*.shop.example.com.", "*.SHOP.example.com."} {
+ if refused, skipped := addRegionalCheck(ctx, store, h); !refused || skipped {
+ t.Errorf("addRegionalCheck(%s) = refused %v, skipped %v, want refused only", h, refused, skipped)
+ }
+ }
+ // A host that does not normalize reads as not-found, as before.
+ for _, h := range []string{"localhost.", "bad_host.example.com."} {
+ if refused, skipped := addRegionalCheck(ctx, store, h); refused || skipped {
+ t.Errorf("addRegionalCheck(%s) = refused %v, skipped %v, want neither", h, refused, skipped)
+ }
+ }
+}