0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-11 02:59:07 +08:00
discourse/.github/workflows
Alan Guo Xiang Tan 9e83a1b304
DEV: Reuse the Playwright browser context between system specs (#41304)
This PR adds a `CAPYBARA_PLAYWRIGHT_SOFT_RESET` env flag which reuses
the Playwright browser context between system specs so each example no
longer pays the full bundle load cost.

`capybara-playwright-driver` already keeps the browser process alive,
but its reset closes the context after every example. That throws away
the context-level HTTP cache and other browser work cached with the
context, so the next example pays the bundle load cost again.

Key changes:
* Add `PlaywrightSoftReset` in `spec/support/system/capybara_patches.rb`
so `Capybara::Playwright::Driver#reset!` clears storage, cookies, and
permissions instead of closing the context. This keeps per-example
isolation while leaving the browser caches warm.
* Detect installed fake clocks by probing `setTimeout.toString()` on the
fresh page during the soft reset. Playwright's clock is context-scoped
and cannot be uninstalled, so any example that installed one (via
`BrowserTime.freeze` or `pw_page.clock.install` directly) automatically
gets a full context reset without having to declare anything.
* Detect downloads by listening for the context's `download` event.
Contexts that produced downloads fall back to a full reset so
Playwright's own artifact lifecycle handles cleanup, avoiding races with
reused contexts.
* Clear `ExtraLocalesController`'s bundle digest cache in `TestSetup`
whenever leftover translation overrides are detected (the same branch
that already calls `I18n.reload!`). Overrides change locale bundle
contents but specs that create them with `create!`/`update_columns`
bypass the digest invalidation that `TranslationOverride.upsert!`
performs, so a warm HTTP cache could serve stale bundles. A fresh digest
changes the bundle URL, which bypasses every cache naturally.
* Store downloads under a worker-local `Downloads::FOLDER` so per-worker
cleanup cannot delete another parallel worker's artifacts.
* Block service workers in system specs (`serviceWorkers: "block"`).
Letting each example register a service worker that the soft reset then
force-clears caused mass spec timeouts on CI. The exact cause requires
further investigation, but system specs currently do not rely on service
workers so blocking them is an acceptable trade-off.
* Measure the impact on a 16-vCPU DO droplet over three rounds, where
the core system suite dropped from ~843s to ~721s (~14.5%).

The optimization is opt-in via `CAPYBARA_PLAYWRIGHT_SOFT_RESET=1`, which
CI sets only for the core system and chat plugin system jobs while the
optimization proves itself.
2026-07-03 09:07:32 +08:00
..
backport.yml DEPS: Bump actions/checkout from 6 to 7 (#41156) 2026-06-24 21:54:51 +02:00
check-pr-body.yml DEPS: Bump actions/checkout from 6 to 7 (#41156) 2026-06-24 21:54:51 +02:00
dependabot-bundler-checksums.yml DEPS: Bump actions/checkout from 6 to 7 (#41156) 2026-06-24 21:54:51 +02:00
dependabot-pnpm-dedupe.yml DEPS: Bump actions/checkout from 6 to 7 (#41156) 2026-06-24 21:54:51 +02:00
developer-docs-lint.yml DEPS: Bump actions/checkout from 6 to 7 (#41156) 2026-06-24 21:54:51 +02:00
developer-docs-publish.yml DEPS: Bump actions/checkout from 6 to 7 (#41156) 2026-06-24 21:54:51 +02:00
labeler.yml Build(deps): Bump actions/labeler from 5 to 6 (#34761) 2025-09-15 17:58:31 +02:00
licenses.yml DEPS: Bump actions/checkout from 6 to 7 (#41156) 2026-06-24 21:54:51 +02:00
linting.yml DEPS: Bump actions/checkout from 6 to 7 (#41156) 2026-06-24 21:54:51 +02:00
migration-tests.yml DEV: Run the migrations gems CI job on self-hosted runners 2026-06-25 17:45:23 +02:00
publish-assets.yml DEPS: Bump actions/checkout from 6 to 7 (#41156) 2026-06-24 21:54:51 +02:00
publish-types.yml DEPS: Bump actions/checkout from 6 to 7 (#41156) 2026-06-24 21:54:51 +02:00
release-branch-handler.yml DEPS: Bump actions/checkout from 6 to 7 (#41156) 2026-06-24 21:54:51 +02:00
release-handler.yml DEPS: Bump actions/checkout from 6 to 7 (#41156) 2026-06-24 21:54:51 +02:00
release-notes.yml DEPS: Bump actions/checkout from 6 to 7 (#41156) 2026-06-24 21:54:51 +02:00
release-prepare-latest-bump.yml DEPS: Bump actions/checkout from 6 to 7 (#41156) 2026-06-24 21:54:51 +02:00
stale-pr-closer.yml Build(deps): Bump actions/stale from 9 to 10 (#34762) 2025-09-15 17:56:44 +02:00
tests.yml DEV: Reuse the Playwright browser context between system specs (#41304) 2026-07-03 09:07:32 +08:00
upcoming-change-status-bump.yml DEPS: Bump actions/checkout from 6 to 7 (#41156) 2026-06-24 21:54:51 +02:00