mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 02:47:34 +00:00
92 lines
3.8 KiB
TypeScript
92 lines
3.8 KiB
TypeScript
// L270: a layout-owner serve host must persist the paired client’s requested tabPlacement using server group/tab ids.
|
||
import { randomUUID } from 'node:crypto'
|
||
import { existsSync } from 'node:fs'
|
||
import path from 'node:path'
|
||
import { AGENT_SESSION_CREATE_TAB_PLACEMENT_RUNTIME_CAPABILITY } from '../../src/shared/agent-session/agent-session-create-capabilities'
|
||
import {
|
||
createStructuredAgentSessionId,
|
||
structuredAgentSessionCreateParams
|
||
} from '../../src/shared/agent-session/structured-agent-session-create'
|
||
import { structuredAgentSessionTabId } from '../../src/shared/agent-session/view/structured-agent-session-projection'
|
||
import { HOST_TERMINAL_SURFACE_SEPARATOR } from '../../src/shared/workspace-layout/terminal-surface-id'
|
||
import { expect, test } from './helpers/orca-app'
|
||
import { launchHeadlessPairedRuntimeHost } from './helpers/headless-paired-runtime-host'
|
||
import { readServerLayout } from './helpers/paired-desktop-server-layout'
|
||
|
||
const LAYOUT_OWNER_BUILD = existsSync(
|
||
path.join(process.cwd(), 'out', 'main', 'ORCA_LAYOUT_OWNER_MAIN')
|
||
)
|
||
|
||
test.describe('a chat a paired client creates lands where it asked', () => {
|
||
test.skip(!LAYOUT_OWNER_BUILD, 'Needs a layout-owner build (ORCA_LAYOUT_OWNER=main)')
|
||
|
||
test('between two terminals, after the one the client named', async ({ testRepoPath }) => {
|
||
test.setTimeout(180_000)
|
||
const host = await launchHeadlessPairedRuntimeHost()
|
||
try {
|
||
const status = await host.client.call<{ capabilities?: string[] }>('status.get')
|
||
expect(status.result.capabilities ?? []).toContain(
|
||
AGENT_SESSION_CREATE_TAB_PLACEMENT_RUNTIME_CAPABILITY
|
||
)
|
||
const added = await host.client.call<{ repo: { id: string } }>('repo.add', {
|
||
path: testRepoPath,
|
||
kind: 'folder'
|
||
})
|
||
let worktreeId = ''
|
||
await expect
|
||
.poll(async () => {
|
||
const listed = await host.client.call<{ worktrees: { id: string }[] }>('worktree.list', {
|
||
repo: `id:${added.result.repo.id}`
|
||
})
|
||
return (worktreeId = listed.result.worktrees[0]?.id ?? '')
|
||
})
|
||
.not.toBe('')
|
||
const worktree = `id:${worktreeId}`
|
||
const terminal = async (): Promise<string> => {
|
||
const created = await host.client.call<{ tab: { id: string } }>(
|
||
'session.tabs.createTerminal',
|
||
{ worktree, activate: false, select: false, navigation: 'caller' }
|
||
)
|
||
return created.result.tab.id.split(HOST_TERMINAL_SURFACE_SEPARATOR)[0]!
|
||
}
|
||
const first = await terminal()
|
||
const second = await terminal()
|
||
let groupId = ''
|
||
await expect
|
||
.poll(async () => {
|
||
const group = (await readServerLayout(host, worktreeId))?.groups.find(
|
||
(entry) => entry.tabIds.includes(first) && entry.tabIds.includes(second)
|
||
)
|
||
groupId = group?.id ?? ''
|
||
return group?.tabIds.filter((id) => id === first || id === second)
|
||
})
|
||
.toEqual([first, second])
|
||
|
||
const sessionId = createStructuredAgentSessionId('claude', randomUUID)
|
||
await host.client.call(
|
||
'agentSession.create',
|
||
structuredAgentSessionCreateParams({
|
||
sessionId,
|
||
worktree,
|
||
agent: 'claude',
|
||
tabPlacement: { groupId, afterTabId: first },
|
||
randomUuid: randomUUID
|
||
})
|
||
)
|
||
|
||
const chatTabId = structuredAgentSessionTabId(sessionId)
|
||
await expect
|
||
.poll(
|
||
async () =>
|
||
(await readServerLayout(host, worktreeId))?.groups
|
||
.find((entry) => entry.id === groupId)
|
||
?.tabIds.filter((id) => id === first || id === second || id === chatTabId),
|
||
{ timeout: 30_000, message: 'The chat never landed after the terminal the client named' }
|
||
)
|
||
.toEqual([first, chatTabId, second])
|
||
} finally {
|
||
await host.dispose()
|
||
}
|
||
})
|
||
})
|