console: getting started fills {console} in every copy field
The substitution now runs over every string field of the card's copy,
and the Show link outside the card reads the same filled-in copy from a
page field. The copy test scans every field for {console} and dashes.
No wording changes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5 files changed,
+59
−11
internal/console/gettingstarted.go+15 −7internal/console/gettingstarted_page_test.go+1 −1internal/console/gettingstarted_test.go+37 −1internal/console/gettingstartedcopy.go+3 −2internal/console/server.go+3 −0
Intent
Human
Mainly for agents to make sure they come out without obvious prototype feel and layout/convention issues
Human
Yes.
diff --git a/internal/console/gettingstarted.go b/internal/console/gettingstarted.go| index a129c0496..54eb20306 100644 |
| --- a/internal/console/gettingstarted.go |
| +++ b/internal/console/gettingstarted.go |
| @@ -2,6 +2,7 @@ package console |
| import ( |
| "log" |
| + "reflect" |
| "strings" |
| "time" |
| ) |
| @@ -89,10 +90,7 @@ func buildGettingStarted(marks map[gsMark]bool, connected, anyLive bool, role st |
| if marks[gsHidden] || marks[gsCompleted] { |
| return nil, false |
| } |
| - c := approvedGettingStartedCopy |
| - for _, p := range []*string{&c.ConnectPrompt, &c.DeployPrompt, &c.SecretsPrompt} { |
| - *p = strings.ReplaceAll(*p, "{console}", consoleName) |
| - } |
| + c := gettingStartedCopyFor(approvedGettingStartedCopy, consoleName) |
| mark := func(done, skip gsMark) gsStepState { |
| switch { |
| case marks[done]: |
| @@ -154,6 +152,8 @@ func (s *Server) fillGettingStarted(p *page, acct *Account, addr, role string, l |
| log.Printf("console: getting started marks %s: %v", acct.Sqid, err) |
| return |
| } |
| + // 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()) |
| if complete { |
| @@ -191,6 +191,14 @@ func gsDomainApp(apps []appRow, live map[string]bool) string { |
| return first |
| } |
| -// GettingStartedCopy is the card's strings, for the Show link the page |
| -// offers when there is no card to carry them. |
| -func (p page) GettingStartedCopy() gettingStartedCopy { return approvedGettingStartedCopy } |
| +// gettingStartedCopyFor is c with {console} replaced by consoleName in |
| +// every string field, so no field can render the placeholder. |
| +func gettingStartedCopyFor(c gettingStartedCopy, consoleName string) gettingStartedCopy { |
| + rv := reflect.ValueOf(&c).Elem() |
| + for i := 0; i < rv.NumField(); i++ { |
| + if f := rv.Field(i); f.Kind() == reflect.String { |
| + f.SetString(strings.ReplaceAll(f.String(), "{console}", consoleName)) |
| + } |
| + } |
| + return c |
| +} |
diff --git a/internal/console/gettingstarted_page_test.go b/internal/console/gettingstarted_page_test.go| index a27e399df..6e4b3f2ec 100644 |
| --- a/internal/console/gettingstarted_page_test.go |
| +++ b/internal/console/gettingstarted_page_test.go |
| @@ -177,7 +177,7 @@ func TestGettingStartedHiddenShowsLink(t *testing.T) { |
| if gsCardShown(body) { |
| t.Fatal("hidden card still rendered") |
| } |
| - if !strings.Contains(body, show) || !strings.Contains(body, approvedGettingStartedCopy.Show) { |
| + if label := gettingStartedCopyFor(approvedGettingStartedCopy, fx.srv.consoleName()).Show; !strings.Contains(body, show) || !strings.Contains(body, label) { |
| t.Fatalf("no Show getting started form:\n%s", body) |
| } |
| } |
diff --git a/internal/console/gettingstarted_test.go b/internal/console/gettingstarted_test.go| index 2374b086f..cf5b220d9 100644 |
| --- a/internal/console/gettingstarted_test.go |
| +++ b/internal/console/gettingstarted_test.go |
| @@ -1,6 +1,7 @@ |
| package console |
| import ( |
| + "reflect" |
| "strings" |
| "testing" |
| "time" |
| @@ -159,7 +160,7 @@ func TestBuildGettingStarted(t *testing.T) { |
| if v.DomainApp != "shop" { |
| t.Errorf("domain app %q", v.DomainApp) |
| } |
| - all2 := v.Copy.ConnectPrompt + v.Copy.DeployPrompt + v.Copy.SecretsPrompt |
| + all2 := strings.Join(gsCopyFields(t, v.Copy), "\n") |
| for _, s := range v.Steps { |
| all2 += s.Title + s.Body + s.Prompt + s.CLI |
| } |
| @@ -191,3 +192,38 @@ func TestGettingStartedDomainAppOrder(t *testing.T) { |
| t.Errorf("no apps: %q", got) |
| } |
| } |
| + |
| +// gsCopyFields is every string field of c, failing on a field of any other |
| +// kind so a new field cannot slip past the scans. |
| +func gsCopyFields(t *testing.T, c gettingStartedCopy) []string { |
| + t.Helper() |
| + rv := reflect.ValueOf(c) |
| + var out []string |
| + for i := 0; i < rv.NumField(); i++ { |
| + f := rv.Field(i) |
| + if f.Kind() != reflect.String { |
| + t.Fatalf("copy field %s is a %s, not a string", rv.Type().Field(i).Name, f.Kind()) |
| + } |
| + out = append(out, f.String()) |
| + } |
| + return out |
| +} |
| + |
| +// {console} is filled in on every field, not only the prompts. |
| +func TestGettingStartedCopyFillsEveryField(t *testing.T) { |
| + var all gettingStartedCopy |
| + rv := reflect.ValueOf(&all).Elem() |
| + for i := 0; i < rv.NumField(); i++ { |
| + rv.Field(i).SetString("on {console} and {console}") |
| + } |
| + for i, got := range gsCopyFields(t, gettingStartedCopyFor(all, "Example Cloud")) { |
| + if got != "on Example Cloud and Example Cloud" { |
| + t.Errorf("field %s = %q", rv.Type().Field(i).Name, got) |
| + } |
| + } |
| + for _, f := range gsCopyFields(t, gettingStartedCopyFor(approvedGettingStartedCopy, "Example Cloud")) { |
| + if strings.Contains(f, "{console}") || strings.ContainsAny(f, "—–") { |
| + t.Errorf("approved copy field %q", f) |
| + } |
| + } |
| +} |
diff --git a/internal/console/gettingstartedcopy.go b/internal/console/gettingstartedcopy.go| index d682b7b94..3d8e88343 100644 |
| --- a/internal/console/gettingstartedcopy.go |
| +++ b/internal/console/gettingstartedcopy.go |
| @@ -1,7 +1,8 @@ |
| package console |
| -// gettingStartedCopy is every string on the Getting started card. Fields |
| -// holding {console} are filled in by buildGettingStarted. |
| +// gettingStartedCopy is every string on the Getting started card. Every |
| +// field has {console} filled in by gettingStartedCopyFor; keep them all |
| +// strings. |
| type gettingStartedCopy struct { |
| Title, Hide, Show, Done, Skipped, MarkDone, Skip, Copy, Copied string |
diff --git a/internal/console/server.go b/internal/console/server.go| index c32ce1595..8f97287b9 100644 |
| --- a/internal/console/server.go |
| +++ b/internal/console/server.go |
| @@ -2656,6 +2656,9 @@ type page struct { |
| // a card the viewer hid or completed. |
| GettingStarted *gettingStartedView |
| ShowGettingStarted bool |
| + // GettingStartedCopy is the card's strings, {console} filled in, for |
| + // the Show link the page offers when there is no card to carry them. |
| + GettingStartedCopy gettingStartedCopy |
| // ExpiresAt is when a temporary app moves to the Trash; zero for a |
| // permanent one. appnav shows it with the Keep button. |