mirror of
https://github.com/elder-plinius/OBLITERATUS.git
synced 2026-12-05 10:34:23 +01:00
76 lines
3.5 KiB
Python
76 lines
3.5 KiB
Python
"""Control failures preserve exact refusal codes and coordinator-owned markers."""
|
|
|
|
from types import SimpleNamespace
|
|
from unittest.mock import Mock
|
|
|
|
import pytest
|
|
|
|
import obliteratus.distributed.preflight as preflight
|
|
from obliteratus.distributed.contracts import RuntimeContractError, contract_digest
|
|
from tests import test_distributed_preflight_boundaries as fixtures
|
|
from tests.test_distributed_preflight_units import _staging_config
|
|
|
|
rank_world = fixtures.rank_world
|
|
|
|
|
|
def test_collective_abort_preserves_transport_refusal(rank_world, monkeypatch):
|
|
error = RuntimeContractError("LMS_COLLECTIVE_FAILED", "transport unavailable")
|
|
monkeypatch.setattr(preflight, "gloo_all_gather_records", Mock(side_effect=error))
|
|
with pytest.raises(RuntimeContractError) as failure:
|
|
preflight._collective_aborting(rank_world.config, rank_world.launch, "a" * 64, "LMS_STAGE_TIMEOUT")
|
|
assert failure.value is error
|
|
assert not rank_world.config.evidence_path.exists()
|
|
|
|
|
|
def test_terminal_evidence_closed_failure_is_not_retried_or_reclassified(tmp_path, monkeypatch):
|
|
error = RuntimeContractError("LMS_EVIDENCE_UNAVAILABLE", "receipt unavailable")
|
|
read = Mock(side_effect=error)
|
|
monkeypatch.setattr(preflight, "read_evidence", read)
|
|
with pytest.raises(RuntimeContractError) as failure:
|
|
preflight._wait_for_evidence(tmp_path / "receipt.json", timeout_seconds=1)
|
|
assert failure.value is error
|
|
read.assert_called_once_with(tmp_path / "receipt.json")
|
|
|
|
|
|
def test_peer_staging_probe_leaves_coordinator_marker_owned(rank_world, tmp_path):
|
|
root = tmp_path / "shared"
|
|
root.mkdir()
|
|
config = _staging_config(root)
|
|
attempt = root / config.run_id
|
|
attempt.mkdir(mode=0o700)
|
|
nonce = contract_digest({"run_id": config.run_id, "rendezvous_id": config.rendezvous_id}).encode()
|
|
marker = attempt / ".shared-probe.ready"
|
|
marker.write_bytes(nonce)
|
|
assert preflight._probe_shared_staging(config, SimpleNamespace(rank=1)) == attempt
|
|
assert marker.read_bytes() == nonce
|
|
|
|
|
|
def test_missing_staging_root_is_rejected_without_creating_it(rank_world, tmp_path):
|
|
config = _staging_config(tmp_path / "missing-root")
|
|
with pytest.raises(RuntimeContractError) as failure:
|
|
preflight._probe_shared_staging(config, SimpleNamespace(rank=0))
|
|
assert failure.value.code == "LMS_STORAGE_PROFILE_MISMATCH"
|
|
assert not config.staging_path.exists()
|
|
|
|
|
|
def test_missing_source_file_preserves_os_cause_without_an_open_descriptor(tmp_path):
|
|
with pytest.raises(RuntimeContractError) as failure:
|
|
preflight._hash_file(tmp_path / "missing.json", deadline=float("inf"), max_bytes=1024)
|
|
assert failure.value.code == "LMS_SOURCE_BOUNDARY_VIOLATION"
|
|
assert isinstance(failure.value.__cause__, FileNotFoundError)
|
|
|
|
|
|
def test_expired_outer_deadline_is_not_rearmed_as_a_fresh_allowance(monkeypatch):
|
|
handler = object()
|
|
set_timer, set_handler = Mock(), Mock()
|
|
signal = SimpleNamespace(SIGALRM=14, ITIMER_REAL=0, getitimer=lambda _: (2.0, 0.0),
|
|
getsignal=lambda _: handler, signal=set_handler, setitimer=set_timer)
|
|
monkeypatch.setattr(preflight, "signal", signal)
|
|
monkeypatch.setattr(preflight, "time", SimpleNamespace(monotonic=Mock(side_effect=[10.0, 13.0])))
|
|
monkeypatch.setattr(preflight, "_ACTIVE_DEADLINE_DEPTH", 1)
|
|
with preflight._stage_deadline(5, "nested deadline"):
|
|
assert preflight._ACTIVE_DEADLINE_DEPTH == 2
|
|
assert preflight._ACTIVE_DEADLINE_DEPTH == 1
|
|
assert set_timer.call_args_list == [((0, 2.0),), ((0, 0),)]
|
|
assert set_handler.call_args.args == (14, handler)
|