We generally close B as a duplicate of A if conceptually, everything that B asks is also asked by A, i.e. (good) answers to A are guaranteed to completely and clearly answer B.
That "completely and clearly" part is really important. It's not enough for questions to just have the same bottom-line answer ("it's safe!"). It's the whole of the potential answers: the possibilities, the reasoning, everything. If there's something big you need to do in order to answer B, and A doesn't ask for it, they're not duplicates.
That is, when we say "this question has been asked before..." we mean the concept of the question, not the literal question. If they're conceptually asking the same thing, they're duplicates, even if they don't look the same on the surface.
Some non-exact cases that are generally still duplicates:
- B is a sub-question of A, i.e. A answers more than just B, but still comprehensively covers B.
- B is the same as A, but with added or changed details that don't make any difference to the answer.
Some cases where questions may not be duplicates:
- A doesn't cover everything that B covers, i.e. only some of ways to answer to B would be covered by A.
- A is so general that it doesn't clearly answer B. If the OP would have to really dig through to understand, or there might be details missing, it's not a duplicate.
- B has new details that make A not really apply. This isn't carte blanche to ask endless variations, of course (we'd try to generalize if that happened), but not all situations can be covered by a single question.
- A does answer B, but substantial explanation is needed to demonstrate why it actually applies.
Note: I'm happy to discuss and tweak this, add examples, and so on. However, my goal is to broadly document our current general approach, not to make any new rules. Anything contentious is probably best left for case-by-case considerations.