mirror of
https://github.com/stablyai/orca.git
synced 2026-11-02 18:17:36 +00:00
Importers call worktreeIdsEqual from shared/worktree/id directly (the alias was a renamed re-export). isRemoteAgentHooksEnabled becomes isWslAgentHookRelayEnabled; the env var and its parsing are unchanged. ws-transport inlines its one-line HTTP server factory, and a duplicated acquisition-id doc comment goes.
124 lines
5.1 KiB
TypeScript
124 lines
5.1 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import {
|
|
AGENT_HOOK_INSTALL_PLUGINS_METHOD,
|
|
AGENT_HOOK_NOTIFICATION_METHOD,
|
|
AGENT_HOOK_REQUEST_REPLAY_METHOD,
|
|
AGENT_HOOK_SHED_FIELDS_KEY,
|
|
ORCA_FEATURE_REMOTE_AGENT_HOOKS_ENV,
|
|
createShedSubagentsField,
|
|
isAgentHookSource,
|
|
isWslAgentHookRelayEnabled,
|
|
restoreShedStatusFields
|
|
} from './agent-hook-relay'
|
|
import type { ParsedAgentStatusPayload } from './agent-status-types'
|
|
|
|
describe('agent-hook-relay wire shape', () => {
|
|
it('exposes stable JSON-RPC method names', () => {
|
|
expect(AGENT_HOOK_NOTIFICATION_METHOD).toBe('agent.hook')
|
|
expect(AGENT_HOOK_REQUEST_REPLAY_METHOD).toBe('agent_hook.requestReplay')
|
|
expect(AGENT_HOOK_INSTALL_PLUGINS_METHOD).toBe('agent_hook.installPlugins')
|
|
})
|
|
|
|
it('validates hook sources crossing persisted and relay trust boundaries', () => {
|
|
expect(isAgentHookSource('claude')).toBe(true)
|
|
expect(isAgentHookSource('kimi')).toBe(true)
|
|
expect(isAgentHookSource('prime-agent')).toBe(true)
|
|
expect(isAgentHookSource('claude\0codex')).toBe(false)
|
|
expect(isAgentHookSource('unknown')).toBe(false)
|
|
expect(isAgentHookSource({ source: 'claude' })).toBe(false)
|
|
})
|
|
})
|
|
|
|
describe('isWslAgentHookRelayEnabled', () => {
|
|
it('is on when the env var is absent', () => {
|
|
expect(isWslAgentHookRelayEnabled({})).toBe(true)
|
|
})
|
|
|
|
it('is off for empty / "0"', () => {
|
|
expect(isWslAgentHookRelayEnabled({ [ORCA_FEATURE_REMOTE_AGENT_HOOKS_ENV]: '' })).toBe(false)
|
|
expect(isWslAgentHookRelayEnabled({ [ORCA_FEATURE_REMOTE_AGENT_HOOKS_ENV]: '0' })).toBe(false)
|
|
expect(isWslAgentHookRelayEnabled({ [ORCA_FEATURE_REMOTE_AGENT_HOOKS_ENV]: ' ' })).toBe(false)
|
|
expect(isWslAgentHookRelayEnabled({ [ORCA_FEATURE_REMOTE_AGENT_HOOKS_ENV]: ' 0 ' })).toBe(false)
|
|
})
|
|
|
|
it('is on for any other non-empty value', () => {
|
|
expect(isWslAgentHookRelayEnabled({ [ORCA_FEATURE_REMOTE_AGENT_HOOKS_ENV]: '1' })).toBe(true)
|
|
expect(isWslAgentHookRelayEnabled({ [ORCA_FEATURE_REMOTE_AGENT_HOOKS_ENV]: 'on' })).toBe(true)
|
|
expect(isWslAgentHookRelayEnabled({ [ORCA_FEATURE_REMOTE_AGENT_HOOKS_ENV]: 'true' })).toBe(true)
|
|
})
|
|
})
|
|
|
|
describe('restoreShedStatusFields', () => {
|
|
const roster = [{ id: 'child-1', agentType: 'reviewer', state: 'working' as const, startedAt: 1 }]
|
|
const cached: ParsedAgentStatusPayload = {
|
|
state: 'working',
|
|
prompt: 'p',
|
|
agentType: 'claude',
|
|
subagents: roster,
|
|
lastAssistantMessage: 'cached message',
|
|
interactivePrompt: '{"questions":["old"]}'
|
|
}
|
|
const shed: ParsedAgentStatusPayload = { state: 'done', prompt: 'p', agentType: 'claude' }
|
|
|
|
it('restores a matching shed roster, so a done pane is not falsely hibernation-eligible', () => {
|
|
const restored = restoreShedStatusFields(shed, [createShedSubagentsField(roster)], cached)
|
|
expect(restored.subagents).toEqual(roster)
|
|
expect(restored.state).toBe('done')
|
|
// Only the named field comes back.
|
|
expect(restored.lastAssistantMessage).toBeUndefined()
|
|
})
|
|
|
|
it('does not restore a shed roster across a prompt identity change', () => {
|
|
expect(AGENT_HOOK_SHED_FIELDS_KEY).toBe('shedFields')
|
|
const nextTurn = { ...shed, prompt: 'next prompt' }
|
|
const restored = restoreShedStatusFields(
|
|
nextTurn,
|
|
['lastAssistantMessage', createShedSubagentsField(roster)],
|
|
cached
|
|
)
|
|
expect(restored.lastAssistantMessage).toBeUndefined()
|
|
expect(restored.subagents).toBeUndefined()
|
|
expect(restored).toBe(nextTurn)
|
|
})
|
|
|
|
it('does not restore the cached roster when the shed roster digest changed', () => {
|
|
const changedRoster = [
|
|
{ id: 'child-2', agentType: 'reviewer', state: 'working' as const, startedAt: 2 }
|
|
]
|
|
const restored = restoreShedStatusFields(
|
|
shed,
|
|
[createShedSubagentsField(changedRoster)],
|
|
cached
|
|
)
|
|
expect(restored.subagents).toBeUndefined()
|
|
expect(restored).toBe(shed)
|
|
})
|
|
|
|
it('never restores interactivePrompt — a stale answerable card is worse than none', () => {
|
|
const restored = restoreShedStatusFields(shed, ['interactivePrompt'], cached)
|
|
expect(restored.interactivePrompt).toBeUndefined()
|
|
expect(restored).toBe(shed)
|
|
})
|
|
|
|
it('leaves an intentional lastAssistantMessage clear intact when the relay shed nothing', () => {
|
|
expect(restoreShedStatusFields(shed, undefined, cached)).toBe(shed)
|
|
expect(restoreShedStatusFields(shed, [], cached)).toBe(shed)
|
|
expect(restoreShedStatusFields(shed, [], cached).lastAssistantMessage).toBeUndefined()
|
|
// A hostile/garbled marker must not throw or restore.
|
|
expect(restoreShedStatusFields(shed, 'subagents', cached)).toBe(shed)
|
|
expect(restoreShedStatusFields(shed, ['subagents'], cached)).toBe(shed)
|
|
expect(restoreShedStatusFields(shed, [{ toString: () => 'subagents' }], cached)).toBe(shed)
|
|
})
|
|
|
|
it('does not overwrite a value the envelope still carries', () => {
|
|
const fresh: ParsedAgentStatusPayload = { ...shed, lastAssistantMessage: 'fresh' }
|
|
expect(
|
|
restoreShedStatusFields(fresh, ['lastAssistantMessage'], cached).lastAssistantMessage
|
|
).toBe('fresh')
|
|
})
|
|
|
|
it('is a no-op with no cached payload for the pane', () => {
|
|
expect(restoreShedStatusFields(shed, ['subagents'], undefined)).toBe(shed)
|
|
})
|
|
})
|