refactor: route network access through upstream

Branch heads (scrapers, FBNeo import, data directories) resolve through
core.upstream.resolve_head, with cache_dir=None to keep nothing under
.cache/upstream. Streaming downloads (large files, external pack files,
data directory archives, scraper downloads, standalone probe) go through
one core.upstream.download: scratch then rename, size cap, retries of a
cut stream, a 5xx or a rate limit. The shared rate limit wait reads
GoatCounter's X-Rate-Limit-Reset, so site insights, download.py,
indexnow and the contributor list use the same retrying client.

list_gitlinks raises TruncatedListingError on a partial tree, read
from one tree walk shared with list_tree (Forgejo paging included).
The Recalbox configs/ listing is paged with the shared page cap.
This commit is contained in:
Abdessamad Derraz committed 2026-11-21 10:30:13 +01:00
1 parent 526d7f09c7
commit 8a8fa71fbc
25 files changed
+708 -266

No files matched your search

+34
View File
@@ -5579,6 +5579,40 @@ class UpstreamVendoredAsASubmodule(unittest.TestCase):
views = self._views({"src-pin": {"deps/zlib": "other"}, "src-head": {}})
self.assertEqual(views[1].head, "nesbox-tip")
def test_a_truncated_port_tree_is_not_read_as_no_submodule(self):
"""A partial listing kept nesbox's tip, the commit a bump must not
move upstream_commit to."""
views = [
profiling_repos.RepoView(object(), "src-pin", "src-head", "source_commit", "source"),
profiling_repos.RepoView(object(), "sub-old", "nesbox-tip", "upstream_commit", "upstream"),
]
with mock.patch.object(
upstream, "list_gitlinks",
side_effect=upstream.TruncatedListingError("tree listing truncated"),
), self.assertRaises(upstream.TruncatedListingError):
profiling_repos._follow_submodule(views, "cache", True)
class TruncatedGitlinksInTheResolver(unittest.TestCase):
"""A read-only report goes on past a partial listing, and says so."""
def test_the_lost_tree_yields_no_link_and_the_next_is_read(self):
from types import SimpleNamespace
views = [SimpleNamespace(repo="a", pin="p1"), SimpleNamespace(repo="b", pin="p2")]
state = SimpleNamespace(views=views, cache_dir="c", offline=True, name="demo")
def links(repo, sha, *_args):
if repo == "a":
raise upstream.TruncatedListingError("a@p1: tree listing truncated")
return {"sub": "s"}
with mock.patch.object(upstream, "list_gitlinks", side_effect=links), \
contextlib.redirect_stderr(io.StringIO()) as err:
found = [list(paths) for paths in resolver._Resolver.gitlinks_in_order(state)]
self.assertEqual(found, [[], ["sub"]])
self.assertIn("submodule paths unknown", err.getvalue())
class AMirrorOutlivesAGoneSource(unittest.TestCase):
"""yuzu's source answers 451. select_views stopped on it and never read