Skip to content

The agent that grows with you

fix(plugins): provenance probes origin with the resolved git

ethernet6c0544746942
diff --git a/hermes_cli/plugins_provenance.py b/hermes_cli/plugins_provenance.py
index 385114082c0..c7d2242869a 100644
--- a/hermes_cli/plugins_provenance.py
+++ b/hermes_cli/plugins_provenance.py
@@ -59,20 +59,25 @@ def _git_origin_url(plugin_dir: Path) -> Optional[str]:
"""origin's URL from the installed .git — remote get-url on a real
repo, config-file parse as the fallback (works for partial/copy
installs where git refuses)."""
- # fast path: real git repo
- try:
- proc = subprocess.run(
- ["git", "-C", str(plugin_dir), "remote", "get-url", "origin"],
- capture_output=True,
- text=True,
- timeout=10,
- )
- if proc.returncode == 0:
- url = (proc.stdout or "").strip()
- if url:
- return url
- except (OSError, subprocess.TimeoutExpired):
- pass
+ # fast path: real git repo. Same resolver as install/update: PATH may be minimal
+ # (gateway service, Windows without Git on PATH); no git → straight to the config parse.
+ from hermes_cli.plugins_cmd import _resolve_git_executable
+
+ git = _resolve_git_executable()
+ if git is not None:
+ try:
+ proc = subprocess.run(
+ [git, "-C", str(plugin_dir), "remote", "get-url", "origin"],
+ capture_output=True,
+ text=True,
+ timeout=10,
+ )
+ if proc.returncode == 0:
+ url = (proc.stdout or "").strip()
+ if url:
+ return url
+ except (OSError, subprocess.TimeoutExpired):
+ pass
# fallback: parse .git/config directly (a .git dir with a config
# file is all the adopt path needs)
config = plugin_dir / ".git" / "config"
diff --git a/tests/hermes_cli/test_plugins_provenance.py b/tests/hermes_cli/test_plugins_provenance.py
index ac50b4145b8..f0b6ac3ea20 100644
--- a/tests/hermes_cli/test_plugins_provenance.py
+++ b/tests/hermes_cli/test_plugins_provenance.py
@@ -97,4 +97,30 @@ def test_update_url_tag_round_trips(tmp_path):
)
_fake_git_dir(tmp_path / "plugins" / "plug")
prov = plugins_provenance(tmp_path / "plugins")
- assert prov[0].saved_update_url == "https://example/feed.yml"
\ No newline at end of file
+ assert prov[0].saved_update_url == "https://example/feed.yml"
+
+def test_origin_url_uses_the_resolved_git_and_survives_no_git_at_all(tmp_path, monkeypatch):
+ """Provenance runs from the gateway service, where PATH can be minimal: the probe must use the
+ same resolved git as install/update, and with no git anywhere the .git/config parse still
+ yields the origin (never a bare ``git`` spawn that raises or picks up a stray binary)."""
+ import subprocess
+ from hermes_cli import plugins_cmd, plugins_provenance
+
+ plugin = tmp_path / "plugins" / "p"
+ plugin.mkdir(parents=True)
+ _fake_git_dir(plugin, "https://example/from-config")
+ spawned = []
+ real_run = subprocess.run
+
+ def record(argv, *a, **k):
+ spawned.append(argv[0])
+ return real_run(argv, *a, **k)
+
+ monkeypatch.setattr(subprocess, "run", record)
+ monkeypatch.setattr(plugins_cmd, "_resolve_git_executable", lambda: None)
+ assert plugins_provenance._git_origin_url(plugin) == "https://example/from-config"
+ assert spawned == []
+
+ monkeypatch.setattr(plugins_cmd, "_resolve_git_executable", lambda: "/nonexistent/resolved-git")
+ assert plugins_provenance._git_origin_url(plugin) == "https://example/from-config"
+ assert spawned == ["/nonexistent/resolved-git"]