mirror of
https://github.com/stablyai/orca.git
synced 2026-09-29 16:02:50 +00:00
`RuntimeGitTarget` carried `connectionId?: string` and no host id, so `undefined` spelled three different answers at once — "runtime: host", "unresolved", and "genuinely local". Its sole resolver read `store.getRepo(worktree.repoId)?.connectionId` and never looked at `worktree.hostId`, which outranks every repo row, so one arbitrarily chosen row decided the execution host for 36 downstream dispatches. The target now carries `executionHostId: ExecutionHostId` (never null, never optional), resolved through the shared rule that landed with #17909/#17919 and dispatched through the host-keyed routes from #18296. Dispatch sites call `requireRuntimeGitProvider`, where `null` means exactly one thing: the host is `local` and the command runs here as free functions. Four answers that used to collapse into one: - `ssh:x` with a rival row on `ssh:y` — routes to x. Previously the first row won, which is the reproduced cross-host leak. - `local` with a surviving `connectionId` — a row contradicting itself; no SSH connection is handed out. - `runtime:<env>` — throws `ExecutionHostNotDispatchableError`. Its repo row's connection names a target in the *server's* namespace; dialling it here reaches a same-named target on this client. - rival rows disagreeing with no worktree host — `worktree_execution_host_unresolved`, matching the launch path rather than guessing a row. An unreachable SSH host still throws `SSH_GIT_PROVIDER_UNAVAILABLE_MESSAGE`; loss of contact is never evidence of locality (docs/reference/ssh-execution-boundary.md). `resolveWorktreeLaunchHost` keeps its exact signature and now delegates to `resolveWorktreeHostRouting`, the same resolution answering "which host is this on" rather than "what may this client dial" — the git target needs the first question because `local` and `runtime:` are two different non-SSH answers. No wire change: `RuntimeGitTarget` is main-process internal, and the SSH and local model-discovery host keys are byte-identical to before. `RuntimeFileTarget` has the same defect in ~30 filesystem dispatches and is deliberately left for a follow-up.
61 lines
2.2 KiB
TypeScript
61 lines
2.2 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest'
|
|
import type { GitAdmissionEvent } from '../git/command-runner/git-admission-state'
|
|
import { GitAdmissionScheduler } from '../git/command-runner/git-subprocess-admission'
|
|
import type * as GitStatusModule from '../git/status'
|
|
import type { OrcaRuntimeService } from './orca-runtime'
|
|
import { RpcDispatcher } from './rpc/dispatcher'
|
|
import { GIT_METHODS } from './rpc/methods/git'
|
|
import { RuntimeGitStatusCommands } from './runtime-git-status-commands'
|
|
|
|
const getStatusMock = vi.hoisted(() => vi.fn())
|
|
|
|
vi.mock('../git/status', async () => ({
|
|
...(await vi.importActual<typeof GitStatusModule>('../git/status')),
|
|
getStatus: getStatusMock
|
|
}))
|
|
|
|
describe('runtime git status admission', () => {
|
|
it('admits RPC reads at the caller tier and defaults future tiers to status', async () => {
|
|
const events: GitAdmissionEvent[] = []
|
|
const scheduler = new GitAdmissionScheduler({
|
|
onAdmissionEvent: (event) => events.push(event)
|
|
})
|
|
getStatusMock.mockImplementation(async (worktreePath, options) => {
|
|
const grant = await scheduler.acquire({
|
|
args: ['status'],
|
|
cwd: worktreePath,
|
|
tier: options.admissionTier
|
|
})
|
|
grant.release()
|
|
return { entries: [], conflictOperation: 'none' }
|
|
})
|
|
const commands = new RuntimeGitStatusCommands({
|
|
resolveRuntimeGitTarget: async () => ({
|
|
worktree: { path: '/workspace/feature' },
|
|
executionHostId: 'local'
|
|
})
|
|
} as never)
|
|
const runtime = {
|
|
getRuntimeId: () => 'test-runtime',
|
|
getRuntimeGitStatus: commands.getRuntimeGitStatus.bind(commands)
|
|
} as unknown as OrcaRuntimeService
|
|
const dispatcher = new RpcDispatcher({ runtime, methods: GIT_METHODS })
|
|
|
|
for (const admissionTier of ['background', 'interactive', 'future-tier']) {
|
|
const response = await dispatcher.dispatch({
|
|
id: `request-${admissionTier}`,
|
|
authToken: 'token',
|
|
method: 'git.status',
|
|
params: { worktree: 'id:wt-1', admissionTier }
|
|
})
|
|
expect(response.ok).toBe(true)
|
|
}
|
|
|
|
expect(events.filter((event) => event.phase === 'grant').map((event) => event.tier)).toEqual([
|
|
'background',
|
|
'interactive',
|
|
'status'
|
|
])
|
|
})
|
|
})
|