chore(consistency): sync task status from DB [auto]
Updated by fix-consistency on 2026-09-04: - update .custodian-brief.md for rein-aharness Assistant: codex Assistant-Model: gpt-5.6-sol Assistant-Session: 01a06ba0-10aa-7ea0-b20a-4f3fac39efe9
This commit is contained in:
parent
7641fcde40
commit
f01b765668
20 changed files with 1027 additions and 165 deletions
|
|
@ -6,7 +6,13 @@ from unittest.mock import MagicMock, patch
|
|||
import time
|
||||
|
||||
from rein_aharness.approaches import ApproachResult, APPROACH_FI_RESEARCH_BRIEF
|
||||
from rein_aharness.claim_loop import process_one, poll_peek
|
||||
from rein_aharness.claim_loop import (
|
||||
_cancel_active_run,
|
||||
_set_active_run_cancel,
|
||||
process_one,
|
||||
poll_peek,
|
||||
)
|
||||
from rein_aharness.execution_cancel import ExecutionCancel, active_cancel
|
||||
from rein_aharness.glas_execution import GLAS_APPROACH, GlasExecutionError
|
||||
from rein_aharness.ops_run_client import (
|
||||
ActivityCoreOpsClient,
|
||||
|
|
@ -135,6 +141,78 @@ def test_process_one_refuses_close_after_lease_loss() -> None:
|
|||
client.fail.assert_not_called()
|
||||
|
||||
|
||||
def test_process_one_lease_loss_cancels_registered_adapter_process() -> None:
|
||||
client = MagicMock(spec=ActivityCoreOpsClient)
|
||||
client.config = OpsRunConfig(worker_id="w", lease_seconds=90)
|
||||
client.claim.return_value = [_claimed_run()]
|
||||
client.heartbeat.side_effect = OpsRunError("lease rejected", status_code=409)
|
||||
proc = MagicMock()
|
||||
proc.poll.return_value = None
|
||||
|
||||
def slow_execute(*_args, **_kwargs):
|
||||
cancel = active_cancel()
|
||||
assert cancel is not None
|
||||
cancel.register_process(proc)
|
||||
deadline = time.monotonic() + 1.0
|
||||
while not cancel.cancelled and time.monotonic() < deadline:
|
||||
time.sleep(0.005)
|
||||
cancel.check()
|
||||
|
||||
with (
|
||||
patch("rein_aharness.claim_loop._heartbeat_interval", return_value=0.01),
|
||||
patch("rein_aharness.claim_loop.execute_approach", side_effect=slow_execute),
|
||||
):
|
||||
result = process_one(client)
|
||||
|
||||
assert result.ok is False
|
||||
assert result.reason.startswith("lease lost")
|
||||
proc.kill.assert_called()
|
||||
client.complete.assert_not_called()
|
||||
client.fail.assert_not_called()
|
||||
|
||||
|
||||
def test_process_one_skips_close_after_signal_cancel() -> None:
|
||||
client = MagicMock(spec=ActivityCoreOpsClient)
|
||||
client.config = OpsRunConfig(worker_id="w", lease_seconds=90)
|
||||
client.claim.return_value = [_claimed_run()]
|
||||
ar = ApproachResult(
|
||||
ok=True,
|
||||
approach=APPROACH_FI_RESEARCH_BRIEF,
|
||||
result={"path": "briefs/x.md"},
|
||||
reason="ok",
|
||||
)
|
||||
|
||||
def execute_then_signal(*_args, **_kwargs):
|
||||
cancel = active_cancel()
|
||||
assert cancel is not None
|
||||
cancel.cancel("signal")
|
||||
return ar
|
||||
|
||||
with patch("rein_aharness.claim_loop.execute_approach", side_effect=execute_then_signal):
|
||||
result = process_one(client)
|
||||
|
||||
assert result.ok is False
|
||||
assert result.reason == "execution cancelled (signal)"
|
||||
assert result.detail == {"cancellation": {"cancelled": "true", "reason": "signal"}}
|
||||
client.complete.assert_not_called()
|
||||
client.fail.assert_not_called()
|
||||
|
||||
|
||||
def test_shutdown_signal_cancels_active_run() -> None:
|
||||
cancel = ExecutionCancel()
|
||||
proc = MagicMock()
|
||||
proc.poll.return_value = None
|
||||
cancel.register_process(proc)
|
||||
_set_active_run_cancel(cancel)
|
||||
try:
|
||||
_cancel_active_run("signal")
|
||||
finally:
|
||||
_set_active_run_cancel(None)
|
||||
|
||||
assert cancel.reason == "signal"
|
||||
proc.kill.assert_called_once()
|
||||
|
||||
|
||||
def test_process_one_records_adapter_exception_without_unbound_result() -> None:
|
||||
client = MagicMock(spec=ActivityCoreOpsClient)
|
||||
client.config = OpsRunConfig(worker_id="w", lease_seconds=90)
|
||||
|
|
@ -220,8 +298,16 @@ def test_profiled_run_uses_glas_and_completes_with_full_result() -> None:
|
|||
|
||||
assert result.ok is True
|
||||
assert result.approach == GLAS_APPROACH
|
||||
assert result.detail == {"execution_evidence": gateway_result["evidence"]}
|
||||
client.complete.assert_called_once_with(run.id, result=gateway_result)
|
||||
assert result.detail["execution_evidence"] == gateway_result["evidence"]
|
||||
transaction = result.detail["repository_transaction"]
|
||||
assert transaction["correlation_id"] == run.id
|
||||
assert transaction["baseline"]["clean"] is True
|
||||
client.complete.assert_called_once()
|
||||
complete_run_id = client.complete.call_args.args[0]
|
||||
complete_result = client.complete.call_args.kwargs["result"]
|
||||
assert complete_run_id == run.id
|
||||
assert complete_result["evidence"] == gateway_result["evidence"]
|
||||
assert complete_result["repository_transaction"] == transaction
|
||||
client.fail.assert_not_called()
|
||||
select.assert_not_called()
|
||||
execute.assert_not_called()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue