Your macOS software does not have its own hardware diagnostics (other than that which verifies the kernel, etc during boot), however the Mac's firmware provides access to that test, and if the local hardware somehow can't, then the Mac boots to Apple's server, where it launches the diagnostics. It's not part of the software that might be loaded on your Mac, and will run even with no storage drive installed. It would probably report an error if there is no storage drive, but the diagnostics doesn't need a local system at all.
You can run the diagnostics at any time. I only suggested running it when a problem is visible, as it might be more likely to report an error code, if there is a noticeable problem at about that time. I would not guarantee a reported code --- and the diagnostics might find something that you don't notice - or the diagnostics might not report any problem at all, even though you might see something at the time. It's just another troubleshooting step to try.