mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-24 23:36:04 +00:00
fix(addons): CurseForge connects once, reuses its game instance and skips rescans after its own changes (#3081)
* fix(addons): CurseForge connects once, reuses its game instance and skips rescans after its own changes * fix(addons): a settled list is dropped by a refresh, a later change or a newer change * fix(curseforge): publish the report under the same lock as the turn check An older change could report its list after a newer one had already reported, so the fallback marks could miss add-ons the newer change installed.
This commit is contained in:
1 parent
963af6df8e
commit
6ecc5a22d3
7 files changed
+217
-29
No files matched your search
@@ -5,6 +5,7 @@ import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNotNull
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertThrows
|
||||
import org.junit.Assert.assertTrue
|
||||
@@ -158,6 +159,7 @@ class CurseForgeAppTest {
|
||||
assertTrue(text.startsWith("(() => { const w = require('electron').BrowserWindow.getAllWindows()"))
|
||||
assertTrue(text.contains("desktop.html"))
|
||||
assertTrue(text.contains("executeJavaScript("))
|
||||
assertTrue(text.contains("let m = globalThis.__droiddeckServices; if (!m || !m[\\\"ProjectAppService\\\"]) m = globalThis.__droiddeckServices = "))
|
||||
assertFalse(text.contains("show()"))
|
||||
val probe = CurseForgeApp.expression("InstalledProjectsAppService", "installAddon", null)
|
||||
assertFalse(probe.contains("await s["))
|
||||
@@ -292,6 +294,37 @@ class CurseForgeAppTest {
|
||||
assertTrue(calls.isEmpty())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aGameFolderCurseForgeAlreadyKnowsSkipsTheFolderDetection() {
|
||||
val flavor = "/root/Games/World of Warcraft/_retail_"
|
||||
val curse = fakeCurse(flavor = flavor)
|
||||
val context = org.robolectric.RuntimeEnvironment.getApplication()
|
||||
assertEquals("g", CurseForgeApp.instance(context, url, "/root/Games/World of Warcraft", flavor))
|
||||
assertFalse("detectGameFromPath" in curse.methods)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aGameFolderCurseForgeDoesNotKnowIsDetectedOnce() {
|
||||
val flavor = "/root/Games/World of Warcraft/_retail_"
|
||||
val curse = fakeCurse(flavor = flavor)
|
||||
curse.known = false
|
||||
val context = org.robolectric.RuntimeEnvironment.getApplication()
|
||||
assertEquals("g", CurseForgeApp.instance(context, url, "/root/Games/World of Warcraft", flavor))
|
||||
assertEquals(1, curse.methods.count { it == "detectGameFromPath" })
|
||||
assertEquals(listOf("getGameInstances", "detectGameFromPath", "getGameInstances"), curse.methods.filter { it != "connect" })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun curseForgeConnectsOncePerLaunch() {
|
||||
val curse = fakeCurse()
|
||||
val context = org.robolectric.RuntimeEnvironment.getApplication()
|
||||
val launched = "ws://127.0.0.1:43118/${java.util.UUID.randomUUID()}"
|
||||
CurseForgeApp.projects(context, launched, "g")
|
||||
CurseForgeApp.projects(context, launched, "g")
|
||||
CurseForgeApp.instance(context, launched, "/root", "")
|
||||
assertEquals(1, curse.methods.count { it == "connect" })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun theInspectorUrlIsRedactedFromCommandLogs() {
|
||||
val line = CurseForgeApp.evalArgv(url, "x", 1_000).joinToString(" ")
|
||||
@@ -305,6 +338,7 @@ class CurseForgeAppTest {
|
||||
val methods = java.util.Collections.synchronizedList(mutableListOf<String>())
|
||||
@Volatile var unreachableAfterDelete = false
|
||||
@Volatile var unreachable = false
|
||||
@Volatile var known = true
|
||||
|
||||
fun add(id: String, folder: String, status: Int) = add(id, listOf(folder), status)
|
||||
|
||||
@@ -328,8 +362,11 @@ class CurseForgeAppTest {
|
||||
projects.forEach { it.put("status", 1) }
|
||||
true
|
||||
}
|
||||
"detectGameFromPath" -> JSONObject().put("gameInstanceGuid", "g")
|
||||
"getGameInstances" -> JSONArray().put(JSONObject().put("guid", "g").put("installPath", flavor))
|
||||
"detectGameFromPath" -> {
|
||||
known = true
|
||||
JSONObject().put("gameInstanceGuid", "g")
|
||||
}
|
||||
"getGameInstances" -> if (known) JSONArray().put(JSONObject().put("guid", "g").put("installPath", flavor)) else JSONArray()
|
||||
"deleteMods" -> {
|
||||
projects.removeAll { p ->
|
||||
(p.getString("installedModId") in expression).also { gone ->
|
||||
@@ -467,7 +504,7 @@ class CurseForgeAppTest {
|
||||
curse.add("18808", "TomTom", 1)
|
||||
val before = CurseForgeApp.projects(context, url, "g", rescan = true).associate { it.id to it.update }
|
||||
assertEquals(mapOf("298842" to true, "18808" to false), before)
|
||||
assertTrue(CurseForgeApp.update(context, url, "g", "298842"))
|
||||
assertNotNull(CurseForgeApp.update(context, url, "g", "298842"))
|
||||
assertTrue("updateMod" in curse.methods)
|
||||
assertTrue(CurseForgeApp.projects(context, url, "g").none { it.update })
|
||||
}
|
||||
@@ -479,7 +516,7 @@ class CurseForgeAppTest {
|
||||
curse.add("298842", "Leatrix_Maps", 1)
|
||||
curse.add("18808", "TomTom", 1)
|
||||
val project = CurseForgeApp.owner(CurseForgeApp.projects(context, url, "g"), "Leatrix_Maps")!!
|
||||
assertTrue(CurseForgeApp.uninstall(context, url, "g", project))
|
||||
assertNotNull(CurseForgeApp.uninstall(context, url, "g", project))
|
||||
assertEquals(listOf("18808"), CurseForgeApp.projects(context, url, "g").map { it.id })
|
||||
assertFalse(File(curse.addOns, "Leatrix_Maps").exists())
|
||||
assertTrue(File(curse.addOns, "TomTom").isDirectory)
|
||||
|
||||
@@ -155,4 +155,37 @@ class LinuxNetworkLinkComponentTest {
|
||||
})
|
||||
assertEquals(before, link)
|
||||
}
|
||||
|
||||
@Test fun parallelPublishersFromSeparateComponentsAllLandAndLeaveNoStagedCopy() {
|
||||
val context = ApplicationProvider.getApplicationContext<Context>()
|
||||
val link = properties("10.0.0.1/24").route("1.0.0.0", 8).route("128.0.0.0", 1)
|
||||
val failures = java.util.concurrent.atomic.AtomicInteger()
|
||||
val threads = (0 until 8).map {
|
||||
Thread {
|
||||
val component = LinuxNetworkLinkComponent(context, temporary.root)
|
||||
repeat(25) {
|
||||
runCatching {
|
||||
ReflectionHelpers.callInstanceMethod<Unit>(component, "replace",
|
||||
from(java.io.File::class.java, temporary.root.resolve("etc/droiddeck-net").apply { parentFile!!.mkdirs() }),
|
||||
from(String::class.java, "if tun0 $it\n"))
|
||||
}.onFailure { failures.incrementAndGet() }
|
||||
}
|
||||
}.apply { start() }
|
||||
}
|
||||
threads.forEach { it.join() }
|
||||
assertEquals(0, failures.get())
|
||||
assertFalse(temporary.root.resolve("etc/droiddeck-net.staged").exists())
|
||||
assertEquals("if tun0 24\n", temporary.root.resolve("etc/droiddeck-net").readText())
|
||||
}
|
||||
|
||||
@Test fun anUnchangedFileIsNotRewritten() {
|
||||
val context = ApplicationProvider.getApplicationContext<Context>()
|
||||
val component = LinuxNetworkLinkComponent(context, temporary.root)
|
||||
val file = temporary.root.resolve("etc/resolv.conf").apply { parentFile!!.mkdirs(); writeText("nameserver 1.1.1.1\n") }
|
||||
assertTrue(file.setLastModified(1_000_000L))
|
||||
ReflectionHelpers.callInstanceMethod<Unit>(component, "replace", from(java.io.File::class.java, file), from(String::class.java, "nameserver 1.1.1.1\n"))
|
||||
assertEquals(1_000_000L, file.lastModified())
|
||||
ReflectionHelpers.callInstanceMethod<Unit>(component, "replace", from(java.io.File::class.java, file), from(String::class.java, "nameserver 8.8.8.8\n"))
|
||||
assertEquals("nameserver 8.8.8.8\n", file.readText())
|
||||
}
|
||||
}
|
||||
@@ -133,6 +133,88 @@ class CurseLinkTabTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun anInstallHandsCurseForgesSettledListToTheNextReadWithoutARescan() {
|
||||
val target = wow()
|
||||
val link = CurseLink(app)
|
||||
try {
|
||||
link.installed(context, target, 0)
|
||||
assertTrue(link.change(context, target) { CurseForgeApp.install(context, it.inspector, it.guid, "298842") })
|
||||
assertEquals(listOf("298842"), link.installed(context, target, 1).map { it.id })
|
||||
assertEquals(1, methods.count { it == "scanGameInstance" })
|
||||
link.installed(context, target, 2)
|
||||
assertEquals(2, methods.count { it == "scanGameInstance" })
|
||||
} finally {
|
||||
runBlocking { link.close(context).join() }
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aFailedInstallLeavesTheNextReadToRescan() {
|
||||
val target = wow()
|
||||
val link = CurseLink(app)
|
||||
try {
|
||||
link.installed(context, target, 0)
|
||||
assertFalse(link.change(context, target) { null })
|
||||
link.installed(context, target, 1)
|
||||
assertEquals(2, methods.count { it == "scanGameInstance" })
|
||||
} finally {
|
||||
runBlocking { link.close(context).join() }
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aRefreshAfterAnInstallStillRescans() {
|
||||
val target = wow()
|
||||
val link = CurseLink(app)
|
||||
try {
|
||||
link.installed(context, target, 0)
|
||||
assertTrue(link.change(context, target) { CurseForgeApp.install(context, it.inspector, it.guid, "298842") })
|
||||
link.refresh()
|
||||
link.installed(context, target, 1)
|
||||
assertEquals(2, methods.count { it == "scanGameInstance" })
|
||||
} finally {
|
||||
runBlocking { link.close(context).join() }
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aFailedChangeDropsAnEarlierSettledList() {
|
||||
val target = wow()
|
||||
val link = CurseLink(app)
|
||||
try {
|
||||
link.installed(context, target, 0)
|
||||
assertTrue(link.change(context, target) { CurseForgeApp.install(context, it.inspector, it.guid, "298842") })
|
||||
assertFalse(link.change(context, target) { null })
|
||||
link.installed(context, target, 1)
|
||||
assertEquals(2, methods.count { it == "scanGameInstance" })
|
||||
} finally {
|
||||
runBlocking { link.close(context).join() }
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun anOlderChangeFinishingLastDoesNotReplaceTheNewerList() {
|
||||
val target = wow()
|
||||
tocFolder(target.addOns, "Older", "1")
|
||||
tocFolder(target.addOns, "Newer", "2")
|
||||
val older = CurseForgeApp.Project("1", "11", listOf("Older"), false)
|
||||
val newer = CurseForgeApp.Project("2", "22", listOf("Newer"), false)
|
||||
val link = CurseLink(app)
|
||||
try {
|
||||
link.installed(context, target, 0)
|
||||
assertTrue(link.change(context, target) {
|
||||
assertTrue(link.change(context, target) { listOf(older, newer) })
|
||||
listOf(older)
|
||||
})
|
||||
assertEquals(setOf("1", "2"), CurseLink.lastReported(target).keys)
|
||||
assertEquals(listOf("1", "2"), link.installed(context, target, 1).map { it.id })
|
||||
assertEquals(1, methods.count { it == "scanGameInstance" })
|
||||
} finally {
|
||||
runBlocking { link.close(context).join() }
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aFailedScanKeepsTheLastReportInsteadOfClearingIt() {
|
||||
val target = wow()
|
||||
|
||||
Reference in new issue
Block a user