E2E: one-time global auth before test start#7272
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
76afe7f to
5f5c9e9
Compare
There was a problem hiding this comment.
Pull request overview
Introduces a Playwright globalSetup flow to authenticate the Shopify CLI and browser once per test run, then reuse the resulting CLI session files and browser storageState across worker-scoped fixtures.
Changes:
- Added
setup/global-auth.tsglobal setup to perform one-time CLI OAuth login and persist browser storage state. - Updated worker fixtures to reuse global session artifacts (copy XDG auth dirs + load
storageState) instead of re-authenticating. - Added a
globalLog()helper for pre-worker logging gated behindDEBUG=1.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/e2e/setup/global-auth.ts | New global setup that performs one-time login and writes reusable session artifacts. |
| packages/e2e/setup/auth.ts | Reuses global CLI session by copying XDG dirs; retains fallback per-worker login. |
| packages/e2e/setup/browser.ts | Loads Playwright storageState from global setup when available. |
| packages/e2e/setup/env.ts | Adds globalLog() for debug logging during global setup. |
| packages/e2e/playwright.config.ts | Registers the new Playwright globalSetup. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
d613bd8 to
3c8cf0e
Compare
ryancbahan
left a comment
There was a problem hiding this comment.
The idea here is great! I'd encourage you to consider how other libraries and tools implement persistence between runs/manage sessions, though. This is a problem that has a lot of prior art to lean on. I don't think we'll end up needing multiple tmp dirs per-state. And I think some clarity in the pr description around choice of state prsistence and caching approach is important here.
3c8cf0e to
121f09a
Compare
121f09a to
cb219bf
Compare
|
@ryancbahan Thanks for the feedback! I've updated the PR description with a "Design decisions" section covering the persistence approach. Please let me know if it’s still unclear. Code changes based on this review:
Things I kept:
More details in the updated PR description. |

WHY are these changes introduced?
E2E tests currently authenticate the CLI and browser per worker on every test run. This PR centralizes authentication into a single
globalSetupstep that runs once before tests start.This lays the foundation for:
admin.shopify.comto create dev stores via the store creation formWHAT is this pull request doing?
Adds a Playwright
globalSetupthat authenticates once before tests start, then reuses the session:setup/global-auth.ts): Spawnsshopify auth loginvia PTY, completes OAuth in a headless browser (with passkey/WebAuthn bypass), waits for "Logged in"admin.shopify.comanddev.shopify.comto establish cookies for both domains (not justaccounts.shopify.com)setup/auth.ts): Copies the pre-authenticated CLI session files (XDG dirs) and loads browserstorageState— no re-authentication neededAlso includes a CodeQL fix: URL checks for
accounts.shopify.comredirects now usenew URL().hostnamecomparison instead of substring matching.Design decisions: session persistence and caching
Approach: Follows Playwright's recommended
storageStatepattern — global setup authenticates once and saves browser cookies to a JSON file. Workers load the saved state into their browser context.Session caching across runs (local dev only):
Before re-authenticating,
globalSetupchecks if a valid cached session exists from a previous run by loading the savedstorageStateand verifying the browser is still logged intoadmin.shopify.com. If valid, skips the full OAuth flow (~30s → ~3s). If expired, re-authenticates and overwrites the cache. On CI (fresh runner each time), there is no cache, so it always authenticates fresh. Caching auth tokens in GitHub Actions cache was considered but rejected since this is a public repo — storing OAuth tokens in GitHub's cache storage is a security risk.Directory structure:
global-auth/: Stable name (not random), reused across runs. All auth state in one place — no scattered files.mkdtemp, isolated XDG dirs so parallel workers don't corrupt each other's CLI state. Workers copy CLI tokens fromglobal-auth/into their own dir at startup.Cross-platform note: On macOS, the CLI's
confpackage ignores XDG env vars and writes to~/Library/Preferences/. The XDG dirs inglobal-auth/are only populated on Linux. BrowserstorageStateworks on all platforms.Files changed:
setup/global-auth.tssetup/auth.tssetup/browser.tsstorageStatefrom global setupsetup/env.tsglobalLog()helper for pre-test loggingplaywright.config.tsglobalSetupentryHow to test your changes?
Example: session caching saves ~30-40s on subsequent runs
First run — full auth (~1.5 min total):
Second run — cached session (~48s total, auth skipped):
Checklist
pnpm changeset add