From e4d409634272dd4af325aa80817b965656857373 Mon Sep 17 00:00:00 2001 From: MaxsTechReview Date: Sat, 7 Nov 2026 15:48:09 -0500 Subject: [PATCH] fix(drivers): a driver repo that fails to answer no longer changes the Auto pick (#2233) * fix(drivers): a driver repo that fails to answer no longer changes the Auto pick The release check reads every driver repo and saved the list even when one of them failed, so that repo's drivers vanished until the next good check. When GitHub rate-limited or dropped the DroidDeck driver repo, Auto on an Adreno 6xx saw no DD-Turnip release, switched to Banner's Turnip, and then switched back after the next clean check. A repo that fails now keeps its releases from the last good check, while still being recorded as failed. A repo that answers and no longer lists a driver still drops it. * test(drivers): carry-over is checked through refresh with one repo failing * fix(drivers): drop a repo's partial results when its answer fails and keep the refresh test offline --- .../droiddeck/launcher/gpu/TurnipReleases.kt | 19 +++- .../gpu/TurnipReleasesCarryOverTest.kt | 103 ++++++++++++++++++ 2 files changed, 119 insertions(+), 3 deletions(-) create mode 100644 app/src/test/java/com/droiddeck/launcher/gpu/TurnipReleasesCarryOverTest.kt diff --git a/app/src/main/java/com/droiddeck/launcher/gpu/TurnipReleases.kt b/app/src/main/java/com/droiddeck/launcher/gpu/TurnipReleases.kt index 1936779cbd..020285d073 100644 --- a/app/src/main/java/com/droiddeck/launcher/gpu/TurnipReleases.kt +++ b/app/src/main/java/com/droiddeck/launcher/gpu/TurnipReleases.kt @@ -97,6 +97,7 @@ object TurnipReleases { // Venus): its driver pairs fall past the first 15, so it is read in one full page. val perPage = if (src.repo == NON_ADRENO_REPO) 100 else 15 val releases = JSONArray(get(context, "https://api.github.com/repos/${src.repo}/releases?per_page=$perPage")) + val found = JSONArray() val seen = HashSet() var newest: String? = null for (i in 0 until releases.length()) { @@ -114,12 +115,13 @@ object TurnipReleases { val label = kind.label val sha = Hashes.githubSha256(a.optString("digest")) ?: continue if (!seen.add(if (kind.bundle) kind.pair else "$linux|$label")) continue - assets.put(JSONObject().put("source", src.label).put("tag", tag).put("name", name) + found.put(JSONObject().put("source", src.label).put("tag", tag).put("name", name) .put("url", a.getString("browser_download_url")).put("size", a.optLong("size")) .put("linux", linux).put("label", label).put("sha256", sha).put("pair", kind.pair) .put("bundle", kind.bundle).put("id", a.optLong("id")).put("updated_at", a.optString("updated_at"))) } } + for (i in 0 until found.length()) assets.put(found.get(i)) if (newest != null) latest.put(JSONObject().put("source", src.label).put("tag", newest)) } catch (e: Exception) { failed.add(src.label) @@ -127,7 +129,8 @@ object TurnipReleases { } } if (failed.size == sources.size) throw lastError ?: IOException("no source answered") - runCatching { get(context, AutoPicks.URL, AutoPicks.URL) } + carryOver(failed, prefs(context).getString(KEY_RELEASE, null)?.let { runCatching { JSONObject(it) }.getOrNull() }, assets, latest) + runCatching { fetch(context, AutoPicks.URL, AutoPicks.URL) } .onFailure { Log.i(TAG, "auto picks: ${it.message}") } .getOrNull()?.takeIf { AutoPicks.parse(it) != null } ?.let { prefs(context).edit().putString(KEY_PICKS, it).apply() } @@ -137,12 +140,22 @@ object TurnipReleases { return parse(stored) } + internal var fetch: (Context, String, String) -> String = { context, source, url -> get(context, source, url) } + + internal fun carryOver(failed: List, previous: JSONObject?, assets: JSONArray, latest: JSONArray) { + if (previous == null || failed.isEmpty()) return + for ((key, into) in listOf("assets" to assets, "latest" to latest)) { + val old = previous.optJSONArray(key) ?: continue + for (i in 0 until old.length()) old.optJSONObject(i)?.takeIf { it.optString("source") in failed }?.let(into::put) + } + } + private fun get(context: Context, url: String): String { val sources = DownloadSource.candidates(url) var last: IOException? = null for ((index, source) in sources.withIndex()) { try { - val body = get(context, source, url) + val body = fetch(context, source, url) DownloadSource.succeeded(source) return body } catch (e: IOException) { diff --git a/app/src/test/java/com/droiddeck/launcher/gpu/TurnipReleasesCarryOverTest.kt b/app/src/test/java/com/droiddeck/launcher/gpu/TurnipReleasesCarryOverTest.kt new file mode 100644 index 0000000000..9bd3e0d655 --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/gpu/TurnipReleasesCarryOverTest.kt @@ -0,0 +1,103 @@ +package com.droiddeck.launcher.gpu + +import android.content.Context +import androidx.test.core.app.ApplicationProvider +import org.json.JSONArray +import org.json.JSONObject +import org.junit.Assert.assertEquals +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.annotation.Config + +@RunWith(RobolectricTestRunner::class) +@Config(manifest = Config.NONE) +class TurnipReleasesCarryOverTest { + private val context: Context = ApplicationProvider.getApplicationContext() + private val a644 = GpuInfo("Adreno 644", 644, GpuInfo.familyOf(true, 644), "", false) + + private fun asset(source: String, tag: String, name: String, pair: String, linux: Boolean = false, bundle: Boolean = false) = + JSONObject().put("source", source).put("tag", tag).put("name", name).put("url", "https://example/$name").put("size", 1L) + .put("linux", linux).put("label", "label").put("sha256", "0".repeat(64)).put("pair", pair).put("bundle", bundle) + + private val dd = asset("DroidDeck", "v0.4.0", "DD-Turnip-v0.4.0.zip", DriverPairs.ddTurnip("v0.4.0"), bundle = true) + private fun banner(tag: String) = listOf(asset("Banners-Turnip", tag, "Turnip-$tag.zip", DriverPairs.BANNER), + asset("Banners-Turnip", tag, "Turnip-$tag-Linux.zip", DriverPairs.BANNER, linux = true)) + + private fun previous() = JSONObject().put("assets", JSONArray().put(dd).apply { banner("r5").forEach(::put) }) + .put("latest", JSONArray().put(JSONObject().put("source", "DroidDeck").put("tag", "v0.4.0")) + .put(JSONObject().put("source", "Banners-Turnip").put("tag", "r5"))) + + private fun pick(assets: JSONArray, latest: JSONArray, failed: List): String? { + val stored = JSONObject().put("assets", assets).put("latest", latest).put("failed", JSONArray(failed)).put("checkedAt", 1L) + context.getSharedPreferences("turnip_releases", Context.MODE_PRIVATE).edit().putString("latest", stored.toString()).commit() + return DriverPairs.recommendedKey(a644, DriverPairs.from(TurnipReleases.cached(context))) + } + + @Test fun aRepoThatFailedToAnswerKeepsItsDriversFromTheLastCheck() { + val assets = JSONArray().apply { banner("r6").forEach(::put) } + val latest = JSONArray().put(JSONObject().put("source", "Banners-Turnip").put("tag", "r6")) + TurnipReleases.carryOver(listOf("DroidDeck"), previous(), assets, latest) + assertEquals(DriverPairs.ddTurnip("v0.4.0"), pick(assets, latest, listOf("DroidDeck"))) + assertEquals(listOf("r6", "r6", "v0.4.0"), (0 until assets.length()).map { assets.getJSONObject(it).getString("tag") }) + assertEquals(listOf("Banners-Turnip" to "r6", "DroidDeck" to "v0.4.0"), + (0 until latest.length()).map { latest.getJSONObject(it).let { l -> l.getString("source") to l.getString("tag") } }) + } + + @Test fun reposThatAnsweredAreNotDuplicatedOrRevived() { + val assets = JSONArray().apply { banner("r6").forEach(::put) } + val latest = JSONArray() + TurnipReleases.carryOver(emptyList(), previous(), assets, latest) + assertEquals(2, assets.length()) + assertEquals(DriverPairs.BANNER, pick(assets, latest, emptyList())) + } + + @Test fun withNoEarlierCheckAFailedRepoContributesNothing() { + val assets = JSONArray().apply { banner("r6").forEach(::put) } + val latest = JSONArray() + TurnipReleases.carryOver(listOf("DroidDeck"), null, assets, latest) + assertEquals(2, assets.length()) + assertEquals(0, latest.length()) + } + + @Test fun refreshKeepsTheDriversOfARepoThatFailedToAnswer() { + context.getSharedPreferences("turnip_releases", Context.MODE_PRIVATE).edit().putString("latest", previous().toString()).commit() + val release = JSONObject().put("tag_name", "r6").put("assets", JSONArray().apply { + for (name in listOf("Turnip-r6.zip", "Turnip-r6-Linux.zip")) put(JSONObject().put("name", name) + .put("browser_download_url", "https://example/$name").put("size", 1L).put("digest", "sha256:" + "0".repeat(64))) + }) + val original = TurnipReleases.fetch + TurnipReleases.fetch = { _, _, url -> + if ("Banners-Turnip" in url) JSONArray().put(release).toString() else throw java.io.IOException("rate limited") + } + try { + val check = TurnipReleases.refresh(context) + assertEquals(listOf("r6", "r6", "v0.4.0"), check.assets.map { it.tag }) + assertEquals(listOf("Banners-Turnip" to "r6", "DroidDeck" to "v0.4.0"), check.latest) + assertEquals(true, "DroidDeck" in check.failed) + assertEquals(DriverPairs.ddTurnip("v0.4.0"), DriverPairs.recommendedKey(a644, DriverPairs.from(check))) + } finally { TurnipReleases.fetch = original } + } + + @Test fun aRepoWhoseAnswerBreaksHalfwayKeepsOnlyItsDriversFromTheLastCheck() { + context.getSharedPreferences("turnip_releases", Context.MODE_PRIVATE).edit().putString("latest", previous().toString()).commit() + val release = JSONObject().put("tag_name", "r6").put("assets", JSONArray().apply { + for (name in listOf("Turnip-r6.zip", "Turnip-r6-Linux.zip")) put(JSONObject().put("name", name) + .put("browser_download_url", "https://example/$name").put("size", 1L).put("digest", "sha256:" + "0".repeat(64))) + }) + val original = TurnipReleases.fetch + TurnipReleases.fetch = { _, _, url -> + when { + "Banners-Turnip" in url -> JSONArray().put(release).put(JSONObject().put("assets", JSONArray())).toString() + "api.github.com" in url -> "[]" + else -> throw java.io.IOException("offline") + } + } + try { + val check = TurnipReleases.refresh(context) + assertEquals(true, "Banners-Turnip" in check.failed) + assertEquals(listOf("r5", "r5"), check.assets.map { it.tag }) + assertEquals(listOf("Banners-Turnip" to "r5"), check.latest) + } finally { TurnipReleases.fetch = original } + } +}