Merge branch 'mantra' into claude/serene-dubinsky-41325e

The ios build line, ten commits, against one nip30303 tag fix. Not a single
file is touched by both sides, so nothing had to be reconciled: this branch
changes TranslationArtifactVersionIdTag and adds TagRoundTripTest, and mantra
arrives with the Darwin ktor engine, the Room constructor, the gradle 9 stub
task, the pin bump and the comma sweep.

19543df2 wrote down the thing to check here: Phase 3 took the commas out of 84
commonTest names to get linkDebugTestIosArm64 past Kotlin/Native's "Name
contains illegal characters: ','", and nothing enforces it, so every merge
arriving with new commonTest files can quietly undo it. This one brings
TagRoundTripTest, whose six names carry no comma. Checked rather than assumed.
Apostrophes are fine -- the sweep kept "the artifact's kind" -- so "no tag
parses another tag's array" stands.

The pin bump is a chain of gitlinks and nothing else: e0d2b823 moves
lightning-kmp to e5b22f5, which moves bitcoin-kmp to 9e3c4f8, which moves
secp256k1-kmp to 8adf6911, onto the merged threshold tips. native/secp256k1 is
unchanged. All four were already in this worktree's object store, so the chain
followed offline.

testDebugUnitTest 605 and jvmTest 1227, both zero failures -- 599 and 1221
before this branch, plus the six new ones in each. The m3 audit is green.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Kgothatso NgakoandClaude Opus 5 committed 2026-10-03 01:24:22 +02:00
commit 7b504ae5fb
52 files changed
+718 -93

No files matched your search

