conversationSessionNetwork.test.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { describe, expect, it } from "vitest";
  2. import { readUpstreamToolResultFromRequest } from "./e2e/helpers/conversation-session-network.js";
  3. describe("conversation session provider capture", () => {
  4. it("reads OpenAI tool messages by exact call id and ignores assistant tool declarations", () => {
  5. const messages = [
  6. { role: "tool", tool_call_id: "call_plugin", content: "old result" },
  7. { role: "tool", tool_call_id: "call_other", content: "other result" },
  8. { role: "assistant", tool_calls: [{ id: "call_plugin" }], content: "not a result" },
  9. { role: "tool", tool_call_id: "call_plugin", content: "E2E_PLUGIN_RUNTIME" },
  10. ];
  11. expect(readUpstreamToolResultFromRequest({ messages }, "call_plugin")).toEqual({
  12. toolCallId: "call_plugin",
  13. content: "E2E_PLUGIN_RUNTIME",
  14. isError: false,
  15. });
  16. expect(readUpstreamToolResultFromRequest({ messages }, "missing")).toBeNull();
  17. expect(
  18. readUpstreamToolResultFromRequest({ messages: [messages[2]] }, "call_plugin"),
  19. ).toBeNull();
  20. });
  21. it("reads the latest matching tool_result error instead of stale success", () => {
  22. const result = readUpstreamToolResultFromRequest(
  23. {
  24. messages: [
  25. {
  26. role: "user",
  27. content: [
  28. {
  29. type: "tool_result",
  30. tool_use_id: "toolu_browser_action",
  31. content: "stale success",
  32. },
  33. ],
  34. },
  35. {
  36. role: "user",
  37. content: [
  38. {
  39. type: "tool_result",
  40. tool_use_id: "toolu_other",
  41. content: "unrelated failure",
  42. is_error: true,
  43. },
  44. {
  45. type: "tool_result",
  46. tool_use_id: "toolu_browser_action",
  47. content: "E2E_INTENTIONAL_TOOL_FAILURE\n\nStructured content:\n",
  48. is_error: true,
  49. },
  50. ],
  51. },
  52. ],
  53. },
  54. "toolu_browser_action",
  55. );
  56. expect(result).toEqual({
  57. content: "E2E_INTENTIONAL_TOOL_FAILURE\n\nStructured content:\n",
  58. isError: true,
  59. toolCallId: "toolu_browser_action",
  60. });
  61. });
  62. });