These rules are simple. Don't strike out. If you have been claiming a home office deduction, beware. There are some Special Exceptions. Couples have special rules.
More special rules kick in when one spouse dies.
Others protect a spouse who leaves the property because of a divorce or separation. But nothing will protect you if you simply don't follow the rules. If you are forced to sell because employer moved you to another city, you can have part of the exclusion. Each of the 3 tests involves a 2-year period. Simply find the one in which you have the least time.