From 91e385598e13e35c6d93c84589ec6522c9f0176e Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Sat, 21 Nov 2026 17:25:44 +0100 Subject: [PATCH] fix: say why a version page or check went unread --- scripts/core/upstream.py | 4 +++- scripts/freshness/profiles.py | 7 ++++++ scripts/profiling/reports.py | 10 +++++++++ scripts/profiling/run.py | 11 ++++++---- scripts/profiling/versions.py | 21 ++++++++++++------ tests/test_check_freshness.py | 11 ++++++++++ tests/test_profile_sync.py | 40 ++++++++++++++++++++++++++++++++++- 7 files changed, 91 insertions(+), 13 deletions(-) diff --git a/scripts/core/upstream.py b/scripts/core/upstream.py index c19585380..4788f4b75 100644 --- a/scripts/core/upstream.py +++ b/scripts/core/upstream.py @@ -623,6 +623,8 @@ def fetch_page(url: str, cache_dir: str, offline: bool) -> str | None: A project published outside a forge (Altirra, mednafen, ePSXe) says its version on a download page: that page is the only release feed there is. + None is a page the site answers absent. Offline, a page the cache never + stored raises NotCachedError, as every other read of this module does. """ key = hashlib.sha256(url.encode()).hexdigest() target = Path(cache_dir) / "_pages" / f"{key}.txt" @@ -632,7 +634,7 @@ def fetch_page(url: str, cache_dir: str, offline: bool) -> str | None: raw = target.read_text(encoding="utf-8") return None if raw == ABSENT else raw if offline: - return None + raise NotCachedError(f"{url} is not in the offline cache") text = http_text(url) write_cache(target, ABSENT if text is None else text) return text diff --git a/scripts/freshness/profiles.py b/scripts/freshness/profiles.py index 373dc1a62..1bf18ce13 100644 --- a/scripts/freshness/profiles.py +++ b/scripts/freshness/profiles.py @@ -113,6 +113,13 @@ def summarize_profile_sync(report: object) -> list[Finding]: findings.append(Finding("profiles", name, status, local=declared, remote=announced, detail=detail)) continue + if row.get("skipped") and row.get("page_version_unread"): + # The release page is the only feed this profile has: unread, a + # new release cannot be told from none, so the row is unknown. + findings.append(Finding("profiles", name, UNKNOWN, + local=str(row.get("declared_version") or ""), + detail=f"version page unread: {row['page_version_unread']}")) + continue if row.get("skipped"): # A skip profile_sync counts as a defect (no repository answers, # no resolvable pin) is unknown. One that is the profile's nature diff --git a/scripts/profiling/reports.py b/scripts/profiling/reports.py index cb658f20f..5d1807c75 100644 --- a/scripts/profiling/reports.py +++ b/scripts/profiling/reports.py @@ -60,6 +60,10 @@ class ProfileReport: # (version_source): the version read there, beside the one declared. declared_version: str | None = None page_version: str | None = None + # Why the page gave no version: not cached offline, absent, refused, or + # the pattern no longer matches. A feed that moved is not a profile + # without one, and check_freshness reads the difference here. + page_version_unread: str | None = None # An announced version searched for and found only rebuilt or re-signed. no_genuine_copy: str | None = None # What realign_prose has to settle before a recale or a bump can run: @@ -71,6 +75,9 @@ class ProfileReport: # release, kept on the report so every output carries it. version: VersionReport | None = None version_warning: str | None = None + # A forge that refused the version check or the tag ancestry read, kept + # here so --json carries it as the text report does. + version_unread: str | None = None # --detect-new-files and --watch-hashes, kept on the report so --json # carries them to check_freshness. None when not asked. A new file is # {path, line, name, since_pin}: since_pin when the pinned revision of @@ -213,6 +220,7 @@ def _report_header(report: ProfileReport) -> list[str]: lines.append( f" version page: declared {report.declared_version or '-'}, " f"announced {report.page_version or 'unreadable'}" + + (f" ({report.page_version_unread})" if report.page_version_unread else "") + (" (no genuine copy found)" if report.page_version and report.page_version == report.no_genuine_copy else "") @@ -224,6 +232,8 @@ def _report_header(report: ProfileReport) -> list[str]: f"latest tag {version.latest_tag}, " f"latest release {version.latest_release} ({version.release_date})" ) + if report.version_unread: + lines.append(f" {report.version_unread}") if report.version_warning: lines.append(f" {report.version_warning}") return lines diff --git a/scripts/profiling/run.py b/scripts/profiling/run.py index 1deac18d4..0f8da0c8a 100644 --- a/scripts/profiling/run.py +++ b/scripts/profiling/run.py @@ -268,7 +268,8 @@ def _attach_version( """Record core_version against the forge's latest tag and release. Kept on the report rather than printed, so --json carries it as the text - report does. A forge that refuses is named on the profile's own line. + 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 if repo is None: @@ -278,7 +279,7 @@ def _attach_version( except upstream.RateLimitError: raise except upstream.UpstreamError as exc: - print(f"{report.name}: version check skipped: {exc}", file=sys.stderr) + report.version_unread = f"version check skipped: {exc}" return relation = None passed = None @@ -295,7 +296,7 @@ def _attach_version( except upstream.RateLimitError: raise except upstream.UpstreamError as exc: - print(f"{report.name}: tag ancestry unread: {exc}", file=sys.stderr) + report.version_unread = f"tag ancestry unread: {exc}" newer = None report.version_warning = version_warning(version, report.pin, relation, passed) or ( f"{'release' if version.latest_release else 'tag'} {newer} is newer than core_version {version.declared} and the pin: " @@ -425,7 +426,9 @@ def _build_full_report( report.stale_prose = _read_stale_prose(name, profile_path, args, failed) if args.check_version and profile.get("version_source"): report.declared_version = str(profile.get("core_version") or "") or None - report.page_version = page_version(profile, args.cache_dir, args.offline) + report.page_version, report.page_version_unread = page_version( + profile, args.cache_dir, args.offline + ) report.no_genuine_copy = str( profile["version_source"].get("no_genuine_copy") or "") or None if args.check_version: diff --git a/scripts/profiling/versions.py b/scripts/profiling/versions.py index 87f34b86a..0f7e7d190 100644 --- a/scripts/profiling/versions.py +++ b/scripts/profiling/versions.py @@ -3,7 +3,6 @@ from __future__ import annotations import re -import sys from dataclasses import dataclass from core import upstream @@ -40,23 +39,31 @@ def check_version( ) -def page_version(profile: dict, cache_dir: str, offline: bool) -> str | None: +def page_version( + profile: dict, cache_dir: str, offline: bool +) -> tuple[str | None, str | None]: """The latest version a profile's version_source page announces. Forty-odd profiles live off any forge: profile_sync could only say "unsupported host", and a new Altirra or mednafen release went unseen. + Returns (version, None) or (None, why the page gave no version): a page + not cached offline, absent, refused, or one the pattern no longer finds. + One None for all four read like a profile with no version_source. """ source = profile.get("version_source") or {} url, pattern = str(source.get("url") or ""), str(source.get("pattern") or "") if not url or not pattern: - return None + return None, "version_source names no url or pattern" try: text = upstream.fetch_page(url, cache_dir, offline) + except upstream.NotCachedError: + return None, "not cached offline" except upstream.UpstreamError as exc: - print(f"{profile.get('emulator', '?')}: {url}: {exc}", file=sys.stderr) - return None - match = re.search(pattern, text or "") - return match.group(1) if match else None + return None, f"{url}: {exc}" + if text is None: + return None, "page absent" + match = re.search(pattern, text) + return (match.group(1), None) if match else (None, "pattern not found") def version_warning( diff --git a/tests/test_check_freshness.py b/tests/test_check_freshness.py index 68969a7e8..0ff83a678 100644 --- a/tests/test_check_freshness.py +++ b/tests/test_check_freshness.py @@ -906,6 +906,17 @@ class AReleasePageMakesAProfileStale(unittest.TestCase): self.assertEqual(found["altirra"], STALE) self.assertEqual(found["mednafen"], OK) + def test_an_unread_release_page_is_unknown_not_skipped(self): + """An unreadable page read like a profile with no version_source: + SKIPPED by nature, and a moved or dead feed went unseen.""" + + rows = [{"name": "altirra", "skipped": "unsupported host: virtualdub.org", + "declared_version": "4.40", "page_version": None, + "page_version_unread": "page absent"}] + (overall, row) = summarize_profile_sync(rows) + self.assertEqual(row.status, UNKNOWN) + self.assertEqual(row.detail, "version page unread: page absent") + def test_a_release_with_no_genuine_copy_waits_for_the_next(self): """FPse 13.0 exists only as rebuilt copies: the profile stays on 12.1 and flagging it on every run said nothing new. 13.1 would.""" diff --git a/tests/test_profile_sync.py b/tests/test_profile_sync.py index ac595c9e0..a57bc574b 100644 --- a/tests/test_profile_sync.py +++ b/tests/test_profile_sync.py @@ -5999,7 +5999,45 @@ class AnOffForgeProfileWatchesItsReleasePage(unittest.TestCase): }} with mock.patch.object(upstream, "fetch_page", return_value="

Altirra 4.50 released

"): - self.assertEqual(versions.page_version(profile, "cache", False), "4.50") + self.assertEqual(versions.page_version(profile, "cache", False), ("4.50", None)) + + def test_an_unread_page_says_why(self): + """A fetch error, an uncached page, a 404 and a pattern miss all + came back None, the error only printed: the JSON could not tell a + moved release page from a profile without one.""" + from unittest import mock + + profile = {"emulator": "Altirra", "version_source": { + "url": "https://example.test/altirra", "pattern": r"Altirra (\d+\.\d+) released", + }} + answers = [ + (upstream.NotCachedError("cold"), "not cached offline"), + (None, "page absent"), + ("

nothing here

", "pattern not found"), + (upstream.UpstreamError("HTTP 500"), "https://example.test/altirra: HTTP 500"), + ] + for answer, reason in answers: + effect = {"side_effect": answer} if isinstance(answer, Exception) else {"return_value": answer} + with self.subTest(reason=reason), \ + mock.patch.object(upstream, "fetch_page", **effect), \ + mock.patch("sys.stderr") as stderr: + self.assertEqual(versions.page_version(profile, "cache", True), (None, reason)) + stderr.write.assert_not_called() + + def test_an_uncached_page_offline_is_not_an_absent_one(self): + with tempfile.TemporaryDirectory() as cache, self.assertRaises(upstream.NotCachedError): + upstream.fetch_page("https://example.invalid/never-cached", cache, True) + + def test_the_reason_reaches_the_json_and_the_text(self): + report = ProfileReport(name="altirra", entries=[], counts={}, skipped="unsupported host: x", + declared_version="4.40", page_version_unread="page absent", + version_unread="tag ancestry unread: refused") + payload = report_to_dict(report) + self.assertEqual(payload["page_version_unread"], "page absent") + self.assertEqual(payload["version_unread"], "tag ancestry unread: refused") + text = format_report(report) + self.assertIn("announced unreadable (page absent)", text) + self.assertIn("tag ancestry unread: refused", text) class ARecaleKeepsTheRepositoryWord(unittest.TestCase):