runForegroundWithOutput runs a foreground command through the Execute tool with a mock that returns the given output, and returns the parsed result.
(t *testing.T, output string)
| 65 | // Execute tool with a mock that returns the given output, and |
| 66 | // returns the parsed result. |
| 67 | func runForegroundWithOutput(t *testing.T, output string) ExecuteResult { |
| 68 | t.Helper() |
| 69 | ctrl := gomock.NewController(t) |
| 70 | mockConn := agentconnmock.NewMockAgentConn(ctrl) |
| 71 | |
| 72 | mockConn.EXPECT(). |
| 73 | StartProcess(gomock.Any(), gomock.Any()). |
| 74 | Return(workspacesdk.StartProcessResponse{ID: "proc-1"}, nil) |
| 75 | exitCode := 0 |
| 76 | mockConn.EXPECT(). |
| 77 | ProcessOutput(gomock.Any(), "proc-1", gomock.Any()). |
| 78 | Return(workspacesdk.ProcessOutputResponse{ |
| 79 | Running: false, |
| 80 | ExitCode: &exitCode, |
| 81 | Output: output, |
| 82 | }, nil) |
| 83 | |
| 84 | tool := Execute(ExecuteOptions{ |
| 85 | GetWorkspaceConn: func(_ context.Context) (workspacesdk.AgentConn, error) { |
| 86 | return mockConn, nil |
| 87 | }, |
| 88 | }) |
| 89 | ctx := testutil.Context(t, testutil.WaitMedium) |
| 90 | resp, err := tool.Run(ctx, fantasy.ToolCall{ |
| 91 | ID: "call-1", |
| 92 | Name: "execute", |
| 93 | Input: `{"command":"echo test"}`, |
| 94 | }) |
| 95 | require.NoError(t, err) |
| 96 | |
| 97 | var result ExecuteResult |
| 98 | require.NoError(t, json.Unmarshal([]byte(resp.Content), &result)) |
| 99 | return result |
| 100 | } |
no test coverage detected