From 448ef93938e2dd77f52f2fd029f066b1c8686fdf Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Wed, 28 Oct 2026 03:06:24 -0700 Subject: [PATCH] test(e2e): retry the PTY write spy's main-process evaluates on transient CDP failures (#34912) The spy already retried its install through retryTransientMainEvaluate, but its reads, clear and delay setter did not, so a 'Resulting promise was garbage collected' (playwright#33737) failed a passing Windows WSL paste test. --- tests/e2e/helpers/terminal-pty-write-spy.ts | 45 ++++++++++++--------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/tests/e2e/helpers/terminal-pty-write-spy.ts b/tests/e2e/helpers/terminal-pty-write-spy.ts index 68295c08e61..0b1b8206971 100644 --- a/tests/e2e/helpers/terminal-pty-write-spy.ts +++ b/tests/e2e/helpers/terminal-pty-write-spy.ts @@ -45,37 +45,46 @@ export async function installTerminalPtyWriteSpy(app: ElectronApplication): Prom ) } +// Idempotent main-process reads and a clear: safe to repeat after a transient CDP failure. export async function clearTerminalPtyWriteLog(app: ElectronApplication): Promise { - await app.evaluate(() => { - const global = globalThis as unknown as { __terminalPtyWriteLog?: PtyWriteLogEntry[] } - if (global.__terminalPtyWriteLog) { - global.__terminalPtyWriteLog.length = 0 - } - }) + await retryTransientMainEvaluate(() => + app.evaluate(() => { + const global = globalThis as unknown as { __terminalPtyWriteLog?: PtyWriteLogEntry[] } + if (global.__terminalPtyWriteLog) { + global.__terminalPtyWriteLog.length = 0 + } + }) + ) } export async function readTerminalPtyWrites(app: ElectronApplication): Promise { - return app.evaluate(() => { - const global = globalThis as unknown as { __terminalPtyWriteLog?: PtyWriteLogEntry[] } - return (global.__terminalPtyWriteLog ?? []).map((entry) => entry.data) - }) + return retryTransientMainEvaluate(() => + app.evaluate(() => { + const global = globalThis as unknown as { __terminalPtyWriteLog?: PtyWriteLogEntry[] } + return (global.__terminalPtyWriteLog ?? []).map((entry) => entry.data) + }) + ) } export async function readTerminalPtyWriteEntries( app: ElectronApplication ): Promise { - return app.evaluate(() => { - const global = globalThis as unknown as { __terminalPtyWriteLog?: PtyWriteLogEntry[] } - return [...(global.__terminalPtyWriteLog ?? [])] - }) + return retryTransientMainEvaluate(() => + app.evaluate(() => { + const global = globalThis as unknown as { __terminalPtyWriteLog?: PtyWriteLogEntry[] } + return [...(global.__terminalPtyWriteLog ?? [])] + }) + ) } export async function setTerminalPtyWriteDelay( app: Pick, delayMs: number ): Promise { - await app.evaluate((_electron, nextDelayMs) => { - const global = globalThis as unknown as { __terminalPtyWriteDelayMs?: number } - global.__terminalPtyWriteDelayMs = Math.max(0, nextDelayMs) - }, delayMs) + await retryTransientMainEvaluate(() => + app.evaluate((_electron, nextDelayMs) => { + const global = globalThis as unknown as { __terminalPtyWriteDelayMs?: number } + global.__terminalPtyWriteDelayMs = Math.max(0, nextDelayMs) + }, delayMs) + ) }