from types import SimpleNamespace import yaml from info_tech_canon.import_reviews import reviewed_import_cycles def fixture(tmp_path): (tmp_path / "validation").mkdir() (tmp_path / "review.md").write_text("Distinct concept owners reviewed.") edges = [["a", "uses", "b"], ["b", "uses", "a"]] (tmp_path / "validation/model-import-reviews.yaml").write_text(yaml.safe_dump( {"reviews": [{"boundary_review": "review.md", "edges": edges}]})) return [SimpleNamespace(id="a", kind="model", relationships=[{"type": "uses", "target": "b"}]), SimpleNamespace(id="b", kind="model", relationships=[{"type": "uses", "target": "a"}])] def test_exact_review_preserves_reciprocal_imports(tmp_path): artifacts = fixture(tmp_path) assert len(reviewed_import_cycles(artifacts, tmp_path)) == 1 assert artifacts[0].relationships == [{"type": "uses", "target": "b"}] def test_new_internal_edge_or_type_is_not_excused(tmp_path): artifacts = fixture(tmp_path) artifacts[0].relationships.append({"type": "defines", "target": "b"}) assert reviewed_import_cycles(artifacts, tmp_path) is None def test_new_component_member_is_not_excused(tmp_path): artifacts = fixture(tmp_path) artifacts[0].relationships.append({"type": "uses", "target": "c"}) artifacts.append(SimpleNamespace(id="c", kind="model", relationships=[{"type": "uses", "target": "a"}])) assert reviewed_import_cycles(artifacts, tmp_path) is None def test_missing_rationale_is_not_excused(tmp_path): artifacts = fixture(tmp_path) (tmp_path / "review.md").unlink() assert reviewed_import_cycles(artifacts, tmp_path) is None def test_unreviewed_second_cycle_is_not_excused(tmp_path): artifacts = fixture(tmp_path) artifacts.append(SimpleNamespace(id="c", kind="model", relationships=[{"type": "uses", "target": "c"}])) assert reviewed_import_cycles(artifacts, tmp_path) is None