Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions emrg/server/git_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,17 @@ def _cached_tool_path(tool: str) -> str | None:


def _cache_tool_paths(git: str, gh: str) -> None:
"""Persist resolved tool paths so later lookups are O(1)."""
"""Persist resolved tool paths so later lookups are O(1).

Also persists the EMRG repo URL (``repo``) so the evolution workspace
self-heal (rant 2026-08-06T20:42:05) can clone on demand without
hardcoding — packaged installs have no git remote to detect.
"""
try:
data = {}
if INSTALL_INFO.exists():
data = json.loads(INSTALL_INFO.read_text(encoding="utf-8"))
data.update({"git_path": git, "gh_path": gh})
data.update({"git_path": git, "gh_path": gh, "repo": "https://github.com/argszero/emrg.git"})
INSTALL_INFO.write_text(
json.dumps(data, ensure_ascii=False, indent=2), encoding="utf-8"
)
Expand Down
38 changes: 38 additions & 0 deletions tests/test_git_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,41 @@ def test_detect_nonexistent_dir():
"""Returns empty string for a directory that doesn't exist."""
result = _detect_git_remote("/nonexistent/path/xyz/test")
assert result == ""


# ── _cache_tool_paths (repo field, rant 2026-08-06T20:42:05) ──────


def test_cache_tool_paths_writes_repo_field(tmp_path, monkeypatch):
"""_cache_tool_paths persists git/gh paths AND the EMRG repo URL."""
from emrg.server import git_utils as mod
import json as _json

info = tmp_path / "install-info.json"
monkeypatch.setattr(mod, "INSTALL_INFO", info)

mod._cache_tool_paths("/usr/bin/git", "/usr/bin/gh")

data = _json.loads(info.read_text(encoding="utf-8"))
assert data["git_path"] == "/usr/bin/git"
assert data["gh_path"] == "/usr/bin/gh"
assert data["repo"] == "https://github.com/argszero/emrg.git"


def test_cache_tool_paths_preserves_existing_fields(tmp_path, monkeypatch):
"""Existing fields in install-info.json are preserved on rewrite."""
from emrg.server import git_utils as mod
import json as _json

info = tmp_path / "install-info.json"
info.write_text(
_json.dumps({"git_path": "/old/git", "custom": 1}), encoding="utf-8"
)
monkeypatch.setattr(mod, "INSTALL_INFO", info)

mod._cache_tool_paths("/usr/bin/git", "/usr/bin/gh")

data = _json.loads(info.read_text(encoding="utf-8"))
assert data["git_path"] == "/usr/bin/git"
assert data["custom"] == 1 # preserved
assert data["repo"] == "https://github.com/argszero/emrg.git"
Loading