MCPcopy Create free account
hub / github.com/astercloud/aster / TestEditTool_SimpleEdit

Function TestEditTool_SimpleEdit

pkg/tools/builtin/edit_test.go:75–116  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

73}
74
75func TestEditTool_SimpleEdit(t *testing.T) {
76 if testing.Short() {
77 t.Skip("Skipping file modification test in short mode")
78 }
79
80 tool, err := NewEditTool(nil)
81 if err != nil {
82 t.Fatalf("Failed to create Edit tool: %v", err)
83 }
84
85 // 创建测试文件
86 helper := NewTestHelper(t)
87 testFile := helper.CreateTempFile("test.txt", "Hello World\nThis is a test\nGoodbye")
88 defer helper.CleanupAll()
89
90 input := map[string]any{
91 "file_path": testFile,
92 "old_string": "Hello World",
93 "new_string": "Hello Universe",
94 }
95
96 result := ExecuteToolWithRealFS(t, tool, input)
97 result = AssertToolSuccess(t, result)
98
99 // 验证响应字段
100 if success, exists := result["success"]; !exists || !success.(bool) {
101 t.Error("Edit operation should succeed")
102 }
103
104 if changes, exists := result["changes_made"]; !exists || changes.(int) != 1 {
105 t.Error("Should indicate 1 change was made")
106 }
107
108 // 验证文件内容确实被修改
109 content := helper.ReadFile(testFile)
110 if !strings.Contains(content, "Hello Universe") {
111 t.Error("File should contain the new string")
112 }
113 if strings.Contains(content, "Hello World") {
114 t.Error("File should not contain the old string")
115 }
116}
117
118func TestEditTool_MultipleEdit(t *testing.T) {
119 if testing.Short() {

Callers

nothing calls this directly

Calls 8

CreateTempFileMethod · 0.95
CleanupAllMethod · 0.95
ReadFileMethod · 0.95
NewEditToolFunction · 0.85
NewTestHelperFunction · 0.85
ExecuteToolWithRealFSFunction · 0.85
AssertToolSuccessFunction · 0.85
ErrorMethod · 0.65

Tested by

no test coverage detected