(t *testing.T)
| 543 | } |
| 544 | |
| 545 | func TestWithToolsAdditive(t *testing.T) { |
| 546 | tools := []ServerTool{ |
| 547 | mockTool("issue_read", "toolset1", true), |
| 548 | mockTool("issue_write", "toolset1", false), |
| 549 | mockTool("repo_read", "toolset2", true), |
| 550 | } |
| 551 | |
| 552 | // Test WithTools bypasses toolset filtering |
| 553 | // Enable only toolset2, but add issue_read as additional tool |
| 554 | filtered := mustBuild(t, NewBuilder().SetTools(tools).WithToolsets([]string{"toolset2"}).WithTools([]string{"issue_read"})) |
| 555 | |
| 556 | available := filtered.AvailableTools(context.Background()) |
| 557 | if len(available) != 2 { |
| 558 | t.Errorf("expected 2 tools (repo_read from toolset + issue_read additional), got %d", len(available)) |
| 559 | } |
| 560 | |
| 561 | // Verify both tools are present |
| 562 | toolNames := make(map[string]bool) |
| 563 | for _, tool := range available { |
| 564 | toolNames[tool.Tool.Name] = true |
| 565 | } |
| 566 | if !toolNames["issue_read"] { |
| 567 | t.Error("expected issue_read to be included as additional tool") |
| 568 | } |
| 569 | if !toolNames["repo_read"] { |
| 570 | t.Error("expected repo_read to be included from toolset2") |
| 571 | } |
| 572 | |
| 573 | // Test WithTools respects read-only mode |
| 574 | readOnlyFiltered := mustBuild(t, NewBuilder().SetTools(tools).WithReadOnly(true).WithTools([]string{"issue_write"})) |
| 575 | available = readOnlyFiltered.AvailableTools(context.Background()) |
| 576 | |
| 577 | // issue_write should be excluded because read-only applies to additional tools too |
| 578 | for _, tool := range available { |
| 579 | if tool.Tool.Name == "issue_write" { |
| 580 | t.Error("expected issue_write to be excluded in read-only mode") |
| 581 | } |
| 582 | } |
| 583 | |
| 584 | // Test WithTools with non-existent tool (should error during Build) |
| 585 | _, err := NewBuilder().SetTools(tools).WithToolsets([]string{}).WithTools([]string{"nonexistent"}).Build() |
| 586 | require.Error(t, err, "expected error for non-existent tool") |
| 587 | require.Contains(t, err.Error(), "nonexistent") |
| 588 | } |
| 589 | |
| 590 | func TestWithToolsResolvesAliases(t *testing.T) { |
| 591 | tools := []ServerTool{ |
nothing calls this directly
no test coverage detected