Pin file-api as a runtime dep of file extracts (flaky test fix)#4938
Pin file-api as a runtime dep of file extracts (flaky test fix)#4938habdelra wants to merge 1 commit into
Conversation
The file-extract route's runtime-dep tracker was missing
`${baseRealm.url}file-api` whenever matrix-service's
`importResource(() => '…/file-api')` did not happen to fire inside the
route's active tracker context — a microtask-scheduling race that
broke after a `BrowserManager.restartBrowser()` between tests.
Explicitly importing the URL inside the file-extract route's
`withRuntimeDependencyTrackingContext` makes the dep deterministic
and is scoped to the file-extract path only, so card prerenders are
not affected. Adds a console.warn diagnostic that fires if the URL
still slips out of the snapshot.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Preview deploymentsHost Test Results 1 files 1 suites 1h 49m 50s ⏱️ Results for commit 2f6ca5b. For more details on these errors, see this check. Realm Server Test Results 1 files 1 suites 10m 15s ⏱️ Results for commit 2f6ca5b. |
There was a problem hiding this comment.
Pull request overview
This PR makes runtime dependency tracking for file extracts deterministic by explicitly importing the base realm file-api module within the file-extract route’s dependency-tracking context, addressing an intermittent prerender test failure where file-api sometimes failed to appear in the extracted deps.
Changes:
- Import
${baseRealm.url}file-apiinsidewithRuntimeDependencyTrackingContextso it is always recorded as a runtime dependency for file extracts. - Add a diagnostic
console.warniffile-apiis still missing from the merged dependency snapshot after the explicit import.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Closing — moving the same fix into #4934 directly. The failure is deterministic on that branch (4/4 recent RS shard 1 runs failed on |
Problem
prerendering-test.ts > prerender - non-mutating tests > runner behavior > file prerender returns extracted metadataintermittently fails on the assertion:Most recent failure: https://github.com/cardstack/boxel/actions/runs/26289527361/job/77386270791
The file-extract pipeline only natively imports
${baseRealm.url}card-api(becausebaseFileRef.moduleresolves there — that's where theFileDefclass actually lives). The public${baseRealm.url}file-apiURL — which is what the indexer keys on when invalidating file extracts — landed indepsonly because matrix-service'sfileAPIModule = importResource(() => '…/file-api')happened to callloader.import('file-api')synchronously inside the activewithRuntimeDependencyTrackingContextwindow.Whether that import landed inside the window was a microtask-scheduling race. It was reliable on a fresh page but flaky after a
BrowserManager.restartBrowser()(e.g., from a preceding test likeconcurrent restart coalescing), where the matrix-service resource fires either too early (before the route starts the session) or too late (afterextract()resolves).Prior art
PR #4875 attempted to fix this by pinning the imports in
RenderRoute.#buildModel, but that ran the imports for every render — card prerenders too — and was reverted because it introduced cross-test instability.Solution
Pin
loader.import('${baseRealm.url}file-api')only inside the file-extract route'swithRuntimeDependencyTrackingContext. This makes the dep deterministic for file extracts and is invisible to the card-prerender path, so it can't reintroduce the destabilisation that closed #4875.Adds a
console.warndiagnostic that fires iffile-apiis still missing from the snapshot after the explicit import — insurance in case the tracker session is ever closed early or the URL is rewritten.Files
packages/host/app/routes/render/file-extract.tsTest plan
prerendering-test.ts(the broader test module)