Files
EvoScientist-Multi/tests/test_host_execution_registry.py
T
m4 d4b53bfb08
Docker / build (push) Has been cancelled
Test / pytest (ubuntu-latest, 3.12) (push) Has been cancelled
Test / pytest (windows-latest, 3.11) (push) Has been cancelled
Test / pytest (windows-latest, 3.12) (push) Has been cancelled
Lint / ruff (push) Has been cancelled
Test / pytest (ubuntu-latest, 3.11) (push) Has been cancelled
Build / build (push) Has been cancelled
test: cover stop contract, execution adapters, checkpointer race and runtime identity
2026-09-13 15:12:17 +08:00

59 lines
3.0 KiB
Python

"""Local durable identity only; no resource-exit inference."""
import importlib
import importlib.util
import json
from pathlib import Path
import os
import pytest
def budget(node):
root = Path(__file__).resolve().parents[2] / ".hermes/test-runtime/unified-execution/b04-registry"
root.mkdir(parents=True, exist_ok=True)
ledger = root / (node + ".jsonl")
used = len(ledger.read_text().splitlines()) if ledger.exists() else 0
assert used < 5, "cumulative node budget exhausted"
with ledger.open("a") as out:
out.write(json.dumps({"node": node, "attempt": used + 1, "limit": 5}) + "\n")
out.flush()
os.fsync(out.fileno())
def test_binding_survives_reopen_as_unknown(tmp_path):
name = "EvoScientist.llm.host_execution_registry"
assert importlib.util.find_spec(name) is not None, "durable host registry missing"
Registry = importlib.import_module(name).SQLiteHostRegistry
first = Registry(tmp_path / "host.sqlite", host_id="host", boot_id="boot-a")
first.bind(execution_id="actual-run", grant_id="grant", digest="digest",
thread_id="thread", turn_id="turn")
recovered = Registry(tmp_path / "host.sqlite", host_id="host", boot_id="boot-b")
evidence = recovered.inspect("actual-run")
assert evidence["status"] == "unknown"
assert evidence["boot_id"] == "boot-a"
assert evidence["resources_confirmed_exited"] is False
assert recovered.lookup_grant("grant", "digest")["execution_id"] == "actual-run"
def test_identity_conflicts_and_old_epoch_control(tmp_path):
budget("identity_conflicts_and_old_epoch_control")
from EvoScientist.llm.host_execution_registry import SQLiteHostRegistry
from EvoScientist.llm.contracts import EvoRuntimeError
registry = SQLiteHostRegistry(tmp_path / "host.sqlite", host_id="host", boot_id="a")
binding = dict(execution_id="run", grant_id="grant", digest="digest",
thread_id="thread", turn_id="turn")
registry.bind(**binding)
with pytest.raises(EvoRuntimeError, match="EXECUTION_IDENTITY_CONFLICT"):
registry.bind(**{**binding, "digest": "different"})
with pytest.raises(EvoRuntimeError, match="TURN_EXECUTION_UNKNOWN"):
registry.bind(**{**binding, "execution_id": "other", "grant_id": "other"})
assert registry.transfer_control("run", expected_epoch=1, new_epoch=2) == 2
with pytest.raises(EvoRuntimeError, match="OWNER_EPOCH_STALE"):
registry.transfer_control("run", expected_epoch=1, new_epoch=3)
with pytest.raises(EvoRuntimeError, match="OWNER_EPOCH_STALE"):
registry.require_control("run", owner_epoch=1)
registry.require_control("run", owner_epoch=2)
recovered = SQLiteHostRegistry(tmp_path / "host.sqlite", host_id="host", boot_id="b")
assert recovered.inspect("run")["owner_epoch"] == 2
assert recovered.inspect("run")["boot_id"] == "a"
assert recovered.inspect("run")["status"] == "unknown"
assert recovered.lookup_grant("grant", "digest")["execution_id"] == "run"