"""The Execution survives on the volume: another process, a restart, a stopped request.""" from app.engine.checkpoints import VolumeSaver from app.engine.recorder import InMemoryRecorder from tests.engine.test_engine import happy_path_turns, make_engine from tests.scoped import ScopedRuntime def engine(tmp_path, saver, runtime): return make_engine(tmp_path, runtime, checkpointer=saver, recorder=InMemoryRecorder()) async def test_a_new_saver_on_the_same_folder_resumes_a_paused_execution(tmp_path): runtime = ScopedRuntime(happy_path_turns()) first = engine(tmp_path, VolumeSaver(tmp_path / "ck"), runtime) paused = await first.start("Ingest webhooks", execution_id="e1") assert paused.status == "awaiting_user" # A second process: nothing shared with the first but the folder. second = engine(tmp_path, VolumeSaver(tmp_path / "ck"), runtime) seen = await second.interaction("e1") assert seen.prompt == paused.prompt phase = paused.prompt["approval"]["phase"] resumed = await second.resume("e1", {"approval": {"phase": phase, "decision": "approve"}}) assert resumed.prompt != paused.prompt async def test_a_pre_approved_execution_completes_on_the_volume(tmp_path): runtime = ScopedRuntime(happy_path_turns()) done = await engine(tmp_path, VolumeSaver(tmp_path / "ck"), runtime).start( "Ingest webhooks", pre_approved=True, execution_id="e2" ) assert done.status == "completed" assert set(done.state["ledger"]["phases"].values()) == {"approved"} async def test_a_request_out_of_time_stops_between_steps_and_carries_on(tmp_path): runtime = ScopedRuntime(happy_path_turns()) saver = VolumeSaver(tmp_path / "ck") built = engine(tmp_path, saver, runtime) budget = iter([1, 1, 0]) stopped = await built.start( "Ingest webhooks", pre_approved=True, execution_id="e3", time_left=lambda: next(budget, 0), ) assert stopped.status == "running" other = engine(tmp_path, VolumeSaver(tmp_path / "ck"), runtime) done = await other.carry_on("e3") assert done.status == "completed"