Fix mobile SSH worktrees (#2198)

Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
Jinwoo Hong
2026-05-17 20:55:30 -07:00
committed by GitHub
co-authored by Orca
parent d89fdd0ab8
commit 29b8e36c39
7 changed files with 265 additions and 11 deletions
+114 -5
View File
@@ -38,6 +38,8 @@ const {
getSshGitProviderMock,
registerSshGitProviderMock,
unregisterSshGitProviderMock,
getActiveMultiplexerMock,
muxRequestMock,
invalidateAuthorizedRootsCacheMock,
createHostedReviewMock,
getHostedReviewCreationEligibilityMock
@@ -68,6 +70,8 @@ const {
unregisterSshGitProviderMock: vi.fn((connectionId: string) => {
sshGitProviders.delete(connectionId)
}),
getActiveMultiplexerMock: vi.fn(),
muxRequestMock: vi.fn(),
invalidateAuthorizedRootsCacheMock: vi.fn(),
createHostedReviewMock: vi.fn(),
getHostedReviewCreationEligibilityMock: vi.fn()
@@ -87,6 +91,10 @@ vi.mock('../providers/ssh-git-dispatch', () => ({
unregisterSshGitProvider: unregisterSshGitProviderMock
}))
vi.mock('../ipc/ssh', () => ({
getActiveMultiplexer: getActiveMultiplexerMock
}))
vi.mock('../hooks', () => ({
createSetupRunnerScript: vi.fn(),
getEffectiveHooks: vi.fn().mockReturnValue(null),
@@ -153,6 +161,10 @@ afterEach(() => {
unregisterSshGitProviderMock.mockImplementation((connectionId: string) => {
sshGitProviders.delete(connectionId)
})
muxRequestMock.mockReset()
muxRequestMock.mockResolvedValue(undefined)
getActiveMultiplexerMock.mockReset()
getActiveMultiplexerMock.mockReturnValue({ request: muxRequestMock, notify: vi.fn() })
vi.mocked(createSetupRunnerScript).mockReset()
vi.mocked(getEffectiveHooks).mockReset()
vi.mocked(hasHooksFile).mockReset()
@@ -622,9 +634,17 @@ describe('OrcaRuntimeService', () => {
})
})
it('does not run local git when runtime worktree creation targets an SSH repo', async () => {
it('creates SSH-backed worktrees through the SSH provider for mobile/runtime callers', async () => {
vi.mocked(listWorktrees).mockClear()
vi.mocked(addWorktree).mockClear()
const created = {
path: '/remote/mobile-feature',
head: 'def',
branch: 'refs/heads/mobile-feature',
isBare: false,
isMainWorktree: false
}
const metaById: Record<string, WorktreeMeta> = {}
const remoteStore = {
...store,
getRepos: () => [
@@ -636,14 +656,53 @@ describe('OrcaRuntimeService', () => {
addedAt: 1,
connectionId: 'ssh-1'
}
]
],
getAllWorktreeMeta: () => metaById,
getWorktreeMeta: (worktreeId: string) => metaById[worktreeId],
setWorktreeMeta: (worktreeId: string, meta: Partial<WorktreeMeta>) => {
metaById[worktreeId] = { ...(metaById[worktreeId] ?? makeWorktreeMeta()), ...meta }
return metaById[worktreeId]
}
}
const provider = {
exec: vi.fn(async (args: string[]) => {
if (args[0] === 'config') {
return { stdout: 'Remote User\n', stderr: '' }
}
if (args[0] === 'branch') {
return { stdout: '', stderr: '' }
}
if (args[0] === 'symbolic-ref') {
return { stdout: 'origin/main\n', stderr: '' }
}
if (args[0] === 'fetch') {
return { stdout: '', stderr: '' }
}
throw new Error(`unexpected git call: ${args.join(' ')}`)
}),
addWorktree: vi.fn().mockResolvedValue(undefined),
listWorktrees: vi.fn().mockResolvedValue([created])
}
registerSshGitProvider('ssh-1', provider as never)
getActiveMultiplexerMock.mockReturnValue({ request: muxRequestMock, notify: vi.fn() })
const runtime = new OrcaRuntimeService(remoteStore as never)
await expect(
runtime.createManagedWorktree({ repoSelector: TEST_REPO_ID, name: 'feature' })
).rejects.toThrow('SSH-backed worktree creation is not supported through runtime RPC yet')
const result = await runtime.createManagedWorktree({
repoSelector: TEST_REPO_ID,
name: 'mobile-feature',
startup: { command: 'claude' }
})
expect(provider.addWorktree).toHaveBeenCalledWith(
'/remote/repo',
'mobile-feature',
'/remote/repo/../mobile-feature',
{ base: 'origin/main' }
)
expect(result.worktree).toMatchObject({
id: `${TEST_REPO_ID}::${created.path}`,
path: created.path
})
expect(addWorktree).not.toHaveBeenCalled()
expect(listWorktrees).not.toHaveBeenCalled()
})
@@ -2351,6 +2410,56 @@ describe('OrcaRuntimeService', () => {
})
})
it('includes SSH-backed worktrees in the mobile worktree summary', async () => {
const remoteRepo = {
id: 'repo-ssh',
path: '/home/me/project',
displayName: 'remote-vm',
badgeColor: 'blue',
addedAt: 1,
connectionId: 'ssh-1'
}
const remoteWorktree = {
path: '/home/me/project/.worktrees/feature-mobile',
head: 'def',
branch: 'refs/heads/feature/mobile',
isBare: false,
isMainWorktree: false
}
const metaById: Record<string, WorktreeMeta> = {
[`${remoteRepo.id}::${remoteWorktree.path}`]: makeWorktreeMeta({
displayName: 'Remote mobile'
})
}
const runtimeStore = {
...store,
getRepos: () => [remoteRepo],
getRepo: (id: string) => (id === remoteRepo.id ? remoteRepo : undefined),
getAllWorktreeMeta: () => metaById,
getWorktreeMeta: (worktreeId: string) => metaById[worktreeId],
setWorktreeMeta: (worktreeId: string, meta: Partial<WorktreeMeta>) => {
metaById[worktreeId] = { ...(metaById[worktreeId] ?? makeWorktreeMeta()), ...meta }
return metaById[worktreeId]
}
}
registerSshGitProvider('ssh-1', {
listWorktrees: vi.fn().mockResolvedValue([remoteWorktree])
} as never)
const runtime = new OrcaRuntimeService(runtimeStore as never)
const summaries = await runtime.getWorktreePs()
expect(summaries.worktrees).toEqual([
expect.objectContaining({
worktreeId: `${remoteRepo.id}::${remoteWorktree.path}`,
repoId: remoteRepo.id,
repo: 'remote-vm',
path: remoteWorktree.path,
displayName: 'Remote mobile'
})
])
})
it('clears stale working status after the agent exits and the shell takes over the title', async () => {
// Why: regression test for issue #1437 — the mobile worktree-list spinner
// kept playing forever because lastAgentStatus was sticky on 'working'