Some states use a tail pipe sensor to test, but most now just query the ECU via the OBD2 port and any recent code even one that has been "cleared" will show up. This recent codes capability is deliberately built in to prevent people from resetting 2 minutes before going through the test.
O2 sensors commonly go at 50-75k miles. And the ones nearest the engine go first. You do not need to buy a Porsche labeled part, Bosch makes 'em and any muffler shop can install em. A writeup with part numbers is
here.