|
1 | 1 | package chat |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "strings" |
4 | 5 | "sync" |
5 | 6 | "testing" |
6 | 7 | "time" |
@@ -201,6 +202,31 @@ func TestPendingApproval_WaitConcurrent(t *testing.T) { |
201 | 202 | wg.Wait() |
202 | 203 | } |
203 | 204 |
|
| 205 | +func TestIsGated_SlackMessage(t *testing.T) { |
| 206 | + t.Parallel() |
| 207 | + |
| 208 | + tests := []struct { |
| 209 | + name string |
| 210 | + toolName string |
| 211 | + want bool |
| 212 | + }{ |
| 213 | + {"send_slack_message is gated", "send_slack_message", true}, |
| 214 | + {"list_slack_channels is not gated", "list_slack_channels", false}, |
| 215 | + {"read_slack_messages is not gated", "read_slack_messages", false}, |
| 216 | + {"search_slack is not gated", "search_slack", false}, |
| 217 | + } |
| 218 | + |
| 219 | + for _, tt := range tests { |
| 220 | + t.Run(tt.name, func(t *testing.T) { |
| 221 | + t.Parallel() |
| 222 | + got := IsGated(tt.toolName) |
| 223 | + if got != tt.want { |
| 224 | + t.Errorf("IsGated(%q) = %v, want %v", tt.toolName, got, tt.want) |
| 225 | + } |
| 226 | + }) |
| 227 | + } |
| 228 | +} |
| 229 | + |
204 | 230 | func TestBuildPreview(t *testing.T) { |
205 | 231 | t.Parallel() |
206 | 232 |
|
@@ -292,3 +318,50 @@ func TestBuildPreview(t *testing.T) { |
292 | 318 | }) |
293 | 319 | } |
294 | 320 | } |
| 321 | + |
| 322 | +func TestBuildPreview_SlackMessage(t *testing.T) { |
| 323 | + t.Parallel() |
| 324 | + |
| 325 | + preview := BuildPreview(ToolCall{ |
| 326 | + Name: "send_slack_message", |
| 327 | + Args: map[string]any{ |
| 328 | + "channel": "#engineering", |
| 329 | + "text": "Hello team!", |
| 330 | + "thread_ts": "1234567890.123456", |
| 331 | + }, |
| 332 | + }) |
| 333 | + |
| 334 | + if preview["channel"] != "#engineering" { |
| 335 | + t.Errorf("channel = %v, want %q", preview["channel"], "#engineering") |
| 336 | + } |
| 337 | + if preview["text"] != "Hello team!" { |
| 338 | + t.Errorf("text = %v, want %q", preview["text"], "Hello team!") |
| 339 | + } |
| 340 | + if preview["thread_ts"] != "1234567890.123456" { |
| 341 | + t.Errorf("thread_ts = %v, want %q", preview["thread_ts"], "1234567890.123456") |
| 342 | + } |
| 343 | +} |
| 344 | + |
| 345 | +func TestBuildPreview_SlackMessage_LongText(t *testing.T) { |
| 346 | + t.Parallel() |
| 347 | + |
| 348 | + longText := strings.Repeat("a", 300) |
| 349 | + preview := BuildPreview(ToolCall{ |
| 350 | + Name: "send_slack_message", |
| 351 | + Args: map[string]any{ |
| 352 | + "channel": "#general", |
| 353 | + "text": longText, |
| 354 | + }, |
| 355 | + }) |
| 356 | + |
| 357 | + text, ok := preview["text"].(string) |
| 358 | + if !ok { |
| 359 | + t.Fatal("text is not a string") |
| 360 | + } |
| 361 | + if len(text) > 203 { // 200 + "..." |
| 362 | + t.Errorf("text length = %d, want <= 203", len(text)) |
| 363 | + } |
| 364 | + if !strings.HasSuffix(text, "...") { |
| 365 | + t.Error("text should end with '...'") |
| 366 | + } |
| 367 | +} |
0 commit comments