How did the author prepare the reader for the ironic ending of "The Sniper"?
You are right in indicating that to a certain extent the author foreshadows the ironic and grimly tragic ending of this short story. For me, the foreshadowing comes in when the sniper has killed his enemy, and he has a moment of remorse as he contemplates what he has done having dispatched his enemy and opened his way to leave the roof:
The snipe looked at his enemy falling and he shuddered. The lust of battle died in him. He became bitten by remorse. The sweat stood out in beads on his forehead. Weakened by his wound and the long summer day of fasting and watching on the roof, he revolted from the sight of the shattered mass of his dead enemy. his teeth chattered, he began to gibber to himself, cursing the war, cursing himself, cursing everybody.
It is this paragraph when we begin to suspect that there is something wrong with what has just happened - we see the student, who was previously described as a "fanatic", now regretting the war and what he has just done. This represents the author preparing us for the shocking ending of the tale - that the man the sniper has killed is his brother.