edge: one static _headers test fixture, shared by the golden and the serving tests
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
internal/edge/static_headers_golden_test.go+13 −7internal/edge/static_headers_test.go+5 −38
Intent
<task-notification> <task-id>bk01ssag7</task-id> <tool-use-id>toolu_01RMe7FAZ3Fz3CeumkHkiLME</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/0f246987-ca6b-4093-b104-f930443a8208/tasks/bk01ssag7.output</output-file> <status>completed</status> <summary>Background command "Run the Astra review of Task 2" completed (exit code 0)</summary> </task-notification>
Attributed to this commit: 18.6 g CO₂e (2,362,315 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on static-headers, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.
diff --git a/internal/edge/static_headers_golden_test.go b/internal/edge/static_headers_golden_test.go| index 44aeb2ec1..31a506a90 100644 |
| --- a/internal/edge/static_headers_golden_test.go |
| +++ b/internal/edge/static_headers_golden_test.go |
| @@ -38,9 +38,12 @@ func staticHeadersTree() map[string]string { |
| } |
| } |
| -// goldenStaticEdge serves files as a static site through the real edge, with |
| -// the shared response cache on as production runs it. |
| -func goldenStaticEdge(t *testing.T, files map[string]string) *httptest.Server { |
| +// staticHeadersEdge serves files as a static site through the real edge, |
| +// with the shared response cache on as production runs it. It returns the |
| +// edge, the server, and the directory the tree is extracted into (it exists |
| +// once the first request has been answered). It is the one fixture for the |
| +// golden and the _headers tests, so the two can never drift apart. |
| +func staticHeadersEdge(t *testing.T, files map[string]string) (*Edge, *httptest.Server, string) { |
| t.Helper() |
| store := release.NewDirStore(filepath.Join(t.TempDir(), "store")) |
| priv, pub := testKeys(t) |
| @@ -48,8 +51,9 @@ func goldenStaticEdge(t *testing.T, files map[string]string) *httptest.Server { |
| if err := release.Promote(context.Background(), store, priv, release.OpsAccount, "site", "canary/x", "v1"); err != nil { |
| t.Fatalf("Promote: %v", err) |
| } |
| + rt := registry.Route{Host: "site.example.com", Kind: "static", App: "site", Channel: "canary/x", Status: "ready"} |
| reg := openReg(t) |
| - if err := reg.Upsert(registry.Route{Host: "site.example.com", Kind: "static", App: "site", Channel: "canary/x", Status: "ready"}); err != nil { |
| + if err := reg.Upsert(rt); err != nil { |
| t.Fatalf("upsert: %v", err) |
| } |
| e, err := New(reg, nil) |
| @@ -57,13 +61,15 @@ func goldenStaticEdge(t *testing.T, files map[string]string) *httptest.Server { |
| t.Fatalf("New: %v", err) |
| } |
| e.EnableCache(NewCache(DefaultCacheMaxEntries, DefaultCacheMaxBodyBytes)) |
| - e.EnableStatic(store, pub, filepath.Join(t.TempDir(), "cache")) |
| + cacheDir := filepath.Join(t.TempDir(), "cache") |
| + e.EnableStatic(store, pub, cacheDir) |
| if err := e.Reload(); err != nil { |
| t.Fatalf("Reload: %v", err) |
| } |
| srv := httptest.NewServer(e) |
| t.Cleanup(srv.Close) |
| - return srv |
| + treeDir := filepath.Join(cacheDir, release.RouteAccount(rt), "site", siteDirOf(t, store, "site", "v1")) |
| + return e, srv, treeDir |
| } |
| // staticClient neither follows redirects nor asks for gzip on its own, so a |
| @@ -106,7 +112,7 @@ type goldenAnswer struct { |
| } |
| func TestStaticWithoutHeadersIsUnchanged(t *testing.T) { |
| - srv := goldenStaticEdge(t, staticHeadersTree()) |
| + _, srv, _ := staticHeadersEdge(t, staticHeadersTree()) |
| got := map[string]goldenAnswer{} |
| record := func(name string, resp *http.Response) { |
| h := resp.Header.Clone() |
diff --git a/internal/edge/static_headers_test.go b/internal/edge/static_headers_test.go| index b2e605707..18d0a9a6c 100644 |
| --- a/internal/edge/static_headers_test.go |
| +++ b/internal/edge/static_headers_test.go |
| @@ -1,7 +1,6 @@ |
| package edge |
| import ( |
| - "context" |
| "fmt" |
| "io" |
| "net/http" |
| @@ -14,7 +13,6 @@ import ( |
| "time" |
| "github.com/carlosframework/platform/internal/registry" |
| - "github.com/carlosframework/platform/internal/release" |
| ) |
| // The edge serving a static site's _headers (spec section 4), through the |
| @@ -47,45 +45,14 @@ func fiestaTree() map[string]string { |
| // fiestaKey is the shared cache's key for a GET of /1.0.0/fiesta.css. |
| var fiestaKey = CacheKey{Host: "site.example.com", Method: "GET", Path: "/1.0.0/fiesta.css"} |
| -// headersEdge serves files as a static site through the real edge with the |
| -// shared cache on, and returns the server and the directory the tree is |
| -// extracted into (it exists once the first request has been answered). |
| +// headersEdge is staticHeadersEdge for tests that need only the server and |
| +// the extracted tree. |
| func headersEdge(t *testing.T, files map[string]string) (srv *httptest.Server, treeDir string) { |
| t.Helper() |
| - _, srv, treeDir = headersEdgeWith(t, files) |
| + _, srv, treeDir = staticHeadersEdge(t, files) |
| return srv, treeDir |
| } |
| -// headersEdgeWith is headersEdge for tests that need the edge itself. |
| -func headersEdgeWith(t *testing.T, files map[string]string) (*Edge, *httptest.Server, string) { |
| - t.Helper() |
| - store := release.NewDirStore(filepath.Join(t.TempDir(), "store")) |
| - priv, pub := testKeys(t) |
| - shipSite(t, store, "site", "v1", files) |
| - if err := release.Promote(context.Background(), store, priv, release.OpsAccount, "site", "canary/x", "v1"); err != nil { |
| - t.Fatalf("Promote: %v", err) |
| - } |
| - rt := registry.Route{Host: "site.example.com", Kind: "static", App: "site", Channel: "canary/x", Status: "ready"} |
| - reg := openReg(t) |
| - if err := reg.Upsert(rt); err != nil { |
| - t.Fatalf("upsert: %v", err) |
| - } |
| - e, err := New(reg, nil) |
| - if err != nil { |
| - t.Fatalf("New: %v", err) |
| - } |
| - e.EnableCache(NewCache(DefaultCacheMaxEntries, DefaultCacheMaxBodyBytes)) |
| - cacheDir := filepath.Join(t.TempDir(), "cache") |
| - e.EnableStatic(store, pub, cacheDir) |
| - if err := e.Reload(); err != nil { |
| - t.Fatalf("Reload: %v", err) |
| - } |
| - srv := httptest.NewServer(e) |
| - t.Cleanup(srv.Close) |
| - treeDir := filepath.Join(cacheDir, release.RouteAccount(rt), "site", siteDirOf(t, store, "site", "v1")) |
| - return e, srv, treeDir |
| -} |
| - |
| // wantHeaders fails unless resp carries the Cache-Control and |
| // Access-Control-Allow-Origin given; "" means the header is absent. |
| func wantHeaders(t *testing.T, what string, resp *http.Response, cc, acao string) { |
| @@ -293,7 +260,7 @@ func TestHeaderWriterKeepsItsOwnMap(t *testing.T) { |
| } |
| func TestStaticWithMaxAgeIsNeverStoredInTheSharedCache(t *testing.T) { |
| - e, srv, treeDir := headersEdgeWith(t, fiestaTree()) |
| + e, srv, treeDir := staticHeadersEdge(t, fiestaTree()) |
| resp, first := staticDo(t, srv, "GET", "/1.0.0/fiesta.css", nil) |
| if resp.StatusCode != http.StatusOK { |
| t.Fatalf("first GET = %d, want 200", resp.StatusCode) |
| @@ -323,7 +290,7 @@ func TestStaticWithMaxAgeIsNeverStoredInTheSharedCache(t *testing.T) { |
| } |
| func TestStaticIgnoresASeededSharedCacheEntry(t *testing.T) { |
| - e, srv, _ := headersEdgeWith(t, fiestaTree()) |
| + e, srv, _ := staticHeadersEdge(t, fiestaTree()) |
| seedSentinel(e) |
| _, body := staticDo(t, srv, "GET", "/1.0.0/fiesta.css", nil) |
| if body != staticHeadersTree()["1.0.0/fiesta.css"] { |