fix(runtime): explain full worktree id selectors (#7432) (#7892)

* fix(runtime): explain full worktree id selectors (#7432)

* Fix full worktree id selectors for bare repo ids and doc guidance

- Reject bare repo-id selectors up front via a shared validator instead
  of relying on worktree-list scanning, so RPC callers no longer trigger
  an unnecessary rescan just to detect the mistake
- Propagate the structured worktree_id_requires_full_path code through
  RPC error mapping so callers get a typed error, not just a message
- Update orca-cli, orca-emulator, and orchestration skill docs to show
  the full `<repo-id>::<path>` id shape and stop implying a bare repo
  id is a valid worktree selector

---------

Co-authored-by: Jinjing <6427696+AmethystLiang@users.noreply.github.com>
This commit is contained in:
Rod Boev
2026-07-11 22:40:44 -07:00
committed by GitHub
co-authored by Jinjing
parent c99095b1e8
commit 3090ff0edb
12 changed files with 219 additions and 45 deletions
+101
View File
@@ -2257,6 +2257,20 @@ describe('OrcaRuntimeService', () => {
expect(internals.ptysById.has('cwd-only-pty')).toBe(false)
})
it('keeps unknown bare terminal-list ids on the no-scan exact-id path', async () => {
vi.mocked(listWorktrees).mockClear()
vi.mocked(listWorktrees).mockRejectedValue(
new Error('unknown explicit ids should not rescan worktrees')
)
const runtime = createRuntime()
await expect(runtime.listTerminals('id:not-a-repo')).resolves.toMatchObject({
terminals: [],
totalCount: 0
})
expect(listWorktrees).not.toHaveBeenCalled()
})
it('matches explicit-id cwd PTYs for folder workspace instance IDs', async () => {
const folderWorktreeId = `${TEST_REPO_ID}::${TEST_FOLDER_WORKSPACE_PATH}${FOLDER_WORKSPACE_INSTANCE_SEPARATOR}11111111-1111-4111-8111-111111111111`
vi.mocked(listWorktrees).mockClear()
@@ -2579,6 +2593,72 @@ describe('OrcaRuntimeService', () => {
).rejects.toThrow('selector_not_found')
})
it('guides bare repo-id worktree selectors to the full id shape', async () => {
vi.mocked(listWorktrees).mockClear()
vi.mocked(listWorktrees).mockRejectedValue(new Error('bare repo ids should not scan worktrees'))
const runtime = new OrcaRuntimeService(store)
await expect(runtime.showManagedWorktree(`id:${TEST_REPO_ID}`)).rejects.toThrow(
'Worktree id selectors must use the full <repo-id>::<path> value.'
)
expect(listWorktrees).not.toHaveBeenCalled()
})
it('guides registered SSH repo ids without probing the provider', async () => {
const remoteRepo = { ...store.getRepos()[0], connectionId: 'ssh-1' }
const remoteStore = {
...store,
getRepos: () => [remoteRepo],
getRepo: (id: string) => (id === remoteRepo.id ? remoteRepo : undefined)
}
vi.mocked(listWorktrees).mockClear()
getSshGitProviderMock.mockClear()
const runtime = new OrcaRuntimeService(remoteStore)
await expect(runtime.showManagedWorktree(`id:${TEST_REPO_ID}`)).rejects.toMatchObject({
code: 'worktree_id_requires_full_path'
})
expect(listWorktrees).not.toHaveBeenCalled()
expect(getSshGitProviderMock).not.toHaveBeenCalled()
})
it('rejects bare repo ids through terminal list RPC with the structured code', async () => {
vi.mocked(listWorktrees).mockClear()
const runtime = new OrcaRuntimeService(store)
const dispatcher = new RpcDispatcher({ runtime, methods: TERMINAL_METHODS })
const response = await dispatcher.dispatch(
makeRpcRequest('terminal.list', { worktree: `id:${TEST_REPO_ID}` })
)
expect(response).toMatchObject({
ok: false,
error: {
code: 'worktree_id_requires_full_path',
message: expect.stringContaining('full <repo-id>::<path> value')
}
})
expect(listWorktrees).not.toHaveBeenCalled()
})
it('rejects bare repo ids through the mobile session exact-id fast path', async () => {
vi.mocked(listWorktrees).mockClear()
const runtime = new OrcaRuntimeService(store)
await expect(runtime.listMobileSessionTabs(`id:${TEST_REPO_ID}`)).rejects.toMatchObject({
code: 'worktree_id_requires_full_path'
})
expect(listWorktrees).not.toHaveBeenCalled()
})
it('still resolves the full worktree id selector', async () => {
const runtime = new OrcaRuntimeService(store)
await expect(runtime.showManagedWorktree(`id:${TEST_WORKTREE_ID}`)).resolves.toMatchObject({
id: TEST_WORKTREE_ID
})
})
it('still throws selector_not_found for an unknown id selector', async () => {
const runtime = new OrcaRuntimeService(store)
@@ -2587,6 +2667,27 @@ describe('OrcaRuntimeService', () => {
)
})
it('still throws selector_not_found for unknown bare ids', async () => {
const runtime = new OrcaRuntimeService(store)
await expect(runtime.showManagedWorktree('id:not-a-repo')).rejects.toThrow('selector_not_found')
})
it('does not treat partial repo ids as full worktree ids', async () => {
const runtime = new OrcaRuntimeService(store)
await expect(runtime.showManagedWorktree('id:repo')).rejects.toThrow('selector_not_found')
})
it('preserves full-id guidance for explicit parent-worktree lineage selectors', async () => {
const runtime = new OrcaRuntimeService(store)
const resolveLineage = runtime['resolveLineageForWorktreeCreate'].bind(runtime)
await expect(resolveLineage({ parentWorktree: `id:${TEST_REPO_ID}` })).rejects.toThrow(
'Worktree id selectors must use the full <repo-id>::<path> value.'
)
})
it('does not reuse stale in-flight worktree scans after creating a worktree', async () => {
const runtime = new OrcaRuntimeService(store)
const staleScan = deferred<typeof MOCK_GIT_WORKTREES>()