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

Function runForegroundWithOutput

coderd/x/chatd/chattool/execute_internal_test.go:67–100  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

65// Execute tool with a mock that returns the given output, and
66// returns the parsed result.
67func 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}

Callers 1

TestTruncateOutputFunction · 0.85

Calls 9

EXPECTMethod · 0.95
NewMockAgentConnFunction · 0.92
ContextFunction · 0.92
ExecuteFunction · 0.85
HelperMethod · 0.65
StartProcessMethod · 0.65
ProcessOutputMethod · 0.65
RunMethod · 0.65
UnmarshalMethod · 0.45

Tested by

no test coverage detected