update
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"""Tests for PackageService."""
|
||||
|
||||
import io
|
||||
import subprocess
|
||||
import tarfile
|
||||
import urllib.error
|
||||
from pathlib import Path
|
||||
@@ -16,6 +17,7 @@ from flow.core.runtime import SystemRuntime
|
||||
from flow.core import paths
|
||||
from flow.domain.packages.models import InstalledPackage, InstalledState, PackageDef
|
||||
from flow.app.packages import PackageService
|
||||
from tests.fakes import FakeRunner
|
||||
|
||||
|
||||
def _make_ctx(tmp_path, manifest=None):
|
||||
@@ -134,6 +136,49 @@ class TestPackageService:
|
||||
assert (home / ".local" / "share" / "nvim" / "runtime.txt").exists()
|
||||
assert (home / ".local" / "share" / "man" / "man1" / "nvim.1").exists()
|
||||
|
||||
def test_install_does_not_write_state_when_package_manager_install_fails(
|
||||
self, tmp_path, monkeypatch,
|
||||
):
|
||||
state_path = tmp_path / "installed.json"
|
||||
monkeypatch.setattr(paths, "INSTALLED_STATE", state_path)
|
||||
monkeypatch.setattr("flow.app.packages.detect_package_manager", lambda: "apt")
|
||||
|
||||
class FailingInstallRunner(FakeRunner):
|
||||
def run(
|
||||
self, argv, *, cwd=None, env=None, capture_output=True,
|
||||
check=False, timeout=None,
|
||||
):
|
||||
parts = list(argv)
|
||||
self.calls.append(parts)
|
||||
self.timeouts.append(timeout)
|
||||
if parts[:3] == ["sudo", "apt-get", "install"]:
|
||||
return subprocess.CompletedProcess(
|
||||
parts, 42, stdout="", stderr="install failed"
|
||||
)
|
||||
return subprocess.CompletedProcess(parts, 0, stdout="", stderr="")
|
||||
|
||||
rt = SystemRuntime()
|
||||
rt.runner = FailingInstallRunner()
|
||||
ctx = FlowContext(
|
||||
config=AppConfig(),
|
||||
manifest={},
|
||||
platform=PlatformInfo(),
|
||||
console=Console(color=False),
|
||||
runtime=rt,
|
||||
)
|
||||
svc = PackageService(ctx)
|
||||
pkg = PackageDef(
|
||||
name="fd", type="pkg", sources={},
|
||||
source=None, version=None, asset_pattern=None,
|
||||
platform_map={}, extract_dir=None, install={},
|
||||
post_install=None,
|
||||
)
|
||||
|
||||
with pytest.raises(FlowError, match="install failed"):
|
||||
svc.install([pkg])
|
||||
|
||||
assert not state_path.exists()
|
||||
|
||||
def test_post_install_with_sudo_runs_unchecked(self, tmp_path, monkeypatch):
|
||||
"""No allow_sudo gate -- post-install scripts run as written."""
|
||||
ctx = _make_ctx(tmp_path)
|
||||
|
||||
Reference in New Issue
Block a user