"""Many meshes: attestation is the only route to kinship, and nothing crosses as truth.""" import os import sys import tempfile from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) import pytest from core import polymesh @pytest.fixture(autouse=True) def isolated(monkeypatch): monkeypatch.setattr(polymesh, "_DB_PATH", os.path.join(tempfile.mkdtemp(), "polymesh.db")) monkeypatch.setenv("SIGNALMESH_POLYMESH_KEY", "owner-key") def test_the_rules(): polymesh.demo() def test_a_peer_cannot_forge_kinship(monkeypatch): """A mesh signing its own attestation is not the owner signing it.""" forged_by_them = None monkeypatch.setenv("SIGNALMESH_POLYMESH_KEY", "not-the-owners-key") forged_by_them = polymesh.attest("evil", "https://evil.example") monkeypatch.setenv("SIGNALMESH_POLYMESH_KEY", "owner-key") assert polymesh.read_attestation(forged_by_them) is None assert polymesh.add_peer("evil", "https://evil.example", attestation=forged_by_them) == polymesh.FOREIGN def test_no_tier_can_make_this_node_act(): for tier, shared in polymesh.SHARES.items(): assert "act" not in shared and "write" not in shared, tier def test_a_neighbours_signal_never_becomes_local_truth(): token = polymesh.attest("kin-mesh", "https://kin.example") assert polymesh.add_peer("kin-mesh", "https://kin.example", attestation=token) == polymesh.KIN got = polymesh.received([{"name": "lead.1", "local": True, "trust": "self"}], "kin-mesh") assert got[0]["local"] is False, "a peer may not claim to be us" assert got[0]["untrusted"] is True and got[0]["via"] == "kin-mesh" def test_attestation_requires_the_owner_key(monkeypatch): monkeypatch.delenv("SIGNALMESH_POLYMESH_KEY", raising=False) with pytest.raises(RuntimeError, match="poly-mesh owner"): polymesh.attest("someone", "https://x.example") def test_a_clone_answers_for_itself(monkeypatch): """Host policy binds the origin's namesake, not somebody else's node.""" from core import orgs, portal root = Path(tempfile.mkdtemp()) / "orgs" monkeypatch.setattr(orgs, "ROOT", root) monkeypatch.setattr(orgs, "REGISTRY", root / "registry.db") monkeypatch.delenv("SIGNALMESH_HOME_ORG", raising=False) monkeypatch.setenv("SIGNALMESH_ORIGIN_SPACE", "acecalisto3/signalmesh") org = orgs.create("Dubai Holdings") monkeypatch.setenv("SPACE_ID", "acecalisto3/signalmesh") with orgs.scope(org): ok, why = portal.hosted("social.post") assert not ok and "Run your own node" in why monkeypatch.setenv("SPACE_ID", "dubaiholdings/signalmesh") with orgs.scope(org): assert portal.hosted("social.post")[0], "their clone is theirs to configure"