I think it depends on how involved the infiltration is. I would hope they first go directly to the candidate for cooperation. If it needs to be made public, they should be as transparent as possible after ferreting out the infiltration, to try to ensure that the revelations impact that campaign as little as possible.
Of course, if made public before the election, the other candidate is going to harp on how their inept opponent allowed foreign spies into their inner circle, and thus cannot be trusted to be president and blahblahblah.