From 1f9633c7e524edec09a3c1b009a21da90a7ed784 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Sat, 21 Nov 2026 20:50:21 +0100 Subject: [PATCH] fix: check core_version in its basis repository version_basis reads core_version in the repository its repo or url names (PCSX2 for pcee2, yaps2, triforce, hatari2014), while --check-version and the triage read the tags of the port the profile was read from, which carries none. version_repo() decides it once for the three readers, and the tag ancestry uses the pin of that repository. A newer release of a held upstream (upstream_frozen) is not reported, as one past a held pin is not. --- scripts/profiling/run.py | 33 ++++++++++++++------ scripts/profiling/triage.py | 4 +-- scripts/profiling/version_basis.py | 31 +++++++++++++----- tests/test_audit_regressions.py | 1 - tests/test_version_basis.py | 50 ++++++++++++++++++++++++++++++ 5 files changed, 100 insertions(+), 19 deletions(-) diff --git a/scripts/profiling/run.py b/scripts/profiling/run.py index 9283b00c7..59fdedfa5 100644 --- a/scripts/profiling/run.py +++ b/scripts/profiling/run.py @@ -23,10 +23,10 @@ from profiling.reports import ( format_report, report_to_dict, ) -from profiling.repos import select_repo from profiling.resolver import build_report from profiling.sourcepaths import record_write from profiling.triage import PROGRESS_SECONDS, Progress, print_interrupted, print_triage +from profiling.version_basis import version_repo from profiling.versions import ( newer_release, latest_passed_release, @@ -266,6 +266,17 @@ def _attach_detection( report.detection_skipped = str(exc) +def _version_pin(report: ProfileReport, repo: upstream.Repo, field: str) -> str | None: + """The pin of the repository core_version is read in: upstream_commit for + a basis reading the upstream, the primary pin for the primary repository, + None for a repository the report did not compare.""" + if field == "upstream": + return report.upstream_pin + if (repo.host, repo.slug) == (report.host, report.repo): + return report.pin + return None + + def _attach_version( args: argparse.Namespace, profile: dict, report: ProfileReport ) -> None: @@ -275,9 +286,13 @@ def _attach_version( report does. A forge that refuses is named on the profile's own line (version_unread). """ - repo = select_repo(profile) if report.head else None + repo, field = version_repo(profile) if report.head else (None, "") if repo is None: return + pin = _version_pin(report, repo, field) + # A held upstream (yaps2 synced to PCSX2 342db515) is not one a newer + # release of that project asks to profile again, as a held pin is not. + frozen_by = "upstream_frozen" if field == "upstream" else "pin_frozen" try: report.version = check_version(profile, repo, args.cache_dir, args.offline) except upstream.RateLimitError: @@ -289,22 +304,22 @@ def _attach_version( passed = None version = report.version try: - if version and version.tag_commit and report.pin and version.tag_commit != report.pin: + if version and version.tag_commit and pin and version.tag_commit != pin: relation = upstream.ancestry( - repo, version.tag_commit, report.pin, args.cache_dir, args.offline + repo, version.tag_commit, pin, args.cache_dir, args.offline ) - passed = latest_passed_release(repo, version, report.pin, args.cache_dir, args.offline) - newer = None if passed or profile.get("pin_frozen") else newer_release( - repo, version, report.pin, args.cache_dir, args.offline + passed = latest_passed_release(repo, version, pin, args.cache_dir, args.offline) + newer = None if passed or profile.get(frozen_by) else newer_release( + repo, version, pin, args.cache_dir, args.offline ) except upstream.RateLimitError: raise except upstream.UpstreamError as exc: report.version_unread = f"tag ancestry unread: {exc}" newer = None - report.version_warning = version_warning(version, report.pin, relation, passed) or ( + report.version_warning = version_warning(version, pin, relation, passed) or ( f"{'release' if version.latest_release else 'tag'} {newer} is newer than core_version {version.declared} and the pin: " - "profile it, or hold the pin with pin_frozen and the reason" + f"profile it, or hold the pin with {frozen_by} and the reason" if newer and version else None ) diff --git a/scripts/profiling/triage.py b/scripts/profiling/triage.py index 127759164..57071e55e 100644 --- a/scripts/profiling/triage.py +++ b/scripts/profiling/triage.py @@ -8,7 +8,7 @@ import time from core import upstream from profiling.reports import ProfileReport, triage_state -from profiling.repos import select_repo +from profiling.version_basis import version_repo from profiling.versions import VersionReport, check_version @@ -114,7 +114,7 @@ def _score( commits = 0 refused = "" sampled = False - repo = select_repo(profile) + repo = version_repo(profile)[0] if report.head and repo is not None: # Each cited path counted in the repository the resolver settled it # in, between that repository's own pin and HEAD. diff --git a/scripts/profiling/version_basis.py b/scripts/profiling/version_basis.py index 904d665ba..1a32c45fa 100644 --- a/scripts/profiling/version_basis.py +++ b/scripts/profiling/version_basis.py @@ -34,7 +34,7 @@ from dataclasses import dataclass from core import upstream from model.profilerepos import pin_field -from profiling.repos import resolve_pin +from profiling.repos import resolve_pin, select_repo KINDS = ("file", "tag", "alias", "package", "none", "unverified") # Values copied from a .info or a branch name, which name no version. @@ -91,6 +91,26 @@ def _by_mode(profile: dict, field: str, mode: str) -> str | None: return str(value) if value else None +def version_repo( + profile: dict, mode: str = "", basis: dict | None = None, +) -> tuple[upstream.Repo | None, str]: + """The repository core_version describes, and the profile field naming it. + + The basis says where the version is read: its url (field "url"), else + the repository its `repo` field names. pcee2 reads PCSX2's tags, which + the port the profile was read from never carries. A profile with no + basis is read in the repository it was profiled from. + """ + if basis is None: + basis = bases(profile).get(mode) + if not basis: + return select_repo(profile), "source" + if basis.get("url"): + return upstream.parse_repo(str(basis["url"])), "url" + field = str(basis.get("repo") or "source") + return upstream.parse_repo(_by_mode(profile, field, mode) or ""), field + + def is_placeholder(value: object) -> bool: """A VCS or branch word standing for a version, alone or annotated ("SVN (2015 snapshot)"). The schema refuses the same strings.""" @@ -133,15 +153,12 @@ def _repo_and_pin( profile: dict, basis: dict, mode: str, cache_dir: str, offline: bool, ) -> tuple[upstream.Repo, str]: """The repository a basis reads and the commit it is read at.""" - if basis.get("url"): - repo = upstream.parse_repo(str(basis["url"])) + repo, field = version_repo(profile, mode, basis) + if field == "url": pin = str(basis.get("commit") or "") where = str(basis["url"]) else: - field = str(basis.get("repo") or "source") - url = _by_mode(profile, field, mode) or "" - repo = upstream.parse_repo(url) - where = url or field + where = _by_mode(profile, field, mode) or field pin = "" if repo is not None: # The pin profile_sync compares at: the declared commit, else diff --git a/tests/test_audit_regressions.py b/tests/test_audit_regressions.py index 8f9a9ed15..256391b50 100644 --- a/tests/test_audit_regressions.py +++ b/tests/test_audit_regressions.py @@ -4360,7 +4360,6 @@ class TriageSurvivesAForgeRefusal(unittest.TestCase): args = SimpleNamespace(cache_dir="", offline=True) out = io.StringIO() with mock.patch.object(triage, "check_version", check_version), \ - mock.patch.object(triage, "select_repo", lambda p: object()), \ contextlib.redirect_stdout(out), \ contextlib.redirect_stderr(io.StringIO()): triage.print_triage(args, selected, reports) diff --git a/tests/test_version_basis.py b/tests/test_version_basis.py index 0cf75be9a..b615d5eaf 100644 --- a/tests/test_version_basis.py +++ b/tests/test_version_basis.py @@ -251,6 +251,56 @@ class TheBasisPinIsTheComparisonPin(unittest.TestCase): self.assertEqual((repo.slug, pin), ("o/m", "b" * 40)) +class TheVersionRepositoryIsTheBasisRepository(unittest.TestCase): + """--check-version read pcee2's core_version against the port's tags, + while version_basis reads it in PCSX2.""" + + PROFILE = { + "source": "https://github.com/o/port", + "upstream": "https://github.com/o/up", + "version_basis": {"kind": "tag", "repo": "upstream"}, + } + + def test_a_basis_naming_the_upstream_is_read_there(self): + repo, field = version_basis.version_repo(self.PROFILE) + self.assertEqual((repo.slug, field), ("o/up", "upstream")) + + def test_a_profile_without_basis_is_read_where_it_was_profiled(self): + profile = {k: v for k, v in self.PROFILE.items() if k != "version_basis"} + repo, field = version_basis.version_repo(profile) + self.assertEqual((repo.slug, field), ("o/port", "source")) + + def test_a_basis_url_is_its_own_repository(self): + profile = dict(self.PROFILE, version_basis={ + "kind": "package", "url": "https://github.com/o/pkg/releases"}) + repo, field = version_basis.version_repo(profile) + self.assertEqual((repo.slug, field), ("o/pkg", "url")) + + def test_the_check_reads_the_tags_and_the_pin_of_that_repository(self): + from profiling import run as profiling_run + + report = ProfileReport( + name="p", repo="o/port", host="github.com", pin="portpin", head="porthead", + upstream_pin="uppin", upstream_head="uphead", + ) + asked = [] + + def tag_commit(repo, tag, *_a, **_k): + asked.append(repo.slug) + return "uptag" if repo.slug == "o/up" else None + + args = mock.Mock(cache_dir="cache", offline=True) + with mock.patch.object(upstream, "latest_release", return_value=None), \ + mock.patch.object(upstream, "newest_tag", return_value=None), \ + mock.patch.object(upstream, "tag_commit", side_effect=tag_commit), \ + mock.patch.object(upstream, "ancestry", return_value=(3, 0)) as ancestry: + profiling_run._attach_version(args, dict(self.PROFILE, core_version="v1"), report) + self.assertEqual(set(asked), {"o/up"}) + self.assertEqual(report.version.tag_commit, "uptag") + self.assertEqual(ancestry.call_args.args[1:3], ("uptag", "uppin")) + self.assertIn("the pin resolved to uppin", report.version_warning) + + class AnAdvanceReadsTheVersionAgain(unittest.TestCase): """A pin never moves without its version: read again, or refused."""