Some checks failed
CI / Unit & Component Tests (pull_request) Failing after 1m56s
CI / OCR Service Tests (pull_request) Successful in 20s
CI / Backend Unit Tests (pull_request) Successful in 3m19s
CI / fail2ban Regex (pull_request) Successful in 41s
CI / Semgrep Security Scan (pull_request) Successful in 20s
CI / Compose Bucket Idempotency (pull_request) Successful in 1m1s
The backport of vitest PR #10267 (unroute-before-register guard that prevents orphan routes causing birpc teardown crashes) was made against 4.1.0. The dep bump moved the package to 4.1.6; patch-package refused to apply the stale file. Regenerated against the installed 4.1.6 — the fix is identical, adapted for the renamed idPreficates → idPredicates typo that upstream corrected in this version. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
63 lines
2.7 KiB
Diff
63 lines
2.7 KiB
Diff
diff --git a/node_modules/@vitest/browser-playwright/dist/index.js b/node_modules/@vitest/browser-playwright/dist/index.js
|
|
index c01e754..f1bb7be 100644
|
|
--- a/node_modules/@vitest/browser-playwright/dist/index.js
|
|
+++ b/node_modules/@vitest/browser-playwright/dist/index.js
|
|
@@ -936,7 +936,7 @@ class PlaywrightBrowserProvider {
|
|
createMocker() {
|
|
const idPredicates = new Map();
|
|
const sessionIds = new Map();
|
|
- function createPredicate(sessionId, url) {
|
|
+ function createPredicate(url) {
|
|
const moduleUrl = new URL(url, "http://localhost");
|
|
const predicate = (url) => {
|
|
if (url.searchParams.has("_vitest_original")) {
|
|
@@ -961,11 +961,7 @@ class PlaywrightBrowserProvider {
|
|
}
|
|
return true;
|
|
};
|
|
- const ids = sessionIds.get(sessionId) || [];
|
|
- ids.push(moduleUrl.href);
|
|
- sessionIds.set(sessionId, ids);
|
|
- idPredicates.set(predicateKey(sessionId, moduleUrl.href), predicate);
|
|
- return predicate;
|
|
+ return { url: moduleUrl.href, predicate };
|
|
}
|
|
function predicateKey(sessionId, url) {
|
|
return `${sessionId}:${url}`;
|
|
@@ -973,7 +969,23 @@ class PlaywrightBrowserProvider {
|
|
return {
|
|
register: async (sessionId, module) => {
|
|
const page = this.getPage(sessionId);
|
|
- await page.context().route(createPredicate(sessionId, module.url), async (route) => {
|
|
+ const { url: moduleUrl, predicate } = createPredicate(module.url);
|
|
+ const key = predicateKey(sessionId, moduleUrl);
|
|
+ // Backport of vitest PR #10267: if a route handler is already
|
|
+ // registered for this resolved module URL in this session,
|
|
+ // unroute it before installing the new one. Without this guard,
|
|
+ // duplicate-id mocks (e.g. '$lib/foo.svelte' + '$lib/foo.svelte.js')
|
|
+ // leak an orphan route whose handler crashes after the next
|
|
+ // session's birpc channel closes.
|
|
+ const existingPredicate = idPredicates.get(key);
|
|
+ if (existingPredicate) {
|
|
+ await page.context().unroute(existingPredicate);
|
|
+ }
|
|
+ const ids = sessionIds.get(sessionId) ?? new Set();
|
|
+ ids.add(moduleUrl);
|
|
+ sessionIds.set(sessionId, ids);
|
|
+ idPredicates.set(key, predicate);
|
|
+ await page.context().route(predicate, async (route) => {
|
|
if (module.type === "manual") {
|
|
const exports$1 = Object.keys(await module.resolve());
|
|
const body = createManualModuleSource(module.url, exports$1);
|
|
@@ -1034,8 +1046,8 @@ class PlaywrightBrowserProvider {
|
|
},
|
|
clear: async (sessionId) => {
|
|
const page = this.getPage(sessionId);
|
|
- const ids = sessionIds.get(sessionId) || [];
|
|
- const promises = ids.map((id) => {
|
|
+ const ids = sessionIds.get(sessionId) ?? new Set();
|
|
+ const promises = [...ids].map((id) => {
|
|
const key = predicateKey(sessionId, id);
|
|
const predicate = idPredicates.get(key);
|
|
if (predicate) {
|