Files
aios/tests/baseline_v1_1/test_claim_heartbeat.py
T
AIOS Governed Continuation 89ed795e33 test(governance): S4 real-run fixes for V2R2C3 task_plane suite
After the S2 import-compatibility fix achieved clean collection (1857/0), the
real test run exposed three further defects in the V2R2C3 task_plane suite.
Fix the tests to match the actual product contract/layout (no product runtime
code touched):

- tests/baseline_v1_1/test_claim_heartbeat.py: mock.patch target
  task_plane.store._now -> app.task_plane.store._now (match import root so the
  clock mock actually applies)
- tests/task_plane/test_terminal_proof_importer.py: fixture built bare
  conditions [{"key":"C01"}] that the intended acceptance contract rejects;
  supply purpose/required_evidence matching the delegation intent, aligning with
  mission.py _acceptance_condition
- tests/task_plane/test_autonomous_next_child.py: test_live_binding_file_matches
  is a deployment-consistency integration check requiring the
  s3/next-action-coordinator-v1 overlay (live-mission-children.json is a live
  observation snapshot, not committed source). Auto-skip when the overlay is
  absent so the clean-checkout gate stays honest (no fabricated data).

Combined task_plane + baseline_v1_1 run: 592 passed, 1 skipped (documented
deployment-integration skip), 14 subtests passed.
2026-09-18 14:15:37 +08:00

74 lines
2.3 KiB
Python

from __future__ import annotations
from unittest import mock
import pytest
from app.task_plane.api import TaskPlaneService
from app.task_plane.errors import ConflictError, LockedError
from app.task_plane.policy import ALL_ACTION_CAPABILITIES, PolicyEngine
from app.task_plane.store import TaskPlaneStore
IDENTITY = "spiffe://aios/agent/heartbeat"
WORKER_ID = "heartbeat-worker"
def claimed_task():
store = TaskPlaneStore(":memory:")
service = TaskPlaneService(
store,
policy=PolicyEngine(
execution_enabled=True,
identity_capabilities={"*": set(ALL_ACTION_CAPABILITIES)},
),
)
service.register_worker(
{
"worker_id": WORKER_ID,
"worker_type": "test",
"identity": IDENTITY,
"capabilities": ["code.read"],
"trust_zone": "test",
"max_concurrency": 1,
"heartbeat_interval_seconds": 15,
"supported_protocols": ["aios-task-v1"],
}
)
task = service.create_task(
{"task_id": "task-heartbeat", "required_capabilities": ["code.read"]}
)
claim = service.claim(
task["task_id"],
{
"worker_id": WORKER_ID,
"actor_identity": IDENTITY,
"lease_seconds": 30,
},
)
return store, task, claim
def test_cancelled_task_cannot_renew_a_still_active_claim():
store, task, claim = claimed_task()
original_lease = store.get_claim(claim["claim_id"]).lease_until
current = store.get_task(task["task_id"])
store.cancel_task_with_event(task["task_id"], current.revision, "owner cancelled")
with pytest.raises(ConflictError, match="task is terminal"):
store.heartbeat_claim(task["task_id"], claim["claim_id"], 60)
assert store.get_claim(claim["claim_id"]).lease_until == original_lease
assert store.get_task(task["task_id"]).status == "CANCELLED"
def test_lease_at_current_time_is_expired_and_cannot_be_renewed():
store, task, claim = claimed_task()
boundary = store.get_claim(claim["claim_id"]).lease_until
with mock.patch("app.task_plane.store._now", return_value=boundary):
with pytest.raises(LockedError, match="lease expired"):
store.heartbeat_claim(task["task_id"], claim["claim_id"], 30)
assert store.get_claim(claim["claim_id"]).lease_until == boundary