From 815341ba3b9f1b6934dc1750ff9f91fc1e449c26 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Sun, 22 Nov 2026 01:53:48 +0100 Subject: [PATCH] fix: refresh source paths only from emulators/ --- scripts/profiling/sourcepaths.py | 18 +++++++++++++++-- tests/test_profile_sync.py | 34 +++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/scripts/profiling/sourcepaths.py b/scripts/profiling/sourcepaths.py index 9b79e3651..f681f8a26 100644 --- a/scripts/profiling/sourcepaths.py +++ b/scripts/profiling/sourcepaths.py @@ -9,6 +9,7 @@ from collections.abc import Iterator from contextlib import contextmanager from pathlib import Path +from core.paths import EMULATORS_DIR, REPO_ROOT from model.profiles import load_emulator_profiles @@ -34,10 +35,21 @@ def refresh_source_paths(args: argparse.Namespace, written: set[str]) -> None: Each bump left website/src/data/source-paths.json behind its pins, and the site's freshness test stayed red until someone ran sitesources.py --fetch by hand. A run that writes nothing, or makes no request, leaves - it alone. + it alone. The record describes the repository's profiles: a pass over + another tree prints the command for it instead of reducing the record + to the trees that tree cites. """ if not written or args.dry_run or args.offline or os.environ.get("RETROBIOS_OFFLINE"): return + if Path(args.emulators_dir).resolve() != (REPO_ROOT / EMULATORS_DIR).resolve(): + print( + f"source paths not refreshed: {args.emulators_dir} is not the repository's " + f"{EMULATORS_DIR}/: run python scripts/sitesources.py --fetch " + f"--emulators-dir {args.emulators_dir} --cache-dir {args.cache_dir} " + "--output to record them", + file=sys.stderr, + ) + return from core.artifacts import ArtifactLockBusy from model.profiles import emulator_profiles_cache from sitegen import sources @@ -48,7 +60,9 @@ def refresh_source_paths(args: argparse.Namespace, written: set[str]) -> None: emulator_profiles_cache.clear() profiles = load_emulator_profiles(args.emulators_dir, skip_aliases=False) try: - held, unread = sources.refresh_record(profiles, [sources.TREE_CACHE], fetch=True) + held, unread = sources.refresh_record( + profiles, [Path(args.cache_dir)], fetch=True, output=sources.SOURCE_PATHS, + ) except ArtifactLockBusy as exc: # The profiles are written: only the record waits for the other run. print( diff --git a/tests/test_profile_sync.py b/tests/test_profile_sync.py index d5ef2e551..df49e6181 100644 --- a/tests/test_profile_sync.py +++ b/tests/test_profile_sync.py @@ -5258,7 +5258,10 @@ class AWriteRefreshesTheSourcePaths(unittest.TestCase): the site's freshness test red until someone ran sitesources by hand.""" def _args(self, **kw): - base = {"dry_run": False, "offline": False, "emulators_dir": "emulators"} + base = { + "dry_run": False, "offline": False, + "emulators_dir": str(profiling_sourcepaths.REPO_ROOT / "emulators"), "cache_dir": ".cache/upstream", + } return argparse.Namespace(**{**base, **kw}) def test_only_a_real_online_write_refreshes(self): @@ -5296,12 +5299,41 @@ class AWriteRefreshesTheSourcePaths(unittest.TestCase): profile.write_text('emulator: P\nsource_commit: "new"\n', encoding="utf-8") with mock.patch.object(sources, "build_source_paths", return_value=({}, [])) as built, \ mock.patch.dict(os.environ, {"RETROBIOS_OFFLINE": ""}), \ + mock.patch.object(profiling_sourcepaths, "REPO_ROOT", Path(tmp).parent), \ + mock.patch.object(profiling_sourcepaths, "EMULATORS_DIR", Path(tmp).name), \ mock.patch.object(sources, "write_if_changed"), \ contextlib.redirect_stderr(io.StringIO()), \ contextlib.redirect_stdout(io.StringIO()): profiling_sourcepaths.refresh_source_paths(self._args(emulators_dir=tmp), {"p"}) self.assertEqual(built.call_args[0][0]["p"]["source_commit"], "new") + def test_another_profile_tree_leaves_the_record_alone(self): + # Rebuilt from a one-profile copy, the record went from 701 trees to 1. + from unittest import mock + + from sitegen import sources + + with tempfile.TemporaryDirectory() as tmp, \ + mock.patch.object(sources, "refresh_record") as refreshed, \ + mock.patch.dict(os.environ, {"RETROBIOS_OFFLINE": ""}), \ + contextlib.redirect_stderr(io.StringIO()) as err: + profiling_sourcepaths.refresh_source_paths(self._args(emulators_dir=tmp), {"p"}) + self.assertFalse(refreshed.called) + self.assertIn(f"sitesources.py --fetch --emulators-dir {tmp}", err.getvalue()) + + def test_the_run_cache_and_the_record_path_are_passed(self): + from unittest import mock + + from sitegen import sources + + with mock.patch.object(sources, "refresh_record", return_value=({}, [])) as refreshed, \ + mock.patch.dict(os.environ, {"RETROBIOS_OFFLINE": ""}), \ + mock.patch.object(profiling_sourcepaths, "load_emulator_profiles", return_value={}), \ + contextlib.redirect_stderr(io.StringIO()): + profiling_sourcepaths.refresh_source_paths(self._args(cache_dir="tmp/c"), {"x"}) + self.assertEqual(refreshed.call_args.args[1], [Path("tmp/c")]) + self.assertEqual(refreshed.call_args.kwargs["output"], sources.SOURCE_PATHS) + def test_the_record_waits_for_a_run_holding_the_repository(self): """profile_sync rewrote source-paths.json without the repository hold sitesources takes, in the middle of a pipeline run."""