console: cache the app-tab frame for 30 s; every console write to the app clears it first
Every app tab read the channel listing, each channel pointer, the production
flag and the pipeline on every view, and the Overview and Releases pending
cards and the Pipeline settings section read the pipeline again. appframe.go
holds those reads per app (appFrames, appFrameTTL 30 s, deep copies out),
loaded in today's order; Assemble's signature is unchanged and page views go
through assembleViews with the cache. The pending cards and the settings
section use the frame's pipeline.
registerRoute wraps every non-GET request: before its first response byte,
and again when the handler returns, it clears the app its pattern names
({app}), or the account ({sqid} or {account}). Refusals and half-done writes
clear too. Rename clears the new name itself. A non-GET request never reads
the cache (frameBypassKey), so a write door decides on nothing cached.
A load stores its frame only if no clear happened while it ran: one
generation counter for the whole cache, since the clears run before the
gates and a per-name map could be grown by anyone. Failed reads are never
stored.
Tests that write straight into the bucket call fx.forgetFrame (seedChannel
and setPipeline do it themselves): they stand for a writer outside the
console, which a console sees within 30 s.
Warm S3 calls: activity, account review, the account home and the pipeline,
placement and delete settings sections 0; Overview 10 -> 3; Releases 13 -> 6;
Analytics 10 -> 4 (now a calls record); Errors and Availability 16 -> 10;
Logs 14 -> 8; Running 23 -> 17; instance page 30 -> 24; Settings General
31 -> 25, heavy sections 30 -> 24, errors-analytics 8 -> 2. Session 820 -> 586.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
25 files changed,
+1,195
−89
internal/console/apiassets_test.go+1 −0internal/console/apicli_test.go+3 −0internal/console/apigatepass_test.go+1 −0internal/console/apiinstanceschannel_test.go+2 −0internal/console/apipipeline_test.go+1 −0internal/console/appframe.go+335 −0internal/console/appframe_test.go+722 −0internal/console/appsettings.go+3 −0internal/console/appsettings_test.go+1 −0internal/console/bakecontrols_test.go+4 −0internal/console/claim_routes.go+6 −0internal/console/deletion_test.go+2 −0internal/console/deployscope_test.go+1 −0internal/console/ladder_test.go+16 −1internal/console/pendingflow_test.go+1 −0internal/console/pipelinepage.go+4 −7internal/console/remoteinstances.go+5 −2internal/console/remoteinstances_round4_test.go+1 −0internal/console/remoteinstances_test.go+1 −0internal/console/rolloutjoin_test.go+1 −0internal/console/serialbump_test.go+3 −0internal/console/server.go+14 −13internal/console/server_test.go+1 −0internal/console/testdata/perf-budgets.txt+14 −16internal/console/view.go+52 −50
diff --git a/internal/console/apiassets_test.go b/internal/console/apiassets_test.go| index 03c56e2cd..66dca5f7a 100644 |
| --- a/internal/console/apiassets_test.go |
| +++ b/internal/console/apiassets_test.go |
| @@ -537,6 +537,7 @@ func TestAssetsStatusJoinsPublishedGeneration(t *testing.T) { |
| if err := release.Promote(ctx, fx.rel, fx.priv, shipAssetsAccount, assetsApp, "stable", "v1"); err != nil { |
| t.Fatal(err) |
| } |
| + fx.forgetFrame(assetsApp) |
| at := time.Date(2026, 10, 25, 9, 0, 0, 0, time.UTC) |
| edges := map[string]any{ |
| "v": 1, "box": "box-a", "eip": "192.0.2.1", "region": "ie", |
diff --git a/internal/console/apicli_test.go b/internal/console/apicli_test.go| index 969d668d3..ced8f9f48 100644 |
| --- a/internal/console/apicli_test.go |
| +++ b/internal/console/apicli_test.go |
| @@ -230,6 +230,7 @@ func TestAPIChannelsErrorRow(t *testing.T) { |
| if _, err := fx.rel.Put(context.Background(), release.ChannelKey(release.OpsAccount, "titogo", "broken"), garbage, ""); err != nil { |
| t.Fatal(err) |
| } |
| + fx.forgetFrame("titogo") |
| token := cliToken(t, fx, "paul@keymail.dev", "code-channels-error-row") |
| status, out := getJSON(t, fx.ts.URL+"/api/cli/apps/bab/titogo/channels", token) |
| @@ -352,6 +353,7 @@ func TestAPIChannelsPipelineUnreadableOmitsKey(t *testing.T) { |
| if _, err := fx.rel.Put(context.Background(), release.PipelineKey("bab", "widget"), []byte("not json"), ""); err != nil { |
| t.Fatal(err) |
| } |
| + fx.forgetFrame("widget") |
| token := cliToken(t, fx, "paul@keymail.dev", "code-channels-pipeline-unreadable") |
| status, out := getJSON(t, fx.ts.URL+"/api/cli/apps/bab/widget/channels", token) |
| @@ -2423,6 +2425,7 @@ func TestAPITrashProductionRefused(t *testing.T) { |
| release.OpsAccount, "titogo", true, "paul@keymail.dev"); err != nil { |
| t.Fatal(err) |
| } |
| + fx.forgetFrame("titogo") |
| status, body := postBody(t, fx.ts.URL+"/api/cli/apps/bab/titogo/delete", token, "") |
| if status != http.StatusConflict { |
diff --git a/internal/console/apigatepass_test.go b/internal/console/apigatepass_test.go| index 75cfb8c6c..177a309f2 100644 |
| --- a/internal/console/apigatepass_test.go |
| +++ b/internal/console/apigatepass_test.go |
| @@ -190,6 +190,7 @@ func TestAPIInstanceGatePassDeployScope(t *testing.T) { |
| []release.PipelineChannel{{Name: "edge"}, {Name: "stable"}}, "paul@keymail.dev"); err != nil { |
| t.Fatal(err) |
| } |
| + fx.forgetFrame("titogo") |
| if status, _, out := rawReq(t, http.MethodPost, edge, tok, ""); status != http.StatusForbidden { |
| t.Fatalf("deploy credential, edge host on a pipelined app = %d %s, want 403", status, out) |
| } |
diff --git a/internal/console/apiinstanceschannel_test.go b/internal/console/apiinstanceschannel_test.go| index bb79b4588..c0173cb62 100644 |
| --- a/internal/console/apiinstanceschannel_test.go |
| +++ b/internal/console/apiinstanceschannel_test.go |
| @@ -201,6 +201,7 @@ func TestAPIInstanceCreateUnreadablePipelineRefuses(t *testing.T) { |
| release.PipelineKey(release.OpsAccount, "titogo"), []byte("not json"), ""); err != nil { |
| t.Fatal(err) |
| } |
| + fx.forgetFrame("titogo") |
| status, _, out := rawReq(t, http.MethodPost, instancesURL(fx, "bab", "titogo"), member, |
| `{"host":"acme.go.tito.io","region":"ie"}`) |
| @@ -229,6 +230,7 @@ func TestAPIInstanceCreateExplicitChannelNeverReadsThePipeline(t *testing.T) { |
| release.PipelineKey(release.OpsAccount, "titogo"), []byte("not json"), ""); err != nil { |
| t.Fatal(err) |
| } |
| + fx.forgetFrame("titogo") |
| status, _, out := rawReq(t, http.MethodPost, instancesURL(fx, "bab", "titogo"), member, |
| `{"host":"acme.go.tito.io","region":"ie","channel":"canary/boot-check"}`) |
diff --git a/internal/console/apipipeline_test.go b/internal/console/apipipeline_test.go| index 74cdc8824..36bd5c30a 100644 |
| --- a/internal/console/apipipeline_test.go |
| +++ b/internal/console/apipipeline_test.go |
| @@ -130,6 +130,7 @@ func TestAPIPipelineGetUnreadableIsNot502(t *testing.T) { |
| if _, err := fx.rel.Put(context.Background(), release.PipelineKey("bab", "widget"), []byte("not json"), ""); err != nil { |
| t.Fatal(err) |
| } |
| + fx.forgetFrame("widget") |
| token := cliToken(t, fx, "paul@keymail.dev", "code-pipeline-unreadable") |
| status, out := getJSON(t, fx.ts.URL+"/api/cli/apps/bab/widget/pipeline", token) |
diff --git a/internal/console/appframe.go b/internal/console/appframe.go| new file mode 100644 |
| index 000000000..2c0fa9baf |
| --- /dev/null |
| +++ b/internal/console/appframe.go |
| @@ -0,0 +1,335 @@ |
| +package console |
| + |
| +import ( |
| + "context" |
| + "crypto/ed25519" |
| + "net/http" |
| + "slices" |
| + "sort" |
| + "strings" |
| + "sync" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/release" |
| +) |
| + |
| +// The app-tab frame: the release-store reads every app tab makes before its |
| +// own part (the channel listing and each channel pointer, the production |
| +// flag, the pipeline), kept per app for appFrameTTL so a person moving |
| +// between tabs does not pay them again on every view. |
| +// |
| +// READ YOUR OWN WRITES. Every console door that writes one of these objects |
| +// sits under an {app} route, and registerRoute clears that app's entry |
| +// before the door's response goes out (frameClearingWriter), so the page a |
| +// write redirects to always loads fresh. A door with only {sqid} (or |
| +// {account}) clears the whole account: the new-app and trash doors. Rename |
| +// clears the new name itself. A writer outside the console (another |
| +// console, a box, an operator's script) is seen within appFrameTTL. |
| +// |
| +// WRITE DOORS NEVER READ IT. A non-GET request's context carries |
| +// frameBypassKey (registerRoute), and appFrame loads fresh for it without |
| +// storing, so a write door that builds its page through appPage decides on |
| +// nothing older than its own request. Doors that decide on these objects |
| +// read them directly anyway. |
| + |
| +// appFrameTTL is how long a frame is served without asking the bucket. |
| +const appFrameTTL = 30 * time.Second |
| + |
| +// frameChannel is one channel pointer as read: the verified pointer, or the |
| +// read's error. |
| +type frameChannel struct { |
| + Name string |
| + Pointer *release.ChannelPointer |
| + Err string |
| +} |
| + |
| +// appFrame is one app's frame. Each *Err holds the read's error text; a |
| +// frame with any of them set is never cached. |
| +type appFrame struct { |
| + Channels []frameChannel |
| + ChannelsErr string |
| + Production *release.ProductionFlag |
| + ProductionErr string |
| + Pipeline *release.Pipeline |
| + PipelineErr string |
| +} |
| + |
| +// failed reports whether any read in the frame failed. |
| +func (f appFrame) failed() bool { |
| + if f.ChannelsErr != "" || f.ProductionErr != "" || f.PipelineErr != "" { |
| + return true |
| + } |
| + for _, c := range f.Channels { |
| + if c.Err != "" { |
| + return true |
| + } |
| + } |
| + return false |
| +} |
| + |
| +// clone is a deep copy: every slice, every pointed-to struct and its slices. |
| +// Cached frames are shared; what a caller gets is its own. |
| +func (f appFrame) clone() appFrame { |
| + out := f |
| + if f.Channels != nil { |
| + out.Channels = make([]frameChannel, len(f.Channels)) |
| + for i, c := range f.Channels { |
| + if c.Pointer != nil { |
| + p := *c.Pointer |
| + p.History = slices.Clone(c.Pointer.History) |
| + p.HistoryDigests = slices.Clone(c.Pointer.HistoryDigests) |
| + p.Audit = slices.Clone(c.Pointer.Audit) |
| + c.Pointer = &p |
| + } |
| + out.Channels[i] = c |
| + } |
| + } |
| + if f.Production != nil { |
| + p := *f.Production |
| + out.Production = &p |
| + } |
| + if f.Pipeline != nil { |
| + p := *f.Pipeline |
| + p.Channels = slices.Clone(f.Pipeline.Channels) |
| + out.Pipeline = &p |
| + } |
| + return out |
| +} |
| + |
| +// loadAppFrame makes the frame's reads, in the order the app tabs have |
| +// always made them: the channel listing, each channel, the production flag, |
| +// then the pipeline (bounded by pipelineStoreTimeout, as it always was). |
| +func loadAppFrame(ctx context.Context, st release.Store, pub ed25519.PublicKey, acct, app string) appFrame { |
| + var f appFrame |
| + prefix := release.ChannelsPrefix(acct, app) |
| + keys, err := st.List(ctx, prefix) |
| + if err != nil { |
| + f.ChannelsErr = err.Error() |
| + } else { |
| + var names []string |
| + for _, k := range keys { |
| + name := strings.TrimPrefix(k, prefix) |
| + if !strings.HasSuffix(name, ".json") { |
| + continue |
| + } |
| + names = append(names, strings.TrimSuffix(name, ".json")) |
| + } |
| + sort.Strings(names) |
| + for _, name := range names { |
| + p, err := release.Channel(ctx, st, pub, acct, app, name) |
| + if err != nil { |
| + f.Channels = append(f.Channels, frameChannel{Name: name, Err: err.Error()}) |
| + continue |
| + } |
| + f.Channels = append(f.Channels, frameChannel{Name: name, Pointer: p}) |
| + } |
| + } |
| + if flag, err := release.GetProduction(ctx, st, pub, acct, app); err != nil { |
| + f.ProductionErr = err.Error() |
| + } else { |
| + f.Production = flag |
| + } |
| + pctx, cancel := context.WithTimeout(ctx, pipelineStoreTimeout) |
| + defer cancel() |
| + if pipe, err := release.GetPipeline(pctx, st, pub, acct, app); err != nil { |
| + f.PipelineErr = err.Error() |
| + } else { |
| + f.Pipeline = pipe |
| + } |
| + return f |
| +} |
| + |
| +type frameKey struct{ acct, app string } |
| + |
| +type frameEntry struct { |
| + frame appFrame |
| + at time.Time |
| +} |
| + |
| +// appFrames is the cache. The zero value is ready (ttl 0 is appFrameTTL, nil |
| +// now is time.Now), like keyedLocks, so &Server{} literals stay safe. It |
| +// holds one entry per app viewed; nothing refreshes in the background. |
| +// |
| +// The generation is what stops a view that began before a write from |
| +// putting the old frame back after the write's clear: get notes it before |
| +// loading and stores only if no clear has happened since. It is one counter |
| +// for the whole cache, not one per app: the clears run on every non-GET |
| +// request before any gate, so a map keyed by the names in those requests |
| +// could be grown by anyone. A clear anywhere costs an in-flight load |
| +// elsewhere its store, which is one extra load on that app's next view. |
| +type appFrames struct { |
| + mu sync.Mutex |
| + ttl time.Duration |
| + now func() time.Time |
| + m map[frameKey]frameEntry |
| + gen uint64 |
| +} |
| + |
| +func (c *appFrames) clock() time.Time { |
| + if c.now != nil { |
| + return c.now() |
| + } |
| + return time.Now() |
| +} |
| + |
| +func (c *appFrames) lifetime() time.Duration { |
| + if c.ttl > 0 { |
| + return c.ttl |
| + } |
| + return appFrameTTL |
| +} |
| + |
| +// get answers acct/app's frame from the cache while it is fresh, else from |
| +// load, storing the result only when it has no error and no clear happened |
| +// while it loaded. Either way the caller gets its own copy. |
| +func (c *appFrames) get(ctx context.Context, acct, app string, load func(context.Context) appFrame) appFrame { |
| + k := frameKey{acct, app} |
| + c.mu.Lock() |
| + now := c.clock() |
| + if e, ok := c.m[k]; ok && now.Before(e.at.Add(c.lifetime())) { |
| + f := e.frame.clone() |
| + c.mu.Unlock() |
| + return f |
| + } |
| + gen := c.gen |
| + c.mu.Unlock() |
| + |
| + f := load(ctx) |
| + if f.failed() { |
| + return f |
| + } |
| + c.mu.Lock() |
| + if c.gen == gen { |
| + if c.m == nil { |
| + c.m = make(map[frameKey]frameEntry) |
| + } |
| + // Stamped with the time the load began: an entry never outlives |
| + // the TTL measured from its oldest read. |
| + c.m[k] = frameEntry{frame: f.clone(), at: now} |
| + } |
| + c.mu.Unlock() |
| + return f |
| +} |
| + |
| +// clearApp drops app's entry in every account (app names are per account, |
| +// and a CLI door's account segment is not checked here). |
| +func (c *appFrames) clearApp(app string) { |
| + c.mu.Lock() |
| + c.gen++ |
| + for k := range c.m { |
| + if k.app == app { |
| + delete(c.m, k) |
| + } |
| + } |
| + c.mu.Unlock() |
| +} |
| + |
| +// clearAccount drops every entry of the account. |
| +func (c *appFrames) clearAccount(sqid string) { |
| + c.mu.Lock() |
| + c.gen++ |
| + for k := range c.m { |
| + if k.acct == sqid { |
| + delete(c.m, k) |
| + } |
| + } |
| + c.mu.Unlock() |
| +} |
| + |
| +// frameBypassKey marks a non-GET request's context: appFrame loads fresh |
| +// for it and stores nothing. |
| +type frameBypassKey struct{} |
| + |
| +// appFrame is the frame for a page view: the cache over the console's |
| +// release store, or a fresh load for a write door's request. |
| +func (s *Server) appFrame(ctx context.Context, acct, app string) appFrame { |
| + load := func(ctx context.Context) appFrame { |
| + return loadAppFrame(ctx, s.cfg.Releases, s.cfg.ReleasePub, acct, app) |
| + } |
| + if ctx.Value(frameBypassKey{}) != nil { |
| + return load(ctx) |
| + } |
| + return s.frames.get(ctx, acct, app, load) |
| +} |
| + |
| +// frameClear is the clear registerRoute runs for a write request: the app |
| +// for a pattern with {app}, else the account for one with {sqid} or |
| +// {account}, else nothing (nil). |
| +func (s *Server) frameClear(pattern string) func(r *http.Request) { |
| + switch { |
| + case strings.Contains(pattern, "{app}"): |
| + return func(r *http.Request) { s.frames.clearApp(r.PathValue("app")) } |
| + case strings.Contains(pattern, "{sqid}"): |
| + return func(r *http.Request) { s.frames.clearAccount(r.PathValue("sqid")) } |
| + case strings.Contains(pattern, "{account}"): |
| + return func(r *http.Request) { s.frames.clearAccount(r.PathValue("account")) } |
| + } |
| + return nil |
| +} |
| + |
| +// patternMethod is a mux pattern's method, "" for a method-less pattern. |
| +func patternMethod(pattern string) string { |
| + if i := strings.IndexByte(pattern, ' '); i > 0 && !strings.Contains(pattern[:i], "/") { |
| + return pattern[:i] |
| + } |
| + return "" |
| +} |
| + |
| +// readOnlyMethod reports whether a request with this method cannot write. |
| +func readOnlyMethod(m string) bool { return m == http.MethodGet || m == http.MethodHead } |
| + |
| +// frameClearingWriter runs clear before the first byte of the response, |
| +// header included, so a client that follows the response (a redirect, a |
| +// reload) never sees a frame from before the write. The wrapper changes |
| +// nothing else: Unwrap keeps http.ResponseController working. |
| +type frameClearingWriter struct { |
| + http.ResponseWriter |
| + clear func() |
| + cleared bool |
| +} |
| + |
| +func (w *frameClearingWriter) before() { |
| + if !w.cleared { |
| + w.cleared = true |
| + w.clear() |
| + } |
| +} |
| + |
| +func (w *frameClearingWriter) WriteHeader(code int) { |
| + w.before() |
| + w.ResponseWriter.WriteHeader(code) |
| +} |
| + |
| +func (w *frameClearingWriter) Write(b []byte) (int, error) { |
| + w.before() |
| + return w.ResponseWriter.Write(b) |
| +} |
| + |
| +func (w *frameClearingWriter) Unwrap() http.ResponseWriter { return w.ResponseWriter } |
| + |
| +// withFrameClear wraps h for pattern: a GET or HEAD request passes through |
| +// untouched; any other request is marked frameBypassKey and has its clear |
| +// run before its first response byte and again when h returns (for work |
| +// done after the response was started). Gate order is h's own: this runs |
| +// nothing before h but the clear itself. |
| +func (s *Server) withFrameClear(pattern string, h http.HandlerFunc) http.HandlerFunc { |
| + method := patternMethod(pattern) |
| + if readOnlyMethod(method) { |
| + return h |
| + } |
| + clear := s.frameClear(pattern) |
| + return func(w http.ResponseWriter, r *http.Request) { |
| + if readOnlyMethod(r.Method) { |
| + h(w, r) |
| + return |
| + } |
| + r = r.WithContext(context.WithValue(r.Context(), frameBypassKey{}, true)) |
| + if clear == nil { |
| + h(w, r) |
| + return |
| + } |
| + cw := &frameClearingWriter{ResponseWriter: w, clear: func() { clear(r) }} |
| + defer clear(r) |
| + h(cw, r) |
| + } |
| +} |
diff --git a/internal/console/appframe_test.go b/internal/console/appframe_test.go| new file mode 100644 |
| index 000000000..7ff21f56c |
| --- /dev/null |
| +++ b/internal/console/appframe_test.go |
| @@ -0,0 +1,722 @@ |
| +package console |
| + |
| +import ( |
| + "context" |
| + "errors" |
| + "io" |
| + "io/fs" |
| + "net/http" |
| + "net/http/httptest" |
| + "net/url" |
| + "os" |
| + "path/filepath" |
| + "regexp" |
| + "strings" |
| + "sync" |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/provision" |
| + "github.com/carlosframework/platform/internal/release" |
| +) |
| + |
| +// ---- appFrames on its own -------------------------------------------------- |
| + |
| +// testFrame is a frame with one channel and a two-channel pipeline, so a |
| +// caller has a slice inside a pointer to mutate. |
| +func testFrame(version string) appFrame { |
| + return appFrame{ |
| + Channels: []frameChannel{{Name: "stable", Pointer: &release.ChannelPointer{ |
| + Version: version, History: []string{"v0"}, HistoryDigests: []string{""}, |
| + Audit: []release.Promotion{{Version: version}}, |
| + }}}, |
| + Production: &release.ProductionFlag{Production: true}, |
| + Pipeline: &release.Pipeline{Channels: []release.PipelineChannel{{Name: "beta"}, {Name: "stable"}}}, |
| + } |
| +} |
| + |
| +// countingLoad returns a load func that answers testFrame(version) and |
| +// counts its calls. |
| +func countingLoad(version string, n *int) func(context.Context) appFrame { |
| + return func(context.Context) appFrame { |
| + *n++ |
| + return testFrame(version) |
| + } |
| +} |
| + |
| +// TestAppFrameLoadDuringWriteNotStored: a load that started before a clear |
| +// and finishes after it must not put its (pre-write) frame into the cache. |
| +func TestAppFrameLoadDuringWriteNotStored(t *testing.T) { |
| + for _, tc := range []struct { |
| + name string |
| + clear func(c *appFrames) |
| + }{ |
| + {"clearApp", func(c *appFrames) { c.clearApp("kass") }}, |
| + {"clearAccount", func(c *appFrames) { c.clearAccount("bab") }}, |
| + {"clearApp of another app", func(c *appFrames) { c.clearApp("other") }}, |
| + } { |
| + t.Run(tc.name, func(t *testing.T) { |
| + var c appFrames |
| + started, unblock := make(chan struct{}), make(chan struct{}) |
| + done := make(chan appFrame) |
| + go func() { |
| + done <- c.get(context.Background(), "bab", "kass", func(context.Context) appFrame { |
| + close(started) |
| + <-unblock |
| + return testFrame("old") |
| + }) |
| + }() |
| + <-started |
| + tc.clear(&c) |
| + close(unblock) |
| + if f := <-done; f.Channels[0].Pointer.Version != "old" { |
| + t.Fatalf("the in-flight get answered %q, want its own load's value", f.Channels[0].Pointer.Version) |
| + } |
| + n := 0 |
| + f := c.get(context.Background(), "bab", "kass", countingLoad("new", &n)) |
| + if n != 1 || f.Channels[0].Pointer.Version != "new" { |
| + t.Fatalf("after a clear during a load: load calls %d, version %q; want 1 and \"new\"", n, f.Channels[0].Pointer.Version) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// TestAppFrameConcurrentGetsAndClears is the race detector's case: views and |
| +// writes on the same app at once. After the last clear, the next get loads. |
| +func TestAppFrameConcurrentGetsAndClears(t *testing.T) { |
| + var c appFrames |
| + var wg sync.WaitGroup |
| + for i := range 8 { |
| + wg.Add(2) |
| + go func() { |
| + defer wg.Done() |
| + for range 50 { |
| + f := c.get(context.Background(), "bab", "kass", func(context.Context) appFrame { return testFrame("v1") }) |
| + f.Channels[0].Pointer.History[0] = "mutated" |
| + f.Pipeline.Channels[0].Name = "mutated" |
| + } |
| + }() |
| + go func() { |
| + defer wg.Done() |
| + for range 50 { |
| + if i%2 == 0 { |
| + c.clearApp("kass") |
| + } else { |
| + c.clearAccount("bab") |
| + } |
| + } |
| + }() |
| + } |
| + wg.Wait() |
| + c.clearApp("kass") |
| + n := 0 |
| + f := c.get(context.Background(), "bab", "kass", countingLoad("v2", &n)) |
| + if n != 1 || f.Channels[0].Pointer.Version != "v2" { |
| + t.Fatalf("after the last clear: load calls %d, version %q; want 1 and v2", n, f.Channels[0].Pointer.Version) |
| + } |
| +} |
| + |
| +// TestAppFrameClears: clearApp drops the app in every account, clearAccount |
| +// drops every app in one account, and neither touches anything else. |
| +func TestAppFrameClears(t *testing.T) { |
| + var c appFrames |
| + n := 0 |
| + load := countingLoad("v1", &n) |
| + keys := [][2]string{{"bab", "kass"}, {"bab", "shop"}, {"other", "kass"}, {"other", "shop"}} |
| + warm := func() { |
| + for _, k := range keys { |
| + c.get(context.Background(), k[0], k[1], load) |
| + } |
| + } |
| + warm() |
| + if n != 4 { |
| + t.Fatalf("cold loads = %d, want 4", n) |
| + } |
| + warm() |
| + if n != 4 { |
| + t.Fatalf("warm loads = %d, want still 4", n) |
| + } |
| + c.clearApp("kass") |
| + warm() |
| + if n != 6 { |
| + t.Fatalf("loads after clearApp(kass) = %d, want 6 (kass in both accounts)", n) |
| + } |
| + c.clearAccount("bab") |
| + warm() |
| + if n != 8 { |
| + t.Fatalf("loads after clearAccount(bab) = %d, want 8 (both of bab's apps)", n) |
| + } |
| +} |
| + |
| +// TestAppFrameCopiesOnRead: what get hands back is the caller's to change. |
| +func TestAppFrameCopiesOnRead(t *testing.T) { |
| + var c appFrames |
| + n := 0 |
| + load := countingLoad("v1", &n) |
| + first := c.get(context.Background(), "bab", "kass", load) |
| + first.Channels[0].Pointer.History[0] = "mutated" |
| + first.Channels[0].Pointer.HistoryDigests[0] = "mutated" |
| + first.Channels[0].Pointer.Audit[0].Version = "mutated" |
| + first.Channels[0].Name = "mutated" |
| + first.Production.Production = false |
| + first.Pipeline.Channels[0].Name = "mutated" |
| + |
| + second := c.get(context.Background(), "bab", "kass", load) |
| + if n != 1 { |
| + t.Fatalf("load calls = %d, want 1 (the second get is a hit)", n) |
| + } |
| + second.Pipeline.Channels = append(second.Pipeline.Channels, release.PipelineChannel{Name: "extra"}) |
| + |
| + third := c.get(context.Background(), "bab", "kass", load) |
| + want := testFrame("v1") |
| + if third.Channels[0].Name != want.Channels[0].Name || |
| + third.Channels[0].Pointer.History[0] != "v0" || |
| + third.Channels[0].Pointer.HistoryDigests[0] != "" || |
| + third.Channels[0].Pointer.Audit[0].Version != "v1" || |
| + !third.Production.Production || |
| + len(third.Pipeline.Channels) != 2 || third.Pipeline.Channels[0].Name != "beta" { |
| + t.Fatalf("a caller's mutation reached the cache: %+v / %+v / %+v", third.Channels[0], third.Production, third.Pipeline) |
| + } |
| +} |
| + |
| +// TestAppFrameExpires: an entry lives appFrameTTL, then the next get loads. |
| +func TestAppFrameExpires(t *testing.T) { |
| + now := time.Unix(1_800_000_000, 0) |
| + c := appFrames{now: func() time.Time { return now }} |
| + n := 0 |
| + load := countingLoad("v1", &n) |
| + c.get(context.Background(), "bab", "kass", load) |
| + now = now.Add(29 * time.Second) |
| + c.get(context.Background(), "bab", "kass", load) |
| + if n != 1 { |
| + t.Fatalf("loads at 29 s = %d, want 1", n) |
| + } |
| + now = now.Add(2 * time.Second) |
| + c.get(context.Background(), "bab", "kass", load) |
| + if n != 2 { |
| + t.Fatalf("loads at 31 s = %d, want 2", n) |
| + } |
| +} |
| + |
| +// TestAppFrameFailedLoadNotStored: a frame carrying any read error is |
| +// answered but never kept. |
| +func TestAppFrameFailedLoadNotStored(t *testing.T) { |
| + for _, tc := range []struct { |
| + name string |
| + fail func(f *appFrame) |
| + }{ |
| + {"channel listing", func(f *appFrame) { f.ChannelsErr = "boom" }}, |
| + {"one channel", func(f *appFrame) { f.Channels[0].Err = "boom" }}, |
| + {"production", func(f *appFrame) { f.ProductionErr = "boom" }}, |
| + {"pipeline", func(f *appFrame) { f.PipelineErr = "boom" }}, |
| + } { |
| + t.Run(tc.name, func(t *testing.T) { |
| + var c appFrames |
| + n := 0 |
| + load := func(context.Context) appFrame { |
| + n++ |
| + f := testFrame("v1") |
| + tc.fail(&f) |
| + return f |
| + } |
| + c.get(context.Background(), "bab", "kass", load) |
| + c.get(context.Background(), "bab", "kass", load) |
| + if n != 2 { |
| + t.Fatalf("loads = %d, want 2 (a failed frame is not cached)", n) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// ---- through the console ---------------------------------------------------- |
| + |
| +// TestAppFrameWarmViewReadsNothing: the second view of an app tab makes no |
| +// S3 request at all. |
| +func TestAppFrameWarmViewReadsNothing(t *testing.T) { |
| + fx, lat := newPerfFixture(t) |
| + c := signInPaul(t, fx) |
| + if status, _, body := get(t, c, fx.u("/apps/kass/activity")); status != http.StatusOK { |
| + t.Fatalf("activity = %d:\n%s", status, body) |
| + } |
| + before, _ := lat.Calls() |
| + if status, _, body := get(t, c, fx.u("/apps/kass/activity")); status != http.StatusOK { |
| + t.Fatalf("activity = %d:\n%s", status, body) |
| + } |
| + if after, _ := lat.Calls(); after != before { |
| + t.Fatalf("warm activity view made %d S3 requests, want 0", after-before) |
| + } |
| +} |
| + |
| +// pipelineKeyRequests counts the S3 requests that name the app's pipeline |
| +// key, and fails them with a 500 while failing is set. (The SDK retries a |
| +// 500, so failing one request alone would not fail the read.) |
| +type pipelineKeyRequests struct { |
| + mu sync.Mutex |
| + n int |
| + failing bool |
| +} |
| + |
| +func watchPipelineKey(lat *perfLatency, key string) *pipelineKeyRequests { |
| + p := &pipelineKeyRequests{} |
| + lat.Fake().OnRequest(func(r *http.Request) (int, <-chan struct{}) { |
| + if !strings.HasSuffix(r.URL.Path, key) { |
| + return 0, nil |
| + } |
| + p.mu.Lock() |
| + defer p.mu.Unlock() |
| + p.n++ |
| + if p.failing { |
| + return http.StatusInternalServerError, nil |
| + } |
| + return 0, nil |
| + }) |
| + return p |
| +} |
| + |
| +func (p *pipelineKeyRequests) count() int { |
| + p.mu.Lock() |
| + defer p.mu.Unlock() |
| + return p.n |
| +} |
| + |
| +func (p *pipelineKeyRequests) fail(on bool) { |
| + p.mu.Lock() |
| + p.failing = on |
| + p.mu.Unlock() |
| +} |
| + |
| +// TestOverviewReadsPipelineOnce: with a pending change on the card, a cold |
| +// Overview reads the pipeline once, for the frame and the card together. |
| +func TestOverviewReadsPipelineOnce(t *testing.T) { |
| + fx, lat := newPerfFixture(t) |
| + c := signInPaul(t, fx) |
| + reqs := watchPipelineKey(lat, release.PipelineKey(fx.sqid, "kass")) |
| + status, _, body := get(t, c, fx.u("/apps/kass")) |
| + if status != http.StatusOK { |
| + t.Fatalf("overview = %d:\n%s", status, body) |
| + } |
| + if !strings.Contains(body, "Pending changes") || !strings.Contains(body, "promote v1 to beta") { |
| + t.Fatalf("the seeded pending change is not on the Overview:\n%s", body) |
| + } |
| + if got := reqs.count(); got != 1 { |
| + t.Fatalf("a cold Overview requested the pipeline %d times, want 1", got) |
| + } |
| +} |
| + |
| +// TestAppFrameErrorNotCached: a pipeline read that fails is not cached; the |
| +// next view reads it again and shows it. |
| +func TestAppFrameErrorNotCached(t *testing.T) { |
| + fx, lat := newPerfFixture(t) |
| + c := signInPaul(t, fx) |
| + reqs := watchPipelineKey(lat, release.PipelineKey(fx.sqid, "kass")) |
| + reqs.fail(true) |
| + status, _, body := get(t, c, fx.u("/apps/kass/settings/pipeline")) |
| + if status != http.StatusOK { |
| + t.Fatalf("pipeline settings = %d:\n%s", status, body) |
| + } |
| + if !strings.Contains(body, "Could not read the pipeline") { |
| + t.Fatalf("the failed pipeline read did not reach the page:\n%s", body) |
| + } |
| + reqs.fail(false) |
| + failed := reqs.count() |
| + status, _, body = get(t, c, fx.u("/apps/kass/settings/pipeline")) |
| + if status != http.StatusOK { |
| + t.Fatalf("pipeline settings = %d:\n%s", status, body) |
| + } |
| + if got := reqs.count() - failed; got != 1 { |
| + t.Fatalf("the view after a failed read requested the pipeline %d times, want 1", got) |
| + } |
| + if strings.Contains(body, "Could not read the pipeline") || !strings.Contains(body, `value="beta"`) { |
| + t.Fatalf("the second view did not show the pipeline:\n%s", body) |
| + } |
| +} |
| + |
| +// channelsTableVersion is the version the Releases page's Channels table |
| +// shows for channel, "" when the table has no row for it. |
| +func channelsTableVersion(body, channel string) string { |
| + _, table, ok := strings.Cut(body, "<h2>Channels</h2>") |
| + if !ok { |
| + return "" |
| + } |
| + m := regexp.MustCompile(`<td>` + regexp.QuoteMeta(channel) + `</td>\s*<td><code>([^<]*)</code></td>`).FindStringSubmatch(table) |
| + if m == nil { |
| + return "" |
| + } |
| + return m[1] |
| +} |
| + |
| +// channelsTableRow is the Channels table's whole row for channel. |
| +func channelsTableRow(body, channel string) string { |
| + _, table, _ := strings.Cut(body, "<h2>Channels</h2>") |
| + _, row, ok := strings.Cut(table, "<td>"+channel+"</td>") |
| + if !ok { |
| + return "" |
| + } |
| + row, _, _ = strings.Cut(row, "</tr>") |
| + return row |
| +} |
| + |
| +// TestAppFrameOwnWriteVisible: a person who changes what the frame holds |
| +// sees the change on the very next view, though that view's frame was warm |
| +// a moment before the write. |
| +func TestAppFrameOwnWriteVisible(t *testing.T) { |
| + for _, tc := range []struct { |
| + name string |
| + // setup runs before the frame is warmed (straight into the bucket). |
| + setup func(t *testing.T, fx *consoleFixture) |
| + // page is the view that shows the change. |
| + page string |
| + path string |
| + form url.Values |
| + // landed checks the write reached the bucket. |
| + landed func(t *testing.T, fx *consoleFixture) |
| + // shows reports whether page's body shows the new value. |
| + shows func(body string) bool |
| + }{ |
| + { |
| + name: "promote", page: "/apps/kass/releases", path: "/apps/kass/promote", |
| + form: url.Values{"channel": {"stable"}, "version": {"v2"}, "confirmed": {"1"}}, |
| + landed: func(t *testing.T, fx *consoleFixture) { wantChannel(t, fx, "stable", "v2") }, |
| + shows: func(body string) bool { return channelsTableVersion(body, "stable") == "v2" }, |
| + }, |
| + { |
| + name: "rollback", |
| + setup: func(t *testing.T, fx *consoleFixture) { |
| + seedChannel(t, fx, "kass", "beta", "v1") |
| + seedChannel(t, fx, "kass", "beta", "v2") |
| + }, |
| + page: "/apps/kass/releases", path: "/apps/kass/rollback", |
| + form: url.Values{"channel": {"beta"}, "confirmed": {"1"}}, |
| + landed: func(t *testing.T, fx *consoleFixture) { wantChannel(t, fx, "beta", "v1") }, |
| + shows: func(body string) bool { return channelsTableVersion(body, "beta") == "v1" }, |
| + }, |
| + { |
| + name: "production switch", |
| + // The safety-delay line is the legacy ladder's: no pipeline. |
| + setup: func(t *testing.T, fx *consoleFixture) { deleteKey(t, fx, release.PipelineKey(fx.sqid, "kass")) }, |
| + page: "/apps/kass", path: "/apps/kass/production", |
| + form: url.Values{"production": {"on"}}, |
| + landed: func(t *testing.T, fx *consoleFixture) { |
| + if f := productionFlag(t, fx, "kass"); f == nil || !f.Production { |
| + t.Fatalf("production flag = %+v, want on", f) |
| + } |
| + }, |
| + shows: func(body string) bool { return strings.Contains(body, "Safety delay: <strong>on</strong>") }, |
| + }, |
| + { |
| + name: "fasttrack", page: "/apps/kass/releases", path: "/apps/kass/fasttrack", |
| + setup: func(t *testing.T, fx *consoleFixture) { deleteKey(t, fx, release.PipelineKey(fx.sqid, "kass")) }, |
| + form: url.Values{"channel": {"stable"}, "confirmed": {"1"}}, |
| + landed: func(t *testing.T, fx *consoleFixture) { |
| + if p := fx.channelVersion(t, "kass", "stable"); !p.FastTrack { |
| + t.Fatalf("stable = %+v, want fast_track set", p) |
| + } |
| + }, |
| + shows: func(body string) bool { return strings.Contains(channelsTableRow(body, "stable"), "delay skipped") }, |
| + }, |
| + { |
| + name: "new canary", page: "/apps/kass/releases", path: "/apps/kass/canary", |
| + form: url.Values{"name": {"rc"}, "version": {"v1"}}, |
| + landed: func(t *testing.T, fx *consoleFixture) { wantChannel(t, fx, "canary/rc", "v1") }, |
| + shows: func(body string) bool { return channelsTableVersion(body, "canary/rc") == "v1" }, |
| + }, |
| + { |
| + name: "canary retire", |
| + // The retire waits for an app whose records have been still |
| + // for channelSettle; the walk's records were just written. |
| + setup: func(t *testing.T, fx *consoleFixture) { ageAppRecords(t, fx, "kass") }, |
| + page: "/apps/kass/releases", path: "/apps/kass/canary/retire", |
| + form: url.Values{"name": {"x"}, "confirmed": {"1"}}, |
| + landed: func(t *testing.T, fx *consoleFixture) { |
| + if _, err := release.Channel(context.Background(), fx.rel, fx.pub, fx.sqid, "kass", "canary/x"); !errors.Is(err, os.ErrNotExist) { |
| + t.Fatalf("canary/x = %v after the retire, want it gone", err) |
| + } |
| + }, |
| + shows: func(body string) bool { return channelsTableRow(body, "canary/x") == "" }, |
| + }, |
| + { |
| + name: "pipeline settings save", page: "/apps/kass/settings/pipeline", path: "/apps/kass/pipeline", |
| + form: url.Values{"ch.0.name": {"edge"}, "ch.1.name": {"beta"}, "ch.2.name": {"stable"}}, |
| + landed: func(t *testing.T, fx *consoleFixture) { |
| + p, err := release.GetPipeline(context.Background(), fx.rel, fx.pub, fx.sqid, "kass") |
| + if err != nil || p == nil || len(p.Channels) != 3 || p.Channels[0].Name != "edge" { |
| + t.Fatalf("pipeline = %+v, %v; want edge, beta, stable", p, err) |
| + } |
| + }, |
| + shows: func(body string) bool { return strings.Contains(body, `value="edge"`) }, |
| + }, |
| + } { |
| + t.Run(tc.name, func(t *testing.T) { |
| + fx, lat := newPerfFixture(t) |
| + c := signInPaul(t, fx) |
| + if tc.setup != nil { |
| + tc.setup(t, fx) |
| + } |
| + // Warm the frame, and prove it is warm: the second view of |
| + // the page reads none of the frame's keys. |
| + stop := func() {} |
| + for i := range 2 { |
| + status, _, body := get(t, c, fx.u(tc.page)) |
| + if status != http.StatusOK { |
| + t.Fatalf("GET %s = %d:\n%s", tc.page, status, body) |
| + } |
| + if tc.shows(body) { |
| + t.Fatalf("GET %s shows the change before the write", tc.page) |
| + } |
| + if i == 0 { |
| + stop = watchFrameKeys(t, lat, fx.sqid, "kass") |
| + } |
| + } |
| + stop() |
| + form := url.Values{"csrf": {sessionToken(t, fx, c)}} |
| + for k, v := range tc.form { |
| + form[k] = v |
| + } |
| + status, loc, body := postGated(t, fx, c, fx.u(tc.path), form) |
| + if status != http.StatusSeeOther { |
| + t.Fatalf("POST %s = %d -> %q:\n%s", tc.path, status, loc, body) |
| + } |
| + tc.landed(t, fx) |
| + status, _, body = get(t, c, fx.u(tc.page)) |
| + if status != http.StatusOK { |
| + t.Fatalf("GET %s after the write = %d:\n%s", tc.page, status, body) |
| + } |
| + if !tc.shows(body) { |
| + t.Fatalf("GET %s after the write does not show it:\n%s", tc.page, body) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// TestAppFrameCLIWriteVisible: a promote through the CLI's door shows on the |
| +// person's next browser view. |
| +func TestAppFrameCLIWriteVisible(t *testing.T) { |
| + fx, lat := newPerfFixture(t) |
| + token := cliToken(t, fx, "paul@keymail.dev", "code-frame-cli") |
| + c := signInPaul(t, fx) |
| + stop := func() {} |
| + for i := range 2 { |
| + status, _, body := get(t, c, fx.u("/apps/kass/releases")) |
| + if status != http.StatusOK || channelsTableVersion(body, "canary/x") != "v2" { |
| + t.Fatalf("releases = %d, canary/x %q; want 200 and v2:\n%s", status, channelsTableVersion(body, "canary/x"), body) |
| + } |
| + if i == 0 { |
| + stop = watchFrameKeys(t, lat, fx.sqid, "kass") |
| + } |
| + } |
| + stop() |
| + status, out := postJSON(t, fx.ts.URL+"/api/cli/apps/"+fx.sqid+"/kass/promote", |
| + map[string]string{"version": "v1", "channel": "canary/x"}, token) |
| + if status != http.StatusOK { |
| + t.Fatalf("CLI promote = %d %v", status, out) |
| + } |
| + wantChannel(t, fx, "canary/x", "v1") |
| + _, _, body := get(t, c, fx.u("/apps/kass/releases")) |
| + if got := channelsTableVersion(body, "canary/x"); got != "v1" { |
| + t.Fatalf("releases after a CLI promote shows canary/x at %q, want v1:\n%s", got, body) |
| + } |
| +} |
| + |
| +func wantChannel(t *testing.T, fx *consoleFixture, channel, version string) { |
| + t.Helper() |
| + if p := fx.channelVersion(t, "kass", channel); p.Version != version { |
| + t.Fatalf("%s = %s, want %s", channel, p.Version, version) |
| + } |
| +} |
| + |
| +func deleteKey(t *testing.T, fx *consoleFixture, key string) { |
| + t.Helper() |
| + if err := fx.rel.Delete(context.Background(), key); err != nil { |
| + t.Fatal(err) |
| + } |
| +} |
| + |
| +// watchFrameKeys fails the test if any request names one of the frame's |
| +// keys until the returned stop is called: the proof that a view was served |
| +// from a warm frame. |
| +func watchFrameKeys(t *testing.T, lat *perfLatency, acct, app string) (stop func()) { |
| + t.Helper() |
| + var mu sync.Mutex |
| + armed := true |
| + keys := []string{release.ChannelsPrefix(acct, app), release.ProductionKey(acct, app), release.PipelineKey(acct, app)} |
| + lat.Fake().OnRequest(func(r *http.Request) (int, <-chan struct{}) { |
| + mu.Lock() |
| + defer mu.Unlock() |
| + if !armed { |
| + return 0, nil |
| + } |
| + where := r.URL.Path + "?" + r.URL.RawQuery |
| + for _, k := range keys { |
| + if strings.Contains(where, k) || strings.Contains(where, url.QueryEscape(k)) { |
| + t.Errorf("a warm view requested %s", where) |
| + } |
| + } |
| + return 0, nil |
| + }) |
| + return func() { |
| + mu.Lock() |
| + armed = false |
| + mu.Unlock() |
| + } |
| +} |
| + |
| +// ageAppRecords backdates the app's instance and sidecar record files past |
| +// channelSettle. |
| +func ageAppRecords(t *testing.T, fx *consoleFixture, app string) { |
| + t.Helper() |
| + old := time.Now().Add(-2 * channelSettle) |
| + for _, prefix := range []string{provision.RecordsPrefix(fx.sqid, app), provision.SidecarsPrefix(fx.sqid, app)} { |
| + dir := filepath.Join(fx.rel.(*deletableStore).root, filepath.FromSlash(prefix)) |
| + err := filepath.WalkDir(dir, func(path string, d fs.DirEntry, err error) error { |
| + if err != nil { |
| + return err |
| + } |
| + return os.Chtimes(path, old, old) |
| + }) |
| + if err != nil && !errors.Is(err, fs.ErrNotExist) { |
| + t.Fatal(err) |
| + } |
| + } |
| +} |
| + |
| +// TestAppFrameGetDuringWrite: a view whose frame load began before a |
| +// promote, and whose reads come back after it, must not leave the old |
| +// frame in the cache. The view's read of the stable pointer is held at the |
| +// fake until the promote has returned. |
| +func TestAppFrameGetDuringWrite(t *testing.T) { |
| + fx, lat := newPerfFixture(t) |
| + c := signInPaul(t, fx) |
| + csrf := sessionToken(t, fx, c) |
| + stableKey := release.ChannelsPrefix(fx.sqid, "kass") + "stable.json" |
| + var mu sync.Mutex |
| + armed := true |
| + reached, hold := make(chan struct{}), make(chan struct{}) |
| + lat.Fake().OnRequest(func(r *http.Request) (int, <-chan struct{}) { |
| + mu.Lock() |
| + defer mu.Unlock() |
| + if armed && r.Method == http.MethodGet && strings.HasSuffix(r.URL.Path, stableKey) { |
| + armed = false |
| + close(reached) |
| + return 0, hold |
| + } |
| + return 0, nil |
| + }) |
| + viewed := make(chan string) |
| + go func() { |
| + res, err := c.Get(fx.u("/apps/kass/releases")) |
| + if err != nil { |
| + viewed <- "error: " + err.Error() |
| + return |
| + } |
| + defer res.Body.Close() |
| + b, _ := io.ReadAll(res.Body) |
| + viewed <- string(b) |
| + }() |
| + <-reached |
| + status, loc, body := postForm(t, c, fx.u("/apps/kass/promote"), |
| + url.Values{"csrf": {csrf}, "channel": {"stable"}, "version": {"v2"}, "confirmed": {"1"}}) |
| + if status != http.StatusSeeOther { |
| + t.Fatalf("promote = %d -> %q:\n%s", status, loc, body) |
| + } |
| + wantChannel(t, fx, "stable", "v2") |
| + close(hold) |
| + if got := channelsTableVersion(<-viewed, "stable"); got != "v1" { |
| + t.Fatalf("the view that began before the promote shows stable at %q, want v1 (its own reads)", got) |
| + } |
| + _, _, body = get(t, c, fx.u("/apps/kass/releases")) |
| + if got := channelsTableVersion(body, "stable"); got != "v2" { |
| + t.Fatalf("the next view shows stable at %q, want v2: the in-flight view stored its old frame", got) |
| + } |
| +} |
| + |
| +// cached reports whether acct/app has an entry, fresh or not. |
| +func (c *appFrames) cached(acct, app string) bool { |
| + c.mu.Lock() |
| + defer c.mu.Unlock() |
| + _, ok := c.m[frameKey{acct, app}] |
| + return ok |
| +} |
| + |
| +// TestAppFrameWriteHookClears: registerRoute's hook clears the app (or the |
| +// account) a write door names before the first byte of its response, leaves |
| +// GET and HEAD alone, and is a no-op for a pattern that names neither. |
| +func TestAppFrameWriteHookClears(t *testing.T) { |
| + warm := func(s *Server) { |
| + for _, k := range [][2]string{{"bab", "kass"}, {"bab", "shop"}, {"other", "kass"}} { |
| + s.frames.get(context.Background(), k[0], k[1], func(context.Context) appFrame { return testFrame("v1") }) |
| + } |
| + } |
| + for _, tc := range []struct { |
| + pattern, method, path string |
| + gone, kept [][2]string |
| + }{ |
| + {"POST /a/{sqid}/apps/{app}/promote", "POST", "/a/bab/apps/kass/promote", |
| + [][2]string{{"bab", "kass"}, {"other", "kass"}}, [][2]string{{"bab", "shop"}}}, |
| + {"POST /api/cli/apps/{account}/{app}/promote", "POST", "/api/cli/apps/bab/kass/promote", |
| + [][2]string{{"bab", "kass"}, {"other", "kass"}}, [][2]string{{"bab", "shop"}}}, |
| + {"POST /a/{sqid}/trash/restore", "POST", "/a/bab/trash/restore", |
| + [][2]string{{"bab", "kass"}, {"bab", "shop"}}, [][2]string{{"other", "kass"}}}, |
| + {"POST /api/cli/apps/{account}/new", "POST", "/api/cli/apps/bab/new", |
| + [][2]string{{"bab", "kass"}, {"bab", "shop"}}, [][2]string{{"other", "kass"}}}, |
| + {"POST /auth/signout", "POST", "/auth/signout", |
| + nil, [][2]string{{"bab", "kass"}, {"bab", "shop"}, {"other", "kass"}}}, |
| + {"GET /a/{sqid}/apps/{app}", "GET", "/a/bab/apps/kass", |
| + nil, [][2]string{{"bab", "kass"}, {"bab", "shop"}, {"other", "kass"}}}, |
| + {"GET /a/{sqid}/apps/{app}", "HEAD", "/a/bab/apps/kass", |
| + nil, [][2]string{{"bab", "kass"}, {"bab", "shop"}, {"other", "kass"}}}, |
| + {"/a/{sqid}/apps/{app}/anything", "GET", "/a/bab/apps/kass/anything", |
| + nil, [][2]string{{"bab", "kass"}, {"bab", "shop"}, {"other", "kass"}}}, |
| + {"/a/{sqid}/apps/{app}/anything", "POST", "/a/bab/apps/kass/anything", |
| + [][2]string{{"bab", "kass"}, {"other", "kass"}}, [][2]string{{"bab", "shop"}}}, |
| + } { |
| + t.Run(tc.method+" "+tc.pattern, func(t *testing.T) { |
| + s := &Server{} |
| + warm(s) |
| + mux := http.NewServeMux() |
| + var beforeWrite, bypass bool |
| + mux.HandleFunc(tc.pattern, s.withFrameClear(tc.pattern, func(w http.ResponseWriter, r *http.Request) { |
| + beforeWrite = s.frames.cached("bab", "kass") |
| + bypass = r.Context().Value(frameBypassKey{}) != nil |
| + w.WriteHeader(http.StatusSeeOther) |
| + for _, k := range tc.gone { |
| + if s.frames.cached(k[0], k[1]) { |
| + t.Errorf("%s/%s still cached once the response started", k[0], k[1]) |
| + } |
| + } |
| + })) |
| + mux.ServeHTTP(httptest.NewRecorder(), httptest.NewRequest(tc.method, tc.path, nil)) |
| + if !beforeWrite { |
| + t.Error("the clear ran before the handler wrote anything; it belongs at the first write") |
| + } |
| + if want := !readOnlyMethod(tc.method); bypass != want { |
| + t.Errorf("the request bypasses the cache: %v, want %v (a write door never reads it)", bypass, want) |
| + } |
| + for _, k := range tc.kept { |
| + if !s.frames.cached(k[0], k[1]) { |
| + t.Errorf("%s/%s was cleared, want it kept", k[0], k[1]) |
| + } |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// TestAppFrameRenameClearsNewName: a rename clears the frame under the new |
| +// name too (the hook clears the old one). |
| +func TestAppFrameRenameClearsNewName(t *testing.T) { |
| + fx, _ := newPerfFixture(t) |
| + freshApp(t, fx, "sprout") |
| + c := signInPaul(t, fx) |
| + for _, app := range []string{"sprout", "sapling"} { |
| + fx.srv.frames.get(context.Background(), fx.sqid, app, func(context.Context) appFrame { return testFrame("stale") }) |
| + } |
| + status, loc, body := postForm(t, c, fx.u("/apps/sprout/rename"), |
| + url.Values{"csrf": {sessionToken(t, fx, c)}, "to": {"sapling"}, "confirmed": {"1"}}) |
| + if status != http.StatusSeeOther || loc != fx.path("/apps/sapling/settings") { |
| + t.Fatalf("rename = %d -> %q:\n%s", status, loc, body) |
| + } |
| + for _, app := range []string{"sprout", "sapling"} { |
| + if fx.srv.frames.cached(fx.sqid, app) { |
| + t.Errorf("%s's frame survived the rename", app) |
| + } |
| + } |
| +} |
diff --git a/internal/console/appsettings.go b/internal/console/appsettings.go| index a6600341c..a80d1da93 100644 |
| --- a/internal/console/appsettings.go |
| +++ b/internal/console/appsettings.go |
| @@ -905,6 +905,9 @@ func (s *Server) handleAppRename(w http.ResponseWriter, r *http.Request) { |
| back("err", renameAdvice(err, to)) |
| return |
| } |
| + // registerRoute's hook clears the old name; the new one is cleared |
| + // here, before any response, so its first page is read fresh. |
| + s.frames.clearApp(to) |
| // The emptiness checks above cannot join the database transaction — the |
| // bucket and the registry are other stores — so a `carlos ship` or |
| // `carlos add` racing this request can land under the old name between |
diff --git a/internal/console/appsettings_test.go b/internal/console/appsettings_test.go| index b8f44ebcb..ac9a97a7a 100644 |
| --- a/internal/console/appsettings_test.go |
| +++ b/internal/console/appsettings_test.go |
| @@ -422,6 +422,7 @@ func TestAppDeleteRefusesAProductionApp(t *testing.T) { |
| release.OpsAccount, "kass", true, "test"); err != nil { |
| t.Fatal(err) |
| } |
| + fx.forgetFrame("kass") |
| c := signInPaul(t, fx) |
| csrf := sessionToken(t, fx, c) |
diff --git a/internal/console/bakecontrols_test.go b/internal/console/bakecontrols_test.go| index e86a9b363..e8f5ea22f 100644 |
| --- a/internal/console/bakecontrols_test.go |
| +++ b/internal/console/bakecontrols_test.go |
| @@ -98,6 +98,7 @@ func TestProductionOffIsOwnerPasskeyGated(t *testing.T) { |
| release.OpsAccount, "kass", true, "test"); err != nil { |
| t.Fatal(err) |
| } |
| + fx.forgetFrame("kass") |
| // Without the passkey the flag does not move. |
| status, loc, _ := postForm(t, c, fx.u("/apps/kass/production"), |
| @@ -128,6 +129,7 @@ func TestProductionOffMemberGets404(t *testing.T) { |
| release.OpsAccount, "kass", true, "test"); err != nil { |
| t.Fatal(err) |
| } |
| + fx.forgetFrame("kass") |
| if err := fx.st.AddMember(OpsAccountID, "sam@keymail.dev", RoleMember, time.Now()); err != nil { |
| t.Fatal(err) |
| } |
| @@ -296,6 +298,7 @@ func TestPromoteEnableBakeSaysWhenItCouldNotRead(t *testing.T) { |
| release.ProductionKey(release.OpsAccount, "kass"), []byte("{not a wrapper"), ""); err != nil { |
| t.Fatal(err) |
| } |
| + fx.forgetFrame("kass") |
| postGated(t, fx, c, fx.u("/apps/kass/promote"), |
| url.Values{"csrf": {csrf}, "channel": {"stable"}, "version": {"v3"}, "enable_bake": {"1"}, "confirmed": {"1"}}) |
| @@ -342,6 +345,7 @@ func TestPromoteBakeNoteFollowsTheFlag(t *testing.T) { |
| release.OpsAccount, "kass", true, "test"); err != nil { |
| t.Fatal(err) |
| } |
| + fx.forgetFrame("kass") |
| shipVersion(t, fx, "kass", "v4") |
| seedChannel(t, fx, "kass", "edge", "v4") |
| if status, _, body := postForm(t, c, fx.u("/apps/kass/promote"), |
diff --git a/internal/console/claim_routes.go b/internal/console/claim_routes.go| index 10107da69..78a0a3359 100644 |
| --- a/internal/console/claim_routes.go |
| +++ b/internal/console/claim_routes.go |
| @@ -56,9 +56,15 @@ func claimHandlerName(h any) string { |
| // registerRoute preserves each handler's existing authorization order. It adds |
| // provenance for the effect-boundary audit; provenance does not grant a permit. |
| +// |
| +// Every non-GET request also clears the app-tab frame cache for the app (or |
| +// account) its pattern names, before its first response byte and again on |
| +// return (withFrameClear, appframe.go). The clear is the only thing it adds |
| +// ahead of the handler's own gates, and it changes no response. |
| func (s *Server) registerRoute(pattern string, h http.HandlerFunc) { |
| e := claimEntry{Kind: "route", Pattern: pattern, Handler: claimHandlerName(h)} |
| s.claimEntries.add(e) |
| + h = s.withFrameClear(pattern, h) |
| if !s.cfg.HostClaim { |
| s.mux.HandleFunc(pattern, h) |
| return |
diff --git a/internal/console/deletion_test.go b/internal/console/deletion_test.go| index f96d3d1e8..3f4c043e3 100644 |
| --- a/internal/console/deletion_test.go |
| +++ b/internal/console/deletion_test.go |
| @@ -461,6 +461,7 @@ func TestDeleteNowRefusesAProductionApp(t *testing.T) { |
| if err := release.SetProduction(ctx, fx.rel, fx.priv, release.OpsAccount, "kass", true, "test"); err != nil { |
| t.Fatal(err) |
| } |
| + fx.forgetFrame("kass") |
| c := newBrowser(t) |
| signUp(t, fx, c, "code-trash-prod") |
| trashKass(t, fx, "paul@keymail.dev", time.Now()) |
| @@ -745,6 +746,7 @@ func TestPurgeRefusesAProductionAppBeforeTouchingItsStore(t *testing.T) { |
| if err := release.SetProduction(ctx, fx.rel, fx.priv, release.OpsAccount, "kass", true, "test"); err != nil { |
| t.Fatal(err) |
| } |
| + fx.forgetFrame("kass") |
| c := newBrowser(t) |
| signUp(t, fx, c, "code-purge-prod-store") |
| trashKass(t, fx, "paul@keymail.dev", time.Now()) |
diff --git a/internal/console/deployscope_test.go b/internal/console/deployscope_test.go| index c05fef515..3e8341877 100644 |
| --- a/internal/console/deployscope_test.go |
| +++ b/internal/console/deployscope_test.go |
| @@ -119,6 +119,7 @@ func TestDeployScopeRefusalsAtTheDoors(t *testing.T) { |
| []release.PipelineChannel{{Name: "edge"}, {Name: "stable"}}, "paul@keymail.dev"); err != nil { |
| t.Fatal(err) |
| } |
| + fx.forgetFrame("hello") |
| for _, a := range []attempt{ |
| {"pipelined edge", map[string]any{"version": "v1", "channel": "edge"}, "edge", |
| "hello has a pipeline, so deploy credential ci may move canary/<name> channels only."}, |
diff --git a/internal/console/ladder_test.go b/internal/console/ladder_test.go| index de333e509..9fd971154 100644 |
| --- a/internal/console/ladder_test.go |
| +++ b/internal/console/ladder_test.go |
| @@ -39,15 +39,23 @@ func shipVersion(t *testing.T, fx *consoleFixture, app, version string) { |
| // seedChannel points a channel at a version through the UNCHECKED primitive. |
| // That is deliberate: these are arrangements of the world the console then has |
| -// to read and gate, not promotions under test. |
| +// to read and gate, not promotions under test. Like every write straight into |
| +// the bucket, it then forgets the app's frame (forgetFrame). |
| func seedChannel(t *testing.T, fx *consoleFixture, app, channel, version string, rec ...release.Promotion) { |
| t.Helper() |
| if err := release.Promote(context.Background(), fx.rel, fx.priv, |
| release.OpsAccount, app, channel, version, rec...); err != nil { |
| t.Fatal(err) |
| } |
| + fx.forgetFrame(app) |
| } |
| +// forgetFrame drops app's app-tab frame (appframe.go). A test that writes a |
| +// channel, the production flag or the pipeline straight into the bucket is a |
| +// writer outside the console, which a running console sees within |
| +// appFrameTTL; this stands for that wait. |
| +func (fx *consoleFixture) forgetFrame(app string) { fx.srv.frames.clearApp(app) } |
| + |
| // rungBlock cuts one rung's markup out of the rendered page, so "the beta rung |
| // shows v4" is an assertion about the beta rung and not about the page |
| // containing "v4" somewhere. |
| @@ -596,6 +604,7 @@ func seedExpiredCanary(t *testing.T, fx *consoleFixture, app, channel, version s |
| release.ChannelKey(release.OpsAccount, app, channel), wrapper, ""); err != nil { |
| t.Fatal(err) |
| } |
| + fx.forgetFrame(app) |
| } |
| // TestLadderPromotesOntoAnExpiredCanary pins spec §5's visibility-only |
| @@ -656,6 +665,7 @@ func TestLadderShowsBakeStateAndControls(t *testing.T) { |
| release.OpsAccount, "kass", true, "test"); err != nil { |
| t.Fatal(err) |
| } |
| + fx.forgetFrame("kass") |
| _, _, body = get(t, c, fx.u("/apps/kass/releases")) |
| if !strings.Contains(body, `action="/a/bab/apps/kass/fasttrack"`) { |
| t.Fatalf("no fast-track control on a held head:\n%s", rungBlock(t, body, "beta")) |
| @@ -729,6 +739,7 @@ func TestLadderBakeControlsMemberView(t *testing.T) { |
| release.OpsAccount, "kass", true, "test"); err != nil { |
| t.Fatal(err) |
| } |
| + fx.forgetFrame("kass") |
| _, _, obody := get(t, c, fx.u("/apps/kass/releases")) |
| if !strings.Contains(obody, `name="production" value="off"`) { |
| t.Fatal("owner is not offered the turn-off control once bake is eligible — the member-only checks below would be vacuous") |
| @@ -759,6 +770,7 @@ func TestLadderUnreadableFlagOffersRepair(t *testing.T) { |
| release.ProductionKey(release.OpsAccount, "kass"), []byte("{not a wrapper"), ""); err != nil { |
| t.Fatal(err) |
| } |
| + fx.forgetFrame("kass") |
| _, _, body := get(t, c, fx.u("/apps/kass/releases")) |
| if !strings.Contains(body, "Safety delay: this app's setting can't be read right now, so the delay stays on.") { |
| t.Fatalf("no error line for an unverifiable flag:\n%s", body) |
| @@ -800,9 +812,11 @@ func TestLadderTurningOffOffersTurnBackOn(t *testing.T) { |
| if err := release.SetProduction(ctx, fx.rel, fx.priv, release.OpsAccount, "kass", true, "test"); err != nil { |
| t.Fatal(err) |
| } |
| + fx.forgetFrame("kass") |
| if err := release.SetProduction(ctx, fx.rel, fx.priv, release.OpsAccount, "kass", false, "test"); err != nil { |
| t.Fatal(err) |
| } |
| + fx.forgetFrame("kass") |
| _, _, body := get(t, c, fx.u("/apps/kass/releases")) |
| if !strings.Contains(body, "turning off") { |
| t.Fatalf("a fresh off-flag on a held app does not say hosts are still ratcheting:\n%s", body) |
| @@ -834,6 +848,7 @@ func TestLadderNudgesProdWiredBakeOff(t *testing.T) { |
| release.OpsAccount, "kass", true, "test"); err != nil { |
| t.Fatal(err) |
| } |
| + fx.forgetFrame("kass") |
| if _, _, body := get(t, c, fx.u("/apps/kass/releases")); strings.Contains(body, "new versions go live immediately") { |
| t.Fatal("the nudge survived the flag turning on") |
| } |
diff --git a/internal/console/pendingflow_test.go b/internal/console/pendingflow_test.go| index 257d9a5ae..2fd8a522a 100644 |
| --- a/internal/console/pendingflow_test.go |
| +++ b/internal/console/pendingflow_test.go |
| @@ -37,6 +37,7 @@ func setPipeline(t *testing.T, fx *consoleFixture, app string, channels ...relea |
| if err != nil { |
| t.Fatal(err) |
| } |
| + fx.forgetFrame(app) |
| return p |
| } |
diff --git a/internal/console/pipelinepage.go b/internal/console/pipelinepage.go| index 75e828d61..295284fad 100644 |
| --- a/internal/console/pipelinepage.go |
| +++ b/internal/console/pipelinepage.go |
| @@ -217,15 +217,12 @@ func (s *Server) writePipeline(ctx context.Context, acct *Account, app string, c |
| // same as the rest of the app's settings tab. |
| func (s *Server) handlePipelineSettingsPage(w http.ResponseWriter, r *http.Request, p page, acct *Account) { |
| setAppSettingsSection(&p, "pipeline") |
| - ctx, cancel := context.WithTimeout(r.Context(), pipelineStoreTimeout) |
| - defer cancel() |
| - pipe, err := release.GetPipeline(ctx, s.cfg.Releases, s.cfg.ReleasePub, acct.Sqid, p.AppName) |
| channels := release.DefaultPipelineChannels() |
| - if err != nil { |
| - log.Printf("console: pipeline settings %s/%s: %v", acct.Sqid, p.AppName, err) |
| + if p.Detail.PipelineErr != "" { |
| + log.Printf("console: pipeline settings %s/%s: %s", acct.Sqid, p.AppName, p.Detail.PipelineErr) |
| p.FlashErr = "Could not read the pipeline — showing the default. Try again to see the real one." |
| - } else if pipe != nil { |
| - channels = pipe.Channels |
| + } else if p.Detail.Pipeline != nil { |
| + channels = p.Detail.Pipeline.Channels |
| } |
| p.PipelineRows = pipelineRowsFromChannels(channels) |
| p.PipelineIsDefault = pipelineIsDefault(p.PipelineRows) |
diff --git a/internal/console/remoteinstances.go b/internal/console/remoteinstances.go| index f3cfcc612..39cb84cfa 100644 |
| --- a/internal/console/remoteinstances.go |
| +++ b/internal/console/remoteinstances.go |
| @@ -527,9 +527,12 @@ func (s *Server) remoteSource(ctx context.Context, acct string) *remoteRows { |
| } |
| // assembleApps is Assemble for a page view: the console box's registry rows |
| -// plus the account's instances on other boxes. |
| +// plus the account's instances on other boxes, each app's release-store |
| +// reads from the frame cache (appframe.go). |
| func (s *Server) assembleApps(ctx context.Context, acct string, apps []string) ([]AppView, error) { |
| - return Assemble(ctx, s.cfg.Registry, s.cfg.Releases, s.cfg.ReleasePub, acct, apps, s.dnsTargets(ctx), s.remoteSource(ctx, acct)) |
| + return assembleViews(ctx, s.cfg.Registry, acct, apps, s.dnsTargets(ctx), s.remoteSource(ctx, acct), func(app string) appFrame { |
| + return s.appFrame(ctx, acct, app) |
| + }) |
| } |
| // errRetireUnsettled is channelHosts' answer when no record names the |
diff --git a/internal/console/remoteinstances_round4_test.go b/internal/console/remoteinstances_round4_test.go| index c0470a852..54e5f27ac 100644 |
| --- a/internal/console/remoteinstances_round4_test.go |
| +++ b/internal/console/remoteinstances_round4_test.go |
| @@ -264,6 +264,7 @@ func TestRetireDoesNotResurrectRemovedPointer(t *testing.T) { |
| if err := tb.fx.rel.Delete(context.Background(), release.ChannelKey(tb.sqid, "shop", "canary/rc")); err != nil { |
| t.Error(err) |
| } |
| + tb.fx.forgetFrame("shop") |
| } |
| if page := retireRC(t, tb); !strings.Contains(page, notSettled) { |
| t.Fatalf("retire with the pointer removed during the check:\n%s", page) |
diff --git a/internal/console/remoteinstances_test.go b/internal/console/remoteinstances_test.go| index 20059a62c..869042341 100644 |
| --- a/internal/console/remoteinstances_test.go |
| +++ b/internal/console/remoteinstances_test.go |
| @@ -101,6 +101,7 @@ func shipAndPromote(t *testing.T, fx *consoleFixture, sqid, app, version, channe |
| if err := release.Promote(ctx, fx.rel, fx.priv, sqid, app, channel, version); err != nil { |
| t.Fatal(err) |
| } |
| + fx.forgetFrame(app) |
| } |
| // create runs the console's create door for host in region. |
diff --git a/internal/console/rolloutjoin_test.go b/internal/console/rolloutjoin_test.go| index c77285386..45c1bf5e7 100644 |
| --- a/internal/console/rolloutjoin_test.go |
| +++ b/internal/console/rolloutjoin_test.go |
| @@ -108,6 +108,7 @@ func TestAPIPromoteHeldSaysWhenItLifts(t *testing.T) { |
| if err := release.SetProduction(context.Background(), fx.rel, fx.priv, release.OpsAccount, "titogo", true, "test"); err != nil { |
| t.Fatal(err) |
| } |
| + fx.forgetFrame("titogo") |
| token := cliToken(t, fx, "paul@keymail.dev", "code-held-until") |
| before := time.Now() |
| code, body := postRaw(t, fx.ts.URL+"/api/cli/apps/bab/titogo/promote", |
diff --git a/internal/console/serialbump_test.go b/internal/console/serialbump_test.go| index a12eb61ab..106fafaef 100644 |
| --- a/internal/console/serialbump_test.go |
| +++ b/internal/console/serialbump_test.go |
| @@ -126,6 +126,7 @@ func TestAPIPromoteHeldOnProductionBeta(t *testing.T) { |
| release.OpsAccount, "titogo", true, "test"); err != nil { |
| t.Fatal(err) |
| } |
| + fx.forgetFrame("titogo") |
| token := cliToken(t, fx, "paul@keymail.dev", "code-serial-held") |
| status, body := postRaw(t, fx.ts.URL+"/api/cli/apps/bab/titogo/promote", |
| @@ -169,6 +170,7 @@ func TestAPIPromoteNotHeldOffProduction(t *testing.T) { |
| release.OpsAccount, "titogo", true, "test"); err != nil { |
| t.Fatal(err) |
| } |
| + fx.forgetFrame("titogo") |
| status, body = postRaw(t, fx.ts.URL+"/api/cli/apps/bab/titogo/promote", |
| map[string]string{"version": "abc1234", "channel": "canary/x"}, token) |
| if status != http.StatusOK { |
| @@ -197,6 +199,7 @@ func TestAPIPromoteNoOpReportsHeld(t *testing.T) { |
| release.OpsAccount, "titogo", true, "test"); err != nil { |
| t.Fatal(err) |
| } |
| + fx.forgetFrame("titogo") |
| token := cliToken(t, fx, "paul@keymail.dev", "code-serial-noopheld") |
| // beta already carries this version: a no-op, and held. |
diff --git a/internal/console/server.go b/internal/console/server.go| index 925889c4f..588599841 100644 |
| --- a/internal/console/server.go |
| +++ b/internal/console/server.go |
| @@ -1222,6 +1222,8 @@ type Server struct { |
| // (applocks.go). Zero values are ready. |
| appLocks keyedLocks |
| acctLocks keyedLocks |
| + // frames is the app-tab frame cache (appframe.go). Zero value ready. |
| + frames appFrames |
| // hostLocks is withHostname's refcounted mutex per hostname |
| // (lifetimes.go), and lifetimeLogged the last time each hourly lifetime |
| // log line was written, pruned past two hours. Zero values are ready. |
| @@ -3662,7 +3664,7 @@ func (s *Server) appPage(w http.ResponseWriter, r *http.Request, tab string) (pa |
| p.Detail.RouteAccount = review.Groups[0].Account.Sqid |
| } |
| } |
| - s.applyPipelineView(r.Context(), p.Detail, acct) |
| + s.applyPipelineView(p.Detail, acct) |
| return p, acct, true |
| } |
| @@ -3690,14 +3692,12 @@ func hasPublishedChannel(channels []ChannelView) bool { |
| // disagree again by construction. Best-effort and view-only, like every |
| // other read in this family: an unreadable pipeline degrades the render to |
| // the legacy ladder rather than failing the page. |
| -func (s *Server) applyPipelineView(ctx context.Context, view *AppView, acct *Account) { |
| - ctx, cancel := context.WithTimeout(ctx, pipelineStoreTimeout) |
| - defer cancel() |
| - pipe, err := release.GetPipeline(ctx, s.cfg.Releases, s.cfg.ReleasePub, acct.Sqid, view.App) |
| - if err != nil { |
| - log.Printf("console: app page %s/%s: read pipeline: %v", acct.Sqid, view.App, err) |
| +func (s *Server) applyPipelineView(view *AppView, acct *Account) { |
| + if view.PipelineErr != "" { |
| + log.Printf("console: app page %s/%s: read pipeline: %s", acct.Sqid, view.App, view.PipelineErr) |
| return |
| } |
| + pipe := view.Pipeline |
| if pipe == nil { |
| return |
| } |
| @@ -3819,9 +3819,9 @@ func (s *Server) handleApp(w http.ResponseWriter, r *http.Request) { |
| if err != nil { |
| log.Printf("console: pending changes %s/%s: %v", acct.Sqid, app, err) |
| } else if len(pcs) > 0 { |
| - // One pipeline read for the whole card: the rows show the quorum |
| + // The frame's pipeline for the whole card: the rows show the quorum |
| // EXECUTION will require, not the one they were proposed under. |
| - p.Pending = s.pendingChangeViews(pcs, s.pendingPipeline(r.Context(), acct, app)) |
| + p.Pending = s.pendingChangeViews(pcs, p.Detail.Pipeline) |
| } |
| s.render(w, http.StatusOK, "app_overview", p) |
| } |
| @@ -3838,9 +3838,10 @@ const overviewActivityCap = 5 |
| // Its data, in one place for perf plan 2's cache. From appPage's p.Detail: |
| // Channels (Live now targets, What's next, the Channels fold, promote |
| // options), Routes (Live now's running versions and instance counts), |
| -// Pipeline and OneChannelPipeline (Live now's columns and rows, the folds), |
| -// Canaries (the Canaries fold) and Production (the ladder). Read here, per |
| -// request: PendingChangesForContext and pendingPipeline (the pending card), |
| +// Pipeline and OneChannelPipeline (Live now's columns and rows, the folds, |
| +// the pending card's quorum), Canaries (the Canaries fold) and Production |
| +// (the ladder). Read here, per request: PendingChangesForContext (the |
| +// pending card), |
| // versionsPage (Versions, and from the same listing page 1's names for the |
| // canary form, whatever ?page= is), release.ListTags (tag pills and the |
| // Tags fold), release.GetRetention (the retention line) and attachHint (the |
| @@ -3860,7 +3861,7 @@ func (s *Server) handleAppReleases(w http.ResponseWriter, r *http.Request) { |
| if err != nil { |
| log.Printf("console: pending changes %s/%s: %v", acct.Sqid, p.AppName, err) |
| } else if len(pcs) > 0 { |
| - p.Pending = s.pendingChangeViews(pcs, s.pendingPipeline(r.Context(), acct, p.AppName)) |
| + p.Pending = s.pendingChangeViews(pcs, p.Detail.Pipeline) |
| } |
| p.ReleaseSummary = assembleReleaseSummary(p.Detail.Channels, p.Detail.Routes, acct.Sqid) |
| p.PromoteChannels = promoteChannelOptions(p.Detail.Channels, p.Detail.Pipeline) |
diff --git a/internal/console/server_test.go b/internal/console/server_test.go| index 8cdddaf20..f7cfd4158 100644 |
| --- a/internal/console/server_test.go |
| +++ b/internal/console/server_test.go |
| @@ -344,6 +344,7 @@ func TestConsoleE2E(t *testing.T) { |
| if err := release.SetProduction(context.Background(), fx.rel, fx.priv, release.OpsAccount, "kass", true, "test"); err != nil { |
| t.Fatal(err) |
| } |
| + fx.forgetFrame("kass") |
| // The ladder, with channel names and versions on it, now lives on the |
| // Releases tab rather than the Overview page. |
diff --git a/internal/console/testdata/perf-budgets.txt b/internal/console/testdata/perf-budgets.txt| index 44dba5ea2..1b168876b 100644 |
| --- a/internal/console/testdata/perf-budgets.txt |
| +++ b/internal/console/testdata/perf-budgets.txt |
| @@ -33,28 +33,26 @@ GET /a/{sqid}/apps/{app}/logs/data deferred: deferred part (the Logs tab's data |
| # Known slow today (measured 2026-10-26, with 25 ms per S3 request and 40 ms |
| # per app-host call). Plan 2 deletes these. "the app-tab frame" is what every |
| -# app tab reads before its own part: the production |
| -# flag, the pipeline, and a listing plus one read per channel (6 S3 calls; the account |
| -# manifest is read once per process and then remembered). |
| +# app tab reads before its own part: the production flag, the pipeline, and a |
| +# listing plus one read per channel (6 S3 calls). It is cached per app for |
| +# 30 s (appframe.go), so a warm view reads none of it; the account manifest |
| +# is read once per process and then remembered. |
| /fleet/architecture over: reads economics/active.json, infra/inventory.json and status/fleet.json, and lists and reads every box report (8 S3 calls warm) |
| -GET /a/{sqid}/apps/{app} over: Overview is the app-tab frame plus a second pipeline read, the release listing, every manifest and every box report (10 S3 calls warm); cold, also every box's metrics hours for two days (about 110) |
| -GET /a/{sqid}/apps/{app}/account-review over: the app-tab frame (6 S3 calls warm) |
| -GET /a/{sqid}/apps/{app}/activity over: the app-tab frame (6 S3 calls warm) |
| -GET /a/{sqid}/apps/{app}/analytics over: the app-tab frame plus both telemetry settings and the analytics day listing and reads (10 S3 calls warm) |
| -GET /a/{sqid}/apps/{app}/availability over: the app-tab frame plus both telemetry settings and three listings and a read each for the log and error chunks (16 S3 calls warm) |
| -GET /a/{sqid}/apps/{app}/errors over: the app-tab frame plus both telemetry settings and three listings and a read each for the log and error chunks (16 S3 calls warm) |
| -GET /a/{sqid}/apps/{app}/instances over: the app-tab frame plus instances.json, and every edges file and box report listed and read twice (23 S3 calls warm) |
| -GET /a/{sqid}/apps/{app}/instances/{host} over: the app-tab frame plus the instance record, and the box reports and the fleet box reports listed and read three times (30 S3 calls warm) |
| -GET /a/{sqid}/apps/{app}/logs over: the app-tab frame plus a listing and a read of every instance record and three listings for the log chunks (14 S3 calls warm) |
| -GET /a/{sqid}/apps/{app}/releases over: the app-tab frame plus a second pipeline read for the pending card, the release and tag listings, at most 20 manifests, retention and instances.json (13 S3 calls warm; 11 on the fixture's empty page 2) |
| -GET /a/{sqid}/apps/{app}/settings over: General builds the whole settings record: each environment and its store read twice, every instance record, the domain claims, cert-warm records, every box report and a listing of every key under the app, plus the swap policy (31 S3 calls warm) |
| -GET /a/{sqid}/apps/{app}/settings/{section} over: Domains, Environments, Storage, Email and Feature flags build the whole settings record, as General does (30 S3 calls warm; General 31); Errors and analytics 8, the pipeline section 7, Placement and Delete 6 (the app-tab frame); the advanced redirect none |
| +GET /a/{sqid}/apps/{app} over: Overview is the release listing and every manifest (3 S3 calls warm, median about 80 ms); cold, also the app-tab frame and every box's metrics hours for two days (about 110) |
| +GET /a/{sqid}/apps/{app}/analytics calls 4: both telemetry settings, the analytics day listing and one day read |
| +GET /a/{sqid}/apps/{app}/availability over: both telemetry settings and three listings and a read each for the log and error chunks (10 S3 calls warm) |
| +GET /a/{sqid}/apps/{app}/errors over: both telemetry settings and three listings and a read each for the log and error chunks (10 S3 calls warm) |
| +GET /a/{sqid}/apps/{app}/instances over: instances.json, and every edges file and box report listed and read twice (17 S3 calls warm) |
| +GET /a/{sqid}/apps/{app}/instances/{host} over: the instance record, and the box reports and the fleet box reports listed and read three times (24 S3 calls warm) |
| +GET /a/{sqid}/apps/{app}/logs over: a listing and a read of every instance record, three listings for the log chunks and a chunk read (8 S3 calls warm) |
| +GET /a/{sqid}/apps/{app}/releases over: the release and tag listings, at most 20 manifests, retention and instances.json (6 S3 calls warm, median about 160 ms; 4 on the fixture's empty page 2) |
| +GET /a/{sqid}/apps/{app}/settings over: General builds the whole settings record: each environment and its store read twice, every instance record, the domain claims, cert-warm records, every box report and a listing of every key under the app, plus the swap policy (25 S3 calls warm) |
| +GET /a/{sqid}/apps/{app}/settings/{section} over: Domains, Environments, Storage, Email and Feature flags build the whole settings record, as General does (24 S3 calls warm; General 25); Errors and analytics 2 (both telemetry settings); the pipeline section, Placement, Delete and the advanced redirect none |
| GET /a/{sqid}/fleet over: reads status/fleet.json and lists and reads each customer fleet's box reports (3 S3 calls warm) |
| GET /a/{sqid}/fleets/{fleet} over: lists and reads the fleet's box reports (2 S3 calls warm) |
| GET /a/{sqid}/plan/keep over: the lapse inventory lists every app's instance records and reads each one, lists every app's sidecar records, and lists the domain claims (8 S3 calls warm for two apps and three instances, median 209 ms; it grows with the account) |
| GET /a/{sqid}/settings over: reads the account and app telemetry settings and the storage entitlement (3 S3 calls warm) |
| GET /a/{sqid}/trash over: reads each trashed app's deleted.json marker (1 S3 call warm per app) |
| -GET /a/{sqid}/{$} over: the account home lists and reads every app's channels and its production flag (5 S3 calls warm) |
| GET /fleet over: lists and reads every box report, reads status/fleet.json, and lists and reads the storage entitlements (8 S3 calls warm) |
| GET /fleet/economics over: the cold view sweeps usage for every day of the period (about 160 S3 calls, over 4 s); warm views come from the 60 s cache |
| GET /fleet/economics/accounts over: shares /fleet/economics's sweep cache, so its own cold view is that same sweep |
diff --git a/internal/console/view.go b/internal/console/view.go| index 6a0ba6345..1122a4d7c 100644 |
| --- a/internal/console/view.go |
| +++ b/internal/console/view.go |
| @@ -52,22 +52,23 @@ type AppView struct { |
| AllMismatched bool |
| // Pipeline is the app's declared release pipeline (release pipelines v2 |
| // §2) — nil for a legacy app that has never opted in, or when the read |
| - // failed (best-effort for a VIEW: a page that cannot read the object |
| - // degrades to the legacy ladder rather than failing outright; a WRITE |
| - // door such as handlePromote reads its own copy and refuses on error |
| - // instead, which is the place that distinction is load-bearing). |
| + // failed (PipelineErr then says why: best-effort for a VIEW, a page that |
| + // cannot read the object degrades to the legacy ladder rather than |
| + // failing outright; a WRITE door such as handlePromote reads its own |
| + // copy and refuses on error instead, which is the place that |
| + // distinction is load-bearing). |
| // |
| - // Deliberately NOT populated by Assemble (view.go's own tagByRelease |
| - // precedent: VersionView.Tag is never read there either — every caller |
| - // that wants it joins separately). Assemble builds a whole account's app |
| - // list for the account home page, which never renders Ladder or |
| - // Pipeline at all; a pipeline read per app there would be a bucket GET |
| - // nobody looks at. appPage (server.go) is the one place every APP page |
| - // funnels through, so it is the one place that reads this, and rebuilds |
| - // Ladder — and corrects each ChannelView's BakedUntil, which the legacy |
| - // per-app table below computes and which means nothing for a pipelined |
| - // channel's own window (Task 9 review) — once it has one. |
| - Pipeline *release.Pipeline |
| + // Assemble fills it from the app's frame (appframe.go), which reads the |
| + // pipeline alongside the channels so every app tab, the pending cards |
| + // and the Pipeline settings section share one read. Assemble itself |
| + // does not apply it: appPage (server.go) is the one place every APP |
| + // page funnels through, so it is the one place that rebuilds Ladder — |
| + // and corrects each ChannelView's BakedUntil, which the legacy per-app |
| + // table computes and which means nothing for a pipelined channel's own |
| + // window (Task 9 review) — from it (applyPipelineView). The account |
| + // home page never renders Ladder or Pipeline. |
| + Pipeline *release.Pipeline |
| + PipelineErr string |
| } |
| // OneChannelPipeline reports whether this app has opted into a pipeline with |
| @@ -558,6 +559,15 @@ func openRegistry(path string) (consoleRegistry, error) { |
| // cannot be read costs that app its remote rows and nothing else. nil is |
| // the console box's registry alone. |
| func Assemble(ctx context.Context, regPath string, s release.Store, pub ed25519.PublicKey, acct string, apps []string, dns DNSTargets, remote *remoteRows) ([]AppView, error) { |
| + return assembleViews(ctx, regPath, acct, apps, dns, remote, func(app string) appFrame { |
| + return loadAppFrame(ctx, s, pub, acct, app) |
| + }) |
| +} |
| + |
| +// assembleViews is Assemble with each app's release-store reads coming from |
| +// frame: a fresh load for Assemble, the frame cache for a page view |
| +// (Server.assembleApps). |
| +func assembleViews(ctx context.Context, regPath, acct string, apps []string, dns DNSTargets, remote *remoteRows, frame func(app string) appFrame) ([]AppView, error) { |
| reg, err := openRegistry(regPath) |
| if err != nil { |
| return nil, err |
| @@ -624,8 +634,9 @@ func Assemble(ctx context.Context, regPath string, s release.Store, pub ed25519. |
| if remote != nil { |
| byApp[app], domainsByApp[app] = addRemoteRows(remote, acct, app, localHosts, byApp[app], domainsByApp[app], dns) |
| } |
| - channels := assembleChannels(ctx, s, pub, acct, app, now) |
| - pv := assembleProduction(ctx, s, pub, acct, app, channels, byApp[app], now) |
| + f := frame(app) |
| + channels := assembleChannels(f, now) |
| + pv := assembleProduction(f, channels, byApp[app], now) |
| if pv.Err == "" && !pv.On { |
| // No production flag (or off): nothing bakes, so no estimate. An |
| // Err keeps the estimate — boxes fail toward baking. |
| @@ -645,12 +656,13 @@ func Assemble(ctx context.Context, regPath string, s release.Store, pub ed25519. |
| Channels: channels, |
| Canaries: assembleCanaries(channels, byApp[app]), |
| // nil pipeline here, always: this Ladder is the legacy shape. |
| - // Pipeline itself is deliberately NOT read here — see |
| - // AppView.Pipeline's doc comment — so appPage (server.go) is |
| - // where a single app's view gets pipeline-aware, and rebuilds |
| - // Ladder from the corrected Channels once it has one. |
| - Ladder: assembleLadder(channels, byApp[app], nil, now), |
| - Production: pv, |
| + // appPage (server.go) is where a single app's view gets |
| + // pipeline-aware (applyPipelineView), and rebuilds Ladder from |
| + // the corrected Channels once it has one. |
| + Ladder: assembleLadder(channels, byApp[app], nil, now), |
| + Production: pv, |
| + Pipeline: f.Pipeline, |
| + PipelineErr: f.PipelineErr, |
| }) |
| } |
| return out, nil |
| @@ -776,31 +788,21 @@ func tagByRelease(ctx context.Context, s release.Store, acct, app string) (map[s |
| return tagIndex(tags), nil |
| } |
| -// assembleChannels lists the app's account-qualified channel pointers and |
| -// resolves each one. An app whose objects are still at the legacy unqualified |
| -// keys lists as empty here, exactly as the fleet sees it — the console showing |
| +// assembleChannels turns the frame's channel pointers (the app's |
| +// account-qualified channels, listed and resolved by loadAppFrame) into the |
| +// view's rows. An app whose objects are still at the legacy unqualified keys |
| +// lists as empty, exactly as the fleet sees it — the console showing |
| // channels the boxes cannot follow is the disagreement the retired |
| // read-fallback used to create. |
| -func assembleChannels(ctx context.Context, s release.Store, pub ed25519.PublicKey, acct, app string, now time.Time) []ChannelView { |
| - prefix := release.ChannelsPrefix(acct, app) |
| - keys, err := s.List(ctx, prefix) |
| - if err != nil { |
| - return []ChannelView{{Name: "(all)", Err: "listing channels: " + err.Error()}} |
| +func assembleChannels(f appFrame, now time.Time) []ChannelView { |
| + if f.ChannelsErr != "" { |
| + return []ChannelView{{Name: "(all)", Err: "listing channels: " + f.ChannelsErr}} |
| } |
| - var names []string |
| - for _, k := range keys { |
| - name := strings.TrimPrefix(k, prefix) |
| - if !strings.HasSuffix(name, ".json") { |
| - continue |
| - } |
| - names = append(names, strings.TrimSuffix(name, ".json")) |
| - } |
| - sort.Strings(names) |
| var out []ChannelView |
| - for _, name := range names { |
| - p, err := release.Channel(ctx, s, pub, acct, app, name) |
| - if err != nil { |
| - out = append(out, ChannelView{Name: name, Err: err.Error()}) |
| + for _, fc := range f.Channels { |
| + name, p := fc.Name, fc.Pointer |
| + if fc.Err != "" || p == nil { |
| + out = append(out, ChannelView{Name: name, Err: fc.Err}) |
| continue |
| } |
| cv := ChannelView{ |
| @@ -829,14 +831,14 @@ func assembleChannels(ctx context.Context, s release.Store, pub ed25519.PublicKe |
| return out |
| } |
| -// assembleProduction reads the app's flag and derives the console's view of |
| -// it: on/off, the turning-off ratchet estimate, and the prod-wiring nudge. |
| -func assembleProduction(ctx context.Context, s release.Store, pub ed25519.PublicKey, acct, app string, channels []ChannelView, routes []RouteView, now time.Time) ProductionView { |
| +// assembleProduction derives the console's view of the frame's production |
| +// flag: on/off, the turning-off ratchet estimate, and the prod-wiring nudge. |
| +func assembleProduction(f appFrame, channels []ChannelView, routes []RouteView, now time.Time) ProductionView { |
| pv := ProductionView{} |
| - flag, err := release.GetProduction(ctx, s, pub, acct, app) |
| + flag := f.Production |
| switch { |
| - case err != nil: |
| - pv.Err = err.Error() |
| + case f.ProductionErr != "": |
| + pv.Err = f.ProductionErr |
| pv.On = true // what the boxes will do: fail toward baking |
| return pv |
| case flag != nil: |