Repository navigation
Conversation
199cff0 to
4b2d028
Compare
Coverage Report for CI Build 46316239834Coverage decreased (-0.002%) to 88.682%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats💛 - Coveralls |
8d61b87 to
b51fc90
Compare
58f4e1b to
283f675
Compare
8c3ed0c to
1d8b632
Compare
There was a problem hiding this comment.
Findings marked 🟡 are optional suggestions and need no follow-up push.
Additional findings (outside the current diff — GitHub can't attach inline comments there):
-
🟡
acceptance/support/cdn-purge.ts— Core and versioning suites with no CDN requirement can fail outright when ACCEPTANCE_CDN_NEEDS_PURGE=true is set against a target with no CDN. The helper checks only cdnNeedsManualPurge, never capabilities.cdn. It then sends DELETE /cdn with expectedStatus: 200, and that fails when no purge endpoint is configured. Fix: skip the purge unless both cdnNeedsManualPurge and capabilities.cdn are true. This covers the new callers in rest-extended.test.ts (profile 'core') and rest-object-versioning.test.ts (requires only 'versioning').Why this was flagged
Trigger: an operator sets ACCEPTANCE_CDN_NEEDS_PURGE=true (for example in a shared CI env) and runs against a target where ACCEPTANCE_ENABLE_CDN is not set, such as the local target. The helper at cdn-purge.ts:43-47 calls purgeCdnCache, which sends DELETE /cdn/... with expectedStatus: 200 and retries: 3 (cdn-purge.ts:532-536). It also calls requireServiceKey(). This diff adds unconditional calls to it in rest-extended.test.ts:479 and :791 (describe profiles: ['core'], no cdn requirement) and in rest-object-versioning.test.ts (requires: ['versioning'] only). Those tests never touch the CDN on the base branch. After this change they fail with 'Unexpected HTTP status for DELETE .../cdn/...' whenever the server has no CDN purge endpoint configured (src/storage/cdn/cdn-cache-manager.test.ts:254 tests the cdnPurgeEndpointURL: undefined case). The capabilities.cdn flag (config.ts:184) exists to gate exactly this, but the helper does not consult it.
Verification: In acceptance/support/cdn-purge.ts, purgeCdnCacheIfNeeded (lines 43-47) checks only
if (getAcceptanceConfig().cdnNeedsManualPurge), and purgeCdnCache (lines 34-38) sendsDELETE /cdn/...withexpectedStatus: 200. config.ts:129 never ties it tocdnEnabled(config.ts:171). The diff calls the helper from rest-extended.test.ts:479 and rest-object-versioning.test.ts:463, which then fail. Hence nit.
| const second = await client.request('GET', secondBustedRoute, { | ||
| expectedCacheStatus: 'HIT', | ||
| expectedStatus: 200, | ||
| retries: CACHE_RETRIES, | ||
| token, | ||
| }) |
There was a problem hiding this comment.
🔴 Several new cache-sharing and cache-retention tests can never fail. Each of their HIT assertions retries, and the first attempt itself caches the entry. Class: a HIT check meant to prove an entry was already shared or kept also passes retries: CACHE_RETRIES. Fix: send these HIT checks once with no retries, as the purge tests in this PR already do, which covers the 5 sites listed. Same pattern at 5 sites (cdn.test.ts:1284, cdn.test.ts:1648, cdn-object-versioning.test.ts:133, cdn-object-versioning.test.ts:232, cdn-object-versioning.test.ts:292).
Why this was flagged
AcceptanceHttpClient.request re-sends the same URL when the cache status does not match (acceptance/support/http.ts:103-114, retry loop around line 52). In 'does not needlessly churn the object cache' (cdn.test.ts:1283-1289), secondBustedRoute is a URL never requested before. If the re-upload changed the etag, the first GET is a MISS, that GET caches the response, and the retry 1s later is a HIT, so the test passes. In 'keeps serving a cached object past its own stated max-age' (cdn.test.ts:1648-1653), an edge that honoured max-age=5 would return EXPIRED or MISS, then the retry HITs the freshly re-cached entry, so the test passes. The 'current'/'historical' HIT checks in cdn-object-versioning.test.ts:129-137, 231-236 and 291-296 claim the etag-only cache key is shared. A separate cache entry per URL would MISS once and then HIT on retry, so they pass either way. The body checks do not help because the bytes are identical. The PR's own comments at cdn-object-versioning.test.ts:386-388 and 431-433 say that retries re-warm entries and mask this, but these new sites keep them anyway.
Verification: AcceptanceHttpClient.request (acceptance/support/http.ts:37-55) loops up to retries times. A MISS or EXPIRED response on a public or authenticated route is stored at the edge. So in any HIT check with retries, a failed first attempt fills the cache and the next attempt is a HIT. The signed variants expect MISS and are not affected.
| { versionId: a.version } | ||
| ) | ||
| const historical = await client.request('GET', historicalRoute, { | ||
| expectedCacheStatus: isSigned ? 'MISS' : 'HIT', |
There was a problem hiding this comment.
🔴 Signed-URL versioning tests will fail on any V2 edge that verifies signed tokens itself, even though the CDN is behaving correctly. They hard-code a MISS for a later signed token on an etag that is already warm. cdn.test.ts:901-917 shows such tokens share the object-level entry and return HIT. Fix: read x-smart-cdn-access from the warm-up response and expect HIT when it is signed-verified, as cdn.test.ts does, which covers the 3 sites listed. Same pattern at 3 sites (cdn-object-versioning.test.ts:127, :226, :286).
Why this was flagged
The trigger is a V2 project whose edge verifies signed tokens, so responses carry x-smart-cdn-access: signed-verified. cdn.test.ts:901-910 already treats that case as valid: a second signed token for the same object gets a HIT on the entry the first token warmed. cdn-object-versioning.test.ts:127 requests current, which resolves to etag B after routeB was warmed, and expects isSigned ? 'MISS' : 'HIT'. Lines 226 and 286 send historical versionId requests for etag A after the current route warmed A, with the same expectation. On such an edge every attempt returns HIT, and the client throws Unexpected cache status after CACHE_RETRIES (15) attempts. So the signed suite fails even though the CDN behaves as designed. These tests are new, so the base branch has nothing to compare against. Retries do not help because each attempt keeps returning HIT.
Verification: Trigger: a Smart CDN V2 project whose edge verifies signed tokens, so responses carry x-smart-cdn-access: signed-verified. cdn.test.ts:901-910 then expects a second signed token to get 'HIT'. cdn-object-versioning.test.ts makes no such check, so line 127 always expects isSigned ? 'MISS' : 'HIT', as do lines 226 and 286. http.ts (lines 102-113) throws on a mismatch, so all 15 CACHE_RETRIES fail.
| const cdnVersion = normalizeCdnVersion(envOption('ACCEPTANCE_CDN_VERSION')) | ||
| const cdnNeedsManualPurge = envOption('ACCEPTANCE_CDN_NEEDS_PURGE') === 'true' |
There was a problem hiding this comment.
🔴 CI remote runs can never select Smart CDN V2 or manual purge, so the new V2 tests always skip in CI and V2 environments are checked against V1 expectations. The two new env vars are read only from process.env. The Remote job in .github/workflows/acceptance.yml passes an explicit env list that lacks ACCEPTANCE_CDN_VERSION and ACCEPTANCE_CDN_NEEDS_PURGE. Fix: add both to that job's env block, e.g. ACCEPTANCE_CDN_VERSION: ${{ vars.ACCEPTANCE_CDN_VERSION }}, and document them in the acceptance/README.md env table.
Why this was flagged
The cdnEdge capability is only true when target === 'remote' (acceptance/support/config.ts:185). The only CI job that sets ACCEPTANCE_TARGET: remote is acceptance_remote in .github/workflows/acceptance.yml (around lines 159-191). It forwards ACCEPTANCE_ENABLE_CDN but not the two new variables, so environment vars set on the GitHub environment never reach vitest. config.ts:128-129 then resolves cdnVersion to '1' and cdnNeedsManualPurge to false. Effects: the V2-only tests are skipped (cdn.test.ts:515 and :526, cdn-object-versioning.test.ts:354 and :397). Every purgeCdnCacheIfNeeded call becomes a no-op. So a dispatch against a V2 project, which per the PR still needs manual purge, fails its invalidation tests (e.g. cdn.test.ts:1095, cdn-object-versioning.test.ts:450) and never runs its V2 coverage. Base had no such settings. Nothing else in the repo sets these variables.
Verification: The two new options are read only from the process environment: acceptance/support/config.ts:128-129. The Remote job's Run acceptance profile step (.github/workflows/acceptance.yml:159-191) maps every ACCEPTANCE_* variable. Neither ACCEPTANCE_CDN_VERSION nor ACCEPTANCE_CDN_NEEDS_PURGE is in that list. So in that job cdnVersion is always '1' and cdnNeedsManualPurge is always false.
| } else if (versionId) { | ||
| url += '?versionId=' + encodeURIComponent(versionId) | ||
| } |
There was a problem hiding this comment.
🟡 (optional) Against this repo's storage server, version-scoped purges clear the whole object, so both V2 per-version purge tests fail. The helper sends ?versionId= to DELETE /cdn/:bucket/*. But purgeQuerySchema (src/http/routes/cdn/purgeCache.ts:25) only declares transformations, so the handler ignores it. Fix: add versionId support to the purge route in this change, or gate both tests on a server that has it. The tests sit at cdn-object-versioning.test.ts:370 and :416.
Why this was flagged
The trigger is a run with ACCEPTANCE_CDN_VERSION=2 against a server built from this checkout. In 'purges only the targeted version...', purgeCdnCache(client, { bucketName, objectKey, versionId: a }) at cdn-object-versioning.test.ts:370 builds /cdn/<bucket>/<key>?versionId=.... The /:bucketName/* handler in src/http/routes/cdn/purgeCache.ts:123-133 reads only transformations and calls cdnCache.purge({ type: 'object', ... }). That purges every cached entry for the object. The hitB and hitCurrent requests run with no retries and expect 'HIT', so they get MISS and the test fails. With ACCEPTANCE_CDN_NEEDS_PURGE=true, the same thing happens at :416 in the auto-purge test, so the stillCurrent HIT assertion fails. No guard catches the unknown query param. The schema has no additionalProperties:false, so the server ignores it and still returns 200 'success'.
Verification: nit. The trigger is a run with ACCEPTANCE_CDN_VERSION=2 against a storage server built from this checkout. On the server, purgeQuerySchema (src/http/routes/cdn/purgeCache.ts:25-30) declares only transformations. So a version-scoped purge is sent upstream as a purge of the whole object. Nothing in the diff adds versionId support to the server route.
| // re-warm lower route to ensure cache purge finished | ||
| await warmCacheEndpoint(client, lowerRoute) |
There was a problem hiding this comment.
🟡 (optional) On V2 runs, the case-sibling purge test can fail when purge propagation is slow, even though the CDN behaves correctly. The step meant to wait for the lower-case purge uses warmCacheEndpoint. That helper retries the expected MISS only CACHE_RETRIES (15) times, about 15s, while cdn.ts says purge propagation can take 60s. Fix: wait for the purge with CACHE_PURGE_RETRIES, as the other post-purge MISS checks do. For example, do an explicit MISS GET on lowerRoute with those retries, then a HIT GET.
Why this was flagged
In 'does not cross-purge a case-differing sibling object' (acceptance/specs/cdn.test.ts:526), purgeCdnCache runs first. Then warmCacheEndpoint(client, lowerRoute) at line 547 is meant "to ensure cache purge finished". warmCacheEndpoint (acceptance/support/cdn.ts) hardcodes retries: CACHE_RETRIES (15) on its MISS request, and the HTTP client waits 1s between retries. acceptance/support/cdn.ts defines CACHE_PURGE_RETRIES = 70 because "Purge propagation can take 60s". Every other post-purge MISS check in this file uses that larger value (lines 109, 180, 237, 493). When the purge needs more than about 15s to reach the edge, the warm step keeps getting HIT, runs out of retries and throws. The V2 run then fails even though the CDN is correct. Nothing else in the test waits longer, so the shorter retry budget is the only gate.
Verification: nit. Trigger: a V2 run where purge propagation takes longer than about 15s, which acceptance/support/cdn.ts says can take 60s. warmCacheEndpoint hardcodes retries: CACHE_RETRIES (15) on its MISS request, used at cdn.test.ts:547 to wait for the purge. Every other post-purge MISS wait uses CACHE_PURGE_RETRIES, so the test fails falsely, not a product defect.
| it('keeps serving a cached object past its own stated max-age', async () => { | ||
| const objectKey = makeObjectKey('short-max-age') | ||
| const maxAgeSeconds = 5 | ||
| const content = 'short-max-age-content' | ||
|
|
||
| try { | ||
| await uploadRestObject(bucketName, objectKey, content, { | ||
| cacheControl: `max-age=${maxAgeSeconds}`, | ||
| }) | ||
|
|
||
| await pauseForWebhookIfNeeded(accessMethod) | ||
|
|
||
| const { route, token } = await getObjectUrl( | ||
| bucketName, | ||
| objectKey, | ||
| bucketType, | ||
| accessMethod | ||
| ) | ||
|
|
||
| await warmCacheEndpoint(client, route, token) | ||
|
|
||
| // Comfortably past the object's own stated max-age | ||
| await delay((maxAgeSeconds + 10) * 1000) | ||
|
|
||
| const stillCached = await client.request('GET', route, { | ||
| expectedCacheStatus: 'HIT', | ||
| expectedStatus: 200, | ||
| retries: CACHE_RETRIES, | ||
| token, | ||
| }) | ||
| expect(stillCached.body).toBe(content) | ||
| } finally { | ||
| await cleanupRestObjects(bucketName, [objectKey], client) | ||
| } | ||
| }, 30_000) |
There was a problem hiding this comment.
🟡 (optional) Two new timing tests can time out on slow CDN edges even when CDN behaviour is correct. Each overrides the timeout to 30_000, below the suite's own 90_000/120_000 budget. Inside that budget they sleep 15s and run several CACHE_RETRIES loops of up to ~15s each. Fix: size each timeout to cover the fixed delay plus every retry loop (e.g. 15s + 3 × 15s ≈ 60s+), or drop the override so the suite timeout applies, which covers the 2 sites listed. Same pattern at 2 sites (cdn.test.ts:961, cdn.test.ts:1658).
Why this was flagged
The test 'keeps serving a cached object past its own stated max-age' (cdn.test.ts:1624-1658) runs warmCacheEndpoint, which makes two requests with retries: CACHE_RETRIES (15, at 1s apart, acceptance/support/cdn.ts:578). It then sleeps (maxAgeSeconds + 10) * 1000 = 15s and makes another CACHE_RETRIES request, all under a per-test timeout of 30_000. The worst case is about 60s, so if the HIT takes more than roughly 15s in total to show up (the reason CACHE_RETRIES exists), vitest kills the test at 30s. The run then reports a timeout, not a CDN assertion. 'bypasses a warmed cache entry once its signed token has expired' (cdn.test.ts:923-961) has the same problem. It may also call pauseForWebhookIfNeeded first (5s on V1) and sleeps 15s, under the same 30_000 cap, even though its suite allows 120_000 (cdn.test.ts:1662).
Verification: Both new tests set }, 30_000) (cdn.test.ts:961, cdn.test.ts:1658), which beats the describe timeout (isSigned ? 120_000 : 90_000) and the config default testTimeout: 60_000. The fixed waits alone are 15s, or 20s on signed V1, leaving about 5-15s for every warm-up retry against a ~45-60s retry budget. A slow MISS->HIT transition is cut off by vitest's 30s timeout rather than handled.
| const profile = normalizeProfile(readOption('profile') ?? envOption('ACCEPTANCE_PROFILE')) | ||
| const target = normalizeTarget(readOption('target') ?? envOption('ACCEPTANCE_TARGET')) | ||
| const cdnVersion = normalizeCdnVersion(envOption('ACCEPTANCE_CDN_VERSION')) | ||
| const cdnNeedsManualPurge = envOption('ACCEPTANCE_CDN_NEEDS_PURGE') === 'true' |
There was a problem hiding this comment.
🟡 nit (optional): Setting ACCEPTANCE_CDN_NEEDS_PURGE=1 or yes silently leaves manual purge off. Every other boolean option here accepts 1/true/yes, plus a CLI flag, through boolOption. Fix: read it with boolOption('cdn-needs-purge', envOption('ACCEPTANCE_CDN_NEEDS_PURGE')). Likewise accept v2/V2 (or reject unknown values) in normalizeCdnVersion at config.ts:278-280, which currently maps them to '1' with no error.
Why this was flagged
config.ts:129 uses a strict === 'true'. The sibling switches go through boolOptionValue (config.ts:301-310), which accepts '1', 'true' and 'yes'. run-managed-local.ts isTruthy (line 437) uses the same truthy set for ACCEPTANCE_ENABLE_CDN. An operator copying that convention with ACCEPTANCE_CDN_NEEDS_PURGE=1 gets cdnNeedsManualPurge=false. purgeCdnCacheIfNeeded (cdn-purge.ts:44) then skips the purge, and the overwrite-then-read tests read stale cached content. normalizeCdnVersion (config.ts:278-280) also maps any value other than exactly '2', such as 'v2' or 'V2', to '1' with no warning. The PR text itself calls the default 'V1', which invites the 'V2' spelling.
Verification: acceptance/support/config.ts:129 reads const cdnNeedsManualPurge = envOption('ACCEPTANCE_CDN_NEEDS_PURGE') === 'true', so only the exact string 'true' turns it on. With =1, cdnNeedsManualPurge is false, and purgeCdnCacheIfNeeded (cdn-purge.ts:44) skips the DELETE /cdn purge. normalizeCdnVersion (config.ts:278-280) is return value === '2' ? '2' : '1', so 'v2' or 'V2' silently becomes '1'.
What kind of change does this PR introduce?
Adds more test coverage for CDN behavior and support for Smart CDN V2 differences
Adds
ACCEPTANCE_CDN_NEEDS_PURGE(default false) to manual purge cache where the storage service will be expected to actively purge in the future. This can be removed once #1772 is deployed and enabled.Adds
ACCEPTANCE_CDN_VERSION(default V1) to allow checking V2 specific expectations and timing. This can be removed once all projects are migrated to V2.Adds cache key edge cases which includes cache keys that cannot be purged with Smart CDN V1. These tests fail against V1 projects and pass when run on projects using Smart CDN V2.