console: Getting started secrets step links to Environments settings
Discussion #719. The secrets step links to the first live app's Settings > Environments page, the app the domain step already picks (gsPickApp). New label approved by the delegated Luna pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Squashed from gs-secrets-link-719 into main.
5 files changed,
+84
−13
internal/console/gettingstarted.go+14 −6internal/console/gettingstarted_page_test.go+60 −0internal/console/gettingstarted_test.go+4 −3internal/console/gettingstartedcopy.go+5 −4internal/console/templates/getting_started.html+1 −0
CI cancelled — superseded by a newer push — run details
diff --git a/internal/console/gettingstarted.go b/internal/console/gettingstarted.go| index 786508090..4ea3aa3fb 100644 |
| --- a/internal/console/gettingstarted.go |
| +++ b/internal/console/gettingstarted.go |
| @@ -81,7 +81,10 @@ type gettingStartedView struct { |
| CanCreate bool |
| IsOwner bool |
| DomainApp string |
| - Copy gettingStartedCopy |
| + // SecretsURL is the Environments settings of the app the domain step |
| + // names, set only when that app is live; "" shows no link. |
| + SecretsURL string |
| + Copy gettingStartedCopy |
| } |
| // buildGettingStarted returns the card, or nil when the person hid it or it |
| @@ -155,7 +158,8 @@ func (s *Server) fillGettingStarted(p *page, acct *Account, addr, role string, l |
| // The Show link outside the card reads the same filled-in copy. |
| p.GettingStartedCopy = gettingStartedCopyFor(approvedGettingStartedCopy, s.consoleName()) |
| anyLive := len(live) > 0 |
| - view, complete := buildGettingStarted(marks, connected, anyLive, role, gsDomainApp(p.Apps, live), s.consoleName()) |
| + app, appLive := gsPickApp(p.Apps, live) |
| + view, complete := buildGettingStarted(marks, connected, anyLive, role, app, s.consoleName()) |
| if complete { |
| if s.gsBeforeCompleteHook != nil { |
| s.gsBeforeCompleteHook() |
| @@ -169,26 +173,30 @@ func (s *Server) fillGettingStarted(p *page, acct *Account, addr, role string, l |
| p.ShowGettingStarted = true |
| return |
| } |
| + if view != nil && appLive { |
| + view.SecretsURL = appSettingsURL(acct.Sqid, app, "environments") |
| + } |
| p.GettingStarted = view |
| p.ShowGettingStarted = view == nil |
| } |
| -// gsDomainApp is the app the domain link names: the first live app in the |
| +// gsPickApp is the app the domain link names: the first live app in the |
| // page's order (starred, regular, temporary), else the first app, else "". |
| -func gsDomainApp(apps []appRow, live map[string]bool) string { |
| +// isLive says the app picked is live; the secrets link needs that. |
| +func gsPickApp(apps []appRow, live map[string]bool) (app string, isLive bool) { |
| starred, regular, temporary := partitionApps(apps) |
| first := "" |
| for _, rows := range [][]appRow{starred, regular, temporary} { |
| for _, r := range rows { |
| if live[r.App] { |
| - return r.App |
| + return r.App, true |
| } |
| if first == "" { |
| first = r.App |
| } |
| } |
| } |
| - return first |
| + return first, false |
| } |
| // gettingStartedCopyFor is c with {console} replaced by consoleName in |
diff --git a/internal/console/gettingstarted_page_test.go b/internal/console/gettingstarted_page_test.go| index e01d18032..ee7ffc4a8 100644 |
| --- a/internal/console/gettingstarted_page_test.go |
| +++ b/internal/console/gettingstarted_page_test.go |
| @@ -326,6 +326,66 @@ func TestGettingStartedDomainLinkFirstLiveApp(t *testing.T) { |
| } |
| } |
| +// The secrets step links to the Environments settings of the same app the |
| +// domain step names: the first live app, not kass, which comes first but |
| +// has failed. |
| +func TestGettingStartedSecretsLinkFirstLiveApp(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + reg, err := registry.Open(fx.regPath) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := reg.Upsert(registry.Route{Host: "kass.carlosapp.dev", Kind: "instance", Status: "failed", |
| + Version: "v1", App: "kass", Channel: "stable", Addr: "127.0.0.1:9001"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + reg.Close() |
| + gsStaticSite(t, fx, "site") |
| + cliToken(t, fx, "paul@keymail.dev", "code-gs-live-sec-cli") |
| + paul, _ := signInAs(t, fx, "paul@keymail.dev", "code-gs-live-sec") |
| + body := gsHome(t, fx, paul, "") |
| + if got := gsRenderedState(body, "secrets"); got != "open" { |
| + t.Fatalf("secrets = %q, want open", got) |
| + } |
| + card := gsCard(t, body) |
| + want := appSettingsURL(fx.sqid, "site", "environments") |
| + if !strings.Contains(card, `href="`+want+`"`) || strings.Contains(card, "/apps/kass/settings/environments") { |
| + t.Fatalf("secrets link does not name the first live app %s:\n%s", want, card) |
| + } |
| + if !strings.Contains(card, approvedGettingStartedCopy.SecretsLink) { |
| + t.Errorf("no secrets link text:\n%s", card) |
| + } |
| +} |
| + |
| +// With no live app on the page's list the secrets step has no settings |
| +// link, while the domain step still names the first app. On the page the |
| +// step is muted until an app is live, so this drives the fill directly; the |
| +// second case is a live app the list does not show (the deploy step is |
| +// done, the secrets step open) and still no link. |
| +func TestGettingStartedSecretsNoLinkWithoutLiveApp(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + acct := fixtureAccount(fx) |
| + apps := []appRow{{App: "idle"}} |
| + for _, live := range []map[string]bool{{}, {"elsewhere": true}} { |
| + var p page |
| + p.Apps = apps |
| + fx.srv.fillGettingStarted(&p, acct, "paul@keymail.dev", RoleOwner, live) |
| + v := p.GettingStarted |
| + if v == nil { |
| + t.Fatalf("live %v: no card", live) |
| + } |
| + if v.SecretsURL != "" || v.DomainApp != "idle" { |
| + t.Errorf("live %v: secrets URL %q, domain app %q", live, v.SecretsURL, v.DomainApp) |
| + } |
| + } |
| + var p page |
| + p.Apps = apps |
| + fx.srv.fillGettingStarted(&p, acct, "paul@keymail.dev", RoleOwner, map[string]bool{"idle": true}) |
| + if want := appSettingsURL(fx.sqid, "idle", "environments"); p.GettingStarted == nil || p.GettingStarted.SecretsURL != want { |
| + t.Errorf("live idle: view %+v, want secrets URL %q", p.GettingStarted, want) |
| + } |
| +} |
| + |
| // The card reads only the console database: rendering it costs no S3 |
| // request beyond what the page already makes. |
| func TestGettingStartedNoS3(t *testing.T) { |
diff --git a/internal/console/gettingstarted_test.go b/internal/console/gettingstarted_test.go| index cf5b220d9..7eafcea46 100644 |
| --- a/internal/console/gettingstarted_test.go |
| +++ b/internal/console/gettingstarted_test.go |
| @@ -184,11 +184,12 @@ func TestGettingStartedDomainAppOrder(t *testing.T) { |
| {map[string]bool{"t": true}, "t"}, |
| {map[string]bool{"a": true, "b": true}, "a"}, |
| } { |
| - if got := gsDomainApp(apps, c.live); got != c.want { |
| - t.Errorf("live %v: got %q want %q", c.live, got, c.want) |
| + got, isLive := gsPickApp(apps, c.live) |
| + if got != c.want || isLive != (c.live[c.want]) { |
| + t.Errorf("live %v: got %q (live %v) want %q", c.live, got, isLive, c.want) |
| } |
| } |
| - if got := gsDomainApp(nil, nil); got != "" { |
| + if got, isLive := gsPickApp(nil, nil); got != "" || isLive { |
| t.Errorf("no apps: %q", got) |
| } |
| } |
diff --git a/internal/console/gettingstartedcopy.go b/internal/console/gettingstartedcopy.go| index 3d8e88343..9de31f1b8 100644 |
| --- a/internal/console/gettingstartedcopy.go |
| +++ b/internal/console/gettingstartedcopy.go |
| @@ -6,10 +6,10 @@ package console |
| type gettingStartedCopy struct { |
| Title, Hide, Show, Done, Skipped, MarkDone, Skip, Copy, Copied string |
| - ConnectTitle, ConnectBody, ConnectPrompt, ConnectCLI string |
| - DeployTitle, DeployBody, DeployPrompt, DeployCreate string |
| - SecretsTitle, SecretsBody, SecretsPrompt string |
| - DomainTitle, DomainBody, DomainCLI, DomainLink string |
| + ConnectTitle, ConnectBody, ConnectPrompt, ConnectCLI string |
| + DeployTitle, DeployBody, DeployPrompt, DeployCreate string |
| + SecretsTitle, SecretsBody, SecretsPrompt, SecretsLink string |
| + DomainTitle, DomainBody, DomainCLI, DomainLink string |
| SaveFailed string |
| } |
| @@ -38,6 +38,7 @@ var approvedGettingStartedCopy = gettingStartedCopy{ |
| SecretsTitle: "Add your app's secrets", |
| SecretsBody: "If your app needs API keys or passwords, give them to your agent, or set them yourself with carlos secrets set.", |
| SecretsPrompt: "Set the secrets my app needs on {console}", |
| + SecretsLink: "Set secrets in settings", |
| DomainTitle: "Use your own domain", |
| DomainBody: "Point a domain you own at your app. Your agent can attach it with the carlos CLI.", |
diff --git a/internal/console/templates/getting_started.html b/internal/console/templates/getting_started.html| index 4b3088306..0762b8c6b 100644 |
| --- a/internal/console/templates/getting_started.html |
| +++ b/internal/console/templates/getting_started.html |
| @@ -13,6 +13,7 @@ |
| {{if .CLI}}<div class="gs-paste"><code id="gs-cli-{{.Key}}">{{.CLI}}</code><button class="btn-sm btn-secondary" type="button" data-copy-target="gs-cli-{{.Key}}" data-copy="{{$c.Copy}}" data-copied="{{$c.Copied}}" aria-live="polite" hidden>{{$c.Copy}}</button></div>{{end}} |
| {{if or (and (eq .Key "deploy") $.GettingStarted.CanCreate) (eq .Key "secrets") (eq .Key "domain")}}<div class="gs-actions"> |
| {{if and (eq .Key "deploy") $.GettingStarted.CanCreate}}<a class="btn btn-sm btn-secondary" href="{{$.Nav}}/apps/new">{{$c.DeployCreate}}</a>{{end}} |
| +{{if and (eq .Key "secrets") $.GettingStarted.SecretsURL}}<a class="btn btn-sm btn-secondary" href="{{$.GettingStarted.SecretsURL}}">{{$c.SecretsLink}}</a>{{end}} |
| {{if and (eq .Key "domain") $.GettingStarted.IsOwner $.GettingStarted.DomainApp}}<a class="btn btn-sm btn-secondary" href="{{$.Base}}/apps/{{$.GettingStarted.DomainApp}}/settings/domains">{{$c.DomainLink}}</a>{{end}} |
| {{if or (eq .Key "secrets") (eq .Key "domain")}}<form method="post" action="{{$.Base}}/getting-started/done"><input type="hidden" name="csrf" value="{{$.CSRF}}"><input type="hidden" name="step" value="{{.Key}}"><button class="btn-sm" type="submit">{{$c.MarkDone}}</button></form> |
| <form method="post" action="{{$.Base}}/getting-started/skip"><input type="hidden" name="csrf" value="{{$.CSRF}}"><input type="hidden" name="step" value="{{.Key}}"><button class="btn-sm btn-secondary" type="submit">{{$c.Skip}}</button></form>{{end}} |