When teams make heavy investments in players with expiring deals, they usually have some knowledge of the players' expectations and, at least, a reasonable degree of confidence in their ability to sign them long term. That's not a guarantee, of course (are there ever any?), but more like a calculated risk they could see worth taking (see Harden & Philly). Or not, who knows.
In the case of Poeltl, the whole "wanting to test he FA waters" deal is a metaphor for not settling for less than he could get, since his current deal limits any extension to around 14 something million per year. What Boston would acquire if they trade for him, are his Bird rights meaning they could go as high as it takes within the CBA, and putting themselves in pole position to sign him. I also wouldn't have anticipated Brad Stevens pulling the trigger on the Derrick White deal, yet he did.
As for Robert Williams, his health is definitely a concern the Spurs should make their due diligence on, yes. I'm taking that for granted if it goes through, otherwise it's a definite pass.