Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(cli): preserve version-control installs during update

Rudy Celeklif8bccffecb13
diff --git a/README.md b/README.md
index 9da849c1c..f63e43f9a 100644
--- a/README.md
+++ b/README.md
@@ -913,6 +913,10 @@ https://github.com/user-attachments/assets/3754a414-c3ee-464f-b1e8-78e1a74fbd30
pip install vibe-trading-ai
```
+`vibe-trading update` upgrades PyPI installs in place. Editable checkouts and
+version-control installs receive manual update guidance so their source revision
+is not silently replaced by a PyPI release.
+
Then run a first research task:
```bash
diff --git a/agent/cli/commands/update.py b/agent/cli/commands/update.py
index 184bea4a0..84c189b76 100644
--- a/agent/cli/commands/update.py
+++ b/agent/cli/commands/update.py
@@ -55,6 +55,7 @@ EXIT_FAILED = 1
KIND_WHEEL = "wheel"
KIND_EDITABLE = "editable"
KIND_CHECKOUT = "checkout"
+KIND_VCS = "vcs"
def fetch_latest_version() -> str:
@@ -80,6 +81,7 @@ def detect_install_kind() -> str:
- ``KIND_EDITABLE``: ``pip install -e .`` — either the modern marker
(``direct_url.json`` in the metadata dir with ``dir_info.editable``) or
the legacy marker (a source-tree ``*.egg-info`` dir on ``sys.path``).
+ - ``KIND_VCS``: installed directly from a Git or other VCS source.
- ``KIND_WHEEL``: anything else that resolves through importlib.metadata.
Why both markers? The metadata dir that ``distribution()`` resolves can be
@@ -103,6 +105,8 @@ def detect_install_kind() -> str:
parsed = json.loads(direct_url)
if isinstance(parsed, dict) and parsed.get("dir_info", {}).get("editable"):
return KIND_EDITABLE
+ if isinstance(parsed, dict) and isinstance(parsed.get("vcs_info"), dict):
+ return KIND_VCS
except (ValueError, AttributeError):
return KIND_WHEEL # corrupt metadata; default to the pip path
return KIND_WHEEL
@@ -160,6 +164,14 @@ def cmd_update() -> int:
"(`pip install -e .`)."
)
return EXIT_OK
+ if kind == KIND_VCS:
+ console.print(
+ f"[yellow]Version-control source install detected[/yellow] "
+ f"({CURRENT_VERSION} -> {latest} is available on PyPI).\n"
+ "A PyPI upgrade would replace your source revision with a released wheel.\n"
+ "Update or reinstall from your original version-control source instead."
+ )
+ return EXIT_OK
if kind == KIND_CHECKOUT:
console.print(
f"[yellow]Running from an uninstalled checkout[/yellow] "
diff --git a/agent/tests/test_cli_update_vcs_install.py b/agent/tests/test_cli_update_vcs_install.py
new file mode 100644
index 000000000..85f21bee8
--- /dev/null
+++ b/agent/tests/test_cli_update_vcs_install.py
@@ -0,0 +1,68 @@
+"""A Git-installed build must not be replaced with a PyPI wheel on update."""
+
+from __future__ import annotations
+
+import json
+from importlib.metadata import Distribution
+from subprocess import CompletedProcess
+
+import pytest
+
+from cli.commands import update
+
+
+def install_metadata(tmp_path, monkeypatch):
+ def install(direct_url: dict) -> None:
+ metadata = tmp_path / "vibe_trading_ai-0.1.dist-info"
+ metadata.mkdir(exist_ok=True)
+ (metadata / "METADATA").write_text("Name: vibe-trading-ai\nVersion: 0.1\n")
+ (metadata / "direct_url.json").write_text(json.dumps(direct_url))
+ monkeypatch.setattr(update, "distribution", lambda _: Distribution.at(metadata))
+
+ return install
+
+
+def test_update_preserves_git_install_provenance(install_metadata, monkeypatch, capsys):
+ install_metadata(
+ {
+ "url": "https://example.org/project.git",
+ "vcs_info": {
+ "vcs": "git",
+ "commit_id": "a" * 40,
+ "requested_revision": "feature",
+ },
+ }
+ )
+ monkeypatch.setattr(update, "fetch_latest_version", lambda: "99.0.0")
+ calls = []
+
+ def fake_run(*args, **kwargs):
+ calls.append(args)
+ return CompletedProcess(args[0], returncode=1)
+
+ monkeypatch.setattr(update.subprocess, "run", fake_run)
+ result = update.cmd_update()
+ assert calls == []
+ assert result == update.EXIT_OK
+ output = capsys.readouterr().out
+ assert "source" in output.lower()
+ assert "original" in output.lower()
+
+
+ "direct_url,kind",
+ [
+ (
+ {"url": "https://example.org/package.whl", "archive_info": {}},
+ update.KIND_WHEEL,
+ ),
+ (
+ {"url": "file:///fixture", "dir_info": {"editable": True}},
+ update.KIND_EDITABLE,
+ ),
+ ],
+)
+def test_existing_wheel_and_editable_detection(install_metadata, direct_url, kind):
+ install_metadata(direct_url)
+ assert update.detect_install_kind() == kind