The node raises the unknown rules warning, and runs the -alertnotify command, twice in this test. The first time is when the unknown deployment becomes active, and the second is after the restart. The test checks the alert file only once, at the end. As the command appends to the alert file, that check is already satisfied by the output of the first alert, so the test does not wait for the second command at all.
The first commit waits for the first alert before the restart.
The second commit empties the alert file while the node is down, so that the final check can only be satisfied by the second alert.
On Windows, this narrows a race in which the test directory was removed while the second command was still starting. The command keeps open the handles it inherits from the node, which made the cleanup fail:
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process:...
This PR improves the test logic and mitigates #28529. However, it does not address the inheritance of the node's handles by child processes, part of which is tracked in #36668.