Files
orca/mobile/src/source-control/folder/MobileFolderSourceControlPanel.test.tsx
T
Brennan Benson 8573f7ce86 Create a worktree per repository from an empty folder workspace on the phone (#40139)
* feat(mobile): create a worktree per repository from an empty folder workspace

A folder workspace with no attached worktrees lists one card per
repository in its project group, as desktop's empty state does. Tapping
one creates a worktree named after the folder, attached to it, in place;
a taken name or a setup choice opens the new-workspace composer with the
repo, the name and the folder parent filled in. Shown only when the host
creating it supports exact-name creation.

* chore(mobile): merge the folder repo read's execution-host imports

* fix(mobile): folder creates keep their repository until the folder shows them

Every create from a folder's empty state, direct or through the
composer, holds its repository from admission until the folder lists
the new worktree, so a lost reply, a remount or a reopened form can't
start a second one. The composer and toasts belong to the folder
screen, stay on the folder's host, and say nothing once it's left. A
relayed server's repository read holds no desktop event stream, and a
failed read can be retried.

* test(mobile): a folder create resent after a lost reply carries the same mutation id

* fix(mobile): folder creates keep their name, and a left or replaced form shows and holds nothing

* fix(mobile): pause folder rows under the create form; a lost folder create is checked, never resent as another

* fix(mobile): a folder card never resends a form's create, and one form owns the folder screen at a time

* fix(mobile): a folder setup choice resends only its own unconfirmed create, and the newest form silences older ones

* test(mobile): declare the submit hook's folder launch in its recording fixture

* fix(mobile): a create refused on a resend after a lost reply tries no other name and stays unconfirmed

* fix(mobile): a replayed refusal after an agent-launch fallback stops the retry, and the composer says it may have been created

* test(mobile): type the replayed refusal reply in the retry test

* ci: retrigger checks

* fix(mobile): localize the folder and uncertain-create messages in the workspace composer
2026-11-09 17:18:33 -08:00

127 lines
4.4 KiB
TypeScript

import { createElement, type ReactNode } from 'react'
import { act, create, type ReactTestRenderer } from 'react-test-renderer'
import { afterEach, describe, expect, it, vi } from 'vitest'
import type { FolderListRow } from './mobile-folder-attached-worktrees'
const seen = vi.hoisted(() => {
const state: { covered: boolean; membersObserving: boolean[]; rowsSubscribed: boolean[] } = {
covered: false,
membersObserving: [],
rowsSubscribed: []
}
return state
})
vi.mock('react-native', () => ({ ScrollView: 'ScrollView', View: 'View' }))
vi.mock('lucide-react-native', () => ({ GitBranch: 'GitBranch' }))
vi.mock('expo-router', () => ({ useFocusEffect: () => {} }))
vi.mock('react-native-safe-area-context', () => ({
SafeAreaView: 'SafeAreaView',
useSafeAreaInsets: () => ({ bottom: 0 })
}))
vi.mock('../../components/MobileStateView', () => ({
MobileLoadErrorState: 'MobileLoadErrorState',
MobileOfflineState: 'MobileOfflineState',
MobileStateView: 'MobileStateView'
}))
vi.mock('../../transport/connection/connection-retry-action', () => ({
connectionRetryAction: () => () => {}
}))
vi.mock('../../transport/connection/host-client-hooks', () => ({
useForceReconnect: () => () => {}
}))
vi.mock('../../components/bottom-drawer/BottomDrawer', () => ({
OptionPager: ({ main }: { main: ReactNode }) => main,
useOptionPager: () => ({ page: null, open: () => {}, close: () => {} })
}))
vi.mock('../../components/list/ListGroup', () => ({ ListGroup: 'ListGroup' }))
vi.mock('../../i18n/use-mobile-translation', () => ({
useMobileTranslation: () => (_key: string, fallback: string) => fallback
}))
vi.mock('../../navigation/use-back-claim', () => ({ useBackClaim: () => {} }))
vi.mock('../../navigation/workspace-route-handoff', () => ({
useWorkspaceRouteHandoff: () => ({ back: () => {} })
}))
vi.mock('../../navigation/workspace-route', () => ({
WorkspaceExecutionScope: 'WorkspaceExecutionScope'
}))
vi.mock('../../theme/mobile-theme', () => ({ colors: {}, spacing: { lg: 16 } }))
vi.mock('../../theme/themed-styles', () => ({
themedStyleSheet: (styles: () => unknown) => styles()
}))
vi.mock('../../theme/use-mobile-color-scheme', () => ({ useMobileColorScheme: () => {} }))
vi.mock('../MobileSourceControlHeader', () => ({
MobileSourceControlHeader: 'MobileSourceControlHeader'
}))
vi.mock('../MobileSourceControlPanel', () => ({ MobileSourceControlPanel: 'Panel' }))
vi.mock('../mobile-source-control-styles', () => ({ styles: {} }))
vi.mock('./MobileFolderEmptyState', () => ({ MobileFolderEmptyState: 'EmptyState' }))
vi.mock('../../components/host-protocol-gates-context', () => ({
useOptionalHostProtocolGates: () => null
}))
vi.mock('./use-folder-create-flow', () => ({
useFolderCreateFlow: () => ({
onCreate: async () => {},
covered: seen.covered,
composerElement: null,
toastElement: null
})
}))
vi.mock('./MobileFolderWorktreeRow', () => ({
MobileFolderWorktreeRow: (props: { subscribed: boolean }) => {
seen.rowsSubscribed.push(props.subscribed)
return null
}
}))
vi.mock('./use-mobile-folder-attached-worktrees', () => ({
useMobileFolderAttachedWorktrees: (_hostId: string, _folderId: string, observing: boolean) => {
seen.membersObserving.push(observing)
return {
folder: { worktreeId: 'folder:f-1', repoId: 'folder-workspace:f-1', displayName: 'payments' },
worktrees: [ROW],
desktopCapabilities: [],
serverHosts: [],
connState: 'connected',
loadError: null,
refetch: () => {}
}
}
}))
import { MobileFolderSourceControlPanel } from './MobileFolderSourceControlPanel'
const ROW: FolderListRow = {
worktreeId: 'repo-1::/w/payments',
repoId: 'repo-1',
repo: 'orca',
displayName: 'payments',
branch: 'payments'
}
let renderer: ReactTestRenderer | null = null
afterEach(() => {
act(() => renderer?.unmount())
renderer = null
seen.covered = false
seen.membersObserving = []
seen.rowsSubscribed = []
})
describe('MobileFolderSourceControlPanel', () => {
it('pauses row status under the create form while the folder members stay live', () => {
seen.covered = true
act(() => {
renderer = create(
createElement(MobileFolderSourceControlPanel, {
hostId: 'host-1',
folderWorktreeId: 'folder:f-1',
name: 'payments',
embedded: true
})
)
})
expect(seen.rowsSubscribed.at(-1)).toBe(false)
expect(seen.membersObserving.at(-1)).toBe(true)
})
})