mirror of
https://github.com/stablyai/orca.git
synced 2026-09-29 16:02:50 +00:00
* fix(host-routing): resolve the execution host before reading a connection Three issues in one defect class: a resolver reads one spelling of one arbitrarily chosen row instead of resolving the worktree's execution host, so something local answers a question about a remote. returned that row's connectionId. With duplicate repo rows for one repo id it could pair a runtime owner with a client-owned SSH connection. It now resolves through the same ambiguity-aware index getRuntimeEnvironmentIdForWorktree uses, prefers the repo row for the host the worktree names, and derives the connection from the resolved host. Conflicting rows return `undefined` (this module's documented "cannot determine the host"), never `null`. `store.getRepo(worktree.repoId)?.connectionId ?? null`. `getRepo` is host-blind and the same repo id can exist on local, SSH and runtime hosts, so a remote worktree could spawn its PTY on the client with the remote cwd. resolveWorktreeLaunchHost picks the row for the worktree's host and reads the connection off that host; conflicting rows are unresolved, not local. session-partition owner maps that contradict each other. Both now compute through one shared function whose argument records the divergence. No behaviour change on either side: converging needs a read-both migration, since both partitions hold real data written by shipping builds. * fix(host-routing): keep nested SSH connections resolvable under a runtime host getRepoSshConnectionId read only the resolved execution host, so a repo row owned by a runtime that reaches a nested SSH target (connectionId: ssh-*, executionHostId: runtime:*) resolved to no connection — answering 'local' for a remote worktree, the same defect #17909 fixed in the other direction. * fix(host-routing): resolve both sides of the execution host through one rule The renderer resolver leaked between two different SSH hosts: a worktree on `ssh:m4air` whose only indexed repo row belonged to `openclaw` answered 'openclaw', because the host-scoped lookup missing fell through to an id-only one. Main's resolver, in the same change, answered 'm4air' — two resolvers, one right and one wrong, on identical input. Both sides now adapt one shared rule (`worktree-execution-host-resolution.ts`): the worktree's own host outranks every repo row, and a row on a different host is never evidence about this one. The renderer's WeakMap index becomes the memoizing adapter it always was; `resolveWorktreeLaunchHost` becomes main's mapping of unresolved onto its throw. Settles the rule the change previously answered two ways. `getRepoSshConnectionId` and `getSshTargetIdForExecutionHost` disagreed for a runtime host carrying a nested `connectionId`; they now compose, so the execution host is the single authority. On a `runtime:*` row that field is a paired HUB's private SSH target, spread through by `repoWithFetchedOwner` and unaddressable from this client — the project-first successor of the row nulls it for exactly that reason. That also fixes the `kind !== 'ssh'` fallback, which fired for `local`: a row declaring itself local handed out an SSH connection. * fix(ssh): resolve the execution host in the worktree scan and managed create The worktree scan and createManagedWorktree both picked remote-vs-local from repo.connectionId, so a row stamped only executionHostId: 'ssh:*' was scanned and created on the client against a remote path. The folder branch returns before the check, so its agent-trust write landed locally too. Refs #11163 * fix(ssh): stop over-rejecting and refusing SSH hosts the process owns runtimeRepoMatchesExecutionHost rejected an unstamped SSH repo against its own ssh:<connectionId>, so repo-add/clone dedupe could register a second row for a path the host already owns. assertHostIsSupported made the CLI/runtime RPC refuse --host ssh:* while the same process's IPC handler routed it correctly; setupExistingFolder now shares that registration. Clone still refuses, because nothing in this process clones onto an SSH host. Refs #11163 * test(ssh): retarget the SSH host-setup guard spec at the substitution it prevents setupProjectExistingFolder now registers the remote path through the same addRemoteRepoFromPath the desktop IPC uses, so it fails on the host's terms (connection not registered) rather than a categorical refusal. The local clone/probe side effects it exists to catch are still asserted absent. Refs #11163 * fix(cli): require an absolute path when setting a project up on an SSH host Routing --host ssh:* to the remote registration made relative paths newly reachable there, and they were resolved against the client cwd — registering a path that names the wrong machine. Refs #11163 * fix(repos): read the SSH registry directly so the runtime stays Node-bootable Routing runtime project setup through addRemoteRepoFromPath dragged ipc/ssh -- and its 25-module electron graph -- into the runtime bundle. ssh-target-registry already exists for exactly this; ipc/ssh only re-exports it. * fix(ssh): close the agent-launch and session-export host-blind twins Three sites left on the legacy spelling, all the same shape as the ones this branch already fixed: - `launchAgentTerminal` did `getRepo(worktree.repoId)` then wrote agent trust with that row's `connectionId`. Host-blind, so a repo id carried by two SSH hosts wrote a remote path into the *client's* Codex/Cursor/Copilot config and the agent on the host never saw the trust. Every sibling call site already passes the resolved `workspace.connectionId`; this was the last that did not. - `targetForWorktree` (workspace-session export) fell back to the same host-blind read, so a session could be published to a machine that never owned the worktree. Unresolvable ownership now exports to nobody. - `addRemoteRepoFromPath` minted `connectionId`-only rows while being the routing path this branch adds, so it kept creating rows in exactly the spelling the branch works around. It now stamps `toSshExecutionHostId(connectionId)` at creation; `reassignSshTargetId` already migrates both spellings, so target rename stays correct. Tests cover two *different* SSH hosts throughout — the case none of the earlier duplicate-row tests had, all of which were local-vs-ssh or runtime-vs-ssh.
156 lines
5.8 KiB
TypeScript
156 lines
5.8 KiB
TypeScript
// createManagedWorktree used to pick remote-vs-local from the raw `connectionId` field, so a repo
|
|
// stamped only `executionHostId: 'ssh:*'` ran `git worktree add` on the client against a remote
|
|
// path — and the folder branch, which returns before that check, wrote agent trust locally for a
|
|
// remote workspace. Both are the #11163 shape: read the execution host, never one spelling of it.
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
vi.mock('electron', () => ({
|
|
BrowserWindow: { fromId: vi.fn(() => null) },
|
|
webContents: { fromId: vi.fn(() => null) },
|
|
ipcMain: { on: vi.fn(), removeListener: vi.fn() },
|
|
app: { getPath: vi.fn(() => '/tmp'), isPackaged: false }
|
|
}))
|
|
|
|
const createRuntimeFolderWorktreeMock = vi.hoisted(() => vi.fn())
|
|
vi.mock('./runtime-folder-worktree-create', () => ({
|
|
createRuntimeFolderWorktree: createRuntimeFolderWorktreeMock
|
|
}))
|
|
|
|
const createRuntimeLocalManagedWorktreeMock = vi.hoisted(() => vi.fn())
|
|
vi.mock('./runtime-local-worktree-create', () => ({
|
|
createRuntimeLocalManagedWorktree: createRuntimeLocalManagedWorktreeMock
|
|
}))
|
|
|
|
const trustMocks = vi.hoisted(() => ({
|
|
local: vi.fn(async () => {}),
|
|
remote: vi.fn(async () => {})
|
|
}))
|
|
vi.mock('./runtime-worktree-agent-startup', async (importOriginal) => ({
|
|
...(await importOriginal<Record<string, unknown>>()),
|
|
markLocalWorktreeTrusted: trustMocks.local,
|
|
markRemoteWorktreeTrusted: trustMocks.remote
|
|
}))
|
|
|
|
import { OrcaRuntimeService } from './orca-runtime'
|
|
|
|
const TARGET_ID = 'remote-1'
|
|
const REMOTE_PATH = '/srv/app'
|
|
|
|
type RuntimeInternals = {
|
|
resolveRepoSelector: (selector: string) => Promise<unknown>
|
|
createManagedRemoteWorktree: (repo: unknown, args: unknown) => Promise<unknown>
|
|
resolveLineageForWorktreeCreate: (input: unknown) => Promise<unknown>
|
|
recordCreatedWorktreeLineage: (worktree: unknown, resolution: unknown) => unknown
|
|
}
|
|
|
|
function makeRuntime(repo: Record<string, unknown>): {
|
|
runtime: OrcaRuntimeService
|
|
createRemote: ReturnType<typeof vi.fn>
|
|
} {
|
|
const store = {
|
|
getSettings: () => ({ disabledTuiAgents: [], workspaceDir: '/tmp/workspaces' }),
|
|
getProjectHostSetups: () => []
|
|
}
|
|
const runtime = new OrcaRuntimeService(store as never)
|
|
const internals = runtime as unknown as RuntimeInternals
|
|
vi.spyOn(internals, 'resolveRepoSelector').mockResolvedValue(repo)
|
|
vi.spyOn(internals, 'resolveLineageForWorktreeCreate').mockResolvedValue(null)
|
|
vi.spyOn(internals, 'recordCreatedWorktreeLineage').mockReturnValue({
|
|
lineage: null,
|
|
workspaceLineage: null,
|
|
warnings: []
|
|
})
|
|
const createRemote = vi.fn().mockResolvedValue({
|
|
worktree: { id: 'wt-1', path: '/srv/app-feature', branch: 'feature' }
|
|
})
|
|
vi.spyOn(internals, 'createManagedRemoteWorktree').mockImplementation(createRemote)
|
|
return { runtime, createRemote }
|
|
}
|
|
|
|
describe('createManagedWorktree execution-host routing', () => {
|
|
beforeEach(() => {
|
|
createRuntimeFolderWorktreeMock.mockReset()
|
|
createRuntimeFolderWorktreeMock.mockResolvedValue({ worktree: { id: 'folder-1' } })
|
|
createRuntimeLocalManagedWorktreeMock.mockReset()
|
|
// Name the defect in the failure output: reaching this mock means a remote repo was routed
|
|
// into a client-side `git worktree add`.
|
|
createRuntimeLocalManagedWorktreeMock.mockRejectedValue(
|
|
new Error('local_worktree_create_ran_for_remote_repo')
|
|
)
|
|
trustMocks.local.mockClear()
|
|
trustMocks.remote.mockClear()
|
|
})
|
|
|
|
it('creates on the SSH host for a repo stamped executionHostId only', async () => {
|
|
const { runtime, createRemote } = makeRuntime({
|
|
id: 'repo-remote',
|
|
path: REMOTE_PATH,
|
|
kind: 'git',
|
|
executionHostId: `ssh:${TARGET_ID}`
|
|
})
|
|
|
|
await runtime.createManagedWorktree({ repoSelector: 'repo-remote', name: 'feature' } as never)
|
|
|
|
// A local `git worktree add` against a remote path is the silent-substitution failure.
|
|
expect(createRuntimeLocalManagedWorktreeMock).not.toHaveBeenCalled()
|
|
expect(createRemote).toHaveBeenCalledWith(
|
|
expect.objectContaining({ id: 'repo-remote', connectionId: TARGET_ID }),
|
|
expect.anything()
|
|
)
|
|
})
|
|
|
|
it('still creates on the SSH host for a legacy connectionId-only repo', async () => {
|
|
const { runtime, createRemote } = makeRuntime({
|
|
id: 'repo-remote',
|
|
path: REMOTE_PATH,
|
|
kind: 'git',
|
|
connectionId: TARGET_ID
|
|
})
|
|
|
|
await runtime.createManagedWorktree({ repoSelector: 'repo-remote', name: 'feature' } as never)
|
|
|
|
expect(createRuntimeLocalManagedWorktreeMock).not.toHaveBeenCalled()
|
|
expect(createRemote).toHaveBeenCalledWith(
|
|
expect.objectContaining({ connectionId: TARGET_ID }),
|
|
expect.anything()
|
|
)
|
|
})
|
|
|
|
it('marks a folder workspace trusted on its SSH host, not on the client', async () => {
|
|
const { runtime } = makeRuntime({
|
|
id: 'repo-folder',
|
|
path: REMOTE_PATH,
|
|
kind: 'folder',
|
|
connectionId: TARGET_ID,
|
|
executionHostId: `ssh:${TARGET_ID}`
|
|
})
|
|
|
|
await runtime.createManagedWorktree({ repoSelector: 'repo-folder', name: 'notes' } as never)
|
|
|
|
const deps = createRuntimeFolderWorktreeMock.mock.calls[0]?.[0]?.deps
|
|
await deps.markTrusted('codex', '/srv/app')
|
|
|
|
expect(trustMocks.remote).toHaveBeenCalledWith('codex', TARGET_ID, '/srv/app')
|
|
expect(trustMocks.local).not.toHaveBeenCalled()
|
|
})
|
|
|
|
it('keeps a local folder workspace trusted on the client', async () => {
|
|
const { runtime } = makeRuntime({
|
|
id: 'repo-folder-local',
|
|
path: '/Users/me/notes',
|
|
kind: 'folder'
|
|
})
|
|
|
|
await runtime.createManagedWorktree({
|
|
repoSelector: 'repo-folder-local',
|
|
name: 'notes'
|
|
} as never)
|
|
|
|
const deps = createRuntimeFolderWorktreeMock.mock.calls[0]?.[0]?.deps
|
|
await deps.markTrusted('codex', '/Users/me/notes')
|
|
|
|
expect(trustMocks.local).toHaveBeenCalledWith('codex', '/Users/me/notes')
|
|
expect(trustMocks.remote).not.toHaveBeenCalled()
|
|
})
|
|
})
|