test: avoid full runtime imports in RPC boundary tests (#29721)

This commit is contained in:
Neil
2026-10-16 08:15:05 -07:00
committed by GitHub
parent 41beb2d0a3
commit 572bde869e
5 changed files with 46 additions and 22 deletions
@@ -634,6 +634,10 @@ describe('OrcaRuntimeService', () => {
})
.catch((error: unknown) => error)
expect(() => runtime.addSshRepo({ connectionId: 'openclaw' })).toThrow(
'SSH connection "openclaw" not found or not connected'
)
// Why: the defect was a silent local clone/probe recorded as remote, not a bad message,
// so the absent side effects are asserted before the wording. Both calls are awaited
// first so a regression reports the corruption rather than stopping at the first throw.
@@ -1,7 +1,7 @@
import '../unused-default-rpc-methods.test-fixture'
import { describe, expect, it, vi } from 'vitest'
import { RpcDispatcher } from '../dispatcher'
import { OrcaRuntimeService } from '../../orca-runtime'
import type { OrcaRuntimeService } from '../../orca-runtime'
import type { DirEntry } from '../../../../shared/filesystem-entry-types'
import { FILE_METHODS } from './files'
@@ -12,9 +12,17 @@ const HUGE_LISTING: DirEntry[] = Array.from({ length: 80_000 }, (_, index) => ({
}))
function dispatcherWithListing(entries: DirEntry[]) {
const runtime = new OrcaRuntimeService()
vi.spyOn(runtime, 'readFileExplorerDir').mockResolvedValue(entries)
return new RpcDispatcher({ runtime, methods: FILE_METHODS })
const runtime: Pick<OrcaRuntimeService, 'getRuntimeId' | 'readFileExplorerDir'> = {
getRuntimeId: () => 'test-runtime',
readFileExplorerDir: vi
.fn<OrcaRuntimeService['readFileExplorerDir']>()
.mockResolvedValue(entries)
}
return new RpcDispatcher({
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: files.readDir uses readFileExplorerDir; its response envelope reads only getRuntimeId.
runtime: runtime as OrcaRuntimeService,
methods: FILE_METHODS
})
}
async function readDir(clientKind: 'runtime' | undefined) {
+4 -2
View File
@@ -1,6 +1,6 @@
import '../unused-default-rpc-methods.test-fixture'
import { describe, expect, it, vi } from 'vitest'
import { OrcaRuntimeService } from '../../orca-runtime'
import type { OrcaRuntimeService } from '../../orca-runtime'
import { RpcDispatcher } from '../dispatcher'
import { PAIRING_METHODS } from './pairing'
@@ -10,8 +10,10 @@ function dispatchPairing(
pairing: NonNullable<Parameters<RpcDispatcher['dispatchStreaming']>[2]>['pairing']
): Promise<Record<string, unknown>> {
return new Promise((resolve) => {
const runtime = { getRuntimeId: () => 'test-runtime' }
const dispatcher = new RpcDispatcher({
runtime: new OrcaRuntimeService(),
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: Pairing handlers use the supplied pairing context; the envelope reads only getRuntimeId.
runtime: runtime as OrcaRuntimeService,
methods: PAIRING_METHODS
})
void dispatcher.dispatchStreaming(
+20 -13
View File
@@ -2,7 +2,7 @@ import '../unused-default-rpc-methods.test-fixture'
import { describe, expect, it, vi } from 'vitest'
import { RpcDispatcher } from '../dispatcher'
import type { RpcRequest } from '../core'
import { OrcaRuntimeService } from '../../orca-runtime'
import type { OrcaRuntimeService } from '../../orca-runtime'
import { REPO_METHODS } from './repo'
import {
NATIVE_REMOTE_RUNTIME_CLIENT_CAPABILITIES,
@@ -18,6 +18,16 @@ function makeRequest(method: string, params?: unknown): RpcRequest {
return { id: 'req-1', authToken: 'tok', method, params }
}
function repoDispatcher(
runtime: Pick<OrcaRuntimeService, 'getRuntimeId'> & Partial<OrcaRuntimeService>
) {
return new RpcDispatcher({
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: These RPC cases supply every runtime method their handlers and envelope access.
runtime: runtime as OrcaRuntimeService,
methods: REPO_METHODS
})
}
describe('repo RPC methods', () => {
it('advertises qualified-ref support from hosts and native remote clients', () => {
expect(RUNTIME_CAPABILITIES).toContain(REPO_SEARCH_QUALIFIED_REFS_RUNTIME_CAPABILITY)
@@ -179,10 +189,9 @@ describe('repo RPC methods', () => {
connectionId: 'ssh-p8',
kind: 'git' as const
}
const runtime = new OrcaRuntimeService(null)
const addSshRepo = vi.spyOn(runtime, 'addSshRepo').mockResolvedValue(repo)
const addRepo = vi.spyOn(runtime, 'addRepo')
const dispatcher = new RpcDispatcher({ runtime, methods: REPO_METHODS })
const addSshRepo = vi.fn<OrcaRuntimeService['addSshRepo']>().mockResolvedValue(repo)
const addRepo = vi.fn<OrcaRuntimeService['addRepo']>()
const dispatcher = repoDispatcher({ getRuntimeId: () => 'test-runtime', addSshRepo, addRepo })
const response = await dispatcher.dispatch(
makeRequest('repo.addRemote', { connectionId: 'ssh-p8', remotePath: '/srv/project' }),
@@ -195,9 +204,8 @@ describe('repo RPC methods', () => {
})
it('refuses a remote project without an SSH target rather than adding a server path', async () => {
const runtime = new OrcaRuntimeService(null)
const addSshRepo = vi.spyOn(runtime, 'addSshRepo')
const dispatcher = new RpcDispatcher({ runtime, methods: REPO_METHODS })
const addSshRepo = vi.fn<OrcaRuntimeService['addSshRepo']>()
const dispatcher = repoDispatcher({ getRuntimeId: () => 'test-runtime', addSshRepo })
const response = await dispatcher.dispatch(
makeRequest('repo.addRemote', { remotePath: '/srv/project' })
@@ -502,8 +510,7 @@ describe('repo RPC methods', () => {
})
it('persists normalized ghAccount bindings and clear sentinels', async () => {
const runtime = new OrcaRuntimeService(null)
vi.spyOn(runtime, 'updateRepo').mockResolvedValue({
const updateRepo = vi.fn<OrcaRuntimeService['updateRepo']>().mockResolvedValue({
id: 'repo-1',
path: '/srv/repo',
displayName: 'repo',
@@ -511,7 +518,7 @@ describe('repo RPC methods', () => {
addedAt: 0,
ghAccount: { host: 'github.com', user: 'Alice' }
})
const dispatcher = new RpcDispatcher({ runtime, methods: REPO_METHODS })
const dispatcher = repoDispatcher({ getRuntimeId: () => 'test-runtime', updateRepo })
const response = await dispatcher.dispatch(
makeRequest('repo.update', {
@@ -521,7 +528,7 @@ describe('repo RPC methods', () => {
{ clientCapabilities: [WORKTREE_VISIBILITY_DEFAULTS_RUNTIME_CAPABILITY] }
)
expect(runtime.updateRepo).toHaveBeenCalledWith('repo-1', {
expect(updateRepo).toHaveBeenCalledWith('repo-1', {
ghAccount: { host: 'github.com', user: 'Alice' }
})
expect(response).toMatchObject({
@@ -535,7 +542,7 @@ describe('repo RPC methods', () => {
updates: { ghAccount: null }
})
)
expect(runtime.updateRepo).toHaveBeenLastCalledWith('repo-1', { ghAccount: null })
expect(updateRepo).toHaveBeenLastCalledWith('repo-1', { ghAccount: null })
})
it('persists agent worktree visibility updates', async () => {
@@ -1,7 +1,8 @@
import './unused-default-rpc-methods.test-fixture'
import { randomUUID } from 'node:crypto'
import { z } from 'zod'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { OrcaRuntimeService } from '../orca-runtime'
import type { OrcaRuntimeService } from '../orca-runtime'
import { publishHostDescriptor } from '../host-descriptor'
import { defineMethod, type RpcRequest } from './core'
import { RpcDispatcher } from './dispatcher'
@@ -19,7 +20,8 @@ describe('runtime source admission', () => {
})
function createHarness(installationId: string | null = SOURCE_A) {
const runtime = new OrcaRuntimeService()
const id = randomUUID()
const runtime = { getRuntimeId: () => id }
const runtimeId = runtime.getRuntimeId()
if (installationId) {
publishHostDescriptor(runtimeId, { installationId })
@@ -27,7 +29,8 @@ describe('runtime source admission', () => {
}
const effect = vi.fn(() => ({ sent: true }))
const dispatcher = new RpcDispatcher({
runtime,
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: The fixture handler is effect; admission and response metadata read only getRuntimeId.
runtime: runtime as OrcaRuntimeService,
methods: [
defineMethod({
name: 'terminal.send',