(t *testing.T)
| 391 | } |
| 392 | |
| 393 | func TestComputerUseTool_Run_Wait(t *testing.T) { |
| 394 | t.Parallel() |
| 395 | |
| 396 | ctrl := gomock.NewController(t) |
| 397 | mockConn := agentconnmock.NewMockAgentConn(ctrl) |
| 398 | geometry := workspacesdk.DefaultDesktopGeometry() |
| 399 | followUpScreenshot := base64.StdEncoding.EncodeToString([]byte("after-wait")) |
| 400 | |
| 401 | mockConn.EXPECT().ExecuteDesktopAction( |
| 402 | gomock.Any(), |
| 403 | gomock.AssignableToTypeOf(workspacesdk.DesktopAction{}), |
| 404 | ).DoAndReturn(func(_ context.Context, action workspacesdk.DesktopAction) (workspacesdk.DesktopActionResponse, error) { |
| 405 | require.NotNil(t, action.ScaledWidth) |
| 406 | require.NotNil(t, action.ScaledHeight) |
| 407 | assert.Equal(t, geometry.DeclaredWidth, *action.ScaledWidth) |
| 408 | assert.Equal(t, geometry.DeclaredHeight, *action.ScaledHeight) |
| 409 | return workspacesdk.DesktopActionResponse{ |
| 410 | Output: "screenshot", |
| 411 | ScreenshotData: followUpScreenshot, |
| 412 | ScreenshotWidth: geometry.DeclaredWidth, |
| 413 | ScreenshotHeight: geometry.DeclaredHeight, |
| 414 | }, nil |
| 415 | }) |
| 416 | |
| 417 | tool := chattool.NewComputerUseTool(chattool.ComputerUseProviderAnthropic, geometry.DeclaredWidth, geometry.DeclaredHeight, func(_ context.Context) (workspacesdk.AgentConn, error) { |
| 418 | return mockConn, nil |
| 419 | }, func(_ context.Context, _ string, _ string, _ []byte) (chattool.AttachmentMetadata, error) { |
| 420 | t.Fatal("storeFile should not be called for wait screenshots") |
| 421 | return chattool.AttachmentMetadata{}, nil |
| 422 | }, quartz.NewReal(), slogtest.Make(t, nil)) |
| 423 | |
| 424 | call := fantasy.ToolCall{ |
| 425 | ID: "test-3", |
| 426 | Name: "computer", |
| 427 | Input: `{"action":"wait","duration":10}`, |
| 428 | } |
| 429 | |
| 430 | resp, err := tool.Run(context.Background(), call) |
| 431 | require.NoError(t, err) |
| 432 | assert.Equal(t, "image", resp.Type) |
| 433 | assert.Equal(t, "image/png", resp.MediaType) |
| 434 | expectedBinary, decErr := base64.StdEncoding.DecodeString(followUpScreenshot) |
| 435 | require.NoError(t, decErr) |
| 436 | assert.Equal(t, expectedBinary, resp.Data) |
| 437 | assert.False(t, resp.IsError) |
| 438 | attachments, err := chattool.AttachmentsFromMetadata(resp.Metadata) |
| 439 | require.NoError(t, err) |
| 440 | assert.Empty(t, attachments) |
| 441 | } |
| 442 | |
| 443 | func TestComputerUseTool_Run_ScreenshotDataIsDecodedBinary(t *testing.T) { |
| 444 | t.Parallel() |
nothing calls this directly
no test coverage detected