Personal AI, On Personal Devices
Python
fix(cli): preserve extras during self-update (#718)
Elliot Slusky7959285ad8c1
diff --git a/src/openjarvis/cli/_install_detect.py b/src/openjarvis/cli/_install_detect.pyindex 91609e66..716a777a 100644--- a/src/openjarvis/cli/_install_detect.py+++ b/src/openjarvis/cli/_install_detect.py@@ -11,7 +11,9 @@ Three install paths are supported today:- **Editable git checkout** (``uv sync`` / ``pip install -e .`` from acloned repo). The package's ``__file__`` is inside a working treewith a ``.git`` directory at the repo root. Upgrade with- ``git pull && uv sync`` from the checkout.+ ``git pull && uv sync --inexact`` from the checkout. ``--inexact`` is+ important here: a bare ``uv sync`` removes packages installed by extras or+ dependency groups that are not part of the base project.We detect by inspecting ``openjarvis.__file__``. If we can't tell withconfidence we fall back to the PyPI command — that's the most common@@ -68,7 +70,7 @@ def detect_install() -> InstallInfo:if (candidate / ".git").exists() and (candidate / "pyproject.toml").exists():return InstallInfo(kind="editable-git",- upgrade_command=f"cd {candidate} && git pull && uv sync",+ upgrade_command=(f"cd {candidate} && git pull && uv sync --inexact"),repo_root=candidate,)if candidate.parent == candidate:diff --git a/src/openjarvis/cli/self_update_cmd.py b/src/openjarvis/cli/self_update_cmd.pyindex a0661a3b..3004b744 100644--- a/src/openjarvis/cli/self_update_cmd.py+++ b/src/openjarvis/cli/self_update_cmd.py@@ -4,7 +4,9 @@ Runs the right upgrade command for how the user installed OpenJarvis:- PyPI installs get ``pip install --upgrade openjarvis``.- uv-tool installs get ``uv tool upgrade openjarvis``.-- Editable git checkouts get ``git pull && uv sync`` in the checkout.+- Editable git checkouts get ``git pull && uv sync --inexact`` in the checkout.+ The inexact sync preserves packages previously installed through extras and+ dependency groups.The detection logic is shared with the post-command "new versionavailable" hint in ``_version_check.py`` so both surfaces stay in sync.diff --git a/tests/cli/test_install_detect.py b/tests/cli/test_install_detect.pyindex 60f72d39..6034bb50 100644--- a/tests/cli/test_install_detect.py+++ b/tests/cli/test_install_detect.py@@ -35,7 +35,7 @@ def test_editable_git_install_detected(tmp_path, monkeypatch):info = detect_install()assert info.kind == "editable-git"assert "git pull" in info.upgrade_command- assert "uv sync" in info.upgrade_command+ assert info.upgrade_command.endswith("uv sync --inexact")assert info.repo_root == repodiff --git a/tests/cli/test_self_update.py b/tests/cli/test_self_update.pyindex 89d4aa94..b9d8df62 100644--- a/tests/cli/test_self_update.py+++ b/tests/cli/test_self_update.py@@ -21,7 +21,7 @@ def _mock_info(kind: str = "pypi") -> InstallInfo:upgrade_command={"pypi": "pip install --upgrade openjarvis","uv-tool": "uv tool upgrade openjarvis",- "editable-git": "cd /tmp/repo && git pull && uv sync",+ "editable-git": "cd /tmp/repo && git pull && uv sync --inexact","unknown": "pip install --upgrade openjarvis",}[kind],)@@ -90,6 +90,26 @@ def test_editable_git_uses_shell_true():assert kwargs.get("shell") is True+def test_editable_git_preserves_extra_dependencies():+ """The update sync must not remove packages from prior extras/groups."""+ mock_proc = MagicMock(returncode=0)+ with (+ patch(+ "openjarvis.cli.self_update_cmd.detect_install",+ return_value=_mock_info("editable-git"),+ ),+ patch(+ "openjarvis.cli.self_update_cmd.subprocess.run",+ return_value=mock_proc,+ ) as mock_run,+ ):+ result = CliRunner().invoke(self_update, ["-y"])++ assert result.exit_code == 0+ assert "uv sync --inexact" in result.output+ assert "uv sync --inexact" in mock_run.call_args.args[0]++def test_failed_upgrade_propagates_exit_code():mock_proc = MagicMock(returncode=3)with (