Commit 763f98d1 authored by Mickaël Desfrênes's avatar Mickaël Desfrênes
Browse files

manage failed bundle install

parent 1c218b3a
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -316,7 +316,14 @@ def _sync_bundles(root_directory: Path):
                f'maxPath="{root_directory}"',
                str(Path(bundle_dir, "install.xq")),
            ]
            subprocess.run(process_args)
            install_process = subprocess.run(process_args)
            if install_process.returncode != 0:
                rich_print(
                    _(
                        "[red]Échec de l'installation du bundle {} (code de sortie: {})[/red]"
                    ).format(bundle_name, install_process.returncode)
                )
                raise typer.Exit(code=install_process.returncode or 1)
            Path(bundle_dir, installed_file).touch()
    _ping_projects(root_directory)

+28 −1
Original line number Diff line number Diff line
import unittest
from src.climax.__main__ import MaXProjectConfig, dir_is_max
from src.climax.__main__ import MaXProjectConfig, dir_is_max, _sync_bundles
from pathlib import Path
import tempfile
import subprocess
import typer
from unittest.mock import patch


TEST_CONFIG_FILE = "tests_assets/max_config.xml"
@@ -144,6 +146,31 @@ class TestConfigFiles(unittest.TestCase):
                ).exists()
            )

    def test_sync_bundle_install_failure_does_not_mark_installed(self):
        with tempfile.TemporaryDirectory() as tmpdir:
            root_dir = Path(tmpdir).resolve()
            bundles_dir = Path(root_dir, ".max", "basex", "webapp", "max", "bundles")
            failing_bundle_dir = Path(bundles_dir, "failing-bundle")
            failing_bundle_dir.mkdir(parents=True)

            # Bundle has an install script, so _sync_bundles will attempt an install.
            Path(failing_bundle_dir, "install.xq").write_text("()", encoding="utf-8")

            config = MaXProjectConfig(Path(root_dir, "config.xml"))
            config.bundles = {"failing-bundle": {"name": "failing-bundle", "url": ""}}
            config.write()

            with (
                patch("src.climax.__main__.subprocess.run") as run_mock,
                patch("src.climax.__main__._ping_projects"),
            ):
                run_mock.return_value.returncode = 2
                with self.assertRaises(typer.Exit) as context:
                    _sync_bundles(root_dir)

            self.assertEqual(2, context.exception.exit_code)
            self.assertFalse(Path(failing_bundle_dir, ".installed").exists())


if __name__ == "__main__":
    unittest.main()