from __future__ import annotations import importlib.util import sys from pathlib import Path import yaml PROJECT_ROOT = Path(__file__).parent.parent _spec = importlib.util.spec_from_file_location( "sync_branch_protection_test", PROJECT_ROOT / "scripts" / "sync_branch_protection.py", ) _mod = importlib.util.module_from_spec(_spec) sys.modules["sync_branch_protection_test"] = _mod _spec.loader.exec_module(_mod) build_branch_protection_payload = _mod.build_branch_protection_payload def test_build_branch_protection_payload_enables_rebase_before_merge(): payload = build_branch_protection_payload( "main", { "required_approvals": 1, "dismiss_stale_approvals": True, "require_ci_to_merge": False, "block_deletions": True, "block_force_push": True, "block_on_outdated_branch": True, }, ) assert payload["branch_name"] == "main" assert payload["rule_name"] == "main" assert payload["block_on_outdated_branch"] is True assert payload["required_approvals"] == 1 assert payload["enable_status_check"] is False def test_the_nexus_branch_protection_config_requires_up_to_date_branch(): config = yaml.safe_load((PROJECT_ROOT / ".gitea" / "branch-protection" / "the-nexus.yml").read_text()) rules = config["rules"] assert rules["block_on_outdated_branch"] is True