diff --git a/scripts/test-changed-scope-coverage.py b/scripts/test-changed-scope-coverage.py index d7fef7e8..36534963 100644 --- a/scripts/test-changed-scope-coverage.py +++ b/scripts/test-changed-scope-coverage.py @@ -10,9 +10,9 @@ import unittest from pathlib import Path ROOT = Path(__file__).resolve().parents[1] -# Reviewed snapshots from frozen infrastructure commit ac070fe2fa8bf0db9aa4f5fe627736c465e6e3e1. -EXISTING_JOBS_SHA256 = "4072554cb17e5afc49aba44a1ecbb5b71fa2d0bbf417512a432e3d519f16496b" -COVERAGE_JOB_SHA256 = "131cd1dc20e77f509137bf5db596466405899d6ed06c702869c46d72b79f38ea" +# Reviewed snapshots from frozen infrastructure commit ba60abfa659da4d418e20e1d5363e468845607e2. +EXISTING_JOBS_SHA256 = "c61b2c03df92cb4027e6d1f666b9ff6f370e9a783ae44662674864db006b7b7f" +COVERAGE_JOB_SHA256 = "22081e16838b5b3d403db38d22753792bcf4d507ae363f7ae9e2c2a0e14f03c5" PUSH_PULL_SHA256 = "cefb2858cd9b21076e171fa764dbf2df1472b911cc0743caa6fac7d09a216c89" SPEC = importlib.util.spec_from_file_location("changed_scope", ROOT / "scripts/check-changed-scope-coverage.py") COVERAGE = importlib.util.module_from_spec(SPEC) @@ -150,6 +150,7 @@ pub fn with_test_only_block() { self._assert_workflow_contract(current, original) def _assert_workflow_contract(self, current: str, original: str) -> None: + self._assert_checkout_contract(current) job_names = ("verify", "keyless-cuda", "hosted-cuda-package", "linux-static-cli", "linux-cli-container", "release-cli") self.assertEqual(_digest("".join(_job_block(current, name) for name in job_names)), @@ -172,6 +173,39 @@ pub fn with_test_only_block() { self.assertNotIn("actions/upload-artifact", job) self.assertNotIn("download-artifact", job) + def _assert_checkout_contract(self, current: str) -> None: + expected = " - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262\n" + names = ("verify", "changed-scope-coverage", "keyless-cuda", "hosted-cuda-package", + "linux-static-cli", "linux-cli-container", "release-cli") + # This explicit allowlist is independent of both the subject and snapshot hashes. + self.assertEqual(current.count("actions/checkout@"), len(names)) + for name in names: + block = _job_block(current, name) + self.assertEqual(block.count("actions/checkout@"), 1, name) + self.assertEqual(block.count(expected), 1, name) + + def test_workflow_requires_seven_immutable_checkout_references(self) -> None: + current = (ROOT / ".github/workflows/linux.yml").read_text() + self._assert_checkout_contract(current) + + def test_workflow_rejects_mutable_checkout_references_in_every_job(self) -> None: + """[SEC][UC-104-CI01] Refuse mutable checkout tags/branches independently of hashes.""" + current = (ROOT / ".github/workflows/linux.yml").read_text() + self._assert_checkout_contract(current) + pinned = "actions/checkout@11d5960a326750d5838078e36cf38b85af677262" + for name in ("verify", "changed-scope-coverage", "keyless-cuda", "hosted-cuda-package", + "linux-static-cli", "linux-cli-container", "release-cli"): + for mutable in ("v4", "v4.2.2", "main"): + with self.subTest(job=name, ref=mutable): + block = _job_block(current, name) + self.assertEqual(block.count(pinned), 1) + mutated = current.replace(block, block.replace(pinned, + f"actions/checkout@{mutable}", 1), 1) + # Exercise the semantic judge directly: no digest or HEAD mismatch + # is needed to reject any of the seven restored mutable callers. + with self.assertRaises(AssertionError): + self._assert_checkout_contract(mutated) + def test_workflow_rejects_restored_unchecked_installer_in_every_bootstrap_job(self) -> None: current = (ROOT / ".github/workflows/linux.yml").read_text() self._assert_workflow_contract(current, current)