You probably ran into a similar situation before: You accidentaly quit an iTerm tab with <Command key> W
or <Control key> D
while the tests were running, an ssh connection was open, etc…
One way to prevent this is whitelist these commands “Profiles > Session” section, like this:
Simply add a command name here, and iTerm will ask for a confirmation before closing the tab.