console: a linked app's own page is the linked overview
Fable's final review, Important 3 (spec 5.4). A linked app's overview was an ordinary app page: deploy, safety-delay, domain and region cards, and a nav whose Releases, Running, Logs and Settings tabs all answer 409. appPage and the app index now mark a linked app (LinkedApp). Its nav offers Overview, Analytics and Protection only, on every page Carloku keeps for it. Its overview says what it is (LD-C31, Served from its home), where it answers (its public URL), whether its home is reachable (the hub's LinkSeen record, in the Fleet card's words LD-C18 to LD-C21), a link to billing for usage when billing is on, and its traffic card. New wording is three named drafts in links_copy.go's pending block.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
6 files changed,
+206
−11
internal/console/accountlinks.go+81 −0internal/console/accountlinks_test.go+61 −0internal/console/links_copy.go+9 −0internal/console/mobilenav.go+15 −0internal/console/server.go+9 −0internal/console/templates/app_overview.html+31 −11
diff --git a/internal/console/accountlinks.go b/internal/console/accountlinks.go| index a232a390a..8f6923f1f 100644 |
| --- a/internal/console/accountlinks.go |
| +++ b/internal/console/accountlinks.go |
| @@ -207,6 +207,87 @@ func (s *Server) linkAppURL(acct *Account, app string) string { |
| return s.linkPublicationURL(acct, app) |
| } |
| +// linkedAppView is a linked app's own page on Carloku (spec §5.4): what it |
| +// is (served from its home deployment), its public address, and whether |
| +// that deployment is reachable now. Its other views (deploys, settings, |
| +// instances, logs) live at home and are not offered. |
| +type linkedAppView struct { |
| + LinkID, Home string |
| + // The overview's lines, filled by handleLinkedAppOverview. |
| + Heading, Managed, AddressLabel, URL string |
| + // SeenKnown: the hub's connection record was read; Reachable and |
| + // StateText are from it, as the Fleet tab's card shows them. |
| + SeenKnown bool |
| + Reachable bool |
| + ReachableText, NotReachableText string |
| + StateText string |
| + // UsageText and UsageHref point at the account's billing page, where a |
| + // linked app's usage is, when billing is on. |
| + UsageText, UsageHref string |
| +} |
| + |
| +// linkedAppPage is the linked-app view of app in acct for its pages' nav, |
| +// or nil for an ordinary app. A failed read is logged and costs only the |
| +// linked view: every refused tab still refuses (linkedAppRefusal). |
| +func (s *Server) linkedAppPage(acct *Account, app string) *linkedAppView { |
| + linkID, err := s.store.appLinkID(acct.ID, app) |
| + if err != nil { |
| + log.Printf("console: linked app page %s/%s: %v", acct.Sqid, app, err) |
| + return nil |
| + } |
| + if linkID == "" { |
| + return nil |
| + } |
| + v := &linkedAppView{LinkID: linkID, Home: linkID} |
| + if l, err := s.store.LinkByID(linkID); err != nil { |
| + log.Printf("console: linked app page %s/%s: link %s: %v", acct.Sqid, app, linkID, err) |
| + } else if l != nil && l.Name != "" { |
| + v.Home = l.Name |
| + } |
| + return v |
| +} |
| + |
| +// handleLinkedAppOverview is a linked app's overview: what it is, its |
| +// public address and its home's reachability, and its traffic, which is |
| +// Carloku's to show. None of an ordinary overview's deploy, instance, |
| +// domain, region or safety-delay cards: those are the home's. |
| +func (s *Server) handleLinkedAppOverview(w http.ResponseWriter, r *http.Request, p page, acct *Account) { |
| + v := p.LinkedApp |
| + v.Heading = linkCopy(copyLD31, "home", v.Home) |
| + v.Managed = linkCopy(copyLinkedOverviewManaged, "app", p.AppName, "home", v.Home) |
| + v.AddressLabel = copyLinkedOverviewAddress |
| + v.URL = s.linkAppURL(acct, p.AppName) |
| + v.ReachableText, v.NotReachableText = copyLD18, copyLD19 |
| + if p.BillingNav { |
| + v.UsageText, v.UsageHref = copyLinkedOverviewUsage, p.Nav+"/billing" |
| + } |
| + if reg, err := s.linkReg(); err != nil { |
| + log.Printf("console: linked app overview %s/%s: open registry: %v", acct.Sqid, p.AppName, err) |
| + } else if seen, err := reg.LinkSeen(); err != nil { |
| + log.Printf("console: linked app overview %s/%s: link seen: %v", acct.Sqid, p.AppName, err) |
| + } else { |
| + v.SeenKnown = true |
| + st, ok := seen[v.LinkID] |
| + v.Reachable = ok && st.Connected |
| + switch { |
| + case v.Reachable: |
| + case !ok || st.At.IsZero(): |
| + v.StateText = copyLD21 |
| + default: |
| + v.StateText = linkCopy(copyLD20, "ago", humanAge(time.Since(st.At))) |
| + } |
| + } |
| + ctx, cancel := context.WithTimeout(r.Context(), overviewTrafficTimeout) |
| + defer cancel() |
| + if win, err := s.readAnalyticsFor(ctx, acct.Sqid, p.AppName, analyticsQuery{Range: range7d}, time.Now(), &s.trafficMemo); err != nil { |
| + log.Printf("console: overview traffic %s/%s: %v", acct.Sqid, p.AppName, err) |
| + } else { |
| + p.Traffic = &win |
| + } |
| + p.TrafficLive = trafficCardLive(p.Traffic, false, p.AppName, p.Nav, time.Now()) |
| + s.render(w, http.StatusOK, "app_overview", p) |
| +} |
| + |
| // accountFleetURL is the account's Fleet tab. |
| func accountFleetURL(sqid string) string { return "/a/" + url.PathEscape(sqid) + "/fleet" } |
diff --git a/internal/console/accountlinks_test.go b/internal/console/accountlinks_test.go| index b6bd272b2..dc3662209 100644 |
| --- a/internal/console/accountlinks_test.go |
| +++ b/internal/console/accountlinks_test.go |
| @@ -468,3 +468,64 @@ func TestPersonUnlinkRefusesAnotherAccountsLink(t *testing.T) { |
| t.Fatalf("bob's forward rows = %v, want one", hosts) |
| } |
| } |
| + |
| +// TestLinkedAppOverview: a linked app's own page on Carloku is the linked |
| +// overview (Fable final review, Important 3; spec §5.4). It says what the |
| +// app is and where it answers, with its home's reachability, and shows no |
| +// deploy, instance, domain, region or safety-delay card; the app nav, on |
| +// every page Carloku keeps for it and on the phone index, offers only |
| +// Overview, Analytics and Protection, never a tab that answers 409. An |
| +// ordinary app's overview is unchanged. |
| +func TestLinkedAppOverview(t *testing.T) { |
| + fx := newLinkFixture(t, "tunnel.example.com") |
| + browser := signInPaul(t, fx) |
| + l := mintLink(t, fx, browser, "shop-home") |
| + if status, out := publish(t, fx, l.token, "shop"); status != http.StatusCreated { |
| + t.Fatalf("publish = %d %v", status, out) |
| + } |
| + if err := linkRegistryOf(t, fx).SetLinkSeen(l.id, 1, true, time.Now()); err != nil { |
| + t.Fatal(err) |
| + } |
| + // The nav's hrefs start with the account's own segment; each is matched |
| + // by its app path and closing quote. |
| + const base = "/apps/shop" |
| + refused := []string{ |
| + base + `/instances"`, base + `/releases"`, base + `/logs"`, |
| + base + `/errors"`, base + `/availability"`, base + `/activity"`, |
| + base + `/settings"`, base + `/settings/domains"`, base + `/settings/index"`, |
| + "Safety delay", "Web addresses", "Resources", esc(regionCopy.PickerLabel), esc(deploymentsCopy.Title), |
| + } |
| + status, _, page := get(t, browser, fx.u("/apps/shop")) |
| + if status != http.StatusOK { |
| + t.Fatalf("linked overview = %d", status) |
| + } |
| + pageHas(t, "the linked overview", page, |
| + esc(linkCopy(copyLD31, "home", "shop-home")), |
| + esc(linkCopy(copyLinkedOverviewManaged, "app", "shop", "home", "shop-home")), |
| + esc(copyLinkedOverviewAddress), `href="https://`+linkHost(fx, "shop")+`"`, esc(copyLD18), |
| + base+`/analytics"`, base+`/protection"`, "Traffic, last 7 days") |
| + pageLacks(t, "the linked overview", page, refused...) |
| + for _, tab := range []string{"/apps/shop/analytics", "/apps/shop/protection", "/apps/shop/index"} { |
| + status, _, page := get(t, browser, fx.u(tab)) |
| + if status != http.StatusOK { |
| + t.Fatalf("%s = %d", tab, status) |
| + } |
| + pageHas(t, tab, page, base+`/analytics"`, base+`/protection"`) |
| + pageLacks(t, tab, page, refused[:9]...) |
| + } |
| + |
| + // Not reachable, seen a while ago: the card's words. |
| + if err := linkRegistryOf(t, fx).SetLinkSeen(l.id, 1, false, time.Now().Add(-3*time.Hour)); err != nil { |
| + t.Fatal(err) |
| + } |
| + _, _, page = get(t, browser, fx.u("/apps/shop")) |
| + pageHas(t, "the linked overview, home not reachable", page, esc(copyLD19), esc(linkCopy(copyLD20, "ago", "3h0m"))) |
| + |
| + // An ordinary app keeps its ordinary overview and nav. |
| + if _, err := fx.st.CreateAppIn(linkOpsAccount(t, fx).ID, "blog", "paul@keymail.dev", time.Now()); err != nil { |
| + t.Fatal(err) |
| + } |
| + _, _, page = get(t, browser, fx.u("/apps/blog")) |
| + pageHas(t, "an ordinary overview", page, `/apps/blog/releases"`, `/apps/blog/settings"`, "Web addresses") |
| + pageLacks(t, "an ordinary overview", page, esc(copyLinkedOverviewAddress)) |
| +} |
diff --git a/internal/console/links_copy.go b/internal/console/links_copy.go| index feeae4ad6..d225034ec 100644 |
| --- a/internal/console/links_copy.go |
| +++ b/internal/console/links_copy.go |
| @@ -183,6 +183,15 @@ const ( |
| // account has no link under; read by the CLI. |
| copyLinkNoSuchLink = "no linked deployment {id} in {account}" |
| + // A linked app's overview on Carloku (Fable final review, Important |
| + // 3): under LD-C31's "Served from {home}", what lives where. |
| + copyLinkedOverviewManaged = "{app} runs on {home}, a deployment linked to this account. Its deploys, settings, instances and logs are managed there. Here you can see its traffic and protection." |
| + // The label before the linked app's public address. |
| + copyLinkedOverviewAddress = "Public address" |
| + // The link to the account's billing page, where the app's usage is, |
| + // when billing is on. |
| + copyLinkedOverviewUsage = "Usage is on the account's billing page." |
| + |
| // The home console (Task 7), read by the home CLI after its "error: " |
| // prefix. |
| // |
diff --git a/internal/console/mobilenav.go b/internal/console/mobilenav.go| index 186ba7c58..a8b0e877b 100644 |
| --- a/internal/console/mobilenav.go |
| +++ b/internal/console/mobilenav.go |
| @@ -63,6 +63,20 @@ func (p page) AppLinks() []navLink { |
| return nil |
| } |
| base := p.appBase() |
| + if p.LinkedApp != nil { |
| + // A linked app's other views live at home (spec §5.4): the nav |
| + // offers only what Carloku keeps for it, so no tab leads to a |
| + // refusal. |
| + links := []navLink{ |
| + {Key: "overview", Label: "Overview", Href: base}, |
| + {Key: "analytics", Label: "Analytics", Href: base + "/analytics"}, |
| + {Key: "protection", Label: "Protection", Href: base + "/protection"}, |
| + } |
| + for i := range links { |
| + links[i].Current = links[i].Key == p.ActiveTab |
| + } |
| + return links |
| + } |
| links := []navLink{ |
| {Key: "overview", Label: "Overview", Href: base}, |
| {Key: "instances", Label: "Running", Href: base + "/instances"}, |
| @@ -221,6 +235,7 @@ func (s *Server) handleAppIndex(w http.ResponseWriter, r *http.Request) { |
| p := s.accountPage(w, r, addr, raw, acct, role) |
| p.Title = app |
| p.AppName = app |
| + p.LinkedApp = s.linkedAppPage(acct, app) |
| p.ActiveNav = "apps" |
| p.IndexOf = indexApp |
| s.render(w, http.StatusOK, "nav_index", p) |
diff --git a/internal/console/server.go b/internal/console/server.go| index f17e608ce..b9e85a56e 100644 |
| --- a/internal/console/server.go |
| +++ b/internal/console/server.go |
| @@ -2670,6 +2670,10 @@ type page struct { |
| // LinkedDeploymentsKnown says the links read SUCCEEDED, the same rule |
| // as FleetsKnown; LinkSection is its fixed text. (Not "AccountLinks": |
| // that is the account nav, mobilenav.go.) |
| + // LinkedApp is set on a linked app's own pages (appPage): its nav |
| + // offers only the views Carloku keeps for it, and its overview is the |
| + // linked one (spec §5.4). |
| + LinkedApp *linkedAppView |
| LinkedDeployments []accountLinkCard |
| LinkedDeploymentsKnown bool |
| LinkSection linkSectionCopy |
| @@ -4280,6 +4284,7 @@ func (s *Server) appPage(w http.ResponseWriter, r *http.Request, tab string) (pa |
| p := s.accountPage(w, r, addr, raw, acct, role) |
| p.Title = app |
| p.AppName = app |
| + p.LinkedApp = s.linkedAppPage(acct, app) |
| if role == RoleOwner || role == RoleMember { |
| p.HasClaimedSource, _ = s.store.hasClaimedSource(acct.ID, app) |
| } |
| @@ -4443,6 +4448,10 @@ func (s *Server) handleApp(w http.ResponseWriter, r *http.Request) { |
| return |
| } |
| app := p.Detail.App |
| + if p.LinkedApp != nil { |
| + s.handleLinkedAppOverview(w, r, p, acct) |
| + return |
| + } |
| // The traffic card reads beside everything else this page reads. The |
| // page waits for it only until overviewTrafficBudget after the request |
| // started (trafficWait), then renders the card as still loading: a slow |
diff --git a/internal/console/templates/app_overview.html b/internal/console/templates/app_overview.html| index df7a9df6f..17cc482ac 100644 |
| --- a/internal/console/templates/app_overview.html |
| +++ b/internal/console/templates/app_overview.html |
| @@ -2,6 +2,21 @@ |
| {{if .Flash}}<p class="banner">{{.Flash}}</p>{{end}} |
| {{if .FlashErr}}<p class="banner error">{{.FlashErr}}</p>{{end}} |
| {{template "appnav" .}} |
| +{{/* A linked app (spec §5.4): served from its home deployment, so none of |
| + the deploy, instance, domain, region or safety-delay cards below. What |
| + it is, where it answers, whether its home is reachable, its traffic. */}} |
| +{{if .LinkedApp}}{{with .LinkedApp}} |
| +<section class="card" aria-label="{{.Heading}}"> |
| + <h2>{{.Heading}}</h2> |
| + <p>{{.Managed}}</p> |
| + {{if .URL}}<p>{{.AddressLabel}}: <a href="{{.URL}}">{{.URL}}</a></p>{{end}} |
| + {{if .SeenKnown}}<p>{{if .Reachable}}<span class="chip chip-health-ok">{{.ReachableText}}</span>{{else}}<span class="chip chip-stale">{{.NotReachableText}}</span>{{end}} |
| + {{if .StateText}}<span class="small">{{.StateText}}</span>{{end}}</p>{{end}} |
| + {{if .UsageHref}}<p class="small"><a href="{{.UsageHref}}">{{.UsageText}}</a></p>{{end}} |
| +</section> |
| +{{end}} |
| +{{template "overviewtraffic" .}} |
| +{{else}} |
| {{if .HasClaimedSource}}<section class="card"><p><a class="btn btn-secondary" href="/a/{{.Account.Sqid}}/apps/{{.AppName}}/source">Download source</a></p><p>Download the source saved when you kept this app. Later deployments do not update it.</p></section>{{end}} |
| {{template "accountreviewbanner" .}} |
| @@ -65,17 +80,7 @@ |
| </a> |
| </section> |
| {{end}} |
| -{{/* Traffic: the Analytics tab's 7-day window, read beside the rest of this |
| - page under its own deadline (handleApp). Off shows where to turn it on; |
| - a failed read says so rather than showing zeros. */}} |
| -<section class="an-overview" aria-labelledby="an-overview-head"> |
| - <div class="an-overview-head"> |
| - <h2 id="an-overview-head">Traffic, last 7 days</h2> |
| - <a href="{{.Nav}}/apps/{{.AppName}}/analytics?range=7d">View analytics</a> |
| - </div> |
| - {{with .TrafficLive}}<div class="an-live" data-live="{{.Src}}">{{template "trafficcard" .}}</div> |
| - {{template "analyticsscript"}}{{end}} |
| -</section> |
| +{{template "overviewtraffic" .}} |
| {{/* The legacy safety-delay flag: legacy-path-only, exactly as ladder.html |
| skips this same block in pipeline mode. A pipelined app's bake story is |
| its own per-channel windows (spec §3) — this global on/off line would |
| @@ -105,4 +110,19 @@ |
| <p class="small"><a href="{{.Nav}}/apps/{{.AppName}}/activity">All activity</a></p> |
| {{end}} |
| {{if not .CanPromote}}<p class="small">Deploys are unavailable on this console — it has no signing key.</p>{{end}} |
| +{{end}} |
| {{template "bottom" .}}{{end}} |
| + |
| +{{define "overviewtraffic"}} |
| +{{/* Traffic: the Analytics tab's 7-day window, read beside the rest of this |
| + page under its own deadline (handleApp). Off shows where to turn it on; |
| + a failed read says so rather than showing zeros. */}} |
| +<section class="an-overview" aria-labelledby="an-overview-head"> |
| + <div class="an-overview-head"> |
| + <h2 id="an-overview-head">Traffic, last 7 days</h2> |
| + <a href="{{.Nav}}/apps/{{.AppName}}/analytics?range=7d">View analytics</a> |
| + </div> |
| + {{with .TrafficLive}}<div class="an-live" data-live="{{.Src}}">{{template "trafficcard" .}}</div> |
| + {{template "analyticsscript"}}{{end}} |
| +</section> |
| +{{end}} |