How to tell if a dynamic sidebar is being displayed on page?

Because of the way templates are rendered in WordPress it won’t be possible to know if a page has a sidebar until after that sidebar has been rendered. This is because code in templates can’t ‘know’ what code exists later in rendering sequence.

What I would recommend is determining what the conditions are which your sidebar is displayed under and using those conditions in your has-sidebar check. For example, if your wrapper opens in header.php but your sidebar is only displayed on posts by rendering it in single.php only, you could check is_single() in header.php to determine whether the sidebar is going to be rendered. You could combine this with is_active_sidebar() if you need to know of the sidebar will have any widgets in it.