| 175 | } |
| 176 | |
| 177 | func TestExecuteEditFileWrapsResult(t *testing.T) { |
| 178 | dir := t.TempDir() |
| 179 | path := filepath.Join(dir, "f.txt") |
| 180 | if err := os.WriteFile(path, []byte("hello world"), 0o644); err != nil { |
| 181 | t.Fatal(err) |
| 182 | } |
| 183 | call := chmctx.ToolCall{ |
| 184 | ID: "call_e", |
| 185 | Name: "edit_file", |
| 186 | Arguments: map[string]any{ |
| 187 | "path": path, |
| 188 | "old_string": "world", |
| 189 | "new_string": "earth", |
| 190 | }, |
| 191 | } |
| 192 | msg := Execute(context.Background(), call) |
| 193 | if msg.Role != chmctx.RoleTool || msg.ToolCallID != "call_e" || msg.ToolName != "edit_file" { |
| 194 | t.Fatalf("bad message: %+v", msg) |
| 195 | } |
| 196 | if !strings.HasPrefix(msg.Content, "edited") { |
| 197 | t.Fatalf("content missing: %q", msg.Content) |
| 198 | } |
| 199 | got, _ := os.ReadFile(path) |
| 200 | if string(got) != "hello earth" { |
| 201 | t.Fatalf("file content wrong: %q", got) |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | func TestInlineStatusEditFile(t *testing.T) { |
| 206 | s := InlineStatus(chmctx.ToolCall{ |