fix: read a source declared gone at its mirror

This commit is contained in:
Abdessamad Derraz committed 2026-11-24 02:18:53 +01:00
1 parent ac334729f5
commit 08fbeff62f
7 files changed
+123 -49

No files matched your search

+25
View File
@@ -2,6 +2,8 @@
from __future__ import annotations
from core import upstream
# Read in this order: a declared repository decides attribution before the
# mirror that only keeps a gone forge's history reachable.
REPOSITORY_FIELDS = ("source", "upstream", "source_mirror")
@@ -30,6 +32,29 @@ def declared_repositories(profile: dict) -> list[tuple[str, str, str]]:
return urls
def _identity(url: str) -> tuple[str, str] | str:
"""What two URLs naming one repository share: host and slug on a known
forge, the URL itself elsewhere."""
repo = upstream.parse_repo(url)
return (repo.host, repo.slug) if repo is not None else url.strip().rstrip("/")
def serving_url(profile: dict, url: str) -> str:
"""The URL that serves a declared repository: the `source_mirror` of a
`source` the profile declares gone, the URL itself otherwise.
The mirror carries the same commits: simple64/simple64 and
teknogods/TeknoParrotUI answer 404, and the site linked every citation
into them while profile_sync read the mirror. An `upstream` naming the
gone source is served by the mirror too.
"""
mirror = str(profile.get("source_mirror") or "")
if not mirror or not str(profile.get("upstream_gone") or "").strip():
return url
gone = {_identity(u) for field, _mode, u in declared_repositories(profile) if field == "source"}
return mirror if _identity(url) in gone else url
def pin_field(field: str) -> str:
"""The `<field>_commit` that pins a repository field. A mirror carries
the source's history, commits and branches alike: source_commit pins it."""
+8 -11
View File
@@ -17,7 +17,7 @@ from profiling.anchoring import anchor_block
from profiling.attribution import owner_order
from profiling.citations import Citation, citation_key, collect_citations, is_external_citation
from profiling.proseedit import apply_prose_edits, run_after_moves
from model.profilerepos import declared_repositories
from model.profilerepos import declared_repositories, serving_url
from profiling.yamledit import apply_edit
@@ -359,24 +359,21 @@ def _prose_repos(document: dict) -> _ProseRepos | None:
# Every repository the profile declares, by build mode where it keys
# them so: eka2l1, mesence, supermodel and xemu pin a dict, and reading
# str(dict) found no repository at all, so their prose was never judged.
repos = [
(field, mode, repo)
urls = {
(field, mode, repo): url
for field, mode, url in declared_repositories(document)
if field != "source_mirror" and (repo := upstream.parse_repo(url)) is not None
]
if not repos:
}
if not urls:
return None
repos = list(urls)
# A source declared gone is read through its mirror, which carries the
# same commits: teknoparrot's notes stayed blocked once
# teknogods/TeknoParrotUI answered 404, every reading of the old pin
# calling the files absent.
mirror = (
upstream.parse_repo(str(document.get("source_mirror") or ""))
if document.get("upstream_gone") else None
)
served = {
repo: mirror for field, _mode, repo in repos
if mirror is not None and field == "source"
repo: mirror for (_field, _mode, repo), url in urls.items()
if (mirror := upstream.parse_repo(serving_url(document, url))) not in (None, repo)
}
pinned = [
(served.get(repo, repo), pin)
+21 -2
View File
@@ -7,7 +7,7 @@ from collections.abc import Iterable
from dataclasses import dataclass, replace
from core import upstream
from model.profilerepos import declared_pin, declared_repositories, pin_field
from model.profilerepos import declared_pin, declared_repositories, pin_field, serving_url
PIN = "pin"
@@ -66,6 +66,25 @@ def resolve_pin(
return (sha, f"profiled_date {date}") if sha else (None, None)
def _read_order(profile: dict) -> list[tuple[str, str, str]]:
"""The declared repositories in the order they are asked, as
(field, build mode, url): a source declared gone is followed at once by
the mirror that serves it, before the upstream.
The gone source is still asked, so a forge that answers again
contradicts the declaration. Listed last, the mirror ranked after a live
upstream and took no part in attribution, while the prose pass and the
site read it in the source's place.
"""
order: list[tuple[str, str, str]] = []
for field_name, mode, url in declared_repositories(profile):
order.append((field_name, mode, url))
served = serving_url(profile, url)
if field_name != "source_mirror" and served != url:
order.append(("source_mirror", mode, served))
return order
def select_views(
profile: dict, cache_dir: str, offline: bool
) -> list[RepoView]:
@@ -81,7 +100,7 @@ def select_views(
# A port living on a branch of a fork is absent from the default tip, so
# the branch it was read from is followed when the profile names one.
declared = str(profile.get("source_branch") or "") or None
for field_name, mode, url in declared_repositories(profile):
for field_name, mode, url in _read_order(profile):
repo = upstream.parse_repo(url)
if repo is None or (repo.host, repo.slug) in seen:
continue
+5 -3
View File
@@ -29,6 +29,7 @@ from model.profilerepos import (
declared_pin,
declared_repositories,
pin_field,
serving_url,
)
from model.sourcerevision import parse_source
from sitegen.render import escape_tags
@@ -41,10 +42,11 @@ def _repo_pins(profile: dict, field: str, label: str) -> list[tuple[str, str, st
and the revision by build mode. Reading them apart would pin a libretro
fork to the standalone revision and produce a permalink into a tree that
never held the cited line. Each tuple is (url, pin, source_commit
fallback for that same mode). A mirror is pinned by source_commit.
fallback for that same mode). A mirror is pinned by source_commit, and
a source the profile declares gone is given as the mirror serving it.
"""
declared = [(mode, url) for name, mode, url in declared_repositories(profile)
if name == field]
declared = [(mode, serving_url(profile, url))
for name, mode, url in declared_repositories(profile) if name == field]
# The requested build mode first, so it wins when several repositories
# would otherwise be equally good candidates.
declared.sort(key=lambda pair: bool(pair[0]) and pair[0] != label)
+49
View File
@@ -5871,6 +5871,55 @@ class AMirrorOutlivesAGoneSource(unittest.TestCase):
views = profiling_repos.select_views(profile, "cache", True)
self.assertEqual([(v.repo, v.field) for v in views], [(mirror, "source_mirror")])
def test_the_mirror_takes_the_gone_source_place_before_the_upstream(self):
"""Read last, the mirror ranked after a live upstream, while the
prose pass and the site read it in the source's place."""
from unittest import mock
gone_repo = upstream.make_repo("github.com", "gone", "emu")
mirror = upstream.make_repo("github.com", "fork", "emu")
live = upstream.make_repo("github.com", "up", "emu")
def head(repo, cache_dir, offline=False, branch=None):
if repo == gone_repo:
raise upstream.GoneError("HTTP 404")
return "tip"
profile = {
"source": "https://github.com/gone/emu",
"upstream": "https://github.com/up/emu",
"source_mirror": "https://github.com/fork/emu",
"source_commit": "pin",
"upstream_gone": "gone/emu answers 404",
}
with mock.patch.object(upstream, "resolve_head", side_effect=head), \
mock.patch.object(profiling_repos, "resolve_pin", return_value=("pin", "c")):
views = profiling_repos.select_views(profile, "cache", True)
self.assertEqual([(v.repo, v.field) for v in views],
[(mirror, "source_mirror"), (live, "upstream")])
def test_the_gone_source_is_still_asked(self):
"""A forge answering again contradicts upstream_gone, so it is asked."""
from unittest import mock
asked = []
def head(repo, cache_dir, offline=False, branch=None):
asked.append(repo.slug)
return "tip"
profile = {
"source": "https://github.com/gone/emu",
"source_mirror": "https://github.com/fork/emu",
"source_commit": "pin",
"upstream_gone": "gone/emu answers 404",
}
with mock.patch.object(upstream, "resolve_head", side_effect=head), \
mock.patch.object(profiling_repos, "resolve_pin", return_value=("pin", "c")):
views = profiling_repos.select_views(profile, "cache", True)
self.assertEqual(asked[0], "gone/emu")
self.assertEqual(views[0].field, "source")
class AHeldUpstreamStaysOnItsPin(unittest.TestCase):
"""aps3e vendors RPCS3 1f080485 and yaps2 PCSX2 342db515: a bump moved
+15
View File
@@ -297,6 +297,21 @@ class PerModeSourcePins(unittest.TestCase):
[("gone/emu", "d" * 40), ("keeper/emu", "d" * 40)],
)
def test_a_source_declared_gone_is_linked_through_its_mirror(self):
"""simple64/simple64 answers 404, and every citation on its page
linked there while profile_sync read simple64-vault/simple64."""
profile = {
"source": "https://github.com/gone/emu",
"upstream": "https://github.com/gone/emu",
"source_mirror": "https://github.com/keeper/emu",
"source_commit": "d" * 40,
"upstream_gone": "gone/emu answers 404",
}
self.assertEqual(
[(repo.slug, pin) for repo, pin in _forge_sources(profile)],
[("keeper/emu", "d" * 40)],
)
def test_sqlite_export_accepts_a_per_mode_commit(self):
from core.artifacts import json_text as _json_text
-33
View File
@@ -59,7 +59,6 @@
"codeberg.org/virtualxt/virtualxt@a400adb0abf242c2fecbe926618338a00dc557c5": [
"virtualxt_libretro.info"
],
"git.citron-emu.org/citron-emu/Citron@79dee42601deff2077160906f9a89756fca820a9": [],
"git.eden-emu.dev/eden-emu/eden@26a03d2473787abf3223b2d0e65b291eee00c1e1": [
"src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/InstallableFragment.kt",
"src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/DirectoryInitialization.kt",
@@ -10329,30 +10328,6 @@
"simple64-input-qt/configdialog.cpp",
"simple64-input-qt/main.cpp"
],
"github.com/simple64/simple64@d8c969c7b932e3d76e6a25549d76348839dbaefd": [
"build.sh",
"mupen64plus-core/CMakeLists.txt",
"mupen64plus-core/src/api/config.c",
"mupen64plus-core/src/api/frontend.c",
"mupen64plus-core/src/api/m64p_types.h",
"mupen64plus-core/src/device/controllers/vru_controller.c",
"mupen64plus-core/src/device/pif/bootrom_hle.c",
"mupen64plus-core/src/device/pif/pif.c",
"mupen64plus-core/src/device/pif/pif.h",
"mupen64plus-core/src/device/r4300/interrupt.c",
"mupen64plus-core/src/main/main.c",
"mupen64plus-core/src/main/rom.c",
"mupen64plus-core/src/main/screenshot.c",
"mupen64plus-core/src/osal/files_unix.c",
"mupen64plus-core/src/osd/osd.h",
"parallel-rdp-standalone/parallel-rdp/rdp_renderer.cpp",
"simple64-gui/cheats.cpp",
"simple64-gui/interface/common.cpp",
"simple64-gui/main.cpp",
"simple64-gui/mainwindow.cpp",
"simple64-input-qt/configdialog.cpp",
"simple64-input-qt/main.cpp"
],
"github.com/skmp/reicast-emulator@ad61f95dd6b4c6218846a25de6194550311a5d28": [
"core/hw/flashrom/flashrom.h",
"core/hw/holly/sb_mem.cpp",
@@ -10471,7 +10446,6 @@
"src/io/file_manager.cpp",
"src/utils/constants.cpp"
],
"github.com/suyu-emu/suyu@ee365bad9501c73ff49936e72ec91cd9c3ce5c24": [],
"github.com/sydarn/yabause@a40dace1ae0af3ebd45848549fdf396f40e3930f": [
"yabause/CMakeLists.txt",
"yabause/src/config.h.in",
@@ -10482,12 +10456,6 @@
"yabause/src/retro_arena/main.cpp",
"yabause/src/yabause.c"
],
"github.com/teknogods/TeknoParrotUI@b75872addc1d5cce81a62f4c1468eab59e2d3cbe": [
"TeknoParrotUi.Common/EmulatorType.cs",
"TeknoParrotUi.Common/TeknoNaomiCatalog.cs",
"TeknoParrotUi.Common/TeknoNaomiLaunch.cs",
"TeknoParrotUi/MainWindow.xaml.cs"
],
"github.com/thecrixux/TeknoParrotUI@b75872addc1d5cce81a62f4c1468eab59e2d3cbe": [
"TeknoParrotUi.Common/EmulatorType.cs",
"TeknoParrotUi.Common/TeknoNaomiCatalog.cs",
@@ -10992,7 +10960,6 @@
"src/common/filesystem.c",
"src/common/header/common.h"
],
"github.com/yuzu-emu-mirror/yuzu@15e6e48bef0216480661444a8d8b348c1cca47bb": [],
"github.com/zelurker/raine@8e25d5d8907ae459181610912b0030c955683015": [
"makefile",
"source/emudx.c",