| |
| |
| |
| |
| |
|
|
| import { describe, it, expect } from 'vitest'; |
| import { ContextGraphMapper } from './mapper.js'; |
| import type { HistoryTurn } from '../../core/agentChatHistory.js'; |
| import { hardenHistory } from '../../utils/historyHardening.js'; |
|
|
| describe('ContextGraphMapper (Round-Trip Fidelity)', () => { |
| it('should flawlessly round-trip a complex history containing parallel tool calls and responses', () => { |
| |
| const envId = 'd04923d38bb0f6017037e74183378ef4'; |
| const originalHistory: HistoryTurn[] = [ |
| { |
| id: envId, |
| content: { |
| role: 'user', |
| parts: [{ text: '<session_context>\nSystem Prompt here' }], |
| }, |
| }, |
| { |
| id: 'user_turn_1', |
| content: { |
| role: 'user', |
| parts: [{ text: 'Please read file A and file B at the same time.' }], |
| }, |
| }, |
| { |
| id: 'model_turn_1', |
| content: { |
| role: 'model', |
| parts: [ |
| { text: 'I will read both files concurrently.' }, |
| { |
| functionCall: { |
| id: 'call_A', |
| name: 'read_file', |
| args: { path: 'A.txt' }, |
| }, |
| thoughtSignature: 'synthetic_sig_xyz', |
| }, |
| { |
| functionCall: { |
| id: 'call_B', |
| name: 'read_file', |
| args: { path: 'B.txt' }, |
| }, |
| }, |
| ], |
| }, |
| }, |
| |
| { |
| id: 'tool_resp_B_id', |
| content: { |
| role: 'user', |
| parts: [ |
| { |
| functionResponse: { |
| id: 'call_B', |
| name: 'read_file', |
| response: { content: 'File B' }, |
| }, |
| }, |
| ], |
| }, |
| }, |
| { |
| id: 'tool_resp_A_id', |
| content: { |
| role: 'user', |
| parts: [ |
| { |
| functionResponse: { |
| id: 'call_A', |
| name: 'read_file', |
| response: { content: 'File A' }, |
| }, |
| }, |
| ], |
| }, |
| }, |
| ]; |
|
|
| |
| |
| const hardenedOriginal = hardenHistory(originalHistory); |
|
|
| |
| const mapper = new ContextGraphMapper(); |
| |
| const nodes = mapper.sync(originalHistory); |
|
|
| |
| const reconstructedHistory = mapper.fromGraph(nodes); |
|
|
| |
| const hardenedReconstructed = hardenHistory(reconstructedHistory); |
|
|
| |
| |
| |
| expect(hardenedReconstructed).toEqual(hardenedOriginal); |
| }); |
| }); |
|
|