| 78 | } |
| 79 | |
| 80 | func TestExecuteWriteFileWrapsResult(t *testing.T) { |
| 81 | dir := t.TempDir() |
| 82 | path := filepath.Join(dir, "out.txt") |
| 83 | call := chmctx.ToolCall{ |
| 84 | ID: "call_w", |
| 85 | Name: "write_file", |
| 86 | Arguments: map[string]any{ |
| 87 | "path": path, |
| 88 | "content": "hello", |
| 89 | }, |
| 90 | } |
| 91 | msg := Execute(context.Background(), call) |
| 92 | if msg.Role != chmctx.RoleTool || msg.ToolCallID != "call_w" || msg.ToolName != "write_file" { |
| 93 | t.Fatalf("bad message: %+v", msg) |
| 94 | } |
| 95 | if !strings.Contains(msg.Content, "wrote 5 bytes") { |
| 96 | t.Fatalf("content missing: %q", msg.Content) |
| 97 | } |
| 98 | got, _ := os.ReadFile(path) |
| 99 | if string(got) != "hello" { |
| 100 | t.Fatalf("file content wrong: %q", got) |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | // TestExecuteWriteFileRefusesMissingContent: valid-JSON args with no string |
| 105 | // "content" ({"path": ...} alone, or "content": null) must not decode to "" |