From 00a82505c46d3beb8d7af0df293e88cc363dd394 Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Wed, 7 Oct 2026 21:01:48 -0700 Subject: [PATCH] test: speed terminal comparisons and retry policy checks (#26396) --- .../daemon/serialize-grid-cell-descriptors.ts | 25 ++++++++++++++++++- .../electron-main-evaluate-retry.unit.test.ts | 16 +++++++++--- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/main/daemon/serialize-grid-cell-descriptors.ts b/src/main/daemon/serialize-grid-cell-descriptors.ts index 9adbbc6c694..9efc74221f7 100644 --- a/src/main/daemon/serialize-grid-cell-descriptors.ts +++ b/src/main/daemon/serialize-grid-cell-descriptors.ts @@ -132,6 +132,29 @@ function sameCellFields(expected: Cell, actual: Cell): boolean { ) } +// Match the frozen default-blank descriptor without formatting every trailing cell. +function isDefaultBlank(line: BufferLine | undefined, x: number, scratch: Cell): boolean { + if (!line || x >= line.length) { + return true + } + const cell = line.getCell(x, scratch) + if (!cell) { + return true + } + const chars = cell.getChars() + return ( + cell.getWidth() === 1 && + cell.getBgColorMode() === 0 && + cell.getBgColor() === -1 && + cell.isInverse() === 0 && + (chars === '' || + (chars === ' ' && + cell.isUnderline() === 0 && + cell.isStrikethrough() === 0 && + cell.isOverline() === 0)) + ) +} + function trimmedEnd( buffer: Buffer, start: number, @@ -143,7 +166,7 @@ function trimmedEnd( const line = buffer.getLine(end - 1) let blank = true for (let x = 0; x < cols; x++) { - if (cellDescriptor(line, x, cols, scratch) !== DEFAULT_BLANK) { + if (!isDefaultBlank(line, x, scratch)) { blank = false break } diff --git a/tests/e2e/helpers/electron-main-evaluate-retry.unit.test.ts b/tests/e2e/helpers/electron-main-evaluate-retry.unit.test.ts index c6735e2fd1f..95b5754e596 100644 --- a/tests/e2e/helpers/electron-main-evaluate-retry.unit.test.ts +++ b/tests/e2e/helpers/electron-main-evaluate-retry.unit.test.ts @@ -1,4 +1,4 @@ -import { describe, expect, it } from 'vitest' +import { afterEach, describe, expect, it, vi } from 'vitest' import { retryTransientMainEvaluate } from './electron-main-evaluate-retry' const transientMessages = [ @@ -6,6 +6,8 @@ const transientMessages = [ 'electronApplication.evaluate: Resulting promise was garbage collected.' ] +afterEach(() => vi.useRealTimers()) + describe('retryTransientMainEvaluate', () => { it('returns the first successful read without retrying', async () => { let calls = 0 @@ -19,8 +21,9 @@ describe('retryTransientMainEvaluate', () => { }) it.each(transientMessages)('retries a transient startup failure: %s', async (message) => { + vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] }) let calls = 0 - await expect( + const outcome = expect( retryTransientMainEvaluate(async () => { calls += 1 if (calls < 3) { @@ -29,6 +32,9 @@ describe('retryTransientMainEvaluate', () => { return '/isolated/home' }) ).resolves.toBe('/isolated/home') + void outcome.catch(() => undefined) + await vi.advanceTimersByTimeAsync(400) + await outcome expect(calls).toBe(3) }) @@ -46,13 +52,17 @@ describe('retryTransientMainEvaluate', () => { it.each(transientMessages)( 'bounds retries when evaluation keeps failing: %s', async (message) => { + vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] }) let calls = 0 - await expect( + const outcome = expect( retryTransientMainEvaluate(async () => { calls += 1 throw new Error(message) }) ).rejects.toThrow(message) + void outcome.catch(() => undefined) + await vi.advanceTimersByTimeAsync(800) + await outcome expect(calls).toBe(5) } )