Files
orca/src/main/runtime/runtime-remote-managed-worktree-create.test.ts
T
Neil 6a9ba9d733 Keep remote worktree creation from navigating paired clients (#25793)
* fix(workspaces): keep remote creation from navigating paired viewers

* fix(workspaces): revoke pending navigation after connection replacement

* fix(workspaces): provision when the host renderer is unavailable

* test: align navigation and cache-scan expectations with current behavior

* fix(workspaces): provision broadcast creates without a host renderer
2026-10-06 00:38:53 -07:00

107 lines
3.6 KiB
TypeScript

/** The startup terminal an SSH-remote create spawns; each create path forwards a reserved pane itself. */
import { describe, expect, it, vi } from 'vitest'
import type { Repo } from '../../shared/repo-types'
import type { WorktreeSetupLaunch } from '../../shared/worktree/launch-types'
const requestRuntimeRemoteWorktree = vi.hoisted(() =>
vi.fn(
async (): Promise<{
worktree: { id: string; path: string }
setup?: WorktreeSetupLaunch
}> => ({ worktree: { id: 'wt-remote', path: '/remote/wt' } })
)
)
vi.mock('./runtime-remote-worktree-create-request', () => ({ requestRuntimeRemoteWorktree }))
const { createRuntimeRemoteManagedWorktree } =
await import('./runtime-remote-managed-worktree-create')
type CreateParams = Parameters<typeof createRuntimeRemoteManagedWorktree>
const repo: Repo = {
id: 'repo-1',
path: '/repo',
displayName: 'repo',
badgeColor: 'blue',
addedAt: 1,
connectionId: 'conn-1'
}
function createDeps() {
const createTerminal = vi
.fn<CreateParams[2]['createTerminal']>()
.mockResolvedValue({ handle: 'term-1' })
const deps: CreateParams[2] = {
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: the create only forwards the store to the mocked request helper, which never reads it.
store: {} as unknown as CreateParams[2]['store'],
canSpawn: () => true,
createTerminal,
pasteDraft: vi.fn(),
sendFollowup: vi.fn(),
provision: vi.fn().mockResolvedValue({ setupSpawned: false, setupTerminalHandle: null }),
activate: vi.fn(),
invalidateResolvedWorktrees: vi.fn(),
invalidateWorktreeScan: vi.fn(),
notifyWorktreesChanged: vi.fn()
}
return { createTerminal, deps }
}
const TAB_ID = '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d'
const LEAF_ID = '3f2504e0-4f89-41d3-9a0c-0305e82c3301'
async function startupTerminalOptions(startupPaneKey?: string): Promise<Record<string, unknown>> {
const { createTerminal, deps } = createDeps()
await createRuntimeRemoteManagedWorktree(
repo,
{
name: 'task',
createdWithAgent: 'codex',
startup: { command: 'codex' },
...(startupPaneKey ? { startupPaneKey } : {})
},
deps
)
return createTerminal.mock.calls[0]?.[1] ?? {}
}
describe('a remote managed create with a startup agent', () => {
it.each([false, true])(
'provisions SSH setup after renderer loss (during request=%s)',
async (duringRequest) => {
const { deps } = createDeps()
let rendererAvailable = duringRequest
deps.provisionInBackground = () => !rendererAvailable
const setup = { runnerScriptPath: '/remote/setup.sh', envVars: {} }
requestRuntimeRemoteWorktree.mockImplementationOnce(async () => {
rendererAvailable = false
return { worktree: { id: 'wt-remote', path: '/remote/wt' }, setup }
})
await createRuntimeRemoteManagedWorktree(repo, { name: 'headless', activate: true }, deps)
expect(deps.provision).toHaveBeenCalledWith(
expect.objectContaining({
worktreeSelector: 'path:/remote/wt',
setup,
surfaceOwner: false,
hasStartupTerminal: false
})
)
}
)
it('creates the startup terminal under the pane the caller reserved', async () => {
expect(await startupTerminalOptions(`${TAB_ID}:${LEAF_ID}`)).toMatchObject({
tabId: TAB_ID,
leafId: LEAF_ID
})
})
it('leaves the pane to the runtime when none was reserved', async () => {
const options = await startupTerminalOptions()
expect(options).not.toHaveProperty('tabId')
expect(options).not.toHaveProperty('leafId')
})
})