mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-21 05:46:03 +00:00
feat(lab): build and run Lab builds of DroidDeck on the device itself (#2375)
* feat(lab): load an on-device Lab build over the installed app * feat(lab): build Lab builds on the device and report the APK commit to agents * fix(lab): dd-agent connects loopback adb before starting Claude Code * feat(lab): tell the app's own agent to continue after a Lab build restart * fix(lab): size the build heap from the device's memory * feat(lab): keep earlier Lab builds and list them in Updates * feat(lab): notify when DroidDeck comes back on a Lab build or turns one off * feat(lab): estimate the time left and compile the installed commit ahead of the first build * fix(lab): report a failed command as a failed build and update progress every five seconds * feat(lab): a kept build for another version can be rebuilt * feat(lab): record which installed commit the build caches are warm for * fix(lab): the app's agent hands its builds to the app, so they outlive the agent's turn * perf(lab): BuildConfig describes the installed base, so a Lab commit does not change it * perf(lab): compile with the Kotlin daemon, since in-process Kotlin compiles always redo the whole app * fix(lab): a build whose last task was up to date no longer counts as failed * feat(lab): dd-lab-build --explain logs why tasks ran and Kotlin's build report * fix(lab): keep a waiting build when another is staged or Lab is turned off, and never restart during a session * fix(lab): keep the installed build's label and exact commit, and refuse AppLanguage changes * fix(lab): setup verifies its downloads and waits for adb before preparing * fix(agent): quote apostrophes in opened URLs and keep the sign-in pid
This commit is contained in:
1 parent
2dbc007a95
commit
61031e3c4b
15 files changed
+1091
-5
No files matched your search
@@ -0,0 +1,154 @@
|
||||
package com.droiddeck.launcher.lab
|
||||
|
||||
import android.app.Application
|
||||
import com.droiddeck.launcher.BuildConfig
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNotNull
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
import java.io.File
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [33], manifest = Config.NONE)
|
||||
class LabOverlayTest {
|
||||
private lateinit var app: Application
|
||||
private lateinit var root: File
|
||||
private val injected = mutableListOf<File>()
|
||||
private val originalInject = LabOverlay.injectDex
|
||||
private val originalResources = LabOverlay.openResources
|
||||
|
||||
@Before fun prepare() {
|
||||
app = RuntimeEnvironment.getApplication()
|
||||
app.applicationInfo.sourceDir = "/data/app/~~test==/com.droiddeck.launcher-test==/base.apk"
|
||||
root = LabOverlay.root(app).apply { deleteRecursively(); mkdirs() }
|
||||
LabOverlay.injectDex = { _, apk -> injected += apk }
|
||||
LabOverlay.openResources = { null }
|
||||
}
|
||||
|
||||
@After fun restore() {
|
||||
LabOverlay.injectDex = originalInject
|
||||
LabOverlay.openResources = originalResources
|
||||
root.deleteRecursively()
|
||||
}
|
||||
|
||||
private fun stage(dir: String, commit: String = BuildConfig.SOURCE_COMMIT, apk: String = app.applicationInfo.sourceDir) =
|
||||
File(root, dir).apply {
|
||||
mkdirs()
|
||||
File(this, "overlay.apk").writeText("dex")
|
||||
File(this, "overlay.json").writeText("""{"label":"feat/x @ abc1234","baseCommit":"$commit","baseApk":"$apk"}""")
|
||||
}
|
||||
|
||||
@Test fun aBuildForThisInstallIsLoaded() {
|
||||
stage("active")
|
||||
LabOverlay.load(app, mainProcess = true)
|
||||
assertEquals("feat/x @ abc1234", LabOverlay.active?.label)
|
||||
assertEquals(listOf(File(root, "active/overlay.apk")), injected)
|
||||
assertEquals(1, LabOverlay.failedStarts(root))
|
||||
}
|
||||
|
||||
@Test fun aStagedBuildIsPromotedAtStart() {
|
||||
stage("next")
|
||||
File(root, "starts").writeText("2")
|
||||
LabOverlay.load(app, mainProcess = true)
|
||||
assertFalse(File(root, "next").exists())
|
||||
assertNotNull(LabOverlay.active)
|
||||
assertEquals(1, LabOverlay.failedStarts(root))
|
||||
}
|
||||
|
||||
@Test fun aBuildForAnotherInstallIsTurnedOff() {
|
||||
stage("active", commit = "0000000")
|
||||
LabOverlay.load(app, mainProcess = true)
|
||||
assertNull(LabOverlay.active)
|
||||
assertTrue(injected.isEmpty())
|
||||
assertFalse(File(root, "active").exists())
|
||||
assertEquals("OTHER_INSTALL", File(root, "last-off-reason").readText())
|
||||
}
|
||||
|
||||
@Test fun aBuildForAnEarlierInstallOfTheSameCommitIsTurnedOff() {
|
||||
stage("active", apk = "/data/app/old/base.apk")
|
||||
LabOverlay.load(app, mainProcess = true)
|
||||
assertNull(LabOverlay.active)
|
||||
assertEquals("OTHER_INSTALL", File(root, "last-off-reason").readText())
|
||||
}
|
||||
|
||||
@Test fun aBuildThatKeepsFailingToStartIsTurnedOff() {
|
||||
stage("active")
|
||||
File(root, "starts").writeText("2")
|
||||
LabOverlay.load(app, mainProcess = true)
|
||||
assertNull(LabOverlay.active)
|
||||
assertEquals("DID_NOT_START", File(root, "last-off-reason").readText())
|
||||
}
|
||||
|
||||
@Test fun otherProcessesLoadWithoutCountingStarts() {
|
||||
stage("active")
|
||||
LabOverlay.load(app, mainProcess = false)
|
||||
assertNotNull(LabOverlay.active)
|
||||
assertEquals(0, LabOverlay.failedStarts(root))
|
||||
}
|
||||
|
||||
@Test fun noBuildMeansNothingIsLoaded() {
|
||||
LabOverlay.load(app, mainProcess = true)
|
||||
assertNull(LabOverlay.active)
|
||||
assertTrue(injected.isEmpty())
|
||||
assertFalse(LabOverlay.promoted)
|
||||
}
|
||||
|
||||
@Test fun aNewBuildKeepsTheOneItReplaces() {
|
||||
stage("active")
|
||||
stage("next")
|
||||
LabOverlay.load(app, mainProcess = true)
|
||||
assertTrue(LabOverlay.promoted)
|
||||
val saved = LabOverlay.saved(app).single()
|
||||
assertEquals(LabOverlay.Reason.REPLACED, saved.reason)
|
||||
assertTrue(saved.usable)
|
||||
}
|
||||
|
||||
@Test fun aRefusedBuildIsKeptButNotUsable() {
|
||||
stage("active", commit = "0000000")
|
||||
LabOverlay.load(app, mainProcess = true)
|
||||
val saved = LabOverlay.saved(app).single()
|
||||
assertEquals(LabOverlay.Reason.OTHER_INSTALL, saved.reason)
|
||||
assertFalse(saved.usable)
|
||||
}
|
||||
|
||||
@Test fun aKeptBuildCanBeStagedAgain() {
|
||||
stage("active", commit = "0000000")
|
||||
LabOverlay.load(app, mainProcess = true)
|
||||
stage("active")
|
||||
LabOverlay.archive(root, File(root, "active"), LabOverlay.Reason.TURNED_OFF)
|
||||
val usable = LabOverlay.saved(app).first { it.usable }
|
||||
LabOverlay.stage(app, usable)
|
||||
assertNotNull(LabOverlay.pending(app))
|
||||
assertEquals(1, LabOverlay.saved(app).size)
|
||||
LabOverlay.load(app, mainProcess = true)
|
||||
assertTrue(LabOverlay.promoted)
|
||||
assertNotNull(LabOverlay.active)
|
||||
}
|
||||
|
||||
@Test fun stagingAKeptBuildKeepsTheOneThatWasWaiting() {
|
||||
stage("builds/1")
|
||||
stage("next")
|
||||
File(root, "next/overlay.json").writeText("""{"label":"feat/y @ def5678","baseCommit":"${BuildConfig.SOURCE_COMMIT}","baseApk":"${app.applicationInfo.sourceDir}"}""")
|
||||
LabOverlay.stage(app, LabOverlay.saved(app).single())
|
||||
assertEquals("feat/x @ abc1234", LabOverlay.pending(app)?.label)
|
||||
val kept = LabOverlay.saved(app).single()
|
||||
assertEquals("feat/y @ def5678", kept.info?.label)
|
||||
assertEquals(LabOverlay.Reason.REPLACED, kept.reason)
|
||||
}
|
||||
|
||||
@Test fun onlyTheNewestBuildsAreKept() {
|
||||
repeat(15) {
|
||||
stage("active")
|
||||
LabOverlay.archive(root, File(root, "active"), LabOverlay.Reason.TURNED_OFF)
|
||||
}
|
||||
assertEquals(12, LabOverlay.saved(app).size)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user