Files
orca/tests/e2e/golden-source-control-commit.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

68 lines
2.6 KiB
TypeScript

import { execFileSync } from 'node:child_process'
import { existsSync } from 'node:fs'
import path from 'node:path'
import { test, expect } from './helpers/orca-app'
import {
cleanupGoldenWorktree,
createGoldenWorktree,
GOLDEN_CHANGED_PATH,
GOLDEN_GIT_AUTHOR_EMAIL,
GOLDEN_GIT_AUTHOR_NAME,
installPassingNodePreCommitHook,
openGoldenSourceControl,
seedGoldenSourceEdit
} from './helpers/golden-source-control'
import { waitForSessionReady } from './helpers/store'
test('@golden stages and commits a file through Source Control', async ({
orcaPage,
testRepoPath,
registerPostElectronShutdownCleanup
}) => {
const fixture = createGoldenWorktree(testRepoPath, 'commit')
registerPostElectronShutdownCleanup(async () => cleanupGoldenWorktree(testRepoPath, fixture))
seedGoldenSourceEdit(fixture.worktreePath)
const hookMarkerPath = installPassingNodePreCommitHook(fixture)
await waitForSessionReady(orcaPage)
await openGoldenSourceControl(orcaPage, testRepoPath, fixture)
const unstagedRow = orcaPage
.locator('[data-testid="source-control-entry"][data-source-control-area="unstaged"]')
.filter({ hasText: path.basename(GOLDEN_CHANGED_PATH) })
await expect(unstagedRow).toBeVisible()
const stageButton = unstagedRow.getByRole('button', { name: 'Stage' })
await stageButton.focus()
await stageButton.press('Enter')
await expect(unstagedRow).toHaveCount(0, { timeout: 10_000 })
const stagedRow = orcaPage
.locator('[data-testid="source-control-entry"][data-source-control-area="staged"]')
.filter({ hasText: path.basename(GOLDEN_CHANGED_PATH) })
await expect(stagedRow).toBeVisible({ timeout: 10_000 })
await orcaPage.getByRole('textbox', { name: 'Commit message' }).fill('test: golden daily loop')
await orcaPage.getByRole('button', { name: 'Commit', exact: true }).click()
await expect(stagedRow).toHaveCount(0, { timeout: 20_000 })
await expect
.poll(
() =>
execFileSync('git', ['status', '--porcelain'], {
cwd: fixture.worktreePath,
encoding: 'utf8'
}),
{ timeout: 20_000, message: 'Golden commit worktree did not become clean' }
)
.toBe('')
expect(
execFileSync('git', ['show', '-s', '--format=%an%n%ae%n%s', 'HEAD'], {
cwd: fixture.worktreePath,
encoding: 'utf8'
}).trim()
).toBe(`${GOLDEN_GIT_AUTHOR_NAME}\n${GOLDEN_GIT_AUTHOR_EMAIL}\ntest: golden daily loop`)
await expect.poll(() => existsSync(hookMarkerPath), { timeout: 20_000 }).toBe(true)
await expect(
orcaPage.locator('[data-sonner-toast]').filter({ hasText: /node|command not found|cmd\.exe/i })
).toHaveCount(0)
})