fix: clear compiler warnings in quartz, commons, marmotBench and quic-interop

Fixes the Kotlin warnings the compiler reports for these modules across the
jvm, android, linuxX64 and metadata compilations:

- PartialTokensTest / marmotBench: drop redundant casts. kotlin.test's
  assertTrue carries a `returns() implies` contract, so the `is` check
  already smart-casts; the benchmark values were never nullable-typed.
- MarmotPublish*Test, LastResortKeyPackageReuseTest: name overridden
  parameters as the supertype does (`retainedSecrets`, `snapshot`), so
  named-argument calls through the interface stay correct.
- AuthOutcomeTest: PersistentMap.put is deprecated in favour of putting(),
  which is what the rest of the codebase already uses.
- IndexableContentGoldenTest: drop an unnecessary !! on a non-null String.
- Nip46Test: the generic encode/decode round trip cannot be checked at
  runtime, so suppress UNCHECKED_CAST with a note on why it is safe.
- InternTradeoffBenchmark: hoist the liveness anchor from a local to a
  field. As a local its assignments were visible to data flow, which folded
  the trailing `check(sink != null)` into a constant.
- Http3GetClient: an empty `else -> {}` branch instead of a bare `Unit`
  expression statement.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0123kXtseu4X18hL3GMDcdER
This commit is contained in:
Claude
2026-09-12 15:31:21 +00:00
parent 0629b23b1a
commit a4b83b86e7
10 changed files with 25 additions and 19 deletions
@@ -38,7 +38,7 @@ class PartialTokensTest {
fun aHalfWrittenFromOpensThePeoplePicker() {
val picker = pickerAtEnd("zaps from:ali")
assertTrue(picker is ActivePicker.People)
assertEquals(KeyField.FROM, (picker as ActivePicker.People).keyField)
assertEquals(KeyField.FROM, picker.keyField)
assertEquals("ali", picker.token.partial)
assertEquals(5, picker.token.start)
}
@@ -65,7 +65,7 @@ class PartialTokensTest {
fun aHalfWrittenDateOpensTheCalendar() {
val picker = pickerAtEnd("since:2026-0")
assertTrue(picker is ActivePicker.Calendar)
assertEquals(DateField.SINCE, (picker as ActivePicker.Calendar).dateField)
assertEquals(DateField.SINCE, picker.dateField)
}
@Test
@@ -461,9 +461,9 @@ class MarmotPublishBeforeApplyTest {
override suspend fun saveRetainedEpochs(
nostrGroupId: String,
epochs: List<ByteArray>,
retainedSecrets: List<ByteArray>,
) {
retained[nostrGroupId] = epochs
retained[nostrGroupId] = retainedSecrets
}
override suspend fun loadRetainedEpochs(nostrGroupId: String): List<ByteArray> = retained[nostrGroupId] ?: emptyList()
@@ -105,9 +105,9 @@ class MarmotPublishDurabilityTest {
override suspend fun saveRetainedEpochs(
nostrGroupId: String,
epochs: List<ByteArray>,
retainedSecrets: List<ByteArray>,
) {
retained[nostrGroupId] = epochs
retained[nostrGroupId] = retainedSecrets
}
override suspend fun loadRetainedEpochs(nostrGroupId: String): List<ByteArray> = retained[nostrGroupId].orEmpty()
@@ -24,12 +24,10 @@ import com.vitorpamplona.amethyst.commons.marmot.MarmotManager
import com.vitorpamplona.amethyst.commons.marmot.ingest
import com.vitorpamplona.quartz.marmot.appComponents.GroupProfileV1
import com.vitorpamplona.quartz.marmot.mip00KeyPackages.KeyPackageEvent
import com.vitorpamplona.quartz.marmot.mip03GroupMessages.GroupEvent
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair
import com.vitorpamplona.quartz.nip01Core.signers.NostrSignerInternal
import com.vitorpamplona.quartz.nip59Giftwrap.wraps.GiftWrapEvent
import com.vitorpamplona.quartz.utils.RandomInstance
import kotlinx.coroutines.runBlocking
@@ -170,7 +168,7 @@ fun benchJoinWelcome(): BenchResult =
}
},
) { (bob, wrap) ->
runBlocking { bob.manager.ingest(wrap as GiftWrapEvent) }
runBlocking { bob.manager.ingest(wrap) }
}
/**
@@ -223,7 +221,7 @@ fun benchIngestAppMessage(members: Int): BenchResult =
}
},
) { (bob, event) ->
runBlocking { bob.manager.ingest(event as GroupEvent) }
runBlocking { bob.manager.ingest(event) }
}
private const val BENCH_RELAY = "wss://bench.invalid"
@@ -56,6 +56,10 @@ internal class Nip46Test {
sig = "ec39e60722a083cccbd2d82d2827e13f5499fa7cbcedac5b76011a844c077473adb629d50d01fab147835ac6c8a3d5ba9aaddd87d6723f0c3c864b9119fc4356",
)
// The round trip is only type-safe by construction: the caller hands in a T,
// the message is encoded and decoded, and the decoder returns the same
// BunkerMessage subtype. The runtime has no way to check that.
@Suppress("UNCHECKED_CAST")
suspend fun <T : BunkerMessage> encodeDecodeEvent(req: T): T {
val eventStr = NostrConnectEvent.create(req, remoteKey.pubKey, signer).toJson()
@@ -61,7 +61,7 @@ class AuthOutcomeTest {
phase: RelayAuthSnapshot.Phase,
successCount: Int = 0,
) {
state.value = state.value.put(relay, RelayAuthSnapshot(phase, null, successCount))
state.value = state.value.putting(relay, RelayAuthSnapshot(phase, null, successCount))
}
}
@@ -245,8 +245,8 @@ class LastResortKeyPackageReuseTest {
override suspend fun load(): ByteArray? = bytes
override suspend fun save(data: ByteArray) {
bytes = data
override suspend fun save(snapshot: ByteArray) {
bytes = snapshot
}
override suspend fun delete() {
@@ -110,10 +110,16 @@ class InternTradeoffBenchmark {
}
}
/**
* Holds the last measured corpus so the JIT cannot drop the allocations we
* just paid for. A field rather than a local: a local's assignments are
* visible to the compiler's data flow, which then folds the `check` below
* into a constant.
*/
private var sink: Any? = null
@Test
fun internCostAndBenefit() {
var sink: Any? = null
println("\n=== corpus: $EVENTS events, $AUTHORS authors, $RELAYS relays ===")
// ---- memory ----
@@ -131,7 +131,7 @@ class IndexableContentGoldenTest {
}
}
val rejoined = visited.joinToString(event.indexableSeparator())
if (rejoined == event.indexableContent()) null else "kind $kind: visitor=${rejoined.take(120)!!} content=${event.indexableContent().take(120)}"
if (rejoined == event.indexableContent()) null else "kind $kind: visitor=${rejoined.take(120)} content=${event.indexableContent().take(120)}"
}
assertEquals("visitor and indexed content disagree", emptyList<String>(), disagreements)
}
@@ -203,9 +203,7 @@ class Http3GetClient(
body += frame.body
}
else -> {
Unit
}
else -> {}
}
}
}