I don't know a ton about this topic, but in Molotov Remembers, a reprint of a bunch of conversations with Molotov in the 70s and 80s, the interviewer asks a lot of questions about this topic.
Molotov said that Stalin knew there would be war with Hitler, and the whole point of the Molotov-Ribbentrop Pact was to stall for time and prepare, and that Stalin felt the country needed two more years before the USSR was ready. Molotov makes clear that all of the ruling circle knew that the Nazis were enemies, and that they knew an attack was eminent. Molotov laughed at the idea that Stalin naively thought that Hitler could be trusted to keep the terms of the Pact - indeed he points out that Stalin trusted no one, even Molotov himself!
So why was the Soviet Union "caught by surprise" when the Germans attacked? Molotov says that Stalin was primarily worried about an anti-USSR German/British alliance, and that Stalin sent orders to his troops specifically to make sure that Germany was the clear aggressor. The orders specified that there was to be no military response to anything the Germans did, except from Stalin himself.
Prior to the invasion, there was a number of border skirmishes and false alarms. Molotov says they were worried about being baited by Hitler into escalating the war, and thus be blamed for its start. The orders helped delay the start of the war by weeks or months. He also mentioned the British intelligence report and that they felt it was something of a joke, that "how could we not know the invasion was eminent? And how could we trust the British?"
Molotov then goes on to call Stalin a genius for this tactic, because:
- The delayed the start of the war allowed winter to interrupt the German invasion, ultimately preventing defeat.
- That showing that Germany was the aggressor split the German/British/capitalist alliance, and even causing the counter-intuitive US/British/Soviet alliance. Molotov states that receiving material help from the US was unthinkable in the 1930s, and that only Stalin could have conceived of this plan.
Just to be clear, I have not read enough about this subject to give a full answer, having only read Molotov's biased opinion. I am not sure I fully buy his opinion, considering what he said about the Holodomor. However, I feel he is correct in stating that the USSR would have lost if the invasion had started even 1 month earlier. I also liked his point about how odd the idea of an alliance with the British was.
On another note, it was interesting to hear his first hand account of what all the major actors in WWII were like personally; he didn't like Ribbentrop very much!