Files
orca/tests/e2e/golden-file-open-edit-save.spec.ts
T
Jinjing e84fb46eaf test: add golden E2E tests for source control workflows (#14260)
* test: add golden E2E tests for source control workflows

- Tests core source control interactions: file edit/save, commit staging, and diff viewing
- Integrated into CI/CD pipelines for Linux, macOS, and Windows
- Includes helper utilities for test setup and worktree management

* test(e2e): verify golden commit author and fix test flakiness

- Configure git author name/email at worktree level during setup
- Verify commits are made with correct author details in assertions
- Add explicit timeouts to file visibility waits and git status polling
- Fix test ordering to seed edits after source control is open
- Simplify git status refresh logic to rely on automatic updates

* Add rollback to createGoldenWorktree on setup failure

Cleanup callbacks only register after setup succeeds. When a config
command fails, the half-built worktree and branch leak into later
test runs, causing flakiness. Now we roll back immediately and
re-throw the setup error.

* test(e2e): match explorer rows after the git status badge appears

The golden file-save spec used an exact /^README.md$/ filter. After save,
the explorer row text becomes "README.md M", so reopen clicked nothing.

* test: strengthen golden worktree setup verification

- Track working directory in git call inspection to verify correct execution context
- Verify user.name/email config applies to worktree-specific settings, not repo
- Add exhaustive setup call sequence assertions to catch setup/rollback leaks
2026-08-13 09:56:30 -07:00

69 lines
2.7 KiB
TypeScript

import { readFileSync } from 'node:fs'
import path from 'node:path'
import { test, expect } from './helpers/orca-app'
import {
activateGoldenWorktree,
cleanupGoldenWorktree,
createGoldenWorktree
} from './helpers/golden-source-control'
import { waitForSessionReady } from './helpers/store'
const README_PATH = 'README.md'
test('@golden opens, edits, saves, and reopens a tracked file', async ({
orcaPage,
testRepoPath,
registerPostElectronShutdownCleanup
}) => {
const fixture = createGoldenWorktree(testRepoPath, 'file-save')
registerPostElectronShutdownCleanup(async () => cleanupGoldenWorktree(testRepoPath, fixture))
const sentinel = `Golden file save ${Date.now()}`
const readmePath = path.join(fixture.worktreePath, README_PATH)
await waitForSessionReady(orcaPage)
await activateGoldenWorktree(orcaPage, testRepoPath, fixture.worktreePath)
await orcaPage.evaluate(() => {
const state = window.__store?.getState()
state?.setRightSidebarTab('source-control')
state?.setRightSidebarOpen(true)
})
await orcaPage.getByRole('button', { name: 'Explorer' }).click()
const explorer = orcaPage.locator('[data-orca-explorer-shell]')
// Why: after save the row's full text is "README.md M" from the git badge.
const readmeRow = explorer.locator('[data-file-explorer-row]').filter({
has: orcaPage.locator('[data-file-explorer-row-name]').getByText(README_PATH, { exact: true })
})
await expect(readmeRow).toBeVisible({ timeout: 10_000 })
await readmeRow.click()
await expect(orcaPage.locator('.editor-header-path').first()).toContainText(README_PATH, {
timeout: 20_000
})
const editor = orcaPage.locator('.rich-markdown-editor')
await expect(editor).toBeVisible({ timeout: 25_000 })
await expect(editor).toContainText('Orca E2E Test Repo')
await editor.click()
await orcaPage.keyboard.press('ControlOrMeta+End')
await orcaPage.keyboard.press('Enter')
await orcaPage.keyboard.type(sentinel)
await orcaPage.keyboard.press('ControlOrMeta+S')
await expect.poll(() => readFileSync(readmePath, 'utf8'), { timeout: 10_000 }).toContain(sentinel)
const readmeTab = orcaPage.locator('[data-tab-id]').filter({ hasText: README_PATH }).last()
await readmeTab.getByRole('button', { name: 'Close tab' }).click()
await expect(
orcaPage.locator('.editor-header-path').filter({ hasText: README_PATH })
).toHaveCount(0)
await readmeRow.click()
await expect(orcaPage.locator('.rich-markdown-editor')).toContainText(sentinel, {
timeout: 25_000
})
await expect(explorer).toBeVisible()
await expect(readmeRow).toBeVisible()
await expect(
orcaPage.getByText(path.basename(testRepoPath), { exact: true }).first()
).toBeVisible()
})