diff --git a/pyproject.toml b/pyproject.toml index 77ed85a..fd002d7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,10 @@ name = "idea151-aidmesh-federated-privacy" version = "0.0.1" description = "Core primitives for AidMesh: federated, privacy-preserving disaster response orchestration" requires-python = ">=3.8" -dynamic = ["readme", "license", "authors"] +readme = "README.md" + +[tool.setuptools.packages.find] +where = ["src"] [tool.setuptools] -packages = ["idea151_aidmesh_federated_privacy"] +package-dir = {"" = "src"} diff --git a/tests/test_models.py b/tests/test_models.py new file mode 100644 index 0000000..19d1866 --- /dev/null +++ b/tests/test_models.py @@ -0,0 +1,42 @@ +from __future__ import annotations + +import pytest + +from datetime import datetime + +from idea151_aidmesh_federated_privacy import models + + +def test_models_to_dict_and_immutability(): + lp = models.LocalProblem( + id="lp-1", + domain="shelter", + assets={"tents": 100}, + objectives=["max_coverage"], + constraints={"max_deploy": 50}, + ) + + sd = models.SharedSignals( + forecast={"demand": 120}, capacity_proxies={"depotA": 80}, privacy_budget=1.0, version=1 + ) + + now = datetime.utcnow() + pd = models.PlanDelta( + delta={"alloc": {"depotA": 40}}, + timestamp=now, + author="planner-1", + contract_id="c-123", + signature="sig", + ) + + al = models.AuditLog(entry="created", signer="alice", timestamp=now, contract_id="c-123", version=1) + + # to_dict should produce serializable dicts and timestamp should be ISO string + assert lp.to_dict()["id"] == "lp-1" + assert sd.to_dict()["version"] == 1 + assert isinstance(pd.to_dict()["timestamp"], str) and "T" in pd.to_dict()["timestamp"] + assert isinstance(al.to_dict()["timestamp"], str) and "T" in al.to_dict()["timestamp"] + + # dataclasses are frozen: setting an attribute should raise + with pytest.raises(Exception): + lp.id = "other"