tool-result-error.test.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { describe, expect, it } from "vitest";
  2. import { isErrorForToolResult } from "../src/runtime/helpers/tool-result.js";
  3. import type { ToolExecutionResult } from "../src/tool/types.js";
  4. describe("tool result model error flag", () => {
  5. it("uses explicit tool output error flags and execution failures", () => {
  6. expect(isErrorForToolResult(toolResult({ success: false, output: "boom" }))).toBe(true);
  7. expect(isErrorForToolResult(toolResult({ output: { isError: true } }))).toBe(true);
  8. expect(isErrorForToolResult(toolResult({ output: { is_error: true } }))).toBe(true);
  9. });
  10. it("marks interrupted and failed Bash commands as is_error", () => {
  11. expect(
  12. isErrorForToolResult(
  13. toolResult({
  14. toolName: "Bash",
  15. output: { interrupted: true, status: "cancelled" },
  16. }),
  17. ),
  18. ).toBe(true);
  19. expect(
  20. isErrorForToolResult(
  21. toolResult({
  22. toolName: "Bash",
  23. output: { exitCode: 1, interrupted: false, status: "failed" },
  24. }),
  25. ),
  26. ).toBe(true);
  27. expect(
  28. isErrorForToolResult(
  29. toolResult({
  30. toolName: "Bash",
  31. output: {
  32. exitCode: 1,
  33. interrupted: false,
  34. returnCodeInterpretation: "No matches found",
  35. status: "failed",
  36. },
  37. }),
  38. ),
  39. ).toBe(false);
  40. });
  41. });
  42. function toolResult(options: {
  43. output: unknown;
  44. success?: boolean;
  45. toolName?: string;
  46. }): ToolExecutionResult {
  47. const now = new Date();
  48. return {
  49. completedAt: now,
  50. durationMs: 1,
  51. output: options.output,
  52. startedAt: now,
  53. success: options.success ?? true,
  54. toolCallId: "call_test",
  55. toolName: options.toolName ?? "Test",
  56. };
  57. }