diff --git a/emrg/server/git_utils.py b/emrg/server/git_utils.py index 3b2b990..012aec1 100644 --- a/emrg/server/git_utils.py +++ b/emrg/server/git_utils.py @@ -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" ) diff --git a/tests/test_git_utils.py b/tests/test_git_utils.py index 994f362..51c96c7 100644 --- a/tests/test_git_utils.py +++ b/tests/test_git_utils.py @@ -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"