from __future__ import annotations from pathlib import Path from repo_manager.owner_interfaces import validate_owner_interfaces def _write_interface(path: Path, *, interface_id: str = "example.port.v1") -> None: path.write_text( f"""apiVersion: helixforge.repo-manager/v1 kind: OwnerTaskInterface metadata: id: {interface_id} title: Example port source: repo: repo-manager workplan_task: RMGR-WP-0010-T04 target: repo: hub-core owner_agent: hub-core approval: dispositions: [approved, amended, rejected] record_in: target owner work record task: title: Adopt the example port priority: medium objective: Consume the published contract without copying its authority. deliverables: - Add the consumer port. acceptance: - Prove an authoritative record can be consumed. """, encoding="utf-8", ) def test_validates_and_filters_owner_consumable_interface(tmp_path: Path) -> None: _write_interface(tmp_path / "example.yaml") result = validate_owner_interfaces(tmp_path, owner="hub-core") assert result["ok"] is True assert result["interface_count"] == 1 assert result["interfaces"][0]["metadata"]["id"] == "example.port.v1" def test_valid_interface_for_another_owner_is_not_returned(tmp_path: Path) -> None: _write_interface(tmp_path / "example.yaml") result = validate_owner_interfaces(tmp_path, owner="ops-warden") assert result["ok"] is True assert result["interfaces"] == [] def test_rejects_lifecycle_status_because_interface_is_not_work_record(tmp_path: Path) -> None: path = tmp_path / "example.yaml" _write_interface(path) path.write_text(path.read_text(encoding="utf-8") + "status: wait\n", encoding="utf-8") result = validate_owner_interfaces(path) assert result["ok"] is False assert result["errors"][0]["code"] == "interface_lifecycle_forbidden" def test_rejects_duplicate_interface_ids(tmp_path: Path) -> None: _write_interface(tmp_path / "one.yaml") _write_interface(tmp_path / "two.yaml") result = validate_owner_interfaces(tmp_path) assert result["ok"] is False assert result["errors"][0]["code"] == "interface_id_duplicate"