Files
orca/tests/e2e/golden-tab-bar-agent-launch.spec.ts
Jinjing f5fd7303ab test(e2e): cover tab-bar agent launches on Windows and WSL (#16110)
* test(e2e): gate the tab-bar agent launcher on Windows shells and WSL

The `+` menu agent launcher had no golden coverage in the Windows lane, so a
Windows-only break anywhere in its chain (detection row, startup-plan build,
tab create, PTY spawn, startup-command injection) could ship unnoticed.

Adds a golden spec that launches a stub agent from the menu and asserts the
agent's own banner reached the pane — a tab that spawned a bare shell instead
is indistinguishable at the store/tab layer. Runs two agents everywhere, and
on Windows also PowerShell, cmd, Git Bash and a WSL project runtime.

* test(e2e): track WSL stub agent staging state for precise cleanup

Refactor `stageWslGoldenStubAgent` to track which artifacts it creates
during setup, then only remove those artifacts during cleanup. This
prevents the test from destructively removing pre-existing symlinks or
state from previous runs, improving test isolation and idempotency.

* test(e2e): track WSL stub agent staging state for precise cleanup

- Back up and restore pre-existing stub agents to avoid destroying them
- Simplify verbose test comments to match project style guidelines

* test(e2e): serialize WSL stub agent setup with distributed lock

- Add mkdir-based lock to prevent concurrent staging invocations
- Reclaim stale locks after 10 minutes to recover from crashes
- Track lock ownership in stage state for safe cleanup

* test(e2e): track WSL stub agent staging state for precise cleanup

Track which stubs this test helper stages by writing a marker file, then
only remove stubs during stale-lock recovery if we created them. Prevents
cleanup from removing stubs left by other processes.
2026-08-24 08:58:19 -07:00

91 lines
3.4 KiB
TypeScript

import type { Page } from '@stablyai/playwright-test'
import { expect, test } from './helpers/orca-app'
import {
configureGoldenStubAgent,
getGoldenStubAgentLaunchEnv,
GOLDEN_STUB_AGENTS,
GOLDEN_STUB_READY_MARKER,
launchGoldenStubAgentFromNewTab
} from './helpers/golden-stub-agent'
import {
getFirstWslDistro,
removeWslGoldenStubAgent,
stageWslGoldenStubAgent,
useWslRuntimeForActiveProject
} from './helpers/wsl-golden-stub-agent'
import { ensureTerminalVisible, waitForActiveWorktree, waitForSessionReady } from './helpers/store'
import { getTerminalContent } from './helpers/terminal'
import type { BuiltInWindowsTerminalShell } from '../../src/shared/windows-terminal-shell'
// Covers the Windows-only tab-bar launch path that the default-shell test misses.
test.use({ launchEnv: getGoldenStubAgentLaunchEnv() })
const WINDOWS_SHELLS: readonly BuiltInWindowsTerminalShell[] = [
'powershell.exe',
'cmd.exe',
'git-bash'
]
async function openWorkspaceTerminal(page: Page): Promise<void> {
await waitForSessionReady(page)
await waitForActiveWorktree(page)
await ensureTerminalVisible(page)
}
for (const { id, menuItemName } of GOLDEN_STUB_AGENTS) {
test(`tab-bar + menu launches ${id} into a live TUI @tab-bar-agent-launch-golden`, async ({
orcaPage
}) => {
await openWorkspaceTerminal(orcaPage)
await configureGoldenStubAgent(orcaPage, { agent: id })
await launchGoldenStubAgentFromNewTab(orcaPage, menuItemName)
const activeTab = orcaPage.locator('[data-testid="sortable-tab"][data-active="true"]')
await expect(activeTab).toHaveAttribute('data-tab-title', /Golden Stub Agent|Codex|Claude/i)
// The marker distinguishes an agent launch from an identical bare-shell tab.
expect(await getTerminalContent(orcaPage)).toContain(GOLDEN_STUB_READY_MARKER)
})
}
// Suite-level skipping avoids launching Electron for each unsupported case.
test.describe('Windows runtimes', () => {
test.skip(process.platform !== 'win32', 'Windows agent launch matrix is Windows-only')
for (const shell of WINDOWS_SHELLS) {
test(`tab-bar + menu launches an agent under ${shell} @tab-bar-agent-launch-golden`, async ({
orcaPage
}) => {
await openWorkspaceTerminal(orcaPage)
// Each shell family requires different launch-command quoting.
await configureGoldenStubAgent(orcaPage, { agent: 'codex', windowsShell: shell })
await launchGoldenStubAgentFromNewTab(orcaPage)
expect(await getTerminalContent(orcaPage)).toContain(GOLDEN_STUB_READY_MARKER)
})
}
test('tab-bar + menu launches an agent inside WSL @tab-bar-agent-launch-golden', async ({
orcaPage
}) => {
await openWorkspaceTerminal(orcaPage)
const distro = await getFirstWslDistro(orcaPage)
test.skip(!distro, 'No WSL distro is available on this Windows host')
const stage = stageWslGoldenStubAgent(distro!)
test.skip(!stage, 'WSL distro would not accept the staged stub agent')
try {
// WSL must retarget both agent detection and the PTY.
await useWslRuntimeForActiveProject(orcaPage, distro!)
await configureGoldenStubAgent(orcaPage, { agent: 'codex' })
await launchGoldenStubAgentFromNewTab(orcaPage)
// The distro-only marker proves the agent ran in WSL.
expect(await getTerminalContent(orcaPage)).toContain(GOLDEN_STUB_READY_MARKER)
} finally {
removeWslGoldenStubAgent(distro!, stage!)
}
})
})