mirror of
https://github.com/stablyai/orca.git
synced 2026-10-31 00:57:45 +00:00
* fix(persistence): worktree meta and lineage writes take the row's host, not the id (R4-2b) * fix(persistence): review fixes for host-targeted worktree writes * test: SAFETY notes on partial runtime store mocks * test: drop imports duplicated by the rebase onto #30797
111 lines
4.0 KiB
TypeScript
111 lines
4.0 KiB
TypeScript
/** The startup terminal a folder workspace's create spawns; this path forwards a reserved pane itself. */
|
|
|
|
import { describe, expect, it, vi } from 'vitest'
|
|
import type { Repo } from '../../shared/repo-types'
|
|
import { createRuntimeFolderWorktree } from './runtime-folder-worktree-create'
|
|
import type { HostWorktreeTarget } from '../../shared/worktree/host-qualified-identity'
|
|
|
|
type CreateArgs = Parameters<typeof createRuntimeFolderWorktree>[0]
|
|
|
|
const repo: Repo = {
|
|
id: 'repo-1',
|
|
path: '/folder',
|
|
displayName: 'folder',
|
|
badgeColor: 'blue',
|
|
addedAt: 1
|
|
}
|
|
|
|
function createDeps() {
|
|
const createTerminal = vi
|
|
.fn<CreateArgs['deps']['createTerminal']>()
|
|
.mockResolvedValue({ handle: 'term-1', worktreeId: 'folder-1', title: null })
|
|
const store = {
|
|
getSettings: () => ({ workspaceDir: '/ws', nestWorkspaces: false }),
|
|
setWorktreeMeta: (_target: HostWorktreeTarget, meta: Record<string, unknown>) => meta,
|
|
getProjectHostSetups: () => []
|
|
}
|
|
const deps: CreateArgs['deps'] = {
|
|
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: the create reads only these three store methods; any other would throw on call rather than read a wrong value.
|
|
store: store as unknown as CreateArgs['deps']['store'],
|
|
ptySpawnAvailable: true,
|
|
createTerminal,
|
|
pasteDraft: vi.fn(),
|
|
sendFollowup: vi.fn(),
|
|
invalidateResolvedWorktrees: vi.fn(),
|
|
notifyWorktreesChanged: vi.fn(),
|
|
emitCreated: vi.fn(),
|
|
activate: 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 createRuntimeFolderWorktree({
|
|
request: {
|
|
repoSelector: `id:${repo.id}`,
|
|
name: 'task',
|
|
...(startupPaneKey ? { startupPaneKey } : {})
|
|
},
|
|
repo,
|
|
createdWithAgent: 'codex',
|
|
startup: { command: 'codex' },
|
|
deps
|
|
})
|
|
return createTerminal.mock.calls[0]?.[1] ?? {}
|
|
}
|
|
|
|
describe('a folder workspace create with a startup agent', () => {
|
|
it('registers a folder launch before announcing its workspace', async () => {
|
|
const { deps } = createDeps()
|
|
const order: string[] = []
|
|
vi.mocked(deps.notifyWorktreesChanged).mockImplementation(() => order.push('notify'))
|
|
const result = await createRuntimeFolderWorktree({
|
|
request: { repoSelector: `id:${repo.id}`, name: 'chat', activate: true },
|
|
repo,
|
|
promisedAgentChat: true,
|
|
onWorkspaceCreated: (id) => order.push(`register:${id}`),
|
|
deps
|
|
})
|
|
expect(order).toEqual([`register:${result.worktree.id}`, 'notify'])
|
|
})
|
|
|
|
it('only promises a chat when the caller explicitly plans one', async () => {
|
|
const { deps } = createDeps()
|
|
await createRuntimeFolderWorktree({
|
|
request: { repoSelector: `id:${repo.id}`, name: 'attributed', activate: true },
|
|
repo,
|
|
createdWithAgent: 'codex',
|
|
deps
|
|
})
|
|
expect(deps.activate).toHaveBeenCalledWith(repo.id, expect.any(String), undefined, undefined)
|
|
})
|
|
|
|
it('seeds a headless activated folder workspace without a paired viewer', async () => {
|
|
const { deps, createTerminal } = createDeps()
|
|
deps.provisionInBackground = () => true
|
|
const result = await createRuntimeFolderWorktree({
|
|
request: { repoSelector: `id:${repo.id}`, name: 'headless', activate: true },
|
|
repo,
|
|
deps
|
|
})
|
|
expect(createTerminal).toHaveBeenCalledWith(`id:${result.worktree.id}`, { surfaceOwner: 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')
|
|
})
|
|
})
|