Files
orca/src/main/runtime/orca-runtime-structured-agent-session-create-intent.test.ts
T

106 lines
3.5 KiB
TypeScript

import { describe, expect, it, vi } from 'vitest'
import { OrcaRuntimeService } from './orca-runtime'
describe('structured agent-session create intent', () => {
it('pins the selected Codex launch home after normal launch preparation', async () => {
const prepareCodexStructuredLaunch = vi.fn(() => '/accounts/selected/home')
const runtime = new OrcaRuntimeService(
{
getSettings: () => ({
agentDefaultEnv: { codex: { CODEX_HOME: '/configured/home' } }
})
} as never,
undefined,
{ prepareCodexStructuredLaunch }
)
vi.spyOn(runtime, 'getStructuredAgentSessionCreateSupport').mockResolvedValue({
supported: true
})
const internal = runtime as unknown as {
resolveStructuredAgentSessionLocation: (selector: string) => Promise<{
executionHostId: string
wslDistro: null
workspaceId: string
workspaceKind: 'git-worktree'
}>
resolveRuntimeFileTarget: (selector: string) => Promise<{
worktree: { path: string }
}>
}
internal.resolveStructuredAgentSessionLocation = vi.fn(async () => ({
executionHostId: 'local',
wslDistro: null,
workspaceId: 'workspace-1',
workspaceKind: 'git-worktree' as const
}))
internal.resolveRuntimeFileTarget = vi.fn(async () => ({
worktree: { path: '/repos/workspace-1' }
}))
const intent = await runtime.resolveStructuredAgentSessionCreateIntent({
envelope: { sessionId: 'session-1', clientOperationId: 'operation-1' },
worktree: 'id:workspace-1',
agent: 'codex'
})
expect(prepareCodexStructuredLaunch).toHaveBeenCalledWith({
workspacePath: '/repos/workspace-1',
launchEnv: expect.objectContaining({ CODEX_HOME: '/configured/home' })
})
expect(intent.accountHome).toEqual({
variable: 'CODEX_HOME',
path: '/accounts/selected/home'
})
})
it('pins the configured Claude launch home without Codex launch preparation', async () => {
const prepareCodexStructuredLaunch = vi.fn()
const runtime = new OrcaRuntimeService(
{
getSettings: () => ({
agentDefaultEnv: {
claude: { CLAUDE_CONFIG_DIR: '/configured/claude-home' }
}
})
} as never,
undefined,
{ prepareCodexStructuredLaunch }
)
vi.spyOn(runtime, 'getStructuredAgentSessionCreateSupport').mockResolvedValue({
supported: true
})
const internal = runtime as unknown as {
resolveStructuredAgentSessionLocation: (selector: string) => Promise<{
executionHostId: string
wslDistro: null
workspaceId: string
workspaceKind: 'git-worktree'
}>
resolveRuntimeFileTarget: (selector: string) => Promise<{
worktree: { path: string }
}>
}
internal.resolveStructuredAgentSessionLocation = vi.fn(async () => ({
executionHostId: 'local',
wslDistro: null,
workspaceId: 'workspace-1',
workspaceKind: 'git-worktree' as const
}))
internal.resolveRuntimeFileTarget = vi.fn(async () => ({
worktree: { path: '/repos/workspace-1' }
}))
const intent = await runtime.resolveStructuredAgentSessionCreateIntent({
envelope: { sessionId: 'session-1', clientOperationId: 'operation-1' },
worktree: 'id:workspace-1',
agent: 'claude'
})
expect(prepareCodexStructuredLaunch).not.toHaveBeenCalled()
expect(intent.accountHome).toEqual({
variable: 'CLAUDE_CONFIG_DIR',
path: '/configured/claude-home'
})
})
})