From ec1001de95fbba9fa576656c1688f682ec6a4925 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Wed, 21 Oct 2026 10:08:23 +0200 Subject: [PATCH] fix: read validate_pr data from the repo root Run from another directory, validate_pr.py read no database, platform or profile and reported every file as referenced by no platform and outside bios/. It now moves to the root as verify.py does, reading the files named from where they were typed. --- scripts/validate_pr.py | 10 ++++++++++ tests/test_refresh_failures.py | 9 ++++++++- tests/test_validate_pr_flow.py | 27 +++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/scripts/validate_pr.py b/scripts/validate_pr.py index 7c66ab88..b1a922b3 100644 --- a/scripts/validate_pr.py +++ b/scripts/validate_pr.py @@ -512,6 +512,16 @@ def main() -> None: output.add_argument("--json", action="store_true", help="Output as JSON") args = parser.parse_args() + # The database, platforms and profiles are read from the repository + # root. Run from elsewhere, every file read as referenced by no platform + # and placed outside bios/. The files named are read from where they + # were typed. + from verify import REPO_ROOT, work_from_repo_root + + if os.path.realpath(os.getcwd()) != os.path.realpath(REPO_ROOT): + args.files = [os.path.abspath(f) for f in args.files] + work_from_repo_root(args, parser, ["db", "platforms_dir", "emulators_dir"]) + files = _files_to_validate(args, parser) if not files: if args.json: diff --git a/tests/test_refresh_failures.py b/tests/test_refresh_failures.py index 31c719e9..ddcdd6b3 100644 --- a/tests/test_refresh_failures.py +++ b/tests/test_refresh_failures.py @@ -30,8 +30,15 @@ class GitThatCannotAnswer(unittest.TestCase): # TMPDIR may lie inside this repository (the audit gate puts it in # tmp/): git must not find the enclosing work tree from there. env = dict(os.environ, GIT_CEILING_DIRECTORIES=str(Path(tmp).parent)) + # The script moves to its own checkout first: kept here, it stands + # for a copy of scripts/ that no repository holds. proc = subprocess.run( - [sys.executable, str(REPO_ROOT / "scripts" / "validate_pr.py"), "--changed"], + [sys.executable, "-c", ( + f"import sys; sys.path.insert(0, {str(REPO_ROOT / 'scripts')!r}); " + "import verify; verify.work_from_repo_root = lambda *a: None; " + "import validate_pr; sys.argv = ['validate_pr.py', '--changed']; " + "validate_pr.main()" + )], cwd=tmp, env=env, capture_output=True, text=True, timeout=60, check=False, ) self.assertEqual(proc.returncode, 2, proc.stdout + proc.stderr) diff --git a/tests/test_validate_pr_flow.py b/tests/test_validate_pr_flow.py index c6fb86c1..e5930f57 100644 --- a/tests/test_validate_pr_flow.py +++ b/tests/test_validate_pr_flow.py @@ -7,7 +7,9 @@ cannot hold has to be an action the contributor can take. from __future__ import annotations +import json import os +import subprocess import sys import tempfile import unittest @@ -119,5 +121,30 @@ class OversizedFileAdvice(unittest.TestCase): ) +class RunFromAnyDirectory(unittest.TestCase): + """database.json, platforms/ and emulators/ were read from the current + directory. Run from elsewhere, scph5501.bin came back referenced by no + platform and not under bios/, with rc 0.""" + + def test_the_report_is_the_one_the_root_gives(self): + path = REPO_ROOT / "bios" / "Sony" / "PlayStation" / "scph5501.bin" + self.assertTrue(path.is_file(), path) + reports = {} + with tempfile.TemporaryDirectory() as elsewhere: + for cwd, arg in ((REPO_ROOT, "bios/Sony/PlayStation/scph5501.bin"), + (Path(elsewhere), str(path))): + proc = subprocess.run( + [sys.executable, str(REPO_ROOT / "scripts" / "validate_pr.py"), + "--json", arg], + cwd=cwd, capture_output=True, text=True, timeout=120, check=False, + ) + self.assertEqual(proc.returncode, 0, proc.stderr) + reports[cwd == REPO_ROOT] = json.loads(proc.stdout)[0]["checks"] + self.assertEqual(reports[False], reports[True]) + messages = [c["message"] for c in reports[False]] + self.assertIn("SHA1 matches known platform requirement", messages) + self.assertIn("Already in the database at this path", messages) + + if __name__ == "__main__": unittest.main()