mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
82 lines
2.9 KiB
TypeScript
82 lines
2.9 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
||
import { readAgentMessageSource, type AgentMessageSource } from './agent-session-message-source'
|
||
import { testOrcaSessionId } from '../orca-session-address-test-fixture'
|
||
|
||
const SESSION = '4a1f6c2e-8b3d-4e7a-9c15-0d2b6e8f1a37'
|
||
|
||
const FROM: AgentMessageSource = {
|
||
kind: 'agent',
|
||
senders: [
|
||
{
|
||
party: { address: 'term_a', terminalHandle: 'term_a', orcaSessionId: null },
|
||
name: 'Build tab',
|
||
agent: 'claude'
|
||
},
|
||
{
|
||
party: {
|
||
address: `orca_session_id:${SESSION}`,
|
||
terminalHandle: null,
|
||
orcaSessionId: testOrcaSessionId(SESSION)
|
||
},
|
||
name: null
|
||
}
|
||
],
|
||
orchestration: {
|
||
message: 'mail-notice',
|
||
mailbox: 'run:r1',
|
||
dispatchId: null,
|
||
messages: [{ messageId: 'm1', runId: 'r1', from: 'term_a' }]
|
||
}
|
||
}
|
||
|
||
describe("a message's sender, read through its one reader", () => {
|
||
it("reads a Dispatch's task back whole", () => {
|
||
const task: AgentMessageSource = {
|
||
...FROM,
|
||
orchestration: { message: 'task', runId: 'r1', taskId: 't1', dispatchId: 'ctx_1' }
|
||
}
|
||
expect(readAgentMessageSource(structuredClone(task))).toEqual(task)
|
||
const parsed = readAgentMessageSource({
|
||
...task,
|
||
senders: FROM.senders.map((sender) => ({ ...sender, relation: 'future' }))
|
||
})
|
||
expect(parsed).toEqual(task)
|
||
})
|
||
|
||
it("keeps a sender's agent this build does not know, and drops only an unreadable one", () => {
|
||
const withAgent = (agent: unknown) =>
|
||
readAgentMessageSource({ ...FROM, senders: [{ ...FROM.senders[0], agent }] })?.senders[0]
|
||
expect(withAgent('future-agent')?.agent).toBe('future-agent')
|
||
expect(withAgent('x'.repeat(200))).toEqual({ ...FROM.senders[0], agent: undefined })
|
||
expect(withAgent(7)?.name).toBe('Build tab')
|
||
})
|
||
|
||
it('keeps an agent an agent when its orchestration kind is newer than this build', () => {
|
||
const newer = { ...FROM, orchestration: { message: 'review', dispatchId: 'ctx_1' } }
|
||
expect(readAgentMessageSource(newer)).toEqual({ ...FROM, orchestration: null })
|
||
// A newer sender kind is still not the person.
|
||
expect(readAgentMessageSource({ ...FROM, kind: 'automation' })).toMatchObject({
|
||
kind: 'agent'
|
||
})
|
||
})
|
||
|
||
it('drops a sender it cannot read and bounds a name, keeping the rest', () => {
|
||
const read = readAgentMessageSource({
|
||
...FROM,
|
||
senders: [
|
||
{ party: { address: 'term_a', terminalHandle: 'term_a', orcaSessionId: 'term_a' } },
|
||
{ party: { address: 'term_b', terminalHandle: 'term_b', orcaSessionId: null }, name: 7 },
|
||
{
|
||
party: { address: 'term_c', terminalHandle: 'term_c', orcaSessionId: null },
|
||
name: `ab\n${'x'.repeat(300)}`
|
||
}
|
||
]
|
||
})
|
||
expect(read?.senders.map(({ party, name }) => [party.address, name?.length ?? null])).toEqual([
|
||
['term_b', null],
|
||
['term_c', 200]
|
||
])
|
||
expect(read?.senders[1]?.name?.startsWith('a b ')).toBe(true)
|
||
})
|
||
})
|