carlos / platform Public

edge: page diagnostics on the demo traffic path

serveDemoTraffic installed the page mark holder but proxied through
appWriter without the diagnostic writer, so a demo instance's marked
response had its marker stripped and reached the visitor with no
Carlos-Cache: bypass. The app's writer is now wrapped with
pageDiagnostics(...).wrap, diagnostic only (nothing is recorded).

TestDemoTrafficPageDiagnostics drives the reload-built demo proxy (the
real response hook) and checks the marker is stripped, the diagnostic
set for a marked response and absent for an unmarked one.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 9aba50ff6e979b6b3c2e8b30aef8a105cc740d00 parent 66b7eac
2 files changed, +64 −1
  • internal/edge/demo_traffic.go +6 −1
  • internal/edge/demo_traffic_test.go +58 −0
diff --git a/internal/edge/demo_traffic.go b/internal/edge/demo_traffic.go
index 6b509c95d..62b910a0e 100644
--- a/internal/edge/demo_traffic.go
+++ b/internal/edge/demo_traffic.go
@@ -323,9 +323,14 @@ func (e *Edge) serveDemoTraffic(dst http.ResponseWriter, r *http.Request, up ups
return
}
// The page mark holder every proxied instance request carries
- // (pagemark.go), as ServeHTTP attaches it on the ordinary path.
+ // (pagemark.go), as ServeHTTP attaches it on the ordinary path, and the
+ // page diagnostics (pagerecord.go) around the app's writer, so a marked
+ // response says Carlos-Cache: bypass here too. Diagnostic only: a demo
+ // response is never recorded into either cache. Platform refusals go to
+ // refusal, beside it, and carry no diagnostic.
if up.route.Kind == "instance" {
r = withPageMarkHolder(r)
+ appWriter = e.pageDiagnostics(r, host, up).wrap(appWriter)
}
if up.hibernating && e.act != nil {
// The activator's own answers are platform refusals. A successful wake
diff --git a/internal/edge/demo_traffic_test.go b/internal/edge/demo_traffic_test.go
index 1c48d9a3e..db6140f2c 100644
--- a/internal/edge/demo_traffic_test.go
+++ b/internal/edge/demo_traffic_test.go
@@ -429,6 +429,64 @@ func TestDemoTrafficReloadAndCacheBypass(t *testing.T) {
}
}
+// TestDemoTrafficPageDiagnostics (final review finding 3): a demo instance's
+// response goes through the reload-built proxy, whose response hook takes
+// the app's Carlos-Page-Cache into the request's holder and strips it, and
+// through the diagnostic writer, so a marked response reaches the visitor
+// with Carlos-Cache: bypass and no marker. An unmarked one gets neither.
+func TestDemoTrafficPageDiagnostics(t *testing.T) {
+ e, rt, c := demoTrafficFixture(t, nil)
+ if err := e.reg.Upsert(rt); err != nil {
+ t.Fatal(err)
+ }
+ if err := e.Reload(); err != nil {
+ t.Fatal(err)
+ }
+ up := e.current()[rt.Host]
+ if up.route.Kind != "instance" {
+ t.Fatalf("the demo route is a %q", up.route.Kind)
+ }
+ wrapped, ok := up.proxy.(assetScrubbedProxy)
+ if !ok {
+ t.Fatalf("proxy %T", up.proxy)
+ }
+ transport, ok := wrapped.proxy.Transport.(demoBannerTransport)
+ if !ok {
+ t.Fatalf("transport %T", wrapped.proxy.Transport)
+ }
+ var mark atomic.Value
+ mark.Store("")
+ transport.base = roundTripperFunc(func(r *http.Request) (*http.Response, error) {
+ h := http.Header{"Content-Type": {"text/plain"}, "Cache-Control": {"public, s-maxage=600"}}
+ if v := mark.Load().(string); v != "" {
+ h.Set(pageCacheHeader, v)
+ }
+ return &http.Response{StatusCode: 200, Header: h, Body: io.NopCloser(strings.NewReader("shop")), Request: r, ContentLength: -1}, nil
+ })
+ wrapped.proxy.Transport = transport
+ for _, tc := range []struct{ mark, want string }{
+ {`on; ignore-cookies="consent"`, "bypass"},
+ {"", ""},
+ } {
+ mark.Store(tc.mark)
+ rec := httptest.NewRecorder()
+ e.ServeHTTP(rec, httptest.NewRequest("GET", "https://"+rt.Host+"/p", nil))
+ if rec.Code != 200 || rec.Body.String() != "shop" {
+ t.Fatalf("mark %q: %d %q", tc.mark, rec.Code, rec.Body.String())
+ }
+ if got := rec.Header().Values(pageCacheHeader); len(got) != 0 {
+ t.Fatalf("mark %q: the visitor got the marker %q", tc.mark, got)
+ }
+ if got := rec.Header().Get(assetCacheHeader); got != tc.want {
+ t.Fatalf("mark %q: Carlos-Cache = %q, want %q", tc.mark, got, tc.want)
+ }
+ assertDemoPolicy(t, rec.Header())
+ }
+ if c.requests != 2 {
+ t.Fatalf("counted %d requests", c.requests)
+ }
+}
+
func TestDemoTrafficPurgeDrainsWriter(t *testing.T) {
entered := make(chan struct{})
release := make(chan struct{})