test(jetbrains): cover malformed CLI checksums

This commit is contained in:
kirillk
2026-08-04 09:46:11 -04:00
parent a957cc3803
commit f8197d869e
3 changed files with 29 additions and 0 deletions
@@ -4,6 +4,7 @@ import com.intellij.openapi.util.SystemInfo
import com.intellij.util.system.CpuArch
internal object KiloCliPlatform {
// Keep supported OS/architecture pairs in sync with Gradle CLI staging task platform lists.
fun current(): String {
val os = when {
SystemInfo.isMac -> "darwin"
@@ -118,6 +118,33 @@ class KiloCliDownloaderTest {
}
}
@Test
fun `falls back to github metadata when bundled checksum is malformed`() = runBlocking {
MockWebServer().use { server ->
val bytes = archive()
server.enqueue(metadata(bytes))
server.enqueue(MockResponse().setResponseCode(200).setBody(Buffer().write(bytes)))
val log = TestLog()
val cli = KiloCliDownloader(
log = log,
root = dir,
baseUrl = server.url("/release").toString(),
api = server.url("/api").toString(),
digests = mapOf(KiloCliPlatform.current() to "not-a-digest"),
).resolve("1.2.3")
assertTrue(cli.isFile)
assertContains(
log.messages,
"WARN: Ignoring malformed bundled Kilo CLI checksum for ${KiloCliPlatform.current()}: not-a-digest"
)
assertEquals("/api/v1.2.3", server.takeRequest().path)
assertEquals("/release/v1.2.3/kilo-${KiloCliPlatform.current()}.${KiloCliPlatform.archive()}", server.takeRequest().path)
assertEquals(2, server.requestCount)
}
}
@Test
fun `prunes stale versions and removes the extracted archive`() = runBlocking {
MockWebServer().use { server ->
@@ -20,6 +20,7 @@ abstract class WriteCliChecksumsTask : DefaultTask() {
private val DIGEST = Regex("^sha256:[a-f0-9]{64}$")
private val JSON = Json { ignoreUnknownKeys = true }
private const val API = "https://api.github.com/repos/Kilo-Org/kilocode/releases/tags"
// Keep in sync with KiloCliPlatform.current() and StageBundledCliTask.PLATFORMS.
private val PLATFORMS = listOf(
"darwin-arm64",
"darwin-x64",