ouroboros/tests/test_update_status_cache.py
Anton Razzhigaev de02b6c14d fix(updates): make managed channels conflict-safe
Add stable-by-default managed update channels with explicit QA and development feeds. Keep clean updates deterministic, invoke assisted merging only for real conflicts, and reserve hard reset for explicit recovery.

Preserve local work, Colab migration, process custody, and complete binary-aware review evidence without adding path-specific restrictions.

Co-authored-by: Ouroboros <311266734+ouroboros-agent@users.noreply.github.com>
Co-authored-by: Claudexor <noreply@claudexor.dev>
2026-08-03 20:27:54 +03:00

122 lines
4.3 KiB
Python

"""Target-bound passive managed-update cache regressions."""
import ouroboros.gateway.control as control
import supervisor.git_ops as git_ops
CURRENT = "a" * 40
LATEST = "b" * 40
def _wire(monkeypatch, *, cache_channel="stable", cache_ref="refs/ouroboros-managed/tags/v6.87.5", ancestor=False):
import ouroboros.update_channels as update_channels
monkeypatch.setattr(update_channels, "get_update_channel", lambda settings=None: "stable")
monkeypatch.setattr(git_ops, "_read_managed_repo_meta", lambda: {"managed_remote_name": "managed"})
monkeypatch.setattr(git_ops, "managed_branch_defaults", lambda: ("ouroboros", "ouroboros-stable"))
monkeypatch.setattr(git_ops, "_managed_update_target", lambda: ("managed", "main", "managed/main"))
monkeypatch.setattr(
git_ops,
"_resolve_managed_update_target",
lambda *_args: ("refs/ouroboros-managed/tags/v6.87.5", LATEST, ""),
)
monkeypatch.setattr(
git_ops,
"load_state",
lambda: {
"managed_update_cache": {
"remote": "managed",
"remote_branch": "main",
"target_ref": cache_ref,
"update_channel": cache_channel,
"available": True,
"safe_to_apply": True,
"latest_sha": LATEST,
"latest_short_sha": LATEST[:8],
"latest_message": "release",
"behind": 1,
"ahead": 0,
"checked_at": "2026-08-03T00:00:00Z",
}
},
)
def fake_git_capture(cmd):
if cmd == ["git", "rev-parse", "--abbrev-ref", "HEAD"]:
return 0, "ouroboros", ""
if cmd == ["git", "rev-parse", "HEAD"]:
return 0, CURRENT, ""
if cmd == ["git", "status", "--porcelain"]:
return 0, "", ""
if cmd[:3] == ["git", "merge-base", "--is-ancestor"]:
return (0 if ancestor else 1), "", ""
if cmd[:4] == ["git", "rev-list", "--left-right", "--count"]:
return 0, "0 1", ""
if cmd == ["git", "show", f"{LATEST}:VERSION"]:
return 0, "6.87.5", ""
raise AssertionError(cmd)
monkeypatch.setattr(git_ops, "git_capture", fake_git_capture)
monkeypatch.setattr(control, "get_version", lambda: "6.87.5")
def test_passive_status_uses_cache_only_for_same_target_identity(monkeypatch):
_wire(monkeypatch)
status = git_ops.compute_managed_update_status(fetch=False)
assert status["available"] is True
assert status["latest_sha"] == LATEST
assert status["from_cache"] is True
def test_passive_status_rejects_cache_from_previous_channel(monkeypatch):
_wire(monkeypatch, cache_channel="qa", cache_ref="managed/ouroboros-stable")
status = git_ops.compute_managed_update_status(fetch=False)
assert status["available"] is False
assert status.get("from_cache") is not True
def test_passive_status_rejects_consumed_target(monkeypatch):
_wire(monkeypatch, ancestor=True)
status = git_ops.compute_managed_update_status(fetch=False)
assert status["available"] is False
assert status.get("from_cache") is not True
def test_payload_reads_version_from_pinned_sha(monkeypatch):
monkeypatch.setattr(
git_ops,
"compute_managed_update_status",
lambda fetch=False: {"latest_sha": LATEST, "target_ref": "managed/main"},
)
seen = []
def fake_capture(cmd):
seen.append(cmd)
return 0, "6.87.5", ""
monkeypatch.setattr(git_ops, "git_capture", fake_capture)
monkeypatch.setattr(control, "get_version", lambda: "6.87.5")
payload = control._managed_update_payload(fetch=False, include_tags=False)
assert payload["latest_version"] == "6.87.5"
assert ["git", "show", f"{LATEST}:VERSION"] in seen
assert ["git", "show", "managed/main:VERSION"] not in seen
def test_failed_remote_check_is_typed_not_reported_as_current(monkeypatch):
_wire(monkeypatch)
monkeypatch.setattr(git_ops, "ensure_official_update_remote", lambda: (True, ""))
monkeypatch.setattr(git_ops, "git_fetch_bounded", lambda _remote: (124, "", "timed out"))
status = git_ops.compute_managed_update_status(fetch=True)
assert status["check_ok"] is False
assert status["available"] is False
assert any(item.startswith("fetch_error:") for item in status["warnings"])