(t *testing.T)
| 623 | } |
| 624 | |
| 625 | func TestRun_ToolError_RecordsMetric(t *testing.T) { |
| 626 | t.Parallel() |
| 627 | |
| 628 | tests := []struct { |
| 629 | name string |
| 630 | toolFn func(context.Context, struct{}, fantasy.ToolCall) (fantasy.ToolResponse, error) |
| 631 | builtinToolNames map[string]bool |
| 632 | wantLabel string |
| 633 | }{ |
| 634 | { |
| 635 | name: "builtin_tool_IsError", |
| 636 | toolFn: func(_ context.Context, _ struct{}, _ fantasy.ToolCall) (fantasy.ToolResponse, error) { |
| 637 | return fantasy.ToolResponse{ |
| 638 | Content: "something went wrong", |
| 639 | IsError: true, |
| 640 | }, nil |
| 641 | }, |
| 642 | builtinToolNames: map[string]bool{"failing_tool": true}, |
| 643 | wantLabel: "failing_tool", |
| 644 | }, |
| 645 | { |
| 646 | name: "mcp_tool_IsError", |
| 647 | toolFn: func(_ context.Context, _ struct{}, _ fantasy.ToolCall) (fantasy.ToolResponse, error) { |
| 648 | return fantasy.ToolResponse{ |
| 649 | Content: "something went wrong", |
| 650 | IsError: true, |
| 651 | }, nil |
| 652 | }, |
| 653 | builtinToolNames: map[string]bool{}, |
| 654 | wantLabel: "failing_tool", |
| 655 | }, |
| 656 | { |
| 657 | name: "tool_Run_returns_error", |
| 658 | toolFn: func(_ context.Context, _ struct{}, _ fantasy.ToolCall) (fantasy.ToolResponse, error) { |
| 659 | return fantasy.ToolResponse{}, xerrors.New("connection refused") |
| 660 | }, |
| 661 | builtinToolNames: map[string]bool{"failing_tool": true}, |
| 662 | wantLabel: "failing_tool", |
| 663 | }, |
| 664 | } |
| 665 | |
| 666 | for _, tt := range tests { |
| 667 | t.Run(tt.name, func(t *testing.T) { |
| 668 | t.Parallel() |
| 669 | |
| 670 | reg := prometheus.NewRegistry() |
| 671 | metrics := chatloop.NewMetrics(reg) |
| 672 | |
| 673 | failingTool := fantasy.NewAgentTool( |
| 674 | "failing_tool", |
| 675 | "a tool that always fails", |
| 676 | tt.toolFn, |
| 677 | ) |
| 678 | |
| 679 | model := &chattest.FakeModel{ |
| 680 | ProviderName: "test-provider", |
| 681 | ModelName: "test-model", |
| 682 | StreamFn: func(_ context.Context, _ fantasy.Call) (fantasy.StreamResponse, error) { |
nothing calls this directly
no test coverage detected