Cherry-picked from PR #5136 by thakoreh. setup_gateway() uses shutil.which('uv') at line 2126 but shutil was never imported at module level, causing NameError during Matrix E2EE auto-install. Adds top-level import and regression test.