|
1 | 1 | package main |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "bytes" |
| 5 | + "context" |
4 | 6 | "testing" |
5 | 7 |
|
6 | 8 | "github.com/google/go-cmp/cmp" |
| 9 | + mockapi "github.com/sourcegraph/src-cli/internal/api/mock" |
| 10 | + "github.com/stretchr/testify/mock" |
| 11 | + "github.com/stretchr/testify/require" |
7 | 12 | ) |
8 | 13 |
|
9 | 14 | // If we were to do a json marshalling roundtrip, it may break large integer literals. |
@@ -42,3 +47,52 @@ func TestParseABCVariables(t *testing.T) { |
42 | 47 | t.Errorf("err: %v", diff) |
43 | 48 | } |
44 | 49 | } |
| 50 | + |
| 51 | +func TestRunABCVariablesSet(t *testing.T) { |
| 52 | + t.Parallel() |
| 53 | + |
| 54 | + client := new(mockapi.Client) |
| 55 | + request := &mockapi.Request{Response: `{"data":{"updateAgenticWorkflowInstanceVariables":{"id":"workflow"}}}`} |
| 56 | + output := &bytes.Buffer{} |
| 57 | + variables := map[string]string{ |
| 58 | + "prompt": `"tighten the review criteria"`, |
| 59 | + "checkpoints": "[1,2,3]", |
| 60 | + } |
| 61 | + |
| 62 | + client.On("NewRequest", updateABCWorkflowInstanceVariablesMutation, map[string]any{ |
| 63 | + "instanceID": "QWdlbnRpY1dvcmtmbG93SW5zdGFuY2U6MQ==", |
| 64 | + "variables": []map[string]string{ |
| 65 | + {"key": "checkpoints", "value": "[1,2,3]"}, |
| 66 | + {"key": "prompt", "value": `"tighten the review criteria"`}, |
| 67 | + }, |
| 68 | + }).Return(request).Once() |
| 69 | + request.On("Do", context.Background(), mock.Anything).Return(true, nil).Once() |
| 70 | + |
| 71 | + err := runABCVariablesSet(context.Background(), client, "QWdlbnRpY1dvcmtmbG93SW5zdGFuY2U6MQ==", variables, output) |
| 72 | + require.NoError(t, err) |
| 73 | + require.Equal(t, "Updated 2 variables on workflow instance \"QWdlbnRpY1dvcmtmbG93SW5zdGFuY2U6MQ==\".\n", output.String()) |
| 74 | + |
| 75 | + client.AssertExpectations(t) |
| 76 | + request.AssertExpectations(t) |
| 77 | +} |
| 78 | + |
| 79 | +func TestRunABCVariablesSetSuppressesSuccessMessageWhenRequestDoesNotExecute(t *testing.T) { |
| 80 | + t.Parallel() |
| 81 | + |
| 82 | + client := new(mockapi.Client) |
| 83 | + request := &mockapi.Request{} |
| 84 | + output := &bytes.Buffer{} |
| 85 | + |
| 86 | + client.On("NewRequest", updateABCWorkflowInstanceVariablesMutation, map[string]any{ |
| 87 | + "instanceID": "QWdlbnRpY1dvcmtmbG93SW5zdGFuY2U6MQ==", |
| 88 | + "variables": []map[string]string{{"key": "prompt", "value": `"tighten the review criteria"`}}, |
| 89 | + }).Return(request).Once() |
| 90 | + request.On("Do", context.Background(), mock.Anything).Return(false, nil).Once() |
| 91 | + |
| 92 | + err := runABCVariablesSet(context.Background(), client, "QWdlbnRpY1dvcmtmbG93SW5zdGFuY2U6MQ==", map[string]string{"prompt": `"tighten the review criteria"`}, output) |
| 93 | + require.NoError(t, err) |
| 94 | + require.Empty(t, output.String()) |
| 95 | + |
| 96 | + client.AssertExpectations(t) |
| 97 | + request.AssertExpectations(t) |
| 98 | +} |
0 commit comments