From 4f731dddcee7970f50183b2b5cb202d43666e577 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 17:01:13 +0000 Subject: [PATCH] Skip the SSO E2E tests when Tsinghua's site drops out mid-test The @network SSO tests checked that id.tsinghua.edu.cn answered before each test, but the site can stop answering a few seconds later, so the web view showed Chromium's error page (chromewebdata) and the test failed instead of skipping. They now record the web view's main frame load failures and skip when its load of the login page fails with a network error (time out, connection or host name error), as the check before the test does. Other failures, such as a load the app blocked or a certificate error, still fail. Co-Authored-By: Claude Opus 5.5 --- electron/e2e/sso.e2e.ts | 92 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 85 insertions(+), 7 deletions(-) diff --git a/electron/e2e/sso.e2e.ts b/electron/e2e/sso.e2e.ts index 6b04867f1..024dee44a 100644 --- a/electron/e2e/sso.e2e.ts +++ b/electron/e2e/sso.e2e.ts @@ -4,7 +4,8 @@ // confirmation, and the page's script fills in learnX's form there. Nothing // is sent to Tsinghua: the made-up account is never submitted. Needs // id.tsinghua.edu.cn, which CI's runners abroad can't always reach: tagged -// @network, and skipped (not failed) when it doesn't answer. +// @network, and skipped (not failed) when it doesn't answer, whether before +// the test or when the web view loads it. import type { Page } from '@playwright/test'; import { expect, test } from './fixtures.ts'; import { exact } from './maestroEnv.ts'; @@ -42,10 +43,91 @@ const guest = (window: Page, script: string) => } }, script); +interface LoadFailure { + code: number; + description: string; + url: string; +} + +/** + * Keeps the web view's failed main frame loads in the page, from the + * `did-fail-load` events Electron sends the . They don't bubble, so + * a capturing listener on the document hears them. Call it before the web + * view opens. + */ +const recordLoadFailures = (window: Page) => + window.evaluate(() => { + const failures: LoadFailure[] = []; + Object.assign(globalThis, { e2eLoadFailures: failures }); + document.addEventListener( + 'did-fail-load', + event => { + const { errorCode, errorDescription, validatedURL, isMainFrame } = + event as Event & { + errorCode: number; + errorDescription: string; + validatedURL: string; + isMainFrame: boolean; + }; + if (isMainFrame) { + failures.push({ + code: errorCode, + description: errorDescription, + url: validatedURL, + }); + } + }, + true, + ); + }); + +/** + * Whether a Chromium net error is the network's: a time out (-7), a changed + * network (-21), a connection or host name error (-100 to -199) or an empty + * answer (-324). Not a load the app stopped (-3) or blocked (-20), nor a + * certificate (-2xx) or other HTTP (-3xx) error. + */ +const isNetworkError = (code: number) => + code === -7 || + code === -21 || + code === -324 || + (code <= -100 && code >= -199); + +/** + * Waits for the web view to show Tsinghua's login page. When the web view + * couldn't load it for the network's sake (recordLoadFailures), the site + * stopped answering after the check before the test, so this skips as that + * check does. + */ +const expectSSOPage = async (window: Page) => { + let failure: LoadFailure | undefined; + await expect + .poll( + async () => { + const failures = await window.evaluate( + () => + (globalThis as unknown as { e2eLoadFailures: LoadFailure[] }) + .e2eLoadFailures, + ); + failure = failures.find( + ({ code, url }) => url.startsWith(SSO) && isNetworkError(code), + ); + return failure ? 'failed' : guest(window, 'location.hostname'); + }, + { timeout: 30_000 }, + ) + .toMatch(/^(?:id\.tsinghua\.edu\.cn|failed)$/); + test.skip( + failure !== undefined, + `${SSO} stopped answering: ${failure?.description} (${failure?.code})`, + ); +}; + const fillLogin = async (window: Page) => { await window.getByTestId('welcome-continue').click(); await window.getByTestId('login-username').fill(NOBODY); await window.getByTestId('login-password').fill('not-a-password'); + await recordLoadFailures(window); }; test( @@ -56,9 +138,7 @@ test( await window.getByRole('button', { name: exact('T_login') }).click(); await window.getByRole('button', { name: exact('T_continue') }).click(); - await expect - .poll(() => guest(window, 'location.hostname'), { timeout: 30_000 }) - .toBe('id.tsinghua.edu.cn'); + await expectSSOPage(window); // learnX's script filled in the form, which stays unsent. await expect .poll( @@ -96,8 +176,6 @@ test( await expect(window.locator('webview')).toHaveCount(0); // Its own press does. await window.keyboard.press('Enter'); - await expect - .poll(() => guest(window, 'location.hostname'), { timeout: 30_000 }) - .toBe('id.tsinghua.edu.cn'); + await expectSSOPage(window); }, );