"""Import adapters: every imported record becomes a signed evidence op.""" from helpers import DATASETS, as_ids, op_index, verifies def _evidence_ops(node): return [op for op in node.store.all_ops() if op.get("type") == "evidence"] def test_calendar_adapter_creates_signed_evidence(phone): ids = as_ids(phone.ingest_calendar(DATASETS / "phone" / "calendar.ics")) assert len(ids) >= 2, "sample calendar should contain at least two events" idx = op_index(phone) for op_id in ids: op = idx[op_id] assert op["type"] == "evidence" assert isinstance(op["payload"], dict) and op["payload"] assert verifies(op), f"evidence op {op_id} fails signature verification" def test_notes_adapter_creates_signed_evidence(laptop): ids = as_ids(laptop.ingest_notes(DATASETS / "laptop" / "notes")) assert len(ids) >= 3, "three sample notes should yield at least three ops" idx = op_index(laptop) for op_id in ids: op = idx[op_id] assert op["type"] == "evidence" assert isinstance(op["payload"], dict) and op["payload"] assert verifies(op) def test_photos_adapter_creates_signed_evidence(phone): ids = as_ids(phone.ingest_photos(DATASETS / "phone" / "photos.json")) assert len(ids) >= 1 idx = op_index(phone) for op_id in ids: op = idx[op_id] assert op["type"] == "evidence" assert isinstance(op["payload"], dict) and op["payload"] assert verifies(op) def test_adapter_only_emits_its_own_evidence(phone): ids = as_ids(phone.ingest_calendar(DATASETS / "phone" / "calendar.ics")) evidence = _evidence_ops(phone) assert len(evidence) == len(ids) assert {op["id"] for op in evidence} == set(ids) def test_evidence_from_all_adapters_coexists(phone): cal = as_ids(phone.ingest_calendar(DATASETS / "phone" / "calendar.ics")) photos = as_ids(phone.ingest_photos(DATASETS / "phone" / "photos.json")) notes = as_ids(phone.ingest_notes(DATASETS / "laptop" / "notes")) all_ids = set(cal) | set(photos) | set(notes) assert len(all_ids) == len(cal) + len(photos) + len(notes), ( "adapters must not produce colliding op ids" ) evidence = _evidence_ops(phone) assert {op["id"] for op in evidence} == all_ids