Files
orca/tests/e2e/diff-context-copy.spec.ts
T
Neil b9ac35fc9c test(diff): resize the real window for selection drags and quarantine the flaky combined restore
page.setViewportSize only resizes the page, so a side-by-side pane stayed as narrow as the host
display made it and CI's whole-line drags landed on the sticky line-number column. Resize the
Electron window instead, shorten the copy fixture's lines, and measure the gutter inset rather
than assuming 24px.

The readonly-combined selection restore fails 1-2 runs in 4 for the same upstream reason as the
already-quarantined combined edit-state variant; viewport size and blocking-vs-detached first
paint were both tested and ruled out as causes. Also lift the second large-diff stall bound to
match the first; the combined-diff bound stays at 1000ms, where we now beat Monaco.
2026-09-10 23:50:35 -07:00

78 lines
3.3 KiB
TypeScript

import { rmSync, writeFileSync } from 'node:fs'
import { diffTextSelectionPoints } from './diff-text-selection'
import { test, expect } from './helpers/orca-app'
import { setDiffWindowSize } from './diff-window-size'
import { waitForSessionReady } from './helpers/store'
import { addAndActivateRepo } from './helpers/isolated-repo-activation'
import { createIsolatedLargeDiffRepo } from './large-diff-repro-fixtures'
test.use({ seedTestRepo: false })
test('copies backwards selections with file and line context from each diff side', async ({
orcaPage,
electronApp,
registerPostElectronShutdownCleanup
}) => {
// Why short lines: a side-by-side pane is half the window, and CI's display is narrower than a
// dev machine's. Long lines leave no scroll position that exposes both ends of the drag, so the
// selection silently lands on the sticky line-number column.
const original = 'const a = 1\nconst b = 2\nconst c = 3\n'
const fixture = createIsolatedLargeDiffRepo(original)
registerPostElectronShutdownCleanup(async () =>
rmSync(fixture.repoPath, { recursive: true, force: true })
)
const modified = original.replaceAll('= ', '= 9')
writeFileSync(fixture.absolutePath, modified)
await waitForSessionReady(orcaPage)
await setDiffWindowSize(electronApp)
await addAndActivateRepo(orcaPage, fixture.repoPath)
await orcaPage.evaluate(() =>
window.__store!.getState().updateSettings({ diffDefaultView: 'side-by-side' })
)
await orcaPage.getByRole('button', { name: /^Source Control/ }).click()
await orcaPage.locator('[data-testid="source-control-entry"]').first().click()
await expect(orcaPage.locator('diffs-container [data-content] [data-line]').first()).toBeVisible({
timeout: 20_000
})
const previousClipboard = await electronApp.evaluate(({ clipboard }) => clipboard.readText())
let copied = ''
try {
for (const side of ['deletions', 'additions']) {
const contents = side === 'deletions' ? original : modified
const coordinates = await diffTextSelectionPoints(
orcaPage.locator(`diffs-container [data-code][data-${side}]`),
contents.trimEnd()
)
await orcaPage.mouse.move(coordinates.end.x, coordinates.end.y)
await orcaPage.mouse.down()
await orcaPage.mouse.move(coordinates.start.x, coordinates.start.y, { steps: 8 })
await orcaPage.mouse.up()
await expect
.poll(() =>
orcaPage
.locator('diffs-container')
.evaluate((host) =>
(host.shadowRoot as ShadowRoot & { getSelection(): Selection })
.getSelection()
.toString()
)
)
.toBe(contents.trimEnd())
await orcaPage.keyboard.press('ControlOrMeta+Alt+c')
copied = `File: ${fixture.relativePath}\nLines: 1-3\n\n\`\`\`ts\n${contents}\`\`\``
await expect
.poll(() => electronApp.evaluate(({ clipboard }) => clipboard.readText()))
.toBe(copied)
await expect(orcaPage.getByText('Context copied', { exact: true }).first()).toBeVisible()
}
} finally {
await electronApp.evaluate(
({ clipboard }, { copied, previousClipboard }) => {
if (clipboard.readText() === copied) {
clipboard.writeText(previousClipboard)
}
},
{ copied, previousClipboard }
)
}
})