fix: refresh source paths only from emulators/

This commit is contained in:
Abdessamad Derraz committed 2026-11-22 02:26:45 +01:00
1 parent 11f6d478d2
commit 815341ba3b
2 files changed
+49 -3

No files matched your search

+16 -2
View File
@@ -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 <record> 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(
+33 -1
View File
@@ -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."""