#!/usr/bin/env python3 """Regression contracts for the public installer and all package entry points.""" from pathlib import Path import re import subprocess import tempfile import unittest ROOT = Path(__file__).resolve().parents[1] class GitOnlyTests(unittest.TestCase): def test_package_installers_share_local_source_owner(self): for script in ROOT.glob('stage_*/*.sh'): source = script.read_text() if re.search(r'\bapt-get\b|\bapt_noninteractive\b', source) and 'uninstall' not in script.name: self.assertTrue('offline/require-local.sh' in source or 'stage_z2m_lib.sh' in source, str(script)) def test_no_external_dependency_fallback_in_installers(self): scripts = list(ROOT.glob('*.sh')) + list(ROOT.glob('stage_*/*.sh')) for script in scripts: source = script.read_text() self.assertNotRegex(source, r'(?:https?://)(?:[^\s"\']*\.)?(?:debian.org|github.com|nodesource.com|npmjs.org)(?:[/:])', str(script)) self.assertNotRegex(source, r'\b(?:npm|pnpm)\s+(?:install|add)\b', str(script)) bootstrap = (ROOT / 'install_iomatex_edge.sh').read_text() self.assertIn('http.followRedirects=false', bootstrap) self.assertIn('/api/v1/repos/', bootstrap) self.assertNotRegex(bootstrap, r'^\s*apt-get', re.M) @unittest.skipUnless(__import__('os').geteuid() == 0, 'missing-bundle guard runs as root') def test_missing_bundle_exits_even_without_errexit(self): with tempfile.TemporaryDirectory() as d: offline = Path(d) / 'offline' offline.mkdir() helper = offline / 'require-local.sh' helper.write_text((ROOT / 'offline/require-local.sh').read_text()) result = subprocess.run(['bash', '-c', 'source "$1"; echo MUST_NOT_RUN', 'test', str(helper)], capture_output=True, text=True) self.assertNotEqual(result.returncode, 0) self.assertNotIn('MUST_NOT_RUN', result.stdout) if __name__ == '__main__': unittest.main()