diff --git a/platform/scripts/kitchen-sink-smoke-test.md b/platform/scripts/kitchen-sink-smoke-test.md index 82addcf6d..f6622413b 100644 --- a/platform/scripts/kitchen-sink-smoke-test.md +++ b/platform/scripts/kitchen-sink-smoke-test.md @@ -49,7 +49,20 @@ EVALEOF 1. Visit `/`. 2. Assert the page contains "Kitchen Sink" and "Auth" in its text. 3. Inspect the page's HTML source for hashed asset URLs (e.g. `.js` or `.css` files with hash in the filename). -4. Use an **in-browser sync XHR** (`XMLHttpRequest` via `agent-browser eval`) to HEAD-request one of those asset URLs and assert its `Cache-Control` header contains `immutable`. Do NOT use `curl` — Cloudflare edge cache rules rewrite headers differently for browser vs non-browser requests. +4. Use an **in-browser sync XHR** (`XMLHttpRequest` via `agent-browser eval`) to GET one of those asset URLs with a cache-busting query parameter, and assert its `Cache-Control` header contains `immutable`. Do NOT use `curl` — Cloudflare edge cache rules rewrite headers differently for browser vs non-browser requests. Do NOT use `HEAD`: the dispatch edge cache stamps `immutable` on `GET`s to hashed paths only, and a conditional `HEAD` is answered from the entry the browser already stored, so it reports `no-store` and looks like a failure. + + ```bash + agent-browser eval --stdin <<'EVALEOF' + const el = document.querySelector('script[src*="/assets/"]') || document.querySelector('link[href*="/assets/"]'); + const url = el.src || el.href; + const xhr = new XMLHttpRequest(); + xhr.open('GET', url + (url.includes('?') ? '&' : '?') + 'smoke=' + Date.now(), false); + xhr.send(); + xhr.status + ' ' + xhr.getResponseHeader('cache-control') + EVALEOF + ``` + + Expect `200 public, max-age=31536000, immutable`. ### 2. SPA navigation (no full reload) diff --git a/platform/scripts/kitchen-sink-smoke-test.ts b/platform/scripts/kitchen-sink-smoke-test.ts index 1aa7532cc..bb6c04197 100644 --- a/platform/scripts/kitchen-sink-smoke-test.ts +++ b/platform/scripts/kitchen-sink-smoke-test.ts @@ -143,15 +143,22 @@ void describe(`kitchen-sink smoke (${BASE})`, { concurrency: true }, () => { const assetUrl = `${BASE}/${assetMatch![1]}`; + // `cache: 'no-store'` makes this a NETWORK get, so the assertion reads the + // response the platform just produced. Reading the stored entry instead + // (plain HEAD after the page load, which is how this test used to run) + // reports whatever the browser cached earlier: the dispatch edge cache only + // stamps `immutable` on gets to hashed paths, so a conditional HEAD is both + // answered from the store and outside the caching contract under test. // Use in-browser fetch (not curl) — CF edge cache rules differ for browser vs non-browser - const cacheControl = await page.evaluate(async (url) => { - const res = await fetch(url, { method: 'HEAD' }); - return res.headers.get('cache-control') || ''; + const asset = await page.evaluate(async (url) => { + const res = await fetch(url, { cache: 'no-store' }); + return { status: res.status, cacheControl: res.headers.get('cache-control') || '' }; }, assetUrl); + assert.equal(asset.status, 200, `asset GET succeeds (got ${asset.status})`); assert.ok( - cacheControl.includes('immutable'), - `Cache-Control includes immutable (got: ${cacheControl})`, + asset.cacheControl.includes('immutable'), + `Cache-Control includes immutable (got: ${asset.cacheControl})`, ); } finally { await ctx.close();