From what I’ve seen in my work with helping couples sort through messy relationships, when people cheat there's a preparation pattern they first go through, especially the first time they cheat.
In much the same manner as criminal offenders building up to committing a crime, they first have to justify it to themselves.
Believe it or not, when people harm others they don’t just think, “I like harming people so that’s a good enough reason”. With the exception of psychopaths, the hundreds of criminal offenders I rehabilitated all had a big story about why they were justified in their offending.
A cheater has to convince themselves that their partner drove them to it, that their partner is inadequate and unsatisfying - a bad partner. Once they can convince themselves of this, they reduce the anticipated guilt enough to excuse the betrayal.
They'll start to hyperfixate on and exaggerate the negative things in the relationship. to paint a picture of their partner being this frustrating or abusive or unsatisfying person who's not doing what they “should”.
You’ll know your partner is doing it when they are becoming increasingly critical and distant, and ignoring the good things you do.
So if you want to prevent this from happening, you both need to be as generous as possible in your interpretation of each other. This is an agreement you can bring into the relationship whenever you like, but the earlier the better.
Whenever they do anything that doesn’t completely satisfy your preferences, you must ask yourself, “What is the most generously honest way that I can interpret this behaviour?”
And reguarly review all the things you take for granted. Make sure you appreciate what they do rather than dismiss it due to hyperfixation on negatives.
Caveat: if, despite your best efforts at honest measurement, it genuinely appears that they are a terrible partner, then just leave them. I can’t think of a situation where cheating is the best integrity-based option.