diff --git a/src/inferrsi/box/protocol.py b/src/inferrsi/box/protocol.py index 4c8b28b30..e9cf4194e 100644 --- a/src/inferrsi/box/protocol.py +++ b/src/inferrsi/box/protocol.py @@ -180,13 +180,7 @@ def receipt(command, current, code, *, phase="rejected", details=None) -> dict: } -def validate_receipt( - command: Command, - data: bytes, - patches: Mapping[str, PatchHistory | tuple[str, ...]], - known_modules: Mapping[str, tuple[str, dict]], - expected_reset: tuple[str, ...], -) -> tuple[dict, Identity]: +def validate_receipt_header(command: Command, data: bytes) -> tuple[dict, Identity]: value = decode(data) expected = command.expected baseline = receipt(command, expected, "ok") @@ -225,10 +219,21 @@ def validate_receipt( or (current.activation_id != expected.activation_id) != advances ): raise BoxError("conflict", "receipt has an invalid phase or activation transition") - if code in {"ok", "rolled_back"}: + return value, current + + +def validate_receipt( + command: Command, + data: bytes, + patches: Mapping[str, PatchHistory | tuple[str, ...]], + known_modules: Mapping[str, tuple[str, dict]], + expected_reset: tuple[str, ...], +) -> tuple[dict, Identity]: + value, current = validate_receipt_header(command, data) + if value["code"] in {"ok", "rolled_back"}: _validate_proof( command, - code, + value["code"], value["details"], patches, known_modules, @@ -242,7 +247,7 @@ def _require(verified: bool) -> None: raise BoxError("conflict", "receipt does not prove the requested result") -def _hash(value: object) -> bool: +def is_sha256(value: object) -> bool: return ( isinstance(value, str) and len(value) == 64 @@ -250,6 +255,9 @@ def _hash(value: object) -> bool: ) +_hash = is_sha256 + + def _valid_bindings(value: object) -> bool: return isinstance(value, dict) and all( isinstance(name, str) diff --git a/src/inferrsi/box/serving.py b/src/inferrsi/box/serving.py index c46029fd8..89ad0ff50 100644 --- a/src/inferrsi/box/serving.py +++ b/src/inferrsi/box/serving.py @@ -13,6 +13,7 @@ from typing import Protocol from uuid import uuid4 +from .patch import PatchSpec, install_specs from .protocol import ( MAX_MESSAGE_BYTES, MUTATIONS, @@ -24,6 +25,9 @@ encode, fields, identifier, + is_sha256, + source_hash, + validate_receipt_header, ) @@ -98,8 +102,10 @@ def __init__( "loaded_root": str(loaded_root), "loaded_revision": loaded_revision, } - self._parent_hash = parent_hash - self._candidate = {"revision": loaded_revision, "artifact_id": "sha256:" + parent_hash} + self._baseline = {"revision": loaded_revision, "artifact_id": "sha256:" + parent_hash} + self._candidate = dict(self._baseline) + self._stack: list[str] = [] + self._candidates: dict[str, dict[str, str]] = {} self._condition = Condition() self._blocked = False self._isolated = False @@ -161,50 +167,114 @@ def _wait(self, active, deadline): self._isolated = self._blocked = True raise BoxError("in_doubt", "serving admission has been isolated") + @staticmethod + def _validate_install(payload: dict) -> PatchSpec: + _, edits = install_specs(payload) + if "edits" in payload or len(edits) != 1 or edits[0].role != "worker": + raise BoxError("invalid_request", "serving install requires a single worker patch") + if edits[0].candidate_revision is None: + raise BoxError("invalid_request", "serving install requires candidate provenance") + return edits[0] + + def _fail_in_doubt(self, reason: str) -> None: + self._isolated = self._blocked = True + raise BoxError("in_doubt", reason) + def _transaction(self, wire): command = Command.parse(wire) + install_patch = None with self._condition: if self._blocked or self._stage is not None: raise BoxError("in_doubt", "cannot control an unverified serving activation") if command.expected != self.endpoint.identity: raise BoxError("stale_instance", "Box control did not bind the live activation") + if command.operation == "install": + install_patch = self._validate_install(command.payload) self._blocked = True # An engine check must witness only its own request, even on a busy frontend. self._wait(lambda: self._active, command.deadline) - result = decode(self.endpoint.handle(wire)) + try: + raw = self.endpoint.handle(wire) + except BaseException: + with self._condition: + self._isolated = self._blocked = True + raise with self._condition: - identity = Identity.parse(result.get("identity")) + try: + result, identity = validate_receipt_header(command, raw) + except BoxError as error: + self._isolated = self._blocked = True + raise BoxError("in_doubt", str(error)) from error if identity != self.endpoint.identity: - raise BoxError("in_doubt", "Box reply and worker identity disagree") - if result["phase"] in ("committed", "rolled_back"): - prior = command.expected - if ( - command.operation not in MUTATIONS - or identity.instance_id != prior.instance_id - or identity.lease_id != prior.lease_id - or identity.participant != prior.participant - or identity.generation != prior.generation + 1 - or identity.activation_id == prior.activation_id - ): - raise BoxError("in_doubt", "Box mutation did not prove the next activation") - elif result["code"] != "in_doubt" and identity != command.expected: - raise BoxError("in_doubt", "Box observation changed the worker activation") - details = result["details"] - if command.operation in MUTATIONS and result["code"] == "ok": + self._fail_in_doubt("Box reply and worker identity disagree") + code, details = result["code"], result["details"] + if code == "in_doubt": + self._fail_in_doubt("Box command outcome is in doubt") + if command.operation in MUTATIONS and code == "rolled_back": + if details.get("patch_stack") != self._stack: + self._fail_in_doubt("Box rollback did not preserve the patch stack") + elif command.operation in ("install", "uninstall") and code == "ok": + stack = details.get("patch_stack") + if not isinstance(stack, list) or not all(isinstance(item, str) for item in stack): + self._fail_in_doubt("Box mutation did not prove its patch stack") if command.operation == "install": - revision = identifier(details["candidate_revision"]) - sha256 = details["source_hashes"][details["module"]] - self._candidate = {"revision": revision, "artifact_id": "sha256:" + sha256} - elif command.operation == "uninstall" and not details["patch_stack"]: - self._candidate = { - "revision": self.loaded["loaded_revision"], - "artifact_id": "sha256:" + self._parent_hash, + sources = details.get("source_hashes") + expected_sha = source_hash(install_patch.source) + if ( + install_patch.patch_id in self._stack + or details.get("patch_id") != install_patch.patch_id + or details.get("candidate_revision") != install_patch.candidate_revision + or details.get("module") != install_patch.module + or not isinstance(sources, dict) + or not all( + isinstance(name, str) and is_sha256(digest) + for name, digest in sources.items() + ) + or sources.get(install_patch.module) != expected_sha + or stack != [*self._stack, install_patch.patch_id] + ): + self._fail_in_doubt("Box install did not prove candidate provenance") + candidate = { + "revision": install_patch.candidate_revision, + "artifact_id": "sha256:" + expected_sha, } - if ( - not self._isolated and result["code"] != "in_doubt" - and monotonic() < command.deadline - ): + self._stack = list(stack) + self._candidates[install_patch.patch_id] = candidate + self._candidate = dict(candidate) + else: + if set(command.payload) != {"patch_id"}: + self._fail_in_doubt("Box uninstall did not carry a valid patch target") + requested = command.payload["patch_id"] + if requested is None: + if not self._stack: + self._fail_in_doubt("Box uninstall succeeded on an empty patch stack") + expected_stack = self._stack[:-1] + elif isinstance(requested, str) and requested in self._stack: + expected_stack = self._stack[: self._stack.index(requested)] + else: + self._fail_in_doubt("Box uninstall did not match an installed patch") + if stack != expected_stack: + self._fail_in_doubt("Box uninstall left an unexpected patch stack") + sources = details.get("source_hashes") + if sources is not None and ( + not isinstance(sources, dict) + or not all( + isinstance(name, str) and is_sha256(digest) + for name, digest in sources.items() + ) + ): + self._fail_in_doubt("Box uninstall did not prove valid source hashes") + self._stack = list(stack) + self._candidates = {pid: self._candidates[pid] for pid in self._stack} + self._candidate = ( + dict(self._baseline) + if not self._stack + else dict(self._candidates[self._stack[-1]]) + ) + if not self._isolated and monotonic() < command.deadline: self._blocked = False + else: + self._isolated = True return result def _begin(self, message): diff --git a/tests/box/conformance/test_serving_admission.py b/tests/box/conformance/test_serving_admission.py new file mode 100644 index 000000000..18906d090 --- /dev/null +++ b/tests/box/conformance/test_serving_admission.py @@ -0,0 +1,509 @@ +"""In-process conformance tests for ServingAdmission provenance and install prevalidation.""" + +from __future__ import annotations + +import importlib +import sys +import time +from dataclasses import replace +from pathlib import Path +from uuid import uuid4 + +import pytest + +from inferrsi.box.endpoint import Endpoint +from inferrsi.box.kernel.swap import ManagedModule +from inferrsi.box.patch import CompoundPatchSpec, PatchSpec +from inferrsi.box.protocol import ( + SCHEMA_VERSION, + BoxError, + Command, + Identity, + decode, + encode, + receipt, + source_hash, +) +from inferrsi.box.serving import ServingAdmission + + +class _State: + reset_items = ("requests",) + + def snapshot(self): + return 0 + + def reset(self): + return self.reset_items + + def restore(self, snap): + del snap + + +@pytest.fixture +def serving_fixture(tmp_path: Path): + suffix = uuid4().hex[:8] + name_a = f"serving_mod_a_{suffix}" + name_b = f"serving_mod_b_{suffix}" + root = tmp_path.resolve() + (root / f"{name_a}.py").write_text("def run(x):\n return x + 1\n", encoding="utf-8") + (root / f"{name_b}.py").write_text("def helper(x):\n return x * 2\n", encoding="utf-8") + sys.path.insert(0, str(root)) + try: + mod_a = importlib.import_module(name_a) + mod_b = importlib.import_module(name_b) + mm_a = ManagedModule(root, mod_a, {"run": ()}) + mm_b = ManagedModule(root, mod_b, {"helper": ()}) + base_a = mm_a.describe()["source_hash"] + base_b = mm_b.describe()["source_hash"] + endpoint = Endpoint( + Identity("inst-1", "lease-1", "worker", 0, "act-0"), + {name_a: mm_a, name_b: mm_b}, + {"run": lambda x: mod_a.run(x)}, + _State(), + ) + admission = ServingAdmission( + endpoint, + profile="fixture", + loaded_root=root, + loaded_revision="rev-base", + parent_hash=base_a, + ) + yield { + "root": root, + "name_a": name_a, + "name_b": name_b, + "mod_a": mod_a, + "mod_b": mod_b, + "base_a": base_a, + "base_b": base_b, + "endpoint": endpoint, + "admission": admission, + } + finally: + sys.path.remove(str(root)) + sys.modules.pop(name_a, None) + sys.modules.pop(name_b, None) + + +def _control(admission: ServingAdmission, message: dict) -> dict: + return decode(admission.handle(encode({"schema_version": SCHEMA_VERSION, **message}))) + + +def _tx(admission: ServingAdmission, endpoint: Endpoint, op: str, payload: dict) -> dict: + tag = uuid4().hex[:8] + cmd = Command( + op, f"op-{op}-{tag}", f"tx-{op}-{tag}", time.monotonic() + 5.0, endpoint.identity, payload + ) + return _control(admission, {"action": "transaction", "command": decode(cmd.wire())}) + + +def test_partial_and_full_uninstall_restore_live_candidate_provenance(serving_fixture): + admission = serving_fixture["admission"] + endpoint = serving_fixture["endpoint"] + name_a = serving_fixture["name_a"] + mod_a = serving_fixture["mod_a"] + base_a = serving_fixture["base_a"] + + src1 = "def run(x):\n return x + 2\n" + src2 = "def run(x):\n return x + 3\n" + src3 = "def run(x):\n return x + 4\n" + + p1 = PatchSpec("patch-1", name_a, "inst-1", 0, base_a, ("run",), src1, "rev-base", "rev-1") + assert _tx(admission, endpoint, "install", p1.payload())["result"]["code"] == "ok" + p2 = PatchSpec( + "patch-2", name_a, "inst-1", endpoint.identity.generation, source_hash(src1), + ("run",), src2, "rev-1", "rev-2", + ) + assert _tx(admission, endpoint, "install", p2.payload())["result"]["code"] == "ok" + p3 = PatchSpec( + "patch-3", name_a, "inst-1", endpoint.identity.generation, source_hash(src2), + ("run",), src3, "rev-2", "rev-3", + ) + assert _tx(admission, endpoint, "install", p3.payload())["result"]["code"] == "ok" + stale_startup = _control(admission, {"action": "startup"})["result"] + stale_provenance = {key: value for key, value in stale_startup.items() if key != "pid"} + + unwound = _tx(admission, endpoint, "uninstall", {"patch_id": "patch-2"}) + assert unwound["result"]["code"] == "ok" + assert unwound["result"]["details"]["patch_stack"] == ["patch-1"] + assert mod_a.run(1) == 3 + + startup = _control(admission, {"action": "startup"})["result"] + assert startup["revision"] == "rev-1" + assert startup["artifact_id"] == "sha256:" + source_hash(src1) + live_provenance = {key: value for key, value in startup.items() if key != "pid"} + + with admission.request() as req: + assert req.lineage["revision"] == "rev-1" + assert req.lineage["artifact_id"] == "sha256:" + source_hash(src1) + + deadline = time.monotonic() + 5.0 + stale_begin = _control( + admission, + { + "action": "begin", + "stage": { + "stage_id": "stale-stage", + "provenance": stale_provenance, + "limit": 1, + "deadline": deadline, + }, + }, + ) + assert stale_begin["error"] == "stale_instance" + + valid_begin = _control( + admission, + { + "action": "begin", + "stage": { + "stage_id": "live-stage", + "provenance": live_provenance, + "limit": 1, + "deadline": deadline, + }, + }, + ) + assert valid_begin["result"] == {"stage_id": "live-stage"} + with admission.request("live-stage") as req: + assert req.lineage["revision"] == "rev-1" + assert req.lineage["artifact_id"] == "sha256:" + source_hash(src1) + req.complete() + finished = _control( + admission, {"action": "finish", "stage_id": "live-stage", "deadline": deadline} + ) + assert len(finished["result"]["requests"]) == 1 + + cleared = _tx(admission, endpoint, "uninstall", {"patch_id": None}) + assert cleared["result"]["code"] == "ok" + assert cleared["result"]["details"]["patch_stack"] == [] + assert mod_a.run(1) == 2 + + baseline_startup = _control(admission, {"action": "startup"})["result"] + assert baseline_startup["revision"] == "rev-base" + assert baseline_startup["artifact_id"] == "sha256:" + base_a + with admission.request() as req: + assert req.lineage["revision"] == "rev-base" + assert req.lineage["artifact_id"] == "sha256:" + base_a + + +@pytest.mark.parametrize( + "kind", + ["compound-two-modules", "compound-single-module", "revisionless", "non-worker-role"], +) +def test_unsupported_and_revisionless_installs_reject_before_mutating_or_blocking( + serving_fixture, kind +): + admission = serving_fixture["admission"] + endpoint = serving_fixture["endpoint"] + name_a = serving_fixture["name_a"] + name_b = serving_fixture["name_b"] + mod_a = serving_fixture["mod_a"] + base_a = serving_fixture["base_a"] + base_b = serving_fixture["base_b"] + src_a = "def run(x):\n return x + 10\n" + src_b = "def helper(x):\n return x * 3\n" + + if kind == "compound-two-modules": + edit_a = PatchSpec( + "patch-compound", name_a, "inst-1", 0, base_a, ("run",), src_a, "rev-base", "rev-c" + ) + edit_b = PatchSpec( + "patch-compound", name_b, "inst-1", 0, base_b, ("helper",), src_b, "rev-base", "rev-c" + ) + payload = CompoundPatchSpec("patch-compound", (edit_a, edit_b)).payload() + elif kind == "compound-single-module": + edit_a = PatchSpec( + "patch-compound-one", name_a, "inst-1", 0, base_a, ("run",), src_a, "rev-base", "rev-c" + ) + payload = CompoundPatchSpec("patch-compound-one", (edit_a,)).payload() + elif kind == "revisionless": + payload = PatchSpec("patch-norev", name_a, "inst-1", 0, base_a, ("run",), src_a).payload() + else: + payload = PatchSpec( + "patch-all", + name_a, + "inst-1", + 0, + base_a, + ("run",), + src_a, + "rev-base", + "rev-all", + role="all", + ).payload() + + before_identity = endpoint.identity + rejected = _tx(admission, endpoint, "install", payload) + assert rejected["error"] == "invalid_request" + assert endpoint.identity == before_identity + assert mod_a.run(1) == 2 + + startup = _control(admission, {"action": "startup"}) + assert "error" not in startup + assert startup["result"]["revision"] == "rev-base" + assert startup["result"]["artifact_id"] == "sha256:" + base_a + + with admission.request() as req: + assert req.lineage["revision"] == "rev-base" + + ok_patch = PatchSpec( + "patch-ok", name_a, "inst-1", 0, base_a, ("run",), src_a, "rev-base", "rev-ok" + ) + valid = _tx(admission, endpoint, "install", ok_patch.payload()) + assert valid["result"]["code"] == "ok" + assert endpoint.identity.generation == 1 + assert mod_a.run(1) == 11 + + +def test_unknown_patch_after_uninstall_isolates_admission(tmp_path: Path): + class _ForgedUninstallEndpoint: + def __init__(self): + self.identity = Identity("inst-1", "lease-1", "worker", 0, "act-0") + + def handle(self, data: bytes) -> bytes: + cmd = Command.parse(data) + self.identity = replace( + self.identity, + generation=self.identity.generation + 1, + activation_id=f"act-{self.identity.generation + 1}", + ) + return encode( + receipt( + cmd, + self.identity, + "ok", + phase="committed", + details={"patch_stack": ["unknown-patch"]}, + ) + ) + + endpoint = _ForgedUninstallEndpoint() + admission = ServingAdmission( + endpoint, + profile="fixture", + loaded_root=tmp_path, + loaded_revision="rev-base", + parent_hash="a" * 64, + ) + response = _tx(admission, endpoint, "uninstall", {"patch_id": "unknown-patch"}) + assert response["error"] == "in_doubt" + assert _control(admission, {"action": "startup"})["error"] == "in_doubt" + with pytest.raises(BoxError) as exc_info: + with admission.request(): + pass + assert exc_info.value.code == "unsafe_point" + + +@pytest.mark.parametrize( + ("op", "code", "phase", "advance_identity", "details_override", "reply_override"), + [ + pytest.param("install", "ok", "observed", False, None, None, id="install-ok-observed"), + pytest.param("install", "ok", "rolled_back", True, None, None, id="install-ok-rolled-back"), + pytest.param( + "uninstall", "ok", "rejected", False, {"patch_stack": []}, None, + id="uninstall-ok-rejected", + ), + pytest.param( + "install", "base_mismatch", "committed", True, None, None, + id="install-error-committed", + ), + pytest.param( + "install", "rolled_back", "rejected", False, None, None, + id="install-rollback-rejected", + ), + pytest.param("reset_state", "ok", "observed", False, {}, None, id="reset-ok-observed"), + pytest.param( + "install", "ok", "committed", True, {"source_hashes": {"mod_a": ""}}, None, + id="install-empty-sha256", + ), + pytest.param( + "install", "ok", "committed", True, {"source_hashes": {"mod_a": "z" * 64}}, None, + id="install-non-hex-sha256", + ), + pytest.param( + "install", "ok", "committed", True, {"patch_id": "forged-pid"}, None, + id="install-mismatched-patch-id", + ), + pytest.param( + "install", "ok", "committed", True, {"candidate_revision": "rev-evil"}, None, + id="install-mismatched-revision", + ), + pytest.param( + "install", "ok", "committed", True, {"source_hashes": {"mod_a": "b" * 64}}, None, + id="install-mismatched-source-hash", + ), + pytest.param( + "install", "ok", "committed", True, None, {"operation_id": "wrong-op-id"}, + id="install-mismatched-operation-id", + ), + pytest.param( + "source", "ok", "in_doubt", False, {"module": "mod_a"}, None, + id="source-ok-in-doubt", + ), + pytest.param( + "source", "ok", "rejected", False, {"module": "mod_a"}, None, + id="source-ok-rejected", + ), + pytest.param( + "source", "rolled_back", "rejected", False, {"module": "mod_a"}, None, + id="source-rolled-back", + ), + pytest.param( + "install", "ok", "committed", True, None, {"deadline": 1.0}, + id="install-mismatched-deadline", + ), + pytest.param( + "install", "ok", "committed", True, None, {"participants": ["other-worker"]}, + id="install-mismatched-participants", + ), + pytest.param( + "install", "ok", "committed", True, None, {"unexpected": True}, + id="install-extra-header-field", + ), + pytest.param( + "install", "rolled_back", "rolled_back", True, {"patch_stack": ["patch-1"]}, None, + id="install-rolled-back-forged-stack", + ), + pytest.param( + "uninstall-empty-payload", "ok", "committed", True, {"patch_stack": []}, None, + id="uninstall-missing-patch-id-key", + ), + ], +) +def test_inconsistent_or_forged_mutation_replies_isolate_admission( + tmp_path: Path, op, code, phase, advance_identity, details_override, reply_override +): + src = "def run(x):\n return x + 2\n" + expected_sha = source_hash(src) + base_sha = "a" * 64 + + class _StubEndpoint: + def __init__(self): + self.identity = Identity("inst-1", "lease-1", "worker", 0, "act-0") + self.mode = "forged" + + def handle(self, data: bytes) -> bytes: + cmd = Command.parse(data) + if self.mode == "commit_install": + self.identity = replace( + self.identity, + generation=self.identity.generation + 1, + activation_id=f"act-{self.identity.generation + 1}", + ) + return encode( + receipt( + cmd, + self.identity, + "ok", + phase="committed", + details={ + "patch_id": "patch-1", + "candidate_revision": "rev-1", + "module": "mod_a", + "source_hashes": {"mod_a": expected_sha}, + "patch_stack": ["patch-1"], + }, + ) + ) + if advance_identity: + self.identity = replace( + self.identity, + generation=self.identity.generation + 1, + activation_id=f"act-{self.identity.generation + 1}", + ) + details = { + "patch_id": "patch-1", + "candidate_revision": "rev-1", + "module": "mod_a", + "source_hashes": {"mod_a": expected_sha}, + "patch_stack": ["patch-1"], + } + if details_override is not None: + details.update(details_override) + body = receipt(cmd, self.identity, code, phase=phase, details=details) + if reply_override is not None: + body.update(reply_override) + return encode(body) + + endpoint = _StubEndpoint() + admission = ServingAdmission( + endpoint, + profile="fixture", + loaded_root=tmp_path, + loaded_revision="rev-base", + parent_hash=base_sha, + ) + if op in ("uninstall", "uninstall-empty-payload"): + endpoint.mode = "commit_install" + seed = PatchSpec( + "patch-1", "mod_a", "inst-1", 0, base_sha, ("run",), src, "rev-base", "rev-1" + ) + assert _tx(admission, endpoint, "install", seed.payload())["result"]["code"] == "ok" + endpoint.mode = "forged" + payload = {"patch_id": "patch-1"} if op == "uninstall" else {} + op = "uninstall" + elif op == "install": + payload = PatchSpec( + "patch-1", "mod_a", "inst-1", 0, base_sha, ("run",), src, "rev-base", "rev-1" + ).payload() + elif op == "source": + payload = {"module": "mod_a"} + else: + payload = {} + + response = _tx(admission, endpoint, op, payload) + assert response["error"] == "in_doubt" + assert _control(admission, {"action": "startup"})["error"] == "in_doubt" + with pytest.raises(BoxError) as exc_info: + with admission.request(): + pass + assert exc_info.value.code == "unsafe_point" + + +def test_rolled_back_mutation_with_fresh_activation_keeps_admission_open(tmp_path: Path): + base_sha = "a" * 64 + src = "def run(x):\n return x + 2\n" + + class _RollbackEndpoint: + def __init__(self): + self.identity = Identity("inst-1", "lease-1", "worker", 0, "act-0") + + def handle(self, data: bytes) -> bytes: + cmd = Command.parse(data) + self.identity = replace( + self.identity, + generation=self.identity.generation + 1, + activation_id=f"act-{self.identity.generation + 1}", + ) + return encode( + receipt( + cmd, + self.identity, + "rolled_back", + phase="rolled_back", + details={"patch_stack": [], "reason": "reset failed"}, + ) + ) + + endpoint = _RollbackEndpoint() + admission = ServingAdmission( + endpoint, + profile="fixture", + loaded_root=tmp_path, + loaded_revision="rev-base", + parent_hash=base_sha, + ) + patch = PatchSpec( + "patch-1", "mod_a", "inst-1", 0, base_sha, ("run",), src, "rev-base", "rev-1" + ) + response = _tx(admission, endpoint, "install", patch.payload()) + assert response["result"]["code"] == "rolled_back" + assert response["result"]["phase"] == "rolled_back" + startup = _control(admission, {"action": "startup"})["result"] + assert startup["revision"] == "rev-base" + assert startup["artifact_id"] == "sha256:" + base_sha + assert startup["identity"]["generation"] == 1 + with admission.request() as req: + assert req.lineage["revision"] == "rev-base" diff --git a/tests/box/repos/test_ascend_managed_serving.py b/tests/box/repos/test_ascend_managed_serving.py index 2537b942c..affb70bba 100644 --- a/tests/box/repos/test_ascend_managed_serving.py +++ b/tests/box/repos/test_ascend_managed_serving.py @@ -35,7 +35,7 @@ async def collective_rpc(self, method, *, args, timeout): data, reset = args assert reset is False command = Command.parse(data) - return [encode(receipt(command, command.expected, "ok", details={ + return [encode(receipt(command, command.expected, "ok", phase="observed", details={ "module": RUNNER_MODULE, "source_hash": self.parent_hash, "patch_stack": [], "registered": True, }))]