"""Cancelling input withdraws its queued runtime preparation. The daemon actor remains live while its runtime is held at a receive barrier. A second input exercises the late cancellation reply crossing a new request. """ import json import unittest from harness import ROOT, Albedo, Provider, exclusive, operation_id, text from inspect_support import Inspection @exclusive class KernelAdmissionTests(unittest.TestCase): def test_cancelled_preparation_does_not_cancel_the_next_input(self) -> None: provider = Provider(lambda request: text("next input completed")) self.addCleanup(provider.close) def prepare(app: Albedo) -> None: app.daemon.env["ALBEDO_INSPECT"] = "1" with Albedo(provider, prepare=prepare) as app: session = app.session() probe = Inspection(app, ROOT / "test/e2e/albedo_runtime_stall_probe.erl") cancelled = operation_id() probe.call_json("suspend_json") try: with app.api( f"/sessions/{session}/inputs/{cancelled}", {"kind": "message", "text": "cancel before preparation"}, method="PUT", ) as response: response.read() self.assertEqual(probe.call("wait_queued", "[prepare]"), "queued") with app.api( f"/sessions/{session}/inputs/{cancelled}/cancel", {} ) as response: self.assertEqual(json.load(response)["result"], "cancelled") self.assertEqual( probe.call("wait_queued", "[cancel_submitted]"), "queued" ) app.prompt(session, "next input").close() finally: probe.call_json("resume_json") app.idle(session) with app.api(f"/sessions/{session}/inputs/{cancelled}") as response: self.assertEqual(json.load(response)["delivery"], "cancelled") history = json.dumps(app.history(session)["items"]) self.assertIn("next input completed", history) self.assertNotIn("could not start", history)