I think it's so specific to a given codebase that it's hard to give advice that generalizes well.
I have the same feelings as you here, I often feel a little lost trying to decide how much duplication is appropriate in a given case.
I try to not overthink it in the difficult cases. There are many other places in code where it's more obvious, because you can see the history of how people worked with the code, what was the frequency of changes and edge cases added to it etc.
Often it's also just about the readability of the code, I tend to go by the "how confusing it will be for the next person if I defuplicate this code in a smart way" metric.
I have the same feelings as you here, I often feel a little lost trying to decide how much duplication is appropriate in a given case.
I try to not overthink it in the difficult cases. There are many other places in code where it's more obvious, because you can see the history of how people worked with the code, what was the frequency of changes and edge cases added to it etc.
Often it's also just about the readability of the code, I tend to go by the "how confusing it will be for the next person if I defuplicate this code in a smart way" metric.