Files
orca/src/main/ipc/agent-hooks.test.ts
T
08ba730d8e feat(devin): managed hooks, sleeping resume, AI Vault (#5380)
* Revert "fix(terminal): add proportional scroll fallback for sidebar resize" (#937)

* fix(sidebar): smoothly animate off-screen worktree reveal on click (#1302)

Clicking a worktree card whose row lies outside the sidebar viewport
caused an instant jump when scrolling it into view. Switching
`scrollToIndex` to `behavior: 'smooth'` turns that minimum-distance
scroll into an animated slide while keeping `align: 'auto'` so visible
cards still no-op (no re-centering).

Co-authored-by: Orca <help@stably.ai>

* Avoid local scrollback serialization on shutdown (#1821)

* Fix PR refresh coordinator test arguments (#2545)

* release: v1.4.31

* release: v1.4.31

* release: v1.4.31

* release: v1.4.31

* release: v1.4.31

* release: v1.4.31

* release: v1.4.31

* release: v1.4.36-rc.6

* release: v1.4.36-rc.6

* release: v1.4.36-rc.6

* ci: gate release-cut to the canonical repo so it skips forks (#4815)

The cut job checks out main, bumps package.json's version, and
fast-forwards main. On a fork with Actions enabled, the scheduled RC
cut runs against the fork's main and diverges it on the version line
every slot, so that contributor's PRs back to upstream conflict on
package.json even when their change never touches it.

Gate the job to github.repository == 'stablyai/orca' so it (and the
jobs that depend on it) no-op on forks. Canonical scheduled and manual
cuts are unaffected.

* feat(hooks): install Devin managed status hooks

* feat(devin): address hook review, resume, and UI polish

- Parse Devin config.json as JSONC; warn on read_config_from overlap
- Windows hook command uses forward slashes; APPDATA fallback
- Add devin to sleeping-agent resume and UI registries (plan 003/004)
- Add hook-service and hook-config-json tests

Closes follow-up for plans 002–004 on feat/add-devin-agent.

* feat(devin): scan ATIF transcripts for AI Vault

Register devin in AI_VAULT_AGENTS, discover ~/.local/share/devin/cli/transcripts
(or DEVIN_HOME), parse ATIF JSON sessions, and build devin --resume commands.

* docs(devin): clarify stdin-after-start vs bracketed paste

* fix(devin): use JSONC for remote install, add partial+APPDATA tests

- installRemote: replace readHooksJsonRemote (JSON.parse) with
  readTextFileRemote + parseJsonc for JSONC compatibility on SSH
- Add partial status test (some hooks missing → state:'partial')
- Add Windows APPDATA config path test with fallback

* fix(devin): address CodeRabbit review — sessionId fallback, parseJsonc errors, comment, i18n

* Fix Devin integration edge cases

Co-authored-by: Orca <help@stably.ai>

* Package Devin JSONC parser dependency

Co-authored-by: Orca <help@stably.ai>

---------

Co-authored-by: Neil <4138956+nwparker@users.noreply.github.com>
Co-authored-by: Brennan Benson <79079362+brennanb2025@users.noreply.github.com>
Co-authored-by: Orca <help@stably.ai>
Co-authored-by: Jinjing <6427696+AmethystLiang@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Trevin Chow <trevin@trevinchow.com>
Co-authored-by: Jinwoo-H <jinwoo0825@gmail.com>
2026-06-17 20:49:29 -07:00

309 lines
10 KiB
TypeScript

import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import type * as AgentHookServerModule from '../agent-hooks/server'
import { makePaneKey } from '../../shared/stable-pane-id'
// Why: cover the agentStatus:drop IPC handler — it must propagate the
// renderer dismissal to dropStatusEntry so the on-disk last-status file
// evicts the entry.
const dropStatusEntry = vi.fn()
const getStatusSnapshot = vi.fn()
const inferInterrupt = vi.fn()
const onHandlers = new Map<string, (event: unknown, ...args: unknown[]) => void>()
const handleHandlers = new Map<string, (event: unknown, ...args: unknown[]) => unknown>()
const removeHandler = vi.fn()
const removeAllListeners = vi.fn()
const PANE_KEY = makePaneKey('tab-1', '11111111-1111-4111-8111-111111111111')
const CHILD_PANE_KEY = makePaneKey('tab-2', '22222222-2222-4222-8222-222222222222')
vi.mock('electron', () => ({
ipcMain: {
handle: (channel: string, handler: (event: unknown, ...args: unknown[]) => unknown) => {
handleHandlers.set(channel, handler)
},
on: (channel: string, handler: (event: unknown, ...args: unknown[]) => void) => {
onHandlers.set(channel, handler)
},
removeHandler,
removeAllListeners
}
}))
vi.mock('../agent-hooks/server', async () => {
// Why: import the real isValidPaneKey so this test stays in sync with any
// tightening of the validator (length cap, character allow-list, etc).
const actual = await vi.importActual<typeof AgentHookServerModule>('../agent-hooks/server')
return {
...actual,
agentHookServer: {
dropStatusEntry,
getStatusSnapshot,
inferInterrupt
}
}
})
vi.mock('../claude/hook-service', () => ({
claudeHookService: { getStatus: vi.fn(() => ({ agent: 'claude', state: 'absent' })) }
}))
vi.mock('../openclaude/hook-service', () => ({
openClaudeHookService: { getStatus: vi.fn(() => ({ agent: 'openclaude', state: 'absent' })) }
}))
vi.mock('../codex/hook-service', () => ({
codexHookService: { getStatus: vi.fn(() => ({ agent: 'codex', state: 'absent' })) }
}))
vi.mock('../gemini/hook-service', () => ({
geminiHookService: { getStatus: vi.fn(() => ({ agent: 'gemini', state: 'absent' })) }
}))
vi.mock('../antigravity/hook-service', () => ({
antigravityHookService: { getStatus: vi.fn(() => ({ agent: 'antigravity', state: 'absent' })) }
}))
vi.mock('../amp/hook-service', () => ({
ampHookService: { getStatus: vi.fn(() => ({ agent: 'amp', state: 'absent' })) }
}))
vi.mock('../cursor/hook-service', () => ({
cursorHookService: { getStatus: vi.fn(() => ({ agent: 'cursor', state: 'absent' })) }
}))
vi.mock('../droid/hook-service', () => ({
droidHookService: { getStatus: vi.fn(() => ({ agent: 'droid', state: 'absent' })) }
}))
vi.mock('../command-code/hook-service', () => ({
commandCodeHookService: { getStatus: vi.fn(() => ({ agent: 'command-code', state: 'absent' })) }
}))
vi.mock('../grok/hook-service', () => ({
grokHookService: { getStatus: vi.fn(() => ({ agent: 'grok', state: 'absent' })) }
}))
vi.mock('../copilot/hook-service', () => ({
copilotHookService: { getStatus: vi.fn(() => ({ agent: 'copilot', state: 'absent' })) }
}))
vi.mock('../hermes/hook-service', () => ({
hermesHookService: { getStatus: vi.fn(() => ({ agent: 'hermes', state: 'absent' })) }
}))
vi.mock('../devin/hook-service', () => ({
devinHookService: { getStatus: vi.fn(() => ({ agent: 'devin', state: 'absent' })) }
}))
beforeEach(() => {
dropStatusEntry.mockReset()
getStatusSnapshot.mockReset()
inferInterrupt.mockReset()
onHandlers.clear()
handleHandlers.clear()
removeHandler.mockReset()
removeAllListeners.mockReset()
})
afterEach(() => {
vi.resetModules()
})
describe('agentStatus:getSnapshot IPC', () => {
it('returns the hook cache snapshot', async () => {
const snapshot = [
{
paneKey: PANE_KEY,
state: 'done',
prompt: 'p',
agentType: 'claude',
receivedAt: 1_700_000_000_000,
stateStartedAt: 1_699_999_999_000
}
]
getStatusSnapshot.mockReturnValue(snapshot)
const { registerAgentHookHandlers } = await import('./agent-hooks')
registerAgentHookHandlers()
const handler = handleHandlers.get('agentStatus:getSnapshot')
expect(handler).toBeDefined()
expect(handler!({})).toEqual(snapshot)
})
it('enriches the hook cache snapshot with runtime lineage metadata', async () => {
const snapshot = [
{
paneKey: PANE_KEY,
state: 'done',
prompt: 'parent',
agentType: 'codex',
connectionId: null,
receivedAt: 1_700_000_000_000,
stateStartedAt: 1_699_999_999_000
},
{
paneKey: CHILD_PANE_KEY,
state: 'done',
prompt: 'child',
agentType: 'codex',
connectionId: null,
receivedAt: 1_700_000_001_000,
stateStartedAt: 1_700_000_000_500
}
]
getStatusSnapshot.mockReturnValue(snapshot)
const runtime = {
getAgentStatusTerminalHandleForPaneKey: vi.fn((paneKey: string) =>
paneKey === PANE_KEY ? 'term-parent' : paneKey === CHILD_PANE_KEY ? 'term-child' : undefined
),
getAgentStatusOrchestrationContextForPaneKey: vi.fn((paneKey: string) =>
paneKey === CHILD_PANE_KEY
? {
taskId: 'task-child',
dispatchId: 'dispatch-child',
parentTerminalHandle: 'term-parent',
parentPaneKey: PANE_KEY,
coordinatorHandle: 'term-parent'
}
: undefined
)
}
const { registerAgentHookHandlers } = await import('./agent-hooks')
registerAgentHookHandlers(runtime)
const handler = handleHandlers.get('agentStatus:getSnapshot')
expect(handler).toBeDefined()
expect(handler!({})).toEqual([
{
...snapshot[0],
terminalHandle: 'term-parent'
},
{
...snapshot[1],
terminalHandle: 'term-child',
orchestration: {
taskId: 'task-child',
dispatchId: 'dispatch-child',
parentTerminalHandle: 'term-parent',
parentPaneKey: PANE_KEY,
coordinatorHandle: 'term-parent'
}
}
])
})
})
describe('agentHooks:antigravityStatus IPC', () => {
it('returns Antigravity hook installation status', async () => {
const { registerAgentHookHandlers } = await import('./agent-hooks')
registerAgentHookHandlers()
const handler = handleHandlers.get('agentHooks:antigravityStatus')
expect(handler).toBeDefined()
expect(handler!({})).toEqual({ agent: 'antigravity', state: 'absent' })
})
})
describe('agentHooks:ampStatus IPC', () => {
it('returns Amp hook installation status', async () => {
const { registerAgentHookHandlers } = await import('./agent-hooks')
registerAgentHookHandlers()
const handler = handleHandlers.get('agentHooks:ampStatus')
expect(handler).toBeDefined()
expect(handler!({})).toEqual({ agent: 'amp', state: 'absent' })
})
})
describe('agentHooks:openClaudeStatus IPC', () => {
it('returns OpenClaude hook installation status', async () => {
const { registerAgentHookHandlers } = await import('./agent-hooks')
registerAgentHookHandlers()
const handler = handleHandlers.get('agentHooks:openClaudeStatus')
expect(handler).toBeDefined()
expect(handler!({})).toEqual({ agent: 'openclaude', state: 'absent' })
})
})
describe('agentHooks:commandCodeStatus IPC', () => {
it('returns Command Code hook installation status', async () => {
const { registerAgentHookHandlers } = await import('./agent-hooks')
registerAgentHookHandlers()
const handler = handleHandlers.get('agentHooks:commandCodeStatus')
expect(handler).toBeDefined()
expect(handler!({})).toEqual({ agent: 'command-code', state: 'absent' })
})
})
describe('agentHooks:devinStatus IPC', () => {
it('returns Devin hook installation status', async () => {
const { registerAgentHookHandlers } = await import('./agent-hooks')
registerAgentHookHandlers()
const handler = handleHandlers.get('agentHooks:devinStatus')
expect(handler).toBeDefined()
expect(handler!({})).toEqual({ agent: 'devin', state: 'absent' })
})
})
describe('agentStatus:inferInterrupt IPC', () => {
it('forwards valid inference requests to the hook server', async () => {
inferInterrupt.mockReturnValue(true)
const { registerAgentHookHandlers } = await import('./agent-hooks')
registerAgentHookHandlers()
const handler = handleHandlers.get('agentStatus:inferInterrupt')
expect(handler).toBeDefined()
const request = {
paneKey: PANE_KEY,
baselineUpdatedAt: 1_000,
baselineStateStartedAt: 900,
baselinePrompt: 'long task',
baselineAgentType: 'codex',
intent: 'ctrl-c'
}
expect(handler!({}, request)).toBe(true)
expect(inferInterrupt).toHaveBeenCalledWith(request)
})
it('rejects malformed requests before the hook server boundary', async () => {
const { registerAgentHookHandlers } = await import('./agent-hooks')
registerAgentHookHandlers()
const handler = handleHandlers.get('agentStatus:inferInterrupt')
expect(handler).toBeDefined()
for (const value of [null, undefined, '', 123, true]) {
expect(handler!({}, value)).toBe(false)
}
expect(inferInterrupt).not.toHaveBeenCalled()
})
})
describe('agentStatus:drop IPC', () => {
it('forwards drop to dropStatusEntry', async () => {
const { registerAgentHookHandlers } = await import('./agent-hooks')
registerAgentHookHandlers()
const handler = onHandlers.get('agentStatus:drop')
expect(handler).toBeDefined()
handler!({}, PANE_KEY)
expect(dropStatusEntry).toHaveBeenCalledWith(PANE_KEY)
})
it('rejects non-string paneKey (defensive against a malformed renderer message)', async () => {
const { registerAgentHookHandlers } = await import('./agent-hooks')
registerAgentHookHandlers()
const handler = onHandlers.get('agentStatus:drop')!
const bad: unknown[] = [
123,
undefined,
'',
null,
{},
[],
'tab-1:0', // legacy numeric pane-key suffix
'no-colon', // missing colon — rejected by isValidPaneKey
':leading', // empty tabId half
'trailing:', // empty leafId half
'a:b:c' // multiple colons
]
for (const value of bad) {
expect(() => handler({}, value)).not.toThrow()
}
expect(dropStatusEntry).not.toHaveBeenCalled()
})
})