host: Change tests to serve test realm fetches in-page - #5717
Open
backspace wants to merge 1 commit into
Open
Conversation
…rker Host tests serve http://test-realm/* URLs through a service worker that relays them to the in-browser mock realm. The worker only intercepts once it controls the page and its per-module activation has been acked, so a fetch issued before that window closes escapes to the real network and fails — test-realm is not a real host. When the fetch is fire-and-forget (a card component loading a realm's _types summary as it renders), the rejection surfaces as a QUnit global error and fails the whole shard rather than a single test. The test fetch wrapper now answers requests whose URL falls under a registered test realm via realm.maybeHandle. The registry is populated at realm construction, before any component can render, so this path has no startup window. A request the realm declines still falls through to the network, and non-fetch resources (images, workers) continue to rely on the service worker. Module-loading latency normally hides the race: base card modules are fetched and transpiled before their components can render, which takes long enough that the worker is ready. Anything that shortens that path re-exposes it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Contributor
backspace
marked this pull request as ready for review
August 7, 2026 22:59
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As the host test suite gets faster, there’s a race condition that has been increasing instability: the
test-realmservice worker can only intercept requests once it’s been set up and activated, soFailed to fetchhappens with theRETRY_PATTERNuntil it comes up. In #5653, where I experimented with bundling@cardstack/baseinstead of as a realm, theFailed to fetchwent from ≈400/run to ≈2500/run.This serves test realm directly instead of through a service worker. The tests that work with
img,audio,videoetc do exercise the service worker so this test-only override doesn’t mean the worker has no test coverage.