Files
orca/mobile/src/tasks/worktree-create-capability.test.ts
T
Jinjing bc55fe3cb0 Support explicit remote branch reuse across workspaces (#34295)
* Support explicit remote branch reuse across workspaces

- Preserve selected branch identity, tracking, and busy-branch handling
- Add explicit branch-off intent with v2 runtime capability gating

* Style existing workspace action in branch reuse UI

* Preserve explicit branch reuse with versioned host support

- Gate strict reuse on a new request capability while retaining legacy behavior
- Warn when a reused remote branch cannot be configured as the push upstream

* Clarify selected branch checkout options

* Offer existing or new branch choices for worktrees

* Preserve new-branch intent when reusing a branch name

* Adapt branch composer tests and catalog after rebase

* Refresh mobile RPC recordings for branch intent capabilities

* Remove retired Russian localization entries

* Remove retired German and Turkish localization entries

* Add branch selection translations for existing workspaces

* Localize mobile worktree branch selection
2026-10-28 20:48:16 -07:00

257 lines
7.7 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import {
AGENT_LAUNCH_REPLAY_REQUIRED_RUNTIME_CAPABILITY,
AGENT_LAUNCH_REPLAY_RUNTIME_CAPABILITY,
AGENT_LAUNCH_RUNTIME_CAPABILITY
} from '../../../src/shared/agent-launch-runtime-capability'
import type { RpcClient } from '../transport/rpc-client'
import { LogicalClientCutoverError } from '../transport/stable-logical-rpc-client'
import { readNewWorktreeRuntimeCapabilities } from './worktree-create-capability'
import { createFakeRpcClient } from '../mobile-web-shell/bridge-host-test-fakes'
type StatusOutcome =
| 'cutover'
| 'error'
| string[]
| {
capabilities?: string[]
worktreeCreateIdempotency?: unknown
}
function statusClient(outcomes: StatusOutcome[]): RpcClient {
let call = 0
return {
...createFakeRpcClient(),
sendRequest: async () => {
const outcome = outcomes[Math.min(call, outcomes.length - 1)]!
call += 1
if (outcome === 'cutover') {
throw new LogicalClientCutoverError()
}
if (outcome === 'error') {
throw new Error('offline')
}
const result = Array.isArray(outcome)
? { capabilities: outcome, hostPlatform: 'darwin' }
: { ...outcome, hostPlatform: 'darwin' }
return {
id: '1',
ok: true,
result,
_meta: { runtimeId: 'r' }
}
}
}
}
describe('readNewWorktreeRuntimeCapabilities', () => {
it('reads task and idempotent-create support from status.get', async () => {
await expect(
readNewWorktreeRuntimeCapabilities(
statusClient([
{
capabilities: ['mobile.tasks.v1', 'worktree.create-idempotency.v1'],
worktreeCreateIdempotency: { dedupeTtlMs: 20_000 }
}
])
)
).resolves.toEqual({
branchIntentV2: false,
branchIntentV2Request: false,
tasksSupported: true,
worktreeCreateIdempotency: { dedupeTtlMs: 20_000 },
agentLaunch: false,
hostPlatform: 'darwin'
})
})
it('reads agent.launch support from the same status.get probe', async () => {
// Resolve launch and create-idempotency support in one probe so creation cannot straddle inconsistent answers.
await expect(
readNewWorktreeRuntimeCapabilities(
statusClient([{ capabilities: [AGENT_LAUNCH_RUNTIME_CAPABILITY] }])
)
).resolves.toEqual({
branchIntentV2: false,
branchIntentV2Request: false,
tasksSupported: false,
worktreeCreateIdempotency: false,
// Method support does not imply ledger support; older hosts may silently strip operationId.
agentLaunch: { replay: false },
hostPlatform: 'darwin'
})
})
it('reads launch replay support only when the host advertises the ledger', async () => {
await expect(
readNewWorktreeRuntimeCapabilities(
statusClient([
{
capabilities: [
AGENT_LAUNCH_RUNTIME_CAPABILITY,
AGENT_LAUNCH_REPLAY_REQUIRED_RUNTIME_CAPABILITY
]
}
])
)
).resolves.toEqual({
branchIntentV2: false,
branchIntentV2Request: false,
tasksSupported: false,
worktreeCreateIdempotency: false,
agentLaunch: { replay: true },
hostPlatform: 'darwin'
})
})
// Ledger capability alone cannot enable a missing launch method.
it('ignores the replay capability on a host without agent.launch', async () => {
await expect(
readNewWorktreeRuntimeCapabilities(
statusClient([{ capabilities: [AGENT_LAUNCH_REPLAY_REQUIRED_RUNTIME_CAPABILITY] }])
)
).resolves.toMatchObject({ agentLaunch: false })
})
it('does not authorize replay from the optional-identity capability alone', async () => {
await expect(
readNewWorktreeRuntimeCapabilities(
statusClient([
{
capabilities: [AGENT_LAUNCH_RUNTIME_CAPABILITY, AGENT_LAUNCH_REPLAY_RUNTIME_CAPABILITY]
}
])
)
).resolves.toMatchObject({ agentLaunch: { replay: false } })
})
it('uses the bounded fallback for an old idempotent host without an advertisement', async () => {
await expect(
readNewWorktreeRuntimeCapabilities(statusClient([['worktree.create-idempotency.v1']]))
).resolves.toEqual({
branchIntentV2: false,
branchIntentV2Request: false,
tasksSupported: false,
worktreeCreateIdempotency: { dedupeTtlMs: 60_000 },
agentLaunch: false,
hostPlatform: 'darwin'
})
})
it('fails closed when a valid idempotency container omits dedupeTtlMs', async () => {
await expect(
readNewWorktreeRuntimeCapabilities(
statusClient([
{
capabilities: ['worktree.create-idempotency.v1'],
worktreeCreateIdempotency: {}
}
])
)
).resolves.toEqual({
branchIntentV2: false,
branchIntentV2Request: false,
tasksSupported: false,
worktreeCreateIdempotency: { dedupeTtlMs: 0 },
agentLaunch: false,
hostPlatform: 'darwin'
})
})
it.each([
{ label: 'null', value: null },
{ label: 'string', value: 'nonsense' },
{ label: 'number', value: 20_000 },
{ label: 'empty array', value: [] }
])(
'fails closed for a malformed idempotency container ($label)',
async ({ value: worktreeCreateIdempotency }) => {
await expect(
readNewWorktreeRuntimeCapabilities(
statusClient([
{
capabilities: ['worktree.create-idempotency.v1'],
worktreeCreateIdempotency
}
])
)
).resolves.toEqual({
branchIntentV2: false,
branchIntentV2Request: false,
tasksSupported: false,
worktreeCreateIdempotency: { dedupeTtlMs: 0 },
agentLaunch: false,
hostPlatform: 'darwin'
})
}
)
it('clamps an over-large host advertisement to the client fallback ceiling', async () => {
await expect(
readNewWorktreeRuntimeCapabilities(
statusClient([
{
capabilities: ['worktree.create-idempotency.v1'],
worktreeCreateIdempotency: { dedupeTtlMs: 600_000 }
}
])
)
).resolves.toEqual({
branchIntentV2: false,
branchIntentV2Request: false,
tasksSupported: false,
worktreeCreateIdempotency: { dedupeTtlMs: 60_000 },
agentLaunch: false,
hostPlatform: 'darwin'
})
})
it.each(['60000', -1, Number.NaN, 60_000.5, {}])(
'fails closed for malformed host advertisement %j',
async (advertisedDedupeTtlMs) => {
await expect(
readNewWorktreeRuntimeCapabilities(
statusClient([
{
capabilities: ['worktree.create-idempotency.v1'],
worktreeCreateIdempotency: { dedupeTtlMs: advertisedDedupeTtlMs }
}
])
)
).resolves.toEqual({
branchIntentV2: false,
branchIntentV2Request: false,
tasksSupported: false,
worktreeCreateIdempotency: { dedupeTtlMs: 0 },
agentLaunch: false,
hostPlatform: 'darwin'
})
}
)
it('retries the safe status probe after a connection cutover', async () => {
await expect(
readNewWorktreeRuntimeCapabilities(
statusClient([
'cutover',
{
capabilities: ['worktree.create-idempotency.v1'],
worktreeCreateIdempotency: { dedupeTtlMs: 30_000 }
}
])
)
).resolves.toEqual({
branchIntentV2: false,
branchIntentV2Request: false,
tasksSupported: false,
worktreeCreateIdempotency: { dedupeTtlMs: 30_000 },
agentLaunch: false,
hostPlatform: 'darwin'
})
})
it('fails closed when capability detection is unavailable', async () => {
await expect(readNewWorktreeRuntimeCapabilities(statusClient(['error']))).resolves.toBeNull()
})
})