+28
View File
@@ -153,11 +153,39 @@ kotlin {
if (org.gradle.internal.os.OperatingSystem.current().isMacOsX) {
iosMain.dependencies {
implementation(libs.sqldelight.native.driver)
// CIO has no TLS implementation on native ("TLS sessions are not
// supported on Native platform"), so every wss/https call it makes on
// a device fails at the handshake. Darwin (NSURLSession) is the engine
// apple targets must use.
implementation(libs.ktor.client.darwin)
}
}
}
}
/**
* Kotlin 2.4.10's release backend crashes linking this module's ios binaries:
*
* e: java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
* at org.jetbrains.kotlin.backend.konan.optimizations.StaticInitializersOptimization
* $InterproceduralAnalysis.getCalledInitializer(StaticInitializersOptimization.kt:244)
*
* `RemoveRedundantCallsToStaticInitializersPhase` -- an LTO pass, so only optimized links hit
* it, which is why the debug test binary links fine -- assumes every function in the call
* graph has at least one statement in its body, and something in this module's graph arrives
* with an empty one. The pass is an optimization only; disabling it costs the redundant
* initializer calls it would have removed and nothing else.
*
* Nothing matches this on a non-mac host, where no ios target is declared and so no
* KotlinNativeLink task exists.
*/
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink>().configureEach {
if (name.startsWith("linkRelease")) {
toolOptions.freeCompilerArgs.add("-Xdisable-phases=RemoveRedundantCallsToStaticInitializersPhase")
}
}
android {
namespace = "press.mantra.android"
compileSdk = libs.versions.android.compileSdk.get().toInt()
@@ -0,0 +1,6 @@
package press.mantra.compose.network
import io.ktor.client.engine.HttpClientEngineFactory
import io.ktor.client.engine.cio.CIO
internal actual fun platformHttpClientEngineFactory(): HttpClientEngineFactory<*> = CIO
@@ -5,17 +5,38 @@ import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.navigation.NavHostController
import coil3.ImageLoader
import coil3.compose.setSingletonImageLoaderFactory
import coil3.network.ktor3.KtorNetworkFetcherFactory
import io.ktor.client.HttpClient
import press.mantra.compose.network.platformHttpClientEngineFactory
import press.mantra.compose.ui.composable.navigation.MantraNavHost
import press.mantra.compose.ui.composable.widgets.ProvideSnackbarHost
import press.mantra.compose.ui.theme.MantraTheme
import fr.acinq.phoenix.PhoenixGlobal
/**
* Coil's default ktor fetcher builds a bare `HttpClient()`, whose engine is whichever the
* classpath happens to serve first. With CIO that means no TLS on ios, so images over
* https fail exactly like the relay sockets did. Pin the singleton loader to the same
* platform engine the sockets use.
*/
private val imageHttpClient by lazy { HttpClient(platformHttpClientEngineFactory()) }
@Composable
fun MantraApp(
navController: NavHostController,
mantraGlobal: MantraGlobal,
phoenixGlobal: PhoenixGlobal
) {
setSingletonImageLoaderFactory { context ->
ImageLoader.Builder(context)
.components {
add(KtorNetworkFetcherFactory(httpClient = { imageHttpClient }))
}
.build()
}
MantraTheme {
Surface(
modifier = Modifier.fillMaxSize()
@@ -2,6 +2,7 @@ package press.mantra.compose.database
import androidx.room3.ColumnTypeConverters
import androidx.room3.AutoMigration
import androidx.room3.ConstructedBy
import androidx.room3.Database
import androidx.room3.RoomDatabase
import androidx.room3.immediateTransaction
@@ -366,6 +367,7 @@ val GENESIS_AT = Instant.fromEpochMilliseconds(1231006505000L)
AutoMigration(from = 21, to = 22),
]
)
@ConstructedBy(MantraDatabaseConstructor::class)
@ColumnTypeConverters(MantraConverters::class)
abstract class MantraDatabase: RoomDatabase() {
abstract fun broadcastNostrEventReceiptDao(): BroadcastNostrEventReceiptDao
@@ -0,0 +1,11 @@
package press.mantra.compose.network
import io.ktor.client.engine.HttpClientEngineFactory
/**
* The engine every Ktor client in the app is built on. CIO serves android and the desktop
* jvm; on apple targets its TLS layer does not exist (`TLS sessions are not supported on
* Native platform`), so every wss/https call fails at the handshake and ios uses Darwin
* (NSURLSession) instead.
*/
internal expect fun platformHttpClientEngineFactory(): HttpClientEngineFactory<*>
@@ -28,5 +28,6 @@ interface EventPublishTransport {
*
* @see RelayPool.publishEvent
*/
@Throws(press.mantra.compose.exceptions.NostrPublishException::class, kotlin.coroutines.cancellation.CancellationException::class)
suspend fun publishEvent(nostrEvent: NostrEvent, relays: Set<RelayDTO>): Flow<NostrPublishResult>
}
@@ -286,7 +286,7 @@ class RelayPool(
)
}
@Throws(press.mantra.compose.exceptions.NostrPublishException::class)
@Throws(press.mantra.compose.exceptions.NostrPublishException::class, kotlin.coroutines.cancellation.CancellationException::class)
suspend fun publishEvent(nostrEvent: press.mantra.compose.database.model.NostrEvent, relays: Set<press.mantra.compose.network.dto.RelayDTO> = emptySet()): Flow<NostrPublishResult> {
val relayUrls = relays.map { NormalizedRelayUrl(it.url).displayUrl() }
@@ -100,7 +100,7 @@ class RelaysSocketManager(
relayPool.closePool()
}
@Throws(press.mantra.compose.exceptions.NostrPublishException::class)
@Throws(press.mantra.compose.exceptions.NostrPublishException::class, kotlin.coroutines.cancellation.CancellationException::class)
suspend fun publishEvent(nostrEvent: press.mantra.compose.database.model.NostrEvent): Flow<NostrPublishResult> {
return if (userRelays.isNotEmpty()) {
relayPool.publishEvent(
@@ -115,7 +115,7 @@ class RelaysSocketManager(
}
}
@Throws(press.mantra.compose.exceptions.NostrPublishException::class)
@Throws(press.mantra.compose.exceptions.NostrPublishException::class, kotlin.coroutines.cancellation.CancellationException::class)
override suspend fun publishEvent(nostrEvent: press.mantra.compose.database.model.NostrEvent, relays: Set<press.mantra.compose.network.dto.RelayDTO>): Flow<NostrPublishResult> {
logger.d("publishEvent: $nostrEvent")
return relayPool.publishEvent(
@@ -4,10 +4,11 @@ import io.ktor.client.HttpClient
import io.ktor.client.plugins.websocket.WebSockets
import io.ktor.serialization.kotlinx.KotlinxWebsocketSerializationConverter
import kotlinx.serialization.json.Json
import press.mantra.compose.network.platformHttpClientEngineFactory
internal val defaultSocketsHttpClient by lazy {
HttpClient {
HttpClient(platformHttpClientEngineFactory()) {
install(WebSockets) {
contentConverter = KotlinxWebsocketSerializationConverter(Json {
isLenient = true
@@ -30,7 +30,7 @@ class NostrPublisherRepository(
}
}
@Throws(press.mantra.compose.exceptions.NostrPublishException::class)
@Throws(press.mantra.compose.exceptions.NostrPublishException::class, kotlin.coroutines.cancellation.CancellationException::class)
private suspend fun publishAndImportEvent(signedNostrEvent: press.mantra.compose.database.model.NostrEvent, outboxRelays: List<String> = emptyList()) {
relaysSocketManager.publishEvent(signedNostrEvent)
importEvent(signedNostrEvent)
@@ -52,7 +52,7 @@ class NostrPublisherRepository(
}
}
@Throws(press.mantra.compose.exceptions.NostrPublishException::class, press.mantra.compose.exceptions.SignatureException::class)
@Throws(press.mantra.compose.exceptions.NostrPublishException::class, press.mantra.compose.exceptions.SignatureException::class, kotlin.coroutines.cancellation.CancellationException::class)
suspend fun signPublishImportNostrEvent(
unsignedNostrEvent: press.mantra.compose.database.model.UnsignedNostrEvent,
outboxRelays: List<String>,
@@ -63,7 +63,7 @@ class NostrPublisherRepository(
}
@Throws(press.mantra.compose.exceptions.NostrPublishException::class, press.mantra.compose.exceptions.SignatureException::class)
@Throws(press.mantra.compose.exceptions.NostrPublishException::class, press.mantra.compose.exceptions.SignatureException::class, kotlin.coroutines.cancellation.CancellationException::class)
suspend fun publishRelayList(userId: String, relays: List<press.mantra.compose.network.dto.RelayDTO>): press.mantra.compose.database.model.NostrEvent {
val signedNostrEvent = nostrNotary.signRelayListMetadata(userId = userId, relays = relays).unwrapOrThrow()
relaysSocketManager.publishEvent(nostrEvent = signedNostrEvent, relays = relays.toSet())
@@ -61,7 +61,7 @@ class NostrEventFilterQueryTest {
/** AND between tag names, OR between the values of one name — as `FilterMatcher` does. */
@Test
fun `tags are matched by name and value, not by substring`() {
fun `tags are matched by name and value not by substring`() {
val query = NostrEventFilterQuery.build(
SynchronizationFilter(
kinds = arrayOf(1059),
@@ -161,7 +161,7 @@ class FrostSigningRoundTest {
}
@Test
fun `one signer set signs a batch of three, and every signature verifies`() {
fun `one signer set signs a batch of three and every signature verifies`() {
// The manager's batch, with the database taken out of the way: one signer
// set and one tweak cache shared, and a nonce, a Session and a signature
// per event. If any of that is wired up wrongly the aggregate simply
@@ -571,7 +571,7 @@ class FrostSigningCompletionTest {
}
@Test
fun `the finished event is the one that was proposed, with a signature on it`() {
fun `the finished event is the one that was proposed with a signature on it`() {
// Not rebuilt and not rehashed: the id a session is pinned to is the id
// the signature is over, so anything that changed here would produce an
// event whose signature verifies against nothing.
@@ -697,7 +697,7 @@ class GroupKeyStateTest {
}
@Test
fun `an event edited after signing fails on the id, not on the signature`() {
fun `an event edited after signing fails on the id not on the signature`() {
val signed = signedByRoom()
val tampered = Event(
@@ -951,7 +951,7 @@ class GroupKeyStateTest {
}
@Test
fun `two parents land as adjacent pairs, each id before its own certificate`() {
fun `two parents land as adjacent pairs each id before its own certificate`() {
// The one thing in this design that exists for *other people's* builds. A
// reader that predates several parents takes the first `parent_group` and
// the first `birth_certificate` and checks them against each other, so
@@ -989,7 +989,7 @@ class GroupKeyStateTest {
}
@Test
fun `a state claiming two parents keeps both, each with its own certificate`() {
fun `a state claiming two parents keeps both each with its own certificate`() {
// Two groups, two quorums, two signatures over the same child's id. The
// second one signed later and could not have named the first as a
// co-parent, which is why nothing requires the certificates to agree on
@@ -1071,7 +1071,7 @@ class GroupKeyStateTest {
}
@Test
fun `an uneven number of halves is refused, not completed from the other`() {
fun `an uneven number of halves is refused not completed from the other`() {
val certificate = birthCertificate()
val extraParent = GroupKeyStateEvent.assembleTags(
@@ -1094,7 +1094,7 @@ class GroupKeyStateTest {
}
@Test
fun `a half that is present and broken shifts nothing, because it is counted`() {
fun `a half that is present and broken shifts nothing because it is counted`() {
// Counted by tag name as well as by successful parse, so a broken half is
// told from one that was never written. Only the first would slide the
// pairing along by one and pair an id with somebody else's certificate.
@@ -128,7 +128,7 @@ class LiveInstanceCacheTest {
}
@Test
fun `does not run the block, or cache anything, when there is nothing to build`() = runBlocking {
fun `does not run the block or cache anything when there is nothing to build`() = runBlocking {
val cache = cache()
var ran = false
@@ -57,7 +57,7 @@ class LiveSubscriptionPlanTest {
* costs; it does not bound what arrives live.
*/
@Test
fun `the group filter asks for the given groups, and also carries no since`() {
fun `the group filter asks for the given groups and also carries no since`() {
val filter = groupFilter(listOf("group-a", "group-b"))
assertEquals(listOf(GroupEvent.KIND), filter.kinds)
@@ -145,7 +145,7 @@ class LiveSubscriptionPlanTest {
// --- what ends a live subscription -------------------------------------------------
@Test
fun `EOSE does not end a live subscription, CLOSED does`() {
fun `a live subscription ends on CLOSED and not on EOSE`() {
assertFalse(NostrIncomingMessage.EoseMessage(subscriptionId = "s").endsLiveSubscription())
assertFalse(NostrIncomingMessage.EventMessage(subscriptionId = "s").endsLiveSubscription())
assertFalse(NostrIncomingMessage.NoticeMessage(message = "hi").endsLiveSubscription())
@@ -72,7 +72,7 @@ class MarmotMip03CarveOutTest {
}
@Test
fun `a sender with no credential identity is rejected, wrap or not`() {
fun `a sender with no credential identity is rejected wrap or not`() {
// Required rather than merely compared: with no identity there is nothing to
// attribute a line to, and for a gift wrap there is nothing to check the seal
// against either. Both kinds must fail, not just the one that does a comparison.
@@ -58,7 +58,7 @@ class SharedKeyDerivationTest {
}
@Test
fun `each step commits to the key it tweaks, so depth is not interchangeable`() {
fun `each step commits to the key it tweaks so depth is not interchangeable`() {
// Index 0 applied once is not index 0 applied three times: the scalar binds
// the key being tweaked, so a shorter path cannot collide with a deeper one
// that happens to end on the same indices.
@@ -107,7 +107,7 @@ class SharedKeyDerivationTest {
}
@Test
fun `a hardened path is refused, not silently walked`() {
fun `a hardened path is refused not silently walked`() {
// Hardened derivation needs the parent private key, which nobody in a
// threshold group has. A path claiming one was never walked, so acting on it
// would mean deriving something different from what the room says.
@@ -157,7 +157,7 @@ class SignedArtifactTest {
}
@Test
fun `the artifact the group signs is authored by the group, not the proposer`() {
fun `the artifact the group signs is authored by the group not the proposer`() {
val artifact = MantraArtifact.fromArtifactEvent(signedArtifactEvent(), chatRoomId)
assertNotNull(artifact)
@@ -282,7 +282,7 @@ class SignedArtifactTest {
}
@Test
fun `the version is a second message, signed under its own nonce`() {
fun `the version is a second message signed under its own nonce`() {
// Two items of a batch are two independent FROST instances: k signatures
// over k ids, never one signature stretched over both. A version whose
// signature verified against the artifact's id would mean a nonce had
@@ -210,7 +210,7 @@ class SignedChapterTest {
}
@Test
fun `the chapter the group signs is authored by the group, not the proposer`() {
fun `the chapter the group signs is authored by the group not the proposer`() {
val chapter = MantraChapter.fromChapterEvent(signedChapterEvent(), chatRoomId)
assertNotNull(chapter)
@@ -103,7 +103,7 @@ class TranslationScaffoldTest {
}
@Test
fun `a catch-up keeps each chapter's own position, not the position in the gap`() {
fun `a catch-up keeps each chapter's own position not the position in the gap`() {
val chapters = (0..5).map(::sourceChapter)
// A catch-up proposes a subset, and the subset is not contiguous.
@@ -151,7 +151,7 @@ class TranslationScaffoldTest {
}
@Test
fun `what is missing is matched on the chapter named, not on how many there are`() {
fun `what is missing is matched on the chapter named not on how many there are`() {
val chapters = (0..3).map(::sourceChapter)
// Chapter 1 never landed but chapter 2 did, which a count would read as
@@ -48,7 +48,7 @@ class RelayPoolSubscriptionTest {
ReqCmd(subId = subId, filters = listOf(Filter(kinds = listOf(kind))))
@Test
fun `a query is retained, and replayed when its socket comes back`() = runTest {
fun `a query is retained and replayed when its socket comes back`() = runTest {
val factory = FakeSocketClientFactory()
val pool = pool(factory)
@@ -66,7 +66,7 @@ class RelayPoolSubscriptionTest {
}
@Test
fun `a closed query is forgotten, and the socket stops reconnecting for it`() = runTest {
fun `a closed query is forgotten and the socket stops reconnecting for it`() = runTest {
val factory = FakeSocketClientFactory()
val pool = pool(factory)
@@ -53,7 +53,7 @@ class ReconnectBackoffTest {
}
@Test
fun `adds at most the jitter fraction on top, never subtracts`() {
fun `adds at most the jitter fraction on top never subtracts`() {
assertEquals(4.seconds, delay(attempt = 3, jitter = 0.0))
assertEquals(5.seconds, delay(attempt = 3, jitter = 1.0))
@@ -22,7 +22,7 @@ class DirectMessagePeerSyncTest {
// --- the DM relays: everything a chat needs ----------------------------------------
@Test
fun `one request per DM relay, asking for the three kinds a chat needs`() {
fun `one request per DM relay asking for the three kinds a chat needs`() {
val requests = DirectMessagePeerSync.requests(alice)
assertEquals(Relays.DefaultDMRelayList.size, requests.size)
@@ -57,7 +57,7 @@ class DirectMessagePeerSyncTest {
// --- the indexers: the kind 0 alone -------------------------------------------------
@Test
fun `one request per bootstrap relay, asking for the kind 0 alone`() {
fun `one request per bootstrap relay asking for the kind 0 alone`() {
val requests = DirectMessagePeerSync.profileRequests(alice)
assertEquals(SignInSync.bootstrapRelays.size, requests.size)
@@ -38,7 +38,7 @@ class MarmotDeliveryTest {
)
@Test
fun `a signing proposal goes out, though nothing in the chat points at it`() {
fun `a signing proposal goes out though nothing in the chat points at it`() {
// The regression. A FROST message has no ChatMessage by design -- the manager
// writes its own transcript lines from what arrives, so a row here would be a
// second, worse account of the same thing -- and that must not be the reason the
@@ -65,7 +65,7 @@ class MarmotDeliveryTest {
}
@Test
fun `every relay gets a request, naming the event`() {
fun `every relay gets a request naming the event`() {
val delivery = MarmotDelivery.plan(groupEventId, relays, chatMessage = chatLine)
assertContentEquals(
@@ -76,7 +76,7 @@ class MarmotDeliveryTest {
}
@Test
fun `requests are queued pending, which is all the broadcaster looks at`() {
fun `requests are queued pending which is all the broadcaster looks at`() {
// `observeBroadcastNostrEventRequestsByStatus("pending")` is the only thing that
// picks these up. A request written in any other state is as unsent as no request.
val delivery = MarmotDelivery.plan(groupEventId, relays, chatMessage = null)
@@ -75,7 +75,7 @@ class MarmotDirectMessageDeliveryTest {
}
@Test
fun `our own message is ours, even though we cannot open it`() {
fun `our own message is ours even though we cannot open it`() {
// The case that destroys data if it is missed. Alice cannot decrypt the wrap she
// sent -- its key was discarded -- so nothing about the payload distinguishes this
// from a bystander's view. Only the MLS sender identity does. Were it to come back
@@ -67,7 +67,7 @@ class MarmotDirectMessageTest {
}
@Test
fun `a bystander gets nothing, and no exception`() {
fun `a bystander gets nothing and no exception`() {
// Null rather than a throw: the caller is midway through processing a kind:445
// that carries a real message for somebody, and an exception would abandon it.
assertNull(MarmotDirectMessage.open(aliceWrapsForBob(), eve))
@@ -103,7 +103,7 @@ class MarmotDirectMessageTest {
}
@Test
fun `a seal from somebody else is still opened, and is caught by its pubkey`() {
fun `a seal from somebody else is still opened and is caught by its pubkey`() {
// open() decrypts; it does not adjudicate. Eve can seal her own rumor to Bob and
// wrap it, and Bob's key will open it -- what stops it being rendered as Alice's
// is the inbound check that the seal's pubkey is the MLS sender's identity. This
@@ -29,7 +29,7 @@ class MemberProfileSyncTest {
* once their single ask comes back empty.
*/
@Test
fun `a placeholder counts as unknown, the same as no row at all`() {
fun `a placeholder counts as unknown the same as no row at all`() {
val rooms = listOf(
room(
members = listOf(
@@ -81,7 +81,7 @@ class MemberProfileSyncTest {
}
@Test
fun `one request per relay, asking those authors for kind zero`() {
fun `one request per relay asking those authors for kind zero`() {
val requests = MemberProfileSync.requests(listOf(alice, bob))
assertEquals(Relays.DefaultDMRelayList.size, requests.size)
@@ -19,7 +19,7 @@ class SignInSyncTest {
private fun relay(url: String) = RelayUrlNormalizer.normalize(url)
@Test
fun `the bootstrap asks every indexer and our own relay, once each`() {
fun `the bootstrap asks every indexer and our own relay once each`() {
val bootstrap = SignInSync.bootstrapRelays
assertTrue(bootstrap.containsAll(Relays.DefaultIndexerRelayList), "the indexers hold everyone's kinds 0, 3 and 10002")
@@ -29,7 +29,7 @@ class SignInSyncTest {
}
@Test
fun `one request per relay, all asking for the same things about the same key`() {
fun `one request per relay all asking for the same things about the same key`() {
val relays = listOf(relay("wss://one.example"), relay("wss://two.example"))
val requests = SignInSync.requests(unsignedNostrEventId = 7, publicKey = publicKey, relays = relays, level = 1)
@@ -47,7 +47,7 @@ class SignInSyncTest {
}
@Test
fun `a relay list yields its write relays, less those already asked`() {
fun `a relay list yields its write relays less those already asked`() {
val tags = arrayOf(
arrayOf("r", "wss://write.example", "write"),
arrayOf("r", "wss://both.example"),
@@ -60,7 +60,7 @@ class ChronicleEventTest {
// ---- The codec -------------------------------------------------------
@Test
fun `what is encoded is what comes back, whole`() {
fun `what is encoded is what comes back whole`() {
val events = listOf(
payload(DialectEvent.KIND, "isiZulu"),
payload(ArtifactEvent.KIND, "an artifact"),
@@ -168,7 +168,7 @@ class ChronicleEventTest {
}
@Test
fun `the byte cap counts bytes, not characters`() {
fun `the byte cap counts bytes not characters`() {
// A multi-byte payload that fits as characters and does not as bytes. If
// this were measured in characters the cap would let through up to four
// times what it says.
@@ -183,7 +183,7 @@ class ChronicleEventTest {
// ---- What a chronicle may carry ---------------------------------------
@Test
fun `the allowlist is every kind the group signs, and only those`() {
fun `the allowlist is every kind the group signs and only those`() {
listOf(
DialectEvent.KIND,
ArtifactEvent.KIND,
@@ -246,7 +246,7 @@ class ChronicleEventTest {
}
@Test
fun `the translated text is chroniclable, now that the group signs it`() {
fun `the translated text is chroniclable now that the group signs it`() {
// Worth its own case because it was the feature's headline limitation for
// as long as `saveTranslation` wrote the row and queued the member's own
// rumor. A chronicle can only carry what the receiver can check, so a
@@ -269,7 +269,7 @@ class ChronicleEventTest {
}
@Test
fun `a chronicle may not carry a key state, however well signed`() {
fun `a chronicle may not carry a key state however well signed`() {
// The attack the allowlist exists for, and the reason it is an allowlist
// rather than a denylist. A GroupKeyStateEvent is signed by the room and
// passes verification perfectly, so a chronicle carrying an old one is a
@@ -298,7 +298,7 @@ class ChronicleEventTest {
}
@Test
fun `a chronicle carries documents, not envelopes or protocol`() {
fun `a chronicle carries documents not envelopes or protocol`() {
assertFalse(ChronicleEvent.isChroniclable(SubmissionEvent.KIND))
assertFalse(ChronicleEvent.isChroniclable(ChronicleEvent.KIND))
assertFalse(ChronicleEvent.isChroniclable(ChronicleRequestEvent.KIND))
@@ -320,7 +320,7 @@ class ChronicleEventTest {
// ---- Dependency order ------------------------------------------------
@Test
fun `the order is the foreign keys, not the kind numbers`() {
fun `the order is the foreign keys not the kind numbers`() {
fun rank(kind: Int) = assertNotNull(ChronicleEvent.applyRank(kind), "kind $kind has no rank")
// Every one of these is a foreign key in Room, so a chronicle applied the
@@ -393,7 +393,7 @@ class ChronicleEventTest {
// ---- The tags --------------------------------------------------------
@Test
fun `a page says which chronicle it is, where in it, and who for`() {
fun `a page says which chronicle it is and where in it and who for`() {
val template = ChronicleEvent.build(
payloads = listOf(payload(DialectEvent.KIND)),
chronicleId = chronicleId,
@@ -451,7 +451,7 @@ class ChronicleEventTest {
// ---- What build refuses to make --------------------------------------
@Test
fun `a page is not built over either cap, or out of what it may not carry`() {
fun `a page is not built over either cap or out of what it may not carry`() {
// The outbound half of both checks. It is politeness rather than
// security -- the inbound one is the boundary -- but a page nobody can
// read back is better failed where it was made.
@@ -28,7 +28,7 @@ class FrostProposalCodecTest {
)
@Test
fun `a batch of one is the bare event, exactly as it always was`() {
fun `a batch of one is the bare event exactly as it always was`() {
val one = event("just this")
// The load-bearing assertion. A device on a build that predates batching
@@ -49,7 +49,7 @@ class FrostProposalCodecTest {
}
@Test
fun `what is encoded is what comes back, in order`() {
fun `what is encoded is what comes back in order`() {
val events = listOf(event("first"), event("second"), event("third"))
val decoded = FrostSigningEvents.decodeProposal(
@@ -65,7 +65,7 @@ class FrostProposalCodecTest {
}
@Test
fun `a bare event decodes as a batch of one, forever`() {
fun `a bare event decodes as a batch of one forever`() {
// Proposals in the old shape do not stop arriving just because this build
// stopped writing them.
val decoded = FrostSigningEvents.decodeProposal(event("from an older build").toJson())
@@ -61,7 +61,7 @@ class ArtifactEventTest {
}
@Test
fun `the proposal is the artifact's kind, so the signing screen can describe it`() {
fun `the proposal is the artifact's kind so the signing screen can describe it`() {
// The session carries a kind and nothing else to go on. Get this wrong
// and members are asked to sign "event of kind 30300" -- a question
// nobody can answer.
@@ -69,7 +69,7 @@ class ArtifactEventTest {
}
@Test
fun `an artifact declares one version, whatever an initializer adds`() {
fun `an artifact declares one version whatever an initializer adds`() {
// addUnique, not add: two labels would leave receivers deriving two
// different first versions depending on which one they read first.
val template = ArtifactEvent.build(
@@ -144,7 +144,7 @@ class ChapterProposalSizeTest {
}
@Test
fun `where the fit runs out, for a chapter-shaped chapter`() {
fun `where the fit runs out for a chapter-shaped chapter`() {
// Pinned so the number is on the record rather than in a comment, and so
// that a change to either event's tags shows up as a moved boundary
// instead of as a quorum that never arrives. Forty paragraphs is the
@@ -169,7 +169,7 @@ class ChapterProposalSizeTest {
}
@Test
fun `the text is measured in bytes, not in characters`() {
fun `the text is measured in bytes not in characters`() {
// The languages this app exists for are full of characters that are one
// UTF-16 unit and three bytes. Measuring by length would under-count a
// Setswana or Amharic chapter and the cap would stop binding exactly
@@ -191,7 +191,7 @@ class ChapterProposalSizeTest {
private val AddChapterMaxChunks: Int get() = FrostSigningManager.MAX_BATCH_SIZE - 1
@Test
fun `the chunk cap is one less than the batch, because the chapter takes a place`() {
fun `the chunk cap is one less than the batch because the chapter takes a place`() {
assertEquals(FrostSigningManager.MAX_BATCH_SIZE - 1, AddChapterMaxChunks)
}
}
@@ -77,7 +77,7 @@ class ProjectEventTest {
// --- owners are a set, and all of them survive ---
@Test
fun `three owners come back, sorted`() {
fun `three owners come back sorted`() {
val event = project(setOf(owner3, owner1, owner2))
// `addUnique` here would leave one. Sorted because the id is a hash over
@@ -243,7 +243,7 @@ class SubgroupBirthCertificateEventTest {
}
@Test
fun `a certificate carrying no parent, no key or no path is refused`() {
fun `a certificate carrying no parent no key or no path is refused`() {
listOf("parent_group", "subgroup_key", "frost_path").forEach { dropped ->
val incomplete = certificate(
tags = SubgroupBirthCertificateEvent.assembleTags(
@@ -359,7 +359,7 @@ class SubgroupBirthCertificateEventTest {
// signature against a room id, and a room id is a public key.
@Test
fun `in the parent's room, a certificate is about the room's own child`() {
fun `in the parent's room a certificate is about the room's own child`() {
assertEquals(
SubgroupManager.ArrivingCertificate.OurChild(subgroupChatRoomId),
SubgroupManager.classify(parentChatRoomId, certificate())
@@ -367,7 +367,7 @@ class SubgroupBirthCertificateEventTest {
}
@Test
fun `in the child's room, the same certificate is an offer to adopt it`() {
fun `in the child's room the same certificate is an offer to adopt it`() {
// The half of an adoption the child's members would otherwise never hear
// about until a proposal asked for their signature. One event, two
// meanings, and the room it arrived in is the whole of the difference.
@@ -398,7 +398,7 @@ class SubgroupBirthCertificateEventTest {
}
@Test
fun `a group is not its own child, however truthfully it says so`() {
fun `a group is not its own child however truthfully it says so`() {
// The one self-referential certificate `certifies` waves through: author,
// subject and named parent all one room, the id deriving from the key,
// the signature verifying. Refused before either branch -- read as an
@@ -446,7 +446,7 @@ class SubgroupBirthCertificateEventTest {
// asserting about it is where it stops.
@Test
fun `an unsigned proposal addresses its child, and certifies nothing`() {
fun `an unsigned proposal addresses its child and certifies nothing`() {
// What the ceremony screen is actually holding: the event as it was
// assembled, before anybody signed it. Any string in `sig` serves --
// the point is that no quorum has put one there.
@@ -472,7 +472,7 @@ class SubgroupBirthCertificateEventTest {
}
@Test
fun `a forgery by another group addresses the pair it names, and certifies nothing`() {
fun `a forgery by another group addresses the pair it names and certifies nothing`() {
// The reason `addresses` must never decide a lineage: anybody can author
// an event naming any pair, and this says yes to it. The guard is that
// nothing downstream of a lineage asks `addresses` -- only the screen
@@ -560,7 +560,7 @@ class SubgroupBirthCertificateEventTest {
}
@Test
fun `everything certifies addresses, so the weaker one cannot be the stricter`() {
fun `everything certifies addresses so the weaker one cannot be the stricter`() {
// `certifies` calls `addresses` and adds to it, and this is what keeps
// that true: a change that let one pass where the other refuses would
// mean two different answers to "which child is this about".
@@ -29,7 +29,7 @@ class SubgroupLineageTest {
}
@Test
fun `one parent cannot fail, because it has nothing to repeat`() {
fun `one parent cannot fail because it has nothing to repeat`() {
val lineage = SubgroupLineage.of(parentage(alpha))
assertEquals(1, lineage.size)
@@ -53,14 +53,14 @@ class SubgroupLineageTest {
}
@Test
fun `a room id is matched case-insensitively, because it is hex`() {
fun `a room id is matched case-insensitively because it is hex`() {
val lineage = SubgroupLineage.of(parentage(alpha))
assertTrue(lineage.names(alpha.uppercase()))
}
@Test
fun `the order is the parents' ids, whatever order they arrived in`() {
fun `the order is the parents' ids whatever order they arrived in`() {
// The whole reason this class sorts: two devices assembling one lineage
// from the same certificates have to emit the same bytes, or a reader
// that pairs the first tag of each name gets a mismatched pair.
@@ -82,7 +82,7 @@ class SubgroupLineageTest {
}
@Test
fun `adding a parent is an addition, not a replacement`() {
fun `adding a parent is an addition not a replacement`() {
// A key state is replaceable and the newest wins wholesale, so an
// adoption that carried only the new parent would silently drop the old
// one. Expressing it as an addition is what stops a caller assembling
@@ -99,7 +99,7 @@ class ChapterTextTest {
}
@Test
fun `utf16 is refused, because it is not supported rather than because it is binary`() {
fun `utf16 is refused because it is not supported rather than because it is binary`() {
// FF FE is a UTF-16LE byte order mark and an illegal UTF-8 lead byte, so
// this lands on NotText either way. Asserted so that a future lenient
// decode cannot quietly turn it into a chapter of interleaved NULs.
@@ -118,7 +118,7 @@ class ChapterTextTest {
}
@Test
fun `an empty file is text, not a failure`() {
fun `an empty file is text not a failure`() {
// Whether an empty chapter may be proposed is the form's decision; decode
// only says what the bytes were.
assertEquals("", decoded(ByteArray(0)))
@@ -30,7 +30,7 @@ class MarkdownBlockTest {
}
@Test
fun `the corpus is not empty, so a generator that wrote nothing fails`() {
fun `the corpus is not empty so a generator that wrote nothing fails`() {
assertEquals(true, MARKDOWN_BLOCK_FIXTURES.size >= 25)
}
}
@@ -76,7 +76,7 @@ class MarkdownProducerTest {
}
@Test
fun `a blockquote is quoted again, line by line`() {
fun `a blockquote is quoted again line by line`() {
val source = "> line one\n> line two\n"
// Two lines in, three out: the marker goes in front of every line, so a
@@ -42,7 +42,7 @@ class ProposedEventTest {
* contains and so the rest of what is being agreed to.
*/
@Test
fun `a chapter is named, measured, and counted`() {
fun `a chapter is named measured and counted`() {
val summary = ProposedEvent.summarize(chapter(name = "The wreck"), chunkCount = 4)
assertEquals("New chapter", summary.label)
@@ -67,7 +67,7 @@ class ProposedEventTest {
* handed -- the text here splits into two, and the batch says five.
*/
@Test
fun `the chunk count is the batch's, not a re-reading of the text`() {
fun `the chunk count is the batch's not a re-reading of the text`() {
val summary = ProposedEvent.summarize(
chapter(originalText = "One.\n\nTwo."),
chunkCount = 5,
@@ -77,7 +77,7 @@ class ProposedEventTest {
}
@Test
fun `with no batch to count, a chapter says nothing about chunks`() {
fun `with no batch to count a chapter says nothing about chunks`() {
// A transcript line, or a signed event on its own: there is no batch to
// ask, and guessing is what this parameter exists to stop.
val summary = ProposedEvent.summarize(chapter(name = "The wreck"))
@@ -86,7 +86,7 @@ class ProposedEventTest {
}
@Test
fun `a chunk is said as its own words, in its own place`() {
fun `a chunk is said as its own words in its own place`() {
// The chunks travel in the same batch as their chapter and are read
// under it, so each has to be checkable on its own.
val summary = ProposedEvent.summarize(
@@ -179,7 +179,7 @@ class ProposedEventTest {
}
@Test
fun `a project owned by somebody else says who, and not the room`() {
fun `a project owned by somebody else says who and not the room`() {
val summary = ProposedEvent.summarize(
project(setOf(roomId, outsider)),
chatRoomId = roomId
@@ -191,7 +191,7 @@ class ProposedEventTest {
}
@Test
fun `with no room to compare against, every owner is named`() {
fun `with no room to compare against every owner is named`() {
val summary = ProposedEvent.summarize(project(setOf(roomId, outsider)))
assertTrue(summary.detail.contains(roomId.take(12)), summary.detail)
@@ -45,7 +45,7 @@ class NavigationSuiteTest {
}
@Test
fun `nothing is drawn off a top-level destination, at any width`() {
fun `nothing is drawn off a top-level destination at any width`() {
// The component belongs on the destinations it switches between. On a chat room, a
// signing screen or an onboarding step -- reached by pushing a route and left by
// coming back -- a persistent bar is an invitation to lose your place.
@@ -176,7 +176,7 @@ class NavigationRoutingTest {
}
@Test
fun `asked from anywhere but startup, it sends the wallet up first`() = runTest {
fun `asked from anywhere but startup it sends the wallet up first`() = runTest {
val viewModel = bootedOn(account(signed = true))
viewModel.loadNostrProfile(startupRoute = null)
@@ -195,7 +195,7 @@ class NavigationRoutingTest {
* to one state, and Landing pops the back stack.
*/
@Test
fun `a key just imported is sent to fetch its profile, not to make one`() = runTest {
fun `a key just imported is sent to fetch its profile not to make one`() = runTest {
val viewModel = bootedOn(placeholderAccount())
viewModel.loadNostrProfile(SovereignWalletStartupRoute)
@@ -99,7 +99,7 @@ class UnsyncedProfileDecisionTest {
}
@Test
fun `a kind 0 that has arrived, indexed or not, is never not-found`() {
fun `a kind 0 that has arrived indexed or not is never not-found`() {
val event = NostrEvent(
id = "e".repeat(64),
pubKey = publicKey,
@@ -117,7 +117,7 @@ class UnsyncedProfileDecisionTest {
}
@Test
fun `no account, or no request yet, is still searching`() {
fun `no account or no request yet is still searching`() {
assertEquals(UnsyncedProfileUIState.Searching, UnsyncedProfileViewModel.decide(null))
assertEquals(UnsyncedProfileUIState.Searching, UnsyncedProfileViewModel.decide(account()))
}
@@ -32,7 +32,7 @@ class StartupChoiceTest {
}
@Test
fun `what a switch or a sign-in named is opened, even after the user once asked for the list`() {
fun `what a switch or a sign-in named is opened even after the user once asked for the list`() {
assertEquals(b, resolve(desired = b.id, startImmediately = false))
}
@@ -53,7 +53,7 @@ class StartupChoiceTest {
}
@Test
fun `a default the list no longer has, or no default, shows the list`() {
fun `a default the list no longer has or no default shows the list`() {
assertNull(resolve(default = WalletId("cc".repeat(20))))
assertNull(resolve())
}
@@ -141,7 +141,7 @@ class UploadChaptersStateTest {
}
@Test
fun `a failed proposal is still proposable, because a retry is a new proposal`() {
fun `a failed proposal is still proposable because a retry is a new proposal`() {
val chapters = listOf(row("tried", problem = UploadProblem.ProposalFailed))
assertEquals(listOf("tried"), state(chapters).proposable.map { it.id })
@@ -49,7 +49,7 @@ class UploadReviewTest {
}
@Test
fun `counts are of the decoded text, not of the file`() {
fun `counts are of the decoded text not of the file`() {
// CRLF in, LF counted: the row shows what would be signed.
val rows = reviewed(file("a.md", "One two.\r\n\r\nThree.\r\n"))
@@ -58,7 +58,7 @@ class UploadReviewTest {
}
@Test
fun `a file that is not text is refused, and blocks only its own row`() {
fun `a file that is not text is refused and blocks only its own row`() {
val rows = reviewed(
file("good.md", "Fine.\n"),
PickedFile("cover.png", byteArrayOf(0x89.toByte(), 0x50, 0x4E, 0x47, 0x00, 0x0D)),
@@ -1,7 +1,6 @@
package press.mantra.compose
import platform.UIKit.UIDevice
import kotlin.native.Platform
class IOSPlatform: Platform {
override val name: String = UIDevice.currentDevice.systemName() + " " + UIDevice.currentDevice.systemVersion
@@ -0,0 +1,6 @@
package press.mantra.compose.network
import io.ktor.client.engine.HttpClientEngineFactory
import io.ktor.client.engine.darwin.Darwin
internal actual fun platformHttpClientEngineFactory(): HttpClientEngineFactory<*> = Darwin
@@ -0,0 +1,6 @@
package press.mantra.compose.network
import io.ktor.client.engine.HttpClientEngineFactory
import io.ktor.client.engine.cio.CIO
internal actual fun platformHttpClientEngineFactory(): HttpClientEngineFactory<*> = CIO
+1
View File
@@ -21,6 +21,7 @@ silent, or a decision that looked arbitrary and was not.
| [npub-sign-in.md](./npub-sign-in.md) | signing in with only a public key — what a key that cannot sign can still see here, why that is a preview rather than a browser, and the four decisions the word settles |
| [multiple-profiles.md](./multiple-profiles.md) | several profiles on one device — why a profile is a credential and a seed is a wallet attached to one, why a switch is a restart rather than a swap, the two entrances the app lacks, and the inbox a switch would silently lose |
| [jvm-target.md](./jvm-target.md) | what desktop support cost, phased — why the native chain was already done, why an empty source set in our phoenix fork was the real blocker, and why DAO tests need none of it |
| [ios-build.md](./ios-build.md) | building for an iPhone, following the route the Curated fork walked — the five defects between here and a device, why the fork's "linux cinterop" fix is the one that makes a mac work, and the one annotation that unblocks native by changing every other target |
| [npub-profile-preview.md](./npub-profile-preview.md) | showing the person before a direct message is started from a pasted npub — why the preview is a screen keyed by public key, what "found" means when a row can be a placeholder, and the phase that makes the button honest about a key package that never comes |
| [chapter-uploads.md](./chapter-uploads.md) | picking files off a device and having the group sign each one in as a chapter — why N files can never be one signing session, and the four things the single-chapter path gets away with |
| [african-dialect-catalogue.md](./african-dialect-catalogue.md) | filling a group's dialects from a bundled catalogue of the languages most spoken in Africa — why a dialect is a language *in a country*, why nothing in the schema makes one unique so duplication has to be stopped at proposal time, and the race two admins hit if the picker cannot see what is already being signed |
+542
View File
@@ -0,0 +1,542 @@
# Bringing up the iOS target
What it takes to build and run Mantra on an iPhone, phased, following the route
the Curated fork already walked. Every one of its findings is diagnosed and
reproducible here, so the work is porting a known answer rather than
re-discovering it.
The headline is that almost nothing is missing. The `iosArm64` and
`iosSimulatorArm64` targets are **already declared** in
[composeApp/build.gradle.kts:36](../composeApp/build.gradle.kts), gated behind
`OperatingSystem.current().isMacOsX` the way everything in the composite chain is;
`composeApp/src/iosMain` holds ten `actual` files that match `jvmMain`'s ten
one-for-one, so no `expect` is unimplemented; `commonMain` has no `java.*` or
`javax.*` import anywhere; quartz 1.14.0 publishes `iosArm64` and
`iosSimulatorArm64` klibs; and `iosApp/` is byte-identical to Curated's apart from
brand tokens and one icon file, Xcode build phase and all.
What stands in the way is five concrete defects, which Curated hit in the order a
build hits them — configure, compile, link, connect, sign — and fixed in eight
commits.
## Where this stands
Phases 0 to 4 are **done and on this branch**, verified on a linux host; Phase 5
needs two decisions and an asset, and Phases 6 and 7 need a mac. Nothing below was
rewritten after the fact — each phase's text is as it was planned, with a
**Landed** note where what happened is worth knowing.
| phase | state | commit |
|---|---|---|
| 0 bootstrap and baseline | done — 1174 + 159 tests green | (no commit) |
| 1 advance the library chain | done — linux unchanged, as predicted | `a8f0e26f`, `1b8df6b4`, `dda2f95c` |
| 2 Room constructor and cancellation | done | `73b2c8ae`, `fc195832` |
| 3 unbreak the ios link tasks | done — linux half only | `d024838b` |
| 4 ktor on Darwin | done — android and jvm halves only | `e6c3c8a2` |
| 5 signing, icon, version | **not started** — needs decisions | — |
| 6 what only a mac can find | **not started** — needs a mac | — |
| 7 write down what it cost | in progress — this section | — |
`:composeApp:check` passes at the tip: lint, the m3 audit's ten counts, and all
three test suites — `jvmTest` 1174, `testDebugUnitTest` 563, the library's own 159.
Every count is the Phase 0 baseline, unmoved.
## The eight commits, and what each one is here
| Curated | what it did | how it lands here |
|---|---|---|
| `94de86a3`, `cbf23640`, `64b37447` | three gitlink bumps of `lightning-kmp-app`, carrying a secp256k1-kmp build fix | the same three bumps, verbatim — Mantra is pinned at their exact parent |
| `987df2c8` | `@ConstructedBy`, `@Throws(CancellationException)`, an unused import, `TEAM_ID` | the same, minus `TEAM_ID`, which is account-specific |
| `aa9312f0` | comma-free `commonTest` names, plus a disabled compiler phase | **rewritten**, not cherry-picked — see Phase 3 |
| `b9140c6a` | the Darwin ktor engine | near-verbatim; the shape it assumes is the shape here |
| `bd47c841` | app icon and `MARKETING_VERSION` | needs Mantra artwork |
| `a673c85e` | `versionName` | a release decision, not a port |
## What is already done for you
**The pin lines up exactly.** Mantra records `lightning-kmp-app` at
`84cc44c855e3d173e26016b807c449153a3af597`. That is the *parent* of Curated's
`94de86a3`. The three bumps are therefore a straight walk along the same gitlinks —
`84cc44c` → `2dcd4fb` → `db15e59` → `e0d2b82` — with no rebase and no divergence
to reconcile.
**The library's own iOS gating is already right.** `lightning-kmp-app/library`
declares `iosArm64()` and `iosSimulatorArm64()` under the same `isMacOsX` guard,
and sets `kotlin.native.enableKlibsCrossCompilation=true`. Nothing in the outer
build has to teach it about apple targets.
**`commonMain` is clean, and the publish surface is small.** One `HttpClient {`
construction in the whole module
([NostrSocketClientFactory.kt:10](../composeApp/src/commonMain/kotlin/press/mantra/compose/network/sockets/NostrSocketClientFactory.kt)),
no explicit Coil `ImageLoader` anywhere, six `@Throws` annotations on the publish
path. That is the same shape Curated's fixes were written against, so Phases 2 and
4 are small and exact rather than a search.
**The audit does not look at tests.** `docs/scripts/m3-audit.sh` scans
`composeApp/src/commonMain/kotlin/press/mantra/compose/ui` only, so Phase 3's sweep
over test names cannot trip `./gradlew check`.
## What actually blocks it
Five things, independent of each other except for the order the build reveals them
in:
1. **The chain will not configure on a mac.** secp256k1-kmp's `.def` declares
`staticLibraries` for every target and the cinterop tool refuses to emit a klib
while the archive is absent. Off a Linux host the Linux archives are never
built, so the IDE sync and configuration fail with `cinterop file ... does not
exist`. The fix — `9bcae25` in secp256k1-kmp, hardened by `8adf691` — stubs those
archives under `if (!currentOs.isLinux)`. Its commit subject says "linux
cinterop", which reads backwards from here: **it is the fix that makes the chain
work on a mac**, and it is a strict no-op on Linux.
2. **Room cannot construct the database on native.**
`MantraDatabaseConstructor` already exists in `commonMain`, `expect`,
`@Suppress`ed and referenced by nothing. Without `@ConstructedBy` naming it,
Room's KSP generates no `actual`, and on a target with no reflection there is no
other way in.
3. **Swift cannot see a cancellation as a cancellation.** Six `@Throws` sites on
the publish path name `NostrPublishException` and not
`kotlin.coroutines.cancellation.CancellationException`, so a cancelled publish
crosses the ObjC boundary as an unexpected throw.
4. **The iOS link tasks fail, twice over.** `linkDebugTestIosArm64` is rejected by
Kotlin/Native over backticked test names containing a comma (`Name contains
illegal characters: ','`), and `linkReleaseFrameworkIosArm64` crashes Kotlin
2.4.10's release backend inside `StaticInitializersOptimization`.
5. **Nothing secure connects on a device.** CIO has no TLS implementation on
Kotlin/Native — every `wss://` and `https://` call dies at the handshake with
`TLS sessions are not supported on Native platform`. The relay sockets and
Coil's image fetcher both sit on a default-engine client.
Everything below is ordered by that list.
---
## Phase 0 — bootstrap, and a recorded baseline
Nothing is changed in this phase. Its output is a green build to compare against,
because four of the five defects above are invisible until a mac is in the loop and
you do not want to be guessing afterwards which failure you introduced.
**In this worktree, initialise the chain first.** Four nested submodules —
`lightning-kmp-app` → `experimental/lightning-kmp` → `experimental/bitcoin-kmp` →
`experimental/secp256k1-kmp` (→ `native/secp256k1`) — are unpopulated, and gradle
dies early and confusingly with `Project with path ':library' not found`:
```bash
git -c protocol.file.allow=always submodule update --init --recursive
```
`protocol.file.allow=always` is required: the recorded url for `lightning-kmp-app`
is the main checkout's path, and git refuses `file` transport for submodules by
default. The last level (`native/secp256k1`, fetched from GitHub) can stall for
ten minutes or more; let the recursive call do what it can and finish that one
level from the main checkout's copy. Trust `git -C <level> rev-parse HEAD` per
level rather than `git submodule status --recursive`, which lies after a
per-level url override.
Then record the baseline:
```bash
ANDROID_HOME=$HOME/Android/Sdk ./gradlew :composeApp:compileDebugKotlinAndroid :composeApp:jvmTest :lightning-kmp-app:library:jvmTest
```
Note the jvmTest count and that it is green. `IdentitySwitchJvmTest`'s "last
profile opened" case fails about one run in nine on a 5s DataStore timeout on a
clean tree too — if you see exactly that, re-run before believing it.
**Deliverable:** no commit. A noted baseline.
---
## Phase 1 — advance the library chain
The three gitlink bumps, kept as three commits so each one says what it carries.
Walk the outer pin, and let the nested gitlinks come with it.
```bash
git -C lightning-kmp-app fetch https://github.com/kngako/lightning-kmp-app.git 'refs/heads/*:refs/remotes/github/*'
git -C lightning-kmp-app checkout --detach 2dcd4fbe1513421d100a4485583f167b1fdcd47c
git -c protocol.file.allow=always -C lightning-kmp-app submodule update --init --recursive
git add lightning-kmp-app && git commit
```
In a worktree the submodule's `origin` is the **main checkout's copy**, not GitHub,
so `git fetch origin` shows nothing new — fetch the `.gitmodules` url directly, as
above. Each bump moves `experimental/lightning-kmp` too, which moves `bitcoin-kmp`,
which moves `secp256k1-kmp`, so re-run `submodule update --init --recursive` inside
`lightning-kmp-app` after each checkout or the chain is left mid-walk.
The three, in order:
| commit | pin | what it carries |
|---|---|---|
| 1 | `2dcd4fb` | secp256k1-kmp `9bcae25` — the stub archives that let the chain configure off Linux |
| 2 | `db15e59` | the same fix merged into the `threshold` branches, so the nested gitlinks name branch tips rather than side commits |
| 3 | `e0d2b82` | secp256k1-kmp `8adf691` — registers the stub task with `tasks.register` instead of the delegate provider, which Gradle 9 requires |
Commits 2 and 3 look like bookkeeping and are not: without 3 the stub task is
never registered under a name, and without 2 the pins sit on commits that were
rebased away.
**Verify, on Linux.** The whole fix is behind `if (!currentOs.isLinux)`, so Linux
must be *unchanged*:
```bash
ANDROID_HOME=$HOME/Android/Sdk ./gradlew :composeApp:compileDebugKotlinAndroid :composeApp:jvmTest :lightning-kmp-app:library:jvmTest
```
Same test count, same green, as Phase 0. The library's own ~159 tests run inside
the composite build and are the thing that proves the wiring still gives it what it
expects.
**Verify, on a mac.** `./gradlew :composeApp:tasks` configures at all, and
`:composeApp:compileKotlinIosArm64` resolves `fr.acinq.phoenix:lightning-kmp-app`.
That is the phase's actual purpose.
> Suggested message, commit 1:
> `build: carry secp256k1-kmp's fix for configuring off a linux host`
> — and say in the body that the upstream subject reads the other way round.
**Landed** as `a8f0e26f`, `1b8df6b4`, `dda2f95c`. All five levels now sit exactly
where Curated's do: `e0d2b82` → `e5b22f5d` → `9e3c4f8` → `8adf691` → `7a35fde1`.
Two things worth knowing. First, the walk across all three bumps touches **no
Kotlin source anywhere in the chain** — the entire payload is eleven
`build.gradle.kts` and `settings.gradle.kts` files in secp256k1-kmp — so gradle
correctly reports `jvmTest UP-TO-DATE` afterwards. That reads like a stale cache
and is not one; a forced `--rerun` returns the same 1174 and 159.
Second, the bump carries four fixes beyond the stub archives, because
`a8cc3ec..8adf691` is seven commits rather than three: the `generateHeaders`
output paths (which were `generated./jni`, with a stray dot, and whose temp
directory was being cleared with a `delete()` that silently does nothing on a
non-empty directory), Gradle 10's removal of the delegated-property DSL, `Project`
objects passed as dependency notation, and `compileSdk 35` → `36` in
secp256k1-kmp's `jni/android`. The last of those is the only one that can touch an
android build here, and it is below Mantra's own 37.
---
## Phase 2 — declare the Room constructor and cancellation to Swift
Four small edits, one commit. All of it compiles on Linux.
**`@ConstructedBy`.** Add the import and the annotation above
[MantraDatabase.kt:369](../composeApp/src/commonMain/kotlin/press/mantra/compose/database/MantraDatabase.kt)'s
`@ColumnTypeConverters`:
```kotlin
import androidx.room3.ConstructedBy
…
@ConstructedBy(MantraDatabaseConstructor::class)
@ColumnTypeConverters(MantraConverters::class)
abstract class MantraDatabase: RoomDatabase() {
```
The `expect object` it names already exists and needs no edit. This is the one
change in the whole plan that **also changes the JVM and Android builds**: Room's
KSP starts generating an `actual` for every target rather than none, so the
annotation that unblocks iOS is the annotation most likely to move something
underneath `:composeApp:jvmTest`. Run it and read the output rather than assuming.
**Cancellation on the publish path.** Add
`kotlin.coroutines.cancellation.CancellationException::class` to the six existing
`@Throws`, and give `EventPublishTransport.publishEvent` one it does not have:
- [RelayPool.kt:289](../composeApp/src/commonMain/kotlin/press/mantra/compose/network/relays/RelayPool.kt)
- [RelaysSocketManager.kt:103](../composeApp/src/commonMain/kotlin/press/mantra/compose/network/relays/RelaysSocketManager.kt) and `:118`
- [NostrPublisherRepository.kt:33](../composeApp/src/commonMain/kotlin/press/mantra/compose/repository/NostrPublisherRepository.kt), `:55` and `:66`
- [EventPublishTransport.kt:31](../composeApp/src/commonMain/kotlin/press/mantra/compose/network/relays/EventPublishTransport.kt) — new, naming `NostrPublishException` as well
Keep the fully-qualified style the surrounding annotations already use.
**One unused import.** `import kotlin.native.Platform` in
[Platform.ios.kt](../composeApp/src/iosMain/kotlin/press/mantra/compose/Platform.ios.kt)
shadows the app's own `Platform` interface. Delete the line. Nothing on Linux
compiles `iosMain`, so this one is carried on Curated's word and the compiler's,
later.
**Verify, on Linux:** `:composeApp:compileDebugKotlinAndroid :composeApp:jvmTest`.
**On a mac:** `:composeApp:compileKotlinIosArm64`.
> `feat(ios): declare the Room constructor and publish cancellation to swift`
**Landed** as two commits rather than one — `73b2c8ae` for `@ConstructedBy` alone,
`fc195832` for the seven annotations and the import — because the first was the
only change in the plan with real linux-side risk and deserved to be readable on
its own.
The risk was real and benign. Room's KSP now emits an `actual object
MantraDatabaseConstructor` for **android and jvm as well**, each returning
`MantraDatabase_Impl()`, where before it emitted none at all and the `expect` sat
`@Suppress`ed and unreferenced. `jvmTest` is unmoved at 1174. A side effect worth
noting: `MantraDatabaseJvmTest`'s comment about the no-`Context` builder overload
being available "because `MantraDatabaseConstructor` gives Room a way to
instantiate without reflection" was aspirational when written and is now true.
---
## Phase 3 — unbreak the iOS link tasks
Two unrelated link failures, one commit, because they are the same symptom from the
outside: `./gradlew :composeApp:linkDebugTestIosArm64` and
`:composeApp:linkReleaseFrameworkIosArm64` both fail.
### The comma names — rewrite, do not cherry-pick
Curated's `aa9312f0` touched 38 `commonTest` files. **Ten of them do not exist
here** (`GroupEventProposalTest`, `CuratedSchemaEventTest`, `CuratedEntryEventTest`,
`CuratedSchemaTemplateTest`, `GroupCuratedEntryTest`, `GroupCuratedSchemaTest`,
`GroupPostTest`, `CuratedSuggestionTest`, `MarmotRoomIdentityTest`,
`MarmotPayloadBoundsTest`, `FrostSigningMembersTest`) — they belong to the fork's
curated-list and Marmot-v2 lines, neither of which Mantra has pulled. Meanwhile
Mantra has test files Curated does not: `ProjectEventTest`,
`ChapterProposalSizeTest`, `UploadChaptersStateTest`, `UploadReviewTest`,
`SubgroupLineageTest`, `MarkdownBlockTest`, `MarkdownProducerTest`,
`ChapterTextTest`.
So do the sweep over **Mantra's own tree**: 84 backticked `fun` names across 35
files in `composeApp/src/commonTest`. Every comma in every one of them is followed
by exactly one space — verified, no exceptions — so the rewrite is total and
unambiguous:
```bash
grep -rl 'fun `[^`]*,[^`]*`' composeApp/src/commonTest --include='*.kt' \
| xargs perl -i -pe 's/(fun `[^`]*`)/($x=$1)=~s{, }{ }g; $x/ge'
```
Then read the diff. A name losing its comma loses a little of its rhythm and none
of its meaning (`read as its kind, tags and content` → `read as its kind tags and
content`); if any of the 84 reads badly afterwards, reword that one by hand rather
than leaving a comma behind.
**Leave `jvmTest` alone.** It has 138 comma names and Kotlin/Native never compiles
it. Curated left it alone for the same reason, and widening the sweep would put 138
cosmetic edits in a commit that is about a link failure.
### The release backend crash
Append to `composeApp/build.gradle.kts`, after the `kotlin { }` block and before
`android {` at line 161 — the same place Curated put it:
```kotlin
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink>().configureEach {
if (name.startsWith("linkRelease")) {
toolOptions.freeCompilerArgs.add("-Xdisable-phases=RemoveRedundantCallsToStaticInitializersPhase")
}
}
```
With the comment Curated wrote, which is the valuable part: the pass is an LTO
optimization, so only optimized links reach it (which is why the debug test binary
links fine); it assumes every function in the call graph has at least one statement
in its body; something in this module's graph arrives with an empty one; and
disabling it costs the redundant initializer calls it would have removed and
nothing else.
`tasks.withType<KotlinNativeLink>()` matches nothing on Linux, so this is inert
there — but the class resolves from the KMP plugin's classpath on any host, so the
script still has to compile. `:composeApp:compileDebugKotlinAndroid` proves that
much.
**Expect this one not to be the end of it.** The crash is a property of the call
graph, and Mantra's graph is a superset of Curated's — projects, chapter uploads,
multi-parent subgroups, the markdown producer. The same phase may crash somewhere
else, or a different phase may crash. Treat the stack trace as the instruction:
disable the named phase, and write down why.
**Verify, on a mac:** `:composeApp:linkDebugTestIosArm64` and
`:composeApp:linkReleaseFrameworkIosArm64`.
**On Linux:** `:composeApp:compileDebugKotlinAndroid :composeApp:jvmTest` — the
renamed tests must still run, and the count must not move.
> `build(ios): unbreak the ios link tasks`
**Landed** as `d024838b`, the linux-verifiable half. The sweep ran exactly as
predicted: 84 names in 35 files, 84 changed lines, every one of them a `fun` line
and no other line in the tree touched. Both renamed tests show up in the results
under their new names, under `jvmTest` and `testDebugUnitTest` alike, and the 138
commas left in the results are `jvmTest`'s own — the set the plan leaves alone.
Two of the 84 needed rewording by hand, where the comma had been carrying real
work rather than pausing: `EOSE does not end a live subscription, CLOSED does`
became `a live subscription ends on CLOSED and not on EOSE`, and `a page says
which chronicle it is, where in it, and who for` became `... and where in it and
who for`. The other 82 lost only a pause.
The `-Xdisable-phases` block is in but **unproven** — no `KotlinNativeLink` task
exists on this host for it to match, so all that is verified is that the build
script still compiles. Whether this module's call graph crashes the same phase
Curated's did is Phase 6's question.
---
## Phase 4 — put every ktor client on Darwin
CIO has no TLS on Kotlin/Native. Pick the engine per platform instead of letting
the classpath pick it.
**Catalogue entry**, beside `ktor-client-cio` in
[gradle/libs.versions.toml:82](../gradle/libs.versions.toml):
```toml
ktor-client-darwin = { module = "io.ktor:ktor-client-darwin", version.ref = "ktor" }
```
**Dependency**, inside the existing `isMacOsX`-gated `iosMain.dependencies` block at
[composeApp/build.gradle.kts:154](../composeApp/build.gradle.kts). It goes inside
the gate, which is why Linux resolution is untouched by this phase.
**Three new files**, an `expect` and two `actual`s, in
`press.mantra.compose.network`:
- `commonMain/.../PlatformHttpClientEngine.kt` — `internal expect fun platformHttpClientEngineFactory(): HttpClientEngineFactory<*>`
- `androidMain/.../PlatformHttpClientEngine.android.kt` — `= CIO`
- `jvmMain/.../PlatformHttpClientEngine.jvm.kt` — `= CIO`
- `iosMain/.../PlatformHttpClientEngine.ios.kt` — `= Darwin`
**Two call sites.** `defaultSocketsHttpClient` becomes
`HttpClient(platformHttpClientEngineFactory()) { … }`, keeping its `WebSockets`
block as-is. And `MantraApp` gains the singleton Coil loader, because Coil's
default ktor fetcher builds a bare `HttpClient()` and would fail on `https://`
images exactly as the sockets did:
```kotlin
private val imageHttpClient by lazy { HttpClient(platformHttpClientEngineFactory()) }
@Composable
fun MantraApp(…) {
setSingletonImageLoaderFactory { context ->
ImageLoader.Builder(context)
.components { add(KtorNetworkFetcherFactory(httpClient = { imageHttpClient })) }
.build()
}
MantraTheme { … }
}
```
`setSingletonImageLoaderFactory` goes *above* `MantraTheme`, at the top of the
composable's body, so it is installed before the first `AsyncImage` composes.
`MantraApp` is the only place both call sites are reachable from, and Mantra has no
`ImageLoader` configuration today to reconcile with.
**Verify, on Linux:** `:composeApp:compileDebugKotlinAndroid :composeApp:compileKotlinJvm :composeApp:jvmTest` — the android and jvm `actual`s and both call sites compile here, which is most of the phase.
**On a mac:** `:composeApp:compileKotlinIosArm64`, then the real test — a device or
simulator that reaches a relay over `wss://` and renders an avatar over `https://`.
> `fix(ios): build ktor clients on Darwin so wss/https work on a device`
**Landed** as `e6c3c8a2`. The android and jvm `actual`s and both call sites
compile; the Darwin `actual` and the thing the phase is actually for do not, here.
`ktor-client-darwin` 3.5.2 has never been resolved on this host — the gradle cache
holds 3.3.3 and 3.4.1 from older work and nothing newer — because the dependency
sits inside the `isMacOsX` gate. It resolves on the mac at the same `ktor` version
ref Curated built against.
---
## Phase 5 — signing, icon, version
Three things Curated's last two commits did that **cannot be ported**, only
decided. Each needs an answer from you before it can be written.
**`TEAM_ID`.** [iosApp/Configuration/Config.xcconfig](../iosApp/Configuration/Config.xcconfig)
has `TEAM_ID=` empty, and the bundle identifier is built from it
(`press.mantra.ios$(TEAM_ID)`). Curated committed its development team id in the
clear, which is normal for an xcconfig — a team id is not a secret — but it signs
builds to a particular account. The expectation is that Mantra uses **the same one
Curare does, `ZK3TQ662GB`**; that still wants confirming before it is written,
since it decides whose account the build belongs to and the bundle identifier is
derived from it.
**The app icon.** Curated replaced its single `app-icon-1024.png` with a 1024
light variant and a 1024 dark one, adding the `luminosity: dark` appearance to
`Contents.json` and leaving the `tinted` slot filenameless so iOS derives it.
Mantra's `AppIcon.appiconset` still holds one 1024 file and one entry. The
*structure* ports; the artwork does not. Two 1024×1024 PNGs are needed.
**`MARKETING_VERSION`.** Mantra's xcconfig says `1.0` while
`android { versionName }` says `0.1.2` — the two have simply never been reconciled
because nothing shipped on iOS. Curated set both to the `0.1.x` line. Pick one
number for both; the mismatch is the bug, not either value.
Curated's `a673c85e` moved `versionName` from `0.1.2` to `0.1.1`, which is a
release-bookkeeping step on their tree and means nothing on this one. Do not port
it.
> `feat(ios): the app icon, the signing team, and one version across both stores`
---
## Phase 6 — the part only a mac can find
Phases 1 to 4 fix everything Curated hit. They do not fix what Curated never had,
and Mantra has pulled four lines of work the fork does not carry: projects, chapter
uploads, multi-parent subgroups, and the markdown producer. None of it has ever
been compiled for `iosArm64`.
So the honest shape of this phase is a loop, not a list:
```bash
./gradlew :composeApp:compileKotlinIosArm64
./gradlew :composeApp:linkDebugTestIosArm64
./gradlew :composeApp:iosSimulatorArm64Test
./gradlew :composeApp:linkReleaseFrameworkIosArm64
```
then Xcode, whose build phase already runs
`:composeApp:embedAndSignAppleFrameworkForXcode` against the `ComposeApp`
framework, deployment target 18.2.
Known places to look first, each a guess with a reason:
- **`FilePicker.ios.kt`** is the newest `iosMain` actual and the one behind chapter
uploads. It exists, so it compiles in principle; whether `UIDocumentPicker`
actually returns bytes on a device is untested anywhere.
- **Anything reached only from the new screens** — the `StaticInitializers` crash in
Phase 3 is call-graph-shaped, and these four lines are what widened the graph.
- **`kotlinx.datetime` and `okio` edges** in the markdown and chapter paths, which
are the usual source of a jvm-only overload that compiles everywhere but native.
Each fix found here is its own commit, in the voice of what broke rather than
"ios fixes".
---
## Phase 7 — write down what it cost
This document, revised from a plan into a record: which of the five defects
behaved as predicted, what Phase 6 actually found, and which compiler phase is
disabled with which stack trace behind it. Then revise its row in
[docs/README.md](./README.md), which this document already carries, so it describes
what happened rather than what was planned.
The `-Xdisable-phases` flag in particular needs a home in prose. It is a load-
bearing workaround for an upstream compiler bug, it is invisible from the source,
and the next person to bump Kotlin should be able to find out in one grep whether
they can take it out again.
---
## What to do if there is no mac
Phases 1 to 4 are worth landing anyway, and all four are verifiable on Linux for
the half that Linux compiles:
| phase | Linux-verifiable | needs a mac |
|---|---|---|
| 1 | the fix is `if (!currentOs.isLinux)`, so "unchanged" is the whole check | that it configures at all |
| 2 | `@ConstructedBy` and all seven `@Throws` | the unused-import removal |
| 3 | the renamed tests still run; the build script still compiles | both link tasks |
| 4 | the `expect`, the android and jvm `actual`s, both call sites | the Darwin `actual`, and TLS actually working |
| 5 | nothing | nothing — it needs decisions, not a host |
Phase 2's `@ConstructedBy` is the one with real Linux-side risk, since it changes
what Room's KSP generates for every target. Land it on its own and read
`:composeApp:jvmTest` carefully.
+1
View File
@@ -80,6 +80,7 @@ kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serializa
kotlinx-serialization-cbor = { module = "org.jetbrains.kotlinx:kotlinx-serialization-cbor", version.ref = "kotlinxSerialization" }
ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
ktor-client-cio = { module = "io.ktor:ktor-client-cio", version.ref = "ktor" }
ktor-client-darwin = { module = "io.ktor:ktor-client-darwin", version.ref = "ktor" }
ktor-client-websockets = { module = "io.ktor:ktor-client-websockets", version.ref = "ktor" }
ktor-serialization-kotlinx-json = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktor" }
lightning-kmp-core = { module = "fr.acinq.lightning:lightning-kmp-core", version.ref = "lightningKmpCore" }