(t *testing.T)
| 18 | ) |
| 19 | |
| 20 | func TestExecuteTool(t *testing.T) { |
| 21 | t.Parallel() |
| 22 | |
| 23 | t.Run("SchemaIncludesOptionalModelIntent", func(t *testing.T) { |
| 24 | t.Parallel() |
| 25 | |
| 26 | tool := chattool.Execute(chattool.ExecuteOptions{}) |
| 27 | info := tool.Info() |
| 28 | modelIntentParam, ok := info.Parameters["model_intent"].(map[string]any) |
| 29 | require.True(t, ok) |
| 30 | assert.Equal(t, "string", modelIntentParam["type"]) |
| 31 | assert.Contains(t, modelIntentParam["description"], "alongside the command") |
| 32 | assert.Contains(t, modelIntentParam["description"], "do not repeat the command") |
| 33 | assert.Contains(t, info.Required, "command") |
| 34 | assert.NotContains(t, info.Required, "model_intent") |
| 35 | }) |
| 36 | |
| 37 | t.Run("EmptyCommand", func(t *testing.T) { |
| 38 | t.Parallel() |
| 39 | ctrl := gomock.NewController(t) |
| 40 | mockConn := agentconnmock.NewMockAgentConn(ctrl) |
| 41 | |
| 42 | tool := newExecuteTool(t, mockConn) |
| 43 | resp, err := tool.Run(context.Background(), fantasy.ToolCall{ |
| 44 | ID: "call-1", |
| 45 | Name: "execute", |
| 46 | Input: `{"command":""}`, |
| 47 | }) |
| 48 | require.NoError(t, err) |
| 49 | assert.True(t, resp.IsError) |
| 50 | assert.Contains(t, resp.Content, "command is required") |
| 51 | }) |
| 52 | |
| 53 | t.Run("AmpersandDetection", func(t *testing.T) { |
| 54 | t.Parallel() |
| 55 | |
| 56 | tests := []struct { |
| 57 | name string |
| 58 | command string |
| 59 | runInBackground *bool |
| 60 | wantCommand string |
| 61 | wantBackground bool |
| 62 | wantBackgroundResp bool // true if the response should contain a background_process_id |
| 63 | comment string |
| 64 | }{ |
| 65 | { |
| 66 | name: "SimpleBackground", |
| 67 | command: "cmd &", |
| 68 | wantCommand: "cmd", |
| 69 | wantBackground: true, |
| 70 | wantBackgroundResp: true, |
| 71 | comment: "Trailing & is correctly detected and stripped.", |
| 72 | }, |
| 73 | { |
| 74 | name: "TrailingDoubleAmpersand", |
| 75 | command: "cmd &&", |
| 76 | wantCommand: "cmd &&", |
| 77 | wantBackground: false, |
nothing calls this directly
no test coverage detected