link: final review minors: dead code, tunnel names, names, words
From both final reviews' small items: - edge: drop the linkAccounts snapshot, written by Reload and never read; consoleRegistry drops SetLinkSeen and ResetLinkSeen, which only the hub calls (tests use the concrete registry). - edge: DispatchArm refuses a row whose Tunnel fails ValidTunnelName (ArmNone), so no route reaches a link's channel or a malformed name through the tunnel arm. TestLinkDispatchArm covers it. - home console: unpublish lower-cases the name as publish does, so carlos link unpublish Shop takes shop down instead of LD-C48. - serving: the publish door answers name refusals in its own draft words; app create's said "create the app", pointed at carlos deploy --temporary, and carried em dashes. "that name is reserved" is reused. - gofmt of link_cli.go's links ls constants.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
11 files changed,
+107
−26
internal/console/apilinks.go+11 −9internal/console/apilinks_test.go+28 −2internal/console/homelink.go+3 −1internal/console/homelink_test.go+28 −0internal/console/links_auth_test.go+4 −2internal/console/links_copy.go+9 −0internal/console/view.go+0 −2internal/edge/edge.go+0 −5internal/edge/fleetforward.go+8 −1internal/edge/linkforward_test.go+12 −0link_cli.go+4 −4
diff --git a/internal/console/apilinks.go b/internal/console/apilinks.go| index e19225231..c5d4c8a8e 100644 |
| --- a/internal/console/apilinks.go |
| +++ b/internal/console/apilinks.go |
| @@ -168,8 +168,10 @@ const ( |
| // handleLinkPublish is POST /api/link/publications {"app": name}: create |
| // the linked app name in the link's account and serve it from the link. |
| // |
| -// The name rules are app create's (validateClaimAppName), under the plan |
| -// lock with the running-things cap (checkCreateApp), on the link's own |
| +// The name rules are app create's (validateClaimAppName), answered in the |
| +// publish door's own words (copyLinkPublish*: the home CLI prints them |
| +// under carlos link publish, where app create's would misdirect), under |
| +// the plan lock with the running-things cap (checkCreateApp), on the link's own |
| // create budget (allowAppCreate keys a link on its ID). A name the account |
| // holds by anything other than this link's own linked app is LD-C10. |
| // |
| @@ -202,7 +204,7 @@ func (s *Server) handleLinkPublish(w http.ResponseWriter, r *http.Request) { |
| } |
| name := normalizeAppName(req.App) |
| if !release.ValidApp(name) { |
| - jsonError(w, http.StatusBadRequest, appCreateInvalidNameMsg) |
| + jsonError(w, http.StatusBadRequest, copyLinkPublishInvalidName) |
| return |
| } |
| if s.apexHost(acct.Sqid, name) == "" { |
| @@ -252,29 +254,29 @@ func (s *Server) handleLinkPublish(w http.ResponseWriter, r *http.Request) { |
| return |
| } |
| log.Printf("console: link %s: publish %s: plan cap: %v", l.ID, name, err) |
| - jsonError(w, http.StatusInternalServerError, appCreateFailedMsg) |
| + jsonError(w, http.StatusInternalServerError, copyLinkPublishFailed) |
| return |
| } |
| outcome, _, _ := s.validateClaimAppName(r.Context(), acct, name, "", false, time.Time{}) |
| switch outcome { |
| case claimOK: |
| case claimInvalid: |
| - jsonError(w, http.StatusBadRequest, appCreateInvalidNameMsg) |
| + jsonError(w, http.StatusBadRequest, copyLinkPublishInvalidName) |
| return |
| case claimReserved: |
| jsonError(w, http.StatusConflict, appCreateReservedMsg) |
| return |
| case claimTemporaryReserved: |
| - jsonError(w, http.StatusConflict, appCreateTemporaryReservedMsg) |
| + jsonError(w, http.StatusConflict, copyLinkPublishTemporaryReserved) |
| return |
| case claimTaken, claimApexHeld: |
| taken() |
| return |
| case claimStoreFailed: |
| - jsonError(w, http.StatusBadGateway, appCreateStoreFailedMsg) |
| + jsonError(w, http.StatusBadGateway, copyLinkPublishStoreFailed) |
| return |
| default: |
| - jsonError(w, http.StatusInternalServerError, appCreateFailedMsg) |
| + jsonError(w, http.StatusInternalServerError, copyLinkPublishFailed) |
| return |
| } |
| created, err := s.createClaimAppRow(r.Context(), acct, name, func(st *Store) (bool, error) { |
| @@ -287,7 +289,7 @@ func (s *Server) handleLinkPublish(w http.ResponseWriter, r *http.Request) { |
| jsonError(w, http.StatusServiceUnavailable, refused.ref.Msg) |
| default: |
| log.Printf("console: link %s: publish %s: create row: %v", l.ID, name, err) |
| - jsonError(w, http.StatusInternalServerError, appCreateFailedMsg) |
| + jsonError(w, http.StatusInternalServerError, copyLinkPublishFailed) |
| } |
| return |
| } |
diff --git a/internal/console/apilinks_test.go b/internal/console/apilinks_test.go| index 740556c89..f55ee3810 100644 |
| --- a/internal/console/apilinks_test.go |
| +++ b/internal/console/apilinks_test.go |
| @@ -140,6 +140,32 @@ func TestPublishCreatesLinkedAppAndRow(t *testing.T) { |
| } |
| } |
| +// TestPublishRefusalWords: the publish door's name refusals are its own |
| +// words, read under carlos link publish, not app create's (which say |
| +// "create the app" or point at carlos deploy --temporary, with em dashes). |
| +func TestPublishRefusalWords(t *testing.T) { |
| + fx := newLinkFixture(t, "tunnel.example.com") |
| + l := mintLink(t, fx, signInPaul(t, fx), "shop-home") |
| + for _, tc := range []struct { |
| + app string |
| + status int |
| + want string |
| + }{ |
| + {"Not A Name!", http.StatusBadRequest, copyLinkPublishInvalidName}, |
| + {"tmp-shop", http.StatusConflict, copyLinkPublishTemporaryReserved}, |
| + } { |
| + status, body := linkDoor(t, fx, http.MethodPost, "/api/link/publications", l.token, `{"app":"`+tc.app+`"}`) |
| + if got := linkJSONErr(body); status != tc.status || got != tc.want { |
| + t.Errorf("publish %q = %d %q; want %d %q", tc.app, status, got, tc.status, tc.want) |
| + } |
| + } |
| + for _, msg := range []string{copyLinkPublishInvalidName, copyLinkPublishTemporaryReserved, copyLinkPublishFailed, copyLinkPublishStoreFailed} { |
| + if strings.Contains(msg, "\u2014") || strings.Contains(msg, "create the app") { |
| + t.Errorf("publish refusal %q has an em dash or app create's wording", msg) |
| + } |
| + } |
| +} |
| + |
| func TestPublishRefusesTakenName(t *testing.T) { |
| fx := newLinkFixture(t, "tunnel.example.com") |
| l := mintLink(t, fx, signInPaul(t, fx), "shop-home") |
| @@ -719,7 +745,7 @@ func worldSnapshot(t *testing.T, fx *consoleFixture) map[string]string { |
| } |
| out["object "+k] = string(body) |
| } |
| - fp, err := linkRegistryOf(t, fx).(*registry.Registry).Fingerprint() |
| + fp, err := linkRegistryOf(t, fx).Fingerprint() |
| if err != nil { |
| t.Fatal(err) |
| } |
| @@ -1885,7 +1911,7 @@ func TestLinkedAppEdgeSettingsLand(t *testing.T) { |
| } |
| // The hub's pass keys those reads on the routes it lists: the forward |
| // row names the account and the app. |
| - routes, err := linkRegistryOf(t, fx).(*registry.Registry).List() |
| + routes, err := linkRegistryOf(t, fx).List() |
| if err != nil { |
| t.Fatal(err) |
| } |
diff --git a/internal/console/homelink.go b/internal/console/homelink.go| index 3b12d289b..39badb6f9 100644 |
| --- a/internal/console/homelink.go |
| +++ b/internal/console/homelink.go |
| @@ -662,7 +662,9 @@ func (s *Server) handleAPIHomeLinkUnpublish(w http.ResponseWriter, r *http.Reque |
| if _, _, ok := s.apiSystemRoller(w, r); !ok { |
| return |
| } |
| - name := strings.TrimSpace(r.PathValue("name")) |
| + // As the serving console's publish does: a name is published lower |
| + // case, so "Blog" unpublishes blog. |
| + name := normalizeAppName(r.PathValue("name")) |
| reg, ok := s.homeLinkRegistry(w) |
| if !ok { |
| return |
diff --git a/internal/console/homelink_test.go b/internal/console/homelink_test.go| index 9254d0002..fbc2cfb4d 100644 |
| --- a/internal/console/homelink_test.go |
| +++ b/internal/console/homelink_test.go |
| @@ -524,6 +524,34 @@ func TestHomeUnpublishDropsHomeSetFirst(t *testing.T) { |
| } |
| } |
| +// TestHomeUnpublishNormalisesTheName: unpublish takes a name as publish |
| +// does, lower case (the serving console lower-cases what it publishes), so |
| +// "carlos link unpublish Shop" takes shop down rather than answering |
| +// LD-C48 (Fable final review). |
| +func TestHomeUnpublishNormalisesTheName(t *testing.T) { |
| + home := newHomeFixture(t) |
| + op := cliToken(t, home, "paul@keymail.dev", "code-home-unpublish-case") |
| + f := newFakeServing(t) |
| + linkHomeTo(t, home, f) |
| + homeApp(t, home, "shop", registry.Route{Host: "shop.home.example.com", Kind: "instance", Status: "ready", Socket: "/run/carlos/shop.sock"}) |
| + if status, body := homeReq(t, home, http.MethodPost, "/api/cli/link/publications", op, `{"app":"shop"}`); status != http.StatusCreated { |
| + t.Fatalf("publish = %d %s", status, body) |
| + } |
| + status, body := homeReq(t, home, http.MethodDelete, "/api/cli/link/publications/%20Shop%20", op, "") |
| + var out map[string]string |
| + if err := json.Unmarshal([]byte(body), &out); status != http.StatusOK || err != nil || out["app"] != "shop" { |
| + t.Fatalf("unpublish Shop = %d %s; want 200 for shop", status, body) |
| + } |
| + if apps, err := homeRegistry(t, home).HomeLinkApps(); err != nil || len(apps) != 0 { |
| + t.Fatalf("the home set after unpublish = %v, %v", apps, err) |
| + } |
| + f.mu.Lock() |
| + defer f.mu.Unlock() |
| + if f.pubs["shop"] { |
| + t.Fatal("the serving console still holds shop") |
| + } |
| +} |
| + |
| func TestHomeLinkRemovePending(t *testing.T) { |
| home := newHomeFixture(t) |
| op := cliToken(t, home, "paul@keymail.dev", "code-home-pending") |
diff --git a/internal/console/links_auth_test.go b/internal/console/links_auth_test.go| index 8b090cd12..f3d1bc4c1 100644 |
| --- a/internal/console/links_auth_test.go |
| +++ b/internal/console/links_auth_test.go |
| @@ -67,13 +67,15 @@ func linkCeremony(t *testing.T, fx *consoleFixture, browser *http.Client, name, |
| return poll |
| } |
| -func linkRegistryOf(t *testing.T, fx *consoleFixture) consoleRegistry { |
| +// linkRegistryOf is fx's registry handle, as the console holds it, with the |
| +// methods only the hub writes (SetLinkSeen) that tests stand in for. |
| +func linkRegistryOf(t *testing.T, fx *consoleFixture) *registry.Registry { |
| t.Helper() |
| reg, err := openRegistry(fx.regPath) |
| if err != nil { |
| t.Fatal(err) |
| } |
| - return reg |
| + return reg.(*registry.Registry) |
| } |
| func TestLinkApprovalMintsLinkToken(t *testing.T) { |
diff --git a/internal/console/links_copy.go b/internal/console/links_copy.go| index d225034ec..34dd0470f 100644 |
| --- a/internal/console/links_copy.go |
| +++ b/internal/console/links_copy.go |
| @@ -150,6 +150,15 @@ const ( |
| // The 429 from POST /api/link/publications when the link has spent its |
| // daily create budget; read by the home CLI. |
| copyLinkPublishRateLimited = "this link has published as many apps as it may today. Try again tomorrow" |
| + // POST /api/link/publications' refusals where app create's words would |
| + // misdirect under carlos link publish (they say "create the app", or |
| + // point at carlos deploy --temporary, with em dashes); read by the home |
| + // CLI after its "error: " prefix. "that name is reserved" is app |
| + // create's, reused unchanged. |
| + copyLinkPublishInvalidName = "invalid app name. use lowercase letters, digits and dashes, starting with a letter" |
| + copyLinkPublishTemporaryReserved = "names starting with tmp- are kept for temporary sites. publish under another name with --name" |
| + copyLinkPublishFailed = "could not publish the app. try again" |
| + copyLinkPublishStoreFailed = "could not check the release store. try again" |
| // The 503 from POST /api/link/publications on a console with no apps |
| // domain (CARLOS_APPS_DOMAIN), so no public address to give; read by |
| // the home CLI. |
diff --git a/internal/console/view.go b/internal/console/view.go| index 3161b2074..607a39ced 100644 |
| --- a/internal/console/view.go |
| +++ b/internal/console/view.go |
| @@ -551,8 +551,6 @@ type consoleRegistry interface { |
| RevokeLinkChannel(linkID string) (bool, error) |
| LinkChannelAuth() (map[string]string, error) |
| LinkOwners() (map[string]string, error) |
| - SetLinkSeen(linkID string, seq uint64, connected bool, at time.Time) error |
| - ResetLinkSeen() error |
| LinkSeen() (map[string]registry.LinkSeen, error) |
| LinkForwards(linkID string) ([]registry.Route, error) |
| DeleteLinkForward(host, linkID string) (bool, error) |
diff --git a/internal/edge/edge.go b/internal/edge/edge.go| index ae5a5c821..746f4b958 100644 |
| --- a/internal/edge/edge.go |
| +++ b/internal/edge/edge.go |
| @@ -281,10 +281,6 @@ type Edge struct { |
| // owners only: a link's ID is never a fleet here, so no link credential |
| // can resolve to a tenancy at the door. |
| fleetAccounts atomic.Pointer[map[string]string] |
| - // linkAccounts is the same pass's link→account-sqid snapshot (active |
| - // links, registry LinkOwners), kept apart from fleetAccounts: the |
| - // owners the verdict judged link-placed forward rows by. |
| - linkAccounts atomic.Pointer[map[string]string] |
| // cache, when non-nil, answers cacheable GET/HEAD requests without ever |
| // invoking the hibernation activator or the backend — the mitigation |
| // this whole feature exists for. nil disables caching entirely. |
| @@ -1512,7 +1508,6 @@ func (e *Edge) Reload() error { |
| if e.tunnels != nil { |
| e.tunnels.SetDynamicAuth(channelAuth) |
| e.fleetAccounts.Store(&owners.Fleets) |
| - e.linkAccounts.Store(&owners.Links) |
| } |
| // Probers BEFORE the map swap — the opposite order to RetireExcept below, |
| // and deliberately so. multiProxy answers 503 + Retry-After when the |
diff --git a/internal/edge/fleetforward.go b/internal/edge/fleetforward.go| index 8496b74cf..5ee4dc22c 100644 |
| --- a/internal/edge/fleetforward.go |
| +++ b/internal/edge/fleetforward.go |
| @@ -203,7 +203,8 @@ type ForwardOwners struct{ Fleets, Links map[string]string } |
| // row through ArmLink, and only when fleetArm (FleetVerdict.Arm holds it); |
| // a validated set through ArmReplica when tunnels are on; otherwise a |
| // forward row only through the fleet arm, and only when fleetArm; then the |
| -// row's own Tunnel where tunnels are on; then the fleet arm; then socket, |
| +// row's own Tunnel where tunnels are on (none at all when that name fails |
| +// registry.ValidTunnelName); then the fleet arm; then socket, |
| // TCP upstreams, static and status. Reload switches on it, and |
| // FleetArmVerdict asks it which rows have an entry before the platform-alias |
| // fold. |
| @@ -226,6 +227,12 @@ func DispatchArm(rt registry.Route, fleetArm, tunnels bool) Arm { |
| } |
| return ArmNone |
| case rt.Tunnel != "" && tunnels: |
| + // Only a name a fleet box can register under: never a link's |
| + // channel ("link:<id>/home", outside ValidTunnelName's alphabet), |
| + // which only ArmLink may reach, and never a malformed one. |
| + if !registry.ValidTunnelName(rt.Tunnel) { |
| + return ArmNone |
| + } |
| return ArmTunnel |
| case fleetArm: |
| return ArmFleet |
diff --git a/internal/edge/linkforward_test.go b/internal/edge/linkforward_test.go| index 988f5641f..9087e3590 100644 |
| --- a/internal/edge/linkforward_test.go |
| +++ b/internal/edge/linkforward_test.go |
| @@ -87,6 +87,18 @@ func TestLinkDispatchArm(t *testing.T) { |
| if got := DispatchArm(fleet, true, true); got != ArmForward { |
| t.Errorf("DispatchArm(admitted fleet forward row) = %v, want ArmForward", got) |
| } |
| + // A row's own Tunnel reaches the tunnel arm only under a name a fleet |
| + // box can register: never a link's channel, never a malformed name |
| + // (Fable final review), and the row falls to no other arm either. |
| + for _, tunnel := range []string{registry.LinkChannelName(linkTestID), "Box_1", "a/b", strings.Repeat("a", 33)} { |
| + row := registry.Route{Host: "t.example.com", Kind: "instance", Status: "ready", Tunnel: tunnel, Socket: "/run/x.sock"} |
| + if got := DispatchArm(row, false, true); got != ArmNone { |
| + t.Errorf("DispatchArm(Tunnel %q) = %v, want ArmNone", tunnel, got) |
| + } |
| + } |
| + if got := DispatchArm(registry.Route{Host: "t.example.com", Kind: "instance", Status: "ready", Tunnel: "box-1"}, false, true); got != ArmTunnel { |
| + t.Errorf("DispatchArm(Tunnel box-1) = %v, want ArmTunnel", got) |
| + } |
| } |
| func TestLinkFleetArmVerdict(t *testing.T) { |
diff --git a/link_cli.go b/link_cli.go| index 67efe08ed..99c493d93 100644 |
| --- a/link_cli.go |
| +++ b/link_cli.go |
| @@ -101,9 +101,9 @@ const ( |
| copyLinkPublishedNoURL = "published {app}" |
| copyLinkUnpublishedNoURL = "unpublished {app}" |
| // links ls cells. |
| - copyLinksYes = "yes" |
| - copyLinksNo = "no" |
| - copyLinksUnknown = "unknown" |
| + copyLinksYes = "yes" |
| + copyLinksNo = "no" |
| + copyLinksUnknown = "unknown" |
| // links ls's REACHABLE cell for a removing link, by the revocation the |
| // console reports (as the Fleet tab's card lines tell them apart): the |
| // hub has cut it (offline), has not yet (its apps may still answer), or |
| @@ -111,7 +111,7 @@ const ( |
| copyLinksRemoving = "removing, offline" |
| copyLinksRemovingPending = "removing, may still answer" |
| copyLinksRemovingUnknown = "removing, not checked" |
| - copyLinksAgo = "{ago} ago" |
| + copyLinksAgo = "{ago} ago" |
| // An answer this CLI could not decode. |
| copyLinkUnreadable = "the console's answer could not be read" |
| ) |