From 9321dff2e969a48926ffe93ed4bf1ab659a83849 Mon Sep 17 00:00:00 2001 From: Codex Date: Fri, 16 Oct 2026 20:42:32 +0200 Subject: [PATCH] Check source archives when Git is unavailable (by Codex) --- tools/public_release/check_public_tree.py | 12 +++++++++--- tools/public_release/test_public_tree.py | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/tools/public_release/check_public_tree.py b/tools/public_release/check_public_tree.py index f84cb29..1794ded 100644 --- a/tools/public_release/check_public_tree.py +++ b/tools/public_release/check_public_tree.py @@ -10,6 +10,7 @@ import dataclasses import json from pathlib import Path, PurePosixPath import re +import shutil import subprocess import sys @@ -197,9 +198,12 @@ def scan_blob(name: str, blob: bytes) -> list[Finding]: def checked_files(root: Path): """Use the Git index when available; otherwise inspect a plain source archive.""" - git = subprocess.run(["git", "-C", str(root), "rev-parse", "--show-toplevel"], - capture_output=True, text=True) - if git.returncode == 0 and Path(git.stdout.strip()).resolve() == root: + try: + git = subprocess.run(["git", "-C", str(root), "rev-parse", "--show-toplevel"], + capture_output=True, text=True) + except FileNotFoundError: + git = None + if git is not None and git.returncode == 0 and Path(git.stdout.strip()).resolve() == root: output = subprocess.check_output(["git", "-C", str(root), "ls-files", "--cached", "--others", "--exclude-standard", "-z"]) return sorted({p.decode("utf-8") for p in output.split(b"\0") if p}) @@ -260,6 +264,8 @@ def main(argv=None): parser.add_argument("--history", action="store_true", help="also check all reachable commits and their blobs") parser.add_argument("--json", type=Path, help="write a report containing rule names and locations only") args = parser.parse_args(argv) + if args.history and shutil.which("git") is None: + parser.error("Git is required for history checks") root = args.root.resolve(strict=True) findings, files = scan_tree(root) commits = blobs = 0 diff --git a/tools/public_release/test_public_tree.py b/tools/public_release/test_public_tree.py index 4da2d2c..737f001 100644 --- a/tools/public_release/test_public_tree.py +++ b/tools/public_release/test_public_tree.py @@ -7,9 +7,11 @@ import contextlib import io import json from pathlib import Path +import shutil import subprocess import tempfile import unittest +from unittest import mock import check_public_tree as guard @@ -71,6 +73,19 @@ class BlobChecks(unittest.TestCase): self.assertNotIn("credential-pattern", self.rules("src/a.cpp", "const int token = state.seller_team_token;")) +class ArchiveChecks(unittest.TestCase): + def test_archive_is_checked_when_git_is_not_installed(self): + with tempfile.TemporaryDirectory(prefix="openbmh-source-test-") as directory: + root = Path(directory) + (root / "README.md").write_text("Synthetic source\n", encoding="utf-8") + (root / "bad.FBM").write_text("Synthetic refusal case\n", encoding="utf-8") + with mock.patch.object(guard.subprocess, "run", side_effect=FileNotFoundError): + findings, count = guard.scan_tree(root) + self.assertEqual(count, 2) + self.assertIn("binary-or-game-asset", {f.rule for f in findings}) + + +@unittest.skipUnless(shutil.which("git"), "Git is required for repository-history tests") class RepositoryChecks(unittest.TestCase): def setUp(self): self.temp = tempfile.TemporaryDirectory(prefix="openbmh-guard-test-")