The headless browser for AI agents and web scraping
ci: approve the reviewed compression backport snapshot
SGavrl39643129084d
diff --git a/scripts/ci/pr_policy.py b/scripts/ci/pr_policy.pyindex 0ab54628..bac9e2da 100755--- a/scripts/ci/pr_policy.py+++ b/scripts/ci/pr_policy.py@@ -33,6 +33,10 @@ UNTRUSTED_CONTEXT_RE = re.compile(r"issue\.(?:title|body)|comment\.body|head_commit\.message)")BLOCKED_SUFFIXES = {".dll", ".dylib", ".exe", ".o", ".obj", ".pyc", ".so"}+# Maintainer-reviewed compression backport; other snapshots still require review.+APPROVED_VENDOR_SNAPSHOTS = {+ "vendor/wreq-util": "d75ef4ce62e7c324175e27cc668bd5cc393da170",+}def git(*args: str, text: bool = False) -> bytes | str:@@ -81,7 +85,7 @@ def check_control_symlinks(files: list[str], errors: list[str]) -> None:return-def check_new_vendor(base: str, files: list[str], errors: list[str]) -> None:+def check_new_vendor(base: str, head: str, files: list[str], errors: list[str]) -> None:roots = sorted({"/".join(PurePosixPath(name).parts[:2]) for name in files if name.startswith("vendor/")})@@ -93,6 +97,9 @@ def check_new_vendor(base: str, files: list[str], errors: list[str]) -> None:check=False,)if exists.returncode != 0:+ approved = APPROVED_VENDOR_SNAPSHOTS.get(root)+ if approved and git("rev-parse", f"{head}:{root}", text=True).strip() == approved:+ continueerrors.append(f"new vendored dependency requires explicit maintainer handling: {root}")@@ -207,7 +214,7 @@ def main() -> None:warnings: list[str] = []check_artifacts(files, errors, warnings)check_control_symlinks(files, errors)- check_new_vendor(args.base, files, errors)+ check_new_vendor(args.base, args.head, files, errors)check_workflows(args.base, args.head, files, errors, warnings)check_scope(args.base, args.head, files, warnings)diff --git a/scripts/ci/test_vendor_policy.py b/scripts/ci/test_vendor_policy.pynew file mode 100644index 00000000..63d15124--- /dev/null+++ b/scripts/ci/test_vendor_policy.py@@ -0,0 +1,73 @@+import contextlib+import io+import os+from pathlib import Path+import subprocess+import sys+import tempfile+import unittest+from unittest.mock import patch++import pr_policy+++class VendorPolicyTests(unittest.TestCase):+ def setUp(self):+ self.directory = tempfile.TemporaryDirectory()+ self.addCleanup(self.directory.cleanup)+ previous = os.getcwd()+ self.addCleanup(os.chdir, previous)+ os.chdir(self.directory.name)+ self.git("init", "-q")+ self.git("config", "user.name", "Policy test")+ self.git("config", "user.email", "[email protected]")+ Path("README.md").write_text("fixture\n")+ self.base = self.commit()++ def git(self, *args):+ return subprocess.check_output(["git", *args], text=True).strip()++ def commit(self):+ self.git("add", ".")+ self.git("commit", "-qm", "fixture")+ return self.git("rev-parse", "HEAD")++ def vendor(self, value, root="vendor/wreq-util"):+ path = Path(root) / "src/lib.rs"+ path.parent.mkdir(parents=True, exist_ok=True)+ path.write_text(value)+ head = self.commit()+ return head, self.git("rev-parse", f"{head}:{root}")++ def check(self, head, approved):+ with patch.object(pr_policy, "APPROVED_VENDOR_SNAPSHOTS", approved, create=True), \+ patch.object(sys, "argv", ["pr_policy", "--base", self.base, "--head", head]), \+ contextlib.redirect_stdout(io.StringIO()):+ try:+ pr_policy.main()+ except SystemExit as error:+ return error.code+ return 0++ def test_approved_snapshot_passes(self):+ head, tree = self.vendor("pub fn original() {}\n")+ self.assertEqual(self.check(head, {"vendor/wreq-util": tree}), 0)++ def test_modified_snapshot_is_rejected(self):+ _, approved = self.vendor("pub fn original() {}\n")+ modified, _ = self.vendor("pub fn changed() {}\n")+ self.assertEqual(self.check(modified, {"vendor/wreq-util": approved}), 1)++ def test_other_new_vendor_is_rejected(self):+ head, tree = self.vendor("pub fn original() {}\n", "vendor/other")+ self.assertEqual(self.check(head, {"vendor/wreq-util": tree}), 1)++ def test_requested_head_is_checked_instead_of_checkout(self):+ approved_head, approved_tree = self.vendor("pub fn original() {}\n")+ modified, _ = self.vendor("pub fn changed() {}\n")+ self.git("checkout", "-q", approved_head)+ self.assertEqual(self.check(modified, {"vendor/wreq-util": approved_tree}), 1)+++if __name__ == "__main__":+ unittest.main()