From 38b47b326cd6e3db1d416d96080004aaab503bda Mon Sep 17 00:00:00 2001 From: huangruiteng <14976749+huangruiteng@users.noreply.github.com> Date: Fri, 25 Sep 2026 07:55:06 +0800 Subject: [PATCH] fix(release): detect installed distribution in scoped doctor Signed-off-by: huangruiteng <14976749+huangruiteng@users.noreply.github.com> --- loopx/release_candidate.py | 6 ++-- tests/test_doctor_installation_scope.py | 37 +++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/loopx/release_candidate.py b/loopx/release_candidate.py index 807a39ff99..85a6b8e3e7 100644 --- a/loopx/release_candidate.py +++ b/loopx/release_candidate.py @@ -289,7 +289,7 @@ def collect_installation_doctor(*, deep: bool) -> dict[str, Any]: from .doctor import current_script_invocation_path, python_distribution_install invocation = current_script_invocation_path() - command = resolve_command_path("loopx") or invocation + command = invocation or resolve_command_path("loopx") package_root = Path(__file__).resolve().parents[1] selected = os.environ.get("LOOPX_RELEASE_ROOT") runtime = collect_effect_runtime_readiness(deep=deep) @@ -311,7 +311,9 @@ def collect_installation_doctor(*, deep: bool) -> dict[str, Any]: invocation_path=invocation, package_root=package_root, invocation_root=Path(selected).expanduser().resolve() if selected else package_root, - distribution_root=python_distribution_install(Path(__file__).resolve()).get("root"), + distribution_root=python_distribution_install( + Path(__file__).with_name("doctor.py").resolve() + ).get("root"), ) checks.extend(candidate["checks"]) payload["release_candidate"] = candidate diff --git a/tests/test_doctor_installation_scope.py b/tests/test_doctor_installation_scope.py index f35d796dd1..92ce7b5a04 100644 --- a/tests/test_doctor_installation_scope.py +++ b/tests/test_doctor_installation_scope.py @@ -77,6 +77,43 @@ def test_installation_scope_cannot_claim_host_integration_health(): parser.parse_args(["doctor", "--installation-only", "--agent-type", "codex"]) +def test_installation_scope_uses_current_distribution_and_console_script( + monkeypatch: pytest.MonkeyPatch, tmp_path: Path +) -> None: + from loopx import release_candidate + + invocation = tmp_path / "current" / "bin" / "loopx" + other_command = tmp_path / "old" / "bin" / "loopx" + distribution_root = tmp_path / "current" / "site-packages" + observed: dict = {} + monkeypatch.setattr(doctor, "current_script_invocation_path", lambda: invocation) + monkeypatch.setattr( + "loopx.command_invocation.resolve_command_path", lambda _name: other_command + ) + + def distribution_install(module_path: Path) -> dict: + observed["module_path"] = module_path + return {"root": str(distribution_root)} + + def deep_checks(**kwargs) -> dict: + observed["deep_checks"] = kwargs + return {"checks": [{"id": "distribution_check", "required": True, "ok": True}]} + + monkeypatch.setattr(doctor, "python_distribution_install", distribution_install) + monkeypatch.setattr(release_candidate, "collect_deep_install_checks", deep_checks) + monkeypatch.setattr( + "loopx.control_plane.effect_runtime.collect_effect_runtime_readiness", + lambda *, deep: {"ready": True, "status": "ready"}, + ) + + result = release_candidate.collect_installation_doctor(deep=True) + assert result["ok"] is True + assert result["path"]["loopx"] == str(invocation) + assert observed["module_path"] == Path(doctor.__file__).resolve() + assert observed["deep_checks"]["invocation_path"] == invocation + assert observed["deep_checks"]["distribution_root"] == str(distribution_root) + + def test_runtime_projection_diagnostics_bound_one_stalled_source_and_retry( monkeypatch: pytest.MonkeyPatch, tmp_path: Path,