Point updater at Forgejo releases and Wolfskin assets
Some checks failed
review/code-gpt Request changes: version equivalence and lost positive asset-selection coverage

This commit is contained in:
justinzeus 2026-10-22 14:47:50 +02:00
parent 7d6f041b55
commit 0f7a23faa8
5 changed files with 238 additions and 72 deletions

View file

@ -1,11 +1,15 @@
package com.github.damontecres.wholphin.test
import com.github.damontecres.wholphin.services.UpdateChecker
import com.github.damontecres.wholphin.services.getDownloadUrl
import com.github.damontecres.wholphin.util.Version
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonArray
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.jsonArray
import kotlinx.serialization.json.jsonObject
import kotlinx.serialization.json.jsonPrimitive
import org.junit.Assert
import org.junit.Before
import org.junit.Test
@ -19,71 +23,104 @@ class TestUpdateChecker {
lateinit var releaseV108Json: JsonObject
val assetsV108Json: JsonArray by lazy { releaseV108Json["assets"]!!.jsonArray }
private fun read(filename: String): JsonObject {
private val forgejoLatest: JsonObject by lazy { read("forgejo_release_latest.json") }
private val forgejoAssets: JsonArray by lazy { forgejoLatest["assets"]!!.jsonArray }
private val forgejoReleases: JsonArray by lazy { readElement("forgejo_releases.json").jsonArray }
private fun readElement(filename: String): JsonElement {
val resource = javaClass.classLoader?.getResource(filename)
Assert.assertNotNull(resource)
val fileContents = Paths.get(resource!!.toURI()).readText()
return Json.parseToJsonElement(fileContents).jsonObject
return Json.parseToJsonElement(fileContents)
}
private fun read(filename: String): JsonObject = readElement(filename).jsonObject
private fun forgejoDownload(name: String) =
"https://git.justinvisser.org/justinzeus/wolfskin/releases/download/pwolfskin-v1.0.9-2-g3094fc8c/$name"
@Before
fun setup() {
releaseJson = read("release_develop.json")
}
// The GitHub fixtures are upstream Wholphin releases: their assets are named Wholphin*.apk, which
// the Wolfskin updater must not select.
@Test
fun `Release chooses release`() {
fun `Release does not choose upstream Wholphin assets`() {
val url = getDownloadUrl(assetsJson, false, listOf())
Assert.assertEquals("https://github.com/damontecres/Wholphin/releases/download/develop/Wholphin-release.apk", url)
Assert.assertNull(url)
}
@Test
fun `Choose abi`() {
fun `Choose abi does not choose upstream Wholphin assets`() {
val url = getDownloadUrl(assetsJson, false, listOf("arm64-v8a"))
Assert.assertEquals("https://github.com/damontecres/Wholphin/releases/download/develop/Wholphin-release-arm64-v8a.apk", url)
Assert.assertNull(url)
}
@Test
fun `Choose unknown abi`() {
fun `Choose unknown abi does not choose upstream Wholphin assets`() {
val url = getDownloadUrl(assetsJson, false, listOf("unknown"))
Assert.assertEquals("https://github.com/damontecres/Wholphin/releases/download/develop/Wholphin-release.apk", url)
Assert.assertNull(url)
}
@Test
fun `Debug chooses debug`() {
fun `Debug does not choose upstream Wholphin assets`() {
val url = getDownloadUrl(assetsJson, true, listOf())
Assert.assertEquals("https://github.com/damontecres/Wholphin/releases/download/develop/Wholphin-debug.apk", url)
Assert.assertNull(url)
}
@Test
fun `Choose debug abi`() {
fun `Choose debug abi does not choose upstream Wholphin assets`() {
val url = getDownloadUrl(assetsJson, true, listOf("arm64-v8a"))
Assert.assertEquals("https://github.com/damontecres/Wholphin/releases/download/develop/Wholphin-debug-arm64-v8a.apk", url)
Assert.assertNull(url)
}
@Test
fun `Test regular release`() {
fun `Test regular release does not choose upstream Wholphin assets`() {
releaseV108Json = read("release_v108.json")
getDownloadUrl(assetsV108Json, false, listOf("arm64-v8a")).let { url ->
Assert.assertEquals(
"https://github.com/damontecres/Wholphin/releases/download/v1.0.8/Wholphin-arm64-v8a.apk",
url,
)
}
getDownloadUrl(assetsV108Json, false, listOf("armeabi-v7a")).let { url ->
Assert.assertEquals(
"https://github.com/damontecres/Wholphin/releases/download/v1.0.8/Wholphin-armeabi-v7a.apk",
url,
)
}
getDownloadUrl(assetsV108Json, false, emptyList()).let { url ->
Assert.assertEquals(
"https://github.com/damontecres/Wholphin/releases/download/v1.0.8/Wholphin.apk",
url,
)
}
getDownloadUrl(assetsV108Json, true, listOf("arm64-v8a")).let { url ->
Assert.assertNull(url)
}
Assert.assertNull(getDownloadUrl(assetsV108Json, false, listOf("arm64-v8a")))
Assert.assertNull(getDownloadUrl(assetsV108Json, false, listOf("armeabi-v7a")))
Assert.assertNull(getDownloadUrl(assetsV108Json, false, emptyList()))
Assert.assertNull(getDownloadUrl(assetsV108Json, true, listOf("arm64-v8a")))
}
@Test
fun `Parse Forgejo latest release`() {
val release = UpdateChecker.parseRelease(forgejoLatest, debug = false, supportedABIs = listOf("arm64-v8a"))
checkNotNull(release)
Assert.assertEquals(Version.fromString("v1.0.9-2-g3094fc8c"), release.version)
Assert.assertEquals(forgejoDownload("Wolfskin-arm64-v8a.apk"), release.downloadUrl)
Assert.assertEquals("2026-10-20T09:05:00Z", release.publishedAt)
Assert.assertEquals(listOf("Subtitle preference fix"), release.notes)
}
@Test
fun `Choose Wolfskin asset for abi`() {
Assert.assertEquals(forgejoDownload("Wolfskin-arm64-v8a.apk"), getDownloadUrl(forgejoAssets, false, listOf("arm64-v8a")))
Assert.assertEquals(forgejoDownload("Wolfskin-armeabi-v7a.apk"), getDownloadUrl(forgejoAssets, false, listOf("armeabi-v7a")))
}
@Test
fun `Choose universal Wolfskin asset for unknown abi`() {
Assert.assertEquals(forgejoDownload("Wolfskin.apk"), getDownloadUrl(forgejoAssets, false, listOf("unknown")))
Assert.assertEquals(forgejoDownload("Wolfskin.apk"), getDownloadUrl(forgejoAssets, false, emptyList()))
}
@Test
fun `Debug asset is not offered when release has none`() {
Assert.assertNull(getDownloadUrl(forgejoAssets, true, listOf("arm64-v8a")))
}
@Test
fun `Find installed version in release list`() {
val release = UpdateChecker.findReleaseByVersion(forgejoReleases, Version.fromString("1.0.9-2-g3094fc8c"))
Assert.assertEquals("v1.0.9-2-g3094fc8c", release?.get("name")?.jsonPrimitive?.content)
}
@Test
fun `Find no release for version missing from list`() {
Assert.assertNull(UpdateChecker.findReleaseByVersion(forgejoReleases, Version.fromString("1.0.9-3-gffffff")))
}
}

View file

@ -0,0 +1,44 @@
{
"id": 42,
"name": "v1.0.9-2-g3094fc8c",
"tag_name": "pwolfskin-v1.0.9-2-g3094fc8c",
"body": "Wolfskin build\n<!-- app-note:Subtitle preference fix -->\n**Full Changelog**: https://git.justinvisser.org/justinzeus/wolfskin/compare/v1.0.8...v1.0.9",
"draft": false,
"prerelease": false,
"created_at": "2026-10-20T09:00:00Z",
"published_at": "2026-10-20T09:05:00Z",
"target_commitish": "3094fc8c",
"html_url": "https://git.justinvisser.org/justinzeus/wolfskin/releases/tag/pwolfskin-v1.0.9-2-g3094fc8c",
"assets": [
{
"id": 101,
"name": "Wolfskin.apk",
"size": 12345678,
"download_count": 3,
"created_at": "2026-10-20T09:05:00Z",
"uuid": "11111111-1111-1111-1111-111111111111",
"type": "attachment",
"browser_download_url": "https://git.justinvisser.org/justinzeus/wolfskin/releases/download/pwolfskin-v1.0.9-2-g3094fc8c/Wolfskin.apk"
},
{
"id": 102,
"name": "Wolfskin-arm64-v8a.apk",
"size": 7654321,
"download_count": 1,
"created_at": "2026-10-20T09:05:00Z",
"uuid": "22222222-2222-2222-2222-222222222222",
"type": "attachment",
"browser_download_url": "https://git.justinvisser.org/justinzeus/wolfskin/releases/download/pwolfskin-v1.0.9-2-g3094fc8c/Wolfskin-arm64-v8a.apk"
},
{
"id": 103,
"name": "Wolfskin-armeabi-v7a.apk",
"size": 6543210,
"download_count": 0,
"created_at": "2026-10-20T09:05:00Z",
"uuid": "33333333-3333-3333-3333-333333333333",
"type": "attachment",
"browser_download_url": "https://git.justinvisser.org/justinzeus/wolfskin/releases/download/pwolfskin-v1.0.9-2-g3094fc8c/Wolfskin-armeabi-v7a.apk"
}
]
}

View file

@ -0,0 +1,52 @@
[
{
"id": 44,
"name": "v1.0.10-0-gfeedbee",
"tag_name": "pwolfskin-v1.0.10-0-gfeedbee",
"body": "",
"draft": false,
"prerelease": false,
"created_at": "2026-10-22T08:00:00Z",
"published_at": "2026-10-22T08:05:00Z",
"target_commitish": "feedbee",
"html_url": "https://git.justinvisser.org/justinzeus/wolfskin/releases/tag/pwolfskin-v1.0.10-0-gfeedbee",
"assets": [
{
"id": 104,
"name": "Wolfskin.apk",
"size": 12345679,
"download_count": 0,
"created_at": "2026-10-22T08:05:00Z",
"uuid": "44444444-4444-4444-4444-444444444444",
"type": "attachment",
"browser_download_url": "https://git.justinvisser.org/justinzeus/wolfskin/releases/download/pwolfskin-v1.0.10-0-gfeedbee/Wolfskin.apk"
}
]
},
{
"id": 42,
"name": "v1.0.9-2-g3094fc8c",
"tag_name": "pwolfskin-v1.0.9-2-g3094fc8c",
"body": "Wolfskin build",
"draft": false,
"prerelease": false,
"created_at": "2026-10-20T09:00:00Z",
"published_at": "2026-10-20T09:05:00Z",
"target_commitish": "3094fc8c",
"html_url": "https://git.justinvisser.org/justinzeus/wolfskin/releases/tag/pwolfskin-v1.0.9-2-g3094fc8c",
"assets": []
},
{
"id": 40,
"name": "nightly",
"tag_name": "nightly",
"body": "",
"draft": false,
"prerelease": true,
"created_at": "2026-10-10T09:00:00Z",
"published_at": "2026-10-10T09:05:00Z",
"target_commitish": "main",
"html_url": "https://git.justinvisser.org/justinzeus/wolfskin/releases/tag/nightly",
"assets": []
}
]