Skip to content
Open
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
4 changes: 3 additions & 1 deletion docs/product/release-readiness.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ names the readback and recovery command for each layer.

For a pip or pipx distribution, apply delegates to that owner. For an archive
snapshot, apply uses the public `stable` ref by default and preserves atomic
snapshot rollback. Before replacing the launcher, `loopx update --rollback
snapshot rollback. When rolling back, keep any `LOOPX_BIN_DIR` or
`LOOPX_RELEASES_DIR` override from installation. Before replacing the launcher,
`loopx update --rollback
previous` checks that the selected release can read the current authoritative
Todos for registered local File and SQLite Goals. If it cannot verify the read,
the running version and Goal state stay in place. Both the registry's configured
Expand Down
4 changes: 4 additions & 0 deletions loopx/self_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,14 @@ def _release_root_from_doctor(doctor_payload: dict[str, Any]) -> str | None:


def _user_loopx_bin(home: Path | None = None) -> Path:
if home is None and (bin_dir := os.environ.get("LOOPX_BIN_DIR")):
return Path(bin_dir) / "loopx"
return (home or Path.home()) / ".local" / "bin" / "loopx"


def _user_releases_dir(home: Path | None = None) -> Path:
if home is None and (releases_dir := os.environ.get("LOOPX_RELEASES_DIR")):
return Path(releases_dir)
return (home or Path.home()) / ".local" / "share" / "loopx" / "releases"


Expand Down
26 changes: 20 additions & 6 deletions tests/test_self_update_runtime_activation.py
Original file line number Diff line number Diff line change
Expand Up @@ -981,8 +981,9 @@ def run(command, **kwargs):

@pytest.mark.skipif(os.name == "nt", reason="POSIX snapshot rollback")
@pytest.mark.parametrize("failed_stage", [None, "compatibility", "doctor", "extensions"])
@pytest.mark.parametrize("archive_layout", ["default", "configured"])
def test_rollback_cli_preserves_selected_route_and_failure_boundaries(
tmp_path, monkeypatch, capsys, failed_stage,
tmp_path, monkeypatch, capsys, failed_stage, archive_layout,
):
from loopx.cli import main
from loopx.self_update import render_update_plan_markdown
Expand All @@ -991,16 +992,27 @@ def test_rollback_cli_preserves_selected_route_and_failure_boundaries(
runtime.mkdir()
registry = runtime / "registry.global.json"
registry.write_text(json.dumps({"goals": [], "common_runtime_root": str(runtime)}))
releases = tmp_path / "releases"
user_home = tmp_path / "user"
monkeypatch.setattr(Path, "home", lambda: user_home)
default_launcher = user_home / ".local/bin/loopx"
if archive_layout == "configured":
releases = tmp_path / "configured releases"
launcher = tmp_path / "configured bin/loopx"
monkeypatch.setenv("LOOPX_RELEASES_DIR", str(releases))
monkeypatch.setenv("LOOPX_BIN_DIR", str(launcher.parent))
default_launcher.parent.mkdir(parents=True)
default_launcher.write_text("Unrelated launcher")
else:
releases = user_home / ".local/share/loopx/releases"
launcher = default_launcher
monkeypatch.setenv("LOOPX_RELEASES_DIR", "")
monkeypatch.setenv("LOOPX_BIN_DIR", "")
current, target = releases / "current", releases / "target"
for release in (current, target):
(release / "scripts").mkdir(parents=True)
(release / "scripts/loopx").write_text("#!/bin/sh\nexit 0\n")
launcher = tmp_path / "bin/loopx"
launcher.parent.mkdir()
launcher.parent.mkdir(parents=True)
launcher.symlink_to(current / "scripts/loopx")
monkeypatch.setattr("loopx.self_update._user_loopx_bin", lambda *_: launcher)
monkeypatch.setattr("loopx.self_update._user_releases_dir", lambda *_: releases)
snapshot = doctor_payload()
snapshot["package"]["release_root"] = str(current)
planning_calls, calls = [], []
Expand Down Expand Up @@ -1053,6 +1065,8 @@ def run(command, **kwargs):
assert "cannot read current authority formats" not in rendered
expected_release = current if failed_stage in {"compatibility", "doctor"} else target
assert launcher.resolve() == expected_release / "scripts/loopx"
if archive_layout == "configured":
assert default_launcher.read_text() == "Unrelated launcher"


@pytest.mark.skipif(os.name == "nt", reason="POSIX snapshot rollback")
Expand Down
Loading