How to determine the traffic avoidance manuver?
In Scenario A there is no obvious answer. You take whatever action is necessary to avoid a collision. If this were a controlled airfield there would be questions raised to the ground controller. If not, similar questions would be directed at the pilot entering a runway without notifying anyone. Even at a completely deserted airfield without any form of station any pilot entering a runway would announce it on a radio beforehand just in case!

Scenario B can be a little more specific, and is a situation that occurs reasonably often at small airfields - less so at large controlled airports. Assuming you've not just busted onto the runway, ignoring traffic on final approach you probably have priority over the approaching aircraft. But if you're a large airliner and/or at a controlled airfield its hugely unlikely you've been cleared to enter the runway to line up if something is on final approach.

If this does happen:


an airliner would follow a missed approach procedure, which would take them well out of the way of the departing aircraft
a light aircraft would perform a similar manoeuvre but commonly known as a "go around". This involves positioning so that the pilot can keep eyes on the departing aircraft, for example flying just to the right of the runway at circuit height.