mirror of
https://github.com/stablyai/orca.git
synced 2026-10-01 00:02:10 +00:00
* oom(01): A1-shared-readers — reintroduce #10179 subset Files: 18 applied, 0 deleted (from6eb70d8370) Co-authored-by: Orca <help@stably.ai> * oom(02): A2-shared-image-media — reintroduce #10179 subset Files: 7 applied, 0 deleted (from6eb70d8370) Co-authored-by: Orca <help@stably.ai> * oom(03): A3-shared-fs-listing — reintroduce #10179 subset Files: 21 applied, 0 deleted (from6eb70d8370) Co-authored-by: Orca <help@stably.ai> * oom(04): A4-shared-remote-relay — reintroduce #10179 subset Files: 8 applied, 0 deleted (from6eb70d8370) Co-authored-by: Orca <help@stably.ai> * oom(05): A5-shared-misc — reintroduce #10179 subset Files: 28 applied, 0 deleted (from6eb70d8370) Co-authored-by: Orca <help@stably.ai> * oom(06): B-shared-wiring — reintroduce #10179 subset Files: 81 applied, 0 deleted (from6eb70d8370) Co-authored-by: Orca <help@stably.ai> --------- Co-authored-by: Orca <help@stably.ai>
67 lines
2.6 KiB
TypeScript
67 lines
2.6 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { createHookListenerState, type AgentHookEventPayload } from './agent-hook-listener'
|
|
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), {
|
|
maxPanes: 3,
|
|
now
|
|
})
|
|
upsertBoundedAgentHookStatus(listener, status('done', 'done', now), { maxPanes: 3, now })
|
|
const stale = listener.lastStatusByPaneKey.get('stale') as AgentHookEventPayload & {
|
|
receivedAt: number
|
|
}
|
|
stale.receivedAt = now - AGENT_STATUS_STALE_AFTER_MS - 1
|
|
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)
|
|
})
|
|
})
|