mirror of
https://github.com/stablyai/orca.git
synced 2026-09-22 16:02:32 +00:00
* refactor(agent-status): isolate legacy status ingress * fix(agent-hooks): move advertised-capability source onto the ingest envelope ingestRemote() gained a third positional argument in this PR (advertisedAgentStatusCapabilities) to satisfy a new ratchet requiring every legacy-ingress call site to name its capability source. Both production callers pass the same constant every time, so the argument carries zero runtime information — but Vitest's toHaveBeenCalledWith matches argument count exactly, so the pre-existing SSH relay integration test (which asserts a 2-argument call) started failing even though nothing about the actual admission decision changed. Capabilities are a property of the producing peer/connection, not an orthogonal call parameter, so move the field onto the envelope object instead of adding a third positional argument: ingestRemote reads envelope.advertisedAgentStatusCapabilities (defaulting to the unadvertised-legacy-peer set), and both call sites stamp the constant onto their envelope literal. Call arity stays at two arguments, so the pre-existing evidence test needs no change. The envelope never crosses the wire in either caller: SSH rebuilds it field-by-field from the RPC params, and the WSL path copies (never mutates) the wire-deserialized notification before stamping the field on, so this is purely an internal main-process shape change. Also strengthens the ingress ratchet test that required this: it previously only checked that the capability constant's name appeared somewhere in each caller's source, which a stray unused import could satisfy. It now asserts the actual `advertisedAgentStatusCapabilities: AGENT_STATUS_LEGACY_UNADVERTISED_PEER_CAPABILITIES` key:value binding is present.
68 lines
2.5 KiB
TypeScript
68 lines
2.5 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { createHookListenerState } from './agent-hook-listener/listener-state'
|
|
import type { AgentHookEventPayload } from './agent-hook-listener/listener-event'
|
|
import { upsertBoundedAgentHookStatus } from './agent-hook-status-cache'
|
|
import { AGENT_STATUS_STALE_AFTER_MS } from './agent-status-types'
|
|
|
|
function status(
|
|
paneKey: string,
|
|
state: AgentHookEventPayload['payload']['state'],
|
|
receivedAt: number
|
|
): AgentHookEventPayload {
|
|
return {
|
|
paneKey,
|
|
connectionId: null,
|
|
payload: { state, prompt: paneKey, agentType: 'claude' },
|
|
receivedAt
|
|
} as AgentHookEventPayload
|
|
}
|
|
|
|
describe('bounded agent hook status cache', () => {
|
|
it('preserves the current row and falls back to least-recently-updated eviction', () => {
|
|
const listener = createHookListenerState()
|
|
const now = Date.now()
|
|
upsertBoundedAgentHookStatus(listener, status('oldest', 'working', now), { maxPanes: 2, now })
|
|
upsertBoundedAgentHookStatus(listener, status('newer', 'working', now), { maxPanes: 2, now })
|
|
|
|
const evicted = upsertBoundedAgentHookStatus(listener, status('current', 'working', now), {
|
|
maxPanes: 2,
|
|
now
|
|
})
|
|
|
|
expect(evicted.map(({ paneKey }) => paneKey)).toEqual(['oldest'])
|
|
expect([...listener.lastStatusByPaneKey.keys()]).toEqual(['newer', 'current'])
|
|
})
|
|
|
|
it('prefers the oldest completed or stale row and clears its related pane caches', () => {
|
|
const listener = createHookListenerState()
|
|
const now = Date.now()
|
|
upsertBoundedAgentHookStatus(listener, status('fresh-oldest', 'working', now), {
|
|
maxPanes: 3,
|
|
now
|
|
})
|
|
upsertBoundedAgentHookStatus(
|
|
listener,
|
|
status('stale', 'working', now - AGENT_STATUS_STALE_AFTER_MS - 1),
|
|
{
|
|
maxPanes: 3,
|
|
now
|
|
}
|
|
)
|
|
upsertBoundedAgentHookStatus(listener, status('done', 'done', now), { maxPanes: 3, now })
|
|
listener.lastPromptByPaneKey.set('stale', 'cached prompt')
|
|
listener.lastToolByPaneKey.set('stale\0tool', {} as never)
|
|
|
|
const evicted = upsertBoundedAgentHookStatus(listener, status('current', 'working', now), {
|
|
maxPanes: 3,
|
|
now
|
|
})
|
|
|
|
expect(evicted.map(({ paneKey }) => paneKey)).toEqual(['stale'])
|
|
expect(listener.lastStatusByPaneKey.has('fresh-oldest')).toBe(true)
|
|
expect(listener.lastStatusByPaneKey.has('done')).toBe(true)
|
|
expect(listener.lastStatusByPaneKey.has('current')).toBe(true)
|
|
expect(listener.lastPromptByPaneKey.has('stale')).toBe(false)
|
|
expect(listener.lastToolByPaneKey.has('stale\0tool')).toBe(false)
|
|
})
|
|
})
|