I think Stalin knew eventually there would be war with Germany....but he had hoped it would have occurred after the Germans got bogged down in the West....one little problem.....France fell in six weeks. Then Stalin desperately tried to buy time by placating the Germans, while trying to build up his military...but Hitler beat him to the punch.
There are some post-perestroika witnesses who were in a position to know, and say that Stalin was seriously freaked out and caught off guard. Saw it on History Channel program about transporting Hitler’s, Eva’s and the Goebels’ remains over half of Russia, with the people who did it providing their stories. Hitler’s skeleton ended up in the Kremlin.