test_setup_matrix_e2ee.py
1 """Test that setup.py has shutil available for Matrix E2EE auto-install.""" 2 import ast 3 4 import pytest 5 6 7 def _parse_setup_imports(): 8 """Parse setup.py and return top-level import names.""" 9 with open("hermes_cli/setup.py") as f: 10 tree = ast.parse(f.read()) 11 names = set() 12 for node in ast.walk(tree): 13 if isinstance(node, ast.Import): 14 for alias in node.names: 15 names.add(alias.name) 16 elif isinstance(node, ast.ImportFrom): 17 for alias in node.names: 18 names.add(alias.name) 19 return names 20 21 22 class TestSetupShutilImport: 23 def test_shutil_imported_at_module_level(self): 24 """shutil must be imported at module level so setup_gateway can use it 25 for the mautrix auto-install path.""" 26 names = _parse_setup_imports() 27 assert "shutil" in names, ( 28 "shutil is not imported at the top of hermes_cli/setup.py. " 29 "This causes a NameError when the Matrix E2EE auto-install " 30 "tries to call shutil.which('uv')." 31 )