console: account subdomain review fixes, round 1 (T6)
- Census: re-pin handleAPIInstanceList, handleAPIInstanceUpdate, handleAPIInstanceChannel, handleAppInstance and routeDecls in the account subdomains overlay; no record write added, class and kinds kept. - Set fails closed on an unread namespace claim: refused before the write when one may be the account's, and any unread namespace claim in the re-read rolls back. - Inventory lists *.<label> catch-alls under their label. - Display only what a box serves: replicas excluded (as namespacealiases.go), records and routes through one rule, the canary flash only for derivable routes. - Instance page: the host's own derived alias is not listed again under Web addresses; other aliases stay as they are. - Stable codes rollback_failed, remove_blocked, not_found; an unknown account answers JSON. - Tests: unread second name and unread own claim, replica routes, hand canary route, rollback bumps the serial (ruled exception), 403 for service tokens on every method; neutral bab/shop fixtures. - UX mock: em dash removed, settings screenshots re-shot.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs/superpowers/plans/account-subdomains-ux/settings-dark-1280.pngbinarydocs/superpowers/plans/account-subdomains-ux/settings-dark-390.pngbinarydocs/superpowers/plans/account-subdomains-ux/settings-light-1280.pngbinarydocs/superpowers/plans/account-subdomains-ux/settings-light-390.pngbinarydocs/superpowers/plans/account-subdomains-ux/settings-mock.html+1 −1internal/console/apiinstances.go+3 −3internal/console/apiroutes.go+0 −10internal/console/apisubdomain.go+38 −11internal/console/apisubdomain_test.go+77 −8internal/console/canonical.go+49 −6internal/console/canonical_test.go+69 −14internal/console/claim_invariant_fixtures_test.go+13 −6internal/console/instancepage.go+9 −0internal/console/remoteinstances.go+1 −0internal/console/server.go+2 −2internal/console/view.go+5 −2internal/provision/account_subdomains_census_test.go+36 −0
Intent
<task-notification> <task-id>a43e438c6ef448f9e</task-id> <tool-use-id>toolu_01KH51jEsQXKPNfy4YYqbJuR</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/709ac745-ee81-4971-97b8-321e18b19cf6/tasks/a43e438c6ef448f9e.output</output-file> <status>completed</status> <summary>Agent "Implement Task 6: door + canonical URLs" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>Status: DONE_WITH_CONCERNS Commits: - `db268270` docs: account subdomains UX pass, settings row and app header (T6). The kit mocks and 8 screenshots (390 and 1280 px, light and dark) are in `docs/superpowers/plans/account-subdomains-ux/`. - `e990eebb` console: subdomain door; name URL is canonical (T6) Tests: RED was a build failure (`canonicalHostIn` undefined). GREEN: the brief's Step 2 selector plus every Task 5 test passes (118s), along with targeted regressions over the touched pages and APIs. `go build ./...` and vet are clean. Concerns (full list in the report): 1. A non-operator gets a 404 that carries the approved `refuse.not_operator` sentence. 2. The inventory also refuses while host claims are on, as the brief asks for every method. 3. A set that is rolled back still resets the claim cache and bumps the serial, because a write landed. 4. `public_host` is left out when it equals `host`, so the Task 7 CLI must fall back to `host`. 5. Pages only rewrite routes a box derives names for (provisioned or platform, not sidecar), so a hand-added route never shows a name URL that wouldn't work. The brief didn't ask for this. 6. The demo claim page and status door now make one bucket LIST in the "claimed" state. I let that test's no-remote fake answer the claim listing; a reviewer may prefer those surfaces stay bucket-free. 7. Set and remove write a log line but no audit row, since there is no approved copy for one. Report: `/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-account-name-hosts/.superpowers/sdd/2026-11-11-account-subdomains/task-6-report.md`</result> <usage><subagent_tokens>408673</subagent_tokens><tool_uses>181</tool_uses><duration_ms>2866883</duration_ms></usage> </task-notification>
<task-notification> <task-id>bk62sy7ku</task-id> <tool-use-id>toolu_01Hm1Wy2X71R8h15N3K8fCyW</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/709ac745-ee81-4971-97b8-321e18b19cf6/tasks/bk62sy7ku.output</output-file> <status>completed</status> <summary>Background command "Package and run Astra + Fable review of T6" completed (exit code 0)</summary> </task-notification>
Attributed to this commit: 18.5 g CO₂e (2,359,834 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/plans/account-subdomains-ux/settings-dark-1280.png b/docs/superpowers/plans/account-subdomains-ux/settings-dark-1280.png| index 1b470209a..9915dff12 100644 |
| Binary files a/docs/superpowers/plans/account-subdomains-ux/settings-dark-1280.png and b/docs/superpowers/plans/account-subdomains-ux/settings-dark-1280.png differ |
diff --git a/docs/superpowers/plans/account-subdomains-ux/settings-dark-390.png b/docs/superpowers/plans/account-subdomains-ux/settings-dark-390.png| index 68f37296b..2d901cd13 100644 |
| Binary files a/docs/superpowers/plans/account-subdomains-ux/settings-dark-390.png and b/docs/superpowers/plans/account-subdomains-ux/settings-dark-390.png differ |
diff --git a/docs/superpowers/plans/account-subdomains-ux/settings-light-1280.png b/docs/superpowers/plans/account-subdomains-ux/settings-light-1280.png| index ba713e027..25e44b8d5 100644 |
| Binary files a/docs/superpowers/plans/account-subdomains-ux/settings-light-1280.png and b/docs/superpowers/plans/account-subdomains-ux/settings-light-1280.png differ |
diff --git a/docs/superpowers/plans/account-subdomains-ux/settings-light-390.png b/docs/superpowers/plans/account-subdomains-ux/settings-light-390.png| index 47d4f348c..272043b36 100644 |
| Binary files a/docs/superpowers/plans/account-subdomains-ux/settings-light-390.png and b/docs/superpowers/plans/account-subdomains-ux/settings-light-390.png differ |
diff --git a/docs/superpowers/plans/account-subdomains-ux/settings-mock.html b/docs/superpowers/plans/account-subdomains-ux/settings-mock.html| index 1f8bdf0fc..30d3e4893 100644 |
| --- a/docs/superpowers/plans/account-subdomains-ux/settings-mock.html |
| +++ b/docs/superpowers/plans/account-subdomains-ux/settings-mock.html |
| @@ -1189,7 +1189,7 @@ |
| <div class="pagehead"> |
| <p class="eyebrow">Account · shop</p> |
| <h1>Account settings</h1> |
| - <p class="lede">The account itself — what it's called, and how it ends.</p> |
| + <p class="lede">The account itself: what it's called, and how it ends.</p> |
| </div> |
| <h2>Identity</h2> |
| <div class="tablewrap"> |
diff --git a/internal/console/apiinstances.go b/internal/console/apiinstances.go| index c1a773dc7..13aa3af81 100644 |
| --- a/internal/console/apiinstances.go |
| +++ b/internal/console/apiinstances.go |
| @@ -1333,7 +1333,7 @@ func (s *Server) handleAPIInstanceList(w http.ResponseWriter, r *http.Request) { |
| } |
| ro := join.rollout(rec.Host, acct.Sqid, app) |
| refusal, refusalsCapped := join.refusalFor(rec, ro) |
| - matched = append(matched, instanceListRecord{Record: rec, PublicHost: canon.public(rec.Host), |
| + matched = append(matched, instanceListRecord{Record: rec, PublicHost: recordPublicHost(canon, rec), |
| ConfigRefusal: refusal, RefusalsCapped: refusalsCapped, |
| StagedVersion: join.versions[rec.Host], Health: h, Upstreams: join.upstreams[rec.Host], |
| ServedBy: served[rec.Host], Gated: rec.Gate != "", DBBytes: join.dbSize(rec.Host), |
| @@ -1420,7 +1420,7 @@ func (s *Server) handleAPIInstanceGet(w http.ResponseWriter, r *http.Request) { |
| return |
| } |
| home, names := s.regionHome(), s.regionNames() |
| - writeJSON(w, http.StatusOK, instanceGetRecord{Record: *rec, PublicHost: s.canon(ctx).public(rec.Host), |
| + writeJSON(w, http.StatusOK, instanceGetRecord{Record: *rec, PublicHost: recordPublicHost(s.canon(ctx), *rec), |
| ServedBy: loadEdgesJoin(ctx, s.cfg.Releases)[host], Gated: rec.Gate != "", |
| RegionName: regionlabel.ForRecord(*rec, home, names).Text, MovePhrase: regionlabel.MovePhrase(*rec, home, names)}) |
| } |
| @@ -1487,7 +1487,7 @@ func recordView(rec provision.Record) apiRecordView { |
| // platform shows it (canonical.go). |
| func (s *Server) publicRecordView(ctx context.Context, rec provision.Record) apiRecordView { |
| v := recordView(rec) |
| - v.PublicHost = s.canon(ctx).public(rec.Host) |
| + v.PublicHost = recordPublicHost(s.canon(ctx), rec) |
| return v |
| } |
diff --git a/internal/console/apiroutes.go b/internal/console/apiroutes.go| index 6846554a3..e757fac50 100644 |
| --- a/internal/console/apiroutes.go |
| +++ b/internal/console/apiroutes.go |
| @@ -228,13 +228,3 @@ func (s *Server) handleAPIRoutes(w http.ResponseWriter, r *http.Request) { |
| // CLI prints them in under each host. |
| writeJSON(w, http.StatusOK, map[string]any{"routes": rows, "paths": paths}) |
| } |
| - |
| -// routePublicHost is rt's public_host: the name host where the account has a |
| -// subdomain and a box derives one for rt (canonical.go, derivesName), else |
| -// "". |
| -func routePublicHost(c *hostCanon, rt registry.Route) string { |
| - if !derivesName(rt.Provisioned, rt.Platform, rt.Kind) { |
| - return "" |
| - } |
| - return c.public(rt.Host) |
| -} |
diff --git a/internal/console/apisubdomain.go b/internal/console/apisubdomain.go| index 0a9f200b3..0a61752c5 100644 |
| --- a/internal/console/apisubdomain.go |
| +++ b/internal/console/apisubdomain.go |
| @@ -54,6 +54,20 @@ type subdomainReply struct { |
| Foreign []occupant `json:"foreign"` |
| } |
| +// The door's own refusal codes, beside domains.SubdomainRefusal's: stable |
| +// wire values the CLI maps to its copy. |
| +const ( |
| + // subdomainCodeRollbackFailed: set wrote the claim, the re-read found a |
| + // conflict, and deleting the claim again failed; the name is held. |
| + subdomainCodeRollbackFailed domains.SubdomainRefusal = "rollback_failed" |
| + // subdomainCodeRemoveBlocked: remove refused while the account still |
| + // has hosts under the name. |
| + subdomainCodeRemoveBlocked domains.SubdomainRefusal = "remove_blocked" |
| + // subdomainCodeNotFound: the path names no account (live, for set; live |
| + // or deleted, for show and remove). Only an operator gets this far. |
| + subdomainCodeNotFound = "not_found" |
| +) |
| + |
| // subdomainRefuse writes a refusal: the approved sentence, the rule's code, |
| // and, when the refusal is about hosts, those hosts (never null then). |
| func subdomainRefuse(w http.ResponseWriter, status int, code domains.SubdomainRefusal, msg string, hosts []occupant, listed bool) { |
| @@ -105,7 +119,9 @@ func (s *Server) subdomainAccount(w http.ResponseWriter, r *http.Request, delete |
| log.Printf("console: subdomain door: account %q: %v", seg, err) |
| } |
| if err != nil || acct == nil { |
| - http.NotFound(w, r) |
| + // JSON like every other answer of the door, with the plain 404's |
| + // own words; the CLI says it in its copy from the code. |
| + jsonErrorCode(w, http.StatusNotFound, subdomainCodeNotFound, "404 page not found") |
| return "", nil, false |
| } |
| return addr, acct, true |
| @@ -255,6 +271,15 @@ func (s *Server) handleAPISubdomainSet(w http.ResponseWriter, r *http.Request) { |
| writeJSON(w, http.StatusOK, s.subdomainShown(acct, name, nil)) |
| return |
| } |
| + // One name per account, established by a complete read: a namespace |
| + // claim that did not read and may be this account's (it names the |
| + // account, or nothing read has said whose it is) could be a name it |
| + // already holds, so nothing is written until it reads. |
| + if v.mayHoldUnread(acct.Sqid) { |
| + log.Printf("console: subdomain set %s %s: a namespace claim that may be the account's did not read", acct.Sqid, name) |
| + s.refuseSubdomain(w, domains.SubdomainUnreadable, acct, req.Name, name, "", nil) |
| + return |
| + } |
| domain := s.appsDomain() |
| host := domains.NamespaceHost(name, domain) |
| created, err := domains.AttachAccountNamespace(ctx, s.cfg.Releases, name, domain, acct.Sqid, |
| @@ -300,9 +325,10 @@ func (s *Server) handleAPISubdomainSet(w http.ResponseWriter, r *http.Request) { |
| // subdomainReread is set's read after its write (§4.2, the race): conflict |
| // when the walk under the name fails or finds another account's host, when |
| -// the view does not show name as the account's, or when the account now |
| -// holds another name too (read, or a namespace claim naming it that did not |
| -// read). found is the other accounts' hosts the walk found. |
| +// the view does not show name as the account's, when the account now holds |
| +// another name too, or when any namespace claim did not read, whoever it |
| +// may belong to (one name per account is established by a complete read). |
| +// found is the other accounts' hosts the walk found. |
| func (s *Server) subdomainReread(ctx context.Context, account, name string) (found []occupant, conflict bool) { |
| v, err := s.loadNamespaces(ctx) |
| if err != nil { |
| @@ -320,10 +346,8 @@ func (s *Server) subdomainReread(ctx context.Context, account, name string) (fou |
| } |
| } |
| for other := range v.unread { |
| - if v.unreadBy[other] == account { |
| - log.Printf("console: subdomain set %s %s: re-read: a namespace claim of the account's at %s did not read", account, name, other) |
| - return nil, true |
| - } |
| + log.Printf("console: subdomain set %s %s: re-read: the namespace claim for %s did not read (account %q)", account, name, other, v.unreadBy[other]) |
| + return nil, true |
| } |
| occ, err := s.namespaceOccupants(ctx, name) |
| if err != nil { |
| @@ -347,7 +371,7 @@ func (s *Server) subdomainRollBack(w http.ResponseWriter, ctx context.Context, a |
| host := domains.NamespaceHost(name, domain) |
| failed := func(err error) { |
| log.Printf("console: subdomain set %s %s: rollback: %v; the name is still held", acct.Sqid, name, err) |
| - jsonErrorCode(w, http.StatusInternalServerError, string(domains.SubdomainRolledBack), |
| + jsonErrorCode(w, http.StatusInternalServerError, string(subdomainCodeRollbackFailed), |
| fmt.Sprintf(subdomainRefuseRollbackFailedCopy, name, acct.Sqid, acct.Sqid)) |
| } |
| cur, etag, err := domains.GetClaimETag(ctx, s.cfg.Releases, host) |
| @@ -418,7 +442,7 @@ func (s *Server) handleAPISubdomainDelete(w http.ResponseWriter, r *http.Request |
| } |
| } |
| if len(own) > 0 { |
| - subdomainRefuse(w, http.StatusConflict, domains.SubdomainOccupied, |
| + subdomainRefuse(w, http.StatusConflict, subdomainCodeRemoveBlocked, |
| fmt.Sprintf(subdomainRefuseRemoveBlockedCopy, acct.Sqid, root), own, true) |
| return |
| } |
| @@ -493,8 +517,11 @@ func (s *Server) subdomainInventory(ctx context.Context) ([]subdomainInventoryLa |
| if err != nil { |
| return nil, err |
| } |
| + // The "*" of a catch-all counts as a label: *.team.<apps> (an instance |
| + // catch-all on team.<apps>) is under team like x.team.<apps>, and blocks |
| + // assigning team to anyone but its holder just the same. |
| under := func(host string) (string, bool) { |
| - label, depth := s.appsLabel(strings.TrimPrefix(host, "*.")) |
| + label, depth := s.appsLabel(host) |
| return label, depth >= 2 |
| } |
| for _, u := range unread { |
diff --git a/internal/console/apisubdomain_test.go b/internal/console/apisubdomain_test.go| index 4655c61ac..d96ca0532 100644 |
| --- a/internal/console/apisubdomain_test.go |
| +++ b/internal/console/apisubdomain_test.go |
| @@ -15,6 +15,7 @@ import ( |
| "net/http" |
| "os" |
| "reflect" |
| + "strings" |
| "sync" |
| "testing" |
| "time" |
| @@ -91,6 +92,14 @@ type nsRaceStore struct { |
| after func() |
| once sync.Once |
| failDelete bool |
| + failGet string // a key whose reads fail |
| +} |
| + |
| +func (s *nsRaceStore) Get(ctx context.Context, key string) ([]byte, string, error) { |
| + if s.failGet != "" && key == s.failGet { |
| + return nil, "", errors.New("nsRaceStore: read refused") |
| + } |
| + return s.Store.Get(ctx, key) |
| } |
| func (s *nsRaceStore) Put(ctx context.Context, key string, body []byte, ifMatch string) (string, error) { |
| @@ -123,9 +132,20 @@ func TestSubdomainDoorOperatorOnly(t *testing.T) { |
| } |
| } |
| } |
| - app := serviceToken(t, fx.st, OpsAccountID, "svc-sd", "shop", svcrole.Admin) |
| - if code, _, out := sdReq(t, fx, http.MethodPost, "bdq", app, `{"name":"harbour"}`); code == http.StatusOK { |
| - t.Errorf("POST by an app token = %d %s, want refused", code, out) |
| + // A service credential, any role, meets the shared gate's closed-door |
| + // 403 (cliGateRefused: Set{} admits no role), on every method and the |
| + // inventory, before the handler runs. |
| + for _, role := range []svcrole.Role{svcrole.Service, svcrole.Admin} { |
| + app := serviceToken(t, fx.st, OpsAccountID, "svc-sd-"+string(role), "shop", role) |
| + for _, m := range []string{http.MethodGet, http.MethodPost, http.MethodDelete} { |
| + if code, _, out := sdReq(t, fx, m, "bdq", app, `{"name":"harbour"}`); code != http.StatusForbidden || !strings.Contains(out, "closed to service credentials") { |
| + t.Errorf("%s by a %s token = %d %s, want the closed-door 403", m, role, code, out) |
| + } |
| + } |
| + code, _, out := rawReq(t, http.MethodGet, fx.ts.URL+"/api/cli/system/subdomain-inventory", app, "") |
| + if code != http.StatusForbidden || !strings.Contains(out, "closed to service credentials") { |
| + t.Errorf("inventory by a %s token = %d %s, want the closed-door 403", role, code, out) |
| + } |
| } |
| if c := nsClaimAt(t, fx, nsHarbourHost); c != nil { |
| t.Fatalf("a refused caller wrote %+v", c) |
| @@ -138,8 +158,10 @@ func TestSubdomainDoorOperatorOnly(t *testing.T) { |
| if code, _, out := sdReq(t, fx, http.MethodGet, "bdq", sys, ""); code != http.StatusOK { |
| t.Errorf("GET by a system operator = %d %s, want 200", code, out) |
| } |
| - if code, _, _ := sdReq(t, fx, http.MethodGet, "bzz", operator, ""); code != http.StatusNotFound { |
| - t.Errorf("GET of an account nobody holds = %d, want 404", code) |
| + for _, m := range []string{http.MethodGet, http.MethodPost, http.MethodDelete} { |
| + if code, a, out := sdReq(t, fx, m, "bzz", operator, `{"name":"harbour"}`); code != http.StatusNotFound || a.Code != subdomainCodeNotFound { |
| + t.Errorf("%s of an account nobody holds = %d %s, want 404 code %q", m, code, out, subdomainCodeNotFound) |
| + } |
| } |
| } |
| @@ -208,6 +230,50 @@ func TestSubdomainDoorRollsBackOnRace(t *testing.T) { |
| if c := nsClaimAt(t, fx, nsHarbourHost); c != nil { |
| t.Errorf("the rolled-back namespace claim is still there: %+v", c) |
| } |
| + // Ruled exception to the brief (Task 6 fix round 1): a claim landed and |
| + // a box may have read it, so the rollback resets the cache and bumps |
| + // the serial like an effective write. |
| + if got := serial(t, fx); got != 1 { |
| + t.Errorf("serial after a rolled-back set = %d, want 1", got) |
| + } |
| +} |
| + |
| +// TestSubdomainDoorRollsBackUnreadSecondName: a second namespace claim for |
| +// the account lands after the write and its read fails. Nobody can say |
| +// whose it is, so one name per account is not established: rolled back. |
| +func TestSubdomainDoorRollsBackUnreadSecondName(t *testing.T) { |
| + fx, operator, _ := sdFixture(t, "code-sd-second-unread") |
| + marina := domains.ClaimKey(domains.NamespaceHost("marina", nsApps)) |
| + fx.srv.cfg.Releases = &nsRaceStore{Store: fx.rel, key: domains.ClaimKey(nsHarbourHost), failGet: marina, |
| + after: func() { nsHold(t, fx, "marina", "bdq") }} |
| + fx.srv.claims.Reset() |
| + code, a, out := sdReq(t, fx, http.MethodPost, "bdq", operator, `{"name":"harbour"}`) |
| + if code != http.StatusConflict || a.Code != string(domains.SubdomainRolledBack) { |
| + t.Fatalf("set while an unread second name lands = %d %s, want 409 rolled_back", code, out) |
| + } |
| + if c := nsClaimAt(t, fx, nsHarbourHost); c != nil { |
| + t.Errorf("the rolled-back namespace claim is still there: %+v", c) |
| + } |
| +} |
| + |
| +// TestSubdomainSetRefusedWhileOwnClaimUnread: bdq already holds marina, but |
| +// its claim does not read and nothing has said whose it is. Set refuses |
| +// before writing, retryably: bdq may already have a name. |
| +func TestSubdomainSetRefusedWhileOwnClaimUnread(t *testing.T) { |
| + fx, operator, _ := sdFixture(t, "code-sd-own-unread") |
| + nsHold(t, fx, "marina", "bdq") |
| + fx.srv.cfg.Releases = &nsFaultStore{Store: fx.rel, failGet: domains.ClaimKey(domains.NamespaceHost("marina", nsApps))} |
| + fx.srv.claims.Reset() |
| + code, a, out := sdReq(t, fx, http.MethodPost, "bdq", operator, `{"name":"harbour"}`) |
| + if want := fmt.Sprintf(subdomainRefuseUnreadableCopy, "harbour."+nsApps); code != http.StatusBadGateway || a.Error != want || a.Code != string(domains.SubdomainUnreadable) { |
| + t.Errorf("set with bdq's own claim unread = %d %s, want 502 %q", code, out, want) |
| + } |
| + if c := nsClaimAt(t, fx, nsHarbourHost); c != nil { |
| + t.Errorf("the refused set wrote %+v", c) |
| + } |
| + if got := serial(t, fx); got != 0 { |
| + t.Errorf("serial after a refused set = %d, want 0", got) |
| + } |
| } |
| // TestSubdomainDoorRollsBackSecondName: a second name for the same account |
| @@ -241,7 +307,7 @@ func TestSubdomainRollbackFailureReportsHeld(t *testing.T) { |
| fx.srv.claims.Reset() |
| code, a, out := sdReq(t, fx, http.MethodPost, "bdq", operator, `{"name":"harbour"}`) |
| want := fmt.Sprintf(subdomainRefuseRollbackFailedCopy, "harbour", "bdq", "bdq") |
| - if code != http.StatusInternalServerError || a.Error != want { |
| + if code != http.StatusInternalServerError || a.Error != want || a.Code != string(subdomainCodeRollbackFailed) { |
| t.Fatalf("set whose rollback fails = %d %s, want 500 %q", code, out, want) |
| } |
| if c := nsClaimAt(t, fx, nsHarbourHost); c == nil { |
| @@ -380,7 +446,7 @@ func TestSubdomainRemoveRefusedWhileHandAttached(t *testing.T) { |
| nsPutClaim(t, fx, domains.Claim{Schema: 1, Host: "blog.harbour." + nsApps, Account: "bdq", App: "blog", CreatedAt: time.Now().UTC().Format(time.RFC3339)}) |
| code, a, out := sdReq(t, fx, http.MethodDelete, "bdq", operator, "") |
| want := fmt.Sprintf(subdomainRefuseRemoveBlockedCopy, "bdq", "harbour."+nsApps) |
| - if code != http.StatusConflict || a.Error != want { |
| + if code != http.StatusConflict || a.Error != want || a.Code != string(subdomainCodeRemoveBlocked) { |
| t.Fatalf("remove with a hand-attached claim = %d %s, want 409 %q", code, out, want) |
| } |
| if wantHosts := []sdHost{{Host: "blog.harbour." + nsApps, Account: "bdq", App: "blog", Source: occupantClaim}}; !reflect.DeepEqual(a.Hosts, wantHosts) { |
| @@ -502,7 +568,9 @@ func TestSubdomainInventory(t *testing.T) { |
| put := func(host, account string) { |
| nsPutClaim(t, fx, domains.Claim{Schema: 1, Host: host, Account: account, App: "web", CreatedAt: now.Format(time.RFC3339)}) |
| } |
| - put("x.team."+nsApps, "bdq") // legacy, under an unassigned label |
| + put("x.team."+nsApps, "bdq") // legacy, under an unassigned label |
| + nsPutClaim(t, fx, domains.Claim{Schema: 1, Host: "*.dock." + nsApps, Account: "bdq", App: "web", Instances: true, |
| + CreatedAt: now.Format(time.RFC3339)}) // a legacy instance catch-all on dock.<apps>, no instance yet |
| put("shop.bdq."+nsApps, "bdq") // under bdq's own sqid |
| put("shop."+fx.sqid+"."+nsApps, fx.sqid) // under bab's own sqid |
| put("team."+nsApps, "bdq") // one label: not under a label |
| @@ -530,6 +598,7 @@ func TestSubdomainInventory(t *testing.T) { |
| t.Fatalf("inventory = %d %s (%v)", code, out, err) |
| } |
| want := []label{ |
| + {Label: "dock", Hosts: []sdHost{{Host: "*.dock." + nsApps, Account: "bdq", App: "web", Source: occupantClaim}}}, |
| {Label: "pier", Hosts: []sdHost{{Host: "z.pier." + nsApps, Account: "bdq", App: "web", Source: occupantRecord}}}, |
| {Label: "team", Hosts: []sdHost{{Host: "x.team." + nsApps, Account: "bdq", App: "web", Source: occupantClaim}}}, |
| } |
diff --git a/internal/console/canonical.go b/internal/console/canonical.go| index 004e2c1ff..b5debf5cf 100644 |
| --- a/internal/console/canonical.go |
| +++ b/internal/console/canonical.go |
| @@ -20,6 +20,9 @@ import ( |
| "log" |
| "strings" |
| "sync" |
| + |
| + "github.com/carlosframework/platform/internal/provision" |
| + "github.com/carlosframework/platform/internal/registry" |
| ) |
| // canonicalHostIn is host as the platform shows it: for a host |
| @@ -93,11 +96,51 @@ func (c *hostCanon) public(h string) string { |
| } |
| // derivesName reports whether a box derives a name host for a route like |
| -// this one (domains.ReconcileNamespaceAliases: provisioned or platform |
| -// routes, never a sidecar). A hand-added route gets no name alias, so its |
| -// name URL would not answer, and it is shown as it is. |
| -func derivesName(provisioned, platform bool, kind string) bool { |
| - return (provisioned || platform) && kind != "sidecar" |
| +// this one (deriveNamespaceAliases, internal/domains/namespacealiases.go: |
| +// provisioned or platform routes, never a sidecar or a replica). Any other |
| +// route (a hand-added one above all) gets no name alias, so its name URL |
| +// would not answer, and it is shown as it is. |
| +func derivesName(provisioned, platform, replica bool, kind string) bool { |
| + return (provisioned || platform) && kind != "sidecar" && !replica |
| +} |
| + |
| +// recordPublicHost is a record's public_host: records are provisioned, so |
| +// the name host where the account has one, unless the record is a replica |
| +// or a sidecar (derivesName); "" when it would be the host itself. |
| +func recordPublicHost(c *hostCanon, rec provision.Record) string { |
| + if !derivesName(true, false, rec.Role == "replica", rec.KindOrDefault()) { |
| + return "" |
| + } |
| + return c.public(rec.Host) |
| +} |
| + |
| +// routePublicHost is a registry row's public_host, by the same rule. |
| +func routePublicHost(c *hostCanon, rt registry.Route) string { |
| + if !derivesName(rt.Provisioned, rt.Platform, rt.Replica, rt.Kind) { |
| + return "" |
| + } |
| + return c.public(rt.Host) |
| +} |
| + |
| +// channelFlashHost is host as the canary create flash names it: the name |
| +// host only when the console box's registry row at host is one a box |
| +// derives a name for, or when no row is there (a record: provisioned). |
| +// A registry that cannot be read leaves the host as it is. |
| +func (s *Server) channelFlashHost(c *hostCanon, host string) string { |
| + reg, err := openRegistry(s.cfg.Registry) |
| + if err != nil { |
| + return host |
| + } |
| + routes, err := reg.List() |
| + if err != nil { |
| + return host |
| + } |
| + for _, rt := range routes { |
| + if rt.Host == host && !derivesName(rt.Provisioned, rt.Platform, rt.Replica, rt.Kind) { |
| + return host |
| + } |
| + } |
| + return c.host(host) |
| } |
| // canonicalViews sets the shown host of every host views carry: each |
| @@ -110,7 +153,7 @@ func (c *hostCanon) canonicalViews(views []AppView) { |
| shown := map[string]string{} |
| for j := range v.Routes { |
| rt := &v.Routes[j] |
| - if derivesName(rt.Provisioned, rt.Platform, rt.Kind) { |
| + if derivesName(rt.Provisioned, rt.Platform, rt.Replica, rt.Kind) { |
| rt.PublicHost = c.host(rt.Host) |
| shown[rt.Host] = rt.PublicHost |
| } |
diff --git a/internal/console/canonical_test.go b/internal/console/canonical_test.go| index 5d55ea6d9..423800960 100644 |
| --- a/internal/console/canonical_test.go |
| +++ b/internal/console/canonical_test.go |
| @@ -108,26 +108,81 @@ func TestInstanceListLinksToName(t *testing.T) { |
| _, _, body = get(t, c, fx.u("/apps/shop/instances")) |
| canonHas(t, "the instance list with a hand route", body, `href="https://hand.shop.bab.`+nsApps+`"`) |
| canonLacks(t, "the instance list with a hand route", body, "hand.shop.harbour") |
| + // The box's derived name alias row and a custom alias: the page's |
| + // heading is the name host, so the derived row is not listed again |
| + // under Web addresses; the custom one is. |
| + reg := openTestReg(t, fx) |
| + for _, a := range []string{"c1.shop.harbour." + nsApps, "www.shop.example.com"} { |
| + if err := reg.UpsertAlias(registry.RouteAlias{Alias: a, Host: "c1.shop.bab." + nsApps, Account: "bab", App: "shop"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + reg.Close() |
| _, _, body = get(t, c, fx.u("/apps/shop/instances/c1.shop.bab."+nsApps)) |
| canonHas(t, "the instance page", body, `href="https://c1.shop.harbour.`+nsApps+`"`, |
| - appSqidURLLabelCopy, `href="https://c1.shop.bab.`+nsApps+`"`, "logs?host=c1.shop.bab."+nsApps) |
| + appSqidURLLabelCopy, `href="https://c1.shop.bab.`+nsApps+`"`, "logs?host=c1.shop.bab."+nsApps, |
| + `<div><a href="https://www.shop.example.com">`) |
| + canonLacks(t, "the instance page", body, `<div><a href="https://c1.shop.harbour.`+nsApps+`">`) |
| } |
| // TestCanaryLinksUseName: the canary create flash and the Canaries table |
| -// both name the name URL. |
| +// both name the name URL for a route a box derives a name for; a |
| +// hand-added route following the canary is named as it is. |
| func TestCanaryLinksUseName(t *testing.T) { |
| - fx := newConsoleFixture(t) |
| - fx.srv.cfg.AppsDomain = nsApps |
| - nsHold(t, fx, "harbour", fx.sqid) |
| - c := signInPaul(t, fx) |
| - csrf := sessionToken(t, fx, c) |
| - fx.addRoute(t, registry.Route{Host: "rc.kass.bab." + nsApps, Kind: "instance", Status: "ready", App: "kass", Account: "bab", |
| - Channel: "canary/rc", Canary: true, Provisioned: true}) |
| - postForm(t, c, fx.u("/apps/kass/canary"), url.Values{"csrf": {csrf}, "name": {"rc"}, "version": {"v1"}}) |
| - _, _, body := get(t, c, fx.u("/apps/kass")) |
| - canonHas(t, "the canary flash", body, "live at https://rc.kass.harbour."+nsApps) |
| - _, _, body = get(t, c, fx.u("/apps/kass/releases")) |
| - canonHas(t, "the canaries table", body, `<a href="https://rc.kass.harbour.`+nsApps+`">rc.kass.harbour.`+nsApps+`</a>`) |
| + for _, c := range []struct { |
| + name string |
| + provisioned bool |
| + want string |
| + }{ |
| + {"provisioned", true, "rc.shop.harbour." + nsApps}, |
| + {"hand-added", false, "rc.shop.bab." + nsApps}, |
| + } { |
| + t.Run(c.name, func(t *testing.T) { |
| + fx, b := canonFixture(t) |
| + shipVersion(t, fx, "shop", "v1") |
| + csrf := sessionToken(t, fx, b) |
| + fx.addRoute(t, registry.Route{Host: "rc.shop.bab." + nsApps, Kind: "instance", Status: "ready", App: "shop", Account: "bab", |
| + Channel: "canary/rc", Canary: true, Provisioned: c.provisioned}) |
| + postForm(t, b, fx.u("/apps/shop/canary"), url.Values{"csrf": {csrf}, "name": {"rc"}, "version": {"v1"}}) |
| + _, _, body := get(t, b, fx.u("/apps/shop")) |
| + canonHas(t, "the canary flash", body, "live at https://"+c.want+" ") |
| + _, _, body = get(t, b, fx.u("/apps/shop/releases")) |
| + canonHas(t, "the canaries table", body, `<a href="https://`+c.want+`">`+c.want+`</a>`) |
| + }) |
| + } |
| +} |
| + |
| +// TestReplicaRoutesKeepTheirHost: no box derives a name for a replica |
| +// route (an edge-checkout shard), so neither the Running tab nor the routes |
| +// read names one. |
| +func TestReplicaRoutesKeepTheirHost(t *testing.T) { |
| + fx, c := canonFixture(t) |
| + host := "r1.shop.bab." + nsApps |
| + fx.addRoute(t, registry.Route{Host: host, App: "shop", Account: "bab", Kind: "instance", Status: "ready", Channel: "stable", |
| + Provisioned: true, Replica: true}) |
| + _, _, body := get(t, c, fx.u("/apps/shop/instances")) |
| + canonHas(t, "the instance list", body, `href="https://`+host+`"`) |
| + canonLacks(t, "the instance list", body, "r1.shop.harbour") |
| + op := cliToken(t, fx, "paul@keymail.dev", "code-canon-replica-cli") |
| + code, _, out := rawReq(t, http.MethodGet, fx.ts.URL+"/api/cli/apps/bab/shop/routes", op, "") |
| + var routes struct { |
| + Routes []struct { |
| + Host string `json:"host"` |
| + PublicHost string `json:"public_host"` |
| + } `json:"routes"` |
| + } |
| + if err := json.Unmarshal([]byte(out), &routes); code != http.StatusOK || err != nil { |
| + t.Fatalf("routes = %d %s", code, out) |
| + } |
| + for _, rt := range routes.Routes { |
| + want := "" |
| + if rt.Host != host { |
| + want = strings.Replace(rt.Host, ".bab.", ".harbour.", 1) |
| + } |
| + if rt.PublicHost != want { |
| + t.Errorf("routes: %s public_host %q, want %q", rt.Host, rt.PublicHost, want) |
| + } |
| + } |
| } |
| // nsCountStore counts the claim listings. It embeds release.Store only, so |
diff --git a/internal/console/claim_invariant_fixtures_test.go b/internal/console/claim_invariant_fixtures_test.go| index 0c1e42afe..1fccb807c 100644 |
| --- a/internal/console/claim_invariant_fixtures_test.go |
| +++ b/internal/console/claim_invariant_fixtures_test.go |
| @@ -46,6 +46,13 @@ import ( |
| // ---- table helpers ---------------------------------------------------------- |
| +// claimEnrollShop is a setup that enrolls bab/shop, for a refusal whose door |
| +// names no app and watches a neutral one. |
| +func claimEnrollShop(t *testing.T, cx *claimCase) { |
| + t.Helper() |
| + cx.enroll(t, "bab", "shop") |
| +} |
| + |
| func claimRead(reason string) claimFixture { return claimFixture{read: reason} } |
| func claimNonApp(reason string) claimFixture { return claimFixture{nonApp: reason} } |
| @@ -1437,22 +1444,22 @@ var claimFixtures = map[string]claimFixture{ |
| // SES delivery events count against the sending app (mail_sender_counts). |
| // Account subdomains (apisubdomain.go): every method of the door and |
| // the inventory refuses on a host-claim console, after the operator |
| - // gate and before any read. bab/titogo is the watched app the |
| - // refusal must leave alone; the doors name no app. |
| + // gate and before any read. The doors name no app; the setup enrolls |
| + // bab/shop as the app the refusal must leave alone. |
| "route GET /api/cli/accounts/{account}/subdomain": {refused: &claimRefusalFixture{ |
| - apps: claimRefs("bab/titogo"), do: claimRefusedAPI(http.MethodGet, "/api/cli/accounts/bab/subdomain", ""), |
| + apps: claimRefs("bab/shop"), setup: claimEnrollShop, do: claimRefusedAPI(http.MethodGet, "/api/cli/accounts/bab/subdomain", ""), |
| status: http.StatusConflict, msg: subdomainRefuseHostClaimsCopy, |
| }}, |
| "route POST /api/cli/accounts/{account}/subdomain": {refused: &claimRefusalFixture{ |
| - apps: claimRefs("bab/titogo"), do: claimRefusedAPI(http.MethodPost, "/api/cli/accounts/bab/subdomain", `{"name":"harbour"}`), |
| + apps: claimRefs("bab/shop"), setup: claimEnrollShop, do: claimRefusedAPI(http.MethodPost, "/api/cli/accounts/bab/subdomain", `{"name":"harbour"}`), |
| status: http.StatusConflict, msg: subdomainRefuseHostClaimsCopy, |
| }}, |
| "route DELETE /api/cli/accounts/{account}/subdomain": {refused: &claimRefusalFixture{ |
| - apps: claimRefs("bab/titogo"), do: claimRefusedAPI(http.MethodDelete, "/api/cli/accounts/bab/subdomain", ""), |
| + apps: claimRefs("bab/shop"), setup: claimEnrollShop, do: claimRefusedAPI(http.MethodDelete, "/api/cli/accounts/bab/subdomain", ""), |
| status: http.StatusConflict, msg: subdomainRefuseHostClaimsCopy, |
| }}, |
| "route GET /api/cli/system/subdomain-inventory": {refused: &claimRefusalFixture{ |
| - apps: claimRefs("bab/titogo"), do: claimRefusedAPI(http.MethodGet, "/api/cli/system/subdomain-inventory", ""), |
| + apps: claimRefs("bab/shop"), setup: claimEnrollShop, do: claimRefusedAPI(http.MethodGet, "/api/cli/system/subdomain-inventory", ""), |
| status: http.StatusConflict, msg: subdomainRefuseHostClaimsCopy, |
| }}, |
| "route POST /api/cli/fleets/{account}/managed-plan": {refused: &claimRefusalFixture{ |
diff --git a/internal/console/instancepage.go b/internal/console/instancepage.go| index f4ffd4edf..305d220dd 100644 |
| --- a/internal/console/instancepage.go |
| +++ b/internal/console/instancepage.go |
| @@ -6,6 +6,7 @@ import ( |
| "fmt" |
| "net/http" |
| "net/url" |
| + "slices" |
| "sort" |
| "time" |
| @@ -314,6 +315,14 @@ func (s *Server) handleAppInstance(w http.ResponseWriter, r *http.Request) { |
| sort.Strings(detail.Aliases) |
| } |
| } |
| + // The aliases are listed as they are, not through canonicalHostIn: a |
| + // box derives name hosts for routes, never for alias rows, so a name |
| + // form of an alias would be an address nothing serves. The one alias |
| + // left out is this host's own derived name alias, when the account has |
| + // a subdomain: it is the page's heading already (canonical.go). |
| + if shown := detail.Row.ShownHost(); shown != host { |
| + detail.Aliases = slices.DeleteFunc(detail.Aliases, func(a string) bool { return a == shown }) |
| + } |
| p.InstanceDetail = detail |
| p.InstanceQuery = parseInstanceQuery(r.URL.Query()) |
| p.InstanceListURL = p.Nav + "/apps/" + p.AppName + "/instances" + instanceQuerySuffix(p.InstanceQuery) |
diff --git a/internal/console/remoteinstances.go b/internal/console/remoteinstances.go| index 1dcecea05..735991dd4 100644 |
| --- a/internal/console/remoteinstances.go |
| +++ b/internal/console/remoteinstances.go |
| @@ -435,6 +435,7 @@ func remoteRoute(rec provision.Record, rep *hostReport, f appFacts, acct string, |
| Account: acct, |
| Environment: rec.Environment, |
| Provisioned: true, |
| + Replica: rec.Role == "replica", |
| remote: true, |
| tenant: metrics.Owner{Account: rec.Account, App: rec.App}, |
| since: rec.CreatedAt, |
diff --git a/internal/console/server.go b/internal/console/server.go| index 739752018..a87c35ed2 100644 |
| --- a/internal/console/server.go |
| +++ b/internal/console/server.go |
| @@ -6608,8 +6608,8 @@ func (s *Server) handleNewCanary(w http.ResponseWriter, r *http.Request) { |
| // rather than failing the create that already succeeded. |
| if hosts, _ := s.channelHosts(ctx, acct.Sqid, app, channel); len(hosts) > 0 { |
| // Shown as the platform shows it: the name host where the account |
| - // has a subdomain (canonical.go). |
| - back("ok", "Created canary "+name+" — live at https://"+s.canon(ctx).host(hosts[0])+" serving "+version+" (test versions have no safety delay).") |
| + // has a subdomain and a box derives it for this route (canonical.go). |
| + back("ok", "Created canary "+name+" — live at https://"+s.channelFlashHost(s.canon(ctx), hosts[0])+" serving "+version+" (test versions have no safety delay).") |
| return |
| } |
| domain, absent := s.instanceDomainFor(ctx, acct.Sqid, app) |
diff --git a/internal/console/view.go b/internal/console/view.go| index fa9b3c654..a2e24a7fc 100644 |
| --- a/internal/console/view.go |
| +++ b/internal/console/view.go |
| @@ -315,7 +315,10 @@ type RouteView struct { |
| // PublicHost is Host as the platform shows it (canonical.go): the name |
| // host where the account has a subdomain. "" when the view was built |
| // without a hostCanon. Display only; Host is the identity. |
| - PublicHost string |
| + PublicHost string |
| + // Replica mirrors registry.Route.Replica (a remote row: the record's |
| + // role): an edge-checkout shard, for which no box derives a name. |
| + Replica bool |
| Hibernate bool |
| Platform bool |
| Restartable bool |
| @@ -677,7 +680,7 @@ func assembleViews(ctx context.Context, regPath, acct string, apps []string, dns |
| Account: rtAcct, |
| Environment: rt.Environment, |
| Caps: capsFor, |
| - Unit: rt.Unit, Backing: rt.Backing, Provisioned: rt.Provisioned, |
| + Unit: rt.Unit, Backing: rt.Backing, Provisioned: rt.Provisioned, Replica: rt.Replica, |
| Restartable: release.Adoptable(rt), |
| } |
| if remote != nil && remote.labels { |
diff --git a/internal/provision/account_subdomains_census_test.go b/internal/provision/account_subdomains_census_test.go| index cf10bb661..814b92dc7 100644 |
| --- a/internal/provision/account_subdomains_census_test.go |
| +++ b/internal/provision/account_subdomains_census_test.go |
| @@ -71,11 +71,47 @@ package provision |
| // on the pinned ETag (or create-only when the pin read no claim), any |
| // other is refused; other keys pass through unchanged. Never a record |
| // key. nonrecord / def:Put,sel:Put, the class of checkedStore.Put. |
| +// |
| +// Task 6 (the console door and canonical URLs, spec §4.3 and §4.8) re-digests |
| +// five console units. No record write is added, moved or removed, and no |
| +// class or kind changes; every change is in what an answer or page shows: |
| +// - Server.handleAPIInstanceList (re-pinned): one hostCanon for the |
| +// request (s.canon(ctx)) and PublicHost on each row |
| +// (recordPublicHost: at most one claim listing, lazily, read only). The |
| +// listing and the instances-literal sites are unchanged. key-site / |
| +// lit:instances, as before. |
| +// - Server.handleAPIInstanceUpdate (re-pinned): answers through |
| +// publicRecordView instead of recordView, after the write and the |
| +// serial bump: one claim listing, a failed one logged and the host |
| +// left as it is. The UpdateRecord path is unchanged. record-writer / |
| +// key:UpdateRecord, as before. |
| +// - Server.handleAPIInstanceChannel (re-pinned): the same answer change, |
| +// in both its no-op and its written answer. record-writer / |
| +// key:UpdateRecord, as before. |
| +// - Server.handleAppInstance (re-pinned, fix round 1): the alias list |
| +// drops the host's own derived name alias when the heading already |
| +// shows it; a filter over rows already read. key-site / |
| +// lit:instances, as before. |
| +// - var routeDecls (re-pinned): four declarations added, the account |
| +// subdomain door (GET, POST, DELETE /api/cli/accounts/{account}/ |
| +// subdomain) and GET /api/cli/system/subdomain-inventory, all kindCLI |
| +// with the empty role set; none names a record path, and the |
| +// instances and sidecars literals are the existing entries'. key-site |
| +// / lit:instances,lit:sidecars, as before. |
| +// |
| +// The create, import and seed doors answer through publicRecordView too; |
| +// the census does not count those functions as units, so they need no pin. |
| func accountSubdomainsWriteCensusInventory() []censusEntry { |
| entries := append([]censusEntry(nil), linkedDeploymentsSlice1WriteCensusInventory()...) |
| repins := []censusEntry{ |
| {"internal/console/apidomains.go", "Server.handleAPIDomainAttach", "key-site", "lit:instances", "3e0501dbc4e79c6f51274c3e02ac34853d20557474e57dbcae8d30e7742e9b9d"}, |
| {"internal/console/domainattach.go", "Server.attachDomainAs", "record-writer", "key:CreateRecord", "cad4da6801d2d1fae6381a9420beda4b881ffdc237c84c05877ac68ba509f609"}, |
| + // Task 6. |
| + {"internal/console/apiinstances.go", "Server.handleAPIInstanceList", "key-site", "lit:instances", "f7cc7f1c2c5a38e1bf3a04f47ce9d3655bce99004aed885a309c0fe80d7672b4"}, |
| + {"internal/console/apiinstances.go", "Server.handleAPIInstanceUpdate", "record-writer", "key:UpdateRecord", "88e986f3e2974be31856296d319d74ffb88733c0840283c3ba410fa557e279ec"}, |
| + {"internal/console/channelmove.go", "Server.handleAPIInstanceChannel", "record-writer", "key:UpdateRecord", "ddbabf888417ae76dfdd381d936248585e937698521cdec43a4207427cf0bffc"}, |
| + {"internal/console/instancepage.go", "Server.handleAppInstance", "key-site", "lit:instances", "9aff13e2ac0a0f7bd6375b3a08e310424afe7b3af75b24fef936119f601f67e8"}, |
| + {"internal/console/routedecls.go", "var routeDecls", "key-site", "lit:instances,lit:sidecars", "cd09e13090c6bb20491a146d35e3dc8a7758c424f8d645c3998771e2ef2a469b"}, |
| } |
| // The one classification change, stated as such rather than slipped |
| // through a re-pin: the kinds narrow, the class stays. |