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

+11 -3
View File
@@ -906,10 +906,12 @@ class FbneoFetchReadsOneRevision(unittest.TestCase):
def tearDown(self):
self._tmp.cleanup()
def _head(self, repo: str, branch: str | None = None) -> str:
self.calls.append(f"{repo}@{branch}")
return "c0ffee"
def _api(self, url: str) -> object:
self.calls.append(url)
if "/commits/" in url:
return {"sha": "c0ffee"}
return [{
"type": "file", "name": "Demo.dat",
"sha": git_blob_sha(FBNEO_DAT),
@@ -927,6 +929,7 @@ class FbneoFetchReadsOneRevision(unittest.TestCase):
from scripts.scraper import base_scraper
with mock.patch.object(self.importer, "_api_json", self._api), \
mock.patch.object(self.importer, "fetch_branch_head", self._head), \
mock.patch.object(base_scraper, "download", self._download):
yield
@@ -941,11 +944,16 @@ class FbneoFetchReadsOneRevision(unittest.TestCase):
target, blobs = self.importer.fetch_pack("fbneo", "v1.0.0.02", self.dir)
self.assertEqual(
self.calls,
[f"{self.importer.FBNEO_API}/commits/v1.0.0.02",
["libretro/FBNeo@v1.0.0.02",
f"{self.importer.FBNEO_API}/contents/dats?ref=c0ffee"],
)
self.assertEqual(list(blobs), ["Demo.dat"])
def test_latest_reads_the_default_branch(self):
with self._patched():
self.importer.fetch_pack("fbneo", "latest", self.dir)
self.assertEqual(self.calls[0], "libretro/FBNeo@None")
def test_a_revision_import_is_labelled_and_leaves_the_tip_blobs(self):
import contextlib
import io