Files
orca/tests/e2e/terminal-pane-layout-resize.spec.ts
Neil 9367169888 refactor(tests): split every oversized test file off the max-lines suppression list (#14728)
* refactor(tests): split oversized test files off the max-lines suppression list

Every `*.test.ts`/`*.spec.ts` that carried an `eslint/oxlint-disable max-lines`
directive is now split into focused, behavior-scoped suites that fit the 800-line
test budget, with shared setup extracted into co-located `*-test-harness.ts` /
`*-test-fixtures.ts` modules (300-line budget). 83 files became ~930; the largest
output is 797 effective lines. `orca-runtime.test.ts` is intentionally untouched.

Test bodies were moved by scripted line-range slicing rather than retyped, so
assertions are byte-identical. The only permitted body edits were mechanical
rebinding where a shared value moved into a harness (e.g. `tmpHome` ->
`homes.tmpHome`).

Registries that enumerate test files were updated in lockstep:
- config/max-lines-baseline.txt: pruned 341 -> 258 entries (all 83 removed).
- config/reliability-gates.jsonc: 33 gates repointed at the split files, with
  assertionRefs split per file where a gate's coverage now spans several.
- .github/workflows/pr.yml: the real-zsh lane now lists the 4 split files that
  actually exercise zsh, so they keep running in the dedicated shell lane.

Also renamed agent-hooks `server-test-fixtures.ts` to `server.test-fixtures.ts`
so the global-fetch call-site audit keeps skipping it, and added `.js` extensions
to the CLI suites' dynamic harness imports (node16 resolution) to unbreak
`build:cli`.

Verification: full suite 52,449 passing vs 52,448 at baseline with zero
assertions lost; `pnpm lint`, `pnpm typecheck`, and `pnpm build:cli` all exit 0;
the terminal-pane e2e spec runs 31/31 headless.

* refactor(tests): split hook-idle arbitration suite that oxfmt pushed over budget

The pre-commit oxfmt pass reflowed pty-connection-hook-idle-arbitration.test.ts
to 811 effective lines, 11 over the test budget. Split the hook-completion side
effect and replacement-agent veto cases into their own suite; both files now sit
well under the cap and the 15 tests are unchanged.

* test: port upstream test changes into the split files after rebase

Rebasing onto main surfaced 27 tests that main had added to files this branch
deleted, plus edits to tests that had already moved. Taking the deletion side of
those modify/delete conflicts would have dropped that coverage silently, so each
upstream change is ported into the split file that now owns the behavior — for
example main's six orchestration mailbox tests land across orchestration-runs,
-send, and -check.

Also repoints `orchestration.notification-mailbox-consistency`, a gate main added
after this branch's gate remap, at those same three split files, and re-prunes
the max-lines baseline against main's (257 entries).

Verified: all 27 upstream test titles present; full suite 52,761 passing with the
only diff vs baseline being 12 tests main itself removed and 3 that moved from
skipped to passing; lint and typecheck exit 0.

* fix(test): flush pending continuations before tearing down terminal test globals

CI shard 5/16 failed on both Node 24 and 26 with `ReferenceError: window is not
defined` from pty-connection.ts, surfacing through
pty-connection-daemon-snapshot-replay.test.ts.

The reattach/settle chains `await` a real promise and then touch `window.api`.
Under fake timers those continuations cannot run, so they only become schedulable
once restoreTerminalTestGlobals() switches back to real timers — which previously
happened immediately before `delete globalThis.window`, so a late continuation
threw and failed the whole file. Flush async ticks in that window instead.

This is latent in the source rather than new: the pre-split 25k-line file kept
running other tests after these, which gave the chains time to settle before
teardown. Splitting the file moved teardown directly behind them.

* fix(test): keep an inert window after terminal test teardown instead of deleting it

The async-tick flush was not enough: the reattach/settle chain can resolve after
teardown regardless of how long we drain, so CI shard 5/16 still failed with
`ReferenceError: window is not defined` from pty-connection.ts.

A real renderer never loses `window`, so deleting it was the artificial part.
Swap in an inert proxy whose properties resolve to callables and whose calls
resolve to undefined, making a late `window.api.pty.*` call a harmless no-op.
The next test replaces it wholesale via installTerminalTestGlobals(), and no test
asserts that `window` is absent.
2026-08-15 00:54:20 -07:00

202 lines
7.6 KiB
TypeScript

/**
* E2E tests for pane layout chrome: the header split button, the divider that
* splitting creates, drag resizing, and the space a closed pane gives back.
*
* User Prompt:
* - resizing terminal panes works
* - closing panes works
*/
import { test, expect } from './helpers/orca-app'
import {
closeActiveTerminalPane,
countVisibleTerminalPanes,
splitActiveTerminalPane,
waitForPaneIdentitySnapshot,
waitForPaneCount,
sendToTerminal
} from './helpers/terminal'
import { readVisiblePaneContents } from './helpers/terminal-pane-geometry'
import { registerTerminalPaneMountReadiness } from './helpers/terminal-pane-mount-readiness'
// Why: keep the suite serial so the headful pane tests never ask Playwright to
// open multiple visible Electron windows at once.
test.describe.configure({ mode: 'serial' })
test.describe('Terminal Panes', () => {
registerTerminalPaneMountReadiness()
test('Always-on pane header split button hover stays transparent', async ({ orcaPage }) => {
const splitButton = orcaPage.getByRole('button', { name: 'Split Terminal Right' })
await expect(splitButton).toBeVisible()
await splitButton.hover()
const hoverStyle = await splitButton.evaluate((element) => {
const style = getComputedStyle(element)
return {
backgroundColor: style.backgroundColor,
opacity: style.opacity
}
})
expect(hoverStyle.backgroundColor).toBe('rgba(0, 0, 0, 0)')
expect(Number(hoverStyle.opacity)).toBeGreaterThan(0.9)
})
/**
* User Prompt:
* - resizing terminal panes works
*/
test('shows a pane divider after splitting', async ({ orcaPage }) => {
// Why: headless Playwright cannot exercise the real pointer-capture resize
// path reliably, so the default suite only verifies the precondition for
// resizing: splitting creates a visible divider for the active layout.
const panesBefore = await countVisibleTerminalPanes(orcaPage)
await splitActiveTerminalPane(orcaPage, 'vertical')
await waitForPaneCount(orcaPage, panesBefore + 1)
await expect(orcaPage.locator('.pane-divider.is-vertical').first()).toBeVisible({
timeout: 3_000
})
})
/**
* User Prompt:
* - resizing terminal panes works (headful variant)
*
* Why this test must be headful: the pane divider's drag handler calls
* setPointerCapture(e.pointerId) on pointerdown. Pointer capture requires
* a valid pointer ID from a real pointing-device event, which Playwright's
* mouse API only produces when the Electron window is visible. In headless
* mode setPointerCapture silently fails, pointermove never fires on the
* divider, and the resize has no effect. Run with:
* ORCA_E2E_HEADFUL=1 pnpm run test:e2e
*/
test('@headful can resize terminal panes by real mouse drag', async ({ orcaPage }) => {
// Split the terminal to create a resizable divider
const panesBefore = await countVisibleTerminalPanes(orcaPage)
await splitActiveTerminalPane(orcaPage, 'vertical')
await waitForPaneCount(orcaPage, panesBefore + 1)
// Get the pane widths before resize
const paneWidthsBefore = await orcaPage.evaluate(() => {
const xterms = document.querySelectorAll('.xterm')
return Array.from(xterms)
.filter((x) => (x as HTMLElement).offsetParent !== null)
.map((x) => (x as HTMLElement).getBoundingClientRect().width)
})
expect(paneWidthsBefore.length).toBeGreaterThanOrEqual(2)
// Find the vertical pane divider and drag it
const divider = orcaPage.locator('.pane-divider.is-vertical').first()
await expect(divider).toBeVisible({ timeout: 3_000 })
const box = await divider.boundingBox()
expect(box).not.toBeNull()
// Drag the divider 150px to the right to resize panes
const startX = box!.x + box!.width / 2
const startY = box!.y + box!.height / 2
await orcaPage.mouse.move(startX, startY)
await orcaPage.mouse.down()
await orcaPage.mouse.move(startX + 150, startY, { steps: 20 })
await orcaPage.mouse.up()
// Verify pane widths changed
await expect
.poll(
async () => {
const widthsAfter = await orcaPage.evaluate(() => {
const xterms = document.querySelectorAll('.xterm')
return Array.from(xterms)
.filter((x) => (x as HTMLElement).offsetParent !== null)
.map((x) => (x as HTMLElement).getBoundingClientRect().width)
})
if (widthsAfter.length < 2) {
return false
}
return paneWidthsBefore.some((w, i) => Math.abs(w - widthsAfter[i]) > 20)
},
{ timeout: 5_000, message: 'Pane widths did not change after dragging divider' }
)
.toBe(true)
})
test('@headful resizing split panes forwards only the settled PTY size', async ({ orcaPage }) => {
await splitActiveTerminalPane(orcaPage, 'vertical')
const snapshot = await waitForPaneIdentitySnapshot(orcaPage, 2)
const ptyIds = snapshot.panes
.map((pane) => pane.ptyId)
.filter((ptyId): ptyId is string => Boolean(ptyId))
for (const ptyId of ptyIds) {
await sendToTerminal(
orcaPage,
ptyId,
"export PS1='ISSUE2910_PROMPT$ '; export PROMPT=\"$PS1\"; trap 'printf \"\\nISSUE2910_WINCH\\n\"' WINCH; clear; printf 'ISSUE2910_READY\\n'\r"
)
}
await expect
.poll(
async () =>
(await readVisiblePaneContents(orcaPage)).every((content) =>
content.includes('ISSUE2910_READY')
),
{ timeout: 10_000, message: 'Split panes did not receive resize-regression prompt setup' }
)
.toBe(true)
const divider = orcaPage.locator('.pane-divider.is-vertical').first()
await expect(divider).toBeVisible({ timeout: 3_000 })
const box = await divider.boundingBox()
expect(box).not.toBeNull()
const startX = box!.x + box!.width / 2
const startY = box!.y + box!.height / 2
await orcaPage.mouse.move(startX, startY)
await orcaPage.mouse.down()
await orcaPage.mouse.move(startX - 350, startY, { steps: 40 })
await orcaPage.mouse.move(startX + 250, startY, { steps: 40 })
await orcaPage.mouse.up()
await orcaPage.waitForTimeout(500)
const paneContents = await readVisiblePaneContents(orcaPage)
for (const content of paneContents) {
const promptRedraws = content.match(/ISSUE2910_PROMPT/g)?.length ?? 0
const winchNotifications = content.match(/ISSUE2910_WINCH/g)?.length ?? 0
expect(promptRedraws).toBeLessThanOrEqual(3)
expect(winchNotifications).toBeLessThanOrEqual(1)
}
})
/**
* User Prompt:
* - closing panes works
*/
test('closing a split pane removes it and remaining pane fills space', async ({ orcaPage }) => {
const panesBefore = await countVisibleTerminalPanes(orcaPage)
// Split the terminal
await splitActiveTerminalPane(orcaPage, 'vertical')
await waitForPaneCount(orcaPage, panesBefore + 1)
const panesAfterSplit = await countVisibleTerminalPanes(orcaPage)
expect(panesAfterSplit).toBeGreaterThanOrEqual(2)
await closeActiveTerminalPane(orcaPage)
await waitForPaneCount(orcaPage, panesAfterSplit - 1)
// The remaining pane should fill the available space
const paneWidth = await orcaPage.evaluate(() => {
const xterms = document.querySelectorAll('.xterm')
const visible = Array.from(xterms).find(
(x) => (x as HTMLElement).offsetParent !== null
) as HTMLElement | null
return visible?.getBoundingClientRect().width ?? 0
})
// Why: threshold is kept low to account for headless mode where the
// window is 1200px wide (not maximized) and the sidebar takes space.
expect(paneWidth).toBeGreaterThan(200)
})
})