fix: say why a version page or check went unread

This commit is contained in:
Abdessamad Derraz committed 2026-11-21 19:50:33 +01:00
1 parent dae6b3a146
commit 91e385598e
7 files changed
+91 -13

No files matched your search

+3 -1
View File
@@ -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
+7
View File
@@ -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
+10
View File
@@ -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
+7 -4
View File
@@ -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:
+14 -7
View File
@@ -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(
+11
View File
@@ -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."""
+39 -1
View File
@@ -5999,7 +5999,45 @@ class AnOffForgeProfileWatchesItsReleasePage(unittest.TestCase):
}}
with mock.patch.object(upstream, "fetch_page",
return_value="<p>Altirra 4.50 released</p>"):
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"),
("<p>nothing here</p>", "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):