MCPcopy Index your code
hub / github.com/coder/coder / TestComputerUseTool_Run_Wait

Function TestComputerUseTool_Run_Wait

coderd/x/chatd/chattool/computeruse_test.go:393–441  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

391}
392
393func 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
443func TestComputerUseTool_Run_ScreenshotDataIsDecodedBinary(t *testing.T) {
444 t.Parallel()

Callers

nothing calls this directly

Calls 11

EXPECTMethod · 0.95
NewMockAgentConnFunction · 0.92
DefaultDesktopGeometryFunction · 0.92
NewComputerUseToolFunction · 0.92
AttachmentsFromMetadataFunction · 0.92
FatalMethod · 0.80
DecodeStringMethod · 0.80
ExecuteDesktopActionMethod · 0.65
RunMethod · 0.65
EqualMethod · 0.45
EmptyMethod · 0.45

Tested by

no test coverage detected