1package tools
 2
 3import (
 4	"context"
 5	"testing"
 6
 7	"github.com/charmbracelet/crush/internal/permission"
 8)
 9
10func TestVSCodeDiffTool(t *testing.T) {
11	// Create a real permission service for testing
12	permissions := permission.NewPermissionService()
13	
14	tool := NewVSCodeDiffTool(permissions)
15	
16	// Test tool info
17	info := tool.Info()
18	if info.Name != VSCodeDiffToolName {
19		t.Errorf("Expected tool name %s, got %s", VSCodeDiffToolName, info.Name)
20	}
21	
22	// Test tool name
23	if tool.Name() != VSCodeDiffToolName {
24		t.Errorf("Expected tool name %s, got %s", VSCodeDiffToolName, tool.Name())
25	}
26	
27	// Test parameter validation
28	params := `{
29		"left_content": "Hello World",
30		"right_content": "Hello Universe",
31		"left_title": "before.txt",
32		"right_title": "after.txt",
33		"language": "text"
34	}`
35	
36	call := ToolCall{
37		ID:    "test-id",
38		Name:  VSCodeDiffToolName,
39		Input: params,
40	}
41	
42	ctx := context.WithValue(context.Background(), SessionIDContextKey, "test-session")
43	
44	// Auto-approve the session to avoid permission prompts during testing
45	permissions.AutoApproveSession("test-session")
46	
47	// This will fail if VS Code is not installed, but should not error on parameter parsing
48	response, err := tool.Run(ctx, call)
49	if err != nil {
50		t.Errorf("Unexpected error: %v", err)
51	}
52	
53	// Should either succeed (if VS Code is available) or fail with a specific error message
54	if response.IsError && response.Content != "VS Code is not available. Please install VS Code and ensure 'code' command is in PATH." {
55		t.Errorf("Unexpected error response: %s", response.Content)
56	}
57}