refactor: identify and freeze messages at creation
This commit is contained in:
@@ -42,10 +42,10 @@ function assertCompleteCordisLifecycle(events: readonly SessionEvent[]): void {
|
||||
const callIds = new Set(calls.map(event => String(event.data.callId)))
|
||||
const results = events.filter(
|
||||
(event): event is Extract<SessionEvent, { type: 'tool/result' }> =>
|
||||
event.type === 'tool/result' && callIds.has(String(event.data.callId)),
|
||||
event.type === 'tool/result' && callIds.has(String(event.data.message.source.callId)),
|
||||
)
|
||||
expect(results).toHaveLength(CORDIS_TOOLS.length)
|
||||
expect(results.every(event => !event.data.isError)).toBe(true)
|
||||
expect(results.every(event => !event.data.message.content[0].isError)).toBe(true)
|
||||
}
|
||||
|
||||
describe('web e2e: Cordis tools use the generic row variants', () => {
|
||||
|
||||
@@ -87,10 +87,10 @@ describe('web e2e: fresh round trip through the real assembly', () => {
|
||||
const bashCall = sessionEvents.find(event => event.type === 'tool/call' && event.data.name === 'bash')
|
||||
if (bashCall?.type !== 'tool/call') throw new Error('the replayed turn did not call the bash tool')
|
||||
const bashResult = sessionEvents.find(event =>
|
||||
event.type === 'tool/result' && event.data.callId === bashCall.data.callId)
|
||||
event.type === 'tool/result' && event.data.message.source.callId === bashCall.data.callId)
|
||||
if (bashResult?.type !== 'tool/result') throw new Error('the bash tool call produced no durable result')
|
||||
expect(bashResult.data.isError).toBe(false)
|
||||
expect(bashResult.data.content.filter(block => block.type === 'text').map(block => block.text).join(''))
|
||||
expect(bashResult.data.message.content[0].isError).toBe(false)
|
||||
expect(bashResult.data.message.content[0].content.filter(block => block.type === 'text').map(block => block.text).join(''))
|
||||
.toBe('WEB_E2E_OK\n')
|
||||
const turnEnds = sessionEvents.filter(e => e.type === 'turn/end')
|
||||
expect(turnEnds.length).toBe(1)
|
||||
|
||||
@@ -89,8 +89,10 @@ function providerTitle(page: HistoryPage): string | undefined {
|
||||
|
||||
function hasAssistantMarker(page: HistoryPage, marker: string): boolean {
|
||||
return page.events.some(({ event }) => {
|
||||
if (event.type !== 'assistant/message' || !isRecord(event.data) || !Array.isArray(event.data.content)) return false
|
||||
return event.data.content.some(block =>
|
||||
if (event.type !== 'assistant/message' || !isRecord(event.data) || !isRecord(event.data.message)) return false
|
||||
const content = event.data.message.content
|
||||
if (!Array.isArray(content)) return false
|
||||
return content.some(block =>
|
||||
isRecord(block) && block.type === 'text' && typeof block.text === 'string' && block.text.includes(marker))
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user