refactor: Enable test coverage and update CI (#4233)

Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit is contained in:
James Rich 2026-01-15 18:47:45 -06:00 committed by GitHub
parent 45d8f5944a
commit 962137ae4d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 140 additions and 126 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2025 Meshtastic LLC
* Copyright (c) 2025-2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -14,19 +14,20 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.meshtastic.core.database
import android.app.Application
import android.content.Context
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.meshtastic.core.di.CoroutineDispatchers
@RunWith(AndroidJUnit4::class)
class DatabaseManagerLegacyCleanupTest {
@ -45,7 +46,9 @@ class DatabaseManagerLegacyCleanupTest {
app.openOrCreateDatabase(legacyName, Context.MODE_PRIVATE, null).close()
assertTrue("Precondition: legacy DB should exist before switch", legacyFile.exists())
val manager = DatabaseManager(app)
val testDispatchers =
CoroutineDispatchers(io = Dispatchers.IO, main = Dispatchers.Main, default = Dispatchers.Default)
val manager = DatabaseManager(app, testDispatchers)
// Switch to a non-null address so active DB != legacy
manager.switchActiveDatabase("01:23:45:67:89:AB")

View file

@ -29,17 +29,15 @@ import org.meshtastic.proto.TelemetryProtos
@Suppress("TooManyFunctions")
class Converters {
@TypeConverter
fun dataFromString(value: String): DataPacket {
val json = Json { isLenient = true }
return json.decodeFromString(DataPacket.serializer(), value)
private val json = Json {
isLenient = true
ignoreUnknownKeys = true
encodeDefaults = true
}
@TypeConverter
fun dataToString(value: DataPacket): String {
val json = Json { isLenient = true }
return json.encodeToString(DataPacket.serializer(), value)
}
@TypeConverter fun dataFromString(value: String): DataPacket = json.decodeFromString(DataPacket.serializer(), value)
@TypeConverter fun dataToString(value: DataPacket): String = json.encodeToString(DataPacket.serializer(), value)
@TypeConverter
fun bytesToFromRadio(bytes: ByteArray): MeshProtos.FromRadio = try {

View file

@ -227,13 +227,17 @@ interface PacketDao {
@Transaction
suspend fun updateMessageStatus(data: DataPacket, m: MessageStatus) {
val new = data.copy(status = m)
findDataPacket(data)?.let { update(it.copy(data = new)) }
// Find by packet ID first for better performance and reliability
findPacketsWithId(data.id).find { it.data == data }?.let { update(it.copy(data = new)) }
?: findDataPacket(data)?.let { update(it.copy(data = new)) }
}
@Transaction
suspend fun updateMessageId(data: DataPacket, id: Int) {
val new = data.copy(id = id)
findDataPacket(data)?.let { update(it.copy(data = new, packetId = id)) }
// Find by packet ID first for better performance and reliability
findPacketsWithId(data.id).find { it.data == data }?.let { update(it.copy(data = new, packetId = id)) }
?: findDataPacket(data)?.let { update(it.copy(data = new, packetId = id)) }
}
@Query(