Ubuntu 패키지 시험의 MIME 설정을 격리함
- 작성자
- 코노모리 카논
- 작성 시각
- 커밋
45c67ba71ab85c37d7eac96cd53a091d5b1918d0- 부모
- ff0fad1
변경된 파일 3개
+186-104| @@ -5,12 +5,12 @@ | ||
| 5 | 5 | ```sh |
| 6 | 6 | python3 tests/ci/run_rust.py local |
| 7 | 7 | python3 -m unittest discover -s tests/release-packages -p "test_*.py" |
| 8 | 삭제: python3 tests/release-packages/ubuntu_smoke.py tests/release-packages/runs/ubuntu-release/zipelo_0.2.1_amd64.deb | |
| 8 | 추가: python3 tests/release-packages/ubuntu_smoke.py tests/work/v021-build-out/zipelo_0.2.1_amd64.deb --work-dir tests/work/ubuntu-package-smoke | |
| 9 | 9 | ``` |
| 10 | 10 | |
| 11 | 삭제: Ubuntu 실기 스모크는 이 패키지를 sudo로 설치하고 ZIP, 7z, TAR.GZ의 기본 앱을 확인합니다. 별도 Xvfb 화면에서 공백이 있는 경로의 합성 ZIP을 실제 앱으로 열어 소유 창을 캡처합니다. 종료 후 패키지를 제거하고 기존 MIME 설정을 복원합니다. 설치나 제거가 실패해도 MIME 설정 복원을 시도하고 원래 실패와 정리 실패를 함께 보고합니다. 설치된 Zipelo나 같은 경로의 기존 파일이 있으면 중단합니다. 시험 중 다른 MIME 설정 변경이 감지되면 해당 파일을 덮어쓰지 않고 나머지 파일은 복원합니다. | |
| 11 | 추가: Ubuntu 실기 스모크는 이 패키지를 sudo로 설치하되, 패키지 설치 및 제거 시 실제 사용자의 기본 앱 설정 단계는 실행하지 않습니다. 대신 tests/work 안의 격리된 HOME에서 ZIP, 7z, TAR.GZ 기본 앱 적용과 제거를 검증합니다. 별도 Xvfb 화면에서 공백이 있는 경로의 합성 ZIP을 실제 앱으로 열어 소유 창을 캡처합니다. 실제 사용자 MIME 설정 파일은 시험 전후 바이트 단위로 비교하며 변경되면 실패를 보고하고 덮어쓰지 않습니다. 설치된 Zipelo나 같은 경로의 기존 파일이 있으면 중단합니다. | |
| 12 | 12 | |
| 13 | 삭제: sudo 비대화형 권한, Xvfb, xdotool과 ImageMagick import가 필요합니다. 이 검사는 실제 시스템 패키지를 설치하고 사용자 기본 앱을 임시로 바꾸므로 실행 전에 해당 작업의 승인이 필요합니다. 출력은 runs/에 남고 Git에는 포함하지 않습니다. | |
| 13 | 추가: sudo 비대화형 권한, Xvfb, xdotool과 ImageMagick import가 필요합니다. 이 검사는 실제 시스템 패키지를 설치하고 제거하므로 해당 작업에 승인된 환경에서 실행합니다. 출력은 지정한 tests/work 폴더에 남고 Git에는 포함하지 않습니다. | |
| 14 | 14 | |
| 15 | 15 | Windows 설치와 설정 화면, 제거의 실기 검증은 이 Linux 시험에 포함되지 않습니다. release 게시와 다운로드 버튼 갱신도 수행하지 않습니다. |
| 16 | 16 |
| @@ -16,8 +16,9 @@ SPEC.loader.exec_module(SMOKE) | ||
| 16 | 16 | |
| 17 | 17 | class LifecycleTests(unittest.TestCase): |
| 18 | 18 | def setUp(self): |
| 19 | 삭제: (ROOT / "tests/release-packages/runs").mkdir(parents=True, exist_ok=True) | |
| 20 | 삭제: temporary = tempfile.TemporaryDirectory(dir=ROOT / "tests/release-packages/runs") | |
| 19 | 추가: work = Path(os.environ.get("TMPDIR", SMOKE.work_root() / "ubuntu-lifecycle")) | |
| 20 | 추가: work.mkdir(parents=True, exist_ok=True) | |
| 21 | 추가: temporary = tempfile.TemporaryDirectory(dir=work) | |
| 21 | 22 | self.addCleanup(temporary.cleanup) |
| 22 | 23 | self.directory = Path(temporary.name) |
| 23 | 24 | self.previous = self.directory / "mimeapps.list" |
| @@ -56,6 +57,11 @@ class LifecycleTests(unittest.TestCase): | ||
| 56 | 57 | subprocess.run(["sh", str(ROOT / "packaging/ubuntu/rust/postinst"), *arguments], |
| 57 | 58 | env=env, check=True) |
| 58 | 59 | self.assertEqual(len(log.read_text().splitlines()), count) |
| 60 | 추가: env["SUDO_USER"] = "root" | |
| 61 | 추가: log.write_text("") | |
| 62 | 추가: subprocess.run(["sh", str(ROOT / "packaging/ubuntu/rust/postinst"), "configure"], | |
| 63 | 추가: env=env, check=True) | |
| 64 | 추가: self.assertEqual(log.read_text(), "") | |
| 59 | 65 | |
| 60 | 66 | def test_prerm_restores_only_on_remove_for_known_user(self): |
| 61 | 67 | commands = self.directory / "bin" |
| @@ -80,6 +86,11 @@ class LifecycleTests(unittest.TestCase): | ||
| 80 | 86 | if count: |
| 81 | 87 | self.assertIn("HOME=" + str(self.directory), calls[0]) |
| 82 | 88 | self.assertTrue(calls[0].endswith("/usr/lib/zipelo/default-apps remove")) |
| 89 | 추가: env["SUDO_USER"] = "root" | |
| 90 | 추가: log.write_text("") | |
| 91 | 추가: subprocess.run(["sh", str(ROOT / "packaging/ubuntu/rust/prerm"), "remove"], | |
| 92 | 추가: env=env, check=True, capture_output=True) | |
| 93 | 추가: self.assertEqual(log.read_text(), "") | |
| 83 | 94 | env.pop("SUDO_USER") |
| 84 | 95 | log.write_text("") |
| 85 | 96 | result = subprocess.run(["sh", str(ROOT / "packaging/ubuntu/rust/prerm"), "remove"], |
| @@ -87,62 +98,101 @@ class LifecycleTests(unittest.TestCase): | ||
| 87 | 98 | self.assertEqual(log.read_text(), "") |
| 88 | 99 | self.assertIn("사용자를 확인할 수 없어", result.stdout) |
| 89 | 100 | |
| 90 | 삭제: def check_smoke(self, install_fails=False, purge_fails=False, body_fails=False): | |
| 101 | 추가: def check_smoke(self, install_fails=False, defaults_fail=False, purge_fails=False, body_fails=False): | |
| 91 | 102 | calls = [] |
| 103 | 추가: home = self.directory / "isolated-home" | |
| 104 | 추가: home.mkdir() | |
| 105 | 추가: isolated_config = home / ".config/mimeapps.list" | |
| 106 | 추가: isolated_config.parent.mkdir() | |
| 107 | 추가: isolated_config.write_bytes(b"previous-app.desktop\n") | |
| 92 | 108 | |
| 93 | 109 | def command(arguments, **options): |
| 94 | 110 | calls.append(arguments) |
| 95 | 삭제: if "-i" in arguments: | |
| 96 | 삭제: self.previous.write_bytes(b"zipelo.desktop\n") | |
| 97 | 삭제: self.created.write_bytes(b"zipelo.desktop\n") | |
| 98 | 삭제: if install_fails: | |
| 111 | 추가: if arguments[0] == "sudo": | |
| 112 | 추가: self.assertIn("SUDO_USER=root", arguments) | |
| 113 | 추가: self.assertIn("HOME=" + str(home), arguments) | |
| 114 | 추가: if "-i" in arguments and install_fails: | |
| 99 | 115 | raise subprocess.CalledProcessError(1, arguments) |
| 100 | 삭제: elif purge_fails: | |
| 101 | 삭제: raise subprocess.CalledProcessError(2, arguments) | |
| 116 | 추가: if "-P" in arguments and purge_fails: | |
| 117 | 추가: raise subprocess.CalledProcessError(2, arguments) | |
| 118 | 추가: else: | |
| 119 | 추가: self.assertEqual(arguments[0], "/usr/lib/zipelo/default-apps") | |
| 120 | 추가: self.assertEqual(options["env"]["HOME"], str(home)) | |
| 121 | 추가: self.assertEqual(options["env"]["XDG_CONFIG_HOME"], str(home / ".config")) | |
| 122 | 추가: self.assertEqual(options["env"]["XDG_DATA_HOME"], str(home / ".local/share")) | |
| 123 | 추가: self.assertEqual(options["env"]["XDG_STATE_HOME"], str(home / ".local/state")) | |
| 124 | 추가: if arguments[1] == "install": | |
| 125 | 추가: isolated_config.write_bytes(b"zipelo.desktop\n") | |
| 126 | 추가: if defaults_fail: | |
| 127 | 추가: raise subprocess.CalledProcessError(3, arguments) | |
| 128 | 추가: else: | |
| 129 | 추가: isolated_config.write_bytes(b"previous-app.desktop\n") | |
| 102 | 130 | return subprocess.CompletedProcess(arguments, 0) |
| 103 | 131 | |
| 104 | 132 | def exercise(): |
| 105 | 133 | with patch.object(SMOKE.subprocess, "run", side_effect=command): |
| 106 | 삭제: with SMOKE.installed_package(self.directory / "sample.deb"): | |
| 107 | 삭제: self.assertFalse(install_fails) | |
| 134 | 추가: with SMOKE.installed_package(self.directory / "sample.deb", home) as isolated: | |
| 135 | 추가: self.assertEqual(isolated["HOME"], str(home)) | |
| 108 | 136 | if body_fails: |
| 109 | 137 | raise RuntimeError("창 실행 실패") |
| 110 | 138 | |
| 111 | 삭제: if install_fails or purge_fails or body_fails: | |
| 112 | 삭제: with self.assertRaises(ExceptionGroup) as raised: | |
| 139 | 추가: if install_fails or defaults_fail or purge_fails or body_fails: | |
| 140 | 추가: with self.assertRaises(BaseExceptionGroup) as raised: | |
| 113 | 141 | exercise() |
| 114 | 142 | self.assertEqual(len(raised.exception.exceptions), |
| 115 | 삭제: int(install_fails) + int(purge_fails) + int(body_fails)) | |
| 143 | 추가: int(install_fails) + int(defaults_fail) + int(purge_fails) + int(body_fails)) | |
| 116 | 144 | else: |
| 117 | 145 | exercise() |
| 118 | 146 | self.assertEqual(SMOKE.configs(), self.original) |
| 119 | 삭제: self.assertEqual(len(calls), 2) | |
| 120 | 삭제: self.assertIn("-P", calls[1]) | |
| 147 | 추가: self.assertEqual(self.previous.read_bytes(), b"previous-app.desktop\n") | |
| 148 | 추가: self.assertFalse(self.created.exists()) | |
| 149 | 추가: if install_fails: | |
| 150 | 추가: self.assertEqual([arguments[-2:] for arguments in calls], | |
| 151 | 추가: [["-i", str(self.directory / "sample.deb")], ["-P", "zipelo"]]) | |
| 152 | 추가: else: | |
| 153 | 추가: self.assertEqual([arguments[-2:] for arguments in calls if arguments[0] == "sudo"], | |
| 154 | 추가: [["-i", str(self.directory / "sample.deb")], ["-P", "zipelo"]]) | |
| 155 | 추가: self.assertEqual([arguments[-1] for arguments in calls if arguments[0] != "sudo"], | |
| 156 | 추가: ["install", "remove"]) | |
| 157 | 추가: self.assertEqual(isolated_config.read_bytes(), b"previous-app.desktop\n") | |
| 121 | 158 | |
| 122 | 삭제: def test_success_restores_settings(self): | |
| 159 | 추가: def test_success_keeps_real_user_settings_unchanged(self): | |
| 123 | 160 | self.check_smoke() |
| 124 | 161 | |
| 125 | 삭제: def test_partial_install_failure_restores_settings(self): | |
| 162 | 추가: def test_partial_install_failure_keeps_real_user_settings_unchanged(self): | |
| 126 | 163 | self.check_smoke(install_fails=True) |
| 127 | 164 | |
| 128 | 삭제: def test_purge_failure_still_restores_settings(self): | |
| 165 | 추가: def test_default_app_failure_still_cleans_isolated_settings(self): | |
| 166 | 추가: self.check_smoke(defaults_fail=True) | |
| 167 | 추가: | |
| 168 | 추가: def test_purge_failure_keeps_real_user_settings_unchanged(self): | |
| 129 | 169 | self.check_smoke(purge_fails=True) |
| 130 | 170 | |
| 131 | 삭제: def test_both_failures_are_reported(self): | |
| 171 | 추가: def test_install_and_purge_failures_are_reported(self): | |
| 132 | 172 | self.check_smoke(install_fails=True, purge_fails=True) |
| 133 | 173 | |
| 134 | 삭제: def test_window_failure_restores_settings(self): | |
| 174 | 추가: def test_window_failure_keeps_real_user_settings_unchanged(self): | |
| 135 | 175 | self.check_smoke(body_fails=True) |
| 136 | 176 | |
| 137 | 삭제: def test_external_change_does_not_skip_other_restores(self): | |
| 138 | 삭제: self.previous.write_bytes(b"zipelo.desktop\n") | |
| 139 | 삭제: self.created.write_bytes(b"zipelo.desktop\n") | |
| 140 | 삭제: after = SMOKE.configs() | |
| 141 | 삭제: self.created.write_bytes(b"external-choice.desktop\n") | |
| 142 | 삭제: with self.assertRaises(ExceptionGroup): | |
| 143 | 삭제: SMOKE.restore_configs(self.original, after) | |
| 144 | 삭제: self.assertEqual(self.previous.read_bytes(), self.original[self.previous]) | |
| 145 | 삭제: self.assertEqual(self.created.read_bytes(), b"external-choice.desktop\n") | |
| 177 | 추가: def test_host_change_is_detected_without_overwrite(self): | |
| 178 | 추가: home = self.directory / "isolated-home" | |
| 179 | 추가: home.mkdir() | |
| 180 | 추가: calls = [] | |
| 181 | 추가: | |
| 182 | 추가: def command(arguments, **options): | |
| 183 | 추가: calls.append(arguments) | |
| 184 | 추가: if "-i" in arguments: | |
| 185 | 추가: self.previous.write_bytes(b"external-choice.desktop\n") | |
| 186 | 추가: return subprocess.CompletedProcess(arguments, 0) | |
| 187 | 추가: | |
| 188 | 추가: with patch.object(SMOKE.subprocess, "run", side_effect=command): | |
| 189 | 추가: with self.assertRaises(BaseExceptionGroup) as raised: | |
| 190 | 추가: with SMOKE.installed_package(self.directory / "sample.deb", home): | |
| 191 | 추가: pass | |
| 192 | 추가: self.assertTrue(any("실제 사용자 MIME 설정" in str(error) | |
| 193 | 추가: for error in raised.exception.exceptions)) | |
| 194 | 추가: self.assertEqual(self.previous.read_bytes(), b"external-choice.desktop\n") | |
| 195 | 추가: self.assertEqual(len(calls), 2) | |
| 146 | 196 | |
| 147 | 197 | |
| 148 | 198 | if __name__ == "__main__": |
| @@ -7,6 +7,7 @@ import os | ||
| 7 | 7 | from pathlib import Path |
| 8 | 8 | import select |
| 9 | 9 | import subprocess |
| 10 | 추가: import tempfile | |
| 10 | 11 | import time |
| 11 | 12 | import zipfile |
| 12 | 13 | |
| @@ -19,46 +20,70 @@ def configs(): | ||
| 19 | 20 | return {p: p.read_bytes() for directory in CONFIGS for p in directory.glob("*mimeapps.list")} |
| 20 | 21 | |
| 21 | 22 | |
| 22 | 삭제: def restore_configs(before, after): | |
| 23 | 삭제: current = configs() | |
| 24 | 삭제: failures = [] | |
| 25 | 삭제: for path in set(before) | set(after): | |
| 26 | 삭제: try: | |
| 27 | 삭제: if current.get(path) != after.get(path): | |
| 28 | 삭제: raise RuntimeError(f"다른 MIME 설정 변경이 있어 복원을 보류함: {path}") | |
| 29 | 삭제: if path in before: | |
| 30 | 삭제: path.write_bytes(before[path]) | |
| 31 | 삭제: elif path.exists(): | |
| 32 | 삭제: path.unlink() | |
| 33 | 삭제: except Exception as error: | |
| 34 | 삭제: failures.append(error) | |
| 35 | 삭제: if failures: | |
| 36 | 삭제: raise ExceptionGroup("MIME 설정 복원 실패", failures) | |
| 23 | 추가: def work_root(): | |
| 24 | 추가: common = subprocess.check_output( | |
| 25 | 추가: ["git", "rev-parse", "--path-format=absolute", "--git-common-dir"], cwd=ROOT, text=True | |
| 26 | 추가: ).strip() | |
| 27 | 추가: directory = Path(common).resolve() | |
| 28 | 추가: if directory.name != ".git": | |
| 29 | 추가: raise RuntimeError("프로젝트 Git 작업 폴더를 찾을 수 없음") | |
| 30 | 추가: return directory.parent / "tests/work" | |
| 31 | 추가: | |
| 32 | 추가: | |
| 33 | 추가: def isolated_environment(home): | |
| 34 | 추가: home = home.resolve() | |
| 35 | 추가: for directory in (home / ".config", home / ".local/share", home / ".local/state", home / ".cache"): | |
| 36 | 추가: directory.mkdir(parents=True, exist_ok=True) | |
| 37 | 추가: return { | |
| 38 | 추가: **os.environ, | |
| 39 | 추가: "HOME": str(home), | |
| 40 | 추가: "XDG_CONFIG_HOME": str(home / ".config"), | |
| 41 | 추가: "XDG_DATA_HOME": str(home / ".local/share"), | |
| 42 | 추가: "XDG_STATE_HOME": str(home / ".local/state"), | |
| 43 | 추가: "XDG_CACHE_HOME": str(home / ".cache"), | |
| 44 | 추가: "XDG_DATA_DIRS": "/usr/local/share:/usr/share", | |
| 45 | 추가: } | |
| 46 | 추가: | |
| 47 | 추가: | |
| 48 | 추가: def ensure_host_configs_unchanged(before): | |
| 37 | 49 | if configs() != before: |
| 38 | 삭제: raise RuntimeError("기존 MIME 설정 복원 실패") | |
| 50 | 추가: raise RuntimeError("실제 사용자 MIME 설정이 시험 중 변경됨") | |
| 39 | 51 | |
| 40 | 52 | |
| 41 | 53 | @contextmanager |
| 42 | 삭제: def installed_package(package): | |
| 54 | 추가: def installed_package(package, home): | |
| 43 | 55 | before = configs() |
| 44 | 삭제: after = None | |
| 56 | 추가: isolated = isolated_environment(home) | |
| 57 | 추가: package_environment = [ | |
| 58 | 추가: "sudo", "-n", "env", "SUDO_USER=root", | |
| 59 | 추가: f"HOME={isolated['HOME']}", | |
| 60 | 추가: f"XDG_CONFIG_HOME={isolated['XDG_CONFIG_HOME']}", | |
| 61 | 추가: f"XDG_DATA_HOME={isolated['XDG_DATA_HOME']}", | |
| 62 | 추가: f"XDG_STATE_HOME={isolated['XDG_STATE_HOME']}", | |
| 63 | 추가: f"XDG_CACHE_HOME={isolated['XDG_CACHE_HOME']}", | |
| 64 | 추가: ] | |
| 65 | 추가: defaults_started = False | |
| 45 | 66 | failures = [] |
| 46 | 67 | try: |
| 47 | 삭제: try: | |
| 48 | 삭제: subprocess.run(["sudo", "-n", "dpkg", "-i", str(package)], check=True) | |
| 49 | 삭제: finally: | |
| 50 | 삭제: after = configs() | |
| 51 | 삭제: yield | |
| 68 | 추가: subprocess.run([*package_environment, "dpkg", "-i", str(package)], check=True) | |
| 69 | 추가: ensure_host_configs_unchanged(before) | |
| 70 | 추가: defaults_started = True | |
| 71 | 추가: subprocess.run(["/usr/lib/zipelo/default-apps", "install"], env=isolated, check=True) | |
| 72 | 추가: yield isolated | |
| 52 | 73 | except BaseException as error: |
| 53 | 74 | failures.append(error) |
| 54 | 75 | finally: |
| 76 | 추가: if defaults_started: | |
| 77 | 추가: try: | |
| 78 | 추가: subprocess.run(["/usr/lib/zipelo/default-apps", "remove"], env=isolated, check=True) | |
| 79 | 추가: except BaseException as error: | |
| 80 | 추가: failures.append(error) | |
| 55 | 81 | try: |
| 56 | 삭제: subprocess.run(["sudo", "-n", "dpkg", "-P", "zipelo"], check=True) | |
| 82 | 추가: subprocess.run([*package_environment, "dpkg", "-P", "zipelo"], check=True) | |
| 57 | 83 | except BaseException as error: |
| 58 | 84 | failures.append(error) |
| 59 | 85 | try: |
| 60 | 삭제: if after is not None: | |
| 61 | 삭제: restore_configs(before, after) | |
| 86 | 추가: ensure_host_configs_unchanged(before) | |
| 62 | 87 | except BaseException as error: |
| 63 | 88 | failures.append(error) |
| 64 | 89 | if failures: |
| @@ -68,9 +93,13 @@ def installed_package(package): | ||
| 68 | 93 | def main(): |
| 69 | 94 | parser = argparse.ArgumentParser(description=__doc__) |
| 70 | 95 | parser.add_argument("package", type=Path) |
| 96 | 추가: parser.add_argument("--work-dir", type=Path) | |
| 71 | 97 | args = parser.parse_args() |
| 72 | 98 | package = args.package.resolve(strict=True) |
| 73 | 삭제: runs = ROOT / "tests/release-packages/runs/smoke" | |
| 99 | 추가: allowed_work_root = work_root().resolve() | |
| 100 | 추가: runs = (args.work_dir or allowed_work_root / "ubuntu-package-smoke").resolve() | |
| 101 | 추가: if not runs.is_relative_to(allowed_work_root) or runs == allowed_work_root: | |
| 102 | 추가: parser.error("작업 폴더는 프로젝트 tests/work 아래에 있어야 함") | |
| 74 | 103 | runs.mkdir(parents=True, exist_ok=False) |
| 75 | 104 | assert subprocess.run(["dpkg-query", "-W", "-f=${db:Status-Status}", "zipelo"], |
| 76 | 105 | capture_output=True).stdout != b"installed", "기존 설치를 보존해야 함" |
| @@ -78,52 +107,55 @@ def main(): | ||
| 78 | 107 | assert not Path(name).exists(), "기존 파일이 있어 설치를 중단함" |
| 79 | 108 | app = None |
| 80 | 109 | display = None |
| 81 | 삭제: with installed_package(package): | |
| 82 | 삭제: try: | |
| 83 | 삭제: for mime in MIMES: | |
| 84 | 삭제: result = subprocess.check_output(["xdg-mime", "query", "default", mime], text=True).strip() | |
| 85 | 삭제: assert result == "zipelo.desktop", f"연결 실패: {mime}" | |
| 86 | 삭제: info = json.loads(Path("/usr/lib/zipelo/BUILD-INFO.json").read_text()) | |
| 87 | 삭제: assert info["profile"] == "release" | |
| 88 | 삭제: archive = runs / "sample archive.zip" | |
| 89 | 삭제: with zipfile.ZipFile(archive, "w") as output: | |
| 90 | 삭제: output.writestr("example.txt", "Zipelo package verification") | |
| 91 | 삭제: display = subprocess.Popen( | |
| 92 | 삭제: ["Xvfb", "-displayfd", "1", "-screen", "0", "1280x900x24", "-nolisten", "tcp"], | |
| 93 | 삭제: stdout=subprocess.PIPE, stderr=subprocess.DEVNULL) | |
| 94 | 삭제: assert select.select([display.stdout], [], [], 15)[0], "Xvfb 준비 실패" | |
| 95 | 삭제: number = display.stdout.readline().decode().strip() | |
| 96 | 삭제: assert number.isdecimal() | |
| 97 | 삭제: env = {**os.environ, "DISPLAY": ":" + number, "WINIT_UNIX_BACKEND": "x11", "XDG_SESSION_TYPE": "x11"} | |
| 98 | 삭제: env.pop("WAYLAND_DISPLAY", None) | |
| 99 | 삭제: with (runs / "app.stdout").open("wb") as stdout, (runs / "app.stderr").open("wb") as stderr: | |
| 100 | 삭제: app = subprocess.Popen(["/usr/bin/zipelo", str(archive)], env=env, stdout=stdout, stderr=stderr) | |
| 101 | 삭제: deadline = time.monotonic() + 30 | |
| 102 | 삭제: while True: | |
| 103 | 삭제: assert app.poll() is None, "설치된 앱이 조기에 종료됨" | |
| 104 | 삭제: window = subprocess.run(["xdotool", "search", "--all", "--pid", str(app.pid), "--name", "Zipelo"], | |
| 105 | 삭제: env=env, capture_output=True, text=True) | |
| 106 | 삭제: if window.returncode == 0: | |
| 107 | 삭제: break | |
| 108 | 삭제: assert time.monotonic() < deadline, "앱 창 표시 시간 초과" | |
| 109 | 삭제: time.sleep(0.2) | |
| 110 | 삭제: time.sleep(3) | |
| 111 | 삭제: assert app.poll() is None | |
| 112 | 삭제: subprocess.run(["import", "-window", window.stdout.splitlines()[0], | |
| 113 | 삭제: str(runs / "installed-window.png")], env=env, check=True) | |
| 114 | 삭제: print("PASS installed package, ZIP/7z/TAR.GZ defaults and native X11 window") | |
| 115 | 삭제: finally: | |
| 116 | 삭제: for process in (app, display): | |
| 117 | 삭제: if process is not None and process.poll() is None: | |
| 118 | 삭제: process.terminate() | |
| 119 | 삭제: try: | |
| 120 | 삭제: process.wait(timeout=10) | |
| 121 | 삭제: except subprocess.TimeoutExpired: | |
| 122 | 삭제: process.kill() | |
| 123 | 삭제: process.wait() | |
| 110 | 추가: with tempfile.TemporaryDirectory(dir=runs) as temporary_home: | |
| 111 | 추가: with installed_package(package, Path(temporary_home)) as isolated: | |
| 112 | 추가: try: | |
| 113 | 추가: for mime in MIMES: | |
| 114 | 추가: result = subprocess.check_output( | |
| 115 | 추가: ["xdg-mime", "query", "default", mime], env=isolated, text=True | |
| 116 | 추가: ).strip() | |
| 117 | 추가: assert result == "zipelo.desktop", f"연결 실패: {mime}" | |
| 118 | 추가: info = json.loads(Path("/usr/lib/zipelo/BUILD-INFO.json").read_text()) | |
| 119 | 추가: assert info["profile"] == "release" | |
| 120 | 추가: archive = runs / "sample archive.zip" | |
| 121 | 추가: with zipfile.ZipFile(archive, "w") as output: | |
| 122 | 추가: output.writestr("example.txt", "Zipelo package verification") | |
| 123 | 추가: display = subprocess.Popen( | |
| 124 | 추가: ["Xvfb", "-displayfd", "1", "-screen", "0", "1280x900x24", "-nolisten", "tcp"], | |
| 125 | 추가: stdout=subprocess.PIPE, stderr=subprocess.DEVNULL) | |
| 126 | 추가: assert select.select([display.stdout], [], [], 15)[0], "Xvfb 준비 실패" | |
| 127 | 추가: number = display.stdout.readline().decode().strip() | |
| 128 | 추가: assert number.isdecimal() | |
| 129 | 추가: env = {**isolated, "DISPLAY": ":" + number, "WINIT_UNIX_BACKEND": "x11", "XDG_SESSION_TYPE": "x11"} | |
| 130 | 추가: env.pop("WAYLAND_DISPLAY", None) | |
| 131 | 추가: with (runs / "app.stdout").open("wb") as stdout, (runs / "app.stderr").open("wb") as stderr: | |
| 132 | 추가: app = subprocess.Popen(["/usr/bin/zipelo", str(archive)], env=env, stdout=stdout, stderr=stderr) | |
| 133 | 추가: deadline = time.monotonic() + 30 | |
| 134 | 추가: while True: | |
| 135 | 추가: assert app.poll() is None, "설치된 앱이 조기에 종료됨" | |
| 136 | 추가: window = subprocess.run(["xdotool", "search", "--all", "--pid", str(app.pid), "--name", "Zipelo"], | |
| 137 | 추가: env=env, capture_output=True, text=True) | |
| 138 | 추가: if window.returncode == 0: | |
| 139 | 추가: break | |
| 140 | 추가: assert time.monotonic() < deadline, "앱 창 표시 시간 초과" | |
| 141 | 추가: time.sleep(0.2) | |
| 142 | 추가: time.sleep(3) | |
| 143 | 추가: assert app.poll() is None | |
| 144 | 추가: subprocess.run(["import", "-window", window.stdout.splitlines()[0], | |
| 145 | 추가: str(runs / "installed-window.png")], env=env, check=True) | |
| 146 | 추가: print("PASS installed package, ZIP/7z/TAR.GZ defaults and native X11 window") | |
| 147 | 추가: finally: | |
| 148 | 추가: for process in (app, display): | |
| 149 | 추가: if process is not None and process.poll() is None: | |
| 150 | 추가: process.terminate() | |
| 151 | 추가: try: | |
| 152 | 추가: process.wait(timeout=10) | |
| 153 | 추가: except subprocess.TimeoutExpired: | |
| 154 | 추가: process.kill() | |
| 155 | 추가: process.wait() | |
| 124 | 156 | assert not Path("/usr/bin/zipelo").exists() |
| 125 | 157 | assert not Path("/usr/lib/zipelo").exists() |
| 126 | 삭제: print("PASS package removed and previous MIME settings restored") | |
| 158 | 추가: print("PASS package removed and host MIME settings unchanged") | |
| 127 | 159 | |
| 128 | 160 | |
| 129 | 161 | if __name__ == "__main__": |