fix: local builds bundle the addon packs they pin (#1908)

This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-10-31 23:32:58 -04:00
1 parent 8a7022fc14
commit 2ff3ab447d
3 files changed
+57 -1

No files matched your search

@@ -2,6 +2,9 @@ package com.droiddeck.launcher.core
import android.content.Context
import androidx.test.core.app.ApplicationProvider
import com.github.luben.zstd.ZstdOutputStream
import org.apache.commons.compress.archivers.tar.TarArchiveEntry
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream
import java.io.File
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
@@ -54,4 +57,35 @@ class AddonPackTest {
installed("b".repeat(64))
assertFalse(AddonPack("sample", "", 0L, listOf("tool"), reuseDeviceCopy = false).installed(context))
}
@Test fun localBuildInstallsTheBundledPackWithoutDownloading() {
val archive = tarZst("tool" to "x")
val pack = AddonPack("sample", Hashes.sha256(archive), archive.length(), listOf("tool"), bundle = { archive.inputStream() })
assertTrue(pack.await(context))
assertEquals("x", pack.file(context, "tool").readText())
}
@Test fun bundledPackWithTheWrongDigestIsRejected() {
val archive = tarZst("tool" to "x")
val pack = AddonPack("sample", "a".repeat(64), archive.length(), listOf("tool"),
bundle = { archive.inputStream() })
val copy = File(context.cacheDir, "copy.tar.zst")
assertFalse(pack.bundled(context, copy))
assertFalse(copy.exists())
}
private fun tarZst(vararg files: Pair<String, String>): File =
File(context.cacheDir, "sample-${System.nanoTime()}.tar.zst").apply {
TarArchiveOutputStream(ZstdOutputStream(outputStream())).use { tar ->
for ((path, text) in files) {
val bytes = text.toByteArray()
tar.putArchiveEntry(TarArchiveEntry(path).apply { size = bytes.size.toLong() })
tar.write(bytes)
tar.closeArchiveEntry()
}
}
}
}