57 lines
1.9 KiB
Python
57 lines
1.9 KiB
Python
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
from aios_online_agent_checkpoint import CheckpointBinding, CheckpointStore
|
|
|
|
|
|
def _binding() -> CheckpointBinding:
|
|
return CheckpointBinding(
|
|
task_id="checkpoint-agent-runtime-test-20260818",
|
|
attempt=1,
|
|
execution_digest="a" * 64,
|
|
job_id="job-checkpoint-agent-runtime-test-20260818",
|
|
repository="aios/aios",
|
|
base_oid="b" * 40,
|
|
expected_branch_oid="b" * 40,
|
|
target_branch="agent/checkpoint-agent-runtime-test-20260818",
|
|
generation=1,
|
|
)
|
|
|
|
|
|
def test_agent_runtime_checkpoint_phase_is_durable_before_result(tmp_path: Path) -> None:
|
|
store = CheckpointStore(tmp_path / "checkpoints.sqlite3")
|
|
binding = _binding()
|
|
phases = [
|
|
"claimed",
|
|
"workspace_prepared",
|
|
"verification_passed",
|
|
"agent_runtime_done",
|
|
"result_pending",
|
|
"result_submitted",
|
|
]
|
|
|
|
rows = [
|
|
store.append(binding, phase, {"phase": phase, "task_id": binding.task_id})
|
|
for phase in phases
|
|
]
|
|
|
|
assert [row["phase"] for row in rows] == phases
|
|
assert [int(row["phase_order"]) for row in rows] == [10, 20, 30, 40, 50, 60]
|
|
latest = store.latest_for_attempt(binding.task_id, binding.attempt)
|
|
assert latest is not None
|
|
assert latest["phase"] == "result_submitted"
|
|
assert latest["payload"] == {"phase": "result_submitted", "task_id": binding.task_id}
|
|
|
|
|
|
def test_agent_runtime_checkpoint_append_is_idempotent(tmp_path: Path) -> None:
|
|
store = CheckpointStore(tmp_path / "checkpoints.sqlite3")
|
|
binding = _binding()
|
|
payload = {"phase": "agent_runtime_done", "result": {"status": "SUCCEEDED"}}
|
|
|
|
first = store.append(binding, "agent_runtime_done", payload)
|
|
replay = store.append(binding, "agent_runtime_done", payload)
|
|
|
|
assert replay["sequence"] == first["sequence"]
|
|
assert replay["payload_sha256"] == first["payload_sha256"]
|