event-reducer-session-status.test.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { describe, expect, it } from "vitest";
  2. import { EventReducer } from "../src/events/event-reducer.js";
  3. import { createSessionEvent, SessionEventType } from "../src/events/session.events.js";
  4. import type { SessionId, ToolCallId, TurnId } from "../src/interfaces/shared.js";
  5. describe("EventReducer session status", () => {
  6. const sessionId = "sess_status" as SessionId;
  7. const turnId = "turn_status" as TurnId;
  8. const toolCallId = "tool_status" as ToolCallId;
  9. it("keeps a turn running after the current tool batch completes", () => {
  10. const events = [
  11. createSessionEvent(SessionEventType.SessionCreated, sessionId, {
  12. mode: "build",
  13. contextWindow: 200000,
  14. }),
  15. createSessionEvent(
  16. SessionEventType.TurnStarted,
  17. sessionId,
  18. { turnNumber: 1, input: "Use a tool" },
  19. { turnId },
  20. ),
  21. createSessionEvent(SessionEventType.ToolCallScheduled, sessionId, {
  22. toolCallId,
  23. toolName: "Read",
  24. input: { filePath: "package.json" },
  25. schedule: { parallelGroups: [[toolCallId]], executionOrder: [toolCallId] },
  26. }),
  27. createSessionEvent(SessionEventType.ToolCallResult, sessionId, {
  28. toolCallId,
  29. result: { success: true, content: "{}" },
  30. duration: 12,
  31. }),
  32. createSessionEvent(SessionEventType.ToolBatchComplete, sessionId, {
  33. toolCallIds: [toolCallId],
  34. successCount: 1,
  35. errorCount: 0,
  36. }),
  37. ];
  38. const projection = new EventReducer().reduce(events);
  39. expect(projection.activeToolCalls).toEqual([]);
  40. expect(projection.status).toBe("running");
  41. const completedProjection = new EventReducer().reduce([
  42. ...events,
  43. createSessionEvent(
  44. SessionEventType.TurnComplete,
  45. sessionId,
  46. {
  47. response: "Done",
  48. tokenCount: 42,
  49. toolCallCount: 1,
  50. duration: 100,
  51. resultType: "success",
  52. },
  53. { turnId },
  54. ),
  55. ]);
  56. expect(completedProjection.status).toBe("idle");
  57. });
  58. });