Auto-install extensions unit tests

This is a squashed version of PR #9581

Auto-install extensions unit tests, bug fixes, code cleanup

This adds unit tests for auto-installing extensions
* refactored code to facilitate testing
* added jsdoc annotations
* minor code cleanup
* fixes #9576

cc @dangoor