test-timeline.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * Test script to verify timeline builder works with real session data
  3. */
  4. import { SessionReader } from './src/collector/session-reader.js';
  5. import { TimelineBuilder } from './src/collector/timeline-builder.js';
  6. async function test() {
  7. const reader = new SessionReader();
  8. const builder = new TimelineBuilder(reader);
  9. // Get sessions
  10. const sessions = await reader.listSessions();
  11. console.log('Total sessions:', sessions.length);
  12. // Find a session with tools (check first 10)
  13. for (const session of sessions.slice(0, 10)) {
  14. console.log('\n--- Checking session:', session.id);
  15. console.log(' Title:', session.title?.substring(0, 60));
  16. const messagesWithParts = await reader.getMessagesWithParts(session.id);
  17. console.log(' Messages:', messagesWithParts.length);
  18. let toolCount = 0;
  19. const toolNames: string[] = [];
  20. for (const msg of messagesWithParts) {
  21. for (const part of msg.parts || []) {
  22. if (part.type === 'tool') {
  23. toolCount++;
  24. toolNames.push(part.tool);
  25. }
  26. }
  27. }
  28. console.log(' Tool parts in raw data:', toolCount);
  29. if (toolNames.length > 0) {
  30. console.log(' Tools:', [...new Set(toolNames)].join(', '));
  31. }
  32. if (toolCount > 0) {
  33. // Build timeline and check
  34. const timeline = await builder.buildTimeline(session.id);
  35. const toolCalls = timeline.filter(e => e.type === 'tool_call');
  36. console.log(' Timeline tool_call events:', toolCalls.length);
  37. if (toolCalls.length > 0) {
  38. console.log(' ✅ Timeline correctly captured tool calls!');
  39. console.log(' First tool in timeline:', toolCalls[0].data?.tool);
  40. } else {
  41. console.log(' ❌ Timeline MISSING tool calls!');
  42. }
  43. // Found a session with tools, we can stop
  44. console.log('\n=== VERIFICATION COMPLETE ===');
  45. if (toolCalls.length === toolCount) {
  46. console.log('✅ SUCCESS: Timeline correctly captures all tool calls');
  47. } else {
  48. console.log(`❌ MISMATCH: Raw data has ${toolCount} tools, timeline has ${toolCalls.length}`);
  49. }
  50. return;
  51. }
  52. }
  53. console.log('\n⚠️ No sessions with tool calls found in first 10 sessions');
  54. }
  55. test().catch(console.error);