Skip to content

Commit 032e4d8

Browse files
committed
fix(e2e): match cancelled RSC fetches by parsed origin and keep a failed paste proof's page
1 parent 85d5a12 commit 032e4d8

1 file changed

Lines changed: 17 additions & 9 deletions

File tree

‎apps/sim/scripts/test-markdown-viewer-e2e.ts‎

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -187,17 +187,23 @@ async function check(name: string, run: () => Promise<void>, page?: Page) {
187187
}
188188
}
189189

190+
const CANCELLED_FETCH = / due to access control checks\.$/
191+
190192
/**
191193
* WebKit rejects a fetch the page cancels by navigating away, such as a Next.js RSC prefetch, with
192-
* "... due to access control checks.", and the router leaves that rejection unhandled. For a
194+
* "<request> due to access control checks.", and the router leaves that rejection unhandled. For a
193195
* same-origin RSC request that is a cancellation, never an access failure.
194196
*/
195197
function isCancelledRscFetch(message: string): boolean {
196-
return (
197-
message.endsWith(' due to access control checks.') &&
198-
message.includes(`${base.host}/`) &&
199-
message.includes('_rsc=')
200-
)
198+
if (!CANCELLED_FETCH.test(message)) return false
199+
// WebKit names the request as `/host:port/path?query`, without its scheme.
200+
const target = message.replace(CANCELLED_FETCH, '').split(' ').pop() ?? ''
201+
try {
202+
const url = new URL(target.startsWith('/') ? `${base.protocol}/${target}` : target)
203+
return url.origin === base.origin && url.searchParams.has('_rsc')
204+
} catch {
205+
return false
206+
}
201207
}
202208

203209
async function wideTableProof(page: Page) {
@@ -445,6 +451,7 @@ async function provePastePersistence(page: Page, browserName: string) {
445451
const pastedShareToken = generateShortId()
446452
const readPasteSource = async () =>
447453
(await request(`/api/files/public/${pastedShareToken}/content`)).text()
454+
let proved = false
448455
try {
449456
await sql`insert into public_share (id, resource_type, resource_id, entity_type, entity_id, workspace_id, created_by, token) values (${pastedShareId}, 'file', ${pastedFileId}, 'workspace', ${workspaceId}, ${workspaceId}, ${userId}, ${pastedShareToken})`
450457
await page.goto(new URL(`/workspace/${workspaceId}/files/${pastedFileId}`, base).href, {
@@ -589,11 +596,12 @@ async function provePastePersistence(page: Page, browserName: string) {
589596
afterLocalEdit.includes(`${marker} measure<br>`),
590597
'External update lost the pasted table'
591598
)
599+
proved = true
592600
} finally {
593601
try {
594-
// An editor left open on the file refetches it after the delete, and the next check on this
595-
// page would record that 404 as its own browser error.
596-
await page.goto('about:blank')
602+
// Leave the file before deleting it, or the open editor refetches it and the next check on
603+
// this page records that 404 as its own. A failed proof keeps the page for its screenshot.
604+
if (proved) await page.goto('about:blank')
597605
await request(`/api/workspaces/${workspaceId}/files/${pastedFileId}`, undefined, 'DELETE')
598606
} finally {
599607
await sql`delete from public_share where id=${pastedShareId}`

0 commit comments

Comments
 (0)