| 917 | } |
| 918 | |
| 919 | func TestRecordingStopIdempotent(t *testing.T) { |
| 920 | t.Parallel() |
| 921 | |
| 922 | logger := slogtest.Make(t, nil) |
| 923 | fake := &fakeDesktop{ |
| 924 | startCfg: agentdesktop.DisplayConfig{Width: 1920, Height: 1080}, |
| 925 | } |
| 926 | api := agentdesktop.NewAPI(logger, fake, nil) |
| 927 | defer api.Close() |
| 928 | |
| 929 | handler := api.Routes() |
| 930 | |
| 931 | // Start recording. |
| 932 | startBody, err := json.Marshal(map[string]string{"recording_id": testRecIDStopIdempotent}) |
| 933 | require.NoError(t, err) |
| 934 | rr := httptest.NewRecorder() |
| 935 | req := httptest.NewRequest(http.MethodPost, "/recording/start", bytes.NewReader(startBody)) |
| 936 | handler.ServeHTTP(rr, req) |
| 937 | require.Equal(t, http.StatusOK, rr.Code) |
| 938 | |
| 939 | // Stop twice - both should succeed with identical data. |
| 940 | var videoParts [2][]byte |
| 941 | for i := range 2 { |
| 942 | body, err := json.Marshal(map[string]string{"recording_id": testRecIDStopIdempotent}) |
| 943 | require.NoError(t, err) |
| 944 | recorder := httptest.NewRecorder() |
| 945 | request := httptest.NewRequest(http.MethodPost, "/recording/stop", bytes.NewReader(body)) |
| 946 | handler.ServeHTTP(recorder, request) |
| 947 | require.Equal(t, http.StatusOK, recorder.Code) |
| 948 | parts := parseMultipartParts(t, recorder.Header().Get("Content-Type"), recorder.Body.Bytes()) |
| 949 | videoParts[i] = parts["video/mp4"] |
| 950 | } |
| 951 | assert.Equal(t, videoParts[0], videoParts[1]) |
| 952 | } |
| 953 | |
| 954 | func TestRecordingStopInvalidIDFormat(t *testing.T) { |
| 955 | t.Parallel() |