50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
"""Single-authority composition root."""
|
|
|
|
from pathlib import Path
|
|
|
|
from rune.orchestration.composition import (
|
|
CompositionRoot,
|
|
DuplicateAuthorityError,
|
|
build_root,
|
|
)
|
|
from rune.orchestration.event_store import DurableEventStore
|
|
|
|
|
|
def test_single_registration_per_kind_passes(tmp_path: Path):
|
|
root = build_root({"events": tmp_path / "e.jsonl", "evidence": tmp_path / "ev"})
|
|
root.assert_single_authority()
|
|
inv = root.inventory()
|
|
assert len(inv["event_store"]) == 1
|
|
assert len(inv["evidence_store"]) == 1
|
|
|
|
|
|
def test_duplicate_authority_raises(tmp_path: Path):
|
|
root = CompositionRoot()
|
|
root.register("event_store", DurableEventStore(tmp_path / "a.jsonl"))
|
|
root.register("event_store", DurableEventStore(tmp_path / "b.jsonl"))
|
|
try:
|
|
root.assert_single_authority()
|
|
raise AssertionError("expected DuplicateAuthorityError")
|
|
except DuplicateAuthorityError:
|
|
pass
|
|
|
|
|
|
def test_unknown_kind_can_be_absent_without_violation():
|
|
root = CompositionRoot()
|
|
root.assert_single_authority() # no authorities registered yet
|
|
|
|
|
|
def test_register_rejects_typo_kind(tmp_path: Path):
|
|
root = CompositionRoot()
|
|
try:
|
|
root.register("event_stor", DurableEventStore(tmp_path / "x.jsonl"))
|
|
raise AssertionError("expected ValueError")
|
|
except ValueError:
|
|
pass
|
|
|
|
|
|
def test_register_accepts_declared_authority_kind(tmp_path: Path):
|
|
root = CompositionRoot()
|
|
root.register("pin_registry", object()) # declared but not yet implemented
|
|
assert "pin_registry" in root.inventory()
|