mirror of
https://github.com/stablyai/orca.git
synced 2026-10-19 00:03:20 +00:00
* feat(mobile): start a workspace from a branch, issue/PR, or Linear ticket Unify mobile workspace creation with desktop. The "+" Create Workspace modal now has a primary "Start from" field that opens a tabbed search drawer (Branch · GitHub · GitLab · Linear), letting a user start a workspace from an existing/new git branch, a GitHub issue/PR, a GitLab issue/MR, or a Linear ticket — in addition to the default blank workspace. No new backend is required: the search RPCs (github.listWorkItems, gitlab.listWorkItems, linear.searchIssues/listIssues, repo.searchRefs) and the worktree.create linked-item params were already used by the mobile Tasks screen. This surfaces them in the create flow, reusing the existing pure modules (buildTaskWorkspaceCreateParams, shouldResolveHostedReviewStartPoint, filterAvailableTaskProviders). Details: - New pure modules: workspace-source-selection, use-workspace-source-search, source-workspace-create, worktree-create-retry, blank-workspace-create (the blank/retry path extracted from the modal for reuse + line budget). - New UI: WorkspaceSourcePickerDrawer (+ row) and SetupHookTrustDrawer (extracted from the modal). - Older paired desktops (missing the mobile.tasks.v1 capability) degrade to Branch + Blank only; GitLab/Linear tabs appear only when available. - GitHub/GitLab sources pin their repo; switching repos resets the source. PR/MR sources resolve their base branch at create time; SSH repos gate search until connected (Linear search is repo/SSH-independent). * fix(mobile): hydrate settings/trust before availability probes settle Review fixes for #7985: setTrustedOrcaHooks/setRuntimeSettings no longer wait on status.get/preflight.check/linear.status (a first-open preflight.check can take seconds, widening the spurious setup-trust re-prompt window). Also adds param-parity tests for createBlankWorkspace and a GitLab MR base-resolve test. * feat(mobile): match desktop's Smart source picker exactly Rework the mobile create-workspace source picker to be a faithful port of desktop's Smart picker instead of the earlier divergent "Start from" drawer. The mobile field is now the workspace-name input AND the source search, with the exact desktop tabs — Smart · GitHub · Linear · GitLab · Branch · Name. "Smart" fans out across GitHub + GitLab + Linear + branches, prepends a "Use '<name>'" row, and resolves pasted URLs / #123 / STA-42 to exact items (with a cross-repo switch prompt). Selecting a source shows a pill and moves the editable name into Advanced. The invented "Blank workspace" concept is removed — the neutral state is just a typed/empty name (blank submit still yields a creature name). DRY: the pure desktop logic (smart-workspace-source-results, -command-value, github-links, gitlab-links, work-item-link-query-bounds, github-work-item-identity) moves to src/shared/new-workspace/ with re-export shims at the old renderer paths, so both renderer and mobile share one implementation. composer-branch-selection and workspace-name were already shared and are reused directly. Two read-only lookup RPCs are allowlisted for mobile so pasted GitLab URLs and cross-repo GitHub URLs resolve to exact items (github.workItemByOwnerRepo, gitlab.workItemByPath). New mobile modules are split for max-lines: use-mobile-composer-source (selection state + desktop-parity handlers, PR/MR base resolve), use-smart-workspace-source + smart-source-fan-out/-search-requests/-paste-intent (RPC orchestration), composer-linked-work-item / work-item-lookup-text / mobile-smart-source-modes (pure logic), and SmartWorkspaceSourceField/Drawer/Row + SmartWorkspaceAdvancedFields. Replaces WorkspaceSourcePickerDrawer/Row, workspace-source-selection, use-workspace-source-search, and MobileWorkspaceNameInput. Reviewed by three adversarial agents + re-reviewed after fixes: GitHub search now returns issues AND PRs (not issues-only), Linear defaults to assigned, create-branch preserves slashy names, cross-repo PR base resolves against the item's own repo, displayName is suppressed for user-edited names, and the smart-mode GitHub fan-out respects availability. tsc/oxlint/max-lines-ratchet clean; 1328 mobile tests pass. * fix(mobile): keep smart source drawer fully visible * refactor: share workspace creation behavior across clients * fix: address workspace creation review findings --------- Co-authored-by: Brennan Benson <brennanbenson@Brennans-MacBook-Pro.local>
221 lines
7.5 KiB
TypeScript
221 lines
7.5 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import type { RpcClient } from '../transport/rpc-client'
|
|
import { createWorkspaceFromComposerSource } from './source-workspace-create'
|
|
import type { MobileComposerCreateSelection } from './mobile-composer-source-types'
|
|
|
|
type Call = { method: string; params: Record<string, unknown> }
|
|
|
|
function fakeClient(handle: (method: string, call: number) => unknown, calls: Call[]): RpcClient {
|
|
return {
|
|
sendRequest: async (method: string, params?: unknown) => {
|
|
calls.push({ method, params: (params ?? {}) as Record<string, unknown> })
|
|
const result = handle(method, calls.length)
|
|
if (result instanceof Error) {
|
|
return {
|
|
id: '1',
|
|
ok: false,
|
|
error: { code: 'x', message: result.message },
|
|
_meta: { runtimeId: 'r' }
|
|
}
|
|
}
|
|
return { id: '1', ok: true, result, _meta: { runtimeId: 'r' } }
|
|
}
|
|
} as unknown as RpcClient
|
|
}
|
|
|
|
const agent = { choice: 'blank' as const, startupCommand: undefined }
|
|
|
|
const baseArgs = {
|
|
targetRepoId: 'repo-1',
|
|
setupDecision: 'inherit' as const,
|
|
agent,
|
|
workspaceName: undefined,
|
|
note: undefined
|
|
}
|
|
|
|
describe('createWorkspaceFromComposerSource', () => {
|
|
it('creates a GitHub issue workspace linking the issue to its own repo', async () => {
|
|
const calls: Call[] = []
|
|
const client = fakeClient(() => ({ worktree: { id: 'wt-1' } }), calls)
|
|
const selection: MobileComposerCreateSelection = {
|
|
kind: 'work-item',
|
|
item: {
|
|
provider: 'github',
|
|
type: 'issue',
|
|
number: 7,
|
|
title: 'Bug',
|
|
url: 'u',
|
|
repoId: 'repo-9'
|
|
}
|
|
}
|
|
// The composer supplies the title-derived name as workspaceName; with none,
|
|
// buildTaskWorkspaceCreateParams falls back to the "<type>-<number>" slug.
|
|
const result = await createWorkspaceFromComposerSource({ client, selection, ...baseArgs })
|
|
expect(result).toEqual({ worktreeId: 'wt-1', name: 'issue-7' })
|
|
expect(calls).toHaveLength(1)
|
|
expect(calls[0]!.method).toBe('worktree.create')
|
|
expect(calls[0]!.params).toMatchObject({
|
|
repo: 'id:repo-9',
|
|
linkedIssue: 7,
|
|
displayName: 'Bug'
|
|
})
|
|
})
|
|
|
|
it('passes composer-resolved PR base fields straight through (no re-resolve)', async () => {
|
|
const calls: Call[] = []
|
|
const client = fakeClient(() => ({ worktree: { id: 'wt-2' } }), calls)
|
|
const selection: MobileComposerCreateSelection = {
|
|
kind: 'work-item',
|
|
item: {
|
|
provider: 'github',
|
|
type: 'pr',
|
|
number: 3,
|
|
title: 'Feat',
|
|
url: 'u',
|
|
repoId: 'repo-1'
|
|
},
|
|
baseBranch: 'main',
|
|
compareBaseRef: 'origin/main',
|
|
pushTarget: { remoteName: 'origin', branchName: 'feat-3' },
|
|
branchNameOverride: 'feat-3'
|
|
}
|
|
await createWorkspaceFromComposerSource({ client, selection, ...baseArgs })
|
|
expect(calls.map((c) => c.method)).toEqual(['worktree.create'])
|
|
expect(calls[0]!.params).toMatchObject({
|
|
linkedPR: 3,
|
|
baseBranch: 'main',
|
|
compareBaseRef: 'origin/main',
|
|
branchNameOverride: 'feat-3',
|
|
pushTarget: { remoteName: 'origin', branchName: 'feat-3' }
|
|
})
|
|
})
|
|
|
|
it('resolves a PR base as a fallback when the selection carries none', async () => {
|
|
const calls: Call[] = []
|
|
const client = fakeClient(
|
|
(method) =>
|
|
method === 'worktree.resolvePrBase'
|
|
? { baseBranch: 'develop' }
|
|
: { worktree: { id: 'wt-3' } },
|
|
calls
|
|
)
|
|
const selection: MobileComposerCreateSelection = {
|
|
kind: 'work-item',
|
|
item: { provider: 'github', type: 'pr', number: 4, title: 'X', url: 'u', repoId: 'repo-1' }
|
|
}
|
|
await createWorkspaceFromComposerSource({ client, selection, ...baseArgs })
|
|
expect(calls.map((c) => c.method)).toEqual(['worktree.resolvePrBase', 'worktree.create'])
|
|
expect(calls[1]!.params).toMatchObject({ baseBranch: 'develop', linkedPR: 4 })
|
|
})
|
|
|
|
it('creates a Linear workspace with workspace + org routing', async () => {
|
|
const calls: Call[] = []
|
|
const client = fakeClient(() => ({ worktree: { id: 'wt-4' } }), calls)
|
|
const selection: MobileComposerCreateSelection = {
|
|
kind: 'work-item',
|
|
item: {
|
|
provider: 'linear',
|
|
type: 'issue',
|
|
number: 0,
|
|
title: 'Ship it',
|
|
url: 'https://linear.app/acme/issue/ENG-9',
|
|
linearIdentifier: 'ENG-9',
|
|
linearWorkspaceId: 'ws-1',
|
|
linearOrganizationUrlKey: 'acme'
|
|
}
|
|
}
|
|
await createWorkspaceFromComposerSource({ client, selection, ...baseArgs })
|
|
expect(calls[0]!.params).toMatchObject({
|
|
repo: 'id:repo-1',
|
|
linkedLinearIssue: 'ENG-9',
|
|
linkedLinearIssueWorkspaceId: 'ws-1',
|
|
linkedLinearIssueOrganizationUrlKey: 'acme'
|
|
})
|
|
})
|
|
|
|
it('reuses an existing branch with a single attempt (no suffix retry)', async () => {
|
|
const calls: Call[] = []
|
|
const client = fakeClient(() => new Error('Branch "feature" already exists.'), calls)
|
|
const selection: MobileComposerCreateSelection = {
|
|
kind: 'branch',
|
|
baseBranch: 'feature',
|
|
refName: 'feature',
|
|
localBranchName: 'feature',
|
|
reuse: true,
|
|
branchNameOverride: 'feature'
|
|
}
|
|
const result = await createWorkspaceFromComposerSource({ client, selection, ...baseArgs })
|
|
expect('error' in result).toBe(true)
|
|
expect(calls).toHaveLength(1)
|
|
expect(calls[0]!.params).toMatchObject({
|
|
baseBranch: 'feature',
|
|
branchNameOverride: 'feature'
|
|
})
|
|
})
|
|
|
|
it('creates a brand-new branch by name, keeping a slashy name as the branch', async () => {
|
|
const calls: Call[] = []
|
|
const client = fakeClient(() => ({ worktree: { id: 'wt-nb' } }), calls)
|
|
const selection: MobileComposerCreateSelection = {
|
|
kind: 'new-branch',
|
|
branchName: 'feature/login'
|
|
}
|
|
const result = await createWorkspaceFromComposerSource({ client, selection, ...baseArgs })
|
|
expect(result).toEqual({ worktreeId: 'wt-nb', name: 'feature/login' })
|
|
expect(calls[0]!.params).toMatchObject({
|
|
repo: 'id:repo-1',
|
|
name: 'feature/login',
|
|
branchNameOverride: 'feature/login'
|
|
})
|
|
})
|
|
|
|
it('suppresses displayName when the name is user-edited (not auto-managed)', async () => {
|
|
const calls: Call[] = []
|
|
const client = fakeClient(() => ({ worktree: { id: 'wt-dn' } }), calls)
|
|
const selection: MobileComposerCreateSelection = {
|
|
kind: 'work-item',
|
|
item: {
|
|
provider: 'github',
|
|
type: 'issue',
|
|
number: 7,
|
|
title: 'Bug',
|
|
url: 'u',
|
|
repoId: 'repo-1'
|
|
}
|
|
}
|
|
await createWorkspaceFromComposerSource({
|
|
client,
|
|
selection,
|
|
...baseArgs,
|
|
workspaceName: 'my-name',
|
|
nameIsAutoManaged: false
|
|
})
|
|
expect(calls[0]!.params.displayName).toBeUndefined()
|
|
expect(calls[0]!.params).toMatchObject({ name: 'my-name', linkedIssue: 7 })
|
|
})
|
|
|
|
it('creates a new branch off a ref, bumping the branch on collision', async () => {
|
|
const calls: Call[] = []
|
|
const client = fakeClient(
|
|
(_m, n) => (n === 1 ? new Error('already exists locally') : { worktree: { id: 'wt-5' } }),
|
|
calls
|
|
)
|
|
const selection: MobileComposerCreateSelection = {
|
|
kind: 'branch',
|
|
baseBranch: 'main',
|
|
refName: 'main',
|
|
localBranchName: 'topic',
|
|
reuse: false,
|
|
branchNameOverride: 'topic'
|
|
}
|
|
const result = await createWorkspaceFromComposerSource({ client, selection, ...baseArgs })
|
|
expect(result).toEqual({ worktreeId: 'wt-5', name: 'topic-2' })
|
|
expect(calls).toHaveLength(2)
|
|
expect(calls[1]!.params).toMatchObject({
|
|
baseBranch: 'main',
|
|
branchNameOverride: 'topic-2',
|
|
name: 'topic-2'
|
|
})
|
|
})
|
|
})
|