Never forget that they were allies until June 22, 1941.
It wasn’t an alliance in a ‘friendly’ sense. More like two warring mafioso defining the boundaries of the turf war. Poland’s geography means it got shafted by two totalitatarian dictatorships. Stalin’s goal appears to have been to buy some time by creating strategic depth before Germans could bust into the pre pact borders of the Soviet Union. The planning for operation that became Barbarossa in june 41 was on the table in october 1940. Stalin would have known this. However he ignored his general staff’s advice that that the onslaught would come through Belorussia (which it did) and focused on a main thrust through the UKSSR. So Stalin probably bought a little time at Poland and elsewhere’s expense, but threw some of it away due to initial tone deafness