domains: account namespace claim (subdomains T2)
Claim.AccountNamespace (json account_namespace) marks a claim at "*.<name>.<apps-domain>" that gives an account the name. namespace.go adds NamespaceHost/ParseNamespaceHost, NormalizeSubdomain, the SubdomainRefusal codes with SubdomainRuleRefusal (shape, reserved, sqid-shaped under 7), the create-only AttachAccountNamespace, the etag- and account-bound DetachAccountNamespaceAt, and the AccountNamespaces fold. The writers are account-level and deliberately not wrapped in release.WithAppMutation. Censuses: record-write overlay accountSubdomainsWriteCensusInventory adds AttachAccountNamespace (nonrecord / sel:Put) and becomes the tip; the group-name schema inventory gains the field; census-propose wrote the root-read overlay for the re-pinned internal/domains envelope. That overlay still needs an independent reviewer's approval on #280.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
9 files changed,
+551
−2
docs/superpowers/notes/census-proposal-account-subdomains.md+11 −0internal/domains/claims.go+14 −0internal/domains/namespace.go+246 −0internal/domains/namespace_test.go+251 −0internal/host/group_names_test.go+1 −1internal/provision/account_subdomains_census_test.go+23 −0internal/provision/plan9_b8_census_test.go+1 −1internal/provision/testdata/plan14-root-reads-account-subdomains.tsv+3 −0internal/provision/testdata/plan14-root-reads-chain.tsv+1 −0
Intent
Attributed to this commit: 27.4 g CO₂e (3,455,750 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on design-account-name-hosts, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.
diff --git a/docs/superpowers/notes/census-proposal-account-subdomains.md b/docs/superpowers/notes/census-proposal-account-subdomains.md| new file mode 100644 |
| index 000000000..7717864e5 |
| --- /dev/null |
| +++ b/docs/superpowers/notes/census-proposal-account-subdomains.md |
| @@ -0,0 +1,11 @@ |
| +# Census approval: account-subdomains |
| + |
| +Ruling `census-ruling-account-subdomains`. 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: `internal/domains`. |
| + |
| +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: `b3d35a0bd7c0500c74efbe5e8f566adb623696d31bd9860164907e08a2e79369` → `b3d35a0bd7c0500c74efbe5e8f566adb623696d31bd9860164907e08a2e79369`. |
| + |
| +Overlay: `internal/provision/testdata/plan14-root-reads-account-subdomains.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`. |
diff --git a/internal/domains/claims.go b/internal/domains/claims.go| index 50aecfd51..883472390 100644 |
| --- a/internal/domains/claims.go |
| +++ b/internal/domains/claims.go |
| @@ -93,6 +93,20 @@ type Claim struct { |
| // a hostname (NormalizeAliasHost), so an older console cannot rewrite or |
| // detach it either. Declared here for the round-trip reason above. |
| Instances bool `json:"instances,omitempty"` |
| + // AccountNamespace marks an account namespace claim (account subdomains, |
| + // spec 2026-11-11 §4.1): Host is "*.<name>.<apps-domain>" |
| + // (NamespaceHost), Account is the sqid the name stands for, and nothing |
| + // else is set (no App, Route, Wildcard, Catchall, Paths, Instances or |
| + // Placements). The bucket key is the uniqueness gate, as for the |
| + // instance catch-all: one account per name, and a namespace and an |
| + // instance catch-all on the same parent cannot coexist. |
| + // |
| + // Additive and inert on a binary that predates it: such a binary decodes |
| + // a claim with no Route, no Instances and no Wildcard, the shape every |
| + // pass already skips. No attach door accepts a "*" (NormalizeAliasHost), |
| + // so no ordinary door can write, rewrite or detach one. Declared here for |
| + // the round-trip reason above. |
| + AccountNamespace bool `json:"account_namespace,omitempty"` |
| // Placements makes this a regional claim (#447): the hostname is served |
| // in each listed region by that region's bound host, never backhauled. |
| // Only SetClaimPlacements writes it, and only on a schema-2 claim, which |
diff --git a/internal/domains/namespace.go b/internal/domains/namespace.go| new file mode 100644 |
| index 000000000..0c2536476 |
| --- /dev/null |
| +++ b/internal/domains/namespace.go |
| @@ -0,0 +1,246 @@ |
| +package domains |
| + |
| +// Account namespace claims: account subdomains (spec |
| +// docs/superpowers/specs/2026-11-11-account-subdomains-design.md §4.1-4.2). |
| +// An account that holds the name N has its apps served at |
| +// <app>.N.<apps-domain> beside <app>.<sqid>.<apps-domain>. The record is a |
| +// Claim at ClaimKey("*.N.<apps-domain>") with AccountNamespace set and |
| +// nothing else, so the bucket key is the uniqueness gate exactly as it is for |
| +// the instance catch-all on the same parent. |
| + |
| +import ( |
| + "context" |
| + "encoding/json" |
| + "errors" |
| + "fmt" |
| + "os" |
| + "strings" |
| + |
| + "github.com/carlosframework/platform/internal/release" |
| +) |
| + |
| +// SubdomainRefusal says why a name cannot be an account's subdomain. The |
| +// values are internal codes the console maps to approved copy; they are |
| +// never shown as they are. "" means allowed. |
| +type SubdomainRefusal string |
| + |
| +const ( |
| + // SubdomainShape: not one DNS label in the account-name shape, or an |
| + // "xn--" style label (hyphens in positions 3 and 4). |
| + SubdomainShape SubdomainRefusal = "shape" |
| + // SubdomainSqidShaped: a short frozen-alphabet word that the sqid |
| + // minter could hand to a future account (spec §4.2 rule 2). |
| + SubdomainSqidShaped SubdomainRefusal = "sqid_shaped" |
| + // SubdomainReserved: in ReservedSqids (spec §4.2 rule 3). |
| + SubdomainReserved SubdomainRefusal = "reserved" |
| + // SubdomainHeld: a sqid an account holds, live or deleted (rule 1), or |
| + // a name another account holds. Answered by the console, which can read |
| + // accounts. |
| + SubdomainHeld SubdomainRefusal = "held" |
| + // SubdomainUnreadable: a read the decision needs failed; retryable. |
| + SubdomainUnreadable SubdomainRefusal = "unreadable" |
| + // SubdomainInfrastructure: the deployment stands on the name (rule 4). |
| + SubdomainInfrastructure SubdomainRefusal = "infrastructure" |
| + // SubdomainOccupied: another account already has something there |
| + // (rule 5), or the key holds a claim of another kind. |
| + SubdomainOccupied SubdomainRefusal = "occupied" |
| + // SubdomainAccountHasOne: the account already holds a name. |
| + SubdomainAccountHasOne SubdomainRefusal = "account_has_one" |
| + // SubdomainRolledBack: the assignment door's re-read found a conflict |
| + // after its write and removed its own claim again. |
| + SubdomainRolledBack SubdomainRefusal = "rolled_back" |
| +) |
| + |
| +// sqidShapedFloor is the length from which a frozen-alphabet word is allowed |
| +// as a name: a 7-letter sqid needs an account id past 23⁶ − 529, about 148 |
| +// million accounts (spec §4.2 rule 2). |
| +const sqidShapedFloor = 7 |
| + |
| +// subdomainLabelOK is the name shape: one DNS label in the account-name |
| +// shape (accountNameRe), refusing "xn--" style labels, which IDNA reserves. |
| +func subdomainLabelOK(name string) bool { |
| + if !accountNameRe.MatchString(name) { |
| + return false |
| + } |
| + return !(len(name) >= 4 && name[2] == '-' && name[3] == '-') |
| +} |
| + |
| +// NormalizeSubdomain trims and lowercases raw and reports whether the result |
| +// has the name shape. It says nothing about whether the name is allowed |
| +// (SubdomainRuleRefusal) or free. |
| +func NormalizeSubdomain(raw string) (string, bool) { |
| + name := strings.ToLower(strings.TrimSpace(raw)) |
| + if !subdomainLabelOK(name) { |
| + return "", false |
| + } |
| + return name, true |
| +} |
| + |
| +// SubdomainRuleRefusal applies the rules of spec §4.2 that need no store: the |
| +// shape, the reserved labels and the sqid-shaped floor. It expects a |
| +// normalised name (an unnormalised one is refused for shape). "" means these |
| +// rules allow it; the console still checks held sqids, the deployment's own |
| +// hosts and what already lives under the name. |
| +func SubdomainRuleRefusal(name string) SubdomainRefusal { |
| + switch { |
| + case !subdomainLabelOK(name): |
| + return SubdomainShape |
| + case IsReservedSqid(name): |
| + return SubdomainReserved |
| + case ValidSqid(name) && len(name) < sqidShapedFloor: |
| + return SubdomainSqidShaped |
| + } |
| + return "" |
| +} |
| + |
| +// NamespaceHost is the claim host of name's account namespace under |
| +// appsDomain: "*.<name>.<appsDomain>". |
| +func NamespaceHost(name, appsDomain string) string { |
| + return "*." + name + "." + appsDomain |
| +} |
| + |
| +// ParseNamespaceHost is NamespaceHost's inverse: it reports whether host is |
| +// "*.<name>.<appsDomain>" with name one label in the name shape, and returns |
| +// name. Matching is exact (claim hosts are stored normalised), so an instance |
| +// catch-all deeper under the apps domain ("*.team.bdq.<appsDomain>") or an |
| +// ordinary host is not a namespace host. |
| +func ParseNamespaceHost(host, appsDomain string) (name string, ok bool) { |
| + if appsDomain == "" { |
| + return "", false |
| + } |
| + rest, ok := strings.CutPrefix(host, "*.") |
| + if !ok { |
| + return "", false |
| + } |
| + name, ok = strings.CutSuffix(rest, "."+appsDomain) |
| + if !ok || !subdomainLabelOK(name) { |
| + return "", false |
| + } |
| + return name, true |
| +} |
| + |
| +// AttachAccountNamespace writes name's namespace claim for account, |
| +// create-only by key. created is false with a nil error when the key already |
| +// holds a claim of any kind (this account's namespace, another account's, or |
| +// an instance catch-all on the same parent): the caller reads the key to |
| +// tell those apart. A lost create race answers the same way. |
| +// |
| +// Only the name's shape is checked here. The rules of spec §4.2 are the |
| +// console door's (SubdomainRuleRefusal and the store reads it adds). |
| +// |
| +// Not wrapped in release.WithAppMutation, unlike the claim writers in |
| +// claims.go: the record is account-level and names no app, the host-claim |
| +// mutation boundary refuses an empty app (hostops app_mutation_runner, |
| +// mutation_classifier), and the console door refuses while host claims are |
| +// on. |
| +func AttachAccountNamespace(ctx context.Context, s release.Store, name, appsDomain, account, createdAt, createdBy string) (created bool, err error) { |
| + host, err := namespaceHostChecked(name, appsDomain, account) |
| + if err != nil { |
| + return false, err |
| + } |
| + body, err := json.Marshal(Claim{ |
| + Schema: 1, Host: host, Account: account, |
| + CreatedAt: createdAt, CreatedBy: createdBy, AccountNamespace: true, |
| + }) |
| + if err != nil { |
| + return false, err |
| + } |
| + if _, _, err := getClaimETag(ctx, s, host); err == nil { |
| + return false, nil |
| + } else if !errors.Is(err, os.ErrNotExist) { |
| + return false, err |
| + } |
| + if _, err := s.Put(ctx, ClaimKey(host), body, ""); errors.Is(err, release.ErrCASConflict) { |
| + return false, nil // lost a create race: the key is someone's now |
| + } else if err != nil { |
| + return false, err |
| + } |
| + return true, nil |
| +} |
| + |
| +// DetachAccountNamespaceAt deletes name's namespace claim only when it is |
| +// still account's namespace claim and its ETag is etag, the revision the |
| +// caller read and judged. The delete is release.DeleteIfMatch, so a claim |
| +// replaced between the read here and the delete is not removed either. Any |
| +// other claim at the key (an instance catch-all), a changed or an absent one |
| +// answers removed=false. A store that cannot delete conditionally refuses |
| +// (release.ErrConditionalDeleteUnsupported): never an unconditional delete. |
| +// |
| +// Not wrapped in release.WithAppMutation, for the reason |
| +// AttachAccountNamespace gives. |
| +func DetachAccountNamespaceAt(ctx context.Context, s release.Store, name, appsDomain, account, etag string) (bool, error) { |
| + host, err := namespaceHostChecked(name, appsDomain, account) |
| + if err != nil { |
| + return false, err |
| + } |
| + cur, curETag, err := getClaimETag(ctx, s, host) |
| + if errors.Is(err, os.ErrNotExist) { |
| + return false, nil |
| + } |
| + if err != nil { |
| + return false, err |
| + } |
| + if curETag != etag || cur.Account != account || !cur.AccountNamespace { |
| + return false, nil |
| + } |
| + err = release.DeleteIfMatch(ctx, s, ClaimKey(host), etag) |
| + if errors.Is(err, release.ErrCASConflict) { |
| + return false, nil |
| + } |
| + if err != nil { |
| + return false, err |
| + } |
| + return true, nil |
| +} |
| + |
| +// namespaceHostChecked is NamespaceHost for the two writers, refusing what no |
| +// door should hand them: a name not in the name shape, an apps domain that is |
| +// not a hostname, or an account that is not a bucket account segment. |
| +func namespaceHostChecked(name, appsDomain, account string) (string, error) { |
| + if !subdomainLabelOK(name) { |
| + return "", fmt.Errorf("domains: account namespace %q: not a valid name", name) |
| + } |
| + if !validHostShape(appsDomain) { |
| + return "", fmt.Errorf("domains: account namespace %q: apps domain %q is not a hostname", name, appsDomain) |
| + } |
| + if !release.ValidAccount(account) { |
| + return "", fmt.Errorf("domains: account namespace %q: account %q is not valid", name, account) |
| + } |
| + return NamespaceHost(name, appsDomain), nil |
| +} |
| + |
| +// AccountNamespaces folds claims into the namespaces in force under |
| +// appsDomain: byName maps a name to its account's sqid, byAccount a sqid to |
| +// its name. Only claims with AccountNamespace set count, and of those only |
| +// the ones that are verified (not Pending), sit at a valid namespace host |
| +// under appsDomain, name a valid account and carry nothing a namespace claim |
| +// never has (an App, Route, Wildcard, Catchall, Paths, Instances or |
| +// Placements: no door writes such a claim, so it is not trusted to be one). |
| +// |
| +// The door leaves an account at most one name. Should a store-mode write |
| +// leave it two, byName keeps both and byAccount keeps the lexically first, |
| +// so every reader picks the same one whatever order the claims came in. |
| +func AccountNamespaces(claims []Claim, appsDomain string) (byName, byAccount map[string]string) { |
| + byName = map[string]string{} |
| + byAccount = map[string]string{} |
| + for _, c := range claims { |
| + if !c.AccountNamespace || c.Pending || !namespaceOnly(c) || !release.ValidAccount(c.Account) { |
| + continue |
| + } |
| + name, ok := ParseNamespaceHost(c.Host, appsDomain) |
| + if !ok { |
| + continue |
| + } |
| + byName[name] = c.Account |
| + if cur, ok := byAccount[c.Account]; !ok || name < cur { |
| + byAccount[c.Account] = name |
| + } |
| + } |
| + return byName, byAccount |
| +} |
| + |
| +// namespaceOnly reports whether c carries nothing but the namespace. |
| +func namespaceOnly(c Claim) bool { |
| + return c.App == "" && c.Route == "" && !c.Wildcard && !c.Catchall && |
| + len(c.Paths) == 0 && !c.Instances && len(c.Placements) == 0 |
| +} |
diff --git a/internal/domains/namespace_test.go b/internal/domains/namespace_test.go| new file mode 100644 |
| index 000000000..f1ca51589 |
| --- /dev/null |
| +++ b/internal/domains/namespace_test.go |
| @@ -0,0 +1,251 @@ |
| +package domains |
| + |
| +import ( |
| + "context" |
| + "encoding/json" |
| + "testing" |
| + |
| + "github.com/carlosframework/platform/internal/release" |
| +) |
| + |
| +func TestSubdomainRuleRefusal(t *testing.T) { |
| + cases := map[string]SubdomainRefusal{ |
| + "harbour": "", |
| + "market": SubdomainSqidShaped, // six frozen-alphabet letters: could be minted |
| + "marketx": "", // seven: past any sqid we will mint |
| + "dev": SubdomainReserved, |
| + "edge": SubdomainReserved, |
| + "www": SubdomainReserved, |
| + "ab--x": SubdomainShape, |
| + "xn--a": SubdomainShape, |
| + "-a": SubdomainShape, |
| + "a-": SubdomainShape, |
| + "": SubdomainShape, |
| + "Harbour": SubdomainShape, // not normalised |
| + "shop2": "", |
| + } |
| + for name, want := range cases { |
| + if got := SubdomainRuleRefusal(name); got != want { |
| + t.Errorf("SubdomainRuleRefusal(%q) = %q, want %q", name, got, want) |
| + } |
| + } |
| +} |
| + |
| +func TestNormalizeSubdomain(t *testing.T) { |
| + cases := []struct { |
| + raw string |
| + want string |
| + ok bool |
| + }{ |
| + {" Harbour ", "harbour", true}, |
| + {"harbour.apps.test", "", false}, |
| + {"ab--x", "", false}, |
| + {"", "", false}, |
| + {"*", "", false}, |
| + {"SHOP2", "shop2", true}, |
| + } |
| + for _, c := range cases { |
| + got, ok := NormalizeSubdomain(c.raw) |
| + if got != c.want || ok != c.ok { |
| + t.Errorf("NormalizeSubdomain(%q) = (%q, %v), want (%q, %v)", c.raw, got, ok, c.want, c.ok) |
| + } |
| + } |
| +} |
| + |
| +func TestAttachAccountNamespaceIsCreateOnly(t *testing.T) { |
| + ctx := context.Background() |
| + s := release.NewDirStore(t.TempDir()) |
| + created, err := AttachAccountNamespace(ctx, s, "harbour", "apps.test", "bdq", "2026-11-11T00:00:00Z", "ops@example.com") |
| + if err != nil || !created { |
| + t.Fatalf("first attach = (%v, %v), want (true, nil)", created, err) |
| + } |
| + created, err = AttachAccountNamespace(ctx, s, "harbour", "apps.test", "bcd", "2026-11-11T00:00:01Z", "ops@example.com") |
| + if err != nil || created { |
| + t.Fatalf("second attach by another account = (%v, %v), want (false, nil)", created, err) |
| + } |
| + created, err = AttachAccountNamespace(ctx, s, "harbour", "apps.test", "bdq", "2026-11-11T00:00:02Z", "ops@example.com") |
| + if err != nil || created { |
| + t.Fatalf("repeat attach by holder = (%v, %v), want (false, nil)", created, err) |
| + } |
| + c, err := GetClaim(ctx, s, "*.harbour.apps.test") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if c.Account != "bdq" { |
| + t.Fatalf("claim account = %q, want bdq", c.Account) |
| + } |
| + if c.Host != "*.harbour.apps.test" || !c.AccountNamespace || c.App != "" || c.Route != "" { |
| + t.Fatalf("claim = %+v, want Host *.harbour.apps.test, AccountNamespace, no App or Route", c) |
| + } |
| + if c.Instances || c.Wildcard || c.Catchall || c.Paths != nil || c.Placements != nil || c.Pending { |
| + t.Fatalf("claim carries more than a namespace: %+v", c) |
| + } |
| + if c.CreatedAt != "2026-11-11T00:00:00Z" || c.CreatedBy != "ops@example.com" || c.Schema != 1 { |
| + t.Fatalf("claim stamps = %+v", c) |
| + } |
| + // The wire carries the field under its declared name. |
| + raw, _, err := s.Get(ctx, ClaimKey("*.harbour.apps.test")) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + var wire map[string]any |
| + if err := json.Unmarshal(raw, &wire); err != nil { |
| + t.Fatal(err) |
| + } |
| + if wire["account_namespace"] != true { |
| + t.Fatalf("wire = %s, want account_namespace true", raw) |
| + } |
| +} |
| + |
| +func TestAttachAccountNamespaceRefusesBadShape(t *testing.T) { |
| + ctx := context.Background() |
| + s := release.NewDirStore(t.TempDir()) |
| + for _, name := range []string{"Harbour", "harbour.x", "ab--x", ""} { |
| + if created, err := AttachAccountNamespace(ctx, s, name, "apps.test", "bdq", "t", ""); err == nil || created { |
| + t.Errorf("attach %q = (%v, %v), want an error", name, created, err) |
| + } |
| + } |
| + if created, err := AttachAccountNamespace(ctx, s, "harbour", "", "bdq", "t", ""); err == nil || created { |
| + t.Errorf("attach with no apps domain = (%v, %v), want an error", created, err) |
| + } |
| + keys, err := s.List(ctx, ClaimsPrefix) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if len(keys) != 0 { |
| + t.Fatalf("refused attaches wrote %v", keys) |
| + } |
| +} |
| + |
| +func TestAttachAccountNamespaceLeavesCatchallAlone(t *testing.T) { |
| + ctx := context.Background() |
| + s := release.NewDirStore(t.TempDir()) |
| + if _, _, err := AttachClaim(ctx, s, Claim{Schema: 1, Host: "harbour.apps.test", Account: "bcd", App: "shop", CreatedAt: "t"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err := AttachInstanceCatchall(ctx, s, "harbour.apps.test", "bcd", "shop", "t", ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + created, err := AttachAccountNamespace(ctx, s, "harbour", "apps.test", "bdq", "t", "") |
| + if err != nil || created { |
| + t.Fatalf("attach over a catch-all = (%v, %v), want (false, nil)", created, err) |
| + } |
| + c, err := GetClaim(ctx, s, "*.harbour.apps.test") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if !c.Instances || c.AccountNamespace || c.Account != "bcd" { |
| + t.Fatalf("catch-all changed: %+v", c) |
| + } |
| +} |
| + |
| +func TestDetachAccountNamespaceNeedsEtagAndAccount(t *testing.T) { |
| + ctx := context.Background() |
| + s := release.NewDirStore(t.TempDir()) |
| + if _, err := AttachAccountNamespace(ctx, s, "harbour", "apps.test", "bdq", "t", ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + _, etag, err := GetClaimETag(ctx, s, NamespaceHost("harbour", "apps.test")) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if removed, err := DetachAccountNamespaceAt(ctx, s, "harbour", "apps.test", "bcd", etag); err != nil || removed { |
| + t.Fatalf("wrong account detach = (%v, %v), want (false, nil)", removed, err) |
| + } |
| + if removed, err := DetachAccountNamespaceAt(ctx, s, "harbour", "apps.test", "bdq", etag+"-stale"); err != nil || removed { |
| + t.Fatalf("stale etag detach = (%v, %v), want (false, nil)", removed, err) |
| + } |
| + if _, err := GetClaim(ctx, s, "*.harbour.apps.test"); err != nil { |
| + t.Fatalf("claim gone after refused detaches: %v", err) |
| + } |
| + if removed, err := DetachAccountNamespaceAt(ctx, s, "harbour", "apps.test", "bdq", etag); err != nil || !removed { |
| + t.Fatalf("detach = (%v, %v), want (true, nil)", removed, err) |
| + } |
| + if _, err := GetClaim(ctx, s, "*.harbour.apps.test"); err == nil { |
| + t.Fatal("claim still there after detach") |
| + } |
| + if removed, err := DetachAccountNamespaceAt(ctx, s, "harbour", "apps.test", "bdq", etag); err != nil || removed { |
| + t.Fatalf("detach of an absent claim = (%v, %v), want (false, nil)", removed, err) |
| + } |
| +} |
| + |
| +func TestDetachAccountNamespaceLeavesCatchallAlone(t *testing.T) { |
| + ctx := context.Background() |
| + s := release.NewDirStore(t.TempDir()) |
| + if _, _, err := AttachClaim(ctx, s, Claim{Schema: 1, Host: "harbour.apps.test", Account: "bdq", App: "shop", CreatedAt: "t"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err := AttachInstanceCatchall(ctx, s, "harbour.apps.test", "bdq", "shop", "t", ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + _, etag, err := GetClaimETag(ctx, s, "*.harbour.apps.test") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if removed, err := DetachAccountNamespaceAt(ctx, s, "harbour", "apps.test", "bdq", etag); err != nil || removed { |
| + t.Fatalf("namespace detach of a catch-all = (%v, %v), want (false, nil)", removed, err) |
| + } |
| +} |
| + |
| +func TestAccountNamespacesSkipsPendingAndOtherKinds(t *testing.T) { |
| + claims := []Claim{ |
| + {Schema: 1, Host: "*.harbour.apps.test", Account: "bdq", AccountNamespace: true}, |
| + {Schema: 1, Host: "*.marketx.apps.test", Account: "bcd", AccountNamespace: true, Pending: true, PendingUntil: "2099-01-01T00:00:00Z"}, |
| + {Schema: 1, Host: "*.team.apps.test", Account: "bcd", App: "shop", Instances: true}, |
| + {Schema: 1, Host: "team.apps.test", Account: "bcd", App: "shop", Route: "shop.bcd.apps.test"}, |
| + // Shapes no door writes: another apps domain, two labels deep, a bad |
| + // label, a namespace claim that also names an app. |
| + {Schema: 1, Host: "*.quay.other.test", Account: "bcd", AccountNamespace: true}, |
| + {Schema: 1, Host: "*.team.bdq.apps.test", Account: "bcd", AccountNamespace: true}, |
| + {Schema: 1, Host: "*.xn--a.apps.test", Account: "bcd", AccountNamespace: true}, |
| + {Schema: 1, Host: "*.dock.apps.test", Account: "bcd", App: "shop", AccountNamespace: true}, |
| + } |
| + byName, byAccount := AccountNamespaces(claims, "apps.test") |
| + if len(byName) != 1 || byName["harbour"] != "bdq" { |
| + t.Fatalf("byName = %v, want only harbour→bdq", byName) |
| + } |
| + if len(byAccount) != 1 || byAccount["bdq"] != "harbour" { |
| + t.Fatalf("byAccount = %v, want only bdq→harbour", byAccount) |
| + } |
| +} |
| + |
| +func TestAccountNamespacesTwoNamesOneAccountIsStable(t *testing.T) { |
| + // The door never leaves an account two names, but a store-mode write |
| + // can. byName keeps both; byAccount picks the same one whatever the order. |
| + a := Claim{Schema: 1, Host: "*.quay.apps.test", Account: "bdq", AccountNamespace: true} |
| + b := Claim{Schema: 1, Host: "*.harbour.apps.test", Account: "bdq", AccountNamespace: true} |
| + for _, claims := range [][]Claim{{a, b}, {b, a}} { |
| + byName, byAccount := AccountNamespaces(claims, "apps.test") |
| + if len(byName) != 2 || byAccount["bdq"] != "harbour" { |
| + t.Fatalf("byName = %v, byAccount = %v", byName, byAccount) |
| + } |
| + } |
| +} |
| + |
| +func TestParseNamespaceHost(t *testing.T) { |
| + host := NamespaceHost("harbour", "apps.test") |
| + if host != "*.harbour.apps.test" { |
| + t.Fatalf("NamespaceHost = %q", host) |
| + } |
| + if name, ok := ParseNamespaceHost(host, "apps.test"); !ok || name != "harbour" { |
| + t.Fatalf("ParseNamespaceHost(%q) = (%q, %v), want (harbour, true)", host, name, ok) |
| + } |
| + for _, h := range []string{ |
| + "*.team.bdq.apps.test", // instance catch-all two labels deep |
| + "shop.apps.test", |
| + "harbour.apps.test", |
| + "*.apps.test", |
| + "*.harbour.other.test", |
| + "*.harbour.xapps.test", |
| + "*.xn--a.apps.test", |
| + "*.Harbour.apps.test", |
| + "", |
| + } { |
| + if name, ok := ParseNamespaceHost(h, "apps.test"); ok { |
| + t.Errorf("ParseNamespaceHost(%q) = (%q, true), want not ok", h, name) |
| + } |
| + } |
| + if _, ok := ParseNamespaceHost("*.harbour.", ""); ok { |
| + t.Error("empty apps domain parsed") |
| + } |
| +} |
diff --git a/internal/host/group_names_test.go b/internal/host/group_names_test.go| index a457cef18..5e6b6fc4c 100644 |
| --- a/internal/host/group_names_test.go |
| +++ b/internal/host/group_names_test.go |
| @@ -256,7 +256,7 @@ func TestGroupNameClassCensus(t *testing.T) { |
| {registry.Route{}, "DemoID DemoHost DemoLifetime DemoExpiresAt ClaimOwnership WakeIncarnation Host Slug Kind Socket Addr Addrs Health Status HoldOp Incarnation ServingSeq SeedSource ImportGate AssetsOff AssetGen PagesOff LastError Stateless FleetBoxes Copies ReplicaRevision ReplicaIncarnation DBPath Version PrevVersion GoodVersion GoodDigest GoodDemand ServingVersion App Pool Region Channel Environment Tunnel FleetBox FleetLabel Assigned Moved Caps Hibernate HA Runtime Gate RateLimit Canary Replication NextDue StatusNamed Backing Unit Platform Provisioned Seed Args IdleSeconds MaxRunSeconds DNSStatus DNSCheckedAt CertExpiresAt Account Steering UpdateSettings EgressAllow Size PolicyExpiresAt BuildState Replicas Replica CreatedAt"}, |
| {provision.Record{}, "DemoClaim Demo ReplicaAssignment Coordinator ReplicaDeploy RecordSeq Acquisition Maintenance Schema Host Slug App Account Pool Region Channel CreatedAt CreatedBy FleetBox FleetBoxAt FleetBoxMoved HA Move LastMove ActiveRun Interactive RunKeys Seed Kind Addr Unit Hibernate Runtime Environment StatusNamed Addrs Health Steering Assets AssetGen Pages Gate Incarnation IncarnationMigrating MoveSeq Retired RateLimit Role Replicas Updates Major Pin InstallRequest"}, |
| {edgeHost{}, "Role Platform Alias Replica Wildcard Account App Stamp Incarnation ServingSeq TargetHost Assets DNSPointing"}, |
| - {domains.Claim{}, "Acquisition RecordIncarnation OwnershipState Schema Host Account App Route CreatedAt CreatedBy Wildcard Catchall Paths Instances Placements Pending PendingUntil"}, |
| + {domains.Claim{}, "Acquisition RecordIncarnation OwnershipState Schema Host Account App Route CreatedAt CreatedBy Wildcard Catchall Paths Instances AccountNamespace Placements Pending PendingUntil"}, |
| {registry.RouteAlias{}, "Alias Host Account App DNSStatus DNSCheckedAt CertExpiresAt CreatedAt"}, |
| {registry.RoutePath{}, "Host Prefix Target Account App"}, |
| {registry.WildcardDomain{}, "Host Account App CreatedAt"}, |
diff --git a/internal/provision/account_subdomains_census_test.go b/internal/provision/account_subdomains_census_test.go| new file mode 100644 |
| index 000000000..e9c863a9f |
| --- /dev/null |
| +++ b/internal/provision/account_subdomains_census_test.go |
| @@ -0,0 +1,23 @@ |
| +package provision |
| + |
| +// accountSubdomainsWriteCensusInventory is the account subdomains review of |
| +// the record-write census (spec 2026-11-11-account-subdomains-design.md), |
| +// layered on linkedDeploymentsSlice1WriteCensusInventory. Later tasks of the |
| +// plan add their re-pins and new units here. |
| +// |
| +// Task 2 (the namespace claim in internal/domains) adds one unit; no record |
| +// write is added and no existing unit changes: |
| +// - AttachAccountNamespace (new): writes the account namespace claim at |
| +// domains.ClaimKey("*.<name>.<apps-domain>"), create-only (Put with |
| +// ifMatch ""), after a getClaimETag that answers created=false for any |
| +// claim already at the key. A domains/ claim key, never a record key |
| +// or prefix. nonrecord / sel:Put, the class of |
| +// claimRawAttachInstanceCatchall, the claim writer it models. |
| +// DetachAccountNamespaceAt deletes through release.DeleteIfMatch, which |
| +// the census does not count as a write site. |
| +func accountSubdomainsWriteCensusInventory() []censusEntry { |
| + entries := append([]censusEntry(nil), linkedDeploymentsSlice1WriteCensusInventory()...) |
| + return append(entries, |
| + censusEntry{"internal/domains/namespace.go", "AttachAccountNamespace", "nonrecord", "sel:Put", "cca934a1385e98ad1decbf49f968a447a54f6983f4d277da7706b16773acd486"}, |
| + ) |
| +} |
diff --git a/internal/provision/plan9_b8_census_test.go b/internal/provision/plan9_b8_census_test.go| index 9f059ae49..a0feab11a 100644 |
| --- a/internal/provision/plan9_b8_census_test.go |
| +++ b/internal/provision/plan9_b8_census_test.go |
| @@ -366,7 +366,7 @@ func TestPlan9B8RecordWriteCensus(t *testing.T) { |
| if len(got) < 100 { |
| t.Fatalf("census found only %d units under %s; the walk is broken", len(got), root) |
| } |
| - inventory := linkedDeploymentsSlice1WriteCensusInventory() |
| + inventory := accountSubdomainsWriteCensusInventory() |
| problems := append(censusDiff(inventory, got), censusPolicy(inventory)...) |
| if len(problems) > 0 { |
| t.Fatalf("record-write census rejected %d site(s); update the explicit inventory only after reviewing the source:\n %s", len(problems), strings.Join(problems, "\n ")) |
diff --git a/internal/provision/testdata/plan14-root-reads-account-subdomains.tsv b/internal/provision/testdata/plan14-root-reads-account-subdomains.tsv| new file mode 100644 |
| index 000000000..a2f68a582 |
| --- /dev/null |
| +++ b/internal/provision/testdata/plan14-root-reads-account-subdomains.tsv |
| @@ -0,0 +1,3 @@ |
| +# Census overlay account-subdomains, written by census-propose (#369). census-ruling-account-subdomains, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-account-subdomains.md. |
| +# 0 body, 0 sites, 1 envelope: each changed unit re-frozen at its existing disposition with its claim appended. |
| +@coverage internal/domains 193d28bd67b0ece5f2a69ae7b44d287839edd2d074d16f915ff0882920274556 |
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv| index 13b555735..20af63c41 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-chain.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-chain.tsv |
| @@ -173,3 +173,4 @@ plan14-root-reads-stats-prune-400.tsv 75b32391a24d2c9269fc579aae68ac80b7b1d4ccf0 |
| plan14-root-reads-group-observation-carry.tsv 587f6e92c5e594b9bb6436a2d0066849454407202e311f43483bed3be4591940 |
| plan14-root-reads-activator-settle-wait.tsv b3d35a0bd7c0500c74efbe5e8f566adb623696d31bd9860164907e08a2e79369 |
| plan14-root-reads-lease-checkpoint-no-compaction.tsv b3d35a0bd7c0500c74efbe5e8f566adb623696d31bd9860164907e08a2e79369 |
| +plan14-root-reads-account-subdomains.tsv b3d35a0bd7c0500c74efbe5e8f566adb623696d31bd9860164907e08a2e79369 |