Skip to content

βœ…πŸ€– add grapher config endpoint e2e tests with local R2 - #6196

Merged
danyx23 merged 2 commits into
masterfrom
cf-workers-vitest-r2-integration
Mar 6, 2026
Merged

βœ…πŸ€– add grapher config endpoint e2e tests with local R2#6196
danyx23 merged 2 commits into
masterfrom
cf-workers-vitest-r2-integration

Conversation

@danyx23

@danyx23 danyx23 commented Mar 6, 2026

Copy link
Copy Markdown
Member

Context

This PR adds end-to-end testing infrastructure for the grapher config R2 functionality using Wrangler's local development capabilities.

Testing guidance

Run the new e2e tests to verify R2 bucket functionality:

yarn test:functions:e2e-r2

The tests verify:

  • Grapher config retrieval from primary R2 bucket
  • ETag-based caching with 304 responses for unchanged configs
  • Fallback to secondary R2 bucket when primary bucket misses
  • 404 responses when configs are missing from both buckets
  • Cache control headers when nocache parameter is present

danyx23 commented Mar 6, 2026

Copy link
Copy Markdown
Member Author

@danyx23
danyx23 marked this pull request as ready for review March 6, 2026 08:18
@owidbot

owidbot commented Mar 6, 2026

Copy link
Copy Markdown
Contributor

Quick links (staging server):

Site Dev Site Preview Admin Wizard Docs

Login: ssh owid@staging-site-cf-workers-vitest-r2-integra

Archive:
SVG tester:

Number of differences (graphers): 0 βœ…
Number of differences (grapher views): skipped
Number of differences (mdims): skipped
Number of differences (explorers): skipped
Number of differences (thumbnails): skipped

Edited: 2026-03-06 08:24:32 UTC
Execution time: 1.47 seconds

@ikesau ikesau left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! just a few suggestions

read through the code then ran each test with logging enabled and changed things to make sure the tests failed in the expected ways.

return context as unknown as Parameters<typeof grapherOnRequest>[0]
}

function makeMultiDimContext(request: Request, env: Env, slug: string) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no tests using the multi-dim path, so this code is redundant?

}

function makeGrapherContext(request: Request, env: Env) {
const envWithAssets = env.ASSETS

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly, unstable_startWorker doesn't inject ASSETS so I'm not sure what the point of this ternary is.

expect(second.status).toBe(304)
})

it("falls back to fallback R2 bucket when primary misses", async () => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one feels like it's testing seedR2 as much as it's testing our worker logic.

It's probably fine, but you could maybe also assert that the primary bucket is empty too.

danyx23 commented Mar 6, 2026

Copy link
Copy Markdown
Member Author

Merge activity

  • Mar 6, 1:07 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Mar 6, 1:10 PM UTC: Graphite rebased this pull request as part of a merge.
  • Mar 6, 1:11 PM UTC: @danyx23 merged this pull request with Graphite.

@danyx23
danyx23 changed the base branch from cf-use-r2-bindings to graphite-base/6196 March 6, 2026 13:08
@danyx23
danyx23 changed the base branch from graphite-base/6196 to master March 6, 2026 13:09
danyx23 added 2 commits March 6, 2026 13:10
- add a worker-runtime e2e test suite for /grapher/:slug.config.json
- seed local Miniflare R2 buckets with a real life-expectancy config fixture
- cover primary bucket fetch, ETag 304, fallback bucket, 404, and nocache behavior
- use a dedicated wrangler e2e config with local-only R2 bindings (no remote: true)
- simplify test worker context by always injecting a test ASSETS stub
- add a test-only r2-has-key endpoint for assertions
- strengthen fallback test to assert key is absent in primary and present in fallback before fetch
@danyx23
danyx23 force-pushed the cf-workers-vitest-r2-integration branch from 971882e to 2c4a241 Compare March 6, 2026 13:10
@danyx23
danyx23 merged commit 9fa52f3 into master Mar 6, 2026
22 of 24 checks passed
@danyx23
danyx23 deleted the cf-workers-vitest-r2-integration branch March 6, 2026 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants