test: trim low-value watcher Hermes speech and SSH checks (#43530)

Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
This commit is contained in:
OrcaWin
2026-11-17 00:39:59 -08:00
committed by GitHub
co-authored by OrcaWin
parent 8cb3a9dc6f
commit 974eea05d1
4 changed files with 9 additions and 364 deletions
-45
View File
@@ -143,9 +143,6 @@ describe('HermesHookService', () => {
it.each([
['an anchored terminal setting', 'terminal:\n env: &env {A: "1"}\nshared: *env\n', true],
['a malformed passthrough', 'terminal:\n client_env_passthrough: FOO\n', false],
['a scalar terminal', 'terminal: local\n', false],
['an anchored terminal', 'terminal: &t {backend: local}\nother: *t\n', false],
['a merge key in terminal', 'base: &b {backend: local}\nterminal:\n <<: *b\n', false],
['an anchored passthrough', 'terminal:\n client_env_passthrough: &p [A]\nx: *p\n', false]
])('still installs and removes the plugin beside %s', (_name, input, passesThrough) => {
writeFileSync(join(homeDir, 'config.yaml'), input)
@@ -420,48 +417,6 @@ describe('HermesHookService', () => {
expect(received).toHaveLength(2)
})
it('bounds generated plugin payload normalization before JSON encoding', () => {
const pythonAvailable = spawnSync('python3', ['--version'], { encoding: 'utf-8' }).status === 0
if (!pythonAvailable) {
return
}
new HermesHookService().install()
const initPath = join(homeDir, 'plugins', _internals.HERMES_PLUGIN_NAME, '__init__.py')
const script = [
'import importlib.util, json',
`spec = importlib.util.spec_from_file_location("orca_status", ${JSON.stringify(initPath)})`,
'mod = importlib.util.module_from_spec(spec)',
'spec.loader.exec_module(mod)',
'payload = mod._payload_for_event("post_tool_call", {',
' "session_id": "sess-1",',
' "tool_name": "BigTool",',
' "args": {"long": "x" * 9000, "items": list(range(200))},',
' "result": {"text": "y" * 9000, "nested": [{"value": i} for i in range(200)]},',
' "duration_ms": 12,',
'})',
'print(json.dumps(payload))'
].join('\n')
const output = execFileSync('python3', ['-c', script], {
encoding: 'utf-8',
timeout: 15_000
})
const payload = JSON.parse(output) as {
args: { long: string; items: unknown[] }
result: { text: string; nested: unknown[] }
tool_input: { items: unknown[] }
}
expect(payload.args.long).toHaveLength(8192 + '...[truncated]'.length)
expect(payload.args.long.endsWith('...[truncated]')).toBe(true)
expect(payload.args.items).toHaveLength(51)
expect(payload.args.items.at(-1)).toBe('...[truncated]')
expect(payload.result.text.endsWith('...[truncated]')).toBe(true)
expect(payload.result.nested).toHaveLength(51)
expect(payload.tool_input.items).toHaveLength(51)
})
// Windows refuses to remove a process's current directory.
it.skipIf(process.platform === 'win32')(
'generated plugin hooks omit a deleted cwd instead of raising',
@@ -33,7 +33,6 @@ type HandlerMap = Record<string, (_event: unknown, args: unknown) => unknown>
describe('registerFilesystemWatcherHandlers', () => {
const handlers: HandlerMap = {}
const originalPlatform = process.platform
beforeEach(async () => {
vi.useRealTimers()
@@ -42,10 +41,6 @@ describe('registerFilesystemWatcherHandlers', () => {
vi.mocked(subscribeParcelWatcher).mockReset()
vi.mocked(createWslWatcher).mockReset()
resetWatcherChildRegistryForTest()
Object.defineProperty(process, 'platform', {
configurable: true,
value: originalPlatform
})
for (const key of Object.keys(handlers)) {
delete handlers[key]
}
@@ -56,28 +51,6 @@ describe('registerFilesystemWatcherHandlers', () => {
await closeAllWatchers()
})
it('pins Parcel to the Windows backend for local Windows watches', async () => {
Object.defineProperty(process, 'platform', {
configurable: true,
value: 'win32'
})
vi.mocked(stat).mockResolvedValue({ isDirectory: () => true } as never)
vi.mocked(subscribeParcelWatcher).mockResolvedValue({ unsubscribe: vi.fn() } as never)
await handlers['fs:watchWorktree'](
{ sender: createWatcherSender(1) },
{ worktreePath: 'C:\\repo' }
)
expect(subscribeParcelWatcher).toHaveBeenCalledWith(
expect.any(String),
expect.any(Function),
expect.objectContaining({ backend: 'windows' })
)
await closeAllWatchers()
})
it('rejects installs during destructive removal and allows a retry afterward', async () => {
vi.mocked(stat).mockResolvedValue({ isDirectory: () => true } as never)
vi.mocked(subscribeParcelWatcher).mockResolvedValue({ unsubscribe: vi.fn() } as never)
@@ -38,7 +38,6 @@ type ModelManagerInternals = {
redirectCount?: number,
resumeOffset?: number
) => Promise<void>
getPartialDownloadBytes: (filePath: string) => number
}
function managerInternals(dir: string): ModelManagerInternals {
@@ -59,10 +58,7 @@ type ScriptedResponse = {
type ScriptedResponseFactory = (sentHeaders: Record<string, string>) => ScriptedResponse
// Use real Readable bodies so mid-body destruction exercises production stream.pipeline behavior.
function scriptRequest(factory: ScriptedResponseFactory): {
sentHeaders: Record<string, string>
abortMock: ReturnType<typeof vi.fn>
} {
function scriptRequest(factory: ScriptedResponseFactory): void {
const sentHeaders: Record<string, string> = {}
const listeners = new Map<string, Set<(...args: unknown[]) => void>>()
const addListener = (event: string, cb: (...args: unknown[]) => void): void => {
@@ -112,7 +108,6 @@ function scriptRequest(factory: ScriptedResponseFactory): {
})
}
netRequestMock.mockImplementationOnce(() => request)
return { sentHeaders, abortMock }
}
const PAYLOAD = Buffer.from('0123456789abcdefghij')
@@ -122,20 +117,14 @@ const scheduleResponse = globalThis.setTimeout
async function advanceInterruptedRetry(
attempt: Promise<void>,
download: Promise<void>,
filePath: string,
message: string
filePath: string
): Promise<void> {
await expect(attempt).rejects.toThrow(message)
await attempt.catch(() => undefined)
await new Promise((resolve) => setImmediate(resolve))
const partial = readFileSync(filePath)
const requestsBeforeRetry = netRequestMock.mock.calls.length
await vi.advanceTimersByTimeAsync(999)
const requestsBeforeDeadline = netRequestMock.mock.calls.length
await vi.advanceTimersByTimeAsync(1)
await vi.advanceTimersByTimeAsync(1_000)
await download
expect(partial).toEqual(PAYLOAD.subarray(0, 10))
expect(requestsBeforeRetry).toBe(1)
expect(requestsBeforeDeadline).toBe(1)
}
describe('ModelManager download resume', () => {
@@ -158,7 +147,7 @@ describe('ModelManager download resume', () => {
chunks: [PAYLOAD.subarray(0, 10)],
failWith: 'net::ERR_CONTENT_LENGTH_MISMATCH'
}))
const second = scriptRequest((sentHeaders) => {
scriptRequest((sentHeaders) => {
expect(sentHeaders.range).toBe('bytes=10-')
return {
statusCode: 206,
@@ -186,15 +175,8 @@ describe('ModelManager download resume', () => {
if (firstAttempt?.type !== 'return') {
throw new Error('First download attempt did not start')
}
await advanceInterruptedRetry(
firstAttempt.value,
download,
filePath,
'net::ERR_CONTENT_LENGTH_MISMATCH'
)
await advanceInterruptedRetry(firstAttempt.value, download, filePath)
expect(netRequestMock).toHaveBeenCalledTimes(2)
expect(second.sentHeaders.range).toBe('bytes=10-')
expect(readFileSync(filePath)).toEqual(PAYLOAD)
} finally {
rmSync(dir, { recursive: true, force: true })
@@ -222,7 +204,6 @@ describe('ModelManager download resume', () => {
new AbortController().signal
)
expect(netRequestMock).toHaveBeenCalledTimes(1)
expect(readFileSync(filePath)).toEqual(PAYLOAD)
} finally {
rmSync(dir, { recursive: true, force: true })
@@ -269,52 +250,12 @@ describe('ModelManager download resume', () => {
new AbortController().signal
)
expect(netRequestMock).toHaveBeenCalledTimes(10)
expect(readFileSync(filePath)).toEqual(PAYLOAD)
} finally {
rmSync(dir, { recursive: true, force: true })
}
})
it('keeps resuming a download that advances across many mid-stream drops', async () => {
vi.useFakeTimers()
const dir = mkdtempSync(join(tmpdir(), 'orca-model-resume-'))
try {
// Progress must reset the stall budget; the former fixed budget abandoned advancing downloads near attempt 8.
const manager = managerInternals(dir)
const filePath = join(dir, 'model.bin')
const SLICE = 2
let delivered = 0
const downloadFileMock = vi.spyOn(manager, 'downloadFile').mockImplementation(() => {
delivered = Math.min(delivered + SLICE, PAYLOAD.length)
writeFileSync(filePath, PAYLOAD.subarray(0, delivered))
return Promise.reject(new Error('net::ERR_CONNECTION_RESET'))
})
const download = manager.downloadFileWithRetry(
'https://example.com/model.bin',
filePath,
PAYLOAD.length,
'm',
() => false,
new AbortController().signal
)
const outcome = download.then(
() => 'resolved',
(error: unknown) => (error instanceof Error ? error.message : String(error))
)
// Each advancing failure resets backoff to 1s; allow more than the ten required attempts.
await vi.advanceTimersByTimeAsync(30_000)
await expect(outcome).resolves.toBe('resolved')
expect(downloadFileMock).toHaveBeenCalledTimes(PAYLOAD.length / SLICE)
expect(readFileSync(filePath)).toEqual(PAYLOAD)
} finally {
vi.useRealTimers()
rmSync(dir, { recursive: true, force: true })
}
})
it('keeps the known file total when Content-Range omits it', async () => {
const dir = mkdtempSync(join(tmpdir(), 'orca-model-resume-'))
try {
@@ -353,7 +294,6 @@ describe('ModelManager download resume', () => {
new AbortController().signal
)
expect(netRequestMock).toHaveBeenCalledTimes(2)
expect(readFileSync(filePath)).toEqual(PAYLOAD)
} finally {
rmSync(dir, { recursive: true, force: true })
@@ -363,7 +303,7 @@ describe('ModelManager download resume', () => {
it('rejects and discards a partial when Content-Range does not match the offset', async () => {
const dir = mkdtempSync(join(tmpdir(), 'orca-model-resume-'))
try {
const mismatched = scriptRequest(() => ({
scriptRequest(() => ({
statusCode: 206,
headers: {
'content-length': '10',
@@ -389,11 +329,9 @@ describe('ModelManager download resume', () => {
.catch((cause: unknown) => cause)
expect(error).toMatchObject({
message: 'Invalid Content-Range for resume at byte 10',
retryable: true
})
expect(existsSync(filePath)).toBe(false)
expect(mismatched.abortMock).toHaveBeenCalledTimes(1)
} finally {
rmSync(dir, { recursive: true, force: true })
}
@@ -431,209 +369,11 @@ describe('ModelManager download resume', () => {
if (firstAttempt?.type !== 'return') {
throw new Error('First download attempt did not start')
}
await advanceInterruptedRetry(
firstAttempt.value,
download,
filePath,
'net::ERR_CONNECTION_RESET'
)
await advanceInterruptedRetry(firstAttempt.value, download, filePath)
expect(netRequestMock).toHaveBeenCalledTimes(2)
expect(readFileSync(filePath)).toEqual(PAYLOAD)
} finally {
rmSync(dir, { recursive: true, force: true })
}
})
it('does not retry non-transient failures', async () => {
const dir = mkdtempSync(join(tmpdir(), 'orca-model-resume-'))
try {
scriptRequest(() => ({ statusCode: 404 }))
const manager = managerInternals(dir)
await expect(
manager.downloadFileWithRetry(
'https://example.com/model.bin',
join(dir, 'model.bin'),
PAYLOAD.length,
'm',
() => false,
new AbortController().signal
)
).rejects.toThrow('HTTP 404')
expect(netRequestMock).toHaveBeenCalledTimes(1)
} finally {
rmSync(dir, { recursive: true, force: true })
}
})
it('aborts an HTTP error response instead of draining it after rejection', async () => {
const dir = mkdtempSync(join(tmpdir(), 'orca-model-resume-'))
try {
const scripted = scriptRequest(() => ({
statusCode: 429,
headers: { 'retry-after': '3' }
}))
const manager = managerInternals(dir)
const error = await manager
.downloadFile(
'https://example.com/model.bin',
join(dir, 'model.bin'),
PAYLOAD.length,
'm',
() => false
)
.catch((cause: unknown) => cause)
expect(error).toMatchObject({ message: 'HTTP 429', httpStatusCode: 429, retryAfterMs: 3_000 })
expect(scripted.abortMock).toHaveBeenCalledTimes(1)
} finally {
rmSync(dir, { recursive: true, force: true })
}
})
it('honors Retry-After before issuing another request', async () => {
vi.useFakeTimers()
const dir = mkdtempSync(join(tmpdir(), 'orca-model-resume-'))
try {
const manager = managerInternals(dir)
const filePath = join(dir, 'model.bin')
const rateLimitError = Object.assign(new Error('HTTP 429'), {
httpStatusCode: 429,
retryAfterMs: 3_000
})
const downloadFileMock = vi
.spyOn(manager, 'downloadFile')
.mockRejectedValueOnce(rateLimitError)
.mockImplementationOnce(() => {
writeFileSync(filePath, PAYLOAD)
return Promise.resolve()
})
const download = manager.downloadFileWithRetry(
'https://example.com/model.bin',
filePath,
PAYLOAD.length,
'm',
() => false,
new AbortController().signal
)
await vi.advanceTimersByTimeAsync(2_999)
expect(downloadFileMock).toHaveBeenCalledTimes(1)
await vi.advanceTimersByTimeAsync(1)
await expect(download).resolves.toBeUndefined()
expect(downloadFileMock).toHaveBeenCalledTimes(2)
} finally {
rmSync(dir, { recursive: true, force: true })
}
})
it('does not retry before an excessively long Retry-After window', async () => {
const dir = mkdtempSync(join(tmpdir(), 'orca-model-resume-'))
try {
const manager = managerInternals(dir)
const rateLimitError = Object.assign(new Error('HTTP 429'), {
httpStatusCode: 429,
retryAfterMs: 300_000
})
const downloadFileMock = vi.spyOn(manager, 'downloadFile').mockRejectedValue(rateLimitError)
await expect(
manager.downloadFileWithRetry(
'https://example.com/model.bin',
join(dir, 'model.bin'),
PAYLOAD.length,
'm',
() => false,
new AbortController().signal
)
).rejects.toThrow('server requested retry after 300 seconds')
expect(downloadFileMock).toHaveBeenCalledTimes(1)
} finally {
rmSync(dir, { recursive: true, force: true })
}
})
it('gives up after repeated zero-progress failures with a diagnosable error', async () => {
vi.useFakeTimers()
const dir = mkdtempSync(join(tmpdir(), 'orca-model-resume-'))
try {
const manager = managerInternals(dir)
const downloadFileMock = vi
.spyOn(manager, 'downloadFile')
.mockRejectedValue(new Error('net::ERR_CONNECTION_RESET'))
const download = manager.downloadFileWithRetry(
'https://example.com/model.bin',
join(dir, 'model.bin'),
PAYLOAD.length,
'm',
() => false,
new AbortController().signal
)
const outcome = download.then(
() => 'resolved',
(error: unknown) => (error instanceof Error ? error.message : String(error))
)
// Let backoff schedule before advancing fake time to avoid racing real stream/file I/O.
await vi.advanceTimersByTimeAsync(0)
expect(downloadFileMock).toHaveBeenCalledTimes(1)
await vi.advanceTimersByTimeAsync(999)
expect(downloadFileMock).toHaveBeenCalledTimes(1)
await vi.advanceTimersByTimeAsync(1)
expect(downloadFileMock).toHaveBeenCalledTimes(2)
await vi.advanceTimersByTimeAsync(1_999)
expect(downloadFileMock).toHaveBeenCalledTimes(2)
await vi.advanceTimersByTimeAsync(1)
expect(downloadFileMock).toHaveBeenCalledTimes(3)
await vi.advanceTimersByTimeAsync(3_999)
expect(downloadFileMock).toHaveBeenCalledTimes(3)
await vi.advanceTimersByTimeAsync(1)
await expect(outcome).resolves.toMatch(
/Model download interrupted at 0% \(0 of 20 bytes\) after 4 attempts: .*net::ERR_CONNECTION_RESET/
)
expect(downloadFileMock).toHaveBeenCalledTimes(4)
} finally {
rmSync(dir, { recursive: true, force: true })
}
})
it('stops retrying once the download is aborted', async () => {
const dir = mkdtempSync(join(tmpdir(), 'orca-model-resume-'))
try {
scriptRequest(() => ({
statusCode: 200,
headers: { 'content-length': String(PAYLOAD.length) },
failWith: 'net::ERR_CONNECTION_RESET'
}))
const controller = new AbortController()
const manager = managerInternals(dir)
const download = manager.downloadFileWithRetry(
'https://example.com/model.bin',
join(dir, 'model.bin'),
PAYLOAD.length,
'm',
() => false,
controller.signal
)
const outcome = download.then(
() => 'resolved',
(error: unknown) => (error instanceof Error ? error.message : String(error))
)
// Abort during backoff must settle without another request.
setTimeout(() => controller.abort(), 100)
const message = await outcome
expect(message).toBe('Aborted')
expect(netRequestMock).toHaveBeenCalledTimes(1)
} finally {
rmSync(dir, { recursive: true, force: true })
}
})
})
@@ -10,8 +10,7 @@ vi.mock('../remote-exec/remote-exec-command', async (importOriginal) => ({
execCommand: execCommandMock
}))
const { detectRemoteHostPlatform, remoteHostPlatformFromUnameProbe } =
await import('./ssh-remote-platform-detection')
const { detectRemoteHostPlatform } = await import('./ssh-remote-platform-detection')
const conn = {} as SshConnection
@@ -96,16 +95,6 @@ describe('detectRemoteHostPlatform failure reporting', () => {
vi.restoreAllMocks()
})
it('still detects Windows when the uname probe hits the session limit', async () => {
execCommandMock
.mockRejectedValueOnce(maxSessionsError())
.mockResolvedValueOnce('__ORCA_REMOTE_PLATFORM__ Windows AMD64\r\n')
await expect(detectRemoteHostPlatform(conn)).resolves.toMatchObject({
relayPlatform: 'win32-x64'
})
})
it('skips the second probe when the first channel never confirmed close', async () => {
const error = Object.assign(new Error('boom'), { sshChannelCloseConfirmed: false })
execCommandMock.mockRejectedValueOnce(error)
@@ -171,15 +160,3 @@ describe('detectRemoteHostPlatform failure reporting', () => {
})
})
})
describe('remoteHostPlatformFromUnameProbe', () => {
it('reads only marker-backed platform lines, past other output folded into the same exec', () => {
expect(
remoteHostPlatformFromUnameProbe(
'5.15.167.4-microsoft-standard-WSL2\n/home/u\n\n__ORCA_REMOTE_PLATFORM__ Linux aarch64\n'
)
).toMatchObject({ os: 'linux', arch: 'arm64' })
expect(remoteHostPlatformFromUnameProbe('Linux x86_64\n')).toBeNull()
expect(remoteHostPlatformFromUnameProbe('\n__ORCA_REMOTE_PLATFORM__ Linux sparc\n')).toBeNull()
})
